Skip to content

Commit

Permalink
fix: Missing radius for tray's background
Browse files Browse the repository at this point in the history
  Add a common function to draw rounded background.

Issue: linuxdeepin/developer-center#3744
  • Loading branch information
asterwyx authored and 18202781743 committed Mar 8, 2023
1 parent 724edd7 commit 83421d0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
9 changes: 3 additions & 6 deletions frame/window/components/datetimedisplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "dockpopupwindow.h"
#include "utils.h"
#include "dbusutil.h"
#include "traymanagerwindow.h"

#include <DFontSizeManager>
#include <DDBusSender>
Expand Down Expand Up @@ -272,12 +273,8 @@ void DateTimeDisplayer::paintEvent(QPaintEvent *e)
painter.setPen(QPen(palette().brightText(), 1));

// 绘制背景色
if (m_isEnter) {
QColor backColor = DGuiApplicationHelper::ColorType::DarkType == DGuiApplicationHelper::instance()->themeType() ? QColor(20, 20, 20) : Qt::white;
backColor.setAlphaF(0.2);
// 鼠标进入的时候,绘制底色
painter.fillRect(rect(), backColor);
}
if (m_isEnter)
TrayManagerWindow::drawHoveredRoundedAreaBackground(this);

int timeAlignFlag = Qt::AlignCenter;
int dateAlignFlag = Qt::AlignCenter;
Expand Down
10 changes: 4 additions & 6 deletions frame/window/systempluginwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "systempluginitem.h"
#include "quicksettingcontroller.h"
#include "utils.h"
#include "traymanagerwindow.h"

#include <DListView>
#include <DGuiApplicationHelper>
Expand Down Expand Up @@ -266,12 +267,9 @@ void StretchPluginsItem::paintEvent(QPaintEvent *event)
rctPixmap.setHeight(ICONSIZE);
}

if (m_isEnter) {
QColor backColor = DGuiApplicationHelper::ColorType::DarkType == DGuiApplicationHelper::instance()->themeType() ? QColor(20, 20, 20) : Qt::white;
backColor.setAlphaF(0.2);
// 鼠标进入的时候,绘制底色
painter.fillRect(rect(), backColor);
}
if (m_isEnter)
TrayManagerWindow::drawHoveredRoundedAreaBackground(this);

// 绘制图标
int iconSize = static_cast<int>(ICONSIZE * (QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? 1 : qApp->devicePixelRatio()));
painter.drawPixmap(rctPixmap, icon.pixmap(iconSize, iconSize));
Expand Down
15 changes: 15 additions & 0 deletions frame/window/traymanagerwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,21 @@ QSize TrayManagerWindow::suitableSize(const Dock::Position &position) const
return QSize(QWIDGETSIZE_MAX, height);
}

void TrayManagerWindow::drawHoveredRoundedAreaBackground(QWidget *widget)
{
const int radius = qApp->property("trayBorderRadius").toInt();
if (Q_UNLIKELY(!widget) || radius <= 0)
return;

QPainter painter(widget);
QColor backColor = DGuiApplicationHelper::ColorType::DarkType == DGuiApplicationHelper::instance()->themeType() ? QColor(20, 20, 20) : Qt::white;
backColor.setAlphaF(0.2);
painter.setPen(Qt::NoPen);
painter.setBrush(backColor);

painter.drawRoundedRect(widget->rect(), radius, radius);
}

// 用于返回需要绘制的圆形区域
QPainterPath TrayManagerWindow::roundedPaths()
{
Expand Down
2 changes: 2 additions & 0 deletions frame/window/traymanagerwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ class TrayManagerWindow : public QWidget
QSize suitableSize() const;
QSize suitableSize(const Dock::Position &position) const;

static void drawHoveredRoundedAreaBackground(QWidget *widget);

Q_SIGNALS:
void requestUpdate();

Expand Down

0 comments on commit 83421d0

Please sign in to comment.