1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2013 Santeri Piippo |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
6 * it under the terms of the GNU General Public License as published by |
|
7 * the Free Software Foundation, either version 3 of the License, or |
|
8 * (at your option) any later version. |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
17 */ |
|
18 |
|
19 #ifndef RADIOBOX_H |
|
20 #define RADIOBOX_H |
|
21 |
|
22 #include "common.h" |
|
23 #include <qwidget.h> |
|
24 #include <QGroupBox> |
|
25 #include <qradiobutton.h> |
|
26 #include <qboxlayout.h> |
|
27 #include <qbuttongroup.h> |
|
28 |
|
29 // ============================================================================= |
|
30 // RadioBox |
|
31 // |
|
32 // Convenience widget - is a groupbox of radio buttons. |
|
33 // ============================================================================= |
|
34 class RadioBox : public QGroupBox { |
|
35 Q_OBJECT |
|
36 |
|
37 public: |
|
38 void init (Qt::Orientation orient); |
|
39 |
|
40 explicit RadioBox (QWidget* parent = null) : QGroupBox (parent) { |
|
41 init (Qt::Vertical); |
|
42 } |
|
43 |
|
44 explicit RadioBox (const QString& title, QWidget* parent = null) : QGroupBox (title, parent) { |
|
45 init (Qt::Vertical); |
|
46 } |
|
47 |
|
48 explicit RadioBox () { |
|
49 init (Qt::Vertical); |
|
50 } |
|
51 |
|
52 explicit RadioBox (const QString& title, initlist<char const*> entries, int const defaultId, |
|
53 const Qt::Orientation orient = Qt::Vertical, QWidget* parent = null); |
|
54 |
|
55 void rowBreak (); |
|
56 void setCurrentRow (uint row); |
|
57 void addButton (const char* entry); |
|
58 void addButton (QRadioButton* button); |
|
59 RadioBox& operator<< (QRadioButton* button); |
|
60 RadioBox& operator<< (const char* entry); |
|
61 |
|
62 int value () const { |
|
63 return buttonGroup->checkedId (); |
|
64 } |
|
65 |
|
66 void setValue (int val) { |
|
67 buttonGroup->button (val)->setChecked (true); |
|
68 } |
|
69 |
|
70 std::vector<QRadioButton*>::iterator begin () { |
|
71 return objects.begin (); |
|
72 } |
|
73 |
|
74 std::vector<QRadioButton*>::iterator end () { |
|
75 return objects.end (); |
|
76 } |
|
77 |
|
78 QRadioButton* operator[] (uint n) const { |
|
79 return objects[n]; |
|
80 } |
|
81 |
|
82 bool exclusive () const { |
|
83 return buttonGroup->exclusive (); |
|
84 } |
|
85 |
|
86 void setExclusive (bool val) { |
|
87 buttonGroup->setExclusive (val); |
|
88 } |
|
89 |
|
90 bool isChecked (int n) const { |
|
91 return buttonGroup->checkedId () == n; |
|
92 } |
|
93 |
|
94 signals: |
|
95 void sig_buttonPressed (int btn); |
|
96 void sig_buttonPressed (QAbstractButton* btn); |
|
97 |
|
98 private: |
|
99 std::vector<QRadioButton*> objects; |
|
100 std::vector<QBoxLayout*> layouts; |
|
101 QBoxLayout* coreLayout; |
|
102 QBoxLayout* currentLayout; |
|
103 QBoxLayout::Direction dir; |
|
104 int currentId; |
|
105 int defaultId; |
|
106 QButtonGroup* buttonGroup; |
|
107 |
|
108 Q_DISABLE_COPY (RadioBox) |
|
109 |
|
110 private slots: |
|
111 void slot_buttonPressed (int btn); |
|
112 void slot_buttonPressed (QAbstractButton* btn); |
|
113 }; |
|
114 |
|
115 #endif // RADIOBOX_H |
|