taskbarbutton.cpp
1 //------------------------------------------------------------------------------
2 // taskbarbutton.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2015 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "taskbarbutton.h"
24 
25 #include "gui/helpers/taskbarprogress.h"
26 
27 #if (QT_VERSION >= QT_VERSION_CHECK(5, 2, 0)) && defined(Q_OS_WIN32)
28 #define WIN_TASKBAR
29 #endif
30 
31 #ifdef WIN_TASKBAR
32 #include <QWinTaskbarButton>
33 #endif
34 
35 #include <QIcon>
36 #include <QString>
37 #include <QSysInfo>
38 
39 DClass<TaskbarButton>
40 {
41 public:
42 #ifdef WIN_TASKBAR
43  QWinTaskbarButton *button;
44 #endif
45  TaskbarProgress *progress;
46 
47  bool isAllowedOsVersion() const
48  {
49 #ifdef WIN_TASKBAR
50  return QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7;
51 #else
52  return false;
53 #endif
54  }
55 };
56 DPointered(TaskbarButton)
57 
58 TaskbarButton::TaskbarButton(QObject *parent)
59 : QObject(parent)
60 {
61 #ifdef WIN_TASKBAR
62  if (d->isAllowedOsVersion())
63  {
64  d->button = new QWinTaskbarButton(this);
65  d->progress = new TaskbarProgress(d->button->progress(), this);
66  }
67  else
68  {
69  d->button = NULL;
70  d->progress = new TaskbarProgress(this);
71  }
72 #else
73  d->progress = new TaskbarProgress(this);
74 #endif
75 }
76 
77 QString TaskbarButton::overlayAccessibleDescription() const
78 {
79 #ifdef WIN_TASKBAR
80  if (d->button != NULL)
81  {
82  return d->button->overlayAccessibleDescription();
83  }
84 #endif
85  return QString();
86 }
87 
88 QIcon TaskbarButton::overlayIcon() const
89 {
90 #ifdef WIN_TASKBAR
91  if (d->button != NULL)
92  {
93  return d->button->overlayIcon();
94  }
95 #endif
96  return QIcon();
97 }
98 
99 TaskbarProgress *TaskbarButton::progress() const
100 {
101  return d->progress;
102 }
103 
104 void TaskbarButton::setWindow(QWindow *window)
105 {
106 #ifdef WIN_TASKBAR
107  if (d->button != NULL)
108  {
109  d->button->setWindow(window);
110  }
111 #endif
112 }
113 
114 QWindow *TaskbarButton::window() const
115 {
116 #ifdef WIN_TASKBAR
117  if (d->button != NULL)
118  {
119  return d->button->window();
120  }
121 #endif
122  return NULL;
123 }
124 
125 void TaskbarButton::clearOverlayIcon()
126 {
127 #ifdef WIN_TASKBAR
128  if (d->button != NULL)
129  {
130  d->button->clearOverlayIcon();
131  }
132 #endif
133 }
134 
135 void TaskbarButton::setOverlayAccessibleDescription(const QString &description)
136 {
137 #ifdef WIN_TASKBAR
138  if (d->button != NULL)
139  {
140  d->button->setOverlayAccessibleDescription(description);
141  }
142 #endif
143 }
144 
145 void TaskbarButton::setOverlayIcon(const QIcon &icon)
146 {
147 #ifdef WIN_TASKBAR
148  if (d->button != NULL)
149  {
150  d->button->setOverlayIcon(icon);
151  }
152 #endif
153 }
Platform-agnostic wrapper for QWinTaskbarButton.
Definition: taskbarbutton.h:42
Platform-agnostic wrapper for QWinTaskbarProgress.