mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
support HiDPI
Change-Id: I2bfe381f07a504ea196e2cf65cb03a7071a5863f
This commit is contained in:
parent
3b472f464d
commit
315581d633
Notes:
Deepin Code Review
2017-09-15 10:38:23 +08:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Fri, 15 Sep 2017 10:38:23 +0800 Reviewed-on: https://cr.deepin.io/26295 Project: dde/dde-dock Branch: refs/heads/master
@ -257,13 +257,15 @@ void AppItem::paintEvent(QPaintEvent *e)
|
||||
return;
|
||||
|
||||
// icon pos
|
||||
const QPointF iconPos = itemRect.center() - QRectF(pixmap.rect()).center();
|
||||
const auto ratio = qApp->devicePixelRatio();
|
||||
const int iconX = itemRect.center().x() - pixmap.rect().center().x() / ratio;
|
||||
const int iconY = itemRect.center().y() - pixmap.rect().center().y() / ratio;
|
||||
|
||||
// draw ligher/normal icon
|
||||
if (!m_hover)
|
||||
painter.drawPixmap(iconPos, pixmap);
|
||||
painter.drawPixmap(iconX, iconY, pixmap);
|
||||
else
|
||||
painter.drawPixmap(iconPos, ImageFactory::lighterEffect(pixmap));
|
||||
painter.drawPixmap(iconX, iconY, ImageFactory::lighterEffect(pixmap));
|
||||
}
|
||||
|
||||
void AppItem::mouseReleaseEvent(QMouseEvent *e)
|
||||
|
@ -45,10 +45,15 @@ void LauncherItem::paintEvent(QPaintEvent *e)
|
||||
|
||||
const QPixmap pixmap = DockDisplayMode == Fashion ? m_largeIcon : m_smallIcon;
|
||||
|
||||
if (m_hover)
|
||||
painter.drawPixmap(rect().center() - pixmap.rect().center(), ImageFactory::lighterEffect(pixmap));
|
||||
const auto ratio = qApp->devicePixelRatio();
|
||||
const int iconX = rect().center().x() - pixmap.rect().center().x() / ratio;
|
||||
const int iconY = rect().center().y() - pixmap.rect().center().y() / ratio;
|
||||
|
||||
// draw ligher/normal icon
|
||||
if (!m_hover)
|
||||
painter.drawPixmap(iconX, iconY, pixmap);
|
||||
else
|
||||
painter.drawPixmap(rect().center() - pixmap.rect().center(), pixmap);
|
||||
painter.drawPixmap(iconX, iconY, ImageFactory::lighterEffect(pixmap));
|
||||
}
|
||||
|
||||
void LauncherItem::resizeEvent(QResizeEvent *e)
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <QIcon>
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
#include <QApplication>
|
||||
|
||||
ThemeAppIcon::ThemeAppIcon(QObject *parent) : QObject(parent)
|
||||
{
|
||||
@ -16,7 +17,8 @@ ThemeAppIcon::~ThemeAppIcon()
|
||||
|
||||
const QPixmap ThemeAppIcon::getIcon(const QString iconName, const int size)
|
||||
{
|
||||
const int s = size & ~1;
|
||||
const auto ratio = qApp->devicePixelRatio();
|
||||
const int s = int(size * ratio) & ~1;
|
||||
|
||||
QPixmap pixmap;
|
||||
|
||||
@ -52,6 +54,9 @@ const QPixmap ThemeAppIcon::getIcon(const QString iconName, const int size)
|
||||
|
||||
} while (false);
|
||||
|
||||
return pixmap.scaled(s, s, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
pixmap = pixmap.scaled(s, s, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
pixmap.setDevicePixelRatio(ratio);
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <QMouseEvent>
|
||||
#include <QProcess>
|
||||
#include <QThread>
|
||||
#include <QApplication>
|
||||
|
||||
#include <X11/extensions/shape.h>
|
||||
#include <X11/extensions/XTest.h>
|
||||
@ -169,11 +170,12 @@ void TrayWidget::enterEvent(QEvent *e)
|
||||
// qDebug() << Q_FUNC_INFO;
|
||||
|
||||
// fake enter event
|
||||
const auto ratio = qApp->devicePixelRatio();
|
||||
const QPoint p(QCursor::pos());
|
||||
configContainerPosition();
|
||||
setX11PassMouseEvent(false);
|
||||
setWindowOnTop(true);
|
||||
XTestFakeMotionEvent(QX11Info::display(), 0, p.x(), p.y(), CurrentTime);
|
||||
XTestFakeMotionEvent(QX11Info::display(), 0, p.x() * ratio, p.y() * ratio, CurrentTime);
|
||||
setX11PassMouseEvent(true);
|
||||
// setWindowOnTop(false);
|
||||
|
||||
@ -182,6 +184,7 @@ void TrayWidget::enterEvent(QEvent *e)
|
||||
|
||||
void TrayWidget::configContainerPosition()
|
||||
{
|
||||
const auto ratio = qApp->devicePixelRatio();
|
||||
auto c = QX11Info::connection();
|
||||
|
||||
QPoint p(QCursor::pos());
|
||||
@ -193,7 +196,7 @@ void TrayWidget::configContainerPosition()
|
||||
// w = static_cast<QWidget *>(w->parent());
|
||||
// }
|
||||
|
||||
const uint32_t containerVals[4] = {uint32_t(p.x()), uint32_t(p.y()), 1, 1};
|
||||
const uint32_t containerVals[4] = {uint32_t(p.x() * ratio), uint32_t(p.y() * ratio), 1, 1};
|
||||
xcb_configure_window(c, m_containerWid,
|
||||
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
|
||||
containerVals);
|
||||
@ -344,10 +347,11 @@ void TrayWidget::sendClick(uint8_t mouseButton, int x, int y)
|
||||
// qDebug() << Q_FUNC_INFO;
|
||||
m_ignoreRepeat->start();
|
||||
|
||||
const auto ratio = qApp->devicePixelRatio();
|
||||
configContainerPosition();
|
||||
setX11PassMouseEvent(false);
|
||||
setWindowOnTop(true);
|
||||
XTestFakeMotionEvent(QX11Info::display(), 0, x, y, CurrentTime);
|
||||
XTestFakeMotionEvent(QX11Info::display(), 0, x * ratio, y * ratio, CurrentTime);
|
||||
XTestFakeButtonEvent(QX11Info::display(), mouseButton, true, CurrentTime);
|
||||
XFlush(QX11Info::display());
|
||||
XTestFakeButtonEvent(QX11Info::display(), mouseButton, false, CurrentTime);
|
||||
|
Loading…
x
Reference in New Issue
Block a user