CheckBox.h
1
2/* Copyright (C) 2016 Marc Boris Duerner
3 Copyright (C) 2016 Laurentiu-Gheorghe Crisan
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 As a special exception, you may use this file as part of a free
11 software library without restriction. Specifically, if other files
12 instantiate templates or use macros or inline functions from this
13 file, or you compile this file and link it with other files to
14 produce an executable, this file does not by itself cause the
15 resulting executable to be covered by the GNU General Public
16 License. This exception does not however invalidate any other
17 reasons why the executable file might be covered by the GNU Library
18 General Public License.
19
20 This library is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 Lesser General Public License for more details.
24
25 You should have received a copy of the GNU Lesser General Public
26 License along with this library; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
28 MA 02110-1301 USA
29*/
30
31#ifndef Pt_Forms_CheckBox_h
32#define Pt_Forms_CheckBox_h
33
34#include <Pt/Forms/Button.h>
35#include <Pt/Forms/CheckBoxStyler.h>
36#include <Pt/Gfx/FontMetrics.h>
37#include <Pt/Gfx/TextMetrics.h>
38
39namespace Pt {
40
41namespace Forms {
42
69class PT_FORMS_API CheckBox : public Button
70{
71 public:
72 typedef Button Base;
73
76 enum State
77 {
81
85
89 // Partial
90 };
91
92 public:
96
99 virtual ~CheckBox();
100
103 State state() const;
104
108
111 bool isChecked() const;
112
113 public:
116 const Gfx::Brush& background() const;
117
120 void setBackground(const Gfx::Brush& b);
121
124 const Gfx::Pen& contour() const;
125
128 void setContour(const Gfx::Pen& p);
129
132 const Gfx::Color& textColor() const;
133
136 void setTextColor(const Gfx::Color& color);
137
141
144 void setFont(const Gfx::Font& font);
145
148 void setFontSize(std::size_t size);
149
153
157
163
164 protected:
167 virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
168
171 virtual void onLayout(const Gfx::RectF& rect);
172
175 virtual void onInvalidate();
176
179 virtual void onPressed();
180
183 virtual void onReleased();
184
187 virtual void onCanceled();
188
189 protected:
192 virtual void onPaint(PaintContext& context, const Gfx::RectF& updateRect);
193
196 virtual void onPaintChrome(PaintContext& context,
197 const Gfx::RectF& rect,
198 const Gfx::RectF& boxRect,
199 const CheckBoxState& state);
200
203 virtual void onPaintText(PaintContext& context,
204 const Gfx::RectF& textRect,
205 const String& text,
206 const Gfx::PointF& pos,
207 const CheckBoxState& state);
208
211 virtual void onPaintMnemonic(PaintContext& context,
212 const Gfx::RectF& rect,
213 const Gfx::RectF& mnemonic,
214 const CheckBoxState& state);
215
216 private:
217 CheckBoxState checkBoxState() const;
218
219 private:
220 State _state;
221 CheckBoxStyler _styler;
222
223 Gfx::RectF _boxRect;
224 Gfx::RectF _textRect;
225 Gfx::PointF _textPos;
226 Gfx::RectF _mnemonicRect;
227};
228
229} // namespace
230
231} // namespace
232
233#endif
const Pt::String & text() const
Returns the caption.
Button()
Creates a button that accepts focus.
Renders the look of a check box.
Definition CheckBoxStyler.h:108
Transient visual state of a check box.
Definition CheckBoxStyler.h:48
Binds a check box to the current style renderer.
Definition CheckBoxStyler.h:275
virtual void onPaint(PaintContext &context, const Gfx::RectF &updateRect)
Paints chrome, caption, and mnemonic.
const Gfx::Color & textColor() const
Returns the effective text color.
virtual ~CheckBox()
Destroys the check box.
virtual void onCanceled()
Forwards cancel to Button.
const Gfx::Brush & background() const
Returns the effective background brush.
State
Value of the choice.
Definition CheckBox.h:77
@ Unspecified
Neither on nor off.
Definition CheckBox.h:80
@ Checked
The choice is on.
Definition CheckBox.h:84
@ Unchecked
The choice is off.
Definition CheckBox.h:88
Gfx::Font font() const
Returns the effective font.
virtual void onLayout(const Gfx::RectF &rect)
Places the checkable area, caption, and mnemonic in rect.
virtual void onPressed()
Forwards press to Button.
void setBackground(const Gfx::Brush &b)
Sets the widget-local background brush to b.
void setRenderer(CheckBoxRenderer *renderer)
Assigns renderer as the family renderer.
virtual void onPaintMnemonic(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &mnemonic, const CheckBoxState &state)
Paints the mnemonic underline for state.
void setContour(const Gfx::Pen &p)
Sets the widget-local contour pen to p.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the checkable area, caption, and frame.
void setState(State s)
Sets the choice to s.
virtual void onPaintText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &pos, const CheckBoxState &state)
Paints the caption for state.
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.
bool isChecked() const
Returns true if the choice is Checked.
State state() const
Returns the current choice.
virtual void onPaintChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &boxRect, const CheckBoxState &state)
Paints the checkable area for state.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
virtual void onInvalidate()
Binds the styler and requests relayout.
CheckBox()
Creates an unchecked check box.
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
virtual void onReleased()
Toggles Checked and Unchecked, then emits clicked().
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
const Pt::Char * mnemonic() const
Returns the registered mnemonic character, or 0 when none is set.
Active painting session on a Forms paint surface.
Definition PaintContext.h:51
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
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
Unicode capable basic_string.
Definition Api-String.h:67
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33