From 54712d7dae5b20fbd9439ecf4c8f5ee320755482 Mon Sep 17 00:00:00 2001 From: Tsu Jan Date: Mon, 28 Feb 2022 17:19:23 +0330 Subject: [PATCH] Removed internal icon engine It could interfere with the active icon engine. Fixes https://github.com/lxqt/libfm-qt/issues/788 --- src/core/iconinfo.cpp | 8 +-- src/core/iconinfo.h | 1 - src/core/iconinfo_p.h | 120 ------------------------------------------ 3 files changed, 1 insertion(+), 128 deletions(-) delete mode 100644 src/core/iconinfo_p.h diff --git a/src/core/iconinfo.cpp b/src/core/iconinfo.cpp index 1b342920..7fd1f423 100644 --- a/src/core/iconinfo.cpp +++ b/src/core/iconinfo.cpp @@ -1,5 +1,4 @@ #include "iconinfo.h" -#include "iconinfo_p.h" #include namespace Fm { @@ -68,12 +67,7 @@ void IconInfo::updateQIcons() { QIcon IconInfo::qicon() const { if(Q_UNLIKELY(qicon_.isNull() && gicon_)) { - if(!G_IS_FILE_ICON(gicon_.get())) { - qicon_ = QIcon(new IconEngine{shared_from_this()}); - } - else { - qicon_ = getFirst(internalQicons_); - } + qicon_ = internalQicon(); } return qicon_; } diff --git a/src/core/iconinfo.h b/src/core/iconinfo.h index 4e8a041b..e223aa47 100644 --- a/src/core/iconinfo.h +++ b/src/core/iconinfo.h @@ -39,7 +39,6 @@ namespace Fm { class LIBFM_QT_API IconInfo: public std::enable_shared_from_this { public: - friend class IconEngine; explicit IconInfo() {} diff --git a/src/core/iconinfo_p.h b/src/core/iconinfo_p.h deleted file mode 100644 index c5570c8f..00000000 --- a/src/core/iconinfo_p.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2016 Hong Jen Yee (PCMan) - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef FM_ICONENGINE_H -#define FM_ICONENGINE_H - -#include -#include -#include "../libfmqtglobals.h" -#include "iconinfo.h" -#include - -namespace Fm { - -class IconEngine: public QIconEngine { -public: - - IconEngine(std::shared_ptr info); - - ~IconEngine() override; - - QSize actualSize(const QSize& size, QIcon::Mode mode, QIcon::State state) override; - - // not supported - void addFile(const QString& /*fileName*/, const QSize& /*size*/, QIcon::Mode /*mode*/, QIcon::State /*state*/) override {} - - // not supported - void addPixmap(const QPixmap& /*pixmap*/, QIcon::Mode /*mode*/, QIcon::State /*state*/) override {} - - QIconEngine* clone() const override; - - QString key() const override; - - void paint(QPainter* painter, const QRect& rect, QIcon::Mode mode, QIcon::State state) override; - - QPixmap pixmap(const QSize& size, QIcon::Mode mode, QIcon::State state) override; - - void virtual_hook(int id, void* data) override; - -private: - std::weak_ptr info_; -}; - -IconEngine::IconEngine(std::shared_ptr info): info_{info} { -} - -IconEngine::~IconEngine() { -} - -QSize IconEngine::actualSize(const QSize& size, QIcon::Mode mode, QIcon::State state) { - auto info = info_.lock(); - return info ? info->internalQicon().actualSize(size, mode, state) : QSize{}; -} - -QIconEngine* IconEngine::clone() const { - IconEngine* engine = new IconEngine(info_.lock()); - return engine; -} - -QString IconEngine::key() const { - return QStringLiteral("Fm::IconEngine"); -} - -void IconEngine::paint(QPainter* painter, const QRect& rect, QIcon::Mode mode, QIcon::State state) { - auto info = info_.lock(); - if(info) { - info->internalQicon().paint(painter, rect, Qt::AlignCenter, mode, state); - } -} - -QPixmap IconEngine::pixmap(const QSize& size, QIcon::Mode mode, QIcon::State state) { - auto info = info_.lock(); - return info ? info->internalQicon().pixmap(size, mode, state) : QPixmap{}; -} - -void IconEngine::virtual_hook(int id, void* data) { - auto info = info_.lock(); - switch(id) { - case QIconEngine::AvailableSizesHook: { - auto* args = reinterpret_cast(data); - args->sizes = info ? info->internalQicon().availableSizes(args->mode, args->state) : QList{}; - break; - } - case QIconEngine::IconNameHook: { - QString* result = reinterpret_cast(data); - *result = info ? info->internalQicon().name() : QString{}; - break; - } - case QIconEngine::IsNullHook: { - bool* result = reinterpret_cast(data); - *result = info ? info->internalQicon().isNull() : true; - break; - } - case QIconEngine::ScaledPixmapHook: { - auto* arg = reinterpret_cast(data); - arg->pixmap = info ? info->internalQicon().pixmap(arg->size, arg->mode, arg->state) : QPixmap{}; - break; - } - } -} - -} // namespace Fm - -#endif // FM_ICONENGINE_H