- Don't create layouts with parent. Qt 4.x automatically reparents
[duncan/yast2-qt4.git] / src / YQSelectionBox.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQSelectionBox.h
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #ifndef YQSelectionBox_h
21 #define YQSelectionBox_h
22
23 #include <QFrame>
24 #include <QTimer>
25
26 #include "YSelectionBox.h"
27
28 class YQWidgetCaption;
29 class QListWidget;
30 class QListWidgetItem;
31
32
33 class YQSelectionBox : public QFrame, public YSelectionBox
34 {
35     Q_OBJECT
36
37 public:
38
39     /**
40      * Constructor.
41      **/
42     YQSelectionBox( YWidget * parent, const string & label );
43
44     /**
45      * Destructor.
46      **/
47     virtual ~YQSelectionBox();
48
49     /**
50      * Change the label text.
51      *
52      * Reimplemented from YSelectionWidget.
53      **/
54     virtual void setLabel( const string & label );
55
56     /**
57      * Add an item.
58      *
59      * Reimplemented from YSelectionWidget.
60      **/
61     virtual void addItem( YItem * item );
62
63     /**
64      * Select or deselect an item.
65      *
66      * Reimplemented from YSelectionWidget.
67      **/
68     virtual void selectItem( YItem * item, bool selected = true );
69
70     /**
71      * Deselect all items.
72      *
73      * Reimplemented from YSelectionWidget.
74      **/
75     virtual void deselectAllItems();
76
77     /**
78      * Delete all items.
79      *
80      * Reimplemented from YSelectionWidget.
81      **/
82     virtual void deleteAllItems();
83
84     /**
85      * Set enabled/disabled state.
86      *
87      * Reimplemented from YWidget.
88      **/
89     virtual void setEnabled( bool enabled );
90
91     /**
92      * Preferred width of the widget.
93      *
94      * Reimplemented from YWidget.
95      **/
96     virtual int preferredWidth();
97
98     /**
99      * Preferred height of the widget.
100      *
101      * Reimplemented from YWidget.
102      **/
103     virtual int preferredHeight();
104
105     /**
106      * Set the new size of the widget.
107      *
108      * Reimplemented from YWidget.
109      **/
110     virtual void setSize( int newWidth, int newHeight );
111
112     /**
113      * Accept the keyboard focus.
114      *
115      * Reimplemented from YWidget.
116      **/
117     virtual bool setKeyboardFocus();
118
119     /**
120      * Event filter.
121      *
122      * Reimplemented from QWidget.
123      **/
124     virtual bool eventFilter( QObject * obj, QEvent * ev );
125
126
127 protected slots:
128
129     /**
130      * Notification that an item has been selected.
131      * This is only relevant if `opt(`notify ) is set.
132      **/
133     void slotSelectionChanged();
134
135     /**
136      * Notification that an item has been activated (double clicked).
137      **/
138     void slotActivated( QListWidgetItem * item );
139
140     /**
141      * Return after some millseconds delay - collect multiple events.
142      * This is only relevant if `opt( `notify ) is set.
143      **/
144     void returnDelayed();
145
146     /**
147      * Return immediately.
148      * This is only relevant if `opt( `notify ) is set.
149      **/
150     void returnImmediately();
151
152
153 protected:
154
155     /**
156      * Select an item by index.
157      **/
158     void selectItem( int index );
159
160
161     //
162     // Data members
163     //
164
165     YQWidgetCaption *   _caption;
166     QListWidget *               _qt_listBox;
167     QTimer              _timer;
168 };
169
170 #endif // YQLabel_h