|
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 WIDGETS_H |
|
20 #define WIDGETS_H |
|
21 |
|
22 #include <QGroupBox> |
|
23 #include <map> |
|
24 #include "common.h" |
|
25 #include "types.h" |
|
26 |
|
27 class QCheckBox; |
|
28 class QButtonGroup; |
|
29 class QBoxLayout; |
|
30 class QRadioButton; |
|
31 |
|
32 // ============================================================================= |
|
33 // RadioBox |
|
34 // |
|
35 // Convenience widget - is a groupbox of radio buttons. |
|
36 // ============================================================================= |
|
37 class RadioBox : public QGroupBox { |
|
38 Q_OBJECT |
|
39 |
|
40 public: |
|
41 typedef std::vector<QRadioButton*>::iterator iter; |
|
42 |
|
43 explicit RadioBox (QWidget* parent = null) : QGroupBox (parent) { init (Qt::Vertical); } |
|
44 explicit RadioBox () { init (Qt::Vertical); } |
|
45 explicit RadioBox (const QString& title, QWidget* parent = null); |
|
46 explicit RadioBox (const QString& title, initlist<char const*> entries, int const defaultId, |
|
47 const Qt::Orientation orient = Qt::Vertical, QWidget* parent = null); |
|
48 |
|
49 void addButton (const char* entry); |
|
50 void addButton (QRadioButton* button); |
|
51 iter begin (); |
|
52 iter end (); |
|
53 void init (Qt::Orientation orient); |
|
54 bool isChecked (int n) const; |
|
55 void rowBreak (); |
|
56 void setCurrentRow (uint row); |
|
57 void setValue (int val); |
|
58 int value () const; |
|
59 |
|
60 QRadioButton* operator[] (uint n) const; |
|
61 RadioBox& operator<< (QRadioButton* button); |
|
62 RadioBox& operator<< (const char* entry); |
|
63 |
|
64 signals: |
|
65 void buttonPressed (int btn); |
|
66 void buttonReleased (int btn); |
|
67 void valueChanged (int val); |
|
68 |
|
69 private: |
|
70 std::vector<QRadioButton*> m_objects; |
|
71 std::vector<QBoxLayout*> m_layouts; |
|
72 QBoxLayout* m_coreLayout; |
|
73 QBoxLayout* m_currentLayout; |
|
74 bool m_vert; |
|
75 int m_curId, m_defId, m_oldId; |
|
76 QButtonGroup* m_buttonGroup; |
|
77 |
|
78 Q_DISABLE_COPY (RadioBox) |
|
79 |
|
80 private slots: |
|
81 void slot_buttonPressed (int btn); |
|
82 void slot_buttonReleased (int btn); |
|
83 }; |
|
84 |
|
85 // ============================================================================= |
|
86 // CheckBoxGroup |
|
87 // ============================================================================= |
|
88 class CheckBoxGroup : public QGroupBox { |
|
89 Q_OBJECT |
|
90 |
|
91 public: |
|
92 CheckBoxGroup (const char* label, Qt::Orientation orient = Qt::Horizontal, QWidget* parent = null); |
|
93 |
|
94 void addCheckBox (const char* label, int key, bool checked = false); |
|
95 vector<int> checkedValues () const; |
|
96 QCheckBox* getCheckBox (int key); |
|
97 bool buttonChecked (int key); |
|
98 |
|
99 signals: |
|
100 void selectionChanged (); |
|
101 |
|
102 private: |
|
103 QBoxLayout* m_layout; |
|
104 std::map<int, QCheckBox*> m_vals; |
|
105 |
|
106 private slots: |
|
107 void buttonChanged (); |
|
108 }; |
|
109 |
|
110 #endif // WIDGETS_H |