Button.h
1/* Copyright (C) 2016 Marc Boris Duerner
2 Copyright (C) 2016 Laurentiu-Gheorghe Crisan
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 As a special exception, you may use this file as part of a free
10 software library without restriction. Specifically, if other files
11 instantiate templates or use macros or inline functions from this
12 file, or you compile this file and link it with other files to
13 produce an executable, this file does not by itself cause the
14 resulting executable to be covered by the GNU General Public
15 License. This exception does not however invalidate any other
16 reasons why the executable file might be covered by the GNU Library
17 General Public License.
18
19 This library is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 Lesser General Public License for more details.
23
24 You should have received a copy of the GNU Lesser General Public
25 License along with this library; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27 MA 02110-1301 USA
28*/
29
30#ifndef Pt_Forms_Button_H
31#define Pt_Forms_Button_H
32
33#include <Pt/Forms/Control.h>
34
35namespace Pt {
36
37namespace Forms {
38
67class PT_FORMS_API Button : public Control
68{
69 public:
70 typedef Control Base;
71
72 public:
76
79 virtual ~Button();
80
83 const Pt::String& text() const;
84
87 void setText(const Pt::String& t);
88
91 bool isHovered() const;
92
95 void click();
96
100
101 protected:
104 virtual void onPressed();
105
108 virtual void onReleased();
109
112 virtual void onCanceled();
113
114 protected:
117 virtual void onMnemonic(Pt::Char m);
118
121 virtual void onShortcut(const Key& key);
122
125 virtual void onActionKey(const KeyEvent& kev);
126
127 protected:
130 virtual bool onEnterEvent(const EnterEvent& ev);
131
134 virtual bool onLeaveEvent(const LeaveEvent& ev);
135
138 virtual void onFocusEvent(const FocusEvent& ev);
139
142 virtual bool onMouseEvent(const MouseEvent& ev);
143
146 virtual bool onTouchEvent(const TouchEvent& ev);
147
150 virtual bool onScrollEvent(const ScrollEvent& ev);
151
152 private:
153 Signal<> _clicked;
154 bool _onClickBegin;
155 Pt::String _text;
156 bool _isHovered;
157};
158
159} // namespace
160
161} // namespace
162
163#endif
virtual bool onMouseEvent(const MouseEvent &ev)
Presses, releases, or cancels from the mouse event ev.
virtual void onFocusEvent(const FocusEvent &ev)
Forwards the focus change to the base control.
virtual ~Button()
Destroys the button.
virtual bool onTouchEvent(const TouchEvent &ev)
Presses, releases, or cancels from the touch event ev.
void setText(const Pt::String &t)
Sets the caption to t and records its mnemonic.
virtual void onCanceled()
Called when a click gesture is abandoned.
virtual bool onEnterEvent(const EnterEvent &ev)
Marks the button hovered and requests a repaint.
const Pt::String & text() const
Returns the caption.
virtual void onPressed()
Called when a click gesture begins.
Signal & clicked()
Returns the signal emitted after a completed click.
virtual void onActionKey(const KeyEvent &kev)
Presses or releases the button for the action key kev.
virtual void onShortcut(const Key &key)
Runs a completed click for the shortcut key.
virtual bool onLeaveEvent(const LeaveEvent &ev)
Clears hover and requests a repaint.
void click()
Runs press then release as a completed click.
virtual void onMnemonic(Pt::Char m)
Runs a completed click for the mnemonic character m.
virtual bool onScrollEvent(const ScrollEvent &ev)
Cancels an in-progress click and forwards ev.
Button()
Creates a button that accepts focus.
bool isHovered() const
Returns true if the pointer is over the button.
virtual void onReleased()
Called when a click gesture completes.
Control()
Creates an unparented control.
Pointer entered a widget.
Definition EnterEvent.h:49
Reports that a widget gained or lost focus.
Definition FocusEvent.h:48
Key press or release.
Definition KeyEvent.h:50
Key code and modifiers.
Definition Key.h:23
Pointer left a widget.
Definition LeaveEvent.h:49
Pointer movement or button change.
Definition MouseEvent.h:134
Scroll or wheel movement.
Definition ScrollEvent.h:51
Touch press, move, or release.
Definition TouchEvent.h:51
Multicast Signal to call multiple slots.
Definition Signal.h:190
Unicode capable basic_string.
Definition Api-String.h:67
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33
Unicode character type.
Definition String.h:67