Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qdbustraytypes.cpp
Go to the documentation of this file.
1
// Copyright (C) 2009 Marco Martin <notmart@gmail.com>
2
// Copyright (C) 2016 The Qt Company Ltd.
3
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
// Qt-Security score:significant reason:default
5
6
#
ifndef
QT_NO_SYSTEMTRAYICON
7
8
#
include
"qdbustraytypes_p.h"
9
10
#
include
<
QDBusConnection
>
11
#
include
<
QDBusMetaType
>
12
#
include
<
QImage
>
13
#
include
<
QIcon
>
14
#
include
<
QIconEngine
>
15
#
include
<
QImage
>
16
#
include
<
QPixmap
>
17
#
include
<
QDebug
>
18
#
include
<
QtEndian
>
19
#
include
<
QPainter
>
20
#
include
<
QGuiApplication
>
21
#
include
<
qpa
/
qplatformmenu
.
h
>
22
#
include
<
private
/
qdbusplatformmenu_p
.
h
>
23
#
include
<
private
/
qicon_p
.
h
>
24
25
QT_BEGIN_NAMESPACE
26
27
QT_IMPL_METATYPE_EXTERN(QXdgDBusImageStruct)
28
QT_IMPL_METATYPE_EXTERN(QXdgDBusImageVector)
29
QT_IMPL_METATYPE_EXTERN(QXdgDBusToolTipStruct)
30
31
static
const
int
IconSizeLimit = 64;
32
static
const
int
IconNormalSmallSize
= 22;
33
static
const
int
IconNormalMediumSize
= 64;
34
35
QXdgDBusImageVector
iconToQXdgDBusImageVector
(
const
QIcon &icon)
36
{
37
QXdgDBusImageVector ret;
38
if
(icon.isNull())
39
return
ret;
40
QIconEngine *engine =
const_cast
<QIcon &>(icon).data_ptr()->engine;
41
QList<QSize> sizes = engine->availableSizes(QIcon::Normal, QIcon::Off);
42
43
// Omit any size larger than 64 px, to save D-Bus bandwidth;
44
// ensure that 22px or smaller exists, because it's a common size;
45
// and ensure that something between 22px and 64px exists, for better scaling to other sizes.
46
bool
hasSmallIcon =
false
;
47
bool
hasMediumIcon =
false
;
48
QList<QSize> toRemove;
49
for
(
const
QSize &size : std::as_const(sizes)) {
50
int
maxSize = qMax(size.width(), size.height());
51
if
(maxSize <= IconNormalSmallSize)
52
hasSmallIcon =
true
;
53
else
if
(maxSize <= IconNormalMediumSize)
54
hasMediumIcon =
true
;
55
else
if
(maxSize > IconSizeLimit)
56
toRemove << size;
57
}
58
for
(
const
QSize &size : std::as_const(toRemove))
59
sizes.removeOne(size);
60
if
(!hasSmallIcon)
61
sizes.append(QSize(
IconNormalSmallSize
,
IconNormalSmallSize
));
62
if
(!hasMediumIcon)
63
sizes.append(QSize(
IconNormalMediumSize
,
IconNormalMediumSize
));
64
65
ret.reserve(sizes.size());
66
for
(
const
QSize &size : std::as_const(sizes)) {
67
// Protocol specifies ARGB32 format in network byte order
68
QImage im = engine->pixmap(size, QIcon::Normal, QIcon::Off).toImage().convertToFormat(QImage::Format_ARGB32);
69
// letterbox if necessary to make it square
70
if
(im.height() != im.width()) {
71
int
maxSize = qMax(im.width(), im.height());
72
QImage padded(maxSize, maxSize, QImage::Format_ARGB32);
73
padded.fill(Qt::transparent);
74
QPainter painter(&padded);
75
painter.drawImage((maxSize - im.width()) / 2, (maxSize - im.height()) / 2, im);
76
im = padded;
77
}
78
// copy and endian-convert
79
QXdgDBusImageStruct kim(im.width(), im.height());
80
qToBigEndian<quint32>(im.constBits(), im.width() * im.height(), kim.data.data());
81
82
ret << kim;
83
}
84
return
ret;
85
}
86
87
// Marshall the ImageStruct data into a D-Bus argument
88
const
QDBusArgument
&
operator
<<(QDBusArgument &argument,
const
QXdgDBusImageStruct &icon)
89
{
90
argument.beginStructure();
91
argument << icon.width;
92
argument << icon.height;
93
argument << icon.data;
94
argument.endStructure();
95
return
argument;
96
}
97
98
// Retrieve the ImageStruct data from the D-Bus argument
99
const
QDBusArgument
&
operator
>>(
const
QDBusArgument &argument, QXdgDBusImageStruct &icon)
100
{
101
qint32 width;
102
qint32 height;
103
QByteArray data;
104
105
argument.beginStructure();
106
argument >> width;
107
argument >> height;
108
argument >> data;
109
argument.endStructure();
110
111
icon.width = width;
112
icon.height = height;
113
icon.data = data;
114
115
return
argument;
116
}
117
118
// Marshall the ImageVector data into a D-Bus argument
119
const
QDBusArgument
&
operator
<<(QDBusArgument &argument,
const
QXdgDBusImageVector &iconVector)
120
{
121
argument.beginArray(qMetaTypeId<QXdgDBusImageStruct>());
122
for
(
int
i = 0; i < iconVector.size(); ++i) {
123
argument << iconVector[i];
124
}
125
argument.endArray();
126
return
argument;
127
}
128
129
// Retrieve the ImageVector data from the D-Bus argument
130
const
QDBusArgument
&
operator
>>(
const
QDBusArgument &argument, QXdgDBusImageVector &iconVector)
131
{
132
argument.beginArray();
133
iconVector.clear();
134
135
while
(!argument.atEnd()) {
136
QXdgDBusImageStruct element;
137
argument >> element;
138
iconVector.append(element);
139
}
140
141
argument.endArray();
142
143
return
argument;
144
}
145
146
// Marshall the ToolTipStruct data into a D-Bus argument
147
const
QDBusArgument
&
operator
<<(QDBusArgument &argument,
const
QXdgDBusToolTipStruct
&toolTip)
148
{
149
argument.beginStructure();
150
argument << toolTip.icon;
151
argument << toolTip.image;
152
argument << toolTip.title;
153
argument << toolTip.subTitle;
154
argument.endStructure();
155
return
argument;
156
}
157
158
// Retrieve the ToolTipStruct data from the D-Bus argument
159
const
QDBusArgument
&
operator
>>(
const
QDBusArgument &argument,
QXdgDBusToolTipStruct
&toolTip)
160
{
161
QString icon;
162
QXdgDBusImageVector image;
163
QString title;
164
QString subTitle;
165
166
argument.beginStructure();
167
argument >> icon;
168
argument >> image;
169
argument >> title;
170
argument >> subTitle;
171
argument.endStructure();
172
173
toolTip.icon = icon;
174
toolTip.image = image;
175
toolTip.title = title;
176
toolTip.subTitle = subTitle;
177
178
return
argument;
179
}
180
181
QT_END_NAMESPACE
182
#
endif
// QT_NO_SYSTEMTRAYICON
operator>>
const QDBusArgument & operator>>(const QDBusArgument &argument, QXdgDBusImageVector &iconVector)
Definition
qdbustraytypes.cpp:130
IconNormalMediumSize
static const int IconNormalMediumSize
Definition
qdbustraytypes.cpp:33
operator>>
const QDBusArgument & operator>>(const QDBusArgument &argument, QXdgDBusImageStruct &icon)
Definition
qdbustraytypes.cpp:99
operator>>
const QDBusArgument & operator>>(const QDBusArgument &argument, QXdgDBusToolTipStruct &toolTip)
Definition
qdbustraytypes.cpp:159
IconNormalSmallSize
static const int IconNormalSmallSize
Definition
qdbustraytypes.cpp:32
iconToQXdgDBusImageVector
QXdgDBusImageVector iconToQXdgDBusImageVector(const QIcon &icon)
Definition
qdbustraytypes.cpp:35
operator<<
const QDBusArgument & operator<<(QDBusArgument &argument, const QXdgDBusImageStruct &icon)
Definition
qdbustraytypes.cpp:88
operator<<
const QDBusArgument & operator<<(QDBusArgument &argument, const QXdgDBusToolTipStruct &toolTip)
Definition
qdbustraytypes.cpp:147
operator<<
QDataStream & operator<<(QDataStream &stream, const QImage &image)
[0]
Definition
qimage.cpp:4045
QXdgDBusToolTipStruct
Definition
qdbustraytypes_p.h:51
qtbase
src
gui
platform
unix
dbustray
qdbustraytypes.cpp
Generated on
for Qt by
1.18.0