mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
auto scale preview image size
Change-Id: I1a1aecc7e2dd3f23df6eb777914cc938e897f76a
This commit is contained in:
parent
7093e945d5
commit
604f85da21
Notes:
Deepin Code Review
2017-05-23 10:55:32 +08:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Tue, 23 May 2017 10:55:30 +0800 Reviewed-on: https://cr.deepin.io/23337 Project: dde/dde-dock Branch: refs/heads/master
@ -1,7 +1,9 @@
|
||||
#include "_previewcontainer.h"
|
||||
|
||||
#define FIXED_WIDTH 200
|
||||
#define FIXED_HEIGHT 130
|
||||
#include <QDesktopWidget>
|
||||
#include <QScreen>
|
||||
#include <QApplication>
|
||||
|
||||
#define SPACING 5
|
||||
#define MARGIN 5
|
||||
|
||||
@ -15,7 +17,7 @@ _PreviewContainer::_PreviewContainer(QWidget *parent)
|
||||
m_windowListLayout->setContentsMargins(MARGIN, MARGIN, MARGIN, MARGIN);
|
||||
|
||||
setLayout(m_windowListLayout);
|
||||
setFixedSize(FIXED_WIDTH, FIXED_HEIGHT);
|
||||
setFixedSize(SNAP_WIDTH, SNAP_HEIGHT);
|
||||
}
|
||||
|
||||
void _PreviewContainer::setWindowInfos(const WindowDict &infos)
|
||||
@ -60,13 +62,22 @@ void _PreviewContainer::adjustSize()
|
||||
if (!count)
|
||||
return;
|
||||
|
||||
const QRect r = qApp->primaryScreen()->geometry();
|
||||
const int padding = 20;
|
||||
|
||||
if (horizontal)
|
||||
{
|
||||
setFixedHeight(FIXED_HEIGHT + MARGIN * 2);
|
||||
setFixedWidth(FIXED_WIDTH * count + MARGIN * 2 + SPACING * (count - 1));
|
||||
const int h = SNAP_HEIGHT + MARGIN * 2;
|
||||
const int w = SNAP_WIDTH * count + MARGIN * 2 + SPACING * (count - 1);
|
||||
|
||||
setFixedHeight(h);
|
||||
setFixedWidth(std::min(w, r.width() - padding));
|
||||
} else {
|
||||
setFixedWidth(FIXED_WIDTH + MARGIN * 2);
|
||||
setFixedHeight(FIXED_HEIGHT * count + MARGIN * 2 + SPACING * (count - 1));
|
||||
const int w = SNAP_WIDTH + MARGIN * 2;
|
||||
const int h = SNAP_HEIGHT * count + MARGIN * 2 + SPACING * (count - 1);
|
||||
|
||||
setFixedWidth(w);
|
||||
setFixedHeight(std::min(h, r.height() - padding));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,9 @@
|
||||
|
||||
#include <DWindowManagerHelper>
|
||||
|
||||
#define SNAP_WIDTH 200
|
||||
#define SNAP_HEIGHT 130
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
class _PreviewContainer : public QWidget
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "appsnapshot.h"
|
||||
#include "_previewcontainer.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/X.h>
|
||||
@ -57,12 +58,13 @@ void AppSnapshot::fetchSnapshot()
|
||||
|
||||
m_snapshot = qimage.copy(left, top, width - left - right, height - top - bottom);
|
||||
} else {
|
||||
m_snapshot = qimage;
|
||||
m_snapshot = qimage.copy();
|
||||
}
|
||||
|
||||
const QSize s = size();
|
||||
m_snapshot = m_snapshot.scaled(s.width(), s.height(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
||||
m_snapshot = m_snapshot.copy((m_snapshot.width() - s.width()) / 2, (m_snapshot.height() - s.height()) / 2, s.width(), s.height());
|
||||
// const int w = width();
|
||||
// const int h = height();
|
||||
// m_snapshot = m_snapshot.scaled(w, h, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
|
||||
// m_snapshot = m_snapshot.copy((m_snapshot.width() - w) / 2, (m_snapshot.height() - h) / 2, w, h);
|
||||
XDestroyImage(ximage);
|
||||
XFree(prop_to_return);
|
||||
|
||||
@ -88,13 +90,16 @@ void AppSnapshot::paintEvent(QPaintEvent *e)
|
||||
const QRect r = rect();
|
||||
|
||||
// draw image
|
||||
// const QRect ir = m_snapshot.rect();
|
||||
// const QPoint offset = r.center() - ir.center();
|
||||
|
||||
// painter.fillRect(offset.x(), offset.y(), ir.width(), ir.height(), Qt::white);
|
||||
// painter.drawImage(offset.x(), offset.y(), m_snapshot);
|
||||
painter.fillRect(r, Qt::white);
|
||||
painter.drawImage(r, m_snapshot);
|
||||
// painter.fillRect(r, Qt::white);
|
||||
const QSize s = size();
|
||||
const QImage im = m_snapshot.scaled(s, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
const QRect ir = im.rect();
|
||||
const QPoint offset = r.center() - ir.center();
|
||||
painter.drawImage(offset.x(), offset.y(), im);
|
||||
}
|
||||
|
||||
void AppSnapshot::resizeEvent(QResizeEvent *e)
|
||||
|
Loading…
x
Reference in New Issue
Block a user