From 742403b09fbbd45ff355a89023904bf996610698 Mon Sep 17 00:00:00 2001 From: wangfei Date: Thu, 22 Aug 2024 16:14:10 +0800 Subject: [PATCH] chore: tweak menu animation 1.add antialising 2.add shadow 3.add submenu background Log: --- styleplugins/chameleon/chameleonstyle.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/styleplugins/chameleon/chameleonstyle.cpp b/styleplugins/chameleon/chameleonstyle.cpp index 91feeb8..30cd590 100644 --- a/styleplugins/chameleon/chameleonstyle.cpp +++ b/styleplugins/chameleon/chameleonstyle.cpp @@ -3002,6 +3002,7 @@ ChameleonMovementAnimation *ChameleonStyle::drawMenuItemBackground(const QStyleO return nullptr; } + if (!selected) { do { color = option->palette.window().color(); @@ -3064,6 +3065,12 @@ ChameleonMovementAnimation *ChameleonStyle::drawMenuItemBackground(const QStyleO if (selected) animation->setTargetRect(option->rect); } + + if (type == QStyleOptionMenuItem::SubMenu) { + color = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType ? + QColor(0, 0, 0, 255 * 0.15): QColor(255, 255, 255, 255 * 0.2); + } + const int round = 6; if (animation && animation->isRuning()) { painter->save(); @@ -3072,15 +3079,19 @@ ChameleonMovementAnimation *ChameleonStyle::drawMenuItemBackground(const QStyleO painter->setOpacity(1.0); painter->setBrush(color); painter->setPen(Qt::NoPen); + painter->setRenderHint(QPainter::Antialiasing); painter->drawRoundedRect(animation->currentRect(), round, round); painter->setOpacity(opacity); painter->restore(); return animation; } else if (selected) { + const QMargins &margins = frameExtentMargins(); + drawShadow(painter, option->rect - margins, getColor(option, QPalette::Shadow)); painter->save(); painter->setBrush(color); painter->setPen(Qt::NoPen); + painter->setRenderHint(QPainter::Antialiasing); painter->drawRoundedRect(option->rect, round, round); painter->restore(); }