-
Notifications
You must be signed in to change notification settings - Fork 7
/
QTaskBarButton.cpp
175 lines (147 loc) · 3.6 KB
/
QTaskBarButton.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/****************************************************************************
** Hyne Final Fantasy VIII Save Editor
** Copyright (C) 2009-2024 Arzel Jérôme <myst6re@gmail.com>
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "QTaskBarButton.h"
#ifdef QTASKBAR_WIN
QTaskBarButton::QTaskBarButton(QWidget *mainWindow) :
QObject(mainWindow), pITask(0), _minimum(0), _maximum(100),
_value(0), _state(Invisible)
{
_winId = mainWindow->window()->winId();
CoInitialize(nullptr);
HRESULT hRes = CoCreateInstance(CLSID_TaskbarList,
nullptr, CLSCTX_INPROC_SERVER,
IID_ITaskbarList3, (LPVOID*)&pITask);
if (FAILED(hRes)) {
pITask = 0;
CoUninitialize();
return;
}
pITask->HrInit();
}
QTaskBarButton::~QTaskBarButton()
{
if (pITask) {
pITask->Release();
pITask = nullptr;
CoUninitialize();
}
}
void QTaskBarButton::setOverlayIcon(const QImage &image, const QString &text)
{
if (!pITask) {
return;
}
if (image.isNull()) {
pITask->SetOverlayIcon(HWND(_winId), nullptr, nullptr);
} else {
const HICON icon = image.toHICON();
pITask->SetOverlayIcon(HWND(_winId), icon, (wchar_t *)text.utf16());
DestroyIcon(icon);
}
}
void QTaskBarButton::setState(State state)
{
if (!pITask) return;
TBPFLAG flag;
switch (state) {
case Invisible: flag = TBPF_NOPROGRESS;
break;
case Indeterminate: flag = TBPF_INDETERMINATE;
break;
case Paused: flag = TBPF_PAUSED;
break;
case Error: flag = TBPF_ERROR;
break;
default: flag = TBPF_NORMAL;
break;
}
if (S_OK == pITask->SetProgressState(HWND(_winId), flag)) {
_state = state;
}
}
void QTaskBarButton::setValue(int value)
{
if (!pITask) {
return;
}
int completed = value - _minimum, total = _maximum - _minimum;
if (completed < 0 || total <= 0) {
return;
}
if (S_OK == pITask->SetProgressValue(HWND(_winId), completed, total)) {
_value = value;
emit valueChanged(value);
}
}
#elif !defined(QTASKBAR_APPLE)
QTaskBarButton::QTaskBarButton(QWidget *parent) :
QObject(parent), _minimum(0), _maximum(100),
_value(0), _state(Invisible)
{
}
QTaskBarButton::~QTaskBarButton()
{
}
void QTaskBarButton::setOverlayIcon(const QImage &image, const QString &text)
{
Q_UNUSED(image)
Q_UNUSED(text)
}
void QTaskBarButton::setState(State state)
{
Q_UNUSED(state)
}
void QTaskBarButton::setValue(int value)
{
Q_UNUSED(value)
}
#endif
int QTaskBarButton::maximum() const
{
return _maximum;
}
int QTaskBarButton::minimum() const
{
return _minimum;
}
QTaskBarButton::State QTaskBarButton::state() const
{
return _state;
}
int QTaskBarButton::value() const
{
return _value;
}
void QTaskBarButton::reset()
{
setState(Normal);
setValue(0);
}
void QTaskBarButton::setMaximum(int maximum)
{
_maximum = maximum;
}
void QTaskBarButton::setMinimum(int minimum)
{
_minimum = minimum;
}
void QTaskBarButton::setRange(int minimum, int maximum)
{
setMinimum(minimum);
setMaximum(maximum);
}