mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-26 08:01:32 +08:00
Changed DockFocusController to properly handle window activation
This commit is contained in:
parent
8d1465a81f
commit
5af7492b67
@ -609,7 +609,6 @@ CMainWindow::CMainWindow(QWidget *parent) :
|
|||||||
// uncomment the following line to enable focus highlighting of the dock
|
// uncomment the following line to enable focus highlighting of the dock
|
||||||
// widget that has the focus
|
// widget that has the focus
|
||||||
CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true);
|
CDockManager::setConfigFlag(CDockManager::FocusHighlighting, true);
|
||||||
CDockManager::setConfigFlag(CDockManager::AllTabsHaveCloseButton, true);
|
|
||||||
|
|
||||||
// uncomment if you would like to enable an equal distribution of the
|
// uncomment if you would like to enable an equal distribution of the
|
||||||
// available size of a splitter to all contained dock widgets
|
// available size of a splitter to all contained dock widgets
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QAbstractButton>
|
#include <QAbstractButton>
|
||||||
|
#include <QWindow>
|
||||||
|
|
||||||
#include "DockWidget.h"
|
#include "DockWidget.h"
|
||||||
#include "DockAreaWidget.h"
|
#include "DockAreaWidget.h"
|
||||||
@ -115,6 +116,11 @@ void DockFocusControllerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto Window = DockWidget->dockContainer()->window()->windowHandle();
|
||||||
|
if (Window)
|
||||||
|
{
|
||||||
|
Window->setProperty("FocusedDockWidget", QVariant::fromValue<CDockWidget*>(DockWidget));
|
||||||
|
}
|
||||||
CDockAreaWidget* NewFocusedDockArea = nullptr;
|
CDockAreaWidget* NewFocusedDockArea = nullptr;
|
||||||
if (FocusedDockWidget)
|
if (FocusedDockWidget)
|
||||||
{
|
{
|
||||||
@ -206,6 +212,8 @@ CDockFocusController::CDockFocusController(CDockManager* DockManager) :
|
|||||||
d->DockManager = DockManager;
|
d->DockManager = DockManager;
|
||||||
connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*, QWidget*)),
|
connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*, QWidget*)),
|
||||||
this, SLOT(onApplicationFocusChanged(QWidget*, QWidget*)));
|
this, SLOT(onApplicationFocusChanged(QWidget*, QWidget*)));
|
||||||
|
connect(QApplication::instance(), SIGNAL(focusWindowChanged(QWindow*)),
|
||||||
|
this, SLOT(onFocusWindowChanged(QWindow*)));
|
||||||
connect(d->DockManager, SIGNAL(stateRestored()), SLOT(onStateRestored()));
|
connect(d->DockManager, SIGNAL(stateRestored()), SLOT(onStateRestored()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,6 +224,30 @@ CDockFocusController::~CDockFocusController()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void CDockFocusController::onFocusWindowChanged(QWindow *focusWindow)
|
||||||
|
{
|
||||||
|
if (!focusWindow)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto vDockWidget = focusWindow->property("FocusedDockWidget");
|
||||||
|
if (!vDockWidget.isValid())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto DockWidget = vDockWidget.value<CDockWidget*>();
|
||||||
|
if (!DockWidget)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
d->updateDockWidgetFocus(DockWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidget* focusedNow)
|
void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidget* focusedNow)
|
||||||
{
|
{
|
||||||
@ -231,49 +263,7 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
CDockWidget* DockWidget = qobject_cast<CDockWidget*>(focusedNow);
|
||||||
// If the close button in another tab steals the focus from the current
|
|
||||||
// active dock widget content, i.e. if the user clicks its close button,
|
|
||||||
// then we immediately give the focus back to the previous focused widget
|
|
||||||
// focusedOld
|
|
||||||
if (CDockManager::testConfigFlag(CDockManager::AllTabsHaveCloseButton))
|
|
||||||
{
|
|
||||||
auto OtherDockWidgetTab = internal::findParent<CDockWidgetTab*>(focusedNow);
|
|
||||||
if (OtherDockWidgetTab && focusedOld)
|
|
||||||
{
|
|
||||||
auto OldFocusedDockWidget = internal::findParent<CDockWidget*>(focusedOld);
|
|
||||||
if (OldFocusedDockWidget)
|
|
||||||
{
|
|
||||||
//focusedOld->setFocus();
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
CDockWidget* DockWidget = nullptr;
|
|
||||||
/*auto DockWidgetTab = qobject_cast<CDockWidgetTab*>(focusedNow);
|
|
||||||
if (DockWidgetTab)
|
|
||||||
{
|
|
||||||
DockWidget = DockWidgetTab->dockWidget();
|
|
||||||
|
|
||||||
// If the DockWidgetTab "steals" the focus from a widget in the same
|
|
||||||
// DockWidget, then we immediately give the focus back to the previous
|
|
||||||
// focused widget focusedOld
|
|
||||||
if (focusedOld)
|
|
||||||
{
|
|
||||||
auto OldFocusedDockWidget = internal::findParent<CDockWidget*>(focusedOld);
|
|
||||||
if (OldFocusedDockWidget && OldFocusedDockWidget == DockWidget)
|
|
||||||
{
|
|
||||||
//focusedOld->setFocus();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (!DockWidget)
|
|
||||||
{
|
|
||||||
DockWidget = qobject_cast<CDockWidget*>(focusedNow);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!DockWidget)
|
if (!DockWidget)
|
||||||
{
|
{
|
||||||
DockWidget = internal::findParent<CDockWidget*>(focusedNow);
|
DockWidget = internal::findParent<CDockWidget*>(focusedNow);
|
||||||
@ -298,7 +288,6 @@ void CDockFocusController::onApplicationFocusChanged(QWidget* focusedOld, QWidge
|
|||||||
//===========================================================================
|
//===========================================================================
|
||||||
void CDockFocusController::setDockWidgetTabFocused(CDockWidgetTab* Tab)
|
void CDockFocusController::setDockWidgetTabFocused(CDockWidgetTab* Tab)
|
||||||
{
|
{
|
||||||
std::cout << "setDockWidgetTabFocused " << Tab->text().toStdString() << std::endl;
|
|
||||||
auto DockWidget = Tab->dockWidget();
|
auto DockWidget = Tab->dockWidget();
|
||||||
if (DockWidget)
|
if (DockWidget)
|
||||||
{
|
{
|
||||||
@ -334,7 +323,7 @@ void CDockFocusController::onFocusedDockAreaViewToggled(bool Open)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CDockManager::setWidgetFocus(OpenedDockAreas[0]->currentDockWidget()->tabWidget());
|
d->updateDockWidgetFocus(OpenedDockAreas[0]->currentDockWidget());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -362,7 +351,7 @@ void CDockFocusController::notifyWidgetOrAreaRelocation(QWidget* DroppedWidget)
|
|||||||
}
|
}
|
||||||
|
|
||||||
d->ForceFocusChangedSignal = true;
|
d->ForceFocusChangedSignal = true;
|
||||||
CDockManager::setWidgetFocus(DockWidget->tabWidget());
|
CDockManager::setWidgetFocus(DockWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -383,9 +372,15 @@ void CDockFocusController::notifyFloatingWidgetDrop(CFloatingDockContainer* Floa
|
|||||||
auto DockWidget = vDockWidget.value<CDockWidget*>();
|
auto DockWidget = vDockWidget.value<CDockWidget*>();
|
||||||
if (DockWidget)
|
if (DockWidget)
|
||||||
{
|
{
|
||||||
|
/*auto Window = DockWidget->dockContainer()->window()->windowHandle();
|
||||||
|
DockWidget->dockContainer()->window()->clearFocus();
|
||||||
|
if (Window)
|
||||||
|
{
|
||||||
|
Window->setProperty("FocusedDockWidget", QVariant::fromValue<CDockWidget*>(DockWidget));
|
||||||
|
}*/
|
||||||
d->FocusedDockWidget = nullptr;
|
d->FocusedDockWidget = nullptr;
|
||||||
DockWidget->dockAreaWidget()->setCurrentDockWidget(DockWidget);
|
DockWidget->dockAreaWidget()->setCurrentDockWidget(DockWidget);
|
||||||
CDockManager::setWidgetFocus(DockWidget->tabWidget());
|
CDockManager::setWidgetFocus(DockWidget);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ private:
|
|||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void onApplicationFocusChanged(QWidget *old, QWidget *now);
|
void onApplicationFocusChanged(QWidget *old, QWidget *now);
|
||||||
|
void onFocusWindowChanged(QWindow *focusWindow);
|
||||||
void onFocusedDockAreaViewToggled(bool Open);
|
void onFocusedDockAreaViewToggled(bool Open);
|
||||||
void onStateRestored();
|
void onStateRestored();
|
||||||
void onDockWidgetVisibilityChanged(bool Visible);
|
void onDockWidgetVisibilityChanged(bool Visible);
|
||||||
|
Loading…
Reference in New Issue
Block a user