mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
fix: 修复高缩放率下图标显示异常的问题
设置qApp的Qt::AA_UseHighDpiPixmaps属性为true,设置高分屏支持 Log: 修复高缩放率下图标显示异常的问题 Influence: 设置高缩放率,观察任务栏图标显示 Bug: https://gerrit.uniontech.com/c/dde-network-core/+/180802 Change-Id: I76b6621c405c4a01d39b68817fe920f8e6671609
This commit is contained in:
parent
8c03c2c768
commit
35b4788180
@ -189,7 +189,7 @@ int main(int argc, char *argv[])
|
||||
app.setApplicationVersion("2.0");
|
||||
app.loadTranslator();
|
||||
app.setAttribute(Qt::AA_EnableHighDpiScaling, true);
|
||||
app.setAttribute(Qt::AA_UseHighDpiPixmaps, false);
|
||||
app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
|
||||
|
||||
// 自动化标记由此开始
|
||||
QAccessible::installFactory(accessibleFactory);
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include <QIcon>
|
||||
#include <QPainter>
|
||||
#include <QCursor>
|
||||
#include <QGSettings>
|
||||
#include <QDebug>
|
||||
#include <QPainterPath>
|
||||
#include <QRegion>
|
||||
@ -44,13 +43,14 @@
|
||||
const QPixmap ImageUtil::loadSvg(const QString &iconName, const QString &localPath, const int size, const qreal ratio)
|
||||
{
|
||||
QIcon icon = QIcon::fromTheme(iconName);
|
||||
int pixmapSize = QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? size : int(size * ratio);
|
||||
if (!icon.isNull()) {
|
||||
QPixmap pixmap = icon.pixmap(int(size * ratio), int(size * ratio));
|
||||
QPixmap pixmap = icon.pixmap(pixmapSize);
|
||||
pixmap.setDevicePixelRatio(ratio);
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
QPixmap pixmap(int(size * ratio), int(size * ratio));
|
||||
QPixmap pixmap(pixmapSize, pixmapSize);
|
||||
QString localIcon = QString("%1%2%3").arg(localPath).arg(iconName).arg(iconName.contains(".svg") ? "" : ".svg");
|
||||
QSvgRenderer renderer(localIcon);
|
||||
pixmap.fill(Qt::transparent);
|
||||
@ -68,7 +68,7 @@ const QPixmap ImageUtil::loadSvg(const QString &iconName, const QSize size, cons
|
||||
{
|
||||
QIcon icon = QIcon::fromTheme(iconName);
|
||||
if (!icon.isNull()) {
|
||||
QPixmap pixmap = icon.pixmap(size*ratio);
|
||||
QPixmap pixmap = icon.pixmap(QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? size : QSize(size * ratio));
|
||||
pixmap.setDevicePixelRatio(ratio);
|
||||
return pixmap;
|
||||
}
|
||||
|
@ -751,7 +751,7 @@ bool QuickDockItem::eventFilter(QObject *watched, QEvent *event)
|
||||
|
||||
QPixmap QuickDockItem::iconPixmap() const
|
||||
{
|
||||
int pixmapSize = static_cast<int>(ICONHEIGHT * qApp->devicePixelRatio());
|
||||
int pixmapSize = static_cast<int>(ICONHEIGHT * (QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? 1 : qApp->devicePixelRatio()));
|
||||
QIcon icon = m_pluginItem->icon(DockPart::QuickShow);
|
||||
if (!icon.isNull())
|
||||
return icon.pixmap(pixmapSize, pixmapSize);
|
||||
|
@ -281,7 +281,7 @@ void StretchPluginsItem::paintEvent(QPaintEvent *event)
|
||||
}
|
||||
|
||||
// 绘制图标
|
||||
int iconSize = static_cast<int>(ICONSIZE * (qApp->devicePixelRatio()));
|
||||
int iconSize = static_cast<int>(ICONSIZE * (QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? 1 : qApp->devicePixelRatio()));
|
||||
painter.drawPixmap(rctPixmap, icon.pixmap(iconSize, iconSize));
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QPainter>
|
||||
#include <QPainterPath>
|
||||
#include <DStyle>
|
||||
|
||||
DGUI_USE_NAMESPACE
|
||||
DWIDGET_USE_NAMESPACE
|
||||
@ -166,12 +167,8 @@ void BluetoothMainWidget::initConnection()
|
||||
|
||||
void BluetoothMainWidget::updateExpandIcon()
|
||||
{
|
||||
QString expandIconFile = ":/arrow-right";
|
||||
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::ColorType::LightType)
|
||||
expandIconFile += "-dark";
|
||||
expandIconFile += ".svg";
|
||||
|
||||
m_expandLabel->setPixmap(expandIconFile);
|
||||
QPixmap enterPixmap = DStyle::standardIcon(style(), DStyle::SP_ArrowEnter).pixmap(QSize(16, 16));
|
||||
m_expandLabel->setPixmap(enterPixmap);
|
||||
}
|
||||
|
||||
bool BluetoothMainWidget::isOpen() const
|
||||
|
@ -4,7 +4,8 @@ set(PLUGIN_NAME "multitasking")
|
||||
project(${PLUGIN_NAME})
|
||||
|
||||
# Sources files
|
||||
file(GLOB SRCS "*.h" "*.cpp" "../../widgets/tipswidget.h" "../../widgets/tipswidget.cpp")
|
||||
file(GLOB SRCS "*.h" "*.cpp" "../../widgets/tipswidget.h" "../../widgets/tipswidget.cpp"
|
||||
"../../frame/util/imageutil.h" "../../frame/util/imageutil.cpp")
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(Qt5Widgets REQUIRED)
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <QPainter>
|
||||
#include <QIcon>
|
||||
#include <QMouseEvent>
|
||||
#include <imageutil.h>
|
||||
|
||||
MultitaskingWidget::MultitaskingWidget(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
@ -46,9 +47,9 @@ void MultitaskingWidget::paintEvent(QPaintEvent *e)
|
||||
QPixmap icon;
|
||||
|
||||
if (Dock::Fashion == qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>()) {
|
||||
icon = QIcon::fromTheme("deepin-multitasking-view", m_icon).pixmap(size() * 0.8 * ratio);
|
||||
icon = ImageUtil::loadSvg("deepin-multitasking-view", QString(":/icons/"), int(size().width() * 0.8), ratio);
|
||||
} else {
|
||||
icon = QIcon::fromTheme("deepin-multitasking-view", m_icon).pixmap(size() * 0.7 * ratio);
|
||||
icon = ImageUtil::loadSvg("deepin-multitasking-view", QString(":/icons/"), int(size().width() * 0.7), ratio);
|
||||
}
|
||||
|
||||
icon.setDevicePixelRatio(ratio);
|
||||
|
@ -113,8 +113,8 @@ const QPixmap OnboardItem::loadSvg(const QString &fileName, const QSize &size) c
|
||||
{
|
||||
const auto ratio = devicePixelRatioF();
|
||||
|
||||
QPixmap pixmap;
|
||||
pixmap = QIcon::fromTheme(fileName, m_icon).pixmap(size * ratio);
|
||||
QSize pixmapSize = QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? size : (size * ratio);
|
||||
QPixmap pixmap = QIcon::fromTheme(fileName, m_icon).pixmap(pixmapSize);
|
||||
pixmap.setDevicePixelRatio(ratio);
|
||||
|
||||
return pixmap;
|
||||
|
@ -67,8 +67,8 @@ const QPixmap OverlayWarningWidget::loadSvg(const QString &fileName, const QSize
|
||||
{
|
||||
const auto ratio = devicePixelRatioF();
|
||||
|
||||
QPixmap pixmap;
|
||||
pixmap = QIcon::fromTheme(fileName).pixmap(size * ratio);
|
||||
QSize pixmapSize = QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? size : (size * ratio);
|
||||
QPixmap pixmap = QIcon::fromTheme(fileName).pixmap(pixmapSize);
|
||||
pixmap.setDevicePixelRatio(ratio);
|
||||
|
||||
return pixmap;
|
||||
|
@ -115,8 +115,8 @@ QPixmap PowerStatusWidget::getBatteryIcon(int themeType)
|
||||
iconStr.append(PLUGIN_MIN_ICON_NAME);
|
||||
|
||||
const auto ratio = devicePixelRatioF();
|
||||
QPixmap pix = QIcon::fromTheme(iconStr,
|
||||
QIcon::fromTheme(":/batteryicons/resources/batteryicons/" + iconStr + ".svg")).pixmap(QSize(20, 20) * ratio);
|
||||
QSize pixmapSize = QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? QSize(20, 20) : (QSize(20, 20) * ratio);
|
||||
QPixmap pix = QIcon::fromTheme(iconStr, QIcon::fromTheme(":/batteryicons/resources/batteryicons/" + iconStr + ".svg")).pixmap(pixmapSize);
|
||||
pix.setDevicePixelRatio(ratio);
|
||||
|
||||
return pix;
|
||||
|
@ -4,7 +4,8 @@ set(PLUGIN_NAME "show-desktop")
|
||||
project(${PLUGIN_NAME})
|
||||
|
||||
# Sources files
|
||||
file(GLOB SRCS "*.h" "*.cpp" "../../widgets/tipswidget.h" "../../widgets/tipswidget.cpp")
|
||||
file(GLOB SRCS "*.h" "*.cpp" "../../widgets/tipswidget.h" "../../widgets/tipswidget.cpp"
|
||||
"../../frame/util/imageutil.h" "../../frame/util/imageutil.cpp")
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(Qt5Widgets REQUIRED)
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
#include "showdesktopwidget.h"
|
||||
#include "showdesktopplugin.h"
|
||||
#include "imageutil.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QIcon>
|
||||
@ -44,9 +45,9 @@ void ShowDesktopWidget::paintEvent(QPaintEvent *e)
|
||||
QPixmap icon;
|
||||
|
||||
if (Dock::Fashion == qApp->property(PROP_DISPLAY_MODE).value<Dock::DisplayMode>()) {
|
||||
icon = QIcon::fromTheme("deepin-toggle-desktop").pixmap(size() * 0.8 * ratio);
|
||||
icon = ImageUtil::loadSvg("deepin-toggle-desktop", QString(), int(size().width() * 0.8), ratio);
|
||||
} else {
|
||||
icon = QIcon::fromTheme("deepin-toggle-desktop").pixmap(size() * 0.7 * ratio);
|
||||
icon = ImageUtil::loadSvg("deepin-toggle-desktop", QString(), int(size().width() * 0.7), ratio);
|
||||
}
|
||||
|
||||
icon.setDevicePixelRatio(ratio);
|
||||
|
@ -4,7 +4,8 @@ set(PLUGIN_NAME "shutdown")
|
||||
project(${PLUGIN_NAME})
|
||||
|
||||
# Sources files
|
||||
file(GLOB_RECURSE SRCS "*.h" "*.cpp" "../../widgets/tipswidget.h" "../../widgets/tipswidget.cpp")
|
||||
file(GLOB_RECURSE SRCS "*.h" "*.cpp" "../../widgets/tipswidget.h" "../../widgets/tipswidget.cpp"
|
||||
"../../frame/util/imageutil.h" "../../frame/util/imageutil.cpp")
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
find_package(Qt5Widgets REQUIRED)
|
||||
|
@ -215,11 +215,11 @@ void TrashWidget::updateIcon()
|
||||
size = PLUGIN_BACKGROUND_MAX_SIZE;
|
||||
}
|
||||
|
||||
|
||||
QIcon icon = QIcon::fromTheme(iconString, m_defaulticon);
|
||||
|
||||
const auto ratio = devicePixelRatioF();
|
||||
m_icon = icon.pixmap(size * ratio, size * ratio);
|
||||
int pixmapSize = QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps) ? size : int(size * ratio);
|
||||
m_icon = icon.pixmap(pixmapSize, pixmapSize);
|
||||
m_icon.setDevicePixelRatio(ratio);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user