Skip to content

Commit

Permalink
active and inactive backcolor, border shadow color
Browse files Browse the repository at this point in the history
  • Loading branch information
kylin-ccn committed Aug 10, 2021
1 parent ca6c78c commit 8e4a53a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
16 changes: 12 additions & 4 deletions plugins/kdecorations/ukui/shadow-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ QSharedPointer<KDecoration2::DecorationShadow> ShadowHelper::getShadow(const Sha

auto shadow = m_shadowsCache.value(index);
if (!shadow.isNull())
return shadow;
{
shadow.clear();
this->releaseShadows();
m_shadowsCache.remove(index);
}

shadow = QSharedPointer<KDecoration2::DecorationShadow>::create();
auto pix = this->getShadowPixmap(index.color(), shadow_border, darkness, borderRadiusTopLeft, borderRadiusTopRight, borderRadiusBottomLeft, borderRadiusBottomRight);
Expand Down Expand Up @@ -176,11 +180,15 @@ QPixmap ShadowHelper::getShadowPixmap(const QColor &color, int shadow_border, qr
painter2.setCompositionMode(QPainter::CompositionMode_DestinationOver);
painter2.setRenderHint(QPainter::HighQualityAntialiasing);
QColor borderColor = color;
borderColor.setAlphaF(0.05);
painter2.setPen(QPen(borderColor, 1, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));

painter2.setPen(QPen(borderColor, 1.5, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin));
painter2.setBrush(Qt::NoBrush);
painter2.translate(shadow_border, shadow_border);
painter2.translate(-0.5, -0.5);
painter2.translate(-0.05, -0.05);
painter2.drawPath(borderPath);

//封口
borderPath.closeSubpath();
painter2.drawPath(borderPath);

return darkerTarget;
Expand Down
20 changes: 16 additions & 4 deletions plugins/kdecorations/ukui/ukui-decoration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,10 @@ void Decoration::updatefont(QFont font)
update();
}

void Decoration::updateShadow()
void Decoration::updateShadow(int themeId)
{
m_themeId = themeId;

auto ubr = XAtomHelper::getInstance()->getWindowBorderRadius(client().data()->windowId());

// 控制左上、右上的阴影,ubr不生效时,阴影也应该是0
Expand All @@ -223,8 +225,16 @@ void Decoration::updateShadow()
ubr.bottomRight = m_shadowRadius;
}

ShadowIndex shadowIndex(this->fontColor(), ubr.topLeft, ubr.topRight, ubr.bottomLeft, ubr.bottomRight, ACTIVE_DARKNESS, SHADOW_BORDER);
if(m_themeId==1)
{
m_BorderColor = QColor(255,255,255);
m_BorderColor.setAlphaF(0.15);
}else{
m_BorderColor = QColor(38,38,38);
m_BorderColor.setAlphaF(0.15);
}

ShadowIndex shadowIndex(m_BorderColor, ubr.topLeft, ubr.topRight, ubr.bottomLeft, ubr.bottomRight, ACTIVE_DARKNESS, SHADOW_BORDER);
auto shadow = ShadowHelper::globalInstance()->getShadow(shadowIndex);
shadow.data()->setPadding(QMargins(SHADOW_BORDER, SHADOW_BORDER, SHADOW_BORDER, SHADOW_BORDER));
setShadow(shadow);
Expand Down Expand Up @@ -370,7 +380,8 @@ void Decoration::themeUpdate(int themeId)
}

update();
updateShadow();
updateShadow(m_themeId);

}

void Decoration::paint(QPainter *painter, const QRect &repaintRegion)
Expand All @@ -394,12 +405,13 @@ void Decoration::paint(QPainter *painter, const QRect &repaintRegion)
painter->setPen(Qt::NoPen);
painter->setBrush(c->palette().color(QPalette::Active, QPalette::Base));
painter->drawRoundedRect(rect, 0, 0);

}
else
{
auto rect = QRect(0, 0, (c->size().width() + m_borderLeft + m_borderRight), (c->size().height() + m_borderTop + m_borderBottom));
painter->setPen(Qt::NoPen);
painter->setBrush(c->palette().color(QPalette::Active, QPalette::Base));
painter->setBrush(c->palette().color(this->client().data()->isActive() ? QPalette::Active : QPalette::Disabled, QPalette::Base));
// 控制左上、右上的阴影
painter->drawRoundedRect(rect, m_shadowRadius, m_shadowRadius);

Expand Down
4 changes: 3 additions & 1 deletion plugins/kdecorations/ukui/ukui-decoration.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class Decoration : public KDecoration2::Decoration
QColor m_fontActiveColor; //活动字体颜色
QColor m_fontInactiveColor; //非活动字体颜色

QColor m_BorderColor; //边框颜色

int m_nleftButtonCout;
int m_nrightButtonCout;

Expand All @@ -116,7 +118,7 @@ public slots:
void calculateBorders();
void calculateRightButtonCout();
void updateTitleBar();
void updateShadow();
void updateShadow(int themeId);
void themeUpdate(int themeId);
void updatefont(QFont font);

Expand Down

0 comments on commit 8e4a53a

Please sign in to comment.