1 | /** =========================================================== |
2 | * @file |
3 | * |
4 | * This file is a part of digiKam project |
5 | * <a href="http://www.digikam.org">http://www.digikam.org</a> |
6 | * |
7 | * @date 2008-03-14 |
8 | * @brief A widget to host settings as expander box |
9 | * |
10 | * @author Copyright (C) 2008-2013 by Gilles Caulier |
11 | * <a href="mailto:caulier dot gilles at gmail dot com">caulier dot gilles at gmail dot com</a> |
12 | * @author Copyright (C) 2008-2013 by Marcel Wiesweg |
13 | * <a href="mailto:marcel dot wiesweg at gmx dot de">marcel dot wiesweg at gmx dot de</a> |
14 | * @author Copyright (C) 2010 by Manuel Viet |
15 | * <a href="mailto:contact at 13zenrv dot fr">contact at 13zenrv dot fr</a> |
16 | * |
17 | * This program is free software; you can redistribute it |
18 | * and/or modify it under the terms of the GNU General |
19 | * Public License as published by the Free Software Foundation; |
20 | * either version 2, or (at your option) |
21 | * any later version. |
22 | * |
23 | * This program is distributed in the hope that it will be useful, |
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26 | * GNU General Public License for more details. |
27 | * |
28 | * ============================================================ */ |
29 | |
30 | #ifndef REXPANDERBOX_H |
31 | #define REXPANDERBOX_H |
32 | |
33 | // Qt includes |
34 | |
35 | #include <QtCore/QObject> |
36 | #include <QtGui/QPixmap> |
37 | #include <QtGui/QLabel> |
38 | #include <QtGui/QWidget> |
39 | #include <QtGui/QScrollArea> |
40 | |
41 | // KDE includes |
42 | |
43 | #include <ksqueezedtextlabel.h> |
44 | #include <kconfig.h> |
45 | |
46 | // Local includes |
47 | |
48 | #include "libkdcraw_export.h" |
49 | |
50 | namespace KDcrawIface |
51 | { |
52 | |
53 | class LIBKDCRAW_EXPORT RClickLabel : public QLabel |
54 | { |
55 | Q_OBJECT |
56 | |
57 | public: |
58 | |
59 | RClickLabel(QWidget* const parent = 0); |
60 | explicit RClickLabel(const QString& text, QWidget* const parent = 0); |
61 | ~RClickLabel(); |
62 | |
63 | Q_SIGNALS: |
64 | |
65 | /// Emitted when activated by left mouse click |
66 | void leftClicked(); |
67 | /// Emitted when activated, by mouse or key press |
68 | void activated(); |
69 | |
70 | protected: |
71 | |
72 | virtual void mousePressEvent(QMouseEvent* event); |
73 | virtual void mouseReleaseEvent(QMouseEvent* event); |
74 | virtual void keyPressEvent(QKeyEvent* event); |
75 | }; |
76 | |
77 | // ------------------------------------------------------------------------- |
78 | |
79 | class LIBKDCRAW_EXPORT RSqueezedClickLabel : public KSqueezedTextLabel |
80 | { |
81 | Q_OBJECT |
82 | |
83 | public: |
84 | |
85 | RSqueezedClickLabel(QWidget* const parent = 0); |
86 | explicit RSqueezedClickLabel(const QString& text, QWidget* const parent = 0); |
87 | ~RSqueezedClickLabel(); |
88 | |
89 | Q_SIGNALS: |
90 | |
91 | void leftClicked(); |
92 | void activated(); |
93 | |
94 | protected: |
95 | |
96 | virtual void mousePressEvent(QMouseEvent* event); |
97 | virtual void mouseReleaseEvent(QMouseEvent* event); |
98 | virtual void keyPressEvent(QKeyEvent* event); |
99 | }; |
100 | |
101 | // ------------------------------------------------------------------------- |
102 | |
103 | class LIBKDCRAW_EXPORT RArrowClickLabel : public QWidget |
104 | { |
105 | Q_OBJECT |
106 | |
107 | public: |
108 | |
109 | RArrowClickLabel(QWidget* const parent = 0); |
110 | ~RArrowClickLabel(); |
111 | |
112 | void setArrowType(Qt::ArrowType arrowType); |
113 | Qt::ArrowType arrowType() const; |
114 | |
115 | virtual QSize sizeHint () const; |
116 | |
117 | Q_SIGNALS: |
118 | |
119 | void leftClicked(); |
120 | |
121 | protected: |
122 | |
123 | virtual void mousePressEvent(QMouseEvent* event); |
124 | virtual void mouseReleaseEvent(QMouseEvent* event); |
125 | virtual void paintEvent(QPaintEvent* event); |
126 | |
127 | protected: |
128 | |
129 | Qt::ArrowType m_arrowType; |
130 | int m_size; |
131 | int m_margin; |
132 | }; |
133 | |
134 | // ------------------------------------------------------------------------- |
135 | |
136 | class LIBKDCRAW_EXPORT RLabelExpander : public QWidget |
137 | { |
138 | Q_OBJECT |
139 | |
140 | public: |
141 | |
142 | RLabelExpander(QWidget* const parent = 0); |
143 | ~RLabelExpander(); |
144 | |
145 | void setCheckBoxVisible(bool b); |
146 | bool checkBoxIsVisible() const; |
147 | |
148 | void setChecked(bool b); |
149 | bool isChecked() const; |
150 | |
151 | void setLineVisible(bool b); |
152 | bool lineIsVisible() const; |
153 | |
154 | void setText(const QString& txt); |
155 | QString text() const; |
156 | |
157 | void setIcon(const QPixmap& pix); |
158 | const QPixmap* icon() const; |
159 | |
160 | void setWidget(QWidget* const widget); |
161 | QWidget* widget() const; |
162 | |
163 | void setExpanded(bool b); |
164 | bool isExpanded() const; |
165 | |
166 | void setExpandByDefault(bool b); |
167 | bool isExpandByDefault() const; |
168 | |
169 | Q_SIGNALS: |
170 | |
171 | void signalExpanded(bool); |
172 | void signalToggled(bool); |
173 | |
174 | private Q_SLOTS: |
175 | |
176 | void slotToggleContainer(); |
177 | |
178 | private: |
179 | |
180 | bool eventFilter(QObject* obj, QEvent* ev); |
181 | |
182 | private: |
183 | |
184 | class Private; |
185 | Private* const d; |
186 | }; |
187 | |
188 | // ------------------------------------------------------------------------- |
189 | |
190 | class LIBKDCRAW_EXPORT RExpanderBox : public QScrollArea |
191 | { |
192 | Q_OBJECT |
193 | |
194 | public: |
195 | |
196 | RExpanderBox(QWidget* const parent = 0); |
197 | ~RExpanderBox(); |
198 | |
199 | /** Add RLabelExpander item at end of box layout with these settings : |
200 | 'w' : the widget hosted by RLabelExpander. |
201 | 'pix' : pixmap used as icon to item title. |
202 | 'txt' : text used as item title. |
203 | 'objName' : item object name used to read/save expanded settings to rc file. |
204 | 'expandBydefault' : item state by default (expanded or not). |
205 | */ |
206 | void addItem(QWidget* const w, const QPixmap& pix, const QString& txt, |
207 | const QString& objName, bool expandBydefault); |
208 | void addItem(QWidget* const w, const QString& txt, |
209 | const QString& objName, bool expandBydefault); |
210 | |
211 | /** Insert RLabelExpander item at box layout index with these settings : |
212 | 'w' : the widget hosted by RLabelExpander. |
213 | 'pix' : pixmap used as icon to item title. |
214 | 'txt' : text used as item title. |
215 | 'objName' : item object name used to read/save expanded settings to rc file. |
216 | 'expandBydefault' : item state by default (expanded or not). |
217 | */ |
218 | void insertItem(int index, QWidget* const w, const QPixmap& pix, const QString& txt, |
219 | const QString& objName, bool expandBydefault); |
220 | void insertItem(int index, QWidget* const w, const QString& txt, |
221 | const QString& objName, bool expandBydefault); |
222 | |
223 | void removeItem(int index); |
224 | |
225 | void setCheckBoxVisible(int index, bool b); |
226 | bool checkBoxIsVisible(int index) const; |
227 | |
228 | void setChecked(int index, bool b); |
229 | bool isChecked(int index) const; |
230 | |
231 | void setItemText(int index, const QString& txt); |
232 | QString itemText (int index) const; |
233 | |
234 | void setItemIcon(int index, const QPixmap& pix); |
235 | const QPixmap* itemIcon(int index) const; |
236 | |
237 | void setItemToolTip(int index, const QString& tip); |
238 | QString itemToolTip(int index) const; |
239 | |
240 | void setItemEnabled(int index, bool enabled); |
241 | bool isItemEnabled(int index) const; |
242 | |
243 | void addStretch(); |
244 | void insertStretch(int index); |
245 | |
246 | void setItemExpanded(int index, bool b); |
247 | bool isItemExpanded(int index) const; |
248 | |
249 | int count() const; |
250 | |
251 | RLabelExpander* widget(int index) const; |
252 | int indexOf(RLabelExpander* const widget) const; |
253 | |
254 | virtual void readSettings(KConfigGroup& group); |
255 | virtual void writeSettings(KConfigGroup& group); |
256 | |
257 | Q_SIGNALS: |
258 | |
259 | void signalItemExpanded(int index, bool b); |
260 | void signalItemToggled(int index, bool b); |
261 | |
262 | private Q_SLOTS: |
263 | |
264 | void slotItemExpanded(bool b); |
265 | void slotItemToggled(bool b); |
266 | |
267 | private: |
268 | |
269 | class Private; |
270 | Private* const d; |
271 | }; |
272 | |
273 | // ------------------------------------------------------------------------- |
274 | |
275 | class LIBKDCRAW_EXPORT RExpanderBoxExclusive : public RExpanderBox |
276 | { |
277 | Q_OBJECT |
278 | |
279 | public: |
280 | |
281 | RExpanderBoxExclusive(QWidget* const parent = 0); |
282 | ~RExpanderBoxExclusive(); |
283 | |
284 | /** Show one expander open at most */ |
285 | void setIsToolBox(bool b); |
286 | bool isToolBox() const; |
287 | |
288 | private Q_SLOTS: |
289 | |
290 | void slotItemExpanded(bool b); |
291 | |
292 | private: |
293 | |
294 | bool m_toolbox; |
295 | }; |
296 | |
297 | } // namespace KDcrawIface |
298 | |
299 | #endif // REXPANDERBOX_H |
300 | |