2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2019-01-20 04:49:48 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Function.h>
|
2020-01-10 19:06:00 +03:00
|
|
|
#include <AK/String.h>
|
2019-07-18 10:15:00 +02:00
|
|
|
#include <LibDraw/GraphicsBitmap.h>
|
|
|
|
#include <LibDraw/StylePainter.h>
|
|
|
|
#include <LibDraw/TextAlignment.h>
|
2020-01-10 19:06:00 +03:00
|
|
|
#include <LibGUI/GAbstractButton.h>
|
2019-01-20 04:49:48 +01:00
|
|
|
|
2019-04-12 02:53:27 +02:00
|
|
|
class GAction;
|
|
|
|
|
2019-05-24 16:32:20 +02:00
|
|
|
class GButton : public GAbstractButton {
|
2019-07-25 19:49:28 +02:00
|
|
|
C_OBJECT(GButton)
|
2019-01-20 04:49:48 +01:00
|
|
|
public:
|
|
|
|
virtual ~GButton() override;
|
|
|
|
|
2019-06-21 18:37:47 +02:00
|
|
|
void set_icon(RefPtr<GraphicsBitmap>&&);
|
2019-02-07 23:13:47 +01:00
|
|
|
const GraphicsBitmap* icon() const { return m_icon.ptr(); }
|
|
|
|
GraphicsBitmap* icon() { return m_icon.ptr(); }
|
|
|
|
|
2019-04-04 14:15:57 +02:00
|
|
|
void set_text_alignment(TextAlignment text_alignment) { m_text_alignment = text_alignment; }
|
|
|
|
TextAlignment text_alignment() const { return m_text_alignment; }
|
|
|
|
|
2019-01-21 00:31:11 +01:00
|
|
|
Function<void(GButton&)> on_click;
|
2019-01-20 04:49:48 +01:00
|
|
|
|
2019-03-28 17:32:38 +01:00
|
|
|
void set_button_style(ButtonStyle style) { m_button_style = style; }
|
|
|
|
ButtonStyle button_style() const { return m_button_style; }
|
2019-02-20 09:22:38 +01:00
|
|
|
|
2019-05-24 16:32:20 +02:00
|
|
|
virtual void click() override;
|
2019-03-19 01:41:00 +01:00
|
|
|
|
2019-04-12 02:53:27 +02:00
|
|
|
void set_action(GAction&);
|
|
|
|
|
2019-06-22 10:39:13 +02:00
|
|
|
virtual bool accepts_focus() const override { return m_focusable; }
|
2019-07-09 22:10:03 +02:00
|
|
|
virtual bool is_uncheckable() const override;
|
2019-06-22 10:39:13 +02:00
|
|
|
|
|
|
|
void set_focusable(bool b) { m_focusable = b; }
|
2019-03-16 12:57:04 +01:00
|
|
|
|
2019-04-13 03:08:16 +02:00
|
|
|
protected:
|
2019-09-21 19:37:38 +02:00
|
|
|
GButton(const StringView& text, GWidget* parent);
|
|
|
|
explicit GButton(GWidget* parent);
|
2019-01-21 00:46:08 +01:00
|
|
|
virtual void paint_event(GPaintEvent&) override;
|
2019-01-20 04:49:48 +01:00
|
|
|
|
2019-04-13 03:08:16 +02:00
|
|
|
private:
|
2019-06-21 18:37:47 +02:00
|
|
|
RefPtr<GraphicsBitmap> m_icon;
|
2019-03-28 17:32:38 +01:00
|
|
|
ButtonStyle m_button_style { ButtonStyle::Normal };
|
2019-04-04 14:15:57 +02:00
|
|
|
TextAlignment m_text_alignment { TextAlignment::Center };
|
2019-04-12 02:53:27 +02:00
|
|
|
WeakPtr<GAction> m_action;
|
2019-06-22 10:39:13 +02:00
|
|
|
bool m_focusable { true };
|
2019-01-20 04:49:48 +01:00
|
|
|
};
|