Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 51 additions & 7 deletions src/DockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <QWindow>
#include <QWindowStateChangeEvent>
#include <QVector>
#include <QStyleHints>

#include "FloatingDockContainer.h"
#include "DockOverlay.h"
Expand Down Expand Up @@ -118,6 +119,7 @@ struct DockManagerPrivate
QMap<QString, QMenu*> ViewMenuGroups;
QMenu* ViewMenu;
CDockManager::eViewMenuInsertionOrder MenuInsertionOrder = CDockManager::MenuAlphabeticallySorted;
CDockManager::eStylesheetColorSchemeBehavior StylesheetColorSchemeBehavior = CDockManager::FollowApplicationPalette;
bool RestoringState = false;
QVector<CFloatingDockContainer*> UninitializedFloatingWidgets;
CDockFocusController* FocusController = nullptr;
Expand All @@ -129,6 +131,7 @@ struct DockManagerPrivate
QSize ToolBarIconSizeFloating = QSize(24, 24);
CDockWidget::DockWidgetFeatures LockedDockWidgetFeatures;
QSharedPointer<ads::CDockComponentsFactory> ComponentFactory {ads::CDockComponentsFactory::factory()};
bool CurrentStylesheetDark;

/**
* Private data constructor
Expand Down Expand Up @@ -215,6 +218,12 @@ void DockManagerPrivate::loadStylesheet()
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
FileName += "_linux";
#endif
if (_this->isDesiredStylesheetDark()) {
CurrentStylesheetDark = true;
FileName += "_dark";
}
else
CurrentStylesheetDark = false;
FileName += ".css";
QFile StyleSheetFile(FileName);
StyleSheetFile.open(QIODevice::ReadOnly);
Expand Down Expand Up @@ -650,9 +659,9 @@ void CDockManager::setComponentsFactory(QSharedPointer<ads::CDockComponentsFacto


//============================================================================
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
bool CDockManager::eventFilter(QObject *obj, QEvent *e)
{
#if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
// Emulate Qt:Tool behaviour.
// Required because on some WMs Tool windows can't be maximized.

Expand Down Expand Up @@ -725,12 +734,7 @@ bool CDockManager::eventFilter(QObject *obj, QEvent *e)
QApplication::setActiveWindow(window());
}
}
return Super::eventFilter(obj, e);
}
#else
//============================================================================
bool CDockManager::eventFilter(QObject *obj, QEvent *e)
{
if (e->type() == QEvent::WindowStateChange)
{
QWindowStateChangeEvent* ev = static_cast<QWindowStateChangeEvent*>(e);
Expand All @@ -740,9 +744,15 @@ bool CDockManager::eventFilter(QObject *obj, QEvent *e)
QMetaObject::invokeMethod(this, "endLeavingMinimizedState", Qt::QueuedConnection);
}
}
#endif
if (e->type() == QEvent::ApplicationPaletteChange && d->StylesheetColorSchemeBehavior == CDockManager::FollowApplicationPalette)
{
if (d->CurrentStylesheetDark != isDesiredStylesheetDark()) {
d->loadStylesheet();
}
}
return Super::eventFilter(obj, e);
}
#endif


//============================================================================
Expand Down Expand Up @@ -1261,6 +1271,18 @@ void CDockManager::setViewMenuInsertionOrder(eViewMenuInsertionOrder Order)
}


//============================================================================
void CDockManager::setStylesheetColorSchemeBehavior(eStylesheetColorSchemeBehavior Behavior)
{
d->StylesheetColorSchemeBehavior = Behavior;

if (d->CurrentStylesheetDark != isDesiredStylesheetDark()) {
d->loadStylesheet();
ensurePolished();
}
}


//===========================================================================
bool CDockManager::isRestoringState() const
{
Expand Down Expand Up @@ -1571,6 +1593,28 @@ void CDockManager::raise()
}


//============================================================================
bool CDockManager::isApplicationPaletteDark()
{
QPalette appPalette = QGuiApplication::palette();

// Extract the background and foreground colors
QColor windowColor = appPalette.color(QPalette::Window);
QColor textColor = appPalette.color(QPalette::WindowText);

// Check lightness values (0.0 = black, 1.0 = white)
// If text is lighter than the background, the app palette is dark
return textColor.lightnessF() > windowColor.lightnessF();
}


//============================================================================
bool CDockManager::isDesiredStylesheetDark()
{
return ((isApplicationPaletteDark() && d->StylesheetColorSchemeBehavior == FollowApplicationPalette) || d->StylesheetColorSchemeBehavior == ForceDark);
}


} // namespace ads

//---------------------------------------------------------------------------
Expand Down
28 changes: 28 additions & 0 deletions src/DockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ public Q_SLOTS:
MenuAlphabeticallySorted
};

enum eStylesheetColorSchemeBehavior
{
ForceLight,
ForceDark,
FollowApplicationPalette
};

/**
* These global configuration flags configure some global dock manager
* settings.
Expand Down Expand Up @@ -397,6 +404,16 @@ public Q_SLOTS:
*/
static CIconProvider& iconProvider();

/**
* Returns if current application palette is dark
*/
static bool isApplicationPaletteDark();

/**
* Returns if currently applied stylesheet is supposed to be dark
*/
bool isDesiredStylesheetDark();

/**
* Adds dockwidget into the given area.
* If DockAreaWidget is not null, then the area parameter indicates the area
Expand Down Expand Up @@ -617,6 +634,17 @@ public Q_SLOTS:
*/
void setViewMenuInsertionOrder(eViewMenuInsertionOrder Order);

/**
* Define the behavior of stylesheet color scheme selection.
* The stylesheet can be fixed to either light or dark scheme,
* or it can follow the current application palette (default).
* Note: The fixed settings implement legacy behavior (before
* dark scheme was implemented) including problems like missing
* palette change propagation. They are implemented solely
* for compatibility reasons and manual stylesheet switching.
*/
void setStylesheetColorSchemeBehavior(eStylesheetColorSchemeBehavior Behavior);

/**
* This function returns true between the restoringState() and
* stateRestored() signals.
Expand Down
24 changes: 22 additions & 2 deletions src/DockOverlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,14 @@ struct DockOverlayCrossPrivate
break;

case CDockOverlayCross::ArrowColor: return pal.color(QPalette::Active, QPalette::Base);
case CDockOverlayCross::ShadowColor: return QColor(0, 0, 0, 64);
case CDockOverlayCross::ShadowColor:
{
QColor Color = pal.color(QPalette::Active, QPalette::Text);
Color.setAlpha(64);
return Color;
}
break;

default:
return QColor();
}
Expand All @@ -146,7 +153,6 @@ struct DockOverlayCrossPrivate
if (!Color.isValid())
{
Color = defaultIconColor(ColorIndex);
IconColors[ColorIndex] = Color;
}
return Color;
}
Expand Down Expand Up @@ -907,6 +913,20 @@ void CDockOverlayCross::showEvent(QShowEvent*)
}


//============================================================================
bool CDockOverlayCross::event(QEvent *e)
{
bool Result = QWidget::event(e);

if (e->type() == QEvent::ApplicationPaletteChange)
{
d->UpdateRequired = true;
}

return Result;
}


//============================================================================
void CDockOverlayCross::updatePosition()
{
Expand Down
1 change: 1 addition & 0 deletions src/DockOverlay.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ class CDockOverlayCross : public QWidget

protected:
virtual void showEvent(QShowEvent* e) override;
virtual bool event(QEvent* e) override;
void setAreaWidgets(const QHash<DockWidgetArea, QWidget*>& widgets);
}; // CDockOverlayCross

Expand Down
23 changes: 23 additions & 0 deletions src/ads.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,28 @@
<file>images/minimize-button.svg</file>
<file>images/minimize-button-focused.svg</file>
<file>images/vs-pin-button-disabled.svg</file>
<file>stylesheets/default_dark.css</file>
<file>images/close-button_dark.svg</file>
<file>images/pin-button_dark.svg</file>
<file>images/close-button-disabled_dark.svg</file>
<file>stylesheets/default_linux_dark.css</file>
<file>images/close-button-focused_dark.svg</file>
<file>stylesheets/focus_highlighting_dark.css</file>
<file>stylesheets/focus_highlighting_linux_dark.css</file>
<file>images/tabs-menu-button_dark.svg</file>
<file>images/detach-button_dark.svg</file>
<file>images/detach-button-disabled_dark.svg</file>
<file>images/maximize-button_dark.svg</file>
<file>images/maximize-button-focused_dark.svg</file>
<file>images/restore-button_dark.svg</file>
<file>images/restore-button-focused_dark.svg</file>
<file>images/vs-pin-button_dark.svg</file>
<file>images/vs-pin-button-pinned_dark.svg</file>
<file>images/vs-pin-button-pinned-focused_dark.svg</file>
<file>images/vs-pin-button_45_dark.svg</file>
<file>images/pin-button-big_dark.svg</file>
<file>images/minimize-button_dark.svg</file>
<file>images/minimize-button-focused_dark.svg</file>
<file>images/vs-pin-button-disabled_dark.svg</file>
</qresource>
</RCC>
139 changes: 139 additions & 0 deletions src/images/close-button-disabled_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading