libyui-qt  2.47.1.1
YQSelectionBox.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQSelectionBox.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YQSelectionBox_h
27 #define YQSelectionBox_h
28 
29 #include <QFrame>
30 #include <QTimer>
31 
32 #include <yui/YSelectionBox.h>
33 
34 class YQWidgetCaption;
35 class QListWidget;
36 class QListWidgetItem;
37 
38 
39 class YQSelectionBox : public QFrame, public YSelectionBox
40 {
41  Q_OBJECT
42 
43 public:
44 
45  /**
46  * Constructor.
47  **/
48  YQSelectionBox( YWidget * parent, const std::string & label );
49 
50  /**
51  * Destructor.
52  **/
53  virtual ~YQSelectionBox();
54 
55  /**
56  * Change the label text.
57  *
58  * Reimplemented from YSelectionWidget.
59  **/
60  virtual void setLabel( const std::string & label );
61 
62  /**
63  * Add an item.
64  *
65  * Reimplemented from YSelectionWidget.
66  **/
67  virtual void addItem( YItem * item );
68 
69  /**
70  * Add multiple items.
71  *
72  * Reimplemented for efficiency from YSelectionWidget.
73  **/
74  virtual void addItems( const YItemCollection & itemCollection );
75 
76  /**
77  * Select or deselect an item.
78  *
79  * Reimplemented from YSelectionWidget.
80  **/
81  virtual void selectItem( YItem * item, bool selected = true );
82 
83  /**
84  * Deselect all items.
85  *
86  * Reimplemented from YSelectionWidget.
87  **/
88  virtual void deselectAllItems();
89 
90  /**
91  * Delete all items.
92  *
93  * Reimplemented from YSelectionWidget.
94  **/
95  virtual void deleteAllItems();
96 
97  /**
98  * Set enabled/disabled state.
99  *
100  * Reimplemented from YWidget.
101  **/
102  virtual void setEnabled( bool enabled );
103 
104  /**
105  * Preferred width of the widget.
106  *
107  * Reimplemented from YWidget.
108  **/
109  virtual int preferredWidth();
110 
111  /**
112  * Preferred height of the widget.
113  *
114  * Reimplemented from YWidget.
115  **/
116  virtual int preferredHeight();
117 
118  /**
119  * Set the new size of the widget.
120  *
121  * Reimplemented from YWidget.
122  **/
123  virtual void setSize( int newWidth, int newHeight );
124 
125  /**
126  * Accept the keyboard focus.
127  *
128  * Reimplemented from YWidget.
129  **/
130  virtual bool setKeyboardFocus();
131 
132  /**
133  * Event filter.
134  *
135  * Reimplemented from QWidget.
136  **/
137  virtual bool eventFilter( QObject * obj, QEvent * ev );
138 
139 
140 protected slots:
141 
142  /**
143  * Notification that an item has been selected.
144  * This is only relevant if `opt(`notify ) is set.
145  **/
146  void slotSelectionChanged();
147 
148  /**
149  * Notification that an item has been activated (double clicked).
150  **/
151  void slotActivated( QListWidgetItem * item );
152 
153  /**
154  * Return after some millseconds delay - collect multiple events.
155  * This is only relevant if `opt( `notify ) is set.
156  **/
157  void returnDelayed();
158 
159  /**
160  * Return immediately.
161  * This is only relevant if `opt( `notify ) is set.
162  **/
163  void returnImmediately();
164 
165 
166 protected:
167 
168  /**
169  * Select an item by index.
170  **/
171  void selectItem( int index );
172 
173  /**
174  * Internal addItem() method that will not do expensive operations in batch
175  * mode.
176  **/
177  void addItem( YItem * item, bool batchMode );
178 
179 
180  //
181  // Data members
182  //
183 
184  YQWidgetCaption * _caption;
185  QListWidget * _qt_listWidget;
186  QTimer _timer;
187 };
188 
189 #endif // YQLabel_h
virtual bool eventFilter(QObject *obj, QEvent *ev)
Event filter.
virtual void deleteAllItems()
Delete all items.
virtual bool setKeyboardFocus()
Accept the keyboard focus.
virtual void addItems(const YItemCollection &itemCollection)
Add multiple items.
void slotActivated(QListWidgetItem *item)
Notification that an item has been activated (double clicked).
virtual void addItem(YItem *item)
Add an item.
YQSelectionBox(YWidget *parent, const std::string &label)
Constructor.
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
void returnDelayed()
Return after some millseconds delay - collect multiple events.
virtual void deselectAllItems()
Deselect all items.
virtual int preferredWidth()
Preferred width of the widget.
virtual int preferredHeight()
Preferred height of the widget.
virtual ~YQSelectionBox()
Destructor.
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
virtual void selectItem(YItem *item, bool selected=true)
Select or deselect an item.
void slotSelectionChanged()
Notification that an item has been selected.
Helper class for captions (labels) above a widget: Takes care of hiding itself when its text is empty...
virtual void setLabel(const std::string &label)
Change the label text.
void returnImmediately()
Return immediately.