Skip to content

Commit 312a8cf

Browse files
Enabled ClickFocus for CDockWidget to support focussing in case the content does not support it
Renamed FocusStyling to FocusHighlighting
1 parent 2fc8bbe commit 312a8cf

File tree

9 files changed

+60
-9
lines changed

9 files changed

+60
-9
lines changed

demo/MainWindow.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ static ads::CDockWidget* createFileSystemTreeDockWidget(QMenu* ViewMenu)
196196
.arg(FileSystemCount++));
197197
DockWidget->setWidget(w);
198198
ViewMenu->addAction(DockWidget->toggleViewAction());
199+
// We disable focus to test focus highlighting if the dock widget content
200+
// does not support focus
201+
w->setFocusPolicy(Qt::NoFocus);
199202
return DockWidget;
200203
}
201204

@@ -572,7 +575,7 @@ CMainWindow::CMainWindow(QWidget *parent) :
572575
// CDockManager::setConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar, true);
573576

574577
//CDockManager::setConfigFlag(CDockManager::AlwaysShowTabs, true);
575-
CDockManager::setConfigFlag(CDockManager::FocusStyling, true);
578+
CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true);
576579

577580
// Now create the dock manager and its content
578581
d->DockManager = new CDockManager(this);
@@ -659,6 +662,7 @@ void CMainWindow::onViewToggled(bool Open)
659662
//============================================================================
660663
void CMainWindow::onViewVisibilityChanged(bool Visible)
661664
{
665+
Q_UNUSED(Visible);
662666
auto DockWidget = qobject_cast<ads::CDockWidget*>(sender());
663667
if (!DockWidget)
664668
{

examples/deleteonclose/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int main(int argc, char *argv[])
1010
QApplication a(argc, argv);
1111
QMainWindow w;
1212

13-
ads::CDockManager::setConfigFlag(ads::CDockManager::FocusStyling, true);
13+
ads::CDockManager::setConfigFlag(ads::CDockManager::FocusHighlighting, true);
1414
auto dockManager = new ads::CDockManager(&w);
1515

1616
QAction *action = new QAction("New Delete On Close", &w);

src/DockAreaTitleBar.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,11 @@ void CDockAreaTitleBar::mousePressEvent(QMouseEvent* ev)
465465
ev->accept();
466466
d->DragStartMousePos = ev->pos();
467467
d->DragState = DraggingMousePressed;
468+
469+
if (CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting))
470+
{
471+
d->TabBar->currentTab()->setFocus(Qt::OtherFocusReason);
472+
}
468473
return;
469474
}
470475
Super::mousePressEvent(ev);
@@ -485,6 +490,7 @@ void CDockAreaTitleBar::mouseReleaseEvent(QMouseEvent* ev)
485490
{
486491
d->FloatingWidget->finishDragging();
487492
}
493+
488494
return;
489495
}
490496
Super::mouseReleaseEvent(ev);

src/DockFocusController.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,13 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge
202202
{
203203
DockWidget = DockWidgetTab->dockWidget();
204204
}
205-
else
205+
206+
if (!DockWidget)
207+
{
208+
DockWidget = qobject_cast<CDockWidget*>(focusedNow);
209+
}
210+
211+
if (!DockWidget)
206212
{
207213
DockWidget = internal::findParent<CDockWidget*>(focusedNow);
208214
}
@@ -226,6 +232,13 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge
226232
}
227233

228234

235+
//===========================================================================
236+
void CDockFocusController::setDockWidgetFocused(CDockWidget* focusedNow)
237+
{
238+
d->updateDockWidgetFocus(focusedNow);
239+
}
240+
241+
229242
//===========================================================================
230243
void CDockFocusController::onFocusedDockAreaViewToggled(bool Open)
231244
{

src/DockFocusController.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private slots:
5454
template <class QWidgetPtr>
5555
static void setWidgetFocus(QWidgetPtr widget)
5656
{
57-
if (!CDockManager::configFlags().testFlag(CDockManager::FocusStyling))
57+
if (!CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting))
5858
{
5959
return;
6060
}
@@ -75,6 +75,12 @@ private slots:
7575
* are already inserted into its new position
7676
*/
7777
void notifyFloatingWidgetDrop(CFloatingDockContainer* FloatingWidget);
78+
79+
public slots:
80+
/**
81+
* Request a focus change to the given dock widget
82+
*/
83+
void setDockWidgetFocused(CDockWidget* focusedNow);
7884
}; // class DockFocusController
7985
}
8086
// namespace ads

src/DockManager.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ CDockManager::CDockManager(QWidget *parent) :
467467
d->Containers.append(this);
468468
d->loadStylesheet();
469469

470-
if (CDockManager::configFlags().testFlag(CDockManager::FocusStyling))
470+
if (CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting))
471471
{
472472
d->FocusController = new CDockFocusController(this);
473473
}
@@ -926,6 +926,16 @@ void CDockManager::notifyFloatingWidgetDrop(CFloatingDockContainer* FloatingWidg
926926
}
927927

928928

929+
//===========================================================================
930+
void CDockManager::setDockWidgetFocused(CDockWidget* DockWidget)
931+
{
932+
if (d->FocusController)
933+
{
934+
d->FocusController->setDockWidgetFocused(DockWidget);
935+
}
936+
}
937+
938+
929939
} // namespace ads
930940

931941
//---------------------------------------------------------------------------

src/DockManager.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
178178
FloatingContainerHasWidgetIcon = 0x80000, //!< If set, the Floating Widget icon reflects the icon of the current dock widget otherwise it displays application icon
179179
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
180180
//!< this only makes sense for non draggable and non floatable widgets and enables the creation of some kind of "central" widget
181-
FocusStyling = 0x200000, //!< enables styling of focused dock widget tabs or floating widget titlebar
181+
FocusHighlighting = 0x200000, //!< enables styling of focused dock widget tabs or floating widget titlebar
182182

183183
DefaultDockAreaButtons = DockAreaHasCloseButton
184184
| DockAreaHasUndockButton
@@ -434,7 +434,7 @@ class ADS_EXPORT CDockManager : public CDockContainerWidget
434434
template <class QWidgetPtr>
435435
static void setWidgetFocus(QWidgetPtr widget)
436436
{
437-
if (!CDockManager::configFlags().testFlag(CDockManager::FocusStyling))
437+
if (!CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting))
438438
{
439439
return;
440440
}
@@ -448,6 +448,13 @@ public slots:
448448
*/
449449
void openPerspective(const QString& PerspectiveName);
450450

451+
/**
452+
* Request a focus change to the given dock widget.
453+
* This function only has an effect, if the flag CDockManager::FocusStyling
454+
* is enabled
455+
*/
456+
void setDockWidgetFocused(CDockWidget* DockWidget);
457+
451458
signals:
452459
/**
453460
* This signal is emitted if the list of perspectives changed

src/DockWidget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ CDockWidget::CDockWidget(const QString &title, QWidget *parent) :
235235
connect(d->ToggleViewAction, SIGNAL(triggered(bool)), this,
236236
SLOT(toggleView(bool)));
237237
setToolbarFloatingStyle(false);
238+
239+
if (CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting))
240+
{
241+
setFocusPolicy(Qt::ClickFocus);
242+
}
238243
}
239244

240245
//============================================================================

src/DockWidgetTab.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ CDockWidgetTab::CDockWidgetTab(CDockWidget* DockWidget, QWidget *parent) :
285285
setAttribute(Qt::WA_NoMousePropagation, true);
286286
d->DockWidget = DockWidget;
287287
d->createLayout();
288-
if (CDockManager::configFlags().testFlag(CDockManager::FocusStyling))
288+
if (CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting))
289289
{
290290
setFocusPolicy(Qt::ClickFocus);
291291
}
@@ -468,7 +468,7 @@ void CDockWidgetTab::setActiveTab(bool active)
468468
d->CloseButton->setVisible(DockWidgetClosable && TabHasCloseButton);
469469

470470
// Focus related stuff
471-
if (CDockManager::configFlags().testFlag(CDockManager::FocusStyling) && !d->DockWidget->dockManager()->isRestoringState())
471+
if (CDockManager::configFlags().testFlag(CDockManager::FocusHighlighting) && !d->DockWidget->dockManager()->isRestoringState())
472472
{
473473
bool UpdateFocusStyle = false;
474474
if (active && !hasFocus())

0 commit comments

Comments
 (0)