taskbarbutton.cpp
1 //------------------------------------------------------------------------------
2 // taskbarbutton.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library 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 GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; 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 = nullptr;
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 != nullptr)
81  return d->button->overlayAccessibleDescription();
82 
83  #endif
84  return QString();
85 }
86 
87 QIcon TaskbarButton::overlayIcon() const
88 {
89  #ifdef WIN_TASKBAR
90  if (d->button != nullptr)
91  return d->button->overlayIcon();
92 
93  #endif
94  return QIcon();
95 }
96 
97 TaskbarProgress *TaskbarButton::progress() const
98 {
99  return d->progress;
100 }
101 
102 void TaskbarButton::setWindow(QWindow *window)
103 {
104  #ifdef WIN_TASKBAR
105  if (d->button != nullptr)
106  d->button->setWindow(window);
107  #else
108  Q_UNUSED(window);
109  #endif
110 }
111 
112 QWindow *TaskbarButton::window() const
113 {
114  #ifdef WIN_TASKBAR
115  if (d->button != nullptr)
116  return d->button->window();
117 
118  #endif
119  return nullptr;
120 }
121 
122 void TaskbarButton::clearOverlayIcon()
123 {
124  #ifdef WIN_TASKBAR
125  if (d->button != nullptr)
126  d->button->clearOverlayIcon();
127 
128  #endif
129 }
130 
131 void TaskbarButton::setOverlayAccessibleDescription(const QString &description)
132 {
133  #ifdef WIN_TASKBAR
134  if (d->button != nullptr)
135  d->button->setOverlayAccessibleDescription(description);
136  #else
137  Q_UNUSED(description);
138  #endif
139 }
140 
141 void TaskbarButton::setOverlayIcon(const QIcon &icon)
142 {
143  #ifdef WIN_TASKBAR
144  if (d->button != nullptr)
145  d->button->setOverlayIcon(icon);
146  #else
147  Q_UNUSED(icon);
148  #endif
149 }