ProgressBar.h
1 /* Copyright (C) 2017 Marc Boris Duerner
2 
3  This library is free software; you can redistribute it and/or
4  modify it under the terms of the GNU Lesser General Public
5  License as published by the Free Software Foundation; either
6  version 2.1 of the License, or (at your option) any later version.
7 
8  As a special exception, you may use this file as part of a free
9  software library without restriction. Specifically, if other files
10  instantiate templates or use macros or inline functions from this
11  file, or you compile this file and link it with other files to
12  produce an executable, this file does not by itself cause the
13  resulting executable to be covered by the GNU General Public
14  License. This exception does not however invalidate any other
15  reasons why the executable file might be covered by the GNU Library
16  General Public License.
17 
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26  MA 02110-1301 USA
27 */
28 
29 #ifndef Pt_Forms_ProgressBar_H
30 #define Pt_Forms_ProgressBar_H
31 
32 #include <Pt/Forms/Control.h>
33 #include <Pt/Forms/ProgressBarStyler.h>
34 #include <Pt/Signal.h>
35 
36 namespace Pt {
37 
38 namespace Forms {
39 
69 class PT_FORMS_API ProgressBar : public Control
70 {
71  public:
72  typedef Control Base;
73 
74  public:
78 
81  virtual ~ProgressBar();
82 
85  int maximum() const;
86 
89  int minimum() const;
90 
93  void setRange(int minpos, int maxpos);
94 
97  int value() const;
98 
101  void setValue(int n);
102 
105  float progress() const;
106 
109  void reset();
110 
114 
115  public:
118  const Gfx::Brush& background() const;
119 
122  void setBackground(const Gfx::Brush& b);
123 
126  const Gfx::Brush& foreground() const;
127 
130  void setForeground(const Gfx::Brush& b);
131 
134  const Gfx::Pen& contour() const;
135 
138  void setContour(const Gfx::Pen& p);
139 
142  const Gfx::Color& textColor() const;
143 
146  void setTextColor(const Gfx::Color& color);
147 
150  Gfx::Font font() const;
151 
154  void setFont(const Gfx::Font& font);
155 
158  void setFontSize(std::size_t size);
159 
163 
167 
173 
177 
178  protected:
181  virtual void onInvalidate();
182 
185  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
186 
189  virtual void onLayout(const Gfx::RectF& rect);
190 
193  virtual void onPaint(PaintContext& context,
194  const Gfx::RectF& updateRect);
195 
198  virtual void onPaintChrome(PaintContext& context,
199  const Gfx::RectF& rect,
200  const Gfx::RectF& trackRect,
201  const Gfx::RectF& chunkRect,
202  const Gfx::RectF& textRect,
203  const String& text,
204  const Gfx::PointF& textPos,
205  const ProgressBarState& state);
206 
207  private:
208  Signal<int> _valueChanged;
209  int _value;
210  int _min;
211  int _max;
212 
213  Gfx::RectF _barRect;
214  Gfx::RectF _textRect;
215  Gfx::RectF _trackRect;
216  Gfx::RectF _chunkRect;
217 
218  ProgressBarStyler _styler;
219 };
220 
221 } // namespace
222 
223 } // namespace
224 
225 #endif
Core module.
Definition: Allocator.h:33
Renders the look of a progress bar.
Definition: ProgressBarStyler.h:88
Binds a progress bar to the current style renderer.
Definition: ProgressBarStyler.h:267
const Gfx::Brush & background() const
Returns the effective background brush.
void setBackground(const Gfx::Brush &b)
Sets the widget-local background brush to b.
Attributes for the drawing of outlines.
Definition: Pen.h:54
Gfx::Font font() const
Returns the effective font.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the track and frame.
virtual void onLayout(const Gfx::RectF &rect)
Places the track and filled portion in rect.
int minimum() const
Returns the lower bound of the range.
virtual void onInvalidate()
Binds the styler and requests relayout.
void setForeground(const Gfx::Brush &b)
Sets the widget-local foreground brush to b.
Control that shows a value within a range.
Definition: ProgressBar.h:70
float progress() const
Returns the filled ratio from 0 to 1.
Slant
Describes the requested font slant.
Definition: Font.h:76
virtual void onPaint(PaintContext &context, const Gfx::RectF &updateRect)
Paints the chrome for the current progress.
const Gfx::Pen & contour() const
Returns the effective contour pen.
const Gfx::Color & textColor() const
Returns the effective text color.
void setValue(int n)
Sets the value to n, clamped to the range, and emits valueChanged().
Active painting session on a Forms paint surface.
Definition: PaintContext.h:51
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
Size with floating-point width and height.
Definition: Size.h:47
int maximum() const
Returns the upper bound of the range.
Point with floating-point X and Y coordinates.
Definition: Point.h:47
Reusable view used as application content.
Definition: Control.h:107
int value() const
Returns the current value.
void setRange(int minpos, int maxpos)
Sets the range to minpos through maxpos.
void setContour(const Gfx::Pen &p)
Sets the widget-local contour pen to p.
Signal< int > & valueChanged()
Returns the signal emitted after setValue() changes the value.
Weight
Describes the requested font weight.
Definition: Font.h:61
void setRenderer(ProgressBarRenderer *renderer)
Assigns renderer as the family renderer.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
Transient visual state of a progress bar.
Definition: ProgressBarStyler.h:47
virtual void onPaintChrome(PaintContext &context, const Gfx::RectF &rect, const Gfx::RectF &trackRect, const Gfx::RectF &chunkRect, const Gfx::RectF &textRect, const String &text, const Gfx::PointF &textPos, const ProgressBarState &state)
Paints track, filled portion, and text for state.
Widget that hosts controls on a paint surface.
Definition: View.h:86
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
Font request used for text drawing and measurement.
Definition: Font.h:56
void reset()
Sets the value to the minimum.
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 ~ProgressBar()
Destroys the progress bar.
ProgressBarState progressBarState() const
Returns the snapshot passed to paint layers.
Fill description for shapes and text.
Definition: Brush.h:145
Rect with floating-point coordinates.
Definition: Rect.h:47
ProgressBar()
Creates a progress bar with range 0 to 100 and value 50.
const Gfx::Brush & foreground() const
Returns the effective foreground brush.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.