Allow enabling/disabling window shadows

This commit is contained in:
Alex Spataru 2021-12-21 17:06:08 -05:00
parent 5792b5ae8a
commit b34255b96f
4 changed files with 48 additions and 1 deletions

View File

@ -97,7 +97,8 @@ QtWindow.Window {
//
// Size of the shadow object
//
property int shadowMargin: Cpp_IsMac ? 0 : (root.radius > 0 ? 20 : 0)
property int shadowMargin: (Cpp_IsMac | !Cpp_ThemeManager.shadowsEnabled) ?
0 : (root.radius > 0 ? 20 : 0)
//
// Titlebar left/right margins for custom controls

View File

@ -35,6 +35,7 @@ Control {
property alias tcpPlugins: _tcpPlugins.checked
property alias language: _langCombo.currentIndex
property alias startSequence: _startSequence.text
property alias windowShadows: _windowShadows.checked
property alias separatorSequence: _separatorSequence.text
property alias multithreadedFrameProcessing: _multithreadedFrameProcessing.checked
@ -166,6 +167,24 @@ Control {
Cpp_JSON_Generator.processFramesInSeparateThread = checked
}
}
//
// Window shadows
//
Label {
visible: !Cpp_IsMac
text: qsTr("Window shadows") + ": "
} Switch {
id: _windowShadows
visible: !Cpp_IsMac
Layout.leftMargin: -app.spacing
Layout.alignment: Qt.AlignLeft
checked: Cpp_ThemeManager.shadowsEnabled
onCheckedChanged: {
if (checked != Cpp_ThemeManager.shadowsEnabled)
Cpp_ThemeManager.shadowsEnabled = checked
}
}
}
//

View File

@ -41,6 +41,7 @@ Misc::ThemeManager::ThemeManager()
{
populateThemes();
loadTheme(m_settings.value("themeId", 0).toInt());
setShadowsEnabled(m_settings.value("shadowsEnabled", true).toBool());
}
/**
@ -60,6 +61,16 @@ int Misc::ThemeManager::themeId() const
return m_themeId;
}
/**
* Returns @c true if the application should draw window shadows. This feature makes the
* frameless windows look good - except if the DE does not support composting (e.g. CDE
* or Haiku OS).
*/
bool Misc::ThemeManager::shadowsEnabled() const
{
return m_enableShadows;
}
/**
* Updates the theme ID to be used & saves the changes to the
* application settings.
@ -93,6 +104,13 @@ void Misc::ThemeManager::setTheme(const int id)
Utilities::rebootApplication();
}
void Misc::ThemeManager::setShadowsEnabled(const bool enabled)
{
m_enableShadows = enabled;
m_settings.setValue("shadowsEnabled", enabled);
Q_EMIT shadowsEnabledChanged();
}
/**
* Parses the JSON theme definition file for the given theme ID.
* The colors are then "extracted" from the JSON file & loaded into the

View File

@ -193,10 +193,15 @@ class ThemeManager : public QObject
Q_PROPERTY(StringList availableThemes
READ availableThemes
NOTIFY availableThemesChanged)
Q_PROPERTY(bool shadowsEnabled
READ shadowsEnabled
WRITE setshadowsEnabled
NOTIFY shadowsEnabledChanged)
// clang-format on
Q_SIGNALS:
void themeChanged();
void shadowsEnabledChanged();
void availableThemesChanged();
private:
@ -210,6 +215,7 @@ public:
static ThemeManager &instance();
int themeId() const;
bool shadowsEnabled() const;
bool titlebarSeparator() const;
QColor base() const;
@ -264,6 +270,7 @@ public:
public Q_SLOTS:
void setTheme(const int id);
void setShadowsEnabled(const bool enabled);
private Q_SLOTS:
void populateThemes();
@ -271,6 +278,8 @@ private Q_SLOTS:
private:
int m_themeId;
bool m_enableShadows;
QSettings m_settings;
bool m_titlebarSeparator;
StringList m_availableThemes;