src/radiobox.h

changeset 202
a027f6fc6141
parent 201
4d620d819f4f
child 203
ccde5e88f0b6
equal deleted inserted replaced
201:4d620d819f4f 202:a027f6fc6141
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 m_buttonGroup->checkedId ();
64 }
65
66 void setValue (int val) {
67 m_buttonGroup->button (val)->setChecked (true);
68 }
69
70 std::vector<QRadioButton*>::iterator begin () {
71 return m_objects.begin ();
72 }
73
74 std::vector<QRadioButton*>::iterator end () {
75 return m_objects.end ();
76 }
77
78 QRadioButton* operator[] (uint n) const {
79 return m_objects[n];
80 }
81
82 bool exclusive () const {
83 return m_buttonGroup->exclusive ();
84 }
85
86 void setExclusive (bool val) {
87 m_buttonGroup->setExclusive (val);
88 }
89
90 bool isChecked (int n) const {
91 return m_buttonGroup->checkedId () == n;
92 }
93
94 signals:
95 void sig_buttonPressed (int btn);
96 void buttonReleased (int btn);
97 void valueChanged (int val);
98
99 private:
100 std::vector<QRadioButton*> m_objects;
101 std::vector<QBoxLayout*> m_layouts;
102 QBoxLayout* m_coreLayout;
103 QBoxLayout* m_currentLayout;
104 QBoxLayout::Direction m_dir;
105 int m_curId, m_defId, m_oldId;
106 QButtonGroup* m_buttonGroup;
107
108 Q_DISABLE_COPY (RadioBox)
109
110 private slots:
111 void slot_buttonPressed (int btn);
112 void slot_buttonReleased (int btn);
113 };
114
115 #endif // RADIOBOX_H

mercurial