]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQMultiSelectionBox.h
one signal left and qmultiselectionbox compiles
[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 <QTreeWidget>
26
27 #include "YMultiSelectionBox.h"
28
29 class YQWidgetCaption;
30 class YQMultiSelectionBoxItem;
31
32
33 class YQMultiSelectionBox : public QFrame, public YMultiSelectionBox
34 {
35     Q_OBJECT
36
37 public:
38
39     /**
40      * Constructor.
41      **/
42     YQMultiSelectionBox( YWidget * parent, const string & label );
43
44     /**
45      * Destructor.
46      **/
47     ~YQMultiSelectionBox();
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      * Return the the item that currently has the keyboard focus
86      * or 0 if no item currently has the keyboard focus.
87      *
88      * Reimplemented from YMultiSelectionBox.
89      **/
90     virtual YItem * currentItem();
91
92     /**
93      * Set the keyboard focus to the specified item.
94      * 0 means clear the keyboard focus.
95      *
96      * Reimplemented from YMultiSelectionBox.
97      **/
98     virtual void setCurrentItem( YItem * item );
99
100     /**
101      * Set enabled/disabled state.
102      *
103      * Reimplemented from YWidget.
104      **/
105     virtual void setEnabled( bool enabled );
106
107     /**
108      * Preferred width of the widget.
109      *
110      * Reimplemented from YWidget.
111      **/
112     virtual int preferredWidth();
113
114     /**
115      * Preferred height of the widget.
116      *
117      * Reimplemented from YWidget.
118      **/
119     virtual int preferredHeight();
120
121     /**
122      * Set the new size of the widget.
123      *
124      * Reimplemented from YWidget.
125      **/
126     virtual void setSize( int newWidth, int newHeight );
127
128     /**
129      * Accept the keyboard focus.
130      **/
131     virtual bool setKeyboardFocus();
132
133     /**
134      * Sends a ValueChanged signal.
135      **/
136     void sendValueChanged();
137
138
139 signals:
140     /**
141      * Emitted upon when an item changes its state.
142      **/
143     void valueChanged();
144
145
146 protected slots:
147     /**
148      * Send SelectionChanged event if `opt(`notify) is set.
149      **/
150     void slotSelected();
151
152     /**
153      * Send ValueChanged event if `opt(`notify) is set.
154      **/
155     void slotValueChanged();
156
157
158 protected:
159     /**
160      * Find the counterpart of 'item'. Return 0 if there is none.
161      **/
162     YQMultiSelectionBoxItem * findItem( YItem * item );
163
164
165     YQWidgetCaption *   _caption;
166     QTreeWidget *       _qt_listView;
167 };
168
169
170
171 class YQMultiSelectionBoxItem: public QTreeWidgetItem
172 {
173 public:
174     /**
175      * Constructor.
176      **/
177     YQMultiSelectionBoxItem( YQMultiSelectionBox *      parent,
178                              QTreeWidget *              listView,
179                              YItem *                    yItem );
180
181     /**
182      * Destructor.
183      **/
184     virtual ~YQMultiSelectionBoxItem() {}
185
186     /**
187      * Return the corresponding YItem.
188      **/
189     YItem * yItem() const { return _yItem; }
190
191
192 protected:
193
194     /**
195      * Called when the on/off state changes.
196      * Triggers a 'valueChanged' event in the associated YQMultiSelectionBox.
197      *
198      * Reimplemented from QChecklistItem.
199      **/
200     void stateChange( bool newState );
201
202     /**
203      * Returns the sort key for any column.
204      * In this case, maintain item creation order.
205      *
206      * Reimplemented from Q3ListViewItem.
207      **/
208     virtual QString key ( int   column,
209                           bool  ascending ) const;
210
211     //
212     // Data members
213     //
214
215     YItem *                     _yItem;
216     int                         _serial;
217     YQMultiSelectionBox *       _multiSelectionBox;
218
219
220     /**
221      * The next serial number to use
222      **/
223     static int _item_count;
224 };
225
226 #endif // YQLabel_h