From aaee1329511ade2ab01eb5e90c60ab3dcf19181c Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sat, 16 Mar 2019 20:40:51 +0200 Subject: [PATCH] add outline width option in Preferences --- app/plasma/extended/theme.cpp | 26 +++- app/plasma/extended/theme.h | 8 + app/settings/settingsdialog.cpp | 12 +- app/settings/settingsdialog.ui | 145 +++++++++++++++--- containment/package/contents/ui/PanelBox.qml | 2 +- .../ui/colorizer/CustomBackground.qml | 12 +- 6 files changed, 171 insertions(+), 34 deletions(-) diff --git a/app/plasma/extended/theme.cpp b/app/plasma/extended/theme.cpp index a107e599b..0d822e9c4 100644 --- a/app/plasma/extended/theme.cpp +++ b/app/plasma/extended/theme.cpp @@ -51,6 +51,11 @@ Theme::Theme(KSharedConfig::Ptr config, QObject *parent) : loadConfig(); + connect(this, &Theme::outlineWidthChanged, this, &Theme::saveConfig); + connect(this, &Theme::userSetRoundnessChanged, this, &Theme::saveConfig); + + connect(this, &Theme::userSetRoundnessChanged, this, &Theme::roundnessChanged); + connect(&m_theme, &Plasma::Theme::themeChanged, this, &Theme::hasShadowChanged); connect(&m_theme, &Plasma::Theme::themeChanged, this, &Theme::load); connect(&m_theme, &Plasma::Theme::themeChanged, this, &Theme::themeChanged); @@ -110,6 +115,21 @@ int Theme::rightEdgeRoundness() const return ((themeHasExtendedInfo() && m_userRoundness == -1) ? m_rightEdgeRoundness : qMax(0, m_userRoundness)); } +int Theme::outlineWidth() const +{ + return m_outlineWidth; +} + +void Theme::setOutlineWidth(int width) +{ + if (m_outlineWidth == width) { + return; + } + + m_outlineWidth = width; + emit outlineWidthChanged(); +} + int Theme::userThemeRoundness() const { return m_userRoundness; @@ -123,9 +143,7 @@ void Theme::setUserThemeRoundness(int roundness) m_userRoundness = roundness; - emit roundnessChanged(); - - saveConfig(); + emit userSetRoundnessChanged(); } float Theme::backgroundMaxOpacity() const @@ -511,11 +529,13 @@ void Theme::loadThemeLightness() void Theme::loadConfig() { setUserThemeRoundness(m_themeGroup.readEntry("userSetPlasmaThemeRoundness", -1)); + setOutlineWidth(m_themeGroup.readEntry("outlineWidth", 1)); } void Theme::saveConfig() { m_themeGroup.writeEntry("userSetPlasmaThemeRoundness", m_userRoundness); + m_themeGroup.writeEntry("outlineWidth", m_outlineWidth); m_themeGroup.sync(); } diff --git a/app/plasma/extended/theme.h b/app/plasma/extended/theme.h index 58d8460f0..3a3f596cd 100644 --- a/app/plasma/extended/theme.h +++ b/app/plasma/extended/theme.h @@ -57,6 +57,8 @@ class Theme: public QObject Q_PROPERTY(int topEdgeRoundness READ topEdgeRoundness NOTIFY roundnessChanged) Q_PROPERTY(int rightEdgeRoundness READ rightEdgeRoundness NOTIFY roundnessChanged) + Q_PROPERTY(int outlineWidth READ outlineWidth NOTIFY outlineWidthChanged) + Q_PROPERTY(float backgroundMaxOpacity READ backgroundMaxOpacity NOTIFY backgroundMaxOpacityChanged) Q_PROPERTY(SchemeColors *defaultTheme READ defaultTheme NOTIFY themeChanged) @@ -76,6 +78,9 @@ public: int topEdgeRoundness() const; int rightEdgeRoundness() const; + int outlineWidth() const; + void setOutlineWidth(int width); + int userThemeRoundness() const; void setUserThemeRoundness(int roundness); @@ -90,8 +95,10 @@ public: signals: void backgroundMaxOpacityChanged(); void hasShadowChanged(); + void outlineWidthChanged(); void roundnessChanged(); void themeChanged(); + void userSetRoundnessChanged(); private slots: void loadConfig(); @@ -119,6 +126,7 @@ private: int m_leftEdgeRoundness{0}; int m_topEdgeRoundness{0}; int m_rightEdgeRoundness{0}; + int m_outlineWidth{1}; int m_userRoundness{-1}; float m_backgroundMaxOpacity{1}; diff --git a/app/settings/settingsdialog.cpp b/app/settings/settingsdialog.cpp index 68f4f0126..352978460 100644 --- a/app/settings/settingsdialog.cpp +++ b/app/settings/settingsdialog.cpp @@ -71,6 +71,7 @@ const int ACTIVITYCOLUMN = 6; const int SCREENTRACKERDEFAULTVALUE = 2500; const int THEMEDEFAULTROUNDNESS = 0; //Breeze default value is used 0px. +const int OUTLINEDEFAULTWIDTH = 1; const QChar CheckMark{0x2714}; @@ -138,6 +139,7 @@ SettingsDialog::SettingsDialog(QWidget *parent, Latte::Corona *corona) ui->screenTrackerSpinBox->setValue(m_corona->universalSettings()->screenTrackerInterval()); ui->themeRoundnessSpinBox->setSpecialValueText(i18nc("automatic background roundness","Automatic")); ui->themeRoundnessSpinBox->setValue(m_corona->themeExtended()->userThemeRoundness()); + ui->outlineSpinBox->setValue(m_corona->themeExtended()->outlineWidth()); //! About Menu QMenuBar *menuBar = new QMenuBar(this); @@ -195,6 +197,10 @@ SettingsDialog::SettingsDialog(QWidget *parent, Latte::Corona *corona) updateApplyButtonsState(); }); + connect(ui->outlineSpinBox, QOverload::of(&QSpinBox::valueChanged), [ = ](int i) { + updateApplyButtonsState(); + }); + connect(ui->autostartChkBox, &QCheckBox::stateChanged, this, &SettingsDialog::updateApplyButtonsState); connect(ui->metaPressChkBox, &QCheckBox::stateChanged, this, &SettingsDialog::updateApplyButtonsState); connect(ui->metaPressHoldChkBox, &QCheckBox::stateChanged, this, &SettingsDialog::updateApplyButtonsState); @@ -760,6 +766,7 @@ void SettingsDialog::restoreDefaults() ui->highSensitivityBtn->setChecked(true); ui->screenTrackerSpinBox->setValue(SCREENTRACKERDEFAULTVALUE); ui->themeRoundnessSpinBox->setValue(THEMEDEFAULTROUNDNESS); + ui->outlineSpinBox->setValue(OUTLINEDEFAULTWIDTH); } } @@ -962,6 +969,7 @@ QList SettingsDialog::currentSettings() settings << m_mouseSensitivityButtons->checkedId(); settings << ui->screenTrackerSpinBox->value(); settings << ui->themeRoundnessSpinBox->value(); + settings << ui->outlineSpinBox->value(); settings << m_model->rowCount(); return settings; @@ -1218,7 +1226,8 @@ void SettingsDialog::updateApplyButtonsState() || ui->noBordersForMaximizedChkBox->isChecked() || !ui->highSensitivityBtn->isChecked() || ui->screenTrackerSpinBox->value() != SCREENTRACKERDEFAULTVALUE - || ui->themeRoundnessSpinBox->value() != THEMEDEFAULTROUNDNESS) { + || ui->themeRoundnessSpinBox->value() != THEMEDEFAULTROUNDNESS + || ui->outlineSpinBox->value() != OUTLINEDEFAULTWIDTH ) { ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)->setEnabled(true); } else { ui->buttonBox->button(QDialogButtonBox::RestoreDefaults)->setEnabled(false); @@ -1352,6 +1361,7 @@ bool SettingsDialog::saveAllChanges() m_corona->universalSettings()->setScreenTrackerInterval(ui->screenTrackerSpinBox->value()); m_corona->themeExtended()->setUserThemeRoundness(ui->themeRoundnessSpinBox->value()); + m_corona->themeExtended()->setOutlineWidth(ui->outlineSpinBox->value()); //! Update Layouts QStringList knownActivities = activities(); diff --git a/app/settings/settingsdialog.ui b/app/settings/settingsdialog.ui index bb3daa9ee..c5ab0e9f5 100644 --- a/app/settings/settingsdialog.ui +++ b/app/settings/settingsdialog.ui @@ -6,8 +6,8 @@ 0 0 - 840 - 621 + 936 + 710 @@ -140,8 +140,7 @@ - - + .. @@ -155,8 +154,7 @@ - - + .. @@ -215,8 +213,7 @@ - - + .. @@ -230,8 +227,7 @@ - - + .. false @@ -248,8 +244,7 @@ - - + .. @@ -279,8 +274,7 @@ - - + .. true @@ -357,8 +351,7 @@ - - + .. false @@ -375,8 +368,7 @@ - - + .. @@ -390,8 +382,7 @@ - - + .. @@ -453,15 +444,24 @@ 0 0 - 805 - 523 + 885 + 613 0 - + + 0 + + + 0 + + + 0 + + 0 @@ -1062,6 +1062,105 @@ when there are no other roundness information. + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + true + + + Outline width used from background to draw its borders + + + Outline width + + + + + + + + 0 + 0 + + + + + 111 + 30 + + + + + 200 + 16777215 + + + + Outline width used from background to draw its borders + + + px. + + + 1 + + + 16 + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + + + Qt::Vertical + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + diff --git a/containment/package/contents/ui/PanelBox.qml b/containment/package/contents/ui/PanelBox.qml index 17f498294..b0b310f25 100644 --- a/containment/package/contents/ui/PanelBox.qml +++ b/containment/package/contents/ui/PanelBox.qml @@ -533,7 +533,7 @@ Item{ sourceComponent: Colorizer.CustomBackground{ backgroundColor: "transparent" borderColor: colorizerManager.outlineColor - borderWidth: 1 + borderWidth: themeExtended ? themeExtended.outlineWidth : 1 roundness: overlayedBackground.roundness } } diff --git a/containment/package/contents/ui/colorizer/CustomBackground.qml b/containment/package/contents/ui/colorizer/CustomBackground.qml index 0d26b320e..e14387234 100644 --- a/containment/package/contents/ui/colorizer/CustomBackground.qml +++ b/containment/package/contents/ui/colorizer/CustomBackground.qml @@ -106,15 +106,15 @@ Item{ if (drawWithoutRoundness) { return parent.width + 2*borderWidth; } else if (noOfBorders === 2) { - return parent.width + Math.max(roundness,borderWidth); + return parent.width + Math.max(roundness, 2*borderWidth); } else if (noOfBorders === 3) { return parent.width; } } else if (plasmoid.formFactor === PlasmaCore.Types.Vertical) { if (drawWithoutRoundness) { - return parent.width + borderWidth; + return parent.width + 2 * borderWidth; } else if (noOfBorders === 2 || noOfBorders === 3) { - return parent.width + Math.max(roundness,borderWidth); + return parent.width + Math.max(roundness, 2 * borderWidth); } } } @@ -123,15 +123,15 @@ Item{ height: { if (plasmoid.formFactor === PlasmaCore.Types.Horizontal) { if (drawWithoutRoundness) { - return parent.height + borderWidth; + return parent.height + 2 * borderWidth; } else if (noOfBorders === 2 || noOfBorders === 3) { - return parent.height + Math.max(roundness,borderWidth); + return parent.height + Math.max(roundness,2 * borderWidth); } } else if (plasmoid.formFactor === PlasmaCore.Types.Vertical) { if (drawWithoutRoundness) { return parent.height + 2*borderWidth; } else if (noOfBorders === 2) { - return parent.height + Math.max(roundness,borderWidth); + return parent.height + Math.max(roundness, 2*borderWidth); } else if (noOfBorders === 3) { return parent.height; }