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
36namespace Pt {
37
38namespace Forms {
39
69class 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
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
Control()
Creates an unparented control.
Active painting session on a Forms paint surface.
Definition PaintContext.h:51
Renders the look of a progress bar.
Definition ProgressBarStyler.h:88
Transient visual state of a progress bar.
Definition ProgressBarStyler.h:47
Binds a progress bar to the current style renderer.
Definition ProgressBarStyler.h:267
void setRenderer(ProgressBarRenderer *renderer)
Assigns renderer as the family renderer.
virtual void onPaint(PaintContext &context, const Gfx::RectF &updateRect)
Paints the chrome for the current progress.
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.
const Gfx::Color & textColor() const
Returns the effective text color.
ProgressBarState progressBarState() const
Returns the snapshot passed to paint layers.
void setForeground(const Gfx::Brush &b)
Sets the widget-local foreground brush to b.
Signal< int > & valueChanged()
Returns the signal emitted after setValue() changes the value.
const Gfx::Brush & background() const
Returns the effective background brush.
const Gfx::Brush & foreground() const
Returns the effective foreground brush.
Gfx::Font font() const
Returns the effective font.
virtual void onLayout(const Gfx::RectF &rect)
Places the track and filled portion in rect.
void setValue(int n)
Sets the value to n, clamped to the range, and emits valueChanged().
ProgressBar()
Creates a progress bar with range 0 to 100 and value 50.
void setBackground(const Gfx::Brush &b)
Sets the widget-local background brush to b.
int value() const
Returns the current value.
int maximum() const
Returns the upper bound of the range.
void setContour(const Gfx::Pen &p)
Sets the widget-local contour pen to p.
virtual Gfx::SizeF onMeasure(const SizePolicy &policy)
Measures the track and frame.
void setRange(int minpos, int maxpos)
Sets the range to minpos through maxpos.
void setTextColor(const Gfx::Color &color)
Sets the widget-local text color to color.
int minimum() const
Returns the lower bound of the range.
void setFont(const Gfx::Font &font)
Sets the widget-local font to font.
const Gfx::Pen & contour() const
Returns the effective contour pen.
void reset()
Sets the value to the minimum.
void setFontWeight(Gfx::Font::Weight weight)
Sets the widget-local font weight to weight.
virtual ~ProgressBar()
Destroys the progress bar.
virtual void onInvalidate()
Binds the styler and requests relayout.
void setFontSize(std::size_t size)
Sets the widget-local font size to size.
float progress() const
Returns the filled ratio from 0 to 1.
void setFontSlant(Gfx::Font::Slant slant)
Sets the widget-local font slant to slant.
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
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