digiKam
sidebar.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 : 2005-03-22
7  * Description : a widget to manage sidebar in GUI.
8  *
9  * Copyright (C) 2005-2006 by Joern Ahrens <joern dot ahrens at kdemail dot net>
10  * Copyright (C) 2006-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
11  * Copyright (C) 2008-2013 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
12  * Copyright (C) 2001-2003 by Joseph Wenninger <jowenn at kde dot org>
13  *
14  * This program is free software; you can redistribute it
15  * and/or modify it under the terms of the GNU General
16  * Public License as published by the Free Software Foundation;
17  * either version 2, or (at your option)
18  * any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * ============================================================ */
26 
27 #ifndef DIGIKAM_SIDE_BAR_H
28 #define DIGIKAM_SIDE_BAR_H
29 
30 // Qt includes
31 
32 #include <QPixmap>
33 #include <QSplitter>
34 #include <QPushButton>
35 #include <QWidget>
36 #include <QList>
37 #include <QStyleOptionToolButton>
38 #include <QBoxLayout>
39 
40 // Local includes
41 
42 #include "digikam_export.h"
43 #include "statesavingobject.h"
44 
45 class KConfigGroup;
46 
47 namespace Digikam
48 {
49 
50 class DMultiTabBarButton;
51 class DMultiTabBarTab;
52 
56 class DIGIKAM_EXPORT DMultiTabBar : public QWidget
57 {
58  Q_OBJECT
59 
60 public:
61 
65  enum TextStyle
66  {
67  ActiveIconText = 0,
68  AllIconsText = 2
69  };
70 
71 public:
72 
73  explicit DMultiTabBar(Qt::Edge pos, QWidget* const parent = nullptr);
74  ~DMultiTabBar() override;
75 
85  void appendButton(const QPixmap& pic,
86  int id = -1,
87  QMenu* const popup = nullptr,
88  const QString& not_used_yet = QString());
89 
93  void removeButton(int id);
94 
101  void appendTab(const QPixmap& pic,
102  int id = -1,
103  const QString& text = QString());
104 
108  void removeTab(int id);
109 
115  void setTab(int id, bool state);
116 
120  bool isTabRaised(int id) const;
121 
125  DMultiTabBarButton* button(int id) const;
126 
130  DMultiTabBarTab* tab(int id) const;
131 
136  void setPosition(Qt::Edge pos);
137 
142  Qt::Edge position() const;
143 
147  void setStyle(TextStyle style);
148 
153  TextStyle tabStyle() const;
154 
155 protected:
156 
157  void updateSeparator();
158 
159  virtual void fontChange(const QFont&);
160 
161 private:
162 
163  friend class DMultiTabBarButton;
164 
165  class Private;
166  Private* const d;
167 };
168 
169 // -------------------------------------------------------------------------------------
170 
171 class DIGIKAM_EXPORT DMultiTabBarButton: public QPushButton
172 {
173  Q_OBJECT
174 
175 public:
176 
177  ~DMultiTabBarButton() override;
178 
179  int id() const;
180 
181 public Q_SLOTS:
182 
183  void setText(const QString& text);
184 
185 Q_SIGNALS:
186 
191  void signalClicked(int id);
192 
193 protected Q_SLOTS:
194 
195  virtual void slotClicked();
196 
197 protected:
198 
199  DMultiTabBarButton(const QPixmap& pic,
200  const QString&,
201  int id,
202  QWidget* const parent);
203 
204  void hideEvent(QHideEvent*) override;
205  void showEvent(QShowEvent*) override;
206  void paintEvent(QPaintEvent*) override;
207 
208 private:
209 
210  friend class DMultiTabBar;
211 
212  int m_id;
213 };
214 
215 // -------------------------------------------------------------------------------------
216 
217 class DIGIKAM_EXPORT DMultiTabBarTab: public DMultiTabBarButton
218 {
219  Q_OBJECT
220 
221 public:
222 
223  ~DMultiTabBarTab() override;
224 
225  QSize sizeHint() const override;
226  QSize minimumSizeHint() const override;
227 
228 public Q_SLOTS:
229 
234  void setPosition(Qt::Edge);
235 
240  void setStyle(DMultiTabBar::TextStyle);
241 
246  void setState(bool state);
247 
248  void setIcon(const QString&);
249  void setIcon(const QPixmap&);
250 
251 protected:
252 
253  void computeMargins (int* hMargin, int* vMargin) const;
254  QSize computeSizeHint(bool withText) const;
255  bool shouldDrawText() const;
256  bool isVertical() const;
257  QPixmap iconPixmap() const;
258  void initButtonStyleOption(QStyleOptionToolButton* opt) const;
259 
260  friend class DMultiTabBarFrame;
261 
265  DMultiTabBarTab(const QPixmap& pic,
266  const QString&,
267  int id,
268  QWidget* const parent,
269  Qt::Edge pos,
271 
272  void paintEvent(QPaintEvent*) override;
273 
274 private:
275 
276  class Private;
277  Private* const d;
278 };
279 
280 // -------------------------------------------------------------------------------------
281 
282 class DMultiTabBarFrame: public QFrame
283 {
284  Q_OBJECT
285 
286 public:
287 
288  explicit DMultiTabBarFrame(QWidget* const parent, Qt::Edge pos);
289  ~DMultiTabBarFrame() override;
290 
291  void appendTab(const QPixmap&, int = -1, const QString& = QString());
292  DMultiTabBarTab* tab(int) const;
293  void removeTab(int);
294  void setPosition(Qt::Edge pos);
295  void setStyle(DMultiTabBar::TextStyle style);
296  void showActiveTabTexts(bool show);
298 
299 protected:
300 
306  virtual void contentsMousePressEvent(QMouseEvent*);
307  void mousePressEvent(QMouseEvent*) override;
308 
309 private:
310 
311  friend class DMultiTabBar;
312 
313  class Private;
314  Private* const d;
315 };
316 
317 // -------------------------------------------------------------------------------------
318 
319 class SidebarSplitter;
320 
331 class DIGIKAM_EXPORT Sidebar : public DMultiTabBar,
332  public StateSavingObject
333 {
334  Q_OBJECT
335 
336 public:
337 
348  explicit Sidebar(QWidget* const parent,
349  SidebarSplitter* const sp,
350  Qt::Edge side = Qt::LeftEdge,
351  bool minimizedDefault = false);
352 
353  ~Sidebar() override;
354 
355  SidebarSplitter* splitter() const;
356 
363  void appendTab(QWidget* const w, const QIcon& pic, const QString& title);
364 
368  void deleteTab(QWidget* const w);
369 
373  void setActiveTab(QWidget* const w);
374 
378  void activeNextTab();
379 
383  void activePreviousTab();
384 
388  QWidget* getActiveTab() const;
389 
393  void shrink();
394 
398  void expand();
399 
403  void backup();
404 
410  void backup(const QList<QWidget*>& thirdWidgetsToBackup, QList<int>* const sizes);
411 
415  void restore();
416 
421  void restore(const QList<QWidget*>& thirdWidgetsToRestore, const QList<int>& sizes);
422 
426  bool isExpanded() const;
427 
428 protected:
429 
433  void doLoadState() override;
434 
438  void doSaveState() override;
439 
440 private:
441 
442  bool eventFilter(QObject* o, QEvent* e) override;
443  void switchTabAndStackToTab(int tab);
444 
445 private Q_SLOTS:
446 
450  void slotClicked(int tab);
451 
452  void slotExpandTimer();
453  void slotDragSwitchTimer();
454 
455  void slotSplitterBtnClicked();
456 
457 Q_SIGNALS:
458 
462  void signalChangedTab(QWidget* w);
463 
468 
469 private:
470 
471  friend class SidebarSplitter;
472 
473  class Private;
474  Private* const d;
475 };
476 
477 // -----------------------------------------------------------------------------
478 
479 class DIGIKAM_EXPORT SidebarSplitter : public QSplitter
480 {
481  Q_OBJECT
482 
483 public:
484 
485  const static QString DEFAULT_CONFIG_KEY;
486 
491  explicit SidebarSplitter(QWidget* const parent = nullptr);
492  explicit SidebarSplitter(Qt::Orientation orientation, QWidget* const parent = nullptr);
493 
494  ~SidebarSplitter() override;
495 
500  void saveState(KConfigGroup& group);
501 
506  void saveState(KConfigGroup& group, const QString& key);
507 
512  void restoreState(KConfigGroup& group);
513 
518  void restoreState(KConfigGroup& group, const QString& key);
519 
523  int size(Sidebar* const bar) const;
524  int size(QWidget* const widget) const;
525 
530  void setSize(Sidebar* const bar, int size);
531  void setSize(QWidget* const widget, int size);
532 
533  void addSplitterCollapserButton(QWidget* const widget);
534 
535 private Q_SLOTS:
536 
537  void slotSplitterMoved(int pos, int index);
538 
539 private:
540 
541  friend class Sidebar;
542 
543  class Private;
544  Private* const d;
545 };
546 
547 } // namespace Digikam
548 
549 #endif // DIGIKAM_SIDE_BAR_H
Definition: sidebar.h:172
Definition: sidebar_p.h:62
Definition: sidebar.h:283
void mousePressEvent(QMouseEvent *) override
Definition: sidebar_dmultitabbarframe.cpp:78
DMultiTabBarFrame(QWidget *const parent, Qt::Edge pos)
Definition: sidebar_dmultitabbarframe.cpp:32
void showActiveTabTexts(bool show)
void appendTab(const QPixmap &, int=-1, const QString &=QString())
Definition: sidebar_dmultitabbarframe.cpp:100
void removeTab(int)
Definition: sidebar_dmultitabbarframe.cpp:111
DMultiTabBarTab * tab(int) const
Definition: sidebar_dmultitabbarframe.cpp:83
~DMultiTabBarFrame() override
Definition: sidebar_dmultitabbarframe.cpp:54
QList< DMultiTabBarTab * > * tabs()
Definition: sidebar_dmultitabbarframe.cpp:137
virtual void contentsMousePressEvent(QMouseEvent *)
Definition: sidebar_dmultitabbarframe.cpp:73
void setPosition(Qt::Edge pos)
Definition: sidebar_dmultitabbarframe.cpp:125
void setStyle(DMultiTabBar::TextStyle style)
Definition: sidebar_dmultitabbarframe.cpp:61
Definition: sidebar_p.h:76
Definition: sidebar.h:218
Definition: sidebar_p.h:88
Definition: sidebar.h:57
TextStyle
Definition: sidebar.h:66
Definition: sidebar_p.h:151
Definition: sidebar.h:480
static const QString DEFAULT_CONFIG_KEY
Definition: sidebar.h:485
void addSplitterCollapserButton(QWidget *const widget)
Definition: sidebar_p.h:116
Definition: sidebar.h:333
void signalViewChanged()
void signalChangedTab(QWidget *w)
Definition: statesavingobject.h:76
Definition: piwigotalker.h:48
@ Orientation
Definition: coredbfields.h:86
Definition: datefolderview.cpp:43
Definition: scan.h:26