/src/wt/src/Wt/WProgressBar.h
Line | Count | Source |
1 | | // This may look like C code, but it's really -*- C++ -*- |
2 | | /* |
3 | | * Copyright (C) 2010 Thomas Suckow. |
4 | | * Copyright (C) 2010 Emweb bv, Herent, Belgium |
5 | | * |
6 | | * See the LICENSE file for terms of use. |
7 | | */ |
8 | | #ifndef WPROGRESSBAR_H_ |
9 | | #define WPROGRESSBAR_H_ |
10 | | |
11 | | #include <Wt/WInteractWidget.h> |
12 | | |
13 | | namespace Wt { |
14 | | |
15 | | /*! \brief A progress bar. |
16 | | * |
17 | | * The progress bar can be used to indicate the progress of a certain |
18 | | * operation. The text displayed in the progress bar can be customized |
19 | | * by specializing text(). |
20 | | * |
21 | | * To use the progress bar, you need to give it a range (minimum and maximum |
22 | | * value), and update the progress using setValue(). |
23 | | * |
24 | | * %WProgressBar is an \link WWidget::setInline(bool) inline \endlink widget. |
25 | | * |
26 | | * \note With the advent of HTML5, this widget will be implemented using |
27 | | * the native HTML5 control when available. |
28 | | */ |
29 | | class WT_API WProgressBar : public WInteractWidget |
30 | | { |
31 | | public: |
32 | | /*! \brief Creates a progress bar. |
33 | | */ |
34 | | WProgressBar(); |
35 | | |
36 | | /*! \brief Sets the minimum value. |
37 | | * |
38 | | * The minimum value is the value that corresponds to 0%. |
39 | | * |
40 | | * The default value is 0. |
41 | | */ |
42 | | void setMinimum(double minimum); |
43 | | |
44 | | /*! \brief Returns the minimum value. |
45 | | * |
46 | | * \sa setMinimum() |
47 | | */ |
48 | 0 | double minimum() const { return min_; } |
49 | | |
50 | | /*! \brief Sets the maximum value. |
51 | | * |
52 | | * The maximum value is the value that corresponds to 100%. |
53 | | * |
54 | | * The default value is 100. |
55 | | */ |
56 | | void setMaximum(double maximum); |
57 | | |
58 | | /*! \brief Returns the maximum value. |
59 | | * |
60 | | * \sa setMaximum() |
61 | | */ |
62 | 0 | double maximum() const { return max_; } |
63 | | |
64 | | /*! \brief Sets the range. |
65 | | * |
66 | | * \sa setMinimum(), setMaximum() |
67 | | */ |
68 | | void setRange(double minimum, double maximum); |
69 | | |
70 | | /*! \brief Sets the current progress. |
71 | | * |
72 | | * \p value must be a value between minimum() and maximum(). |
73 | | */ |
74 | | void setValue(double value); |
75 | | |
76 | | /*! \brief Returns the current progress. |
77 | | */ |
78 | 0 | double value() const { return value_; } |
79 | | |
80 | | /*! \brief Sets the progress format string. |
81 | | * |
82 | | * The format is used by text() to indicate the progress value. |
83 | | * |
84 | | * The default value is "%.0f %%" |
85 | | */ |
86 | | void setFormat(const WString& format); |
87 | | |
88 | | /*! \brief Returns the progress format string. |
89 | | * |
90 | | * \sa setFormat() |
91 | | */ |
92 | 0 | const WString& format() const { return format_; } |
93 | | |
94 | | /*! \brief Returns the text displayed inside the progress bar. |
95 | | * |
96 | | * This text must be an XHTML formatted text fragment. The default |
97 | | * text prints the current progress using format(). You may want to |
98 | | * reimplement this method to display a different text corresponding |
99 | | * to the current value(). |
100 | | */ |
101 | | virtual WString text() const; |
102 | | |
103 | | /*! \brief A %signal that indicates when the value has changed. |
104 | | * |
105 | | * This signal is emitted when setValue() is called. |
106 | | * |
107 | | * \sa setValue() |
108 | | */ |
109 | 0 | Signal<double>& valueChanged() { return valueChanged_; } |
110 | | |
111 | | /*! \brief A %signal that indicates when 100% is reached. |
112 | | * |
113 | | * This signal is emitted when setValue(maximum()) is called. |
114 | | * |
115 | | * \sa setValue() |
116 | | */ |
117 | 0 | Signal<>& progressCompleted() { return progressCompleted_; } |
118 | | |
119 | | virtual void resize(const WLength& width, const WLength& height) override; |
120 | | |
121 | | /*! \brief Updates the style class of the bar part of the WProgressBar. |
122 | | * |
123 | | * This can be used to style the bar part of the WProgressBar, e.g. "progress-bar-success" or "progress-bar-danger". |
124 | | * |
125 | | */ |
126 | | void setValueStyleClass(const std::string& valueClass); |
127 | | void setState(double minimum, double maximum, double value); |
128 | | |
129 | | protected: |
130 | | /*! \brief Update the progress bar itself. |
131 | | * |
132 | | * Will be called whenever the value changes, and changes |
133 | | * the width of the progress bar accordingly. |
134 | | * |
135 | | * You can reimplement this method to apply certain |
136 | | * style changes to the progress bar according to the |
137 | | * value. Don't forget to call WProgressBar::updateBar |
138 | | * if you still want the width to change. |
139 | | */ |
140 | | virtual void updateBar(DomElement& bar); |
141 | | |
142 | | virtual void updateDom(DomElement& element, bool all) override; |
143 | | virtual DomElementType domElementType() const override; |
144 | | virtual void propagateRenderOk(bool deep) override; |
145 | | |
146 | | private: |
147 | | double min_, max_, value_; |
148 | | WString format_; |
149 | | bool changed_, valueStyleClassChanged_; |
150 | | std::string valueStyleClass_; |
151 | | |
152 | | void onChange(); |
153 | | |
154 | | Signal<double> valueChanged_; |
155 | | Signal<> progressCompleted_; |
156 | | |
157 | | double percentage() const; |
158 | | }; |
159 | | |
160 | | } |
161 | | |
162 | | #endif // WPROGRESSBAR_H_ |