mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-25 23:51:33 +08:00
Some refactorings in onFocusChanged() to improve code readibility
This commit is contained in:
parent
789f78354a
commit
3a0c2a3113
@ -442,8 +442,8 @@ CDockManager::CDockManager(QWidget *parent) :
|
|||||||
d->ContainerOverlay = new CDockOverlay(this, CDockOverlay::ModeContainerOverlay);
|
d->ContainerOverlay = new CDockOverlay(this, CDockOverlay::ModeContainerOverlay);
|
||||||
d->Containers.append(this);
|
d->Containers.append(this);
|
||||||
d->loadStylesheet();
|
d->loadStylesheet();
|
||||||
connect(QGuiApplication::instance(), SIGNAL(focusObjectChanged(QObject*)),
|
connect(QApplication::instance(), SIGNAL(focusChanged(QWidget*, QWidget*)),
|
||||||
this, SLOT(onFocusObjectChanged(QObject*)));
|
this, SLOT(onFocusChanged(QWidget*, QWidget*)));
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
@ -880,29 +880,42 @@ CIconProvider& CDockManager::iconProvider()
|
|||||||
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
void CDockManager::onFocusObjectChanged(QObject *focusObject)
|
void updateDockWidgetFocusStyle(CDockWidget* DockWidget, bool Focused)
|
||||||
{
|
{
|
||||||
if (!focusObject)
|
DockWidget->setProperty("focused", Focused);
|
||||||
{
|
DockWidget->tabWidget()->setProperty("focused", Focused);
|
||||||
return;
|
DockWidget->tabWidget()->updateStyle();
|
||||||
}
|
internal::repolishStyle(DockWidget);
|
||||||
|
}
|
||||||
|
|
||||||
auto FocusWidget = qobject_cast<QWidget*>(focusObject);
|
|
||||||
if (!FocusWidget)
|
//===========================================================================
|
||||||
|
void updateDockAreaFocusStyle(CDockAreaWidget* DockArea, bool Focused)
|
||||||
|
{
|
||||||
|
DockArea->setProperty("focused", Focused);
|
||||||
|
internal::repolishStyle(DockArea);
|
||||||
|
internal::repolishStyle(DockArea->titleBar());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
void CDockManager::onFocusChanged(QWidget* focusedOld, QWidget* focusedNow)
|
||||||
|
{
|
||||||
|
Q_UNUSED(focusedOld)
|
||||||
|
if (!focusedNow)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CDockWidget* DockWidget = nullptr;
|
CDockWidget* DockWidget = nullptr;
|
||||||
|
auto DockWidgetTab = qobject_cast<CDockWidgetTab*>(focusedNow);
|
||||||
auto DockWidgetTab = qobject_cast<CDockWidgetTab*>(focusObject);
|
|
||||||
if (DockWidgetTab)
|
if (DockWidgetTab)
|
||||||
{
|
{
|
||||||
DockWidget = DockWidgetTab->dockWidget();
|
DockWidget = DockWidgetTab->dockWidget();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DockWidget = internal::findParent<CDockWidget*>(FocusWidget);
|
DockWidget = internal::findParent<CDockWidget*>(focusedNow);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DockWidget)
|
if (!DockWidget)
|
||||||
@ -910,32 +923,14 @@ void CDockManager::onFocusObjectChanged(QObject *focusObject)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<CDockWidget*> DockWidgets;
|
|
||||||
CDockAreaWidget* NewFocusedDockArea = nullptr;
|
CDockAreaWidget* NewFocusedDockArea = nullptr;
|
||||||
if (d->FocusedDockWidget)
|
if (d->FocusedDockWidget)
|
||||||
{
|
{
|
||||||
|
updateDockWidgetFocusStyle(d->FocusedDockWidget, false);
|
||||||
d->FocusedDockWidget->setProperty("focused", false);
|
|
||||||
d->FocusedDockWidget->tabWidget()->setProperty("focused", false);
|
|
||||||
DockWidgets.append(d->FocusedDockWidget);
|
|
||||||
}
|
}
|
||||||
d->FocusedDockWidget = DockWidget;
|
d->FocusedDockWidget = DockWidget;
|
||||||
d->FocusedDockWidget->setProperty("focused", true);
|
updateDockWidgetFocusStyle(d->FocusedDockWidget, true);
|
||||||
d->FocusedDockWidget->tabWidget()->setProperty("focused", true);
|
|
||||||
//connect(d->FocusedDockWidget, SIGNAL(closed()), this, SLOT(onFocusedDockWidgetClosed()));
|
|
||||||
NewFocusedDockArea = d->FocusedDockWidget->dockAreaWidget();
|
NewFocusedDockArea = d->FocusedDockWidget->dockAreaWidget();
|
||||||
if (NewFocusedDockArea)
|
|
||||||
{
|
|
||||||
NewFocusedDockArea->setProperty("focused", true);
|
|
||||||
}
|
|
||||||
DockWidgets.append(d->FocusedDockWidget);
|
|
||||||
|
|
||||||
for (auto DockWidget : DockWidgets)
|
|
||||||
{
|
|
||||||
DockWidget->tabWidget()->updateStyle();
|
|
||||||
internal::repolishStyle(DockWidget);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!NewFocusedDockArea || (d->FocusedArea == NewFocusedDockArea))
|
if (!NewFocusedDockArea || (d->FocusedArea == NewFocusedDockArea))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -944,26 +939,15 @@ void CDockManager::onFocusObjectChanged(QObject *focusObject)
|
|||||||
if (d->FocusedArea)
|
if (d->FocusedArea)
|
||||||
{
|
{
|
||||||
disconnect(d->FocusedArea, SIGNAL(viewToggled(bool)), this, SLOT(onFocusedDockAreaViewToggled(bool)));
|
disconnect(d->FocusedArea, SIGNAL(viewToggled(bool)), this, SLOT(onFocusedDockAreaViewToggled(bool)));
|
||||||
d->FocusedArea->setProperty("focused", false);
|
updateDockAreaFocusStyle(d->FocusedArea, false);
|
||||||
internal::repolishStyle(d->FocusedArea);
|
|
||||||
internal::repolishStyle(d->FocusedArea->titleBar());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NewFocusedDockArea->setProperty("focused", true);
|
|
||||||
internal::repolishStyle(NewFocusedDockArea);
|
|
||||||
internal::repolishStyle(NewFocusedDockArea->titleBar());
|
|
||||||
d->FocusedArea = NewFocusedDockArea;
|
d->FocusedArea = NewFocusedDockArea;
|
||||||
|
updateDockAreaFocusStyle(d->FocusedArea, true);
|
||||||
connect(d->FocusedArea, SIGNAL(viewToggled(bool)), this, SLOT(onFocusedDockAreaViewToggled(bool)));
|
connect(d->FocusedArea, SIGNAL(viewToggled(bool)), this, SLOT(onFocusedDockAreaViewToggled(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void CDockManager::onFocusedDockWidgetClosed()
|
|
||||||
{
|
|
||||||
std::cout << "CDockManager::onFocusedDockWidgetClosed()" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
void CDockManager::onFocusedDockAreaViewToggled(bool Open)
|
void CDockManager::onFocusedDockAreaViewToggled(bool Open)
|
||||||
{
|
{
|
||||||
|
@ -85,8 +85,7 @@ private:
|
|||||||
friend class CDockAreaTitleBar;
|
friend class CDockAreaTitleBar;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onFocusObjectChanged(QObject *focusObject);
|
void onFocusChanged(QWidget *old, QWidget *now);
|
||||||
void onFocusedDockWidgetClosed();
|
|
||||||
void onFocusedDockAreaViewToggled(bool Open);
|
void onFocusedDockAreaViewToggled(bool Open);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
@ -72,11 +72,6 @@ protected:
|
|||||||
*/
|
*/
|
||||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
/**
|
|
||||||
* Update stylesheet style if a property changes
|
|
||||||
*/
|
|
||||||
void updateStyle();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using Super = QFrame;
|
using Super = QFrame;
|
||||||
/**
|
/**
|
||||||
@ -159,6 +154,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
void setElideMode(Qt::TextElideMode mode);
|
void setElideMode(Qt::TextElideMode mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update stylesheet style if a property changes
|
||||||
|
*/
|
||||||
|
void updateStyle();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void setVisible(bool visible) override;
|
virtual void setVisible(bool visible) override;
|
||||||
|
Loading…
Reference in New Issue
Block a user