summaryrefslogtreecommitdiffstats
path: root/src/gui/platform/unix/dbustray/qdbustraytypes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/platform/unix/dbustray/qdbustraytypes.cpp')
-rw-r--r--src/gui/platform/unix/dbustray/qdbustraytypes.cpp77
1 files changed, 23 insertions, 54 deletions
diff --git a/src/gui/platform/unix/dbustray/qdbustraytypes.cpp b/src/gui/platform/unix/dbustray/qdbustraytypes.cpp
index 97cc8b7f36..accbd87e7e 100644
--- a/src/gui/platform/unix/dbustray/qdbustraytypes.cpp
+++ b/src/gui/platform/unix/dbustray/qdbustraytypes.cpp
@@ -1,42 +1,6 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Marco Martin <notmart@gmail.com>
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtGui module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2009 Marco Martin <notmart@gmail.com>
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QT_NO_SYSTEMTRAYICON
@@ -46,6 +10,7 @@
#include <QDBusMetaType>
#include <QImage>
#include <QIcon>
+#include <QIconEngine>
#include <QImage>
#include <QPixmap>
#include <QDebug>
@@ -54,9 +19,14 @@
#include <QGuiApplication>
#include <qpa/qplatformmenu.h>
#include <private/qdbusplatformmenu_p.h>
+#include <private/qicon_p.h>
QT_BEGIN_NAMESPACE
+QT_IMPL_METATYPE_EXTERN(QXdgDBusImageStruct)
+QT_IMPL_METATYPE_EXTERN(QXdgDBusImageVector)
+QT_IMPL_METATYPE_EXTERN(QXdgDBusToolTipStruct)
+
static const int IconSizeLimit = 64;
static const int IconNormalSmallSize = 22;
static const int IconNormalMediumSize = 64;
@@ -64,35 +34,37 @@ static const int IconNormalMediumSize = 64;
QXdgDBusImageVector iconToQXdgDBusImageVector(const QIcon &icon)
{
QXdgDBusImageVector ret;
- QList<QSize> sizes = icon.availableSizes();
+ if (icon.isNull())
+ return ret;
+ QIconEngine *engine = const_cast<QIcon &>(icon).data_ptr()->engine;
+ QList<QSize> sizes = engine->availableSizes(QIcon::Normal, QIcon::Off);
// Omit any size larger than 64 px, to save D-Bus bandwidth;
// ensure that 22px or smaller exists, because it's a common size;
// and ensure that something between 22px and 64px exists, for better scaling to other sizes.
bool hasSmallIcon = false;
bool hasMediumIcon = false;
- qreal dpr = qGuiApp->devicePixelRatio();
QList<QSize> toRemove;
- for (const QSize &size : qAsConst(sizes)) {
+ for (const QSize &size : std::as_const(sizes)) {
int maxSize = qMax(size.width(), size.height());
- if (maxSize <= IconNormalSmallSize * dpr)
+ if (maxSize <= IconNormalSmallSize)
hasSmallIcon = true;
- else if (maxSize <= IconNormalMediumSize * dpr)
+ else if (maxSize <= IconNormalMediumSize)
hasMediumIcon = true;
- else if (maxSize > IconSizeLimit * dpr)
+ else if (maxSize > IconSizeLimit)
toRemove << size;
}
- for (const QSize &size : qAsConst(toRemove))
+ for (const QSize &size : std::as_const(toRemove))
sizes.removeOne(size);
if (!hasSmallIcon)
- sizes.append(QSize(IconNormalSmallSize * dpr, IconNormalSmallSize * dpr));
+ sizes.append(QSize(IconNormalSmallSize, IconNormalSmallSize));
if (!hasMediumIcon)
- sizes.append(QSize(IconNormalMediumSize * dpr, IconNormalMediumSize * dpr));
+ sizes.append(QSize(IconNormalMediumSize, IconNormalMediumSize));
ret.reserve(sizes.size());
- for (const QSize &size : qAsConst(sizes)) {
+ for (const QSize &size : std::as_const(sizes)) {
// Protocol specifies ARGB32 format in network byte order
- QImage im = icon.pixmap(size).toImage().convertToFormat(QImage::Format_ARGB32);
+ QImage im = engine->pixmap(size, QIcon::Normal, QIcon::Off).toImage().convertToFormat(QImage::Format_ARGB32);
// letterbox if necessary to make it square
if (im.height() != im.width()) {
int maxSize = qMax(im.width(), im.height());
@@ -104,10 +76,7 @@ QXdgDBusImageVector iconToQXdgDBusImageVector(const QIcon &icon)
}
// copy and endian-convert
QXdgDBusImageStruct kim(im.width(), im.height());
- const uchar *end = im.constBits() + im.sizeInBytes();
- uchar *dest = reinterpret_cast<uchar *>(kim.data.data());
- for (const uchar *src = im.constBits(); src < end; src += 4, dest += 4)
- qToUnaligned(qToBigEndian<quint32>(qFromUnaligned<quint32>(src)), dest);
+ qToBigEndian<quint32>(im.constBits(), im.width() * im.height(), kim.data.data());
ret << kim;
}