| 1 |
/** =========================================================== |
| 2 |
* @file |
| 3 |
* |
| 4 |
* This file is a part of digiKam project |
| 5 |
* <a href="https://www.digikam.org">https://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-2015 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 <QObject> |
| 36 |
#include <QPixmap> |
| 37 |
#include <QLabel> |
| 38 |
#include <QWidget> |
| 39 |
#include <QScrollArea> |
| 40 |
|
| 41 |
// KDE includes |
| 42 |
|
| 43 |
#include <kconfiggroup.h> |
| 44 |
|
| 45 |
// Local includes |
| 46 |
|
| 47 |
|
| 48 |
#include "rwidgetutils.h" |
| 49 |
|
| 50 |
namespace KDcrawIface |
| 51 |
{ |
| 52 |
|
| 53 |
class 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() override; |
| 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 |
void mousePressEvent(QMouseEvent* event) override; |
| 73 |
void mouseReleaseEvent(QMouseEvent* event) override; |
| 74 |
void keyPressEvent(QKeyEvent* event) override; |
| 75 |
}; |
| 76 |
|
| 77 |
// ------------------------------------------------------------------------- |
| 78 |
|
| 79 |
class RSqueezedClickLabel : public RAdjustableLabel |
| 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() override; |
| 88 |
|
| 89 |
Q_SIGNALS: |
| 90 |
|
| 91 |
void leftClicked(); |
| 92 |
void activated(); |
| 93 |
|
| 94 |
protected: |
| 95 |
|
| 96 |
void mousePressEvent(QMouseEvent* event) override; |
| 97 |
void mouseReleaseEvent(QMouseEvent* event) override; |
| 98 |
void keyPressEvent(QKeyEvent* event) override; |
| 99 |
}; |
| 100 |
|
| 101 |
// ------------------------------------------------------------------------- |
| 102 |
|
| 103 |
class RArrowClickLabel : public QWidget |
| 104 |
{ |
| 105 |
Q_OBJECT |
| 106 |
|
| 107 |
public: |
| 108 |
|
| 109 |
RArrowClickLabel(QWidget* const parent = 0); |
| 110 |
~RArrowClickLabel() override; |
| 111 |
|
| 112 |
void setArrowType(Qt::ArrowType arrowType); |
| 113 |
Qt::ArrowType arrowType() const; |
| 114 |
|
| 115 |
QSize sizeHint () const override; |
| 116 |
|
| 117 |
Q_SIGNALS: |
| 118 |
|
| 119 |
void leftClicked(); |
| 120 |
|
| 121 |
protected: |
| 122 |
|
| 123 |
void mousePressEvent(QMouseEvent* event) override; |
| 124 |
void mouseReleaseEvent(QMouseEvent* event) override; |
| 125 |
void paintEvent(QPaintEvent* event) override; |
| 126 |
|
| 127 |
protected: |
| 128 |
|
| 129 |
Qt::ArrowType m_arrowType; |
| 130 |
int m_size; |
| 131 |
int m_margin; |
| 132 |
}; |
| 133 |
|
| 134 |
// ------------------------------------------------------------------------- |
| 135 |
|
| 136 |
class RLabelExpander : public QWidget |
| 137 |
{ |
| 138 |
Q_OBJECT |
| 139 |
|
| 140 |
public: |
| 141 |
|
| 142 |
RLabelExpander(QWidget* const parent = 0); |
| 143 |
~RLabelExpander() override; |
| 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 QIcon &icon); |
| 158 |
QIcon 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) override; |
| 181 |
|
| 182 |
private: |
| 183 |
|
| 184 |
class Private; |
| 185 |
Private* const d; |
| 186 |
}; |
| 187 |
|
| 188 |
// ------------------------------------------------------------------------- |
| 189 |
|
| 190 |
class RExpanderBox : public QScrollArea |
| 191 |
{ |
| 192 |
Q_OBJECT |
| 193 |
|
| 194 |
public: |
| 195 |
|
| 196 |
RExpanderBox(QWidget* const parent = 0); |
| 197 |
~RExpanderBox() override; |
| 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 QIcon &icon, 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 QIcon &icon, 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 QIcon &icon); |
| 235 |
QIcon 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 RExpanderBoxExclusive : public RExpanderBox |
| 276 |
{ |
| 277 |
Q_OBJECT |
| 278 |
|
| 279 |
public: |
| 280 |
|
| 281 |
RExpanderBoxExclusive(QWidget* const parent = 0); |
| 282 |
~RExpanderBoxExclusive() override; |
| 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 |