Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: from linuxdeepin/dtkgui #13

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/kernel/dguiapplicationhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <QLockFile>
#include <QDirIterator>
#include <QDesktopServices>
#include <QTimer>

#ifdef Q_OS_UNIX
#include <QDBusError>
Expand Down Expand Up @@ -495,10 +494,7 @@ DGuiApplicationHelper::DGuiApplicationHelper()
: QObject(nullptr)
, DObject(*new DGuiApplicationHelperPrivate(this))
{
// load qt/qtbase translation for qt app which load dtk ?
QTimer::singleShot(0, [](){
DGuiApplicationHelper::loadTranslator();
});

}

void DGuiApplicationHelper::initialize()
Expand Down
5 changes: 3 additions & 2 deletions src/util/private/diconproxyengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <QDir>

#include <private/qiconloader_p.h>
#if (XDG_ICON_VERSION_MAR >= 3)
#if XDG_ICON_VERSION_MAR >= 3
#define private public
#include <private/xdgiconloader/xdgiconloader_p.h>
#undef private
Expand Down Expand Up @@ -156,8 +156,9 @@ QIconEngine *DIconProxyEngine::clone() const

bool DIconProxyEngine::read(QDataStream &in)
{
// ensureEngine, will changed themeName if not the same
in >> m_iconName >> m_iconThemeName;

ensureEngine();
return m_iconEngine ? m_iconEngine->read(in) : false;
}

Expand Down
10 changes: 1 addition & 9 deletions src/util/private/xdgiconproxyengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,8 @@ void XdgIconProxyEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode
QPixmap XdgIconProxyEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
{
engine->ensureLoaded();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)

QIconLoaderEngineEntry *entry = engine->entryForSize(size);
#else
QIconLoaderEngineEntry *entry = engine->entryForSize(engine->m_info ,size);
#endif

if (!entry) {
DEEPIN_XDG_THEME::colorScheme.setLocalData(DEEPIN_XDG_THEME::PALETTE_MAP());
Expand Down Expand Up @@ -302,12 +299,7 @@ void XdgIconProxyEngine::virtual_hook(int id, void *data)
QIconEngine::ScaledPixmapArgument &arg = *reinterpret_cast<QIconEngine::ScaledPixmapArgument *>(data);
// QIcon::pixmap() multiplies size by the device pixel ratio.
const int integerScale = qCeil(arg.scale);

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QIconLoaderEngineEntry *entry = engine->entryForSize(arg.size / integerScale, integerScale);
#else
QIconLoaderEngineEntry *entry = engine->entryForSize(engine->m_info, arg.size / integerScale, integerScale);
#endif
// 先禁用缩放,因为此size是已经缩放过的
bool useHighDpiPixmap = qGuiApp->testAttribute(Qt::AA_UseHighDpiPixmaps);
qGuiApp->setAttribute(Qt::AA_UseHighDpiPixmaps, false);
Expand Down
4 changes: 1 addition & 3 deletions src/util/private/xdgiconproxyengine_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#define XDGICONPROXYENGINE_H

#include <dtkgui_global.h>
#include <QHash>

#if XDG_ICON_VERSION_MAR >= 3
#include <QIconEngine>
Expand All @@ -26,8 +25,7 @@ struct ScalableEntry;
class QIconLoaderEngineEntry;
class XdgIconLoaderEngine;
DGUI_BEGIN_NAMESPACE

#if (XDG_ICON_VERSION_MAR >= 3)
#if XDG_ICON_VERSION_MAR >= 3
class Q_DECL_HIDDEN XdgIconProxyEngine : public QIconEngine
{
public:
Expand Down
9 changes: 5 additions & 4 deletions src/util/util.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
if(NOT DTK_DISABLE_LIBXDG)
message("Enable libxdg!")
find_package(qt${QT_VERSION_MAJOR}xdgiconloader)

add_definitions(-DXDG_ICON_VERSION_MAR=${qt${QT_VERSION_MAJOR}xdgiconloader_VERSION_MAJOR})

# find_package(qt${QT_VERSION_MAJOR}xdgiconloader)
if (Qt5_FOUND)
find_package(qt5xdgiconloader)
add_definitions(-DXDG_ICON_VERSION_MAR=${qt5xdgiconloader_VERSION_MAJOR})
endif()
set(UTIL_PRIVATE
${CMAKE_CURRENT_LIST_DIR}/private/xdgiconproxyengine_p.h
${CMAKE_CURRENT_LIST_DIR}/private/xdgiconproxyengine.cpp
Expand Down
Binary file modified tests/dcis/selected_indicator.dci
Binary file not shown.
20 changes: 12 additions & 8 deletions tests/src/ut_diconproxyengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <QPainter>
#include <QIODevice>
#include <private/qicon_p.h>

#include <DGuiApplicationHelper>
#include <DPlatformTheme>
Expand Down Expand Up @@ -115,18 +116,21 @@ TEST_F(ut_DIconProxyEngine, read_write)
ASSERT_EQ(iconName, mIconEngine->iconName());
}

iconName = "test_icon_name";
themeName = "test_theme_name";
{
auto engine = new DIconProxyEngine("selected_indicator" ,DIconTheme::DontFallbackToQIconFromTheme);
QIcon icon_write(engine);
QDataStream out(&data, QIODevice::WriteOnly);
out << iconName << themeName;
}
{
out << icon_write;

QIcon icon_read;
QDataStream in(&data, QIODevice::ReadOnly);
mIconEngine->read(in);
in >> icon_read;

ASSERT_EQ(themeName, mIconEngine->themeName());
ASSERT_EQ(iconName, mIconEngine->iconName());
ASSERT_TRUE(icon_read.data_ptr()->engine);
EXPECT_EQ(icon_read.data_ptr()->engine->key(),
engine->key());
EXPECT_EQ(icon_read.data_ptr()->engine->iconName(),
engine->iconName());
}
}

Expand Down
5 changes: 1 addition & 4 deletions tests/src/ut_xdgiconproxyengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,8 @@ TEST_F(ut_XdgIconProxyEngine, pixmapByEntry)
QPalette pa = qApp->palette();
// ensureLoaded
EXPECT_EQ(s64, mIconEngine->actualSize(s64, QIcon::Normal, QIcon::On));
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)

QIconLoaderEngineEntry *entry = mIconEngine->engine->entryForSize(s64);
#else
QIconLoaderEngineEntry *entry = mIconEngine->engine->entryForSize(mIconEngine->engine->m_info, s64);
#endif
ASSERT_TRUE(entry);

QPixmap normalPix = mIconEngine->pixmapByEntry(entry, s64, QIcon::Normal, QIcon::On);
Expand Down