mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +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 MARGINLEFTSPACE 10
|
||||
#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)
|
||||
: DockItem(parent)
|
||||
@ -108,7 +108,18 @@ void QuickSettingItem::paintEvent(QPaintEvent *e)
|
||||
// 绘制背景色
|
||||
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);
|
||||
pa.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||
pa.fillRect(pm.rect(), painter.pen().brush());
|
||||
@ -116,10 +127,17 @@ void QuickSettingItem::paintEvent(QPaintEvent *e)
|
||||
// 如果是主图标,则显示阴影背景
|
||||
int marginYSpace = yMarginSpace();
|
||||
QRect iconBg(MARGINLEFTSPACE, marginYSpace, BGSIZE, BGSIZE);
|
||||
QPixmap bgPixmap = ImageUtil::getShadowPixmap(pm, shadowColor(), QSize(BGSIZE, BGSIZE));
|
||||
painter.drawPixmap(iconBg, bgPixmap);
|
||||
painter.save();
|
||||
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);
|
||||
QFont font = DFontSizeManager::instance()->t6();
|
||||
@ -128,7 +146,6 @@ void QuickSettingItem::paintEvent(QPaintEvent *e)
|
||||
QTextOption textOption;
|
||||
textOption.setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
QString displayName = QFontMetrics(font).elidedText(m_pluginInter->pluginDisplayName(), Qt::TextElideMode::ElideRight, rctPluginName.width());
|
||||
QFontMetrics fm(font);
|
||||
painter.drawText(rctPluginName, displayName, textOption);
|
||||
// 绘制下方啊的状态文字
|
||||
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());
|
||||
painter.drawText(rctPluginStatus, description, textOption);
|
||||
// 绘制右侧的展开按钮
|
||||
QPen pen;
|
||||
pen.setColor(QColor(0, 0, 0));
|
||||
pen.setWidth(2);
|
||||
painter.setPen(pen);
|
||||
int iconLeft = rect().width() - MARGINRIGHTSPACE - expandSize.width();
|
||||
QPixmap expandPixmap = ImageUtil::loadSvg(expandFileName(), expandSize);
|
||||
int iconRight = rect().width() - MARGINRIGHTSPACE;
|
||||
painter.drawLine(QPoint(iconLeft, (iconBg.y() + (iconBg.height() - expandSize.height()) / 2)),
|
||||
QPoint(iconRight, (iconBg.y() + iconBg.height() / 2)));
|
||||
painter.drawLine(QPoint(iconRight, (iconBg.y() + iconBg.height() / 2)),
|
||||
QPoint(iconLeft, (iconBg.y() + (iconBg.height() + expandSize.height()) / 2)));
|
||||
QRect rectOfExpand(iconRight - expandSize.width(),
|
||||
(rctIcon.y() + (rctIcon.height() - expandSize.height()) / 2),
|
||||
expandSize.width(), expandSize.height());
|
||||
painter.drawPixmap(rectOfExpand, expandPixmap);
|
||||
} else {
|
||||
// 绘制图标
|
||||
QRect rctIcon = iconRect();
|
||||
@ -224,3 +237,11 @@ int QuickSettingItem::yMarginSpace()
|
||||
{
|
||||
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:
|
||||
int yMarginSpace();
|
||||
QString expandFileName();
|
||||
|
||||
private:
|
||||
PluginsItemInterface *m_pluginInter;
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <QSize>
|
||||
#include <QMouseEvent>
|
||||
#include <QBoxLayout>
|
||||
#include <QGuiApplication>
|
||||
|
||||
#define ITEMSIZE 22
|
||||
#define ITEMSPACE 6
|
||||
@ -488,7 +489,8 @@ void QuickDockItem::paintEvent(QPaintEvent *event)
|
||||
if (!m_pluginItem)
|
||||
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,
|
||||
ICONHEIGHT, ICONHEIGHT);
|
||||
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <QBoxLayout>
|
||||
#include <QDir>
|
||||
#include <QMetaObject>
|
||||
#include <QGuiApplication>
|
||||
|
||||
#define MAXICONSIZE 48
|
||||
#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
|
||||
{
|
||||
int iconSize = static_cast<int>(ICONSIZE * (qApp->devicePixelRatio()));
|
||||
if (m_position == Dock::Position::Top || m_position == Dock::Position::Bottom) {
|
||||
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
|
||||
height += ICONSIZE; // 图标尺寸20
|
||||
height += iconSize; // 图标尺寸20
|
||||
height += ICONTEXTSPACE; // 图标与文字间距6
|
||||
height += QFontMetrics(textFont()).height(); // 文本高度
|
||||
height += 4; // 下间距4
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "tray_model.h"
|
||||
#include "tray_delegate.h"
|
||||
#include "dockpopupwindow.h"
|
||||
#include "imageutil.h"
|
||||
|
||||
#include <DGuiApplicationHelper>
|
||||
#include <DRegionMonitor>
|
||||
@ -88,13 +89,15 @@ QPixmap ExpandIconWidget::icon()
|
||||
return QPixmap(dropIconFile());
|
||||
}
|
||||
|
||||
void ExpandIconWidget::paintEvent(QPaintEvent *e)
|
||||
void ExpandIconWidget::paintEvent(QPaintEvent *)
|
||||
{
|
||||
Q_UNUSED(e);
|
||||
|
||||
QPainter painter(this);
|
||||
QPixmap pixmap(dropIconFile());
|
||||
painter.drawPixmap(0, 0, pixmap);
|
||||
QPixmap pixmap = ImageUtil::loadSvg(dropIconFile(), QSize(ICON_SIZE, ICON_SIZE));
|
||||
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
|
||||
|
@ -58,7 +58,7 @@ private Q_SLOTS:
|
||||
void onRowCountChanged();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
const QString dropIconFile() const;
|
||||
|
||||
void resetPosition();
|
||||
|
@ -296,8 +296,7 @@ QIcon ShutdownPlugin::icon(const DockPart &dockPart)
|
||||
{
|
||||
Q_UNUSED(dockPart);
|
||||
|
||||
static QIcon shutdownIcon;
|
||||
shutdownIcon.detach();
|
||||
QIcon shutdownIcon;
|
||||
shutdownIcon.addPixmap(m_shutdownWidget->loadPixmap());
|
||||
return shutdownIcon;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user