mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-11-15 13:15:43 +08:00
Added CDockManager::lockDockWidgetFeaturesGlobally functionality to globally "freeze" the current docking layout
This commit is contained in:
parent
1a543e946d
commit
ed6636ae26
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,6 +68,7 @@ private slots:
|
||||
void toggleDockWidgetWindowTitle();
|
||||
void applyVsStyle();
|
||||
void createImageViewer();
|
||||
void lockWorkspace(bool Value);
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
@ -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
demo/images/lock.svg
Normal file
6
demo/images/lock.svg
Normal file
@ -0,0 +1,6 @@
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0,0,1024,1024">
|
||||
<desc>lock icon - Licensed under Apache License v2.0 (http://www.apache.org/licenses/LICENSE-2.0) - Created with Iconfu.com - Derivative work of Material icons (Copyright Google Inc.)</desc>
|
||||
<g fill="#03b8e5" fill-rule="nonzero" style="mix-blend-mode: normal">
|
||||
<path d="M853.33,426.67v426.66c0,46.93 -38.4,85.34 -85.33,85.34h-512c-46.93,0 -85.33,-38.41 -85.33,-85.34v-426.66c0,-46.93 38.4,-85.34 85.33,-85.34h42.67v-85.33c0,-117.76 95.57,-213.33 213.33,-213.33c117.76,0 213.33,95.57 213.33,213.33v85.33h42.67c46.93,0 85.33,38.41 85.33,85.34zM644.27,256c0,-72.96 -59.31,-132.27 -132.27,-132.27c-72.96,0 -132.27,59.31 -132.27,132.27v85.33h264.54zM597.33,640c0,-46.93 -38.4,-85.33 -85.33,-85.33c-46.93,0 -85.33,38.4 -85.33,85.33c0,46.93 38.4,85.33 85.33,85.33c46.93,0 85.33,-38.4 85.33,-85.33z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 932 B |
6
demo/images/lock_open.svg
Normal file
6
demo/images/lock_open.svg
Normal file
@ -0,0 +1,6 @@
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0,0,1024,1024">
|
||||
<desc>lock_open icon - Licensed under Apache License v2.0 (http://www.apache.org/licenses/LICENSE-2.0) - Created with Iconfu.com - Derivative work of Material icons (Copyright Google Inc.)</desc>
|
||||
<g fill="#03b8e5" fill-rule="nonzero" style="mix-blend-mode: normal">
|
||||
<path d="M853.33,426.67v426.66c0,46.93 -38.4,85.34 -85.33,85.34h-512c-46.93,0 -85.33,-38.41 -85.33,-85.34v-426.66c0,-46.93 38.4,-85.34 85.33,-85.34h388.27v-85.33c0,-72.96 -59.31,-132.27 -132.27,-132.27c-72.96,0 -132.27,59.31 -132.27,132.27h-81.06c0,-117.76 95.57,-213.33 213.33,-213.33c117.76,0 213.33,95.57 213.33,213.33v85.33h42.67c46.93,0 85.33,38.41 85.33,85.34zM768,426.67h-512v426.66h512zM426.67,640c0,-46.93 38.4,-85.33 85.33,-85.33c46.93,0 85.33,38.4 85.33,85.33c0,46.93 -38.4,85.33 -85.33,85.33c-46.93,0 -85.33,-38.4 -85.33,-85.33z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 948 B |
6
demo/images/lock_outline.svg
Normal file
6
demo/images/lock_outline.svg
Normal file
@ -0,0 +1,6 @@
|
||||
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0,0,1024,1024">
|
||||
<desc>lock_outline icon - Licensed under Apache License v2.0 (http://www.apache.org/licenses/LICENSE-2.0) - Created with Iconfu.com - Derivative work of Material icons (Copyright Google Inc.)</desc>
|
||||
<g fill="#03b8e5" fill-rule="nonzero" style="mix-blend-mode: normal">
|
||||
<path d="M853.33,426.67v426.66c0,46.93 -38.4,85.34 -85.33,85.34h-512c-46.93,0 -85.33,-38.41 -85.33,-85.34v-426.66c0,-46.93 38.4,-85.34 85.33,-85.34h42.67v-85.33c0,-117.76 95.57,-213.33 213.33,-213.33c117.76,0 213.33,95.57 213.33,213.33v85.33h42.67c46.93,0 85.33,38.41 85.33,85.34zM768,426.67h-512v426.66h512zM379.73,341.33h264.54v-85.33c0,-72.96 -59.31,-132.27 -132.27,-132.27c-72.96,0 -132.27,59.31 -132.27,132.27zM426.67,640c0,-46.93 38.4,-85.33 85.33,-85.33c46.93,0 85.33,38.4 85.33,85.33c0,46.93 -38.4,85.33 -85.33,85.33c-46.93,0 -85.33,-38.4 -85.33,-85.33z"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 972 B |
@ -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
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user