Skip to content

Commit

Permalink
Added setting from breeze "Draw circle arround close button" (in gene…
Browse files Browse the repository at this point in the history
…ral tab)
  • Loading branch information
David-118 committed Feb 4, 2022
1 parent 4b2e4e5 commit 029c374
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 8 deletions.
13 changes: 7 additions & 6 deletions src/Button.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
#include <QVariantAnimation>
#include <QtMath> // qFloor


namespace Material
{

Expand Down Expand Up @@ -155,7 +154,6 @@ KDecoration2::DecorationButton* Button::create(KDecoration2::DecorationButtonTyp

switch (type) {
case KDecoration2::DecorationButtonType::Menu:
// case KDecoration2::DecorationButtonType::ApplicationMenu:
case KDecoration2::DecorationButtonType::OnAllDesktops:
case KDecoration2::DecorationButtonType::ContextHelp:
case KDecoration2::DecorationButtonType::Shade:
Expand Down Expand Up @@ -336,14 +334,16 @@ void Button::setPenWidth(QPainter *painter, const qreal gridUnit, const qreal sc

QColor returnVal;
QColor normalColor = QColor(0,0,0,0);
auto c = d->client().data();
auto c = d->client().toStrongRef().data();
bool circleClose = d->isCloseButtonCircled();

QColor redColor( c->color( KDecoration2::ColorGroup::Warning, KDecoration2::ColorRole::Foreground ) );

if (type() == KDecoration2::DecorationButtonType::Menu) {
returnVal= normalColor;
} else if( isPressed() ) {

if( type() == KDecoration2::DecorationButtonType::Close ) returnVal = redColor.darker();
if( type() == KDecoration2::DecorationButtonType::Close) returnVal = redColor.darker();
else returnVal = KColorUtils::mix( normalColor, d->titleBarForegroundColor(), 0.5 );

} else if( isChecked() && type() != KDecoration2::DecorationButtonType::Maximize ) {
Expand All @@ -355,7 +355,7 @@ void Button::setPenWidth(QPainter *painter, const qreal gridUnit, const qreal sc
if( type() == KDecoration2::DecorationButtonType::Close ) {return c->isActive() ? redColor.lighter() : redColor;}
else {returnVal = d->titleBarForegroundColor();}
} else {
if (type() == KDecoration2::DecorationButtonType::Close) {
if (type() == KDecoration2::DecorationButtonType::Close && circleClose) {
returnVal = c->isActive() ? redColor : d->titleBarForegroundColor();
} else {
returnVal = normalColor;
Expand All @@ -369,6 +369,7 @@ void Button::setPenWidth(QPainter *painter, const qreal gridUnit, const qreal sc
QColor Button::foregroundColor() const
{
auto d = qobject_cast<Decoration*>( decoration() );
bool circleClose = d->isCloseButtonCircled();
if( !d ) {

return QColor();
Expand All @@ -385,7 +386,7 @@ void Button::setPenWidth(QPainter *painter, const qreal gridUnit, const qreal sc

return d->titleBarBackgroundColor();

} else if (type() == KDecoration2::DecorationButtonType::Close) {
} else if (type() == KDecoration2::DecorationButtonType::Close && circleClose) {
return d->titleBarBackgroundColor();
} else {

Expand Down
1 change: 1 addition & 0 deletions src/Button.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Button : public KDecoration2::DecorationButton

bool animationEnabled() const;
void setAnimationEnabled(bool value);
void setCircleClose(bool isCircled);

int animationDuration() const;
void setAnimationDuration(int duration);
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ target_link_libraries (breezelimdeco
)
if (Qt6_FOUND)
# The QX11Info class has been removed.
target_link_libraries (materialdecoration
target_link_libraries (breezelimdeco
PUBLIC
Qt${QT_VERSION_MAJOR}::GuiPrivate
)
elseif(Qt5_FOUND)
target_link_libraries (materialdecoration
target_link_libraries (breezelimdeco
PUBLIC
Qt${QT_VERSION_MAJOR}::X11Extras
)
Expand Down
14 changes: 14 additions & 0 deletions src/ConfigurationModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ ConfigurationModule::ConfigurationModule(QWidget *parent, const QVariantList &ar
, m_titleAlignment(InternalSettings::AlignCenterFullWidth)
, m_buttonSize(InternalSettings::ButtonDefault)
, m_shadowSize(InternalSettings::ShadowVeryLarge)
, m_circleClose(false)
{
init();
}
Expand Down Expand Up @@ -100,6 +101,11 @@ void ConfigurationModule::init()
buttonSizes->setObjectName(QStringLiteral("kcfg_ButtonSize"));
generalForm->addRow(i18nd("breeze_kwin_deco", "B&utton size:"), buttonSizes);

QCheckBox *closeButtonCircle = new QCheckBox(generalTab);
closeButtonCircle->setText(i18n("Show circle around close button"));
closeButtonCircle->setObjectName(QStringLiteral("kcfg_CloseButtonCircle"));
generalForm->addRow(QStringLiteral(""), closeButtonCircle);

QDoubleSpinBox *activeOpacity = new QDoubleSpinBox(generalTab);
activeOpacity->setMinimum(0.0);
activeOpacity->setMaximum(1.0);
Expand Down Expand Up @@ -209,6 +215,14 @@ void ConfigurationModule::init()
InternalSettings::ButtonDefault,
QStringLiteral("ButtonSize")
);

skel->addItemBool(
QStringLiteral("CloseButtonCircle"),
m_circleClose,
false,
QStringLiteral("CloseButtonCircle")
);

skel->addItemDouble(
QStringLiteral("ActiveOpacity"),
m_activeOpacity,
Expand Down
1 change: 1 addition & 0 deletions src/ConfigurationModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ConfigurationModule : public KCModule
int m_shadowSize;
int m_shadowStrength;
QColor m_shadowColor;
bool m_circleClose;
};

} // namespace Material
7 changes: 7 additions & 0 deletions src/Decoration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ void Decoration::updateBorders()
setBorders(borders);
}


void Decoration::updateResizeBorders()
{
QMargins borders;
Expand Down Expand Up @@ -511,6 +512,7 @@ void Decoration::updateButtonsGeometry()
m_menuButtons->setPos(availableRect.topLeft());
m_menuButtons->setSpacing(0);
m_menuButtons->updateOverflow(availableRect);

}

update();
Expand Down Expand Up @@ -1099,4 +1101,9 @@ void Decoration::paintOutline(QPainter *painter, const QRect &repaintRegion) con
painter->restore();
}

bool Decoration::isCloseButtonCircled()
{
return this->m_internalSettings->closeButtonCircle();
}

} // namespace Material
2 changes: 2 additions & 0 deletions src/Decoration.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class Decoration : public KDecoration2::Decoration

void paint(QPainter *painter, const QRect &repaintRegion) override;

bool isCloseButtonCircled();

public slots:
void init() override;
void reconfigure();
Expand Down
5 changes: 5 additions & 0 deletions src/InternalSettingsSchema.kcfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<default>ButtonDefault</default>
</entry>

<!-- TitleAlignment-->
<entry name="CloseButtonCircle" type="Bool">
<default>false</default>
</entry>

<!-- title alignment -->
<entry name="TitleAlignment" type="Enum">
<choices>
Expand Down

0 comments on commit 029c374

Please sign in to comment.