terminalgui  0.1.0
Widgets for your terminal, powered by Qt! Create textual GUI (TUI) in your console easily.
tgscrollbar.h
1 #pragma once
2 
3 #include <widgets/tgwidget.h>
4 
5 #include <QChar>
6 #include <QString>
7 #include <QTimer>
8 
9 namespace Tg {
10 class ScrollBar : public Widget
11 {
12  Q_OBJECT
13 
14  Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
15 
16  // Slider
17  Q_PROPERTY(int minimum READ minimum WRITE setMinimum NOTIFY minimumChanged)
18  Q_PROPERTY(int maximum READ maximum WRITE setMaximum NOTIFY maximumChanged)
19  Q_PROPERTY(QString sliderCharacter READ sliderCharacter WRITE setSliderCharacter NOTIFY sliderCharacterChanged)
20  Q_PROPERTY(Tg::Color sliderColor READ sliderColor WRITE setSliderColor NOTIFY sliderColorChanged)
21  Q_PROPERTY(Tg::Color sliderActiveColor READ sliderActiveColor WRITE setSliderActiveColor NOTIFY sliderActiveColorChanged)
22  Q_PROPERTY(Tg::Color sliderInactiveColor READ sliderInactiveColor WRITE setSliderInactiveColor NOTIFY sliderInactiveColorChanged)
23 
24  Q_PROPERTY(Tg::Color sliderBackgroundColor READ sliderBackgroundColor WRITE setSliderBackgroundColor NOTIFY sliderBackgroundColorChanged)
25  Q_PROPERTY(Tg::Color sliderActiveBackgroundColor READ sliderActiveBackgroundColor WRITE setSliderActiveBackgroundColor NOTIFY sliderActiveBackgroundColorChanged)
26  Q_PROPERTY(Tg::Color sliderInactiveBackgroundColor READ sliderInactiveBackgroundColor WRITE setSliderInactiveBackgroundColor NOTIFY sliderInactiveBackgroundColorChanged)
27 
28  // Backward arrow (up or left)
29  Q_PROPERTY(QString backwardArrowUpCharacter READ backwardArrowUpCharacter WRITE setBackwardArrowUpCharacter NOTIFY backwardArrowUpCharacterChanged)
30  Q_PROPERTY(QString backwardArrowLeftCharacter READ backwardArrowLeftCharacter WRITE setBackwardArrowLeftCharacter NOTIFY backwardArrowLeftCharacterChanged)
31 
32  Q_PROPERTY(Tg::Color backwardArrowColor READ backwardArrowColor WRITE setBackwardArrowColor NOTIFY backwardArrowColorChanged)
33  Q_PROPERTY(Tg::Color backwardArrowActiveColor READ backwardArrowActiveColor WRITE setBackwardArrowActiveColor NOTIFY backwardArrowActiveColorChanged)
34  Q_PROPERTY(Tg::Color backwardArrowInactiveColor READ backwardArrowInactiveColor WRITE setBackwardArrowInactiveColor NOTIFY backwardArrowInactiveColorChanged)
35 
36  Q_PROPERTY(Tg::Color backwardArrowBackgroundColor READ backwardArrowBackgroundColor WRITE setBackwardArrowBackgroundColor NOTIFY backwardArrowColorBackgroundChanged)
37  Q_PROPERTY(Tg::Color backwardArrowActiveBackgroundColor READ backwardArrowActiveBackgroundColor WRITE setBackwardArrowActiveBackgroundColor NOTIFY backwardArrowActiveColorBackgroundChanged)
38  Q_PROPERTY(Tg::Color backwardArrowInactiveBackgroundColor READ backwardArrowInactiveBackgroundColor WRITE setBackwardArrowInactiveBackgroundColor NOTIFY backwardArrowInactiveColorBackgroundChanged)
39 
40  // Forward arrow (down or right)
41  Q_PROPERTY(QString forwardArrowDownCharacter READ forwardArrowDownCharacter WRITE setForwardArrowDownCharacter NOTIFY forwardArrowDownCharacterChanged)
42  Q_PROPERTY(QString forwardArrowRightCharacter READ forwardArrowRightCharacter WRITE setForwardArrowRightCharacter NOTIFY forwardArrowRightCharacterChanged)
43 
44  Q_PROPERTY(Tg::Color forwardArrowColor READ forwardArrowColor WRITE setForwardArrowColor NOTIFY forwardArrowColorChanged)
45  Q_PROPERTY(Tg::Color forwardArrowActiveColor READ forwardArrowActiveColor WRITE setForwardArrowActiveColor NOTIFY forwardArrowActiveColorChanged)
46  Q_PROPERTY(Tg::Color forwardArrowInactiveColor READ forwardArrowInactiveColor WRITE setForwardArrowInactiveColor NOTIFY forwardArrowInactiveColorChanged)
47 
48  Q_PROPERTY(Tg::Color forwardArrowBackgroundColor READ forwardArrowBackgroundColor WRITE setForwardArrowBackgroundColor NOTIFY forwardArrowColorBackgroundChanged)
49  Q_PROPERTY(Tg::Color forwardArrowActiveBackgroundColor READ forwardArrowActiveBackgroundColor WRITE setForwardArrowActiveBackgroundColor NOTIFY forwardArrowActiveColorBackgroundChanged)
50  Q_PROPERTY(Tg::Color forwardArrowInactiveBackgroundColor READ forwardArrowInactiveBackgroundColor WRITE setForwardArrowInactiveBackgroundColor NOTIFY forwardArrowInactiveColorBackgroundChanged)
51 
52  friend class ScrollArea;
53 
54 public:
55  ScrollBar(Widget *parent);
57 
58  Qt::Orientation orientation() const;
59 
60  int length() const;
61  int step() const;
62 
63  int minimum() const;
64  int maximum() const;
65  int sliderPosition() const;
66  QString sliderCharacter() const;
67  Tg::Color sliderColor() const;
68  Tg::Color sliderActiveColor() const;
69  Tg::Color sliderInactiveColor() const;
70  Tg::Color sliderBackgroundColor() const;
71  Tg::Color sliderActiveBackgroundColor() const;
72  Tg::Color sliderInactiveBackgroundColor() const;
73 
74  QString backwardArrowUpCharacter() const;
75  QString backwardArrowLeftCharacter() const;
76  Tg::Color backwardArrowColor() const;
77  Tg::Color backwardArrowActiveColor() const;
78  Tg::Color backwardArrowInactiveColor() const;
79  Tg::Color backwardArrowBackgroundColor() const;
80  Tg::Color backwardArrowActiveBackgroundColor() const;
81  Tg::Color backwardArrowInactiveBackgroundColor() const;
82 
83  QString forwardArrowDownCharacter() const;
84  QString forwardArrowRightCharacter() const;
85  Tg::Color forwardArrowColor() const;
86  Tg::Color forwardArrowActiveColor() const;
87  Tg::Color forwardArrowInactiveColor() const;
88  Tg::Color forwardArrowBackgroundColor() const;
89  Tg::Color forwardArrowActiveBackgroundColor() const;
90  Tg::Color forwardArrowInactiveBackgroundColor() const;
91 
92 public slots:
93  void setOrientation(const Qt::Orientation orientation);
94 
95  void setMinimum(const int minimum);
96  void setMaximum(const int maximum);
97  void setValue(const int value);
98  void setSliderPosition(const int sliderPosition);
99  void setSliderCharacter(const QString &sliderCharacter);
100  void setSliderColor(const Tg::Color &sliderColor);
101  void setSliderActiveColor(const Tg::Color &sliderActiveColor);
102  void setSliderInactiveColor(const Tg::Color &sliderInactiveColor);
103  void setSliderBackgroundColor(const Tg::Color &sliderBackgroundColor);
104  void setSliderActiveBackgroundColor(const Tg::Color &sliderActiveBackgroundColor);
105  void setSliderInactiveBackgroundColor(const Tg::Color &sliderInactiveBackgroundColor);
106 
107  void setBackwardArrowUpCharacter(const QString &backwardArrowUpCharacter);
108  void setBackwardArrowLeftCharacter(const QString &backwardArrowLeftCharacter);
109  void setBackwardArrowColor(const Tg::Color &backwardArrowColor);
110  void setBackwardArrowActiveColor(const Tg::Color &backwardArrowActiveColor);
111  void setBackwardArrowInactiveColor(const Tg::Color &backwardArrowInactiveColor);
112  void setBackwardArrowBackgroundColor(const Tg::Color &backwardArrowBackgroundColor);
113  void setBackwardArrowActiveBackgroundColor(const Tg::Color &backwardArrowActiveBackgroundColor);
114  void setBackwardArrowInactiveBackgroundColor(const Tg::Color &backwardArrowInactiveBackgroundColor);
115 
116  void setForwardArrowDownCharacter(const QString &forwardArrowDownCharacter);
117  void setForwardArrowRightCharacter(const QString &forwardArrowRightCharacter);
118  void setForwardArrowColor(const Tg::Color &forwardArrowColor);
119  void setForwardArrowActiveColor(const Tg::Color &forwardArrowActiveColor);
120  void setForwardArrowInactiveColor(const Tg::Color &forwardArrowInactiveColor);
121  void setForwardArrowBackgroundColor(const Tg::Color &forwardArrowBackgroundColor);
122  void setForwardArrowActiveBackgroundColor(const Tg::Color &forwardArrowActiveBackgroundColor);
123  void setForwardArrowInactiveBackgroundColor(const Tg::Color &forwardArrowInactiveBackgroundColor);
124 
125 signals:
126  void backwardArrowClicked() const;
127  void forwardArrowClicked() const;
128 
129  void orientationChanged(const Qt::Orientation orientation) const;
130 
131  void minimumChanged(const int minimum) const;
132  void maximumChanged(const int maximum) const;
133  void sliderPositionChanged(const int sliderPosition) const;
134  void sliderCharacterChanged(const QString &sliderCharacter) const;
135  void sliderColorChanged(const Tg::Color &sliderColor) const;
136  void sliderActiveColorChanged(const Tg::Color &sliderActiveColor) const;
137  void sliderInactiveColorChanged(const Tg::Color &sliderInactiveColor) const;
138  void sliderBackgroundColorChanged(const Tg::Color &sliderBackgroundColor) const;
139  void sliderActiveBackgroundColorChanged(const Tg::Color &sliderActiveBackgroundColor) const;
140  void sliderInactiveBackgroundColorChanged(const Tg::Color &sliderInactiveBackgroundColor) const;
141 
142  void backwardArrowUpCharacterChanged(const QString &backwardArrowUpCharacter) const;
143  void backwardArrowLeftCharacterChanged(const QString &backwardArrowLeftCharacter) const;
144  void backwardArrowColorChanged(const Tg::Color &backwardArrowColor) const;
145  void backwardArrowActiveColorChanged(const Tg::Color &backwardArrowActiveColor) const;
146  void backwardArrowInactiveColorChanged(const Tg::Color &backwardArrowInactiveColor) const;
147  void backwardArrowColorBackgroundChanged(const Tg::Color &backwardArrowBackgroundColor) const;
148  void backwardArrowActiveColorBackgroundChanged(const Tg::Color &backwardArrowActiveBackgroundColor) const;
149  void backwardArrowInactiveColorBackgroundChanged(const Tg::Color &backwardArrowInactiveBackgroundColor) const;
150 
151  void forwardArrowDownCharacterChanged(const QString &forwardArrowDownCharacter) const;
152  void forwardArrowRightCharacterChanged(const QString &forwardArrowRightCharacter) const;
153  void forwardArrowColorChanged(const Tg::Color &forwardArrowColor) const;
154  void forwardArrowActiveColorChanged(const Tg::Color &forwardArrowActiveColor) const;
155  void forwardArrowInactiveColorChanged(const Tg::Color &forwardArrowInactiveColor) const;
156  void forwardArrowColorBackgroundChanged(const Tg::Color &forwardArrowBackgroundColor) const;
157  void forwardArrowActiveColorBackgroundChanged(const Tg::Color &forwardArrowActiveBackgroundColor) const;
158  void forwardArrowInactiveColorBackgroundChanged(const Tg::Color &forwardArrowInactiveBackgroundColor) const;
159 
160 protected slots:
161  void enforceProperSize();
162 
163 protected:
164  void init() override;
165  void consumeKeyboardBuffer(const QString &keyboardBuffer) override;
166  QString drawPixel(const QPoint &pixel) const override;
167  QString linearPixel(const int pixel, const int length) const;
168 
169 private:
170  Qt::Orientation _orientation = Qt::Orientation::Vertical;
171 
172  int _minimum = 0;
173  int _maximum = 100;
174  int _sliderPosition = 3;
175  QString _sliderCharacter;
176  Tg::Color _sliderColor;
177  Tg::Color _sliderActiveColor;
178  Tg::Color _sliderInactiveColor;
179  Tg::Color _sliderBackgroundColor;
180  Tg::Color _sliderActiveBackgroundColor;
181  Tg::Color _sliderInactiveBackgroundColor;
182  QTimer _sliderPressTimer;
183 
184  QString _backwardArrowUpCharacter;
185  QString _backwardArrowLeftCharacter;
186  Tg::Color _backwardArrowColor;
187  Tg::Color _backwardArrowActiveColor;
188  Tg::Color _backwardArrowInactiveColor;
189  Tg::Color _backwardArrowBackgroundColor;
190  Tg::Color _backwardArrowActiveBackgroundColor;
191  Tg::Color _backwardArrowInactiveBackgroundColor;
192  QTimer _backwardArrowPressTimer;
193 
194  QString _forwardArrowDownCharacter;
195  QString _forwardArrowRightCharacter;
196  Tg::Color _forwardArrowColor;
197  Tg::Color _forwardArrowActiveColor;
198  Tg::Color _forwardArrowInactiveColor;
199  Tg::Color _forwardArrowBackgroundColor;
200  Tg::Color _forwardArrowActiveBackgroundColor;
201  Tg::Color _forwardArrowInactiveBackgroundColor;
202  QTimer _forwardArrowPressTimer;
203 };
204 }
Tg::Screen
Screen is the "canvas" on which widgets (subclasses of Widget) are drawn.
Definition: tgscreen.h:31
Tg
All Terminal GUI classes (both core and widgets) are defined within the Tg namespace.
Definition: tgcolor.h:6
Tg::Widget
Base class for all widgets in a Terminal Gui application.
Definition: tgwidget.h:64
Tg::Color
Represents colors in a terminal.
Definition: tgcolor.h:20
Tg::ScrollBar::consumeKeyboardBuffer
void consumeKeyboardBuffer(const QString &keyboardBuffer) override
Called when Widget accepts focus and keyboardBuffer is not empty.
Definition: tgscrollbar.cpp:613
Tg::Widget::screen
Screen * screen() const
Returns the Screen on which this Widget is being drawn.
Definition: tgwidget.cpp:174
Tg::ScrollBar::step
int step() const
How much to add or remove from value (sliderPosition()) to move the slider by a single pixel (charact...
Definition: tgscrollbar.cpp:54
Tg::ScrollArea
Definition: tgscrollarea.h:11
Tg::ScrollBar::drawPixel
QString drawPixel(const QPoint &pixel) const override
Returns ANSI-encoded string, used by Screen to draw the pixel.
Definition: tgscrollbar.cpp:16
Tg::ScrollBar::init
void init() override
Initializes Widget and it's connections.
Definition: tgscrollbar.cpp:534
Tg::ScrollBar
Definition: tgscrollbar.h:11