diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp
index 9b79fb4..cde5492 100644
--- a/demo/MainWindow.cpp
+++ b/demo/MainWindow.cpp
@@ -592,19 +592,29 @@ void MainWindowPrivate::createActions()
ui.toolBar->addAction(ui.actionRestoreState);
ui.actionRestoreState->setIcon(svgIcon(":/adsdemo/images/restore.svg"));
- SavePerspectiveAction = new QAction("Create Perspective", _this);
- SavePerspectiveAction->setIcon(svgIcon(":/adsdemo/images/picture_in_picture.svg"));
- _this->connect(SavePerspectiveAction, SIGNAL(triggered()), SLOT(savePerspective()));
+ ui.toolBar->addSeparator();
+
+ QAction* a = ui.toolBar->addAction("Lock Workspace");
+ a->setIcon(svgIcon(":/adsdemo/images/lock_outline.svg"));
+ a->setCheckable(true);
+ a->setChecked(false);
+ QObject::connect(a, &QAction::triggered, _this, &CMainWindow::lockWorkspace);
+
PerspectiveListAction = new QWidgetAction(_this);
PerspectiveComboBox = new QComboBox(_this);
PerspectiveComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
- PerspectiveComboBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
+ PerspectiveComboBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
PerspectiveListAction->setDefaultWidget(PerspectiveComboBox);
- ui.toolBar->addSeparator();
ui.toolBar->addAction(PerspectiveListAction);
+
+ a = SavePerspectiveAction = ui.toolBar->addAction("Create Perspective");
+ a->setIcon(svgIcon(":/adsdemo/images/picture_in_picture.svg"));
+ QObject::connect(a, &QAction::triggered, _this, &CMainWindow::savePerspective);
ui.toolBar->addAction(SavePerspectiveAction);
- QAction* a = ui.toolBar->addAction("Create Floating Editor");
+ ui.toolBar->addSeparator();
+
+ a = ui.toolBar->addAction("Create Floating Editor");
a->setProperty("Floating", true);
a->setToolTip("Creates floating dynamic dockable editor windows that are deleted on close");
a->setIcon(svgIcon(":/adsdemo/images/note_add.svg"));
@@ -626,6 +636,7 @@ void MainWindowPrivate::createActions()
_this->connect(a, SIGNAL(triggered()), SLOT(createEditor()));
ui.menuTests->addAction(a);
+ ui.toolBar->addSeparator();
a = ui.toolBar->addAction("Create Floating Table");
a->setToolTip("Creates floating dynamic dockable table with millions of entries");
a->setIcon(svgIcon(":/adsdemo/images/grid_on.svg"));
@@ -1030,3 +1041,17 @@ void CMainWindow::createImageViewer()
}
}
+
+//============================================================================
+void CMainWindow::lockWorkspace(bool Value)
+{
+ if (Value)
+ {
+ d->DockManager->lockDockWidgetFeaturesGlobally();
+ }
+ else
+ {
+ d->DockManager->lockDockWidgetFeaturesGlobally(ads::CDockWidget::NoDockWidgetFeatures);
+ }
+}
+
diff --git a/demo/MainWindow.h b/demo/MainWindow.h
index 4afee14..dd12360 100644
--- a/demo/MainWindow.h
+++ b/demo/MainWindow.h
@@ -68,6 +68,7 @@ private slots:
void toggleDockWidgetWindowTitle();
void applyVsStyle();
void createImageViewer();
+ void lockWorkspace(bool Value);
};
#endif // MAINWINDOW_H
diff --git a/demo/demo.qrc b/demo/demo.qrc
index 6fadba2..8b35293 100644
--- a/demo/demo.qrc
+++ b/demo/demo.qrc
@@ -36,5 +36,8 @@
images/panorama.svg
images/ads_icon2.svg
images/font_download.svg
+ images/lock_outline.svg
+ images/lock.svg
+ images/lock_open.svg
diff --git a/demo/images/lock.svg b/demo/images/lock.svg
new file mode 100644
index 0000000..ec11129
--- /dev/null
+++ b/demo/images/lock.svg
@@ -0,0 +1,6 @@
+
\ No newline at end of file
diff --git a/demo/images/lock_open.svg b/demo/images/lock_open.svg
new file mode 100644
index 0000000..a30effc
--- /dev/null
+++ b/demo/images/lock_open.svg
@@ -0,0 +1,6 @@
+
\ No newline at end of file
diff --git a/demo/images/lock_outline.svg b/demo/images/lock_outline.svg
new file mode 100644
index 0000000..613e430
--- /dev/null
+++ b/demo/images/lock_outline.svg
@@ -0,0 +1,6 @@
+
\ No newline at end of file
diff --git a/src/DockManager.cpp b/src/DockManager.cpp
index 0b1950f..5d47394 100644
--- a/src/DockManager.cpp
+++ b/src/DockManager.cpp
@@ -122,6 +122,7 @@ struct DockManagerPrivate
Qt::ToolButtonStyle ToolBarStyleFloating = Qt::ToolButtonTextUnderIcon;
QSize ToolBarIconSizeDocked = QSize(16, 16);
QSize ToolBarIconSizeFloating = QSize(24, 24);
+ CDockWidget::DockWidgetFeatures LockedDockWidgetFeatures;
/**
* Private data constructor
@@ -1446,6 +1447,33 @@ QSize CDockManager::dockWidgetToolBarIconSize(CDockWidget::eState State) const
}
+//===========================================================================
+void CDockManager::lockDockWidgetFeaturesGlobally(CDockWidget::DockWidgetFeatures Value)
+{
+ // Limit the features to CDockWidget::GloballyLockableFeatures
+ Value &= CDockWidget::GloballyLockableFeatures;
+ if (d->LockedDockWidgetFeatures == Value)
+ {
+ return;
+ }
+
+ d->LockedDockWidgetFeatures = Value;
+ // Call the notifyFeaturesChanged() function for all dock widgets to update
+ // the state of the close and detach buttons
+ for (auto DockWidget : d->DockWidgetsMap)
+ {
+ DockWidget->notifyFeaturesChanged();
+ }
+}
+
+
+//===========================================================================
+CDockWidget::DockWidgetFeatures CDockManager::globallyLockedDockWidgetFeatures() const
+{
+ return d->LockedDockWidgetFeatures;
+}
+
+
} // namespace ads
//---------------------------------------------------------------------------
diff --git a/src/DockManager.h b/src/DockManager.h
index 4088e60..dcb2356 100644
--- a/src/DockManager.h
+++ b/src/DockManager.h
@@ -660,6 +660,38 @@ public:
*/
QSize dockWidgetToolBarIconSize(CDockWidget::eState State) const;
+ /**
+ * Returns all dock widget features that are globally locked by the dock
+ * manager.
+ * Globally locked features are removed from the features of all dock
+ * widgets.
+ */
+ CDockWidget::DockWidgetFeatures globallyLockedDockWidgetFeatures() const;
+
+ /**
+ * Globally Lock features of all dock widgets to "freeze" the current
+ * workspace layout.
+ * For example, it is now possible to lock the workspace to avoid
+ * accidentally dragging a docked view. Locking wasn’t possible before.
+ * So, users had to manually dock it back to the desired place after
+ * each accidental undock.
+ * You can use a combination of the following feature flags:
+ * - CDockWidget::DockWidgetClosable
+ * - CDockWidget::DockWidgetMovable
+ * - CDockWidget::DockWidgetFloatable
+ * - CDockWidget::DockWidgetPinable
+ *
+ * To clear the locked features, you can use CDockWidget::NoDockWidgetFeatures
+ * The following code shows how to lock and unlock dock widget features
+ * globally.
+ *
+ * \code
+ * DockManager->lockDockWidgetFeaturesGlobally();
+ * DockManager->lockDockWidgetFeaturesGlobally(CDockWidget::NoDockWidgetFeatures);
+ * \code
+ */
+ void lockDockWidgetFeaturesGlobally(CDockWidget::DockWidgetFeatures Features = CDockWidget::GloballyLockableFeatures);
+
public Q_SLOTS:
/**
* Opens the perspective with the given name.
diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp
index b74c172..1185082 100644
--- a/src/DockWidget.cpp
+++ b/src/DockWidget.cpp
@@ -80,7 +80,7 @@ struct DockWidgetPrivate
QWidget* Widget = nullptr;
CDockWidgetTab* TabWidget = nullptr;
CDockWidget::DockWidgetFeatures Features = CDockWidget::DefaultDockWidgetFeatures;
- CDockManager* DockManager = nullptr;
+ QPointer DockManager;
QPointer DockArea;
QAction* ToggleViewAction = nullptr;
bool Closed = false;
@@ -511,10 +511,19 @@ void CDockWidget::setFeatures(DockWidgetFeatures features)
return;
}
d->Features = features;
+ notifyFeaturesChanged();
+}
+
+
+//============================================================================
+void CDockWidget::notifyFeaturesChanged()
+{
Q_EMIT featuresChanged(d->Features);
d->TabWidget->onDockWidgetFeaturesChanged();
if(CDockAreaWidget* DockArea = dockAreaWidget())
+ {
DockArea->onDockWidgetFeaturesChanged();
+ }
}
@@ -530,7 +539,14 @@ void CDockWidget::setFeature(DockWidgetFeature flag, bool on)
//============================================================================
CDockWidget::DockWidgetFeatures CDockWidget::features() const
{
- return d->Features;
+ if (d->DockManager)
+ {
+ return d->Features &~ d->DockManager->globallyLockedDockWidgetFeatures();
+ }
+ else
+ {
+ return d->Features;
+ }
}
diff --git a/src/DockWidget.h b/src/DockWidget.h
index e423101..0d6b88c 100644
--- a/src/DockWidget.h
+++ b/src/DockWidget.h
@@ -165,6 +165,7 @@ public:
DefaultDockWidgetFeatures = DockWidgetClosable | DockWidgetMovable | DockWidgetFloatable | DockWidgetFocusable | DockWidgetPinnable,
AllDockWidgetFeatures = DefaultDockWidgetFeatures | DockWidgetDeleteOnClose | CustomCloseHandling,
DockWidgetAlwaysCloseAndDelete = DockWidgetForceCloseWithArea | DockWidgetDeleteOnClose,
+ GloballyLockableFeatures = DockWidgetClosable | DockWidgetMovable | DockWidgetFloatable | DockWidgetPinnable,
NoDockWidgetFeatures = 0x000
};
Q_DECLARE_FLAGS(DockWidgetFeatures, DockWidgetFeature)
@@ -336,6 +337,11 @@ public:
*/
DockWidgetFeatures features() const;
+ /**
+ * Triggers notification of feature change signals and functions
+ */
+ void notifyFeaturesChanged();
+
/**
* Returns the dock manager that manages the dock widget or 0 if the widget
* has not been assigned to any dock manager yet