| 1 |
/**************************************************************************** |
| 2 |
* Copyright (c) 2022 Zheng Lei (realthunder) <[email protected]> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
****************************************************************************/ |
| 22 |
|
| 23 |
#ifndef FC_OVERLAYMANAGER_H |
| 24 |
#define FC_OVERLAYMANAGER_H |
| 25 |
|
| 26 |
#include <QObject> |
| 27 |
#include <QDockWidget> |
| 28 |
#include <FCGlobal.h> |
| 29 |
|
| 30 |
class QAction; |
| 31 |
class QDockWidget; |
| 32 |
class QString; |
| 33 |
class QPoint; |
| 34 |
class QWidget; |
| 35 |
|
| 36 |
namespace Gui |
| 37 |
{ |
| 38 |
|
| 39 |
class OverlayTabWidget; |
| 40 |
|
| 41 |
/// Class that manages overlay dockable widgets |
| 42 |
class GuiExport OverlayManager: public QObject |
| 43 |
{ |
| 44 |
Q_OBJECT |
| 45 |
public: |
| 46 |
OverlayManager(); |
| 47 |
~OverlayManager() override; |
| 48 |
|
| 49 |
/// restore states |
| 50 |
void restore(); |
| 51 |
/// save states |
| 52 |
void save(); |
| 53 |
/// Retranslate text on language change |
| 54 |
void retranslate(); |
| 55 |
/// Reload icon images |
| 56 |
void refreshIcons(); |
| 57 |
|
| 58 |
/// Reload mode |
| 59 |
enum class ReloadMode |
| 60 |
{ |
| 61 |
/// Reload is pending |
| 62 |
ReloadPending = 0, |
| 63 |
/// Reload is paused |
| 64 |
ReloadPause = 1, |
| 65 |
/// Resume state reload |
| 66 |
ReloadResume = 2, |
| 67 |
}; |
| 68 |
/** Set reload mode |
| 69 |
* |
| 70 |
* An internal timer is used to batch handle all relevant parameter |
| 71 |
* changes. The function is provided to let other code temporarily disable |
| 72 |
* the timer before changing the parameter, and then resume it after done. |
| 73 |
*/ |
| 74 |
void reload(ReloadMode mode = ReloadMode::ReloadPending); |
| 75 |
|
| 76 |
/** Refresh overlay internal layout |
| 77 |
* @param widget: optional source widget that triggers the refresh |
| 78 |
* @param refreshStyle: whether to reload stylesheet |
| 79 |
*/ |
| 80 |
void refresh(QWidget* widget = nullptr, bool refreshStyle = false); |
| 81 |
|
| 82 |
/// Setup title bar for a QDockWidget |
| 83 |
void setupTitleBar(QDockWidget*); |
| 84 |
|
| 85 |
/// Overlay mode |
| 86 |
enum class OverlayMode |
| 87 |
{ |
| 88 |
/// Toggle the focused widget between normal and overlay on top of MDI client area |
| 89 |
ToggleActive, |
| 90 |
/// Toggle overlay dock widget background between opaque and transparent |
| 91 |
ToggleTransparent, |
| 92 |
/// Make the focused widget switch to overlay on top of MDI client area |
| 93 |
EnableActive, |
| 94 |
/// Make the focused widget switch back to normal dockable widget |
| 95 |
DisableActive, |
| 96 |
/// Make all docked widget switch to overlay |
| 97 |
EnableAll, |
| 98 |
/// Make all docked widget switch back to normal |
| 99 |
DisableAll, |
| 100 |
/// Toggle all docked widget between normal and overlay |
| 101 |
ToggleAll, |
| 102 |
/// Set all overlay dock widget to transparent background |
| 103 |
TransparentAll, |
| 104 |
/// Set all overlay dock widget to opaque background |
| 105 |
TransparentNone, |
| 106 |
/// Toggle all overlay dock widget background between opaque and transparent |
| 107 |
ToggleTransparentAll, |
| 108 |
/// Toggle show/hide of the left docked widgets |
| 109 |
ToggleLeft, |
| 110 |
/// Toggle show/hide of the right docked widgets |
| 111 |
ToggleRight, |
| 112 |
/// Toggle show/hide of the top docked widgets |
| 113 |
ToggleTop, |
| 114 |
/// Toggle show/hide of the bottom docked widgets |
| 115 |
ToggleBottom, |
| 116 |
}; |
| 117 |
/// Set overlay mode |
| 118 |
void setOverlayMode(OverlayMode mode); |
| 119 |
|
| 120 |
/// Enable/disable mouse transparent mode |
| 121 |
void setMouseTransparent(bool enabled); |
| 122 |
/// Report if mouse transparent mode is active |
| 123 |
bool isMouseTransparent() const; |
| 124 |
|
| 125 |
/// Check if the cursor is within an overlay docked widget |
| 126 |
bool isUnderOverlay() const; |
| 127 |
|
| 128 |
/// Initialize a newly created dock widget |
| 129 |
void initDockWidget(QDockWidget*); |
| 130 |
/// Prepare a dock widget for overlay display |
| 131 |
void setupDockWidget(QDockWidget*, int dockArea = Qt::NoDockWidgetArea); |
| 132 |
/// Switch a dock widget back to normal display |
| 133 |
void unsetupDockWidget(QDockWidget*); |
| 134 |
|
| 135 |
/** Mouse event handler for dragging a dock widget |
| 136 |
* @param pos: mouse cursor position |
| 137 |
* @param widget: dragging widget, can either be a QDockWidget if it is |
| 138 |
* floating, or a OverlayTabWidget if docked in overlay mode |
| 139 |
* @param offset: offset from the mouse cursor to the widget origin |
| 140 |
* @param size: widget size before dragging start |
| 141 |
* @param drop: whether to drop after drag to the position |
| 142 |
*/ |
| 143 |
void dragDockWidget( |
| 144 |
const QPoint& pos, |
| 145 |
QWidget* widget, |
| 146 |
const QPoint& offset, |
| 147 |
const QSize& size, |
| 148 |
bool drop = false |
| 149 |
); |
| 150 |
|
| 151 |
/// Float an overlay docked widget |
| 152 |
void floatDockWidget(QDockWidget*); |
| 153 |
|
| 154 |
/// Return the last widget whose mouse event got intercepted by the overlay manager for mouse |
| 155 |
/// pass through |
| 156 |
QWidget* getLastMouseInterceptWidget() const; |
| 157 |
|
| 158 |
/// Return the stylesheet for overlay widgets |
| 159 |
const QString& getStyleSheet() const; |
| 160 |
|
| 161 |
/// Check whether to hide tab in overlay dock widget |
| 162 |
bool getHideTab() const; |
| 163 |
|
| 164 |
/// Helper function to set focus when switching active sub window |
| 165 |
static void setFocusView(); |
| 166 |
|
| 167 |
/// Return the singleton instance of the overlay manager |
| 168 |
static OverlayManager* instance(); |
| 169 |
/// Destroy the overlay manager |
| 170 |
static void destruct(); |
| 171 |
|
| 172 |
class Private; |
| 173 |
|
| 174 |
protected: |
| 175 |
bool eventFilter(QObject* obj, QEvent* ev) override; |
| 176 |
|
| 177 |
/// Register a named docked widget with an overlay tab widget |
| 178 |
void registerDockWidget(const QString& name, OverlayTabWidget*); |
| 179 |
/// Unregister a named docked widget with an overlay tab widget |
| 180 |
void unregisterDockWidget(const QString& name, OverlayTabWidget*); |
| 181 |
|
| 182 |
private: |
| 183 |
void onToggleDockWidget(bool checked); |
| 184 |
void onDockVisibleChange(bool visible); |
| 185 |
void onDockFeaturesChange(QDockWidget::DockWidgetFeatures features); |
| 186 |
void onDockWidgetTitleChange(const QString&); |
| 187 |
void onTaskViewUpdate(); |
| 188 |
void onFocusChanged(QWidget*, QWidget*); |
| 189 |
void onAction(); |
| 190 |
|
| 191 |
private Q_SLOTS: |
| 192 |
void raiseAll(); |
| 193 |
|
| 194 |
private: |
| 195 |
friend class Private; |
| 196 |
friend class OverlayTabWidget; |
| 197 |
Private* d; |
| 198 |
}; |
| 199 |
|
| 200 |
} // namespace Gui |
| 201 |
|
| 202 |
#endif // FC_OVERLAYMANAGER_H |