radiobox.h

Sat, 04 May 2013 02:52:33 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 04 May 2013 02:52:33 +0300
changeset 157
635da3135bd4
permissions
-rw-r--r--

Un-templated ButtonBox and renamed to RadioBox. Much better this way.

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

mercurial