diff --git a/demo/MainWindow.cpp b/demo/MainWindow.cpp index 56b59a0..c9016a4 100644 --- a/demo/MainWindow.cpp +++ b/demo/MainWindow.cpp @@ -196,6 +196,9 @@ static ads::CDockWidget* createFileSystemTreeDockWidget(QMenu* ViewMenu) .arg(FileSystemCount++)); DockWidget->setWidget(w); ViewMenu->addAction(DockWidget->toggleViewAction()); + // We disable focus to test focus highlighting if the dock widget content + // does not support focus + w->setFocusPolicy(Qt::NoFocus); return DockWidget; } @@ -572,7 +575,7 @@ CMainWindow::CMainWindow(QWidget *parent) : // CDockManager::setConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar, true); //CDockManager::setConfigFlag(CDockManager::AlwaysShowTabs, true); - CDockManager::setConfigFlag(CDockManager::FocusStyling, true); + CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true); // Now create the dock manager and its content d->DockManager = new CDockManager(this); @@ -659,6 +662,7 @@ void CMainWindow::onViewToggled(bool Open) //============================================================================ void CMainWindow::onViewVisibilityChanged(bool Visible) { + Q_UNUSED(Visible); auto DockWidget = qobject_cast(sender()); if (!DockWidget) { diff --git a/examples/deleteonclose/main.cpp b/examples/deleteonclose/main.cpp index f217dd0..2f08ffe 100644 --- a/examples/deleteonclose/main.cpp +++ b/examples/deleteonclose/main.cpp @@ -10,7 +10,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); QMainWindow w; - ads::CDockManager::setConfigFlag(ads::CDockManager::FocusStyling, true); + ads::CDockManager::setConfigFlag(ads::CDockManager::FocusHighlighting, true); auto dockManager = new ads::CDockManager(&w); QAction *action = new QAction("New Delete On Close", &w); diff --git a/src/DockAreaTitleBar.cpp b/src/DockAreaTitleBar.cpp index aec4cc9..61142e1 100644 --- a/src/DockAreaTitleBar.cpp +++ b/src/DockAreaTitleBar.cpp @@ -465,6 +465,11 @@ void CDockAreaTitleBar::mousePressEvent(QMouseEvent* ev) ev->accept(); d->DragStartMousePos = ev->pos(); d->DragState = DraggingMousePressed; + + if (CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting)) + { + d->TabBar->currentTab()->setFocus(Qt::OtherFocusReason); + } return; } Super::mousePressEvent(ev); @@ -485,6 +490,7 @@ void CDockAreaTitleBar::mouseReleaseEvent(QMouseEvent* ev) { d->FloatingWidget->finishDragging(); } + return; } Super::mouseReleaseEvent(ev); diff --git a/src/DockFocusController.cpp b/src/DockFocusController.cpp index ea81d1b..409d854 100644 --- a/src/DockFocusController.cpp +++ b/src/DockFocusController.cpp @@ -202,7 +202,13 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge { DockWidget = DockWidgetTab->dockWidget(); } - else + + if (!DockWidget) + { + DockWidget = qobject_cast(focusedNow); + } + + if (!DockWidget) { DockWidget = internal::findParent(focusedNow); } @@ -226,6 +232,13 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge } +//=========================================================================== +void CDockFocusController::setDockWidgetFocused(CDockWidget* focusedNow) +{ + d->updateDockWidgetFocus(focusedNow); +} + + //=========================================================================== void CDockFocusController::onFocusedDockAreaViewToggled(bool Open) { diff --git a/src/DockFocusController.h b/src/DockFocusController.h index cff65bf..f93b485 100644 --- a/src/DockFocusController.h +++ b/src/DockFocusController.h @@ -54,7 +54,7 @@ public: template static void setWidgetFocus(QWidgetPtr widget) { - if (!CDockManager::configFlags().testFlag(CDockManager::FocusStyling)) + if (!CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting)) { return; } @@ -75,6 +75,12 @@ public: * are already inserted into its new position */ void notifyFloatingWidgetDrop(CFloatingDockContainer* FloatingWidget); + +public slots: + /** + * Request a focus change to the given dock widget + */ + void setDockWidgetFocused(CDockWidget* focusedNow); }; // class DockFocusController } // namespace ads diff --git a/src/DockManager.cpp b/src/DockManager.cpp index 9ff7a08..84b97f2 100644 --- a/src/DockManager.cpp +++ b/src/DockManager.cpp @@ -467,7 +467,7 @@ CDockManager::CDockManager(QWidget *parent) : d->Containers.append(this); d->loadStylesheet(); - if (CDockManager::configFlags().testFlag(CDockManager::FocusStyling)) + if (CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting)) { d->FocusController = new CDockFocusController(this); } @@ -926,6 +926,16 @@ void CDockManager::notifyFloatingWidgetDrop(CFloatingDockContainer* FloatingWidg } +//=========================================================================== +void CDockManager::setDockWidgetFocused(CDockWidget* DockWidget) +{ + if (d->FocusController) + { + d->FocusController->setDockWidgetFocused(DockWidget); + } +} + + } // namespace ads //--------------------------------------------------------------------------- diff --git a/src/DockManager.h b/src/DockManager.h index 1a5fc2c..6a9fb1f 100644 --- a/src/DockManager.h +++ b/src/DockManager.h @@ -178,7 +178,7 @@ public: FloatingContainerHasWidgetIcon = 0x80000, //!< If set, the Floating Widget icon reflects the icon of the current dock widget otherwise it displays application icon HideSingleCentralWidgetTitleBar = 0x100000, //!< If there is only one single visible dock widget in the main dock container (the dock manager) and if this flag is set, then the titlebar of this dock widget will be hidden //!< this only makes sense for non draggable and non floatable widgets and enables the creation of some kind of "central" widget - FocusStyling = 0x200000, //!< enables styling of focused dock widget tabs or floating widget titlebar + FocusHighlighting = 0x200000, //!< enables styling of focused dock widget tabs or floating widget titlebar DefaultDockAreaButtons = DockAreaHasCloseButton | DockAreaHasUndockButton @@ -434,7 +434,7 @@ public: template static void setWidgetFocus(QWidgetPtr widget) { - if (!CDockManager::configFlags().testFlag(CDockManager::FocusStyling)) + if (!CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting)) { return; } @@ -448,6 +448,13 @@ public slots: */ void openPerspective(const QString& PerspectiveName); + /** + * Request a focus change to the given dock widget. + * This function only has an effect, if the flag CDockManager::FocusStyling + * is enabled + */ + void setDockWidgetFocused(CDockWidget* DockWidget); + signals: /** * This signal is emitted if the list of perspectives changed diff --git a/src/DockWidget.cpp b/src/DockWidget.cpp index 0c5c2a2..3dba01b 100644 --- a/src/DockWidget.cpp +++ b/src/DockWidget.cpp @@ -235,6 +235,11 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) : connect(d->ToggleViewAction, SIGNAL(triggered(bool)), this, SLOT(toggleView(bool))); setToolbarFloatingStyle(false); + + if (CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting)) + { + setFocusPolicy(Qt::ClickFocus); + } } //============================================================================ diff --git a/src/DockWidgetTab.cpp b/src/DockWidgetTab.cpp index 28a0448..2341a1a 100644 --- a/src/DockWidgetTab.cpp +++ b/src/DockWidgetTab.cpp @@ -285,7 +285,7 @@ CDockWidgetTab::CDockWidgetTab(CDockWidget* DockWidget, QWidget *parent) : setAttribute(Qt::WA_NoMousePropagation, true); d->DockWidget = DockWidget; d->createLayout(); - if (CDockManager::configFlags().testFlag(CDockManager::FocusStyling)) + if (CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting)) { setFocusPolicy(Qt::ClickFocus); } @@ -468,7 +468,7 @@ void CDockWidgetTab::setActiveTab(bool active) d->CloseButton->setVisible(DockWidgetClosable && TabHasCloseButton); // Focus related stuff - if (CDockManager::configFlags().testFlag(CDockManager::FocusStyling) && !d->DockWidget->dockManager()->isRestoringState()) + if (CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting) && !d->DockWidget->dockManager()->isRestoringState()) { bool UpdateFocusStyle = false; if (active && !hasFocus())