mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2024-12-24 23:31:32 +08:00
Enable styling of focused dockwidget
This commit is contained in:
parent
b7e7c0ccc3
commit
067338ef23
@ -45,6 +45,8 @@
|
||||
#include <QSettings>
|
||||
#include <QMenu>
|
||||
#include <QApplication>
|
||||
#include <QGuiApplication>
|
||||
#include <QPointer>
|
||||
|
||||
#include "FloatingDockContainer.h"
|
||||
#include "DockOverlay.h"
|
||||
@ -53,6 +55,7 @@
|
||||
#include "DockAreaWidget.h"
|
||||
#include "IconProvider.h"
|
||||
#include "DockingStateReader.h"
|
||||
#include "DockAreaTitleBar.h"
|
||||
|
||||
|
||||
/**
|
||||
@ -91,6 +94,7 @@ struct DockManagerPrivate
|
||||
CDockManager::eViewMenuInsertionOrder MenuInsertionOrder = CDockManager::MenuAlphabeticallySorted;
|
||||
bool RestoringState = false;
|
||||
QVector<CFloatingDockContainer*> UninitializedFloatingWidgets;
|
||||
QPointer<CDockWidget> FocusedDockWidget;
|
||||
|
||||
/**
|
||||
* Private data constructor
|
||||
@ -437,6 +441,8 @@ CDockManager::CDockManager(QWidget *parent) :
|
||||
d->ContainerOverlay = new CDockOverlay(this, CDockOverlay::ModeContainerOverlay);
|
||||
d->Containers.append(this);
|
||||
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
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
@ -84,6 +84,9 @@ private:
|
||||
friend struct FloatingDragPreviewPrivate;
|
||||
friend class CDockAreaTitleBar;
|
||||
|
||||
private slots:
|
||||
void onFocusObjectChanged(QObject *focusObject);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Registers the given floating widget in the internal list of
|
||||
|
@ -160,6 +160,7 @@ struct DockWidgetTabPrivate
|
||||
GlobalDragStartMousePosition = GlobalPos;
|
||||
DragStartMousePosition = _this->mapFromGlobal(GlobalPos);
|
||||
}
|
||||
|
||||
};
|
||||
// struct DockWidgetTabPrivate
|
||||
|
||||
@ -467,10 +468,7 @@ void CDockWidgetTab::setActiveTab(bool active)
|
||||
}
|
||||
|
||||
d->IsActiveTab = active;
|
||||
style()->unpolish(this);
|
||||
style()->polish(this);
|
||||
d->TitleLabel->style()->unpolish(d->TitleLabel);
|
||||
d->TitleLabel->style()->polish(d->TitleLabel);
|
||||
updateStyle();
|
||||
update();
|
||||
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
|
||||
|
@ -39,6 +39,7 @@ namespace ads
|
||||
class CDockWidget;
|
||||
class CDockAreaWidget;
|
||||
struct DockWidgetTabPrivate;
|
||||
class CDockManager;
|
||||
|
||||
/**
|
||||
* A dock widget tab that shows a title and an icon.
|
||||
@ -54,6 +55,7 @@ private:
|
||||
DockWidgetTabPrivate* d; ///< private data (pimpl)
|
||||
friend struct DockWidgetTabPrivate;
|
||||
friend class CDockWidget;
|
||||
friend class CDockManager;
|
||||
void onDockWidgetFeaturesChanged();
|
||||
|
||||
private slots:
|
||||
@ -70,6 +72,11 @@ protected:
|
||||
*/
|
||||
virtual void mouseDoubleClickEvent(QMouseEvent *event) override;
|
||||
|
||||
/**
|
||||
* Update stylesheet style if a property changes
|
||||
*/
|
||||
void updateStyle();
|
||||
|
||||
public:
|
||||
using Super = QFrame;
|
||||
/**
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <QVariant>
|
||||
#include <QPainter>
|
||||
#include <QAbstractButton>
|
||||
#include <QStyle>
|
||||
|
||||
#include "DockSplitter.h"
|
||||
#include "DockManager.h"
|
||||
@ -118,6 +119,18 @@ void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
void repolishStyle(QWidget* w)
|
||||
{
|
||||
if (!w)
|
||||
{
|
||||
return;
|
||||
}
|
||||
w->style()->unpolish(w);
|
||||
w->style()->polish(w);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace ads
|
||||
|
||||
|
@ -251,6 +251,13 @@ void setToolTip(QObjectPtr obj, const QString &tip)
|
||||
void setButtonIcon(QAbstractButton* Button, QStyle::StandardPixmap StandarPixmap,
|
||||
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 ads
|
||||
|
||||
|
@ -9,10 +9,6 @@ ads--CDockContainerWidget
|
||||
background: palette(dark);
|
||||
}
|
||||
|
||||
ads--CDockContainerWidget QSplitter::handle
|
||||
{
|
||||
background: palette(dark);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user