Skip to content

Commit c939df7

Browse files
Merge branch 'focused_dockwidget'
2 parents fdf169c + ff3fcdc commit c939df7

27 files changed

+1186
-249
lines changed

demo/MainWindow.cpp

Lines changed: 8 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

@@ -571,6 +574,9 @@ CMainWindow::CMainWindow(QWidget *parent) :
571574
// dock widget.
572575
// CDockManager::setConfigFlag(CDockManager::HideSingleCentralWidgetTitleBar, true);
573576

577+
//CDockManager::setConfigFlag(CDockManager::AlwaysShowTabs, true);
578+
CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true);
579+
574580
// Now create the dock manager and its content
575581
d->DockManager = new CDockManager(this);
576582

@@ -656,13 +662,14 @@ void CMainWindow::onViewToggled(bool Open)
656662
//============================================================================
657663
void CMainWindow::onViewVisibilityChanged(bool Visible)
658664
{
665+
Q_UNUSED(Visible);
659666
auto DockWidget = qobject_cast<ads::CDockWidget*>(sender());
660667
if (!DockWidget)
661668
{
662669
return;
663670
}
664671

665-
qDebug() << DockWidget->objectName() << " visibilityChanged(" << Visible << ")";
672+
//qDebug() << DockWidget->objectName() << " visibilityChanged(" << Visible << ")";
666673
}
667674

668675

examples/deleteonclose/main.cpp

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

13+
ads::CDockManager::setConfigFlag(ads::CDockManager::FocusHighlighting, true);
1314
auto dockManager = new ads::CDockManager(&w);
1415

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

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ set(ads_SRCS
1717
DockWidget.cpp
1818
DockWidgetTab.cpp
1919
DockingStateReader.cpp
20+
DockFocusController.cpp
2021
ElidingLabel.cpp
2122
FloatingDockContainer.cpp
2223
FloatingDragPreview.cpp
@@ -37,6 +38,7 @@ set(ads_INSTALL_INCLUDE
3738
DockWidget.h
3839
DockWidgetTab.h
3940
DockingStateReader.h
41+
DockFocusController.h
4042
ElidingLabel.h
4143
FloatingDockContainer.h
4244
FloatingDragPreview.h

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/DockAreaWidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
413413
bool Activate)
414414
{
415415
d->ContentsLayout->insertWidget(index, DockWidget);
416+
DockWidget->setDockArea(this);
416417
DockWidget->tabWidget()->setDockAreaWidget(this);
417418
auto TabWidget = DockWidget->tabWidget();
418419
// Inserting the tab will change the current index which in turn will
@@ -428,7 +429,6 @@ void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget,
428429
{
429430
setCurrentIndex(index);
430431
}
431-
DockWidget->setDockArea(this);
432432
// If this dock area is hidden, then we need to make it visible again
433433
// by calling DockWidget->toggleViewInternal(true);
434434
if (!this->isVisible() && d->ContentsLayout->count() > 1 && !dockManager()->isRestoringState())

src/DockContainerWidget.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,13 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
14591459
// level widget anymore
14601460
CDockWidget::emitTopLevelEventForWidget(SingleDockWidget, false);
14611461
}
1462+
1463+
window()->activateWindow();
1464+
if (SingleDroppedDockWidget)
1465+
{
1466+
d->DockManager->notifyWidgetOrAreaRelocation(SingleDroppedDockWidget);
1467+
}
1468+
d->DockManager->notifyFloatingWidgetDrop(FloatingWidget);
14621469
}
14631470

14641471

@@ -1478,6 +1485,19 @@ void CDockContainerWidget::dropWidget(QWidget* Widget, DockWidgetArea DropArea,
14781485
// If there was a top level widget before the drop, then it is not top
14791486
// level widget anymore
14801487
CDockWidget::emitTopLevelEventForWidget(SingleDockWidget, false);
1488+
CDockWidget* DockWidget = qobject_cast<CDockWidget*>(Widget);
1489+
if (!DockWidget)
1490+
{
1491+
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(Widget);
1492+
auto OpenDockWidgets = DockArea->openedDockWidgets();
1493+
if (OpenDockWidgets.count() == 1)
1494+
{
1495+
DockWidget = OpenDockWidgets[0];
1496+
}
1497+
}
1498+
1499+
window()->activateWindow();
1500+
d->DockManager->notifyWidgetOrAreaRelocation(Widget);
14811501
}
14821502

14831503

src/DockContainerWidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class ADS_EXPORT CDockContainerWidget : public QFrame
193193
bool isInFrontOf(CDockContainerWidget* Other) const;
194194

195195
/**
196-
* Returns the dock area at teh given global position or 0 if there is no
196+
* Returns the dock area at the given global position or 0 if there is no
197197
* dock area at this position
198198
*/
199199
CDockAreaWidget* dockAreaAt(const QPoint& GlobalPos) const;

0 commit comments

Comments
 (0)