Skip to content

Commit

Permalink
Added CDockManager::lockDockWidgetFeaturesGlobally functionality to g…
Browse files Browse the repository at this point in the history
…lobally "freeze" the current docking layout
  • Loading branch information
githubuser0xFFFF committed Jan 23, 2024
1 parent 1a543e9 commit ed6636a
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 8 deletions.
37 changes: 31 additions & 6 deletions demo/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand All @@ -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"));
Expand Down Expand Up @@ -1030,3 +1041,17 @@ void CMainWindow::createImageViewer()
}
}


//============================================================================
void CMainWindow::lockWorkspace(bool Value)
{
if (Value)
{
d->DockManager->lockDockWidgetFeaturesGlobally();
}
else
{
d->DockManager->lockDockWidgetFeaturesGlobally(ads::CDockWidget::NoDockWidgetFeatures);
}
}

1 change: 1 addition & 0 deletions demo/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private slots:
void toggleDockWidgetWindowTitle();
void applyVsStyle();
void createImageViewer();
void lockWorkspace(bool Value);
};

#endif // MAINWINDOW_H
3 changes: 3 additions & 0 deletions demo/demo.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,8 @@
<file>images/panorama.svg</file>
<file>images/ads_icon2.svg</file>
<file>images/font_download.svg</file>
<file>images/lock_outline.svg</file>
<file>images/lock.svg</file>
<file>images/lock_open.svg</file>
</qresource>
</RCC>
6 changes: 6 additions & 0 deletions demo/images/lock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions demo/images/lock_open.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions demo/images/lock_outline.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions src/DockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

//---------------------------------------------------------------------------
Expand Down
32 changes: 32 additions & 0 deletions src/DockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,38 @@ public Q_SLOTS:
*/
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.
Expand Down
20 changes: 18 additions & 2 deletions src/DockWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ struct DockWidgetPrivate
QWidget* Widget = nullptr;
CDockWidgetTab* TabWidget = nullptr;
CDockWidget::DockWidgetFeatures Features = CDockWidget::DefaultDockWidgetFeatures;
CDockManager* DockManager = nullptr;
QPointer<CDockManager> DockManager;
QPointer<CDockAreaWidget> DockArea;
QAction* ToggleViewAction = nullptr;
bool Closed = false;
Expand Down Expand Up @@ -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();
}
}


Expand All @@ -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;
}
}


Expand Down
6 changes: 6 additions & 0 deletions src/DockWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private Q_SLOTS:
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)
Expand Down Expand Up @@ -336,6 +337,11 @@ private Q_SLOTS:
*/
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
Expand Down

0 comments on commit ed6636a

Please sign in to comment.