]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQMultiSelectionBox.h
merge Huha's ydialog changes
[duncan/yast2-qt4.git] / src / YQMultiSelectionBox.h
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:       YQMultiSelectionBox.h
14
15   Author:     Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #ifndef YQMultiSelectionBox_h
21 #define YQMultiSelectionBox_h
22
23 #include <QFrame>
24 #include <QColorGroup>
25 #include <Q3CheckListItem>
26 #include <qlistview.h>
27
28 #include "YMultiSelectionBox.h"
29
30 class YQWidgetCaption;
31 class YQMultiSelectionBoxItem;
32
33
34 class YQMultiSelectionBox : public QFrame, public YMultiSelectionBox
35 {
36     Q_OBJECT
37
38 public:
39
40     /**
41      * Constructor.
42      **/
43     YQMultiSelectionBox( YWidget * parent, const string & label );
44
45     /**
46      * Destructor.
47      **/
48     ~YQMultiSelectionBox();
49
50     /**
51      * Change the label text.
52      *
53      * Reimplemented from YSelectionWidget.
54      **/
55     virtual void setLabel( const string & label );
56
57     /**
58      * Add an item.
59      *
60      * Reimplemented from YSelectionWidget.
61      **/
62     virtual void addItem( YItem * item );
63
64     /**
65      * Select or deselect an item.
66      *
67      * Reimplemented from YSelectionWidget.
68      **/
69     virtual void selectItem( YItem * item, bool selected = true );
70
71     /**
72      * Deselect all items.
73      *
74      * Reimplemented from YSelectionWidget.
75      **/
76     virtual void deselectAllItems();
77
78     /**
79      * Delete all items.
80      *
81      * Reimplemented from YSelectionWidget.
82      **/
83     virtual void deleteAllItems();
84
85     /**
86      * Return the the item that currently has the keyboard focus
87      * or 0 if no item currently has the keyboard focus.
88      *
89      * Reimplemented from YMultiSelectionBox.
90      **/
91     virtual YItem * currentItem();
92
93     /**
94      * Set the keyboard focus to the specified item.
95      * 0 means clear the keyboard focus.
96      *
97      * Reimplemented from YMultiSelectionBox.
98      **/
99     virtual void setCurrentItem( YItem * item );
100
101     /**
102      * Set enabled/disabled state.
103      *
104      * Reimplemented from YWidget.
105      **/
106     virtual void setEnabled( bool enabled );
107
108     /**
109      * Preferred width of the widget.
110      *
111      * Reimplemented from YWidget.
112      **/
113     virtual int preferredWidth();
114
115     /**
116      * Preferred height of the widget.
117      *
118      * Reimplemented from YWidget.
119      **/
120     virtual int preferredHeight();
121
122     /**
123      * Set the new size of the widget.
124      *
125      * Reimplemented from YWidget.
126      **/
127     virtual void setSize( int newWidth, int newHeight );
128
129     /**
130      * Accept the keyboard focus.
131      **/
132     virtual bool setKeyboardFocus();
133
134     /**
135      * Sends a ValueChanged signal.
136      **/
137     void sendValueChanged();
138
139
140 signals:
141     /**
142      * Emitted upon when an item changes its state.
143      **/
144     void valueChanged();
145
146
147 protected slots:
148     /**
149      * Send SelectionChanged event if `opt(`notify) is set.
150      **/
151     void slotSelected();
152
153     /**
154      * Send ValueChanged event if `opt(`notify) is set.
155      **/
156     void slotValueChanged();
157
158
159 protected:
160     /**
161      * Find the counterpart of 'item'. Return 0 if there is none.
162      **/
163     YQMultiSelectionBoxItem * findItem( YItem * item );
164
165
166     YQWidgetCaption *   _caption;
167     Q3ListView *        _qt_listView;
168 };
169
170
171
172 class YQMultiSelectionBoxItem: public Q3CheckListItem
173 {
174 public:
175     /**
176      * Constructor.
177      **/
178     YQMultiSelectionBoxItem( YQMultiSelectionBox *      parent,
179                              Q3ListView *               listView,
180                              YItem *                    yItem );
181
182     /**
183      * Destructor.
184      **/
185     virtual ~YQMultiSelectionBoxItem() {}
186
187     /**
188      * Return the corresponding YItem.
189      **/
190     YItem * yItem() const { return _yItem; }
191
192
193 protected:
194
195     /**
196      * Called when the on/off state changes.
197      * Triggers a 'valueChanged' event in the associated YQMultiSelectionBox.
198      *
199      * Reimplemented from QChecklistItem.
200      **/
201     void stateChange( bool newState );
202
203     /**
204      * Returns the sort key for any column.
205      * In this case, maintain item creation order.
206      *
207      * Reimplemented from Q3ListViewItem.
208      **/
209     virtual QString key ( int   column,
210                           bool  ascending ) const;
211
212     //
213     // Data members
214     //
215
216     YItem *                     _yItem;
217     int                         _serial;
218     YQMultiSelectionBox *       _multiSelectionBox;
219
220
221     /**
222      * The next serial number to use
223      **/
224     static int _item_count;
225 };
226
227 #endif // YQLabel_h