digiKam
dexpanderbox.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2008-03-14
7  * Description : A widget to host settings as expander box
8  *
9  * Copyright (C) 2008-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  * Copyright (C) 2008-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  * Copyright (C) 2010 by Manuel Viet <contact at 13zenrv dot fr>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_DEXPANDER_BOX_H
27 #define DIGIKAM_DEXPANDER_BOX_H
28 
29 // Qt includes
30 
31 #include <QObject>
32 #include <QPixmap>
33 #include <QLabel>
34 #include <QWidget>
35 #include <QScrollArea>
36 #include <QFrame>
37 
38 // Local includes
39 
40 #include "digikam_export.h"
41 
42 class KConfigGroup;
43 
44 namespace Digikam
45 {
46 
50 class DIGIKAM_EXPORT DLineWidget : public QFrame
51 {
52  Q_OBJECT
53 
54 public:
55 
56  explicit DLineWidget(Qt::Orientation orientation, QWidget* const parent = nullptr);
57  ~DLineWidget() override;
58 };
59 
60 // -------------------------------------------------------------------------
61 
65 class DIGIKAM_EXPORT DAdjustableLabel : public QLabel
66 {
67  Q_OBJECT
68 
69 public:
70 
71  explicit DAdjustableLabel(QWidget* const parent = nullptr);
72  ~DAdjustableLabel() override;
73 
74  QSize minimumSizeHint() const override;
75  QSize sizeHint() const override;
76 
77  void setAlignment(Qt::Alignment align);
78  void setElideMode(Qt::TextElideMode mode);
79 
80  QString adjustedText() const;
81 
82 public Q_SLOTS:
83 
84  void setAdjustedText(const QString& text = QString());
85 
86 private:
87 
88  void resizeEvent(QResizeEvent*) override;
89  void adjustTextToLabel();
90 
91  // Disabled methods from QLabel
92  QString text() const { return QString(); };
93  void setText(const QString&) {};
94  void clear() {};
95 
96 private:
97 
98  class Private;
99  Private* const d;
100 };
101 
102 // -------------------------------------------------------------------------
103 
104 class DIGIKAM_EXPORT DClickLabel : public QLabel
105 {
106  Q_OBJECT
107 
108 public:
109 
110  explicit DClickLabel(QWidget* const parent = nullptr);
111  explicit DClickLabel(const QString& text, QWidget* const parent = nullptr);
112  ~DClickLabel() override;
113 
114 Q_SIGNALS:
115 
117  void leftClicked();
118 
120  void activated();
121 
122 protected:
123 
124  void mousePressEvent(QMouseEvent* event) override;
125  void mouseReleaseEvent(QMouseEvent* event) override;
126  void keyPressEvent(QKeyEvent* event) override;
127 };
128 
129 // -------------------------------------------------------------------------
130 
131 class DIGIKAM_EXPORT DSqueezedClickLabel : public DAdjustableLabel
132 {
133  Q_OBJECT
134 
135 public:
136 
137  explicit DSqueezedClickLabel(QWidget* const parent = nullptr);
138  explicit DSqueezedClickLabel(const QString& text, QWidget* const parent = nullptr);
139  ~DSqueezedClickLabel() override;
140 
141 Q_SIGNALS:
142 
143  void leftClicked();
144  void activated();
145 
146 protected:
147 
148  void mousePressEvent(QMouseEvent* event) override;
149  void mouseReleaseEvent(QMouseEvent* event) override;
150  void keyPressEvent(QKeyEvent* event) override;
151 };
152 
153 // -------------------------------------------------------------------------
154 
155 class DIGIKAM_EXPORT DArrowClickLabel : public QWidget
156 {
157  Q_OBJECT
158 
159 public:
160 
161  explicit DArrowClickLabel(QWidget* const parent = nullptr);
162  ~DArrowClickLabel() override;
163 
164  void setArrowType(Qt::ArrowType arrowType);
165  Qt::ArrowType arrowType() const;
166 
167  QSize sizeHint () const override;
168 
169 Q_SIGNALS:
170 
171  void leftClicked();
172 
173 protected:
174 
175  void mousePressEvent(QMouseEvent* event) override;
176  void mouseReleaseEvent(QMouseEvent* event) override;
177  void paintEvent(QPaintEvent* event) override;
178 
179 protected:
180 
181  Qt::ArrowType m_arrowType;
182  int m_size;
183  int m_margin;
184 };
185 
186 // -------------------------------------------------------------------------
187 
188 class DIGIKAM_EXPORT DLabelExpander : public QWidget
189 {
190  Q_OBJECT
191 
192 public:
193 
194  explicit DLabelExpander(QWidget* const parent = nullptr);
195  ~DLabelExpander() override;
196 
197  void setCheckBoxVisible(bool b);
198  bool checkBoxIsVisible() const;
199 
200  void setChecked(bool b);
201  bool isChecked() const;
202 
203  void setLineVisible(bool b);
204  bool lineIsVisible() const;
205 
206  void setText(const QString& txt);
207  QString text() const;
208 
209  void setIcon(const QIcon &icon);
210  QIcon icon() const;
211 
212  void setWidget(QWidget* const widget);
213  QWidget* widget() const;
214 
215  void setExpanded(bool b);
216  bool isExpanded() const;
217 
218  void setExpandByDefault(bool b);
219  bool isExpandByDefault() const;
220 
221 Q_SIGNALS:
222 
223  void signalExpanded(bool);
224  void signalToggled(bool);
225 
226 private Q_SLOTS:
227 
228  void slotToggleContainer();
229 
230 private:
231 
232  bool eventFilter(QObject* obj,
233  QEvent* ev) override;
234 
235 private:
236 
237  class Private;
238  Private* const d;
239 };
240 
241 // -------------------------------------------------------------------------
242 
243 class DIGIKAM_EXPORT DExpanderBox : public QScrollArea
244 {
245  Q_OBJECT
246 
247 public:
248 
249  explicit DExpanderBox(QWidget* const parent = nullptr);
250  ~DExpanderBox() override;
251 
260  void addItem(QWidget* const w, const QIcon &icon, const QString& txt,
261  const QString& objName, bool expandBydefault);
262  void addItem(QWidget* const w, const QString& txt,
263  const QString& objName, bool expandBydefault);
264 
273  void insertItem(int index, QWidget* const w, const QIcon &icon, const QString& txt,
274  const QString& objName, bool expandBydefault);
275  void insertItem(int index, QWidget* const w, const QString& txt,
276  const QString& objName, bool expandBydefault);
277 
278  void removeItem(int index);
279 
280  void setCheckBoxVisible(int index, bool b);
281  bool checkBoxIsVisible(int index) const;
282 
283  void setChecked(int index, bool b);
284  bool isChecked(int index) const;
285 
286  void setItemText(int index, const QString& txt);
287  QString itemText (int index) const;
288 
289  void setItemIcon(int index, const QIcon &icon);
290  QIcon itemIcon(int index) const;
291 
292  void setItemToolTip(int index, const QString& tip);
293  QString itemToolTip(int index) const;
294 
295  void setItemEnabled(int index, bool enabled);
296  bool isItemEnabled(int index) const;
297 
298  void addStretch();
299  void insertStretch(int index);
300 
301  void setItemExpanded(int index, bool b);
302  bool isItemExpanded(int index) const;
303 
304  int count() const;
305 
306  DLabelExpander* widget(int index) const;
307  int indexOf(DLabelExpander* const widget) const;
308 
309  virtual void readSettings(KConfigGroup& group);
310  virtual void writeSettings(KConfigGroup& group);
311 
312 Q_SIGNALS:
313 
314  void signalItemExpanded(int index, bool b);
315  void signalItemToggled(int index, bool b);
316 
317 private Q_SLOTS:
318 
319  void slotItemExpanded(bool b);
320  void slotItemToggled(bool b);
321 
322 private:
323 
324  class Private;
325  Private* const d;
326 };
327 
328 // -------------------------------------------------------------------------
329 
330 class DIGIKAM_EXPORT DExpanderBoxExclusive : public DExpanderBox
331 {
332  Q_OBJECT
333 
334 public:
335 
336  explicit DExpanderBoxExclusive(QWidget* const parent = nullptr);
337  ~DExpanderBoxExclusive() override;
338 
342  void setIsToolBox(bool b);
343  bool isToolBox() const;
344 
345 private Q_SLOTS:
346 
347  void slotItemExpanded(bool b);
348 
349 private:
350 
351  bool m_toolbox;
352 };
353 
354 } // namespace Digikam
355 
356 #endif // DIGIKAM_DEXPANDER_BOX_H
Definition: dexpanderbox.h:66
Definition: dexpanderbox.h:156
int m_margin
Definition: dexpanderbox.h:183
int m_size
Definition: dexpanderbox.h:182
Qt::ArrowType m_arrowType
Definition: dexpanderbox.h:181
Definition: dexpanderbox.h:105
void leftClicked()
Emitted when activated by left mouse click.
void activated()
Emitted when activated, by mouse or key press.
Definition: dexpanderbox.h:331
Definition: dexpanderbox.h:244
void signalItemToggled(int index, bool b)
void signalItemExpanded(int index, bool b)
Definition: dexpanderbox.h:189
Definition: dexpanderbox.h:51
Definition: dexpanderbox.h:132
@ Orientation
Definition: coredbfields.h:86
Definition: datefolderview.cpp:43