mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-26 08:01:32 +08:00
Improved focus style handling
This commit is contained in:
parent
e760d3e967
commit
79cb889d83
@ -1459,6 +1459,7 @@ void CDockContainerWidget::dropFloatingWidget(CFloatingDockContainer* FloatingWi
|
|||||||
//============================================================================
|
//============================================================================
|
||||||
void CDockContainerWidget::dropWidget(QWidget* Widget, DockWidgetArea DropArea, CDockAreaWidget* TargetAreaWidget)
|
void CDockContainerWidget::dropWidget(QWidget* Widget, DockWidgetArea DropArea, CDockAreaWidget* TargetAreaWidget)
|
||||||
{
|
{
|
||||||
|
std::cout << "dropWidget" << std::endl;
|
||||||
CDockWidget* SingleDockWidget = topLevelDockWidget();
|
CDockWidget* SingleDockWidget = topLevelDockWidget();
|
||||||
if (TargetAreaWidget)
|
if (TargetAreaWidget)
|
||||||
{
|
{
|
||||||
@ -1472,6 +1473,19 @@ void CDockContainerWidget::dropWidget(QWidget* Widget, DockWidgetArea DropArea,
|
|||||||
// If there was a top level widget before the drop, then it is not top
|
// If there was a top level widget before the drop, then it is not top
|
||||||
// level widget anymore
|
// level widget anymore
|
||||||
CDockWidget::emitTopLevelEventForWidget(SingleDockWidget, false);
|
CDockWidget::emitTopLevelEventForWidget(SingleDockWidget, false);
|
||||||
|
CDockWidget* DockWidget = qobject_cast<CDockWidget*>(Widget);
|
||||||
|
if (!DockWidget)
|
||||||
|
{
|
||||||
|
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(Widget);
|
||||||
|
auto OpenDockWidgets = DockArea->openedDockWidgets();
|
||||||
|
if (OpenDockWidgets.count() == 1)
|
||||||
|
{
|
||||||
|
DockWidget = OpenDockWidgets[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this->window()->activateWindow();
|
||||||
|
d->DockManager->emitWidgetDroppedSignals(Widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -153,6 +153,12 @@ struct DockManagerPrivate
|
|||||||
* Adds action to menu - optionally in sorted order
|
* Adds action to menu - optionally in sorted order
|
||||||
*/
|
*/
|
||||||
void addActionToMenu(QAction* Action, QMenu* Menu, bool InsertSorted);
|
void addActionToMenu(QAction* Action, QMenu* Menu, bool InsertSorted);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function updates the focus style of the given dock widget and
|
||||||
|
* the dock area that it belongs to
|
||||||
|
*/
|
||||||
|
void updateDockWidgetFocus(CDockWidget* DockWidget);
|
||||||
};
|
};
|
||||||
// struct DockManagerPrivate
|
// struct DockManagerPrivate
|
||||||
|
|
||||||
@ -425,6 +431,54 @@ void DockManagerPrivate::addActionToMenu(QAction* Action, QMenu* Menu, bool Inse
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
void updateDockWidgetFocusStyle(CDockWidget* DockWidget, bool Focused)
|
||||||
|
{
|
||||||
|
DockWidget->setProperty("focused", Focused);
|
||||||
|
DockWidget->tabWidget()->setProperty("focused", Focused);
|
||||||
|
DockWidget->tabWidget()->updateStyle();
|
||||||
|
internal::repolishStyle(DockWidget);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
void updateDockAreaFocusStyle(CDockAreaWidget* DockArea, bool Focused)
|
||||||
|
{
|
||||||
|
DockArea->setProperty("focused", Focused);
|
||||||
|
internal::repolishStyle(DockArea);
|
||||||
|
internal::repolishStyle(DockArea->titleBar());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//============================================================================
|
||||||
|
void DockManagerPrivate::updateDockWidgetFocus(CDockWidget* DockWidget)
|
||||||
|
{
|
||||||
|
CDockAreaWidget* NewFocusedDockArea = nullptr;
|
||||||
|
if (FocusedDockWidget)
|
||||||
|
{
|
||||||
|
updateDockWidgetFocusStyle(FocusedDockWidget, false);
|
||||||
|
}
|
||||||
|
FocusedDockWidget = DockWidget;
|
||||||
|
updateDockWidgetFocusStyle(FocusedDockWidget, true);
|
||||||
|
NewFocusedDockArea = FocusedDockWidget->dockAreaWidget();
|
||||||
|
if (!NewFocusedDockArea || (FocusedArea == NewFocusedDockArea))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FocusedArea)
|
||||||
|
{
|
||||||
|
std::cout << "FocusedArea" << std::endl;
|
||||||
|
QObject::disconnect(FocusedArea, SIGNAL(viewToggled(bool)), _this, SLOT(onFocusedDockAreaViewToggled(bool)));
|
||||||
|
updateDockAreaFocusStyle(FocusedArea, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
FocusedArea = NewFocusedDockArea;
|
||||||
|
updateDockAreaFocusStyle(FocusedArea, true);
|
||||||
|
QObject::connect(FocusedArea, SIGNAL(viewToggled(bool)), _this, SLOT(onFocusedDockAreaViewToggled(bool)));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
CDockManager::CDockManager(QWidget *parent) :
|
CDockManager::CDockManager(QWidget *parent) :
|
||||||
CDockContainerWidget(this, parent),
|
CDockContainerWidget(this, parent),
|
||||||
@ -879,25 +933,6 @@ CIconProvider& CDockManager::iconProvider()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void updateDockWidgetFocusStyle(CDockWidget* DockWidget, bool Focused)
|
|
||||||
{
|
|
||||||
DockWidget->setProperty("focused", Focused);
|
|
||||||
DockWidget->tabWidget()->setProperty("focused", Focused);
|
|
||||||
DockWidget->tabWidget()->updateStyle();
|
|
||||||
internal::repolishStyle(DockWidget);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//===========================================================================
|
|
||||||
void updateDockAreaFocusStyle(CDockAreaWidget* DockArea, bool Focused)
|
|
||||||
{
|
|
||||||
DockArea->setProperty("focused", Focused);
|
|
||||||
internal::repolishStyle(DockArea);
|
|
||||||
internal::repolishStyle(DockArea->titleBar());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//===========================================================================
|
//===========================================================================
|
||||||
void CDockManager::onFocusChanged(QWidget* focusedOld, QWidget* focusedNow)
|
void CDockManager::onFocusChanged(QWidget* focusedOld, QWidget* focusedNow)
|
||||||
{
|
{
|
||||||
@ -909,6 +944,7 @@ void CDockManager::onFocusChanged(QWidget* focusedOld, QWidget* focusedNow)
|
|||||||
|
|
||||||
CDockWidget* DockWidget = nullptr;
|
CDockWidget* DockWidget = nullptr;
|
||||||
auto DockWidgetTab = qobject_cast<CDockWidgetTab*>(focusedNow);
|
auto DockWidgetTab = qobject_cast<CDockWidgetTab*>(focusedNow);
|
||||||
|
std::cout << "FocuseNow " << focusedNow->metaObject()->className() << std::endl;
|
||||||
if (DockWidgetTab)
|
if (DockWidgetTab)
|
||||||
{
|
{
|
||||||
DockWidget = DockWidgetTab->dockWidget();
|
DockWidget = DockWidgetTab->dockWidget();
|
||||||
@ -918,33 +954,13 @@ void CDockManager::onFocusChanged(QWidget* focusedOld, QWidget* focusedNow)
|
|||||||
DockWidget = internal::findParent<CDockWidget*>(focusedNow);
|
DockWidget = internal::findParent<CDockWidget*>(focusedNow);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DockWidget)
|
if (!DockWidget || !DockWidget->tabWidget()->isVisible())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CDockAreaWidget* NewFocusedDockArea = nullptr;
|
std::cout << "CDockManager::onFocusChanged " << DockWidget->tabWidget()->text().toStdString() << std::endl;
|
||||||
if (d->FocusedDockWidget)
|
d->updateDockWidgetFocus(DockWidget);
|
||||||
{
|
|
||||||
updateDockWidgetFocusStyle(d->FocusedDockWidget, false);
|
|
||||||
}
|
|
||||||
d->FocusedDockWidget = DockWidget;
|
|
||||||
updateDockWidgetFocusStyle(d->FocusedDockWidget, true);
|
|
||||||
NewFocusedDockArea = d->FocusedDockWidget->dockAreaWidget();
|
|
||||||
if (!NewFocusedDockArea || (d->FocusedArea == NewFocusedDockArea))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (d->FocusedArea)
|
|
||||||
{
|
|
||||||
disconnect(d->FocusedArea, SIGNAL(viewToggled(bool)), this, SLOT(onFocusedDockAreaViewToggled(bool)));
|
|
||||||
updateDockAreaFocusStyle(d->FocusedArea, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
d->FocusedArea = NewFocusedDockArea;
|
|
||||||
updateDockAreaFocusStyle(d->FocusedArea, true);
|
|
||||||
connect(d->FocusedArea, SIGNAL(viewToggled(bool)), this, SLOT(onFocusedDockAreaViewToggled(bool)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -967,6 +983,28 @@ void CDockManager::onFocusedDockAreaViewToggled(bool Open)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//===========================================================================
|
||||||
|
void CDockManager::emitWidgetDroppedSignals(QWidget* DroppedWidget)
|
||||||
|
{
|
||||||
|
CDockWidget* DockWidget = qobject_cast<CDockWidget*>(DroppedWidget);
|
||||||
|
if (DockWidget)
|
||||||
|
{
|
||||||
|
DockWidget->tabWidget()->setFocus(Qt::OtherFocusReason);
|
||||||
|
emit dockWidgetDropped(DockWidget);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CDockAreaWidget* DockArea = qobject_cast<CDockAreaWidget*>(DroppedWidget);
|
||||||
|
if (!DockArea)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
DockWidget = DockArea->currentDockWidget();
|
||||||
|
DockWidget->tabWidget()->setFocus(Qt::OtherFocusReason);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} // namespace ads
|
} // namespace ads
|
||||||
|
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
@ -122,6 +122,12 @@ protected:
|
|||||||
*/
|
*/
|
||||||
CDockOverlay* dockAreaOverlay() const;
|
CDockOverlay* dockAreaOverlay() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A container needs to call this function if a widget has been dropped
|
||||||
|
* into it
|
||||||
|
*/
|
||||||
|
void emitWidgetDroppedSignals(QWidget* DroppedWidget);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the floating widgets that has been created floating
|
* Show the floating widgets that has been created floating
|
||||||
*/
|
*/
|
||||||
@ -483,6 +489,18 @@ signals:
|
|||||||
* docking system but it is not deleted yet.
|
* docking system but it is not deleted yet.
|
||||||
*/
|
*/
|
||||||
void dockWidgetRemoved(CDockWidget* DockWidget);
|
void dockWidgetRemoved(CDockWidget* DockWidget);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This signal is emitted if a dock widget has been dropped into a new
|
||||||
|
* position
|
||||||
|
*/
|
||||||
|
void dockWidgetDropped(CDockWidget* DockWidget);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This signal is emitted if a dock area has been dropped into a new
|
||||||
|
* position
|
||||||
|
*/
|
||||||
|
void dockAreaDropped(CDockAreaWidget* DockArea);
|
||||||
}; // class DockManager
|
}; // class DockManager
|
||||||
} // namespace ads
|
} // namespace ads
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user