mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
fix: 修复高屏幕缩放下图标显示模糊的问题
增加对屏幕缩放的处理,保证图标正常显示 Log: Influence: 将缩放设置为大于1,查看任务栏电源图标、网络等图标的展示情况 Task: https://pms.uniontech.com/task-view-149623.html Change-Id: Ie4be9d0644b5be1f961ee70ee8472cab9dec9377
This commit is contained in:
parent
0340166430
commit
fc181973ce
@ -38,9 +38,9 @@
|
|||||||
#define BGSIZE 36
|
#define BGSIZE 36
|
||||||
#define MARGINLEFTSPACE 10
|
#define MARGINLEFTSPACE 10
|
||||||
#define OPENICONSIZE 12
|
#define OPENICONSIZE 12
|
||||||
#define MARGINRIGHTSPACE 12
|
#define MARGINRIGHTSPACE 9
|
||||||
|
|
||||||
static QSize expandSize = QSize(6, 10);
|
static QSize expandSize = QSize(20, 20);
|
||||||
|
|
||||||
QuickSettingItem::QuickSettingItem(PluginsItemInterface *const pluginInter, const QString &itemKey, QWidget *parent)
|
QuickSettingItem::QuickSettingItem(PluginsItemInterface *const pluginInter, const QString &itemKey, QWidget *parent)
|
||||||
: DockItem(parent)
|
: DockItem(parent)
|
||||||
@ -108,7 +108,18 @@ void QuickSettingItem::paintEvent(QPaintEvent *e)
|
|||||||
// 绘制背景色
|
// 绘制背景色
|
||||||
painter.fillRect(rect(), backgroundColor());
|
painter.fillRect(rect(), backgroundColor());
|
||||||
// 让图标填上前景色
|
// 让图标填上前景色
|
||||||
QPixmap pm = m_pluginInter->icon(DockPart::QuickPanel).pixmap(ICONWIDTH, ICONHEIGHT);
|
int pixmapWidth = static_cast<int>(ICONWIDTH * qApp->devicePixelRatio());
|
||||||
|
int pixmapHeight = static_cast<int>(ICONHEIGHT * qApp->devicePixelRatio());
|
||||||
|
QIcon icon = m_pluginInter->icon(DockPart::QuickPanel);
|
||||||
|
QList<QSize> iconSizes = icon.availableSizes();
|
||||||
|
if (iconSizes.size() > 0) {
|
||||||
|
QSize size = iconSizes[0];
|
||||||
|
if (size.isValid() && !size.isEmpty() && !size.isNull()) {
|
||||||
|
pixmapWidth = size.width();
|
||||||
|
pixmapHeight = size.height();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
QPixmap pm = icon.pixmap(pixmapWidth, pixmapHeight);
|
||||||
QPainter pa(&pm);
|
QPainter pa(&pm);
|
||||||
pa.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
pa.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||||
pa.fillRect(pm.rect(), painter.pen().brush());
|
pa.fillRect(pm.rect(), painter.pen().brush());
|
||||||
@ -116,10 +127,17 @@ void QuickSettingItem::paintEvent(QPaintEvent *e)
|
|||||||
// 如果是主图标,则显示阴影背景
|
// 如果是主图标,则显示阴影背景
|
||||||
int marginYSpace = yMarginSpace();
|
int marginYSpace = yMarginSpace();
|
||||||
QRect iconBg(MARGINLEFTSPACE, marginYSpace, BGSIZE, BGSIZE);
|
QRect iconBg(MARGINLEFTSPACE, marginYSpace, BGSIZE, BGSIZE);
|
||||||
QPixmap bgPixmap = ImageUtil::getShadowPixmap(pm, shadowColor(), QSize(BGSIZE, BGSIZE));
|
painter.save();
|
||||||
painter.drawPixmap(iconBg, bgPixmap);
|
painter.setPen(Qt::NoPen);
|
||||||
|
painter.setBrush(shadowColor());
|
||||||
|
painter.drawEllipse(iconBg);
|
||||||
|
painter.restore();
|
||||||
|
QRect rctIcon(iconBg.x() + (iconBg.width() - pixmapWidth) / 2,
|
||||||
|
iconBg.y() + (iconBg.height() - pixmapHeight) / 2,
|
||||||
|
pixmapWidth, pixmapHeight);
|
||||||
|
painter.drawPixmap(rctIcon, pm);
|
||||||
// 绘制文字
|
// 绘制文字
|
||||||
painter.setPen(QColor(0, 0, 0));
|
painter.setPen(Qt::black);
|
||||||
|
|
||||||
QRect rctPluginName(iconBg.right() + 10, iconBg.top(), BGWIDTH - BGSIZE - OPENICONSIZE - 10 * 2, BGSIZE / 2);
|
QRect rctPluginName(iconBg.right() + 10, iconBg.top(), BGWIDTH - BGSIZE - OPENICONSIZE - 10 * 2, BGSIZE / 2);
|
||||||
QFont font = DFontSizeManager::instance()->t6();
|
QFont font = DFontSizeManager::instance()->t6();
|
||||||
@ -128,7 +146,6 @@ void QuickSettingItem::paintEvent(QPaintEvent *e)
|
|||||||
QTextOption textOption;
|
QTextOption textOption;
|
||||||
textOption.setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
textOption.setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||||
QString displayName = QFontMetrics(font).elidedText(m_pluginInter->pluginDisplayName(), Qt::TextElideMode::ElideRight, rctPluginName.width());
|
QString displayName = QFontMetrics(font).elidedText(m_pluginInter->pluginDisplayName(), Qt::TextElideMode::ElideRight, rctPluginName.width());
|
||||||
QFontMetrics fm(font);
|
|
||||||
painter.drawText(rctPluginName, displayName, textOption);
|
painter.drawText(rctPluginName, displayName, textOption);
|
||||||
// 绘制下方啊的状态文字
|
// 绘制下方啊的状态文字
|
||||||
QRect rctPluginStatus(rctPluginName.x(), rctPluginName.bottom() + 1,
|
QRect rctPluginStatus(rctPluginName.x(), rctPluginName.bottom() + 1,
|
||||||
@ -138,16 +155,12 @@ void QuickSettingItem::paintEvent(QPaintEvent *e)
|
|||||||
QString description = QFontMetrics(font).elidedText(m_pluginInter->description(), Qt::TextElideMode::ElideRight, rctPluginStatus.width());
|
QString description = QFontMetrics(font).elidedText(m_pluginInter->description(), Qt::TextElideMode::ElideRight, rctPluginStatus.width());
|
||||||
painter.drawText(rctPluginStatus, description, textOption);
|
painter.drawText(rctPluginStatus, description, textOption);
|
||||||
// 绘制右侧的展开按钮
|
// 绘制右侧的展开按钮
|
||||||
QPen pen;
|
QPixmap expandPixmap = ImageUtil::loadSvg(expandFileName(), expandSize);
|
||||||
pen.setColor(QColor(0, 0, 0));
|
|
||||||
pen.setWidth(2);
|
|
||||||
painter.setPen(pen);
|
|
||||||
int iconLeft = rect().width() - MARGINRIGHTSPACE - expandSize.width();
|
|
||||||
int iconRight = rect().width() - MARGINRIGHTSPACE;
|
int iconRight = rect().width() - MARGINRIGHTSPACE;
|
||||||
painter.drawLine(QPoint(iconLeft, (iconBg.y() + (iconBg.height() - expandSize.height()) / 2)),
|
QRect rectOfExpand(iconRight - expandSize.width(),
|
||||||
QPoint(iconRight, (iconBg.y() + iconBg.height() / 2)));
|
(rctIcon.y() + (rctIcon.height() - expandSize.height()) / 2),
|
||||||
painter.drawLine(QPoint(iconRight, (iconBg.y() + iconBg.height() / 2)),
|
expandSize.width(), expandSize.height());
|
||||||
QPoint(iconLeft, (iconBg.y() + (iconBg.height() + expandSize.height()) / 2)));
|
painter.drawPixmap(rectOfExpand, expandPixmap);
|
||||||
} else {
|
} else {
|
||||||
// 绘制图标
|
// 绘制图标
|
||||||
QRect rctIcon = iconRect();
|
QRect rctIcon = iconRect();
|
||||||
@ -224,3 +237,11 @@ int QuickSettingItem::yMarginSpace()
|
|||||||
{
|
{
|
||||||
return (rect().height() - BGSIZE) / 2;
|
return (rect().height() - BGSIZE) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString QuickSettingItem::expandFileName()
|
||||||
|
{
|
||||||
|
if (DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::LightType)
|
||||||
|
return QString(":/icons/resources/arrow-right-dark.svg");
|
||||||
|
|
||||||
|
return QString(":/icons/resources/arrow-right.svg");
|
||||||
|
}
|
||||||
|
@ -54,6 +54,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int yMarginSpace();
|
int yMarginSpace();
|
||||||
|
QString expandFileName();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PluginsItemInterface *m_pluginInter;
|
PluginsItemInterface *m_pluginInter;
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include <QSize>
|
#include <QSize>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
|
#include <QGuiApplication>
|
||||||
|
|
||||||
#define ITEMSIZE 22
|
#define ITEMSIZE 22
|
||||||
#define ITEMSPACE 6
|
#define ITEMSPACE 6
|
||||||
@ -488,7 +489,8 @@ void QuickDockItem::paintEvent(QPaintEvent *event)
|
|||||||
if (!m_pluginItem)
|
if (!m_pluginItem)
|
||||||
return QWidget::paintEvent(event);
|
return QWidget::paintEvent(event);
|
||||||
|
|
||||||
QPixmap pixmap = m_pluginItem->icon(DockPart::QuickPanel).pixmap(ICONHEIGHT, ICONHEIGHT);
|
int pixmapSize = static_cast<int>(ICONHEIGHT * qApp->devicePixelRatio());
|
||||||
|
QPixmap pixmap = m_pluginItem->icon(DockPart::QuickPanel).pixmap(pixmapSize, pixmapSize);
|
||||||
QRect pixmapRect = QRect((rect().width() - ICONHEIGHT) / 2, (rect().height() - ICONHEIGHT) / 2,
|
QRect pixmapRect = QRect((rect().width() - ICONHEIGHT) / 2, (rect().height() - ICONHEIGHT) / 2,
|
||||||
ICONHEIGHT, ICONHEIGHT);
|
ICONHEIGHT, ICONHEIGHT);
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QMetaObject>
|
#include <QMetaObject>
|
||||||
|
#include <QGuiApplication>
|
||||||
|
|
||||||
#define MAXICONSIZE 48
|
#define MAXICONSIZE 48
|
||||||
#define MINICONSIZE 24
|
#define MINICONSIZE 24
|
||||||
@ -192,18 +193,20 @@ void StretchPluginsItem::paintEvent(QPaintEvent *event)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 绘制图标
|
// 绘制图标
|
||||||
painter.drawPixmap(rctPixmap, icon.pixmap(ICONSIZE, ICONSIZE));
|
int iconSize = static_cast<int>(ICONSIZE * (qApp->devicePixelRatio()));
|
||||||
|
painter.drawPixmap(rctPixmap, icon.pixmap(iconSize, iconSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
QSize StretchPluginsItem::suitableSize() const
|
QSize StretchPluginsItem::suitableSize() const
|
||||||
{
|
{
|
||||||
|
int iconSize = static_cast<int>(ICONSIZE * (qApp->devicePixelRatio()));
|
||||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
||||||
int textWidth = QFontMetrics(textFont()).boundingRect(m_pluginInter->pluginDisplayName()).width();
|
int textWidth = QFontMetrics(textFont()).boundingRect(m_pluginInter->pluginDisplayName()).width();
|
||||||
return QSize(qMax(textWidth, ICONSIZE) + 10 * 2, -1);
|
return QSize(qMax(textWidth, iconSize) + 10 * 2, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int height = 6; // 图标上边距6
|
int height = 6; // 图标上边距6
|
||||||
height += ICONSIZE; // 图标尺寸20
|
height += iconSize; // 图标尺寸20
|
||||||
height += ICONTEXTSPACE; // 图标与文字间距6
|
height += ICONTEXTSPACE; // 图标与文字间距6
|
||||||
height += QFontMetrics(textFont()).height(); // 文本高度
|
height += QFontMetrics(textFont()).height(); // 文本高度
|
||||||
height += 4; // 下间距4
|
height += 4; // 下间距4
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "tray_model.h"
|
#include "tray_model.h"
|
||||||
#include "tray_delegate.h"
|
#include "tray_delegate.h"
|
||||||
#include "dockpopupwindow.h"
|
#include "dockpopupwindow.h"
|
||||||
|
#include "imageutil.h"
|
||||||
|
|
||||||
#include <DGuiApplicationHelper>
|
#include <DGuiApplicationHelper>
|
||||||
#include <DRegionMonitor>
|
#include <DRegionMonitor>
|
||||||
@ -88,13 +89,15 @@ QPixmap ExpandIconWidget::icon()
|
|||||||
return QPixmap(dropIconFile());
|
return QPixmap(dropIconFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExpandIconWidget::paintEvent(QPaintEvent *e)
|
void ExpandIconWidget::paintEvent(QPaintEvent *)
|
||||||
{
|
{
|
||||||
Q_UNUSED(e);
|
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
QPixmap pixmap(dropIconFile());
|
QPixmap pixmap = ImageUtil::loadSvg(dropIconFile(), QSize(ICON_SIZE, ICON_SIZE));
|
||||||
painter.drawPixmap(0, 0, pixmap);
|
QRect rectOfPixmap(rect().x() + (rect().width() - ICON_SIZE) / 2,
|
||||||
|
rect().y() + (rect().height() - ICON_SIZE) / 2,
|
||||||
|
ICON_SIZE, ICON_SIZE);
|
||||||
|
|
||||||
|
painter.drawPixmap(rectOfPixmap, pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString ExpandIconWidget::dropIconFile() const
|
const QString ExpandIconWidget::dropIconFile() const
|
||||||
|
@ -58,7 +58,7 @@ private Q_SLOTS:
|
|||||||
void onRowCountChanged();
|
void onRowCountChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *) override;
|
||||||
const QString dropIconFile() const;
|
const QString dropIconFile() const;
|
||||||
|
|
||||||
void resetPosition();
|
void resetPosition();
|
||||||
|
@ -296,8 +296,7 @@ QIcon ShutdownPlugin::icon(const DockPart &dockPart)
|
|||||||
{
|
{
|
||||||
Q_UNUSED(dockPart);
|
Q_UNUSED(dockPart);
|
||||||
|
|
||||||
static QIcon shutdownIcon;
|
QIcon shutdownIcon;
|
||||||
shutdownIcon.detach();
|
|
||||||
shutdownIcon.addPixmap(m_shutdownWidget->loadPixmap());
|
shutdownIcon.addPixmap(m_shutdownWidget->loadPixmap());
|
||||||
return shutdownIcon;
|
return shutdownIcon;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user