forked from linuxdeepin/dde-tray-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjumpsettingbutton.cpp
More file actions
142 lines (122 loc) · 3.65 KB
/
Copy pathjumpsettingbutton.cpp
File metadata and controls
142 lines (122 loc) · 3.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "jumpsettingbutton.h"
#include "dock-constants.h"
#include <QHBoxLayout>
#include <DFontSizeManager>
#include <DGuiApplicationHelper>
#include <DPlatformTheme>
#include <DDBusSender>
#include <DPaletteHelper>
DWIDGET_USE_NAMESPACE
JumpSettingButton::JumpSettingButton(QWidget *parent)
: QFrame(parent)
, m_hover(false)
, m_autoShowPage(true)
, m_iconButton(new CommonIconButton(this))
, m_descriptionLabel(new DLabel(this))
{
initUI();
}
JumpSettingButton::JumpSettingButton(const QIcon& icon, const QString& description, QWidget* parent)
: QFrame(parent)
, m_hover(false)
, m_autoShowPage(true)
, m_iconButton(new CommonIconButton(this))
, m_descriptionLabel(new DLabel(this))
{
initUI();
m_iconButton->setIcon(icon);
m_descriptionLabel->setText(description);
}
JumpSettingButton::~JumpSettingButton()
{
}
void JumpSettingButton::initUI()
{
setFixedHeight(36);
setForegroundRole(QPalette::BrightText);
m_iconButton->setFixedSize(16, 16);
m_iconButton->setForegroundRole(QPalette::BrightText);
m_descriptionLabel->setElideMode(Qt::ElideRight);
m_descriptionLabel->setForegroundRole(foregroundRole());
DFontSizeManager::instance()->bind(m_descriptionLabel, DFontSizeManager::T6);
auto* layout = new QHBoxLayout(this);
layout->setContentsMargins(10, 0, 10, 0);
layout->addWidget(m_iconButton);
layout->addWidget(m_descriptionLabel);
layout->addStretch();
}
void JumpSettingButton::setIcon(const QIcon &icon)
{
m_iconButton->setIcon(icon, Qt::black, Qt::white);
}
void JumpSettingButton::setDescription(const QString& description)
{
m_descriptionLabel->setText(description);
}
bool JumpSettingButton::event(QEvent* e)
{
switch (e->type()) {
case QEvent::Leave:
case QEvent::Enter:
m_hover = e->type() == QEvent::Enter;
update();
break;
case QEvent::Hide:
m_hover = false;
update();
break;
default:
break;
}
return QWidget::event(e);
}
void JumpSettingButton::paintEvent(QPaintEvent* e)
{
Q_UNUSED(e)
QPainter p(this);
QPalette palette = this->palette();
QColor bgColor, textColor;
if (m_hover) {
textColor = palette.highlightedText().color();
bgColor = palette.color(QPalette::Active, QPalette::Highlight);
} else {
textColor = palette.brightText().color();
bgColor = palette.brightText().color();
bgColor.setAlphaF(0.05);
}
palette.setBrush(QPalette::BrightText, textColor);
m_iconButton->setPalette(palette);
m_descriptionLabel->setPalette(palette);
p.setBrush(bgColor);
p.setRenderHint(QPainter::Antialiasing);
p.setPen(Qt::NoPen);
p.drawRoundedRect(rect(), 8, 8);
return QFrame::paintEvent(e);
}
void JumpSettingButton::mouseReleaseEvent(QMouseEvent* event)
{
if (underMouse()) {
Q_EMIT clicked();
if (m_autoShowPage && !m_fistPage.isEmpty()) {
DDBusSender()
.service("org.deepin.dde.ControlCenter1")
.path("/org/deepin/dde/ControlCenter1")
.interface("org.deepin.dde.ControlCenter1")
.method(QString("ShowPage"))
.arg(QString(m_fistPage))
//.arg(QString(m_secondPage))
.call();
Q_EMIT showPageRequestWasSended();
}
return;
}
return QWidget::mouseReleaseEvent(event);
}
void JumpSettingButton::setDccPage(const QString &first, const QString &second)
{
m_fistPage = first;
m_secondPage = second;
}