forked from linuxdeepin/dde-tray-loader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjumpcalendarbutton.cpp
More file actions
145 lines (125 loc) · 3.71 KB
/
Copy pathjumpcalendarbutton.cpp
File metadata and controls
145 lines (125 loc) · 3.71 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
143
144
145
// SPDX-FileCopyrightText: 2019 - 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "jumpcalendarbutton.h"
#include <QHBoxLayout>
#include <QProcess>
#include <QMouseEvent>
#include <DFontSizeManager>
#include <DPlatformTheme>
#include <DDBusSender>
#include <DPaletteHelper>
DWIDGET_USE_NAMESPACE
DGUI_USE_NAMESPACE
JumpCalendarButton::JumpCalendarButton(QWidget *parent)
: QFrame(parent)
, m_hover(false)
, m_mousePress(false)
, m_iconButton(new CommonIconButton(this))
, m_descriptionLabel(new DLabel(this))
{
initUI();
}
JumpCalendarButton::JumpCalendarButton(const QIcon& icon, const QString& description, QWidget* parent)
: QFrame(parent)
, m_hover(false)
, m_mousePress(false)
, m_iconButton(new CommonIconButton(this))
, m_descriptionLabel(new DLabel(this))
{
initUI();
m_iconButton->setIcon(icon);
m_descriptionLabel->setText(description);
}
JumpCalendarButton::~JumpCalendarButton()
{
}
void JumpCalendarButton::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->addSpacing(5);
layout->addWidget(m_descriptionLabel);
layout->addStretch();
}
void JumpCalendarButton::setIcon(const QIcon &icon)
{
m_iconButton->setIcon(icon, Qt::black, Qt::white);
}
void JumpCalendarButton::setDescription(const QString& description)
{
m_descriptionLabel->setText(description);
}
bool JumpCalendarButton::event(QEvent* e)
{
switch (e->type()) {
case QEvent::Leave:
case QEvent::Enter:
m_hover = e->type() == QEvent::Enter;
update();
break;
default:
break;
}
return QWidget::event(e);
}
void JumpCalendarButton::paintEvent(QPaintEvent* e)
{
Q_UNUSED(e)
QPainter p(this);
QPalette palette = this->palette();
QColor bgColor, textColor;
if (m_mousePress) {
textColor = palette.highlight().color();
bgColor = palette.windowText().color();
bgColor.setAlphaF(0.15);
} else if(m_hover) {
textColor = palette.windowText().color();
bgColor = palette.windowText().color();
bgColor.setAlphaF(0.1);
} else {
textColor = palette.windowText().color();
bgColor = DPaletteHelper::instance()->palette(this).color(DPalette::ItemBackground);
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 JumpCalendarButton::mousePressEvent(QMouseEvent *event)
{
if(m_mousePress != true) {
m_mousePress = true;
update();
}
QWidget::mouseReleaseEvent(event);
}
void JumpCalendarButton::mouseReleaseEvent(QMouseEvent* event)
{
if(m_mousePress == true) {
m_mousePress = false;
update();
}
if (underMouse() && this->rect().contains(event->pos())) {
Q_EMIT clicked();
QProcess::startDetached("dbus-send", QStringList()
<< "--print-reply"
<< "--dest=com.deepin.Calendar"
<< "/com/deepin/Calendar"
<< "com.deepin.Calendar.RaiseWindow");
}
QWidget::mouseReleaseEvent(event);
}