draw preview window content at floating window

Change-Id: I9d8e16463b3f84de331a0da76f3126ef659cc488
This commit is contained in:
石博文 2017-05-24 10:56:43 +08:00
parent 336c6b25dd
commit e8a560faee
Notes: Deepin Code Review 2017-05-24 11:02:54 +08:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: 石博文 <sbw@sbw.so>
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Wed, 24 May 2017 11:02:48 +0800
Reviewed-on: https://cr.deepin.io/23369
Project: dde/dde-dock
Branch: refs/heads/master
4 changed files with 38 additions and 6 deletions

View File

@ -4,8 +4,8 @@
#include <QScreen> #include <QScreen>
#include <QApplication> #include <QApplication>
#define SPACING 5 #define SPACING 0
#define MARGIN 5 #define MARGIN 0
_PreviewContainer::_PreviewContainer(QWidget *parent) _PreviewContainer::_PreviewContainer(QWidget *parent)
: QWidget(parent), : QWidget(parent),
@ -49,6 +49,7 @@ void _PreviewContainer::setWindowInfos(const WindowDict &infos)
{ {
if (!m_snapshots.contains(it.key())) if (!m_snapshots.contains(it.key()))
appendSnapWidget(it.key()); appendSnapWidget(it.key());
m_snapshots[it.key()]->setWindowTitle(it.value());
} }
adjustSize(); adjustSize();

View File

@ -42,6 +42,11 @@ void AppSnapshot::closeWindow() const
XFlush(display); XFlush(display);
} }
void AppSnapshot::setWindowTitle(const QString &title)
{
m_title = title;
}
void AppSnapshot::fetchSnapshot() void AppSnapshot::fetchSnapshot()
{ {
if (!isVisible()) if (!isVisible())
@ -105,7 +110,7 @@ void AppSnapshot::paintEvent(QPaintEvent *e)
if (m_snapshot.isNull()) if (m_snapshot.isNull())
return; return;
const QRect r = rect(); const QRect r = rect().marginsRemoved(QMargins(8, 8, 8, 8));
// draw image // draw image
// const QPoint offset = r.center() - ir.center(); // const QPoint offset = r.center() - ir.center();
@ -113,8 +118,7 @@ void AppSnapshot::paintEvent(QPaintEvent *e)
// painter.fillRect(offset.x(), offset.y(), ir.width(), ir.height(), Qt::white); // painter.fillRect(offset.x(), offset.y(), ir.width(), ir.height(), Qt::white);
// painter.drawImage(offset.x(), offset.y(), m_snapshot); // painter.drawImage(offset.x(), offset.y(), m_snapshot);
// painter.fillRect(r, Qt::white); // painter.fillRect(r, Qt::white);
const QSize s = size(); const QImage im = m_snapshot.scaled(r.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
const QImage im = m_snapshot.scaled(s, Qt::KeepAspectRatio, Qt::SmoothTransformation);
const QRect ir = im.rect(); const QRect ir = im.rect();
const QPoint offset = r.center() - ir.center(); const QPoint offset = r.center() - ir.center();
painter.drawImage(offset.x(), offset.y(), im); painter.drawImage(offset.x(), offset.y(), im);

View File

@ -13,6 +13,8 @@ public:
explicit AppSnapshot(const WId wid, QWidget *parent = 0); explicit AppSnapshot(const WId wid, QWidget *parent = 0);
WId wid() const { return m_wid; } WId wid() const { return m_wid; }
const QImage snapshot() const { return m_snapshot; }
const QString title() const { return m_title; }
signals: signals:
void entered(const WId wid) const; void entered(const WId wid) const;
@ -20,6 +22,7 @@ signals:
public slots: public slots:
void closeWindow() const; void closeWindow() const;
void setWindowTitle(const QString &title);
private slots: private slots:
void fetchSnapshot(); void fetchSnapshot();
@ -33,6 +36,7 @@ private:
private: private:
const WId m_wid; const WId m_wid;
QString m_title;
QImage m_snapshot; QImage m_snapshot;
QTimer *m_fetchSnapshotTimer; QTimer *m_fetchSnapshotTimer;

View File

@ -42,9 +42,32 @@ void FloatingPreview::paintEvent(QPaintEvent *e)
{ {
QWidget::paintEvent(e); QWidget::paintEvent(e);
if (m_tracked.isNull())
return;
QPainter painter(this); QPainter painter(this);
painter.fillRect(rect(), Qt::red); const QRect r = rect().marginsRemoved(QMargins(8, 8, 8, 8));
const QImage snapshot = m_tracked->snapshot();
const QImage im = snapshot.scaled(r.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
const QRect ir = im.rect();
const QPoint offset = r.center() - ir.center();
painter.fillRect(r, Qt::black);
painter.drawImage(offset.x(), offset.y(), im);
// bottom black background
QRect bgr = r;
bgr.setTop(bgr.bottom() - 25);
painter.fillRect(bgr, QColor(0, 0, 0, 255 * 0.3));
// bottom title
painter.drawText(bgr, Qt::AlignCenter, m_tracked->title());
// draw border
const QRect br = r.marginsAdded(QMargins(1, 1, 1, 1));
painter.setBrush(Qt::transparent);
painter.setRenderHint(QPainter::Antialiasing);
painter.drawRoundedRect(br, 3, 3);
} }
void FloatingPreview::mouseReleaseEvent(QMouseEvent *e) void FloatingPreview::mouseReleaseEvent(QMouseEvent *e)