libyui-qt  2.53.0
YQCustomStatusItemSelector.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: YQCustomStatusItemSelector.h
20 
21  Author: Stefan Hundhammer <shundhammer@suse.de>
22 
23 /-*/
24 
25 
26 #ifndef YQCustomStatusItemSelector_h
27 #define YQCustomStatusItemSelector_h
28 
29 #include "YQItemSelector.h"
30 
31 
33 
34 
35 /**
36  * ItemSelector widget with support for custom status values, not just 0 or 1.
37  *
38  * This does not use a standard QCheckBox or QRadioButton, but a QToolButton
39  * with an icon that is exchanged whenever the status changes.
40  **/
42 {
43  Q_OBJECT
44 
45 public:
46 
47  /**
48  * Constructor.
49  **/
50  YQCustomStatusItemSelector( YWidget * parent,
51  const YItemCustomStatusVector & customStates );
52 
53  /**
54  * Destructor.
55  **/
57 
58  /**
59  * Add an item.
60  *
61  * Reimplemented from YQItemSelector / YSelectionWidget.
62  **/
63  virtual void addItem( YItem * item );
64 
65  /**
66  * Select or deselect an item.
67  *
68  * Reimplemented from YSelectionWidget.
69  **/
70  virtual void selectItem( YItem * item, bool selected = true );
71 
72  /**
73  * Return the status icon for the specified status.
74  **/
75  const QIcon & statusIcon( int status ) const;
76 
77  /**
78  * Activate selected item. Can be used in tests to simulate user input.
79  *
80  * Derived classes are required to implement this.
81  **/
82  virtual void activateItem( YItem * item );
83 
84 protected slots:
85 
86  /**
87  * Cycle the status of an item and report the click to the calling
88  * application.
89  **/
90  void itemClicked( YQCustomStatusSelectorItemWidget * itemWidget );
91 
92 
93 protected:
94 
95  /**
96  * Preload and cache the status icons.
97  **/
98  void preloadStatusIcons();
99 
100  /**
101  * Update the status indicator (the status icon) for an item.
102  *
103  * Reimplemented from YItemSelector.
104  **/
105  virtual void updateCustomStatusIndicator( YItem * item );
106 
107 
108  // Data members
109 
110  QList<QIcon> _statusIcons;
111 
112 }; // class YQCustomStatusItemSelector
113 
114 
115 
116 /**
117  * Class for the widgets of one YQCustomStatusItemSelector item.
118  **/
120 {
121  Q_OBJECT
122 
123 public:
124 
125  /**
126  * Constructor.
127  **/
129  YItem * item );
130 
131  /**
132  * Destructor.
133  **/
135 
136  /**
137  * Set the correct status icon according to the status of this item.
138  **/
139  void setStatusIcon();
140 
141 signals:
142 
143  /**
144  * Emitted when the user clicks on the heading toggle to change the status
145  * or uses a keyboard operation to do the same.
146  **/
148 
149 protected slots:
150 
151  /**
152  * Forwarder slot from the heading toggle to this class.
153  **/
154  void slotClicked();
155 
156 protected:
157 
158  /**
159  * Create the appropriate toggle button for this item and connect it to
160  * appropriate slots.
161  *
162  * Reimplemented from YQCustomStatusSelectorItemWidget.
163  **/
164  virtual QAbstractButton * createHeadingToggle( const std::string & label,
165  QWidget * parent );
166 
167  /**
168  * Set the correct status icon according to the status of this item.
169  **/
170  void setStatusIcon( QAbstractButton * toggle );
171 
172  /**
173  * Return the amount of indentation in pixels for the description text.
174  *
175  * Reimplemented from YQCustomStatusSelectorItemWidget.
176  **/
177  virtual int itemDescriptionIndent() const;
178 
179 }; // class YQCustomStatusSelectorItemWidget
180 
181 
182 #endif // YQCustomStatusItemSelector_h
ItemSelector widget with support for custom status values, not just 0 or 1.
const QIcon & statusIcon(int status) const
Return the status icon for the specified status.
virtual ~YQCustomStatusItemSelector()
Destructor.
virtual void activateItem(YItem *item)
Activate selected item.
virtual void selectItem(YItem *item, bool selected=true)
Select or deselect an item.
virtual void updateCustomStatusIndicator(YItem *item)
Update the status indicator (the status icon) for an item.
void preloadStatusIcons()
Preload and cache the status icons.
void itemClicked(YQCustomStatusSelectorItemWidget *itemWidget)
Cycle the status of an item and report the click to the calling application.
YQCustomStatusItemSelector(YWidget *parent, const YItemCustomStatusVector &customStates)
Constructor.
virtual void addItem(YItem *item)
Add an item.
Class for the widgets of one YQCustomStatusItemSelector item.
void slotClicked()
Forwarder slot from the heading toggle to this class.
virtual int itemDescriptionIndent() const
Return the amount of indentation in pixels for the description text.
void clicked(YQCustomStatusSelectorItemWidget *itemWidget)
Emitted when the user clicks on the heading toggle to change the status or uses a keyboard operation ...
virtual QAbstractButton * createHeadingToggle(const std::string &label, QWidget *parent)
Create the appropriate toggle button for this item and connect it to appropriate slots.
YQCustomStatusSelectorItemWidget(YQItemSelector *parent, YItem *item)
Constructor.
void setStatusIcon()
Set the correct status icon according to the status of this item.
Class for the widgets of one ItemSelector item.