Skip to content

Commit d4cd163

Browse files
committed
fix: Modify icon color processing
Modify icon color processing pms: TASK-361719
1 parent 6886ce2 commit d4cd163

3 files changed

Lines changed: 29 additions & 19 deletions

File tree

dock-network-plugin/quickpanelwidget.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ class QuickButton : public DFloatingButton
5656
}
5757
option->palette.setBrush(QPalette::Button, bgColor);
5858
option->palette.setBrush(QPalette::ButtonText, textColor);
59-
option->palette.setBrush(QPalette::WindowText, Qt::red);
6059
option->state.setFlag(QStyle::State_MouseOver, false);
6160
option->state.setFlag(QStyle::State_Sunken, false);
6261
option->state.setFlag(QStyle::State_Raised, true);
@@ -79,19 +78,12 @@ QuickPanelWidget::~QuickPanelWidget() { }
7978
void QuickPanelWidget::setIcon(const QIcon &icon)
8079
{
8180

82-
// DDciIcon dciIcon = DDciIcon::fromTheme(icon.name());
83-
// if(dciIcon.isNull()){
81+
DDciIcon dciIcon = DDciIcon::fromTheme(icon.name());
82+
if (dciIcon.isNull()) {
8483
m_iconWidget->setIcon(icon);
85-
// }else{
86-
// m_iconWidget->setIcon(dciIcon);
87-
// }
88-
// m_iconWidget->setIcon(icon);
89-
// // "network-wireless-6-offline-secure-symbolic"
90-
// DDciIcon::fromTheme("network-wireless-6-offline-secure-symbolic");
91-
// m_iconWidget->setIcon(DDciIcon::fromTheme("network-wireless-6-offline-secure-symbolic"));
92-
// DDciIcon::fromTheme("network-wireless-6-offline-secure-symbolic");
93-
// m_iconWidget->setIcon(QIcon::fromTheme("network-wireless-6-offline-secure-symbolic"));
94-
// network-wireless-6-signal-full-secure-symbolic_16px.svg
84+
} else {
85+
m_iconWidget->setIcon(dciIcon);
86+
}
9587
}
9688

9789
void QuickPanelWidget::setText(const QString &text)

net-view/window/private/neticonbutton.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ NetIconButton::NetIconButton(QWidget *parent)
1717
, m_clickable(false)
1818
, m_rotatable(false)
1919
, m_hover(false)
20+
, m_textType(true)
2021
{
2122
setAccessibleName("NetIconButton");
2223
setFixedSize(24, 24);
@@ -50,6 +51,12 @@ void NetIconButton::setRotatable(bool rotatable)
5051
}
5152
}
5253

54+
void NetIconButton::setTextType(bool textType)
55+
{
56+
m_textType = textType;
57+
update();
58+
}
59+
5360
void NetIconButton::startRotate()
5461
{
5562
if (!m_refreshTimer) {
@@ -93,18 +100,27 @@ void NetIconButton::paintEvent(QPaintEvent *e)
93100
return;
94101
QPainter painter(this);
95102
painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
96-
103+
QRect r = rect();
97104
if (m_rotateAngle != 0) {
98-
painter.translate(this->width() / 2, this->height() / 2);
105+
painter.translate(r.width() / 2, r.height() / 2);
99106
painter.rotate(m_rotateAngle);
100-
painter.translate(-(this->width() / 2), -(this->height() / 2));
107+
painter.translate(-(r.width() / 2), -(r.height() / 2));
101108
}
102-
109+
const qreal scale = devicePixelRatio();
110+
QSize pixmapSize = r.size() * scale;
111+
QPixmap pm;
103112
if (m_hover && !m_hoverIcon.isNull()) {
104-
m_hoverIcon.paint(&painter, rect());
113+
pm = m_hoverIcon.pixmap(pixmapSize);
105114
} else {
106-
m_icon.paint(&painter, rect());
115+
pm = m_icon.pixmap(pixmapSize);
116+
}
117+
if (m_textType) {
118+
QPainter pa(&pm);
119+
pa.setCompositionMode(QPainter::CompositionMode_SourceIn);
120+
pa.fillRect(r, painter.pen().brush());
107121
}
122+
pm.setDevicePixelRatio(scale);
123+
painter.drawPixmap(r, pm);
108124
}
109125

110126
void NetIconButton::mousePressEvent(QMouseEvent *event)

net-view/window/private/neticonbutton.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public Q_SLOTS:
2222

2323
void setClickable(bool clickable);
2424
void setRotatable(bool rotatable);
25+
void setTextType(bool textType);
2526

2627
signals:
2728
void clicked();
@@ -44,6 +45,7 @@ public Q_SLOTS:
4445
bool m_clickable;
4546
bool m_rotatable;
4647
bool m_hover;
48+
bool m_textType;
4749
};
4850

4951
} // namespace network

0 commit comments

Comments
 (0)