terminalgui  0.1.0
Widgets for your terminal, powered by Qt! Create textual GUI (TUI) in your console easily.
tgbutton.h
1 #pragma once
2 
3 #include <widgets/tglabel.h>
4 
5 #include <QTimer>
6 
7 namespace Tg {
8 class Button : public Label
9 {
10  Q_OBJECT
11 
12  Q_PROPERTY(Tg::Color activeTextColor READ activeTextColor WRITE setActiveTextColor NOTIFY activeTextColorChanged)
13  Q_PROPERTY(Tg::Color activeBackgroundColor READ activeBackgroundColor WRITE setActiveBackgroundColor NOTIFY activeBackgroundColorChanged)
14 
15  Q_PROPERTY(Tg::Color inactiveTextColor READ inactiveTextColor WRITE setInactiveTextColor NOTIFY inactiveTextColorChanged)
16  Q_PROPERTY(Tg::Color inactiveBackgroundColor READ inactiveBackgroundColor WRITE setInactiveBackgroundColor NOTIFY inactiveBackgroundColorChanged)
17 
18  Q_PROPERTY(Tg::Color pressedTextColor READ pressedTextColor WRITE setPressedTextColor NOTIFY pressedTextColorChanged)
19  Q_PROPERTY(Tg::Color pressedBackgroundColor READ pressedBackgroundColor WRITE setPressedBackgroundColor NOTIFY pressedBackgroundColorChanged)
20 
21 public:
22  Button(Widget *parent);
24  Button(const QString &text = QString(), Widget *parent = nullptr);
25  Button(const QString &text = QString(), Screen *screen = nullptr);
26 
27  Tg::Color activeTextColor() const;
28  Tg::Color activeBackgroundColor() const;
29  Tg::Color inactiveTextColor() const;
30  Tg::Color inactiveBackgroundColor() const;
31  Tg::Color pressedTextColor() const;
32  Tg::Color pressedBackgroundColor() const;
33 
34  void click();
35 
36 public slots:
37  void setActiveTextColor(const Tg::Color &activeTextColor);
38  void setActiveBackgroundColor(const Tg::Color &activeBackgroundColor);
39  void setInactiveTextColor(const Tg::Color &inactiveTextColor);
40  void setInactiveBackgroundColor(const Tg::Color &inactiveBackgroundColor);
41  void setPressedTextColor(const Tg::Color &pressedTextColor);
42  void setPressedBackgroundColor(const Tg::Color &pressedBackgroundColor);
43 
44 signals:
45  void clicked() const;
46 
47  void activeTextColorChanged(const Tg::Color &activeTextColor) const;
48  void activeBackgroundColorChanged(const Tg::Color &activeBackgroundColor) const;
49  void inactiveTextColorChanged(const Tg::Color &inactiveTextColor) const;
50  void inactiveBackgroundColorChanged(const Tg::Color &inactiveBackgroundColor) const;
51  void pressedTextColorChanged(const Tg::Color &pressedTextColor) const;
52  void pressedBackgroundColorChanged(const Tg::Color &pressedBackgroundColor) const;
53 
54 protected:
55  void init() override;
56  void consumeKeyboardBuffer(const QString &keyboardBuffer) override;
57 
58 protected slots:
59  void onButtonPressTimeout();
60  void onHasFocusChanged();
61 
62 private:
63  QTimer _buttonPressTimer;
64  Tg::Color _activeTextColor;
65  Tg::Color _activeBackgroundColor;
66  Tg::Color _inactiveTextColor;
67  Tg::Color _inactiveBackgroundColor;
68  Tg::Color _pressedTextColor;
69  Tg::Color _pressedBackgroundColor;
70 };
71 }
Tg::Screen
Screen is the "canvas" on which widgets (subclasses of Widget) are drawn.
Definition: tgscreen.h:31
Tg::Button::consumeKeyboardBuffer
void consumeKeyboardBuffer(const QString &keyboardBuffer) override
Called when Widget accepts focus and keyboardBuffer is not empty.
Definition: tgbutton.cpp:183
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::Widget::screen
Screen * screen() const
Returns the Screen on which this Widget is being drawn.
Definition: tgwidget.cpp:174
Tg::Label
Definition: tglabel.h:7
Tg::Button::init
void init() override
Initializes Widget and it's connections.
Definition: tgbutton.cpp:143
Tg::Button
Definition: tgbutton.h:9