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 
39 namespace Pt {
40 
41 namespace Forms {
42 
69 class PT_FORMS_API CheckBox : public Button
70 {
71  public:
72  typedef Button Base;
73 
76  enum State
77  {
80  Unspecified = 0,
81 
84  Checked = 1,
85 
88  Unchecked = 2
89  // Partial
90  };
91 
92  public:
96 
99  virtual ~CheckBox();
100 
103  State state() const;
104 
107  void setState(State s);
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 
140  Gfx::Font font() const;
141 
144  void setFont(const Gfx::Font& font);
145 
148  void setFontSize(std::size_t size);
149 
153 
157 
162  void setRenderer(CheckBoxRenderer* renderer);
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
Core module.
Definition: Allocator.h:33
virtual ~CheckBox()
Destroys the check box.
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.
void setBackground(const Gfx::Brush &b)
Sets the widget-local background brush to b.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
virtual void onPaintMnemonic(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &mnemonic, const CheckBoxState &state)
Paints the mnemonic underline for state.
Attributes for the drawing of outlines.
Definition: Pen.h:54
Renders the look of a check box.
Definition: CheckBoxStyler.h:108
virtual void onCanceled()
Forwards cancel to Button.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
Slant
Describes the requested font slant.
Definition: Font.h:76
void setContour(const Gfx::Pen &p)
Sets the widget-local contour pen to p.
CheckBox()
Creates an unchecked check box.
Active painting session on a Forms paint surface.
Definition: PaintContext.h:51
Gfx::Font font() const
Returns the effective font.
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
State state() const
Returns the current choice.
Size with floating-point width and height.
Definition: Size.h:47
Point with floating-point X and Y coordinates.
Definition: Point.h:47
virtual void onPaintText(PaintContext &context, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &pos, const CheckBoxState &state)
Paints the caption for state.
State
Value of the choice.
Definition: CheckBox.h:77
Reusable view used as application content.
Definition: Control.h:107
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the checkable area, caption, and frame.
Weight
Describes the requested font weight.
Definition: Font.h:61
virtual void onInvalidate()
Binds the styler and requests relayout.
virtual void onPaintChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &boxRect, const CheckBoxState &state)
Paints the checkable area for state.
Button that presents a boolean choice.
Definition: CheckBox.h:70
virtual void onPaint(PaintContext &context, const Gfx::RectF &updateRect)
Paints chrome, caption, and mnemonic.
Font request used for text drawing and measurement.
Definition: Font.h:56
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
Interaction control for press, release, and click.
Definition: Button.h:68
virtual void onLayout(const Gfx::RectF &rect)
Places the checkable area, caption, and mnemonic in rect.
const Gfx::Brush & background() const
Returns the effective background brush.
Constraint used when measuring a control.
Definition: SizePolicy.h:48
Standard color type.
Definition: Color.h:47
Unicode capable basic_string.
Definition: Api-String.h:44
virtual void onReleased()
Toggles Checked and Unchecked, then emits clicked().
void setState(State s)
Sets the choice to s.
virtual void onPressed()
Forwards press to Button.
Fill description for shapes and text.
Definition: Brush.h:145
Transient visual state of a check box.
Definition: CheckBoxStyler.h:48
Rect with floating-point coordinates.
Definition: Rect.h:47
const Gfx::Color & textColor() const
Returns the effective text color.
bool isChecked() const
Returns true if the choice is Checked.
Binds a check box to the current style renderer.
Definition: CheckBoxStyler.h:275
void setRenderer(CheckBoxRenderer *renderer)
Assigns renderer as the family renderer.
const Gfx::Pen & contour() const
Returns the effective contour pen.