From bd0b2ad483f9369d8d08a907fecddfa567fee714 Mon Sep 17 00:00:00 2001 From: Uwe Kindler Date: Sat, 5 Nov 2022 10:11:09 +0100 Subject: [PATCH] Improved title bar button tooltips and made naming consistend with context menu --- src/DockAreaTitleBar.cpp | 58 ++++++++++++++++++++++++++++++---------- src/DockAreaTitleBar.h | 2 +- src/DockAreaWidget.cpp | 9 ++++--- src/DockAreaWidget.h | 2 +- src/DockWidgetTab.cpp | 4 +-- 5 files changed, 54 insertions(+), 21 deletions(-) diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index 91737c2..02796af 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include "DockAreaTitleBar_p.h" #include "ads_globals.h" @@ -209,7 +210,7 @@ void DockAreaTitleBarPrivate::createButtons() AutoHideButton = new CTitleBarButton(testAutoHideConfigFlag(CDockManager::DockAreaHasAutoHideButton) && autoHideEnabled); AutoHideButton->setObjectName("dockAreaAutoHideButton"); AutoHideButton->setAutoRaise(true); - internal::setToolTip(AutoHideButton, QObject::tr("Toggle Auto Hide")); + internal::setToolTip(AutoHideButton, _this->titleBarButtonToolTip(TitleBarButtonAutoHide)); internal::setButtonIcon(AutoHideButton, QStyle::SP_DialogOkButton, ads::AutoHideIcon); AutoHideButton->setSizePolicy(ButtonSizePolicy); AutoHideButton->setCheckable(testAutoHideConfigFlag(CDockManager::AutoHideButtonCheckable)); @@ -222,7 +223,7 @@ void DockAreaTitleBarPrivate::createButtons() CloseButton->setObjectName("dockAreaCloseButton"); CloseButton->setAutoRaise(true); internal::setButtonIcon(CloseButton, QStyle::SP_TitleBarCloseButton, ads::DockAreaCloseIcon); - internal::setToolTip(CloseButton, _this->closeGroupToolTip()); + internal::setToolTip(CloseButton, _this->titleBarButtonToolTip(TitleBarButtonClose)); CloseButton->setSizePolicy(ButtonSizePolicy); CloseButton->setIconSize(QSize(16, 16)); Layout->addWidget(CloseButton, 0); @@ -507,7 +508,8 @@ void CDockAreaTitleBar::onCurrentTabChanged(int Index) //============================================================================ void CDockAreaTitleBar::onAutoHideButtonClicked() { - if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideButtonTogglesArea)) + if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideButtonTogglesArea) + || qApp->keyboardModifiers().testFlag(Qt::ControlModifier)) { d->DockArea->toggleAutoHide(); } @@ -698,13 +700,13 @@ void CDockAreaTitleBar::contextMenuEvent(QContextMenuEvent* ev) Action->setEnabled(d->DockArea->features().testFlag(CDockWidget::DockWidgetFloatable)); if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled)) { - Action = Menu.addAction(isAutoHide ? tr("Dock") : tr("Auto Hide Group"), this, SLOT(onAutoHideDockAreaActionClicked())); + Action = Menu.addAction(isAutoHide ? tr("Unpin (Dock)") : tr("Pin Group"), this, SLOT(onAutoHideDockAreaActionClicked())); auto AreaIsPinnable = d->DockArea->features().testFlag(CDockWidget::DockWidgetPinnable); Action->setEnabled(AreaIsPinnable); if (!isAutoHide) { - auto menu = Menu.addMenu(tr("Auto Hide Group To...")); + auto menu = Menu.addMenu(tr("Pin Group To...")); menu->setEnabled(AreaIsPinnable); d->createAutoHideToAction(tr("Top"), SideBarTop, menu); d->createAutoHideToAction(tr("Left"), SideBarLeft, menu); @@ -738,19 +740,47 @@ int CDockAreaTitleBar::indexOf(QWidget *widget) const } //============================================================================ -QString CDockAreaTitleBar::closeGroupToolTip() const +QString CDockAreaTitleBar::titleBarButtonToolTip(TitleBarButton Button) const { - if (d->DockArea->isAutoHide()) + switch (Button) { - return QObject::tr("Close Overlay"); - - } - if (CDockManager::testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab)) - { - return QObject::tr("Close Active Tab"); + case TitleBarButtonAutoHide: + if (d->DockArea->isAutoHide()) + { + return tr("Unpin (Dock)"); + } + + if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideButtonTogglesArea)) + { + return tr("Pin Group"); + } + else + { + return tr("Pin Active Tab (Press Ctrl to Pin Group)"); + } + break; + + case TitleBarButtonClose: + if (d->DockArea->isAutoHide()) + { + return tr("Close"); + } + + if (CDockManager::testConfigFlag(CDockManager::DockAreaCloseButtonClosesTab)) + { + return tr("Close Active Tab"); + } + else + { + return tr("Close Group"); + } + break; + + default: + break; } - return QObject::tr("Close Group") ; + return QString(); } //============================================================================ diff --git a/src/DockAreaTitleBar.h b/src/DockAreaTitleBar.h index 6cc8e50..a314640 100644 --- a/src/DockAreaTitleBar.h +++ b/src/DockAreaTitleBar.h @@ -161,7 +161,7 @@ public: * Close group tool tip based on the current state * Auto hide widgets can only have one dock widget so it does not make sense for the tooltip to show close group */ - QString closeGroupToolTip() const; + QString titleBarButtonToolTip(TitleBarButton Button) const; Q_SIGNALS: /** diff --git a/src/DockAreaWidget.cpp b/src/DockAreaWidget.cpp index 5d7df44..93c816b 100644 --- a/src/DockAreaWidget.cpp +++ b/src/DockAreaWidget.cpp @@ -465,7 +465,7 @@ void CDockAreaWidget::setAutoHideDockContainer(CAutoHideDockContainer* AutoHideD { d->AutoHideDockContainer = AutoHideDockContainer; updateAutoHideButtonCheckState(); - updateTitleBarButtonToolTip(); + updateTitleBarButtonsToolTips(); } @@ -880,9 +880,12 @@ void CDockAreaWidget::updateTitleBarButtonVisibility(bool IsTopLevel) const //============================================================================ -void CDockAreaWidget::updateTitleBarButtonToolTip() +void CDockAreaWidget::updateTitleBarButtonsToolTips() { - internal::setToolTip(titleBarButton(TitleBarButtonClose), titleBar()->closeGroupToolTip()); + internal::setToolTip(titleBarButton(TitleBarButtonClose), + titleBar()->titleBarButtonToolTip(TitleBarButtonClose)); + internal::setToolTip(titleBarButton(TitleBarButtonAutoHide), + titleBar()->titleBarButtonToolTip(TitleBarButtonAutoHide)); } diff --git a/src/DockAreaWidget.h b/src/DockAreaWidget.h index fface99..a3ef76c 100644 --- a/src/DockAreaWidget.h +++ b/src/DockAreaWidget.h @@ -87,7 +87,7 @@ private Q_SLOTS: /* * Update the title bar button tooltips */ - void updateTitleBarButtonToolTip(); + void updateTitleBarButtonsToolTips(); /** * Calculate the auto hide side bar location depending on the dock area diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index 5d1ce04..7a81942 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -532,11 +532,11 @@ void CDockWidgetTab::contextMenuEvent(QContextMenuEvent* ev) Action->setEnabled(isDetachable); if (CDockManager::testAutoHideConfigFlag(CDockManager::AutoHideFeatureEnabled)) { - Action = Menu.addAction(tr("Auto Hide"), this, SLOT(autoHideDockWidget())); + Action = Menu.addAction(tr("Pin"), this, SLOT(autoHideDockWidget())); auto IsPinnable = d->DockWidget->features().testFlag(CDockWidget::DockWidgetPinnable); Action->setEnabled(IsPinnable); - auto menu = Menu.addMenu(tr("Auto Hide To...")); + auto menu = Menu.addMenu(tr("Pin To...")); menu->setEnabled(IsPinnable); d->createAutoHideToAction(tr("Top"), SideBarTop, menu); d->createAutoHideToAction(tr("Left"), SideBarLeft, menu);