| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/platformsupport/dbustray/qdbustraytypes.cpp | 
| Source code | Switch to Preprocessed file | 
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2009 Marco Martin <notmart@gmail.com> | - | ||||||
| 4 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
| 5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
| 6 | ** | - | ||||||
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. | - | ||||||
| 8 | ** | - | ||||||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||
| 10 | ** Commercial License Usage | - | ||||||
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
| 12 | ** accordance with the commercial license agreement provided with the | - | ||||||
| 13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
| 16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||
| 17 | ** | - | ||||||
| 18 | ** GNU Lesser General Public License Usage | - | ||||||
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
| 20 | ** General Public License version 3 as published by the Free Software | - | ||||||
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
| 22 | ** packaging of this file. Please review the following information to | - | ||||||
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
| 25 | ** | - | ||||||
| 26 | ** GNU General Public License Usage | - | ||||||
| 27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
| 28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
| 29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
| 30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
| 32 | ** included in the packaging of this file. Please review the following | - | ||||||
| 33 | ** information to ensure the GNU General Public License requirements will | - | ||||||
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
| 36 | ** | - | ||||||
| 37 | ** $QT_END_LICENSE$ | - | ||||||
| 38 | ** | - | ||||||
| 39 | ****************************************************************************/ | - | ||||||
| 40 | - | |||||||
| 41 | #ifndef QT_NO_SYSTEMTRAYICON | - | ||||||
| 42 | - | |||||||
| 43 | #include "qdbustraytypes_p.h" | - | ||||||
| 44 | - | |||||||
| 45 | #include <QDBusConnection> | - | ||||||
| 46 | #include <QDBusMetaType> | - | ||||||
| 47 | #include <QImage> | - | ||||||
| 48 | #include <QIcon> | - | ||||||
| 49 | #include <QImage> | - | ||||||
| 50 | #include <QPixmap> | - | ||||||
| 51 | #include <QDebug> | - | ||||||
| 52 | #include <QtEndian> | - | ||||||
| 53 | #include <QPainter> | - | ||||||
| 54 | #include <QGuiApplication> | - | ||||||
| 55 | #include <qpa/qplatformmenu.h> | - | ||||||
| 56 | #include "qdbusplatformmenu_p.h" | - | ||||||
| 57 | - | |||||||
| 58 | QT_BEGIN_NAMESPACE | - | ||||||
| 59 | - | |||||||
| 60 | static const int IconSizeLimit = 64; | - | ||||||
| 61 | static const int IconNormalSmallSize = 22; | - | ||||||
| 62 | static const int IconNormalMediumSize = 64; | - | ||||||
| 63 | - | |||||||
| 64 | QXdgDBusImageVector iconToQXdgDBusImageVector(const QIcon &icon) | - | ||||||
| 65 | { | - | ||||||
| 66 | QXdgDBusImageVector ret; | - | ||||||
| 67 | QList<QSize> sizes = icon.availableSizes(); | - | ||||||
| 68 | - | |||||||
| 69 | // Omit any size larger than 64 px, to save D-Bus bandwidth; | - | ||||||
| 70 | // ensure that 22px or smaller exists, because it's a common size; | - | ||||||
| 71 | // and ensure that something between 22px and 64px exists, for better scaling to other sizes. | - | ||||||
| 72 | bool hasSmallIcon = false; | - | ||||||
| 73 | bool hasMediumIcon = false; | - | ||||||
| 74 | qreal dpr = qGuiApp->devicePixelRatio(); | - | ||||||
| 75 | QList<QSize> toRemove; | - | ||||||
| 76 | Q_FOREACH (const QSize &size, sizes) { | - | ||||||
| 77 | int maxSize = qMax(size.width(), size.height()); | - | ||||||
| 78 | if (maxSize <= IconNormalSmallSize * dpr) 
 | 0 | ||||||
| 79 | hasSmallIcon = true; never executed:  hasSmallIcon = true; | 0 | ||||||
| 80 | else if (maxSize <= IconNormalMediumSize * dpr) 
 | 0 | ||||||
| 81 | hasMediumIcon = true; never executed:  hasMediumIcon = true; | 0 | ||||||
| 82 | else if (maxSize > IconSizeLimit * dpr) 
 | 0 | ||||||
| 83 | toRemove << size; never executed:  toRemove << size; | 0 | ||||||
| 84 | } never executed:  end of block | 0 | ||||||
| 85 | Q_FOREACH (const QSize &size, toRemove) | - | ||||||
| 86 | sizes.removeOne(size); never executed:  sizes.removeOne(size); | 0 | ||||||
| 87 | if (!hasSmallIcon) 
 | 0 | ||||||
| 88 | sizes.append(QSize(IconNormalSmallSize * dpr, IconNormalSmallSize * dpr)); never executed:  sizes.append(QSize(IconNormalSmallSize * dpr, IconNormalSmallSize * dpr)); | 0 | ||||||
| 89 | if (!hasMediumIcon) 
 | 0 | ||||||
| 90 | sizes.append(QSize(IconNormalMediumSize * dpr, IconNormalMediumSize * dpr)); never executed:  sizes.append(QSize(IconNormalMediumSize * dpr, IconNormalMediumSize * dpr)); | 0 | ||||||
| 91 | - | |||||||
| 92 | ret.reserve(sizes.size()); | - | ||||||
| 93 | foreach (QSize size, sizes) { | - | ||||||
| 94 | // Protocol specifies ARGB32 format in network byte order | - | ||||||
| 95 | QImage im = icon.pixmap(size).toImage().convertToFormat(QImage::Format_ARGB32); | - | ||||||
| 96 | // letterbox if necessary to make it square | - | ||||||
| 97 | if (im.height() != im.width()) { 
 | 0 | ||||||
| 98 | int maxSize = qMax(im.width(), im.height()); | - | ||||||
| 99 | QImage padded(maxSize, maxSize, QImage::Format_ARGB32); | - | ||||||
| 100 | padded.fill(Qt::transparent); | - | ||||||
| 101 | QPainter painter(&padded); | - | ||||||
| 102 | painter.drawImage((maxSize - im.width()) / 2, (maxSize - im.height()) / 2, im); | - | ||||||
| 103 | im = padded; | - | ||||||
| 104 | } never executed:  end of block | 0 | ||||||
| 105 | // copy and endian-convert | - | ||||||
| 106 | QXdgDBusImageStruct kim(im.width(), im.height()); | - | ||||||
| 107 | const uchar *end = im.constBits() + im.byteCount(); | - | ||||||
| 108 | uchar *dest = reinterpret_cast<uchar *>(kim.data.data()); | - | ||||||
| 109 | for (const uchar *src = im.constBits(); src < end; src += 4, dest += 4) 
 | 0 | ||||||
| 110 | qToUnaligned(qToBigEndian<quint32>(qFromUnaligned<quint32>(src)), dest); never executed:  qToUnaligned(qToBigEndian<quint32>(qFromUnaligned<quint32>(src)), dest); | 0 | ||||||
| 111 | - | |||||||
| 112 | ret << kim; | - | ||||||
| 113 | } never executed:  end of block | 0 | ||||||
| 114 | return ret; never executed:  return ret; | 0 | ||||||
| 115 | } | - | ||||||
| 116 | - | |||||||
| 117 | // Marshall the ImageStruct data into a D-Bus argument | - | ||||||
| 118 | const QDBusArgument &operator<<(QDBusArgument &argument, const QXdgDBusImageStruct &icon) | - | ||||||
| 119 | { | - | ||||||
| 120 | argument.beginStructure(); | - | ||||||
| 121 | argument << icon.width; | - | ||||||
| 122 | argument << icon.height; | - | ||||||
| 123 | argument << icon.data; | - | ||||||
| 124 | argument.endStructure(); | - | ||||||
| 125 | return argument; never executed:  return argument; | 0 | ||||||
| 126 | } | - | ||||||
| 127 | - | |||||||
| 128 | // Retrieve the ImageStruct data from the D-Bus argument | - | ||||||
| 129 | const QDBusArgument &operator>>(const QDBusArgument &argument, QXdgDBusImageStruct &icon) | - | ||||||
| 130 | { | - | ||||||
| 131 | qint32 width; | - | ||||||
| 132 | qint32 height; | - | ||||||
| 133 | QByteArray data; | - | ||||||
| 134 | - | |||||||
| 135 | argument.beginStructure(); | - | ||||||
| 136 | argument >> width; | - | ||||||
| 137 | argument >> height; | - | ||||||
| 138 | argument >> data; | - | ||||||
| 139 | argument.endStructure(); | - | ||||||
| 140 | - | |||||||
| 141 | icon.width = width; | - | ||||||
| 142 | icon.height = height; | - | ||||||
| 143 | icon.data = data; | - | ||||||
| 144 | - | |||||||
| 145 | return argument; never executed:  return argument; | 0 | ||||||
| 146 | } | - | ||||||
| 147 | - | |||||||
| 148 | // Marshall the ImageVector data into a D-Bus argument | - | ||||||
| 149 | const QDBusArgument &operator<<(QDBusArgument &argument, const QXdgDBusImageVector &iconVector) | - | ||||||
| 150 | { | - | ||||||
| 151 | argument.beginArray(qMetaTypeId<QXdgDBusImageStruct>()); | - | ||||||
| 152 | for (int i = 0; i < iconVector.size(); ++i) { 
 | 0 | ||||||
| 153 | argument << iconVector[i]; | - | ||||||
| 154 | } never executed:  end of block | 0 | ||||||
| 155 | argument.endArray(); | - | ||||||
| 156 | return argument; never executed:  return argument; | 0 | ||||||
| 157 | } | - | ||||||
| 158 | - | |||||||
| 159 | // Retrieve the ImageVector data from the D-Bus argument | - | ||||||
| 160 | const QDBusArgument &operator>>(const QDBusArgument &argument, QXdgDBusImageVector &iconVector) | - | ||||||
| 161 | { | - | ||||||
| 162 | argument.beginArray(); | - | ||||||
| 163 | iconVector.clear(); | - | ||||||
| 164 | - | |||||||
| 165 | while (!argument.atEnd()) { 
 | 0 | ||||||
| 166 | QXdgDBusImageStruct element; | - | ||||||
| 167 | argument >> element; | - | ||||||
| 168 | iconVector.append(element); | - | ||||||
| 169 | } never executed:  end of block | 0 | ||||||
| 170 | - | |||||||
| 171 | argument.endArray(); | - | ||||||
| 172 | - | |||||||
| 173 | return argument; never executed:  return argument; | 0 | ||||||
| 174 | } | - | ||||||
| 175 | - | |||||||
| 176 | // Marshall the ToolTipStruct data into a D-Bus argument | - | ||||||
| 177 | const QDBusArgument &operator<<(QDBusArgument &argument, const QXdgDBusToolTipStruct &toolTip) | - | ||||||
| 178 | { | - | ||||||
| 179 | argument.beginStructure(); | - | ||||||
| 180 | argument << toolTip.icon; | - | ||||||
| 181 | argument << toolTip.image; | - | ||||||
| 182 | argument << toolTip.title; | - | ||||||
| 183 | argument << toolTip.subTitle; | - | ||||||
| 184 | argument.endStructure(); | - | ||||||
| 185 | return argument; never executed:  return argument; | 0 | ||||||
| 186 | } | - | ||||||
| 187 | - | |||||||
| 188 | // Retrieve the ToolTipStruct data from the D-Bus argument | - | ||||||
| 189 | const QDBusArgument &operator>>(const QDBusArgument &argument, QXdgDBusToolTipStruct &toolTip) | - | ||||||
| 190 | { | - | ||||||
| 191 | QString icon; | - | ||||||
| 192 | QXdgDBusImageVector image; | - | ||||||
| 193 | QString title; | - | ||||||
| 194 | QString subTitle; | - | ||||||
| 195 | - | |||||||
| 196 | argument.beginStructure(); | - | ||||||
| 197 | argument >> icon; | - | ||||||
| 198 | argument >> image; | - | ||||||
| 199 | argument >> title; | - | ||||||
| 200 | argument >> subTitle; | - | ||||||
| 201 | argument.endStructure(); | - | ||||||
| 202 | - | |||||||
| 203 | toolTip.icon = icon; | - | ||||||
| 204 | toolTip.image = image; | - | ||||||
| 205 | toolTip.title = title; | - | ||||||
| 206 | toolTip.subTitle = subTitle; | - | ||||||
| 207 | - | |||||||
| 208 | return argument; never executed:  return argument; | 0 | ||||||
| 209 | } | - | ||||||
| 210 | - | |||||||
| 211 | QT_END_NAMESPACE | - | ||||||
| 212 | #endif // QT_NO_SYSTEMTRAYICON | - | ||||||
| Source code | Switch to Preprocessed file |