libyui-qt
YQItemSelector.h
1 /*
2  Copyright (C) 2019 SUSE LLC
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: YQItemSelector.h
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YQItemSelector_h
27 #define YQItemSelector_h
28 
29 #include <QScrollArea>
30 #include <QMap>
31 
32 #include <yui/YItemSelector.h>
33 
34 class QScrollArea;
35 class QHBoxLayout;
36 class QVBoxLayout;
37 class QButtonGroup;
38 class QLabel;
40 
41 
42 class YQItemSelector: public QScrollArea, public YItemSelector
43 {
44  Q_OBJECT
45 
46 public:
47 
51  YQItemSelector( YWidget * parent,
52  bool enforceSingleSelection = true );
53 
54 public:
55 
59  virtual ~YQItemSelector();
60 
66  virtual void addItem( YItem * item );
67 
73  virtual void addItems( const YItemCollection & itemCollection );
74 
80  virtual void selectItem( YItem * item, bool selected = true );
81 
87  virtual void deselectAllItems();
88 
94  virtual void deleteAllItems();
95 
101  virtual void setEnabled( bool enabled );
102 
108  virtual int preferredWidth();
109 
115  virtual int preferredHeight();
116 
122  virtual void setSize( int newWidth, int newHeight );
123 
129  virtual bool setKeyboardFocus();
130 
134  QWidget * itemContainer() const { return _itemContainer; }
135 
140  QButtonGroup * buttonGroup() const { return _buttonGroup; }
141 
146  void addItemWidget( YQSelectorItemWidget * itemWidget );
147 
153  virtual void activateItem( YItem * item );
154 
160  virtual void shortcutChanged();
161 
162 protected slots:
163 
168  void slotSelectionChanged( YQSelectorItemWidget * itemWidget,
169  bool selected );
170 
171 
172 
173 protected:
174 
181  YQItemSelector( YWidget * parent,
182  const YItemCustomStatusVector & customStates );
183 
187  void init();
188 
192  void deselectOtherItems( YItem * selectedItem );
193 
194  //
195  // Data members
196  //
197 
198  QWidget * _itemContainer;
199  QButtonGroup * _buttonGroup;
200  QVBoxLayout * _itemLayout;
201 
202  QMap<YItem *, YQSelectorItemWidget *> _itemWidgets;
203 
204 }; // class YQItemSelector
205 
206 
207 
211 class YQSelectorItemWidget: public QFrame
212 {
213  Q_OBJECT
214 
215 public:
216 
221  YItem * item );
225  virtual ~YQSelectorItemWidget();
226 
231  virtual void createWidgets();
232 
237  virtual void setSelected( bool sel = true );
238 
242  virtual bool selected() const;
243 
247  bool singleSelection() const;
248 
252  bool multiSelection() const { return ! singleSelection(); }
253 
259  void setLabel( const QString & label );
260 
266  QAbstractButton * headingToggle() const { return _headingToggle; }
267 
268  //
269  // Getters
270  //
271 
272  YQItemSelector * parent() const { return _parent; }
273  QLabel * descriptionLabel() const { return _descriptionLabel; }
274  QLabel * iconLabel() const { return _iconLabel; }
275  YItem * item() const { return _item; }
276 
277 signals:
278 
279  void selectionChanged( YQSelectorItemWidget * itemWidget, bool selected );
280 
281 
282 protected slots:
283 
284  void slotSelectionChanged( bool selected );
285 
286 
287 protected:
288 
289  virtual void createWidgets( const std::string & label,
290  const std::string & description,
291  const std::string & iconName,
292  bool selected = false );
293 
303  virtual QAbstractButton * createHeadingToggle( const std::string & label,
304  QWidget * parent );
305 
309  virtual int itemDescriptionIndent() const;
310 
311  //
312  // Data members
313  //
314 
315  YQItemSelector * _parent;
316  YItem * _item;
317 
318  QHBoxLayout * _hBox;
319  QVBoxLayout * _vBox;
320  QAbstractButton * _headingToggle;
321  QLabel * _descriptionLabel;
322  QLabel * _iconLabel;
323 
324 }; // class YQSelectorItemWidget
325 
326 
327 
328 #endif // YQItemSelector_h
virtual int itemDescriptionIndent() const
Definition: YQItemSelector.cc:480
QWidget * itemContainer() const
Definition: YQItemSelector.h:134
virtual void setEnabled(bool enabled)
Definition: YQItemSelector.cc:187
virtual void createWidgets()
Definition: YQItemSelector.cc:333
virtual ~YQItemSelector()
Definition: YQItemSelector.cc:92
QButtonGroup * buttonGroup() const
Definition: YQItemSelector.h:140
bool multiSelection() const
Definition: YQItemSelector.h:252
YQItemSelector(YWidget *parent, bool enforceSingleSelection=true)
Definition: YQItemSelector.cc:49
virtual int preferredWidth()
Definition: YQItemSelector.cc:193
QAbstractButton * headingToggle() const
Definition: YQItemSelector.h:266
void init()
Definition: YQItemSelector.cc:67
void deselectOtherItems(YItem *selectedItem)
Definition: YQItemSelector.cc:161
virtual void addItems(const YItemCollection &itemCollection)
Definition: YQItemSelector.cc:128
virtual ~YQSelectorItemWidget()
Definition: YQItemSelector.cc:327
virtual void deselectAllItems()
Definition: YQItemSelector.cc:152
virtual void setSize(int newWidth, int newHeight)
Definition: YQItemSelector.cc:241
Definition: YQItemSelector.h:211
void slotSelectionChanged(YQSelectorItemWidget *itemWidget, bool selected)
Definition: YQItemSelector.cc:264
virtual int preferredHeight()
Definition: YQItemSelector.cc:206
virtual void shortcutChanged()
Definition: YQItemSelector.cc:302
void setLabel(const QString &label)
Definition: YQItemSelector.cc:521
virtual void setSelected(bool sel=true)
Definition: YQItemSelector.cc:508
virtual void activateItem(YItem *item)
Definition: YQItemSelector.cc:295
bool singleSelection() const
Definition: YQItemSelector.cc:496
virtual void addItem(YItem *item)
Definition: YQItemSelector.cc:109
virtual bool selected() const
Definition: YQItemSelector.cc:502
virtual bool setKeyboardFocus()
Definition: YQItemSelector.cc:247
YQSelectorItemWidget(YQItemSelector *parent, YItem *item)
Definition: YQItemSelector.cc:318
virtual QAbstractButton * createHeadingToggle(const std::string &label, QWidget *parent)
Definition: YQItemSelector.cc:461
virtual void deleteAllItems()
Definition: YQItemSelector.cc:176
void addItemWidget(YQSelectorItemWidget *itemWidget)
Definition: YQItemSelector.cc:98
virtual void selectItem(YItem *item, bool selected=true)
Definition: YQItemSelector.cc:135
Definition: YQItemSelector.h:42