PushButton.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_PushButton_H
31#define Pt_Forms_PushButton_H
32
33#include <Pt/Forms/Button.h>
34#include <Pt/Forms/ButtonStyler.h>
35#include <Pt/Forms/Icon.h>
36#include <Pt/Forms/Pixmap.h>
37#include <Pt/Forms/Direction.h>
38#include <Pt/Gfx/Image.h>
39#include <Pt/Gfx/Brush.h>
40#include <Pt/Gfx/Pen.h>
41#include <Pt/SmartPtr.h>
42
43namespace Pt {
44
45namespace Forms {
46
76class PT_FORMS_API PushButton : public Button
77{
78 public:
79 typedef Button Base;
80
81 public:
85
88 virtual ~PushButton();
89
92 bool isPressed() const;
93
96 void setPressed(bool pressed);
97
100 bool isToggle() const;
101
104 void setToggle(bool toggle);
105
110 void setIcon(const Icon& icon, const Gfx::SizeF& iconSize);
111
114 bool isFlat() const;
115
118 void setFlat(bool f);
119
123
124 public:
127 const Gfx::Brush& foreground() const;
128
131 void setForeground(const Gfx::Brush& b);
132
135 const Gfx::Pen& contour() const;
136
139 void setContour(const Gfx::Pen& p);
140
143 const Gfx::Color& accentColor() const;
144
147 void setAccentColor(const Gfx::Color& color);
148
152
156
159 const Gfx::Color& textColor() const;
160
163 void setTextColor(const Gfx::Color& color);
164
168
171 void setFont(const Gfx::Font& font);
172
175 void setFontSize(std::size_t size);
176
180
184
191
192 protected:
195 virtual void onPressed();
196
199 virtual void onReleased();
200
203 virtual void onCanceled();
204
205 protected:
208 virtual void onRescaleEvent(const RescaleEvent& ev);
209
210 protected:
217 virtual void onInvalidate();
218
221 virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
222
225 virtual void onLayout(const Gfx::RectF& rect);
226
229 virtual void onPaint(PaintContext& context, const Gfx::RectF& updateRect);
230
235 virtual void onPaintBackground(PaintContext& context,
236 const Gfx::RectF& rect,
237 const ButtonState& state);
238
243 virtual void onPaintFrame(PaintContext& context,
244 const Gfx::RectF& rect,
245 const ButtonState& state);
246
251 virtual void onPaintIcon(PaintContext& context,
252 const Gfx::RectF& rect,
253 const Pixmap& picture,
254 const Gfx::PointF& pos,
255 const ButtonState& state);
256
261 virtual void onPaintText(PaintContext& context,
262 const Gfx::RectF& rect,
263 const String& text,
264 const Gfx::PointF& pos,
265 const ButtonState& state);
266
271 virtual void onPaintMnemonic(PaintContext& context,
272 const Gfx::RectF& rect,
273 const Gfx::RectF& mnemonic,
274 const ButtonState& state);
275
276 private:
277 const ButtonState& buttonState();
278
279 private:
280 bool _isToggle;
281 bool _isBeingToggled;
282 Direction _direction;
283 Icon _icon;
284 bool _iconInvalid;
285 Pixmap _picture;
286
287 ButtonState _buttonState;
288 ButtonStyler _styler;
289
290 Gfx::SizeF _iconSize;
291 Gfx::PointF _textPos;
292 Gfx::PointF _iconPos;
293 Gfx::RectF _contentRect;
294 Gfx::RectF _iconRect;
295 Gfx::RectF _textRect;
296 Gfx::RectF _mnemonicRect;
297 Gfx::TextMetrics _textMetrics;
298 Gfx::FontMetrics _fontMetrics;
299 Gfx::SizeF _measuredIconSize;
300};
301
302} // namespace
303
304} // namespace
305
306#endif
Renders the look of a push button.
Definition ButtonStyler.h:124
Transient visual state of a push button.
Definition ButtonStyler.h:49
Binds a push button to the current style renderer.
Definition ButtonStyler.h:334
const Pt::String & text() const
Returns the caption.
Button()
Creates a button that accepts focus.
const Pt::Char * mnemonic() const
Returns the registered mnemonic character, or 0 when none is set.
Names a flow direction.
Definition Direction.h:52
Represents an image at one or more logical sizes.
Definition Icon.h:144
Active painting session on a Forms paint surface.
Definition PaintContext.h:51
Off-screen Forms paint surface.
Definition Pixmap.h:130
void setLayout(Direction d)
Sets the direction of icon and caption to d.
virtual void onPaint(PaintContext &context, const Gfx::RectF &updateRect)
Paints background, frame, icon, caption, and mnemonic.
const Gfx::Color & highlightColor() const
Returns the effective highlight color.
const Gfx::Color & textColor() const
Returns the effective text color.
virtual void onRescaleEvent(const RescaleEvent &ev)
Invalidates a prepared icon after a scale change.
void setIcon(const Icon &icon, const Gfx::SizeF &iconSize)
Sets the icon shown beside the caption.
void setToggle(bool toggle)
Sets whether the button stays pressed after a click.
PushButton()
Creates a command button.
void setHighlightColor(const Gfx::Color &c)
Sets the widget-local highlight color to c.
virtual void onCanceled()
Restores the pressed state after an abandoned click.
void setForeground(const Gfx::Brush &b)
Sets the widget-local foreground brush to b.
bool isPressed() const
Returns true if the button is visually pressed.
const Gfx::Brush & foreground() const
Returns the effective foreground brush.
virtual void onPaintIcon(PaintContext &context, const Gfx::RectF &rect, const Pixmap &picture, const Gfx::PointF &pos, const ButtonState &state)
Paints the button icon layer.
Gfx::Font font() const
Returns the effective font.
virtual void onLayout(const Gfx::RectF &rect)
Places icon, caption, and mnemonic in rect.
virtual void onPaintMnemonic(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &mnemonic, const ButtonState &state)
Paints the button mnemonic layer.
virtual void onPressed()
Presses the button, or toggles it when isToggle() is true.
void setRenderer(ButtonRenderer *renderer)
Assigns renderer as the family renderer.
void setPressed(bool pressed)
Sets whether the button is visually pressed.
void setContour(const Gfx::Pen &p)
Sets the widget-local contour pen to p.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures icon, caption, and frame.
bool isFlat() const
Returns true if the button uses a flat face.
const Gfx::Color & accentColor() const
Returns the effective accent color.
virtual ~PushButton()
Destroys the button.
bool isToggle() const
Returns true if the button stays pressed after a click.
virtual void onPaintBackground(PaintContext &context, const Gfx::RectF &rect, const ButtonState &state)
Paints the button background layer.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.
const Gfx::Pen & contour() const
Returns the effective contour pen.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
void setFlat(bool f)
Sets whether the button uses a flat face.
virtual void onInvalidate()
Binds the styler and prepares the icon.
void setAccentColor(const Gfx::Color &color)
Sets the widget-local accent color to color.
virtual void onPaintText(PaintContext &context, const Gfx::RectF &rect, const String &text, const Gfx::PointF &pos, const ButtonState &state)
Paints the button text layer.
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
virtual void onReleased()
Completes the click and emits clicked().
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
virtual void onPaintFrame(PaintContext &context, const Gfx::RectF &rect, const ButtonState &state)
Paints the button frame layer.
Constraint used when measuring a control.
Definition SizePolicy.h:48
const Gfx::SizeF & size() const
Returns the size in local logical coordinates.
Fill color, gradient or texture.
Definition Brush.h:151
8-bit ARGB color.
Definition Color.h:65
Ascent, descent and line height of a font.
Definition FontMetrics.h:50
Font family, size and style.
Definition Font.h:63
Slant
Describes the requested font slant.
Definition Font.h:83
Weight
Describes the requested font weight.
Definition Font.h:68
Outline color, width and style.
Definition Pen.h:59
Width and bounds of a text run.
Definition TextMetrics.h:49
Unicode capable basic_string.
Definition Api-String.h:67
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33