optimize snapshot image quality

Change-Id: Ib201e632dfd43ff455746515d05f859a090c4280
This commit is contained in:
石博文 2017-12-28 15:41:47 +08:00
parent cdfe2d48f3
commit ed4ac954e3
Notes: Deepin Code Review 2017-12-28 16:00:54 +08:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: 石博文 <sbw@sbw.so>
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Thu, 28 Dec 2017 16:00:54 +0800
Reviewed-on: https://cr.deepin.io/29804
Project: dde/dde-dock
Branch: refs/heads/master
4 changed files with 12 additions and 7 deletions

View File

@ -3,7 +3,6 @@ TEMPLATE = subdirs
SUBDIRS = frame \
plugins
# Automating generation .qm files from .ts files
CONFIG(release, debug|release) {
!system($$PWD/translate_generation.sh): error("Failed to generate translation")

View File

@ -55,12 +55,12 @@ AppSnapshot::AppSnapshot(const WId wid, QWidget *parent)
setLayout(centralLayout);
setAcceptDrops(true);
setFixedSize(SNAP_WIDTH, SNAP_HEIGHT);
connect(m_closeBtn, &DImageButton::clicked, this, &AppSnapshot::closeWindow, Qt::QueuedConnection);
connect(m_wmHelper, &DWindowManagerHelper::hasCompositeChanged, this, &AppSnapshot::compositeChanged, Qt::QueuedConnection);
QTimer::singleShot(1, this, &AppSnapshot::compositeChanged);
// QTimer::singleShot(1, this, &AppSnapshot::fetchSnapshot);
}
void AppSnapshot::closeWindow() const
@ -147,6 +147,11 @@ void AppSnapshot::fetchSnapshot()
m_snapshot = qimage.copy();
}
const auto size = rect().marginsRemoved(QMargins(8, 8, 8, 8)).size();
const auto ratio = devicePixelRatioF();
m_snapshot = m_snapshot.scaled(size * ratio, Qt::KeepAspectRatio, Qt::SmoothTransformation);
m_snapshot.setDevicePixelRatio(ratio);
XDestroyImage(ximage);
XFree(prop_to_return);
@ -190,8 +195,9 @@ void AppSnapshot::paintEvent(QPaintEvent *e)
const auto ratio = devicePixelRatioF();
// draw image
QImage im = m_snapshot.scaled(r.size() * ratio, Qt::KeepAspectRatio, Qt::SmoothTransformation);
im.setDevicePixelRatio(ratio);
// QImage im = m_snapshot.scaled(r.size() * ratio, Qt::KeepAspectRatio, Qt::SmoothTransformation);
// im.setDevicePixelRatio(ratio);
const QImage &im = m_snapshot;
const QRect ir = im.rect();
const int offset_x = r.x() + r.width() / 2 - ir.width() / ratio / 2;

View File

@ -32,6 +32,9 @@
DWIDGET_USE_NAMESPACE
#define SNAP_WIDTH 200
#define SNAP_HEIGHT 130
class AppSnapshot : public QWidget
{
Q_OBJECT

View File

@ -33,9 +33,6 @@
#include <DWindowManagerHelper>
#define SNAP_WIDTH 200
#define SNAP_HEIGHT 130
DWIDGET_USE_NAMESPACE
class PreviewContainer : public QWidget