ProgressBar.h
1 /* Copyright (C) 2017 Marc Boris Duerner
2  Copyright (C) 2017 Ilja Maier
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  As a special exception, you may use this file as part of a free
10  software library without restriction. Specifically, if other files
11  instantiate templates or use macros or inline functions from this
12  file, or you compile this file and link it with other files to
13  produce an executable, this file does not by itself cause the
14  resulting executable to be covered by the GNU General Public
15  License. This exception does not however invalidate any other
16  reasons why the executable file might be covered by the GNU Library
17  General Public License.
18 
19  This library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  Lesser General Public License for more details.
23 
24  You should have received a copy of the GNU Lesser General Public
25  License along with this library; if not, write to the Free Software
26  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27  MA 02110-1301 USA
28 */
29 
30 #ifndef Pt_Forms_ProgressBar_H
31 #define Pt_Forms_ProgressBar_H
32 
33 #include <Pt/Forms/Control.h>
34 #include <Pt/SmartPtr.h>
35 #include <Pt/Signal.h>
36 
37 namespace Pt {
38 
39 namespace Forms {
40 
41 class PT_FORMS_API ProgressBar : public Control
42 {
43  public:
44  typedef Control Base;
45 
46  public:
47  ProgressBar();
48 
49  virtual ~ProgressBar();
50 
51  int maximum() const;
52 
53  int minimum() const;
54 
55  void setRange(int minpos, int maxpos);
56 
57  int value() const;
58 
59  void setValue(int n);
60 
61  float progress() const;
62 
63  void reset();
64 
65  Signal<int>& valueChanged();
66 
67  public:
68  const Gfx::Brush& background() const;
69 
70  void setBackground(const Gfx::Brush& b);
71 
72  const Gfx::Color& foreground() const;
73 
74  void setForeground(const Gfx::Color& b);
75 
76  const Gfx::Pen& contour() const;
77 
78  void setContour(const Gfx::Pen& p);
79 
80  const Gfx::Color& textColor() const;
81 
82  void setTextColor(const Gfx::Color& color);
83 
84  const Gfx::Font& font() const;
85 
86  void setFont(const Gfx::Font& font);
87 
88  void setFontSize(std::size_t size);
89 
90  void setFontWeight(Gfx::Font::Weight weight);
91 
92  void setFontSlant(Gfx::Font::Slant slant);
93 
94  void setRenderer(ProgressBarRenderer* renderer);
95 
96  protected:
97  virtual Gfx::SizeF onMeasure(const SizePolicy& policy);
98 
99  virtual void onInvalidate();
100 
101  virtual void onPaint(PaintSurface& surface, const Gfx::RectF& updateRect);
102 
103  private:
104  Gfx::Font getFont() const;
105 
106  private:
107  enum FontOverride : unsigned
108  {
109  OverrideSize = 0x01,
110  OverrideWeight = 0x02,
111  OverrideSlant = 0x04,
112  OverrideAll = 0xFF
113  };
114 
115  Signal<int> _valueChanged;
116  int _value;
117  int _min;
118  int _max;
119 
120  AutoPtr<Gfx::Brush> _background;
121  AutoPtr<Gfx::Color> _foreground;
122  AutoPtr<Gfx::Pen> _contour;
123  AutoPtr<Gfx::Color> _textColor;
124  Gfx::Font _customFont;
125  unsigned _fontOverride;
126 
127  FacetPtr<ProgressBarRenderer> _renderer;
128  bool _hasRenderer;
129 
130  Gfx::Brush _backgroundBrush;
131  Gfx::Brush _foregroundBrush;
132  Gfx::Pen _contourPen;
133  Gfx::Pen _textPen;
134  Gfx::Font _font;
135 };
136 
137 } // namespace
138 
139 } // namespace
140 
141 #endif