File indexing completed on 2025-04-27 03:58:31
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2009-15-08 0007 * Description : A floatable/dockable widget for thumbnail bars (ThumbBarView 0008 * and its descendants), providing i drag handle similar to the 0009 * one on toolbars and a standard Action to show/hide the 0010 * thumbnail bar. It inherits QDockWidget and can be used in 0011 * the dock area's of a QMainWindow. 0012 * 0013 * SPDX-FileCopyrightText: 2009 by Pieter Edelman <p dot edelman at gmx dot net> 0014 * 0015 * SPDX-License-Identifier: GPL-2.0-or-later 0016 * 0017 * ============================================================ */ 0018 0019 #ifndef DIGIKAM_THUMB_BAR_DOCK_H 0020 #define DIGIKAM_THUMB_BAR_DOCK_H 0021 0022 // Qt includes 0023 0024 #include <QDockWidget> 0025 #include <QPainter> 0026 #include <QString> 0027 #include <QStyle> 0028 #include <QStyleOptionToolBar> 0029 #include <QMainWindow> 0030 #include <QAction> 0031 0032 // Local includes 0033 0034 #include "digikam_export.h" 0035 0036 namespace Digikam 0037 { 0038 0039 /** 0040 * An alternative handle for QDockWidget's that looks like a toolbar handle. 0041 */ 0042 class DragHandle : public QWidget 0043 { 0044 Q_OBJECT 0045 0046 public: 0047 0048 explicit DragHandle(QDockWidget* const); 0049 ~DragHandle() override; 0050 0051 QSize sizeHint() const override; 0052 QSize minimumSizeHint() const override; 0053 0054 protected: 0055 0056 void paintEvent(QPaintEvent*) override; 0057 0058 private Q_SLOTS: 0059 0060 void dockLocationChanged(Qt::DockWidgetArea); 0061 0062 private: 0063 0064 class Private; 0065 Private* const d; 0066 }; 0067 0068 // -------------------------------------------------------------------------------- 0069 0070 /** 0071 * A dock widget specifically designed for thumbnail bars (class ThumbNailView 0072 * or one of its descendants). It provides the same look as a toolbar. 0073 */ 0074 class DIGIKAM_EXPORT ThumbBarDock : public QDockWidget 0075 { 0076 Q_OBJECT 0077 0078 public: 0079 0080 enum Visibility 0081 { 0082 WAS_HIDDEN, 0083 WAS_SHOWN, 0084 SHOULD_BE_HIDDEN, 0085 SHOULD_BE_SHOWN 0086 }; 0087 0088 public: 0089 0090 explicit ThumbBarDock(QWidget* const parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); 0091 ~ThumbBarDock() override; 0092 0093 /** 0094 * Measure the orientation and size of the widget and adjust the containing 0095 * thumbnail bar accordingly. Normally not needed, but useful when the 0096 * dock widget has changed location and/or size and the appropriate signals 0097 * aren't emitted. 0098 */ 0099 void reInitialize(); 0100 0101 /** 0102 * Return an Action to show and hide the thumbnail bar. 0103 */ 0104 QAction* getToggleAction(QObject* const parent, 0105 const QString& caption = QString()) const; 0106 0107 /** 0108 * The normal show() and hide() functions don't apply that well, because 0109 * there are two orthogonal reasons to hide the thumbbar: the user doesn't 0110 * want it, and the window with the thumbbar isn't shown. 0111 * The restoreVisibility() function will set the visibility status to what 0112 * it should be according to the user setting. The setShouldBeVisible() 0113 * function can change this setting. showThumbBar() can be used to hide and 0114 * show the thumbbar according to the user preference. shouldBeVisible() 0115 * tells whether the thumbbar should be shown according to the user. 0116 */ 0117 bool shouldBeVisible() const; 0118 void setShouldBeVisible(bool); 0119 void restoreVisibility(); 0120 0121 static QPixmap generateFuzzyRect(const QSize& size, const QColor& color, int radius, const QColor& fillColor = Qt::transparent); 0122 static QPixmap generateFuzzyRectForGroup(const QSize& size, const QColor& color, int radius); 0123 0124 public Q_SLOTS: 0125 0126 void showThumbBar(bool); 0127 0128 private: 0129 0130 Visibility m_visible; 0131 }; 0132 0133 } // namespace Digikam 0134 0135 #endif // DIGIKAM_THUMB_BAR_DOCK_H