-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathQQuickWindowIconHelper.cpp
47 lines (40 loc) · 1.39 KB
/
QQuickWindowIconHelper.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
#include "QQuickWindowIconHelper.h"
#include <QUrl>
#include <QIcon>
#include <QWindow>
#include <QQuickWindow>
QQuickWindowIconHelper::QQuickWindowIconHelper (QQuickItem * parent)
: QQuickItem (parent)
{
connect (this, &QQuickWindowIconHelper::windowChanged, this, &QQuickWindowIconHelper::refreshWindowIcon);
connect (this, &QQuickWindowIconHelper::iconPathChanged, this, &QQuickWindowIconHelper::refreshWindowIcon);
}
void QQuickWindowIconHelper::componentComplete (void) {
QQuickItem::componentComplete ();
refreshWindowIcon ();
}
const QString & QQuickWindowIconHelper::getIconPath (void) const {
return m_iconPath;
}
void QQuickWindowIconHelper::setIconPath (const QString & iconPath) {
if (m_iconPath != iconPath) {
m_iconPath = iconPath;
emit iconPathChanged (iconPath);
}
}
void QQuickWindowIconHelper::refreshWindowIcon (void) {
if (window ()) {
if (m_iconPath.startsWith ("file://")) {
window ()->setIcon (QIcon (QUrl (m_iconPath).toLocalFile ()));
}
else if (m_iconPath.startsWith ("qrc:///")) {
window ()->setIcon (QIcon (m_iconPath.replace ("qrc:///", ":/")));
}
else if (m_iconPath.startsWith ("qrc://")) {
window ()->setIcon (QIcon (m_iconPath.replace ("qrc://", ":/")));
}
else {
window ()->setIcon (QIcon (m_iconPath));
}
}
}