src/labeledwidget.h

changeset 223
4f95d7f2e9ef
parent 198
f246725199dc
child 421
7d26db0be944
equal deleted inserted replaced
222:fddd36a6526c 223:4f95d7f2e9ef
17 */ 17 */
18 18
19 #ifndef LABELEDWIDGET_H 19 #ifndef LABELEDWIDGET_H
20 #define LABELEDWIDGET_H 20 #define LABELEDWIDGET_H
21 21
22 #include "common.h"
22 #include <QLabel> 23 #include <QLabel>
23 #include <QBoxLayout> 24 #include <QBoxLayout>
24 25
25 // ============================================================================= 26 // =============================================================================
26 // LabeledWidget 27 // LabeledWidget
27 // 28 //
28 // Convenience class for a widget with a label beside it. 29 // Convenience class for a widget with a label beside it.
29 // ============================================================================= 30 // =============================================================================
30 template<class R> class LabeledWidget : public QWidget { 31 template<class R> class LabeledWidget : public QWidget {
32 PROPERTY (QLabel*, label, setLabel)
33 PROPERTY (R*, widget, setWidget)
34
31 public: 35 public:
32 explicit LabeledWidget (const char* labelstr, QWidget* parent = null) : QWidget (parent) { 36 explicit LabeledWidget (const char* labelstr, QWidget* parent = null) : QWidget (parent) {
33 m_widget = new R (this); 37 m_widget = new R (this);
34 commonInit (labelstr); 38 commonInit (labelstr);
35 } 39 }
43 explicit LabeledWidget (QWidget* parent = 0, Qt::WindowFlags f = 0) { 47 explicit LabeledWidget (QWidget* parent = 0, Qt::WindowFlags f = 0) {
44 m_widget = new R (this); 48 m_widget = new R (this);
45 commonInit (""); 49 commonInit ("");
46 } 50 }
47 51
48 R* widget () const { return m_widget; }
49 R* w () const { return m_widget; } 52 R* w () const { return m_widget; }
50 QLabel* label () const { return m_label; }
51 QLabel* l () const { return m_label; }
52 void setWidget (R* widget) { m_widget = widget; }
53 void setLabel (QLabel* label) { m_label = label; }
54 operator R* () { return m_widget; } 53 operator R* () { return m_widget; }
55 54
56 private: 55 private:
57 Q_DISABLE_COPY (LabeledWidget<R>) 56 Q_DISABLE_COPY (LabeledWidget<R>)
58 57
62 m_layout->addWidget (m_label); 61 m_layout->addWidget (m_label);
63 m_layout->addWidget (m_widget); 62 m_layout->addWidget (m_widget);
64 setLayout (m_layout); 63 setLayout (m_layout);
65 } 64 }
66 65
67 R* m_widget;
68 QLabel* m_label;
69 QHBoxLayout* m_layout; 66 QHBoxLayout* m_layout;
70 }; 67 };
71 68
72 #endif // LABELEDWIDGET_H 69 #endif // LABELEDWIDGET_H

mercurial