diff options
Diffstat (limited to 'src/gui/image/qiconloader_p.h')
-rw-r--r-- | src/gui/image/qiconloader_p.h | 94 |
1 files changed, 44 insertions, 50 deletions
diff --git a/src/gui/image/qiconloader_p.h b/src/gui/image/qiconloader_p.h index d02b2da2cc..3cfa9381d1 100644 --- a/src/gui/image/qiconloader_p.h +++ b/src/gui/image/qiconloader_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** 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) 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 QICONLOADER_P_H #define QICONLOADER_P_H @@ -58,11 +22,15 @@ #include <QtGui/QIconEngine> #include <QtGui/QPixmapCache> #include <private/qicon_p.h> +#include <private/qiconengine_p.h> #include <private/qfactoryloader_p.h> #include <QtCore/QHash> #include <QtCore/QList> #include <QtCore/QTypeInfo> +#include <vector> +#include <memory> + QT_BEGIN_NAMESPACE class QIconLoader; @@ -70,6 +38,7 @@ class QIconLoader; struct QIconDirInfo { enum Type { Fixed, Scalable, Threshold, Fallback }; + enum Context { UnknownContext, Applications, MimeTypes }; QIconDirInfo(const QString &_path = QString()) : path(_path), size(0), @@ -77,7 +46,8 @@ struct QIconDirInfo minSize(0), threshold(0), scale(1), - type(Threshold) {} + type(Threshold), + context(UnknownContext) {} QString path; short size; short maxSize; @@ -85,6 +55,7 @@ struct QIconDirInfo short threshold; short scale; Type type; + Context context; }; Q_DECLARE_TYPEINFO(QIconDirInfo, Q_RELOCATABLE_TYPE); @@ -111,7 +82,7 @@ struct PixmapEntry : public QIconLoaderEngineEntry QPixmap basePixmap; }; -typedef QList<QIconLoaderEngineEntry*> QThemeIconEntries; +using QThemeIconEntries = std::vector<std::unique_ptr<QIconLoaderEngineEntry>>; struct QThemeIconInfo { @@ -119,6 +90,27 @@ struct QThemeIconInfo QString iconName; }; +class QThemeIconEngine : public QProxyIconEngine +{ +public: + QThemeIconEngine(const QString& iconName = QString()); + QIconEngine *clone() const override; + bool read(QDataStream &in) override; + bool write(QDataStream &out) const override; + +protected: + QIconEngine *proxiedEngine() const override; + +private: + QThemeIconEngine(const QThemeIconEngine &other); + QString key() const override; + + QString m_iconName; + mutable uint m_themeKey = 0; + + mutable std::unique_ptr<QIconEngine> m_proxiedEngine; +}; + class QIconLoaderEngine : public QIconEngine { public: @@ -129,8 +121,6 @@ public: QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override; QSize actualSize(const QSize &size, QIcon::Mode mode, QIcon::State state) override; QIconEngine *clone() const override; - bool read(QDataStream &in) override; - bool write(QDataStream &out) const override; QString iconName() override; bool isNull() override; @@ -140,14 +130,13 @@ public: Q_GUI_EXPORT static QIconLoaderEngineEntry *entryForSize(const QThemeIconInfo &info, const QSize &size, int scale = 1); private: + Q_DISABLE_COPY(QIconLoaderEngine) + QString key() const override; bool hasIcon() const; - void ensureLoaded(); - QIconLoaderEngine(const QIconLoaderEngine &other); - QThemeIconInfo m_info; QString m_iconName; - uint m_key; + QThemeIconInfo m_info; friend class QIconLoader; }; @@ -159,7 +148,7 @@ class QIconTheme public: QIconTheme(const QString &name); QIconTheme() : m_valid(false) {} - QStringList parents() { return m_parents; } + QStringList parents() const; QList<QIconDirInfo> keyList() { return m_keyList; } QStringList contentDirs() { return m_contentDirs; } bool isValid() { return m_valid; } @@ -179,7 +168,7 @@ public: QThemeIconInfo loadIcon(const QString &iconName) const; uint themeKey() const { return m_themeKey; } - QString themeName() const { return m_userTheme.isEmpty() ? m_systemTheme : m_userTheme; } + QString themeName() const; void setThemeName(const QString &themeName); QString fallbackThemeName() const; void setFallbackThemeName(const QString &themeName); @@ -191,14 +180,18 @@ public: QIconDirInfo dirInfo(int dirindex); static QIconLoader *instance(); void updateSystemTheme(); - void invalidateKey() { m_themeKey++; } + void invalidateKey(); void ensureInitialized(); bool hasUserTheme() const { return !m_userTheme.isEmpty(); } + QIconEngine *iconEngine(const QString &iconName) const; + private: + enum DashRule { FallBack, NoFallBack }; QThemeIconInfo findIconHelper(const QString &themeName, const QString &iconName, - QStringList &visited) const; + QStringList &visited, + DashRule rule) const; QThemeIconInfo lookupFallbackIcon(const QString &iconName) const; uint m_themeKey; @@ -211,6 +204,7 @@ private: mutable QStringList m_iconDirs; mutable QHash <QString, QIconTheme> themeList; mutable QStringList m_fallbackDirs; + mutable QString m_iconName; }; QT_END_NAMESPACE |