Enable styling of focused dockwidget

This commit is contained in:
Uwe Kindler 2020-05-10 19:30:34 +02:00
parent b7e7c0ccc3
commit 067338ef23
7 changed files with 156 additions and 8 deletions

View File

@ -45,6 +45,8 @@
#include <QSettings> #include <QSettings>
#include <QMenu> #include <QMenu>
#include <QApplication> #include <QApplication>
#include <QGuiApplication>
#include <QPointer>
#include "FloatingDockContainer.h" #include "FloatingDockContainer.h"
#include "DockOverlay.h" #include "DockOverlay.h"
@ -53,6 +55,7 @@
#include "DockAreaWidget.h" #include "DockAreaWidget.h"
#include "IconProvider.h" #include "IconProvider.h"
#include "DockingStateReader.h" #include "DockingStateReader.h"
#include "DockAreaTitleBar.h"
/** /**
@ -91,6 +94,7 @@ struct DockManagerPrivate
CDockManager::eViewMenuInsertionOrder MenuInsertionOrder = CDockManager::MenuAlphabeticallySorted; CDockManager::eViewMenuInsertionOrder MenuInsertionOrder = CDockManager::MenuAlphabeticallySorted;
bool RestoringState = false; bool RestoringState = false;
QVector<CFloatingDockContainer*> UninitializedFloatingWidgets; QVector<CFloatingDockContainer*> UninitializedFloatingWidgets;
QPointer<CDockWidget> FocusedDockWidget;
/** /**
* Private data constructor * Private data constructor
@ -437,6 +441,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*)),
this, SLOT(onFocusObjectChanged(QObject*)));
} }
//============================================================================ //============================================================================
@ -872,6 +878,74 @@ CIconProvider& CDockManager::iconProvider()
} }
//===========================================================================
void CDockManager::onFocusObjectChanged(QObject *focusObject)
{
auto FocusWidget = qobject_cast<QWidget*>(focusObject);
if (!FocusWidget)
{
return;
}
auto DockWidget = internal::findParent<CDockWidget*>(FocusWidget);
if (!DockWidget)
{
return;
}
if (d->FocusedDockWidget.data() == DockWidget)
{
return;
}
QList<CDockWidget*> DockWidgets;
CDockAreaWidget* OldFocusedDockArea = nullptr;
CDockAreaWidget* NewFocusedDockArea = nullptr;
if (d->FocusedDockWidget)
{
d->FocusedDockWidget->setProperty("focused", false);
d->FocusedDockWidget->tabWidget()->setProperty("focused", false);
OldFocusedDockArea = d->FocusedDockWidget->dockAreaWidget();
if (OldFocusedDockArea)
{
OldFocusedDockArea->setProperty("focused", false);
}
DockWidgets.append(d->FocusedDockWidget);
}
d->FocusedDockWidget = DockWidget;
d->FocusedDockWidget->setProperty("focused", true);
d->FocusedDockWidget->tabWidget()->setProperty("focused", true);
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 (OldFocusedDockArea == NewFocusedDockArea)
{
return;
}
if (OldFocusedDockArea)
{
internal::repolishStyle(OldFocusedDockArea);
internal::repolishStyle(OldFocusedDockArea->titleBar());
}
if (NewFocusedDockArea)
{
internal::repolishStyle(NewFocusedDockArea);
internal::repolishStyle(NewFocusedDockArea->titleBar());
}
}
} // namespace ads } // namespace ads
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------

View File

@ -84,6 +84,9 @@ private:
friend struct FloatingDragPreviewPrivate; friend struct FloatingDragPreviewPrivate;
friend class CDockAreaTitleBar; friend class CDockAreaTitleBar;
private slots:
void onFocusObjectChanged(QObject *focusObject);
protected: protected:
/** /**
* Registers the given floating widget in the internal list of * Registers the given floating widget in the internal list of

View File

@ -160,6 +160,7 @@ struct DockWidgetTabPrivate
GlobalDragStartMousePosition = GlobalPos; GlobalDragStartMousePosition = GlobalPos;
DragStartMousePosition = _this->mapFromGlobal(GlobalPos); DragStartMousePosition = _this->mapFromGlobal(GlobalPos);
} }
}; };
// struct DockWidgetTabPrivate // struct DockWidgetTabPrivate
@ -467,10 +468,7 @@ void CDockWidgetTab::setActiveTab(bool active)
} }
d->IsActiveTab = active; d->IsActiveTab = active;
style()->unpolish(this); updateStyle();
style()->polish(this);
d->TitleLabel->style()->unpolish(d->TitleLabel);
d->TitleLabel->style()->polish(d->TitleLabel);
update(); update();
updateGeometry(); updateGeometry();
@ -641,6 +639,16 @@ void CDockWidgetTab::setElideMode(Qt::TextElideMode mode)
} }
//============================================================================
void CDockWidgetTab::updateStyle()
{
this->style()->unpolish(this);
this->style()->polish(this);
d->TitleLabel->style()->unpolish(d->TitleLabel);
d->TitleLabel->style()->polish(d->TitleLabel);
}
} // namespace ads } // namespace ads

View File

@ -39,6 +39,7 @@ namespace ads
class CDockWidget; class CDockWidget;
class CDockAreaWidget; class CDockAreaWidget;
struct DockWidgetTabPrivate; struct DockWidgetTabPrivate;
class CDockManager;
/** /**
* A dock widget tab that shows a title and an icon. * A dock widget tab that shows a title and an icon.
@ -54,6 +55,7 @@ private:
DockWidgetTabPrivate* d; ///< private data (pimpl) DockWidgetTabPrivate* d; ///< private data (pimpl)
friend struct DockWidgetTabPrivate; friend struct DockWidgetTabPrivate;
friend class CDockWidget; friend class CDockWidget;
friend class CDockManager;
void onDockWidgetFeaturesChanged(); void onDockWidgetFeaturesChanged();
private slots: private slots:
@ -70,6 +72,11 @@ 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;
/** /**

View File

@ -31,6 +31,7 @@
#include <QVariant> #include <QVariant>
#include <QPainter> #include <QPainter>
#include <QAbstractButton> #include <QAbstractButton>
#include <QStyle>
#include "DockSplitter.h" #include "DockSplitter.h"
#include "DockManager.h" #include "DockManager.h"
@ -118,6 +119,18 @@ void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap
#endif #endif
} }
//============================================================================
void repolishStyle(QWidget* w)
{
if (!w)
{
return;
}
w->style()->unpolish(w);
w->style()->polish(w);
}
} // namespace internal } // namespace internal
} // namespace ads } // namespace ads

View File

@ -251,6 +251,13 @@ void setToolTip(QObjectPtr obj, const QString &tip)
void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap, void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap,
ads::eIcon CustomIconId); ads::eIcon CustomIconId);
/**
* Calls unpolish() / polish for the style of the given widget to update
* stylesheet if a property changes
*/
void repolishStyle(QWidget* w);
} // namespace internal } // namespace internal
} // namespace ads } // namespace ads

View File

@ -9,10 +9,6 @@ ads--CDockContainerWidget
background: palette(dark); background: palette(dark);
} }
ads--CDockContainerWidget QSplitter::handle
{
background: palette(dark);
}
ads--CDockAreaWidget ads--CDockAreaWidget
{ {
@ -92,3 +88,43 @@ QScrollArea#dockWidgetScrollArea
} }
ads--CDockSplitter::handle
{
background-color: palette(dark);
/* uncomment the following line if you would like to change the size of
the splitter handles */
/* height: 1px; */
}
ads--CDockWidgetTab[focused="true"]
{
background: palette(highlight);
border-color: palette(highlight);
}
ads--CDockWidgetTab[focused="true"] QLabel
{
color: palette(light);
}
ads--CDockAreaTitleBar
{
background: transparent;
border-bottom: 2px solid palette(light);
padding-bottom: 0px;
}
ads--CDockAreaWidget[focused="true"] ads--CDockAreaTitleBar
{
background: transparent;
border-bottom: 2px solid palette(highlight);
padding-bottom: 0px;
}