terminalgui  0.1.0
Widgets for your terminal, powered by Qt! Create textual GUI (TUI) in your console easily.
tgradiobutton.h
1 #pragma once
2 
3 #include <widgets/tgbutton.h>
4 
5 #include <QPointer>
6 #include <QSharedPointer>
7 
8 namespace Tg {
9 class RadioButton;
10 class ExclusiveGroup : public QObject
11 {
12  Q_OBJECT
13 
14 public:
16 
17  void registerRadioButton(RadioButton *radioButton);
18  void deRegisterRadioButton(RadioButton *radioButton);
19 
20 protected slots:
21  void onRadioButtonCheckedChanged(const bool checked);
22 
23 private:
24  QList<QPointer<RadioButton>> _members;
25 };
26 
27 using ExclusiveGroupPointer = QSharedPointer<ExclusiveGroup>;
28 
29 class RadioButton : public Button
30 {
31  Q_OBJECT
32 
33  Q_PROPERTY(bool checked READ checked WRITE setChecked NOTIFY checkedChanged)
34  Q_PROPERTY(bool autoExclusive READ autoExclusive WRITE setAutoExclusive NOTIFY autoExclusiveChanged)
35 
36 public:
37  RadioButton(Widget *parent);
39  RadioButton(const QString &text = QString(), Widget *parent = nullptr);
40  RadioButton(const QString &text = QString(), Screen *screen = nullptr);
41 
42  void toggleState();
43  bool checked() const;
44 
45  bool autoExclusive() const;
46  ExclusiveGroupPointer exclusiveGroup() const;
47 
48 public slots:
49  void setChecked(const bool checked);
50  void setAutoExclusive(const bool autoExclusive);
51 
52 signals:
53  void checkedChanged(const bool checked) const;
54  void autoExclusiveChanged(const bool autoExclusive) const;
55 
56 protected:
57  void init() override;
58  void consumeKeyboardBuffer(const QString &keyboardBuffer) override;
59  QString radioButtonText() const;
60 
61 private:
62  void prepareAutoExclusiveGroup();
63 
64  bool _checked = true;
65  bool _autoExclusive = true;
66  ExclusiveGroupPointer _group;
67 };
68 }
Tg::RadioButton::consumeKeyboardBuffer
void consumeKeyboardBuffer(const QString &keyboardBuffer) override
Called when Widget accepts focus and keyboardBuffer is not empty.
Definition: tgradiobutton.cpp:141
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::RadioButton
Definition: tgradiobutton.h:30
Tg::RadioButton::init
void init() override
Initializes Widget and it's connections.
Definition: tgradiobutton.cpp:129
Tg::Widget::screen
Screen * screen() const
Returns the Screen on which this Widget is being drawn.
Definition: tgwidget.cpp:174
Tg::ExclusiveGroup
Definition: tgradiobutton.h:11
Tg::Button
Definition: tgbutton.h:9