Skip to content

Commit ed6636a

Browse files
Added CDockManager::lockDockWidgetFeaturesGlobally functionality to globally "freeze" the current docking layout
1 parent 1a543e9 commit ed6636a

File tree

10 files changed

+137
-8
lines changed

10 files changed

+137
-8
lines changed

demo/MainWindow.cpp

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -592,19 +592,29 @@ void MainWindowPrivate::createActions()
592592
ui.toolBar->addAction(ui.actionRestoreState);
593593
ui.actionRestoreState->setIcon(svgIcon(":/adsdemo/images/restore.svg"));
594594

595-
SavePerspectiveAction = new QAction("Create Perspective", _this);
596-
SavePerspectiveAction->setIcon(svgIcon(":/adsdemo/images/picture_in_picture.svg"));
597-
_this->connect(SavePerspectiveAction, SIGNAL(triggered()), SLOT(savePerspective()));
595+
ui.toolBar->addSeparator();
596+
597+
QAction* a = ui.toolBar->addAction("Lock Workspace");
598+
a->setIcon(svgIcon(":/adsdemo/images/lock_outline.svg"));
599+
a->setCheckable(true);
600+
a->setChecked(false);
601+
QObject::connect(a, &QAction::triggered, _this, &CMainWindow::lockWorkspace);
602+
598603
PerspectiveListAction = new QWidgetAction(_this);
599604
PerspectiveComboBox = new QComboBox(_this);
600605
PerspectiveComboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
601-
PerspectiveComboBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
606+
PerspectiveComboBox->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
602607
PerspectiveListAction->setDefaultWidget(PerspectiveComboBox);
603-
ui.toolBar->addSeparator();
604608
ui.toolBar->addAction(PerspectiveListAction);
609+
610+
a = SavePerspectiveAction = ui.toolBar->addAction("Create Perspective");
611+
a->setIcon(svgIcon(":/adsdemo/images/picture_in_picture.svg"));
612+
QObject::connect(a, &QAction::triggered, _this, &CMainWindow::savePerspective);
605613
ui.toolBar->addAction(SavePerspectiveAction);
606614

607-
QAction* a = ui.toolBar->addAction("Create Floating Editor");
615+
ui.toolBar->addSeparator();
616+
617+
a = ui.toolBar->addAction("Create Floating Editor");
608618
a->setProperty("Floating", true);
609619
a->setToolTip("Creates floating dynamic dockable editor windows that are deleted on close");
610620
a->setIcon(svgIcon(":/adsdemo/images/note_add.svg"));
@@ -626,6 +636,7 @@ void MainWindowPrivate::createActions()
626636
_this->connect(a, SIGNAL(triggered()), SLOT(createEditor()));
627637
ui.menuTests->addAction(a);
628638

639+
ui.toolBar->addSeparator();
629640
a = ui.toolBar->addAction("Create Floating Table");
630641
a->setToolTip("Creates floating dynamic dockable table with millions of entries");
631642
a->setIcon(svgIcon(":/adsdemo/images/grid_on.svg"));
@@ -1030,3 +1041,17 @@ void CMainWindow::createImageViewer()
10301041
}
10311042
}
10321043

1044+
1045+
//============================================================================
1046+
void CMainWindow::lockWorkspace(bool Value)
1047+
{
1048+
if (Value)
1049+
{
1050+
d->DockManager->lockDockWidgetFeaturesGlobally();
1051+
}
1052+
else
1053+
{
1054+
d->DockManager->lockDockWidgetFeaturesGlobally(ads::CDockWidget::NoDockWidgetFeatures);
1055+
}
1056+
}
1057+

demo/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ private slots:
6868
void toggleDockWidgetWindowTitle();
6969
void applyVsStyle();
7070
void createImageViewer();
71+
void lockWorkspace(bool Value);
7172
};
7273

7374
#endif // MAINWINDOW_H

demo/demo.qrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,8 @@
3636
<file>images/panorama.svg</file>
3737
<file>images/ads_icon2.svg</file>
3838
<file>images/font_download.svg</file>
39+
<file>images/lock_outline.svg</file>
40+
<file>images/lock.svg</file>
41+
<file>images/lock_open.svg</file>
3942
</qresource>
4043
</RCC>

demo/images/lock.svg

Lines changed: 6 additions & 0 deletions
Loading

demo/images/lock_open.svg

Lines changed: 6 additions & 0 deletions
Loading

demo/images/lock_outline.svg

Lines changed: 6 additions & 0 deletions
Loading

src/DockManager.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ struct DockManagerPrivate
122122
Qt::ToolButtonStyle ToolBarStyleFloating = Qt::ToolButtonTextUnderIcon;
123123
QSize ToolBarIconSizeDocked = QSize(16, 16);
124124
QSize ToolBarIconSizeFloating = QSize(24, 24);
125+
CDockWidget::DockWidgetFeatures LockedDockWidgetFeatures;
125126

126127
/**
127128
* Private data constructor
@@ -1446,6 +1447,33 @@ QSize CDockManager::dockWidgetToolBarIconSize(CDockWidget::eState State) const
14461447
}
14471448

14481449

1450+
//===========================================================================
1451+
void CDockManager::lockDockWidgetFeaturesGlobally(CDockWidget::DockWidgetFeatures Value)
1452+
{
1453+
// Limit the features to CDockWidget::GloballyLockableFeatures
1454+
Value &= CDockWidget::GloballyLockableFeatures;
1455+
if (d->LockedDockWidgetFeatures == Value)
1456+
{
1457+
return;
1458+
}
1459+
1460+
d->LockedDockWidgetFeatures = Value;
1461+
// Call the notifyFeaturesChanged() function for all dock widgets to update
1462+
// the state of the close and detach buttons
1463+
for (auto DockWidget : d->DockWidgetsMap)
1464+
{
1465+
DockWidget->notifyFeaturesChanged();
1466+
}
1467+
}
1468+
1469+
1470+
//===========================================================================
1471+
CDockWidget::DockWidgetFeatures CDockManager::globallyLockedDockWidgetFeatures() const
1472+
{
1473+
return d->LockedDockWidgetFeatures;
1474+
}
1475+
1476+
14491477
} // namespace ads
14501478

14511479
//---------------------------------------------------------------------------

src/DockManager.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,38 @@ public Q_SLOTS:
660660
*/
661661
QSize dockWidgetToolBarIconSize(CDockWidget::eState State) const;
662662

663+
/**
664+
* Returns all dock widget features that are globally locked by the dock
665+
* manager.
666+
* Globally locked features are removed from the features of all dock
667+
* widgets.
668+
*/
669+
CDockWidget::DockWidgetFeatures globallyLockedDockWidgetFeatures() const;
670+
671+
/**
672+
* Globally Lock features of all dock widgets to "freeze" the current
673+
* workspace layout.
674+
* For example, it is now possible to lock the workspace to avoid
675+
* accidentally dragging a docked view. Locking wasn’t possible before.
676+
* So, users had to manually dock it back to the desired place after
677+
* each accidental undock.
678+
* You can use a combination of the following feature flags:
679+
* - CDockWidget::DockWidgetClosable
680+
* - CDockWidget::DockWidgetMovable
681+
* - CDockWidget::DockWidgetFloatable
682+
* - CDockWidget::DockWidgetPinable
683+
*
684+
* To clear the locked features, you can use CDockWidget::NoDockWidgetFeatures
685+
* The following code shows how to lock and unlock dock widget features
686+
* globally.
687+
*
688+
* \code
689+
* DockManager->lockDockWidgetFeaturesGlobally();
690+
* DockManager->lockDockWidgetFeaturesGlobally(CDockWidget::NoDockWidgetFeatures);
691+
* \code
692+
*/
693+
void lockDockWidgetFeaturesGlobally(CDockWidget::DockWidgetFeatures Features = CDockWidget::GloballyLockableFeatures);
694+
663695
public Q_SLOTS:
664696
/**
665697
* Opens the perspective with the given name.

src/DockWidget.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct DockWidgetPrivate
8080
QWidget* Widget = nullptr;
8181
CDockWidgetTab* TabWidget = nullptr;
8282
CDockWidget::DockWidgetFeatures Features = CDockWidget::DefaultDockWidgetFeatures;
83-
CDockManager* DockManager = nullptr;
83+
QPointer<CDockManager> DockManager;
8484
QPointer<CDockAreaWidget> DockArea;
8585
QAction* ToggleViewAction = nullptr;
8686
bool Closed = false;
@@ -511,10 +511,19 @@ void CDockWidget::setFeatures(DockWidgetFeatures features)
511511
return;
512512
}
513513
d->Features = features;
514+
notifyFeaturesChanged();
515+
}
516+
517+
518+
//============================================================================
519+
void CDockWidget::notifyFeaturesChanged()
520+
{
514521
Q_EMIT featuresChanged(d->Features);
515522
d->TabWidget->onDockWidgetFeaturesChanged();
516523
if(CDockAreaWidget* DockArea = dockAreaWidget())
524+
{
517525
DockArea->onDockWidgetFeaturesChanged();
526+
}
518527
}
519528

520529

@@ -530,7 +539,14 @@ void CDockWidget::setFeature(DockWidgetFeature flag, bool on)
530539
//============================================================================
531540
CDockWidget::DockWidgetFeatures CDockWidget::features() const
532541
{
533-
return d->Features;
542+
if (d->DockManager)
543+
{
544+
return d->Features &~ d->DockManager->globallyLockedDockWidgetFeatures();
545+
}
546+
else
547+
{
548+
return d->Features;
549+
}
534550
}
535551

536552

src/DockWidget.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ private Q_SLOTS:
165165
DefaultDockWidgetFeatures = DockWidgetClosable | DockWidgetMovable | DockWidgetFloatable | DockWidgetFocusable | DockWidgetPinnable,
166166
AllDockWidgetFeatures = DefaultDockWidgetFeatures | DockWidgetDeleteOnClose | CustomCloseHandling,
167167
DockWidgetAlwaysCloseAndDelete = DockWidgetForceCloseWithArea | DockWidgetDeleteOnClose,
168+
GloballyLockableFeatures = DockWidgetClosable | DockWidgetMovable | DockWidgetFloatable | DockWidgetPinnable,
168169
NoDockWidgetFeatures = 0x000
169170
};
170171
Q_DECLARE_FLAGS(DockWidgetFeatures, DockWidgetFeature)
@@ -336,6 +337,11 @@ private Q_SLOTS:
336337
*/
337338
DockWidgetFeatures features() const;
338339

340+
/**
341+
* Triggers notification of feature change signals and functions
342+
*/
343+
void notifyFeaturesChanged();
344+
339345
/**
340346
* Returns the dock manager that manages the dock widget or 0 if the widget
341347
* has not been assigned to any dock manager yet

0 commit comments

Comments
 (0)