This repository was archived by the owner on Jun 19, 2020. It is now read-only.
forked from Skycoder42/QTaskbarControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqtaskbarcontrol_win.cpp
More file actions
114 lines (101 loc) · 2.75 KB
/
Copy pathqtaskbarcontrol_win.cpp
File metadata and controls
114 lines (101 loc) · 2.75 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
#include "qtaskbarcontrol_win.h"
#include <QLocale>
#include <QPainter>
#include <QWinTaskbarProgress>
QTaskbarControlPrivate *QTaskbarControlPrivate::createPrivate(QTaskbarControl *q_ptr)
{
return new QWinTaskbarControl{q_ptr};
}
QWinTaskbarControl::QWinTaskbarControl(QTaskbarControl *q_ptr) :
_q_ptr{q_ptr},
_button{new QWinTaskbarButton{q_ptr}}
{}
void QWinTaskbarControl::setWindow(QWindow *window)
{
if(_button->window() == window)
return;
_button->setWindow(window);
}
bool QWinTaskbarControl::setAttribute(QTaskbarControl::SetupKey key, const QVariant &data)
{
switch (key) {
case QTaskbarControl::WindowsProgressState:
_button->progress()->resume();
switch (data.toInt()) {
case QTaskbarControl::Running:
return true;
case QTaskbarControl::Paused:
_button->progress()->pause();
return true;
case QTaskbarControl::Stopped:
_button->progress()->stop();
return true;
default:
return false;
}
case QTaskbarControl::WindowsBadgeIcon:
{
auto icon = data.value<QIcon>();
if(!icon.isNull()) {
_badgeIcon = icon;
setCounter(_q_ptr->counterVisible(), _q_ptr->counter());
return true;
} else
return false;
}
case QTaskbarControl::WindowsBadgeTextColor:
_badgeColor = data.value<QColor>();
setCounter(_q_ptr->counterVisible(), _q_ptr->counter());
default:
return false;
}
}
QVariant QWinTaskbarControl::attribute(QTaskbarControl::SetupKey key)
{
switch (key) {
case QTaskbarControl::WindowsProgressState:
if(_button->progress()->isStopped())
return QTaskbarControl::Stopped;
else if (_button->progress()->isPaused())
return QTaskbarControl::Paused;
else
return QTaskbarControl::Running;
case QTaskbarControl::WindowsBadgeIcon:
return QVariant::fromValue(_badgeIcon);
case QTaskbarControl::WindowsBadgeTextColor:
return _badgeColor;
default:
return QVariant();
}
}
void QWinTaskbarControl::setProgress(bool progressVisible, double progress)
{
if(progress < 0)
_button->progress()->setRange(0, 0);
else {
_button->progress()->setRange(0, 1000);
_button->progress()->setValue(progress * 1000);
}
_button->progress()->setVisible(progressVisible);
}
void QWinTaskbarControl::setCounter(bool counterVisible, int counter)
{
if(counterVisible) {
QIcon currentBadge;
auto text = QLocale{}.toString(counter);
foreach(auto size, _badgeIcon.availableSizes()) {
auto pm = _badgeIcon.pixmap(size);
pm.setDevicePixelRatio(1);
QPainter painter{&pm};
auto font = painter.font();
font.setPixelSize(pm.height() * 0.6);
painter.setFont(font);
painter.setPen(_badgeColor);
painter.drawText(pm.rect(), Qt::AlignCenter, text);
currentBadge.addPixmap(pm);
}
_button->setOverlayIcon(currentBadge);
_button->setOverlayAccessibleDescription(text);
} else
_button->clearOverlayIcon();
}