This repository has been archived by the owner on Jul 4, 2024. It is now read-only.
forked from Skycoder42/QTaskbarControl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
qtaskbarcontrol_win.cpp
107 lines (89 loc) · 2.45 KB
/
qtaskbarcontrol_win.cpp
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
#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);
}
void QWinTaskbarControl::setWindowsProgressState(QTaskbarControl::WinProgressState state)
{
_button->progress()->resume();
switch (state) {
case QTaskbarControl::Running:
case QTaskbarControl::Paused:
_button->progress()->pause();
break;
case QTaskbarControl::Stopped:
_button->progress()->stop();
}
}
QTaskbarControl::WinProgressState QWinTaskbarControl::windowsProgressState() const
{
if(_button->progress()->isStopped())
return QTaskbarControl::Stopped;
if (_button->progress()->isPaused())
return QTaskbarControl::Paused;
return QTaskbarControl::Running;
}
void QWinTaskbarControl::setWindowsBadgeIcon(const QIcon &icon)
{
if(!icon.isNull()) {
_badgeIcon = icon;
setCounter(_q_ptr->counterVisible(), _q_ptr->counter());
}
}
QIcon QWinTaskbarControl::windowsBadgeIcon() const
{
return _badgeIcon;
}
void QWinTaskbarControl::setWindowsBadgeTextColor(const QColor &color)
{
_badgeColor = color;
setCounter(_q_ptr->counterVisible(), _q_ptr->counter());
}
QColor QWinTaskbarControl::windowsBadgeTextColor() const
{
return _badgeColor;
}
void QWinTaskbarControl::setProgress(bool visible, double value)
{
if(value < 0)
_button->progress()->setRange(0, 0);
else {
_button->progress()->setRange(0, 1000);
_button->progress()->setValue(static_cast<int>(value * 1000));
}
_button->progress()->setVisible(visible);
}
void QWinTaskbarControl::setCounter(bool visible, int value)
{
if(visible) {
QIcon currentBadge;
auto text = QLocale{}.toString(value);
foreach(auto size, _badgeIcon.availableSizes()) {
auto pm = _badgeIcon.pixmap(size);
pm.setDevicePixelRatio(1);
QPainter painter{&pm};
auto font = painter.font();
font.setPixelSize(static_cast<int>(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();
}