preview: close window when click 'x' button

Change-Id: I672a5ba18197c562261c9f1d53428381733ddee4
This commit is contained in:
石博文 2017-04-20 13:53:15 +08:00
parent f583684252
commit f233970dc8
Notes: Deepin Code Review 2017-04-20 13:54:54 +08:00
Code-Review+2: 石博文 <sbw@sbw.so>
Verified+1: 石博文 <sbw@sbw.so>
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Thu, 20 Apr 2017 13:54:54 +0800
Reviewed-on: https://cr.deepin.io/22435
Project: dde/dde-dock
Branch: refs/heads/master
2 changed files with 15 additions and 2 deletions

View File

@ -33,6 +33,8 @@ PreviewWidget::PreviewWidget(const WId wid, QWidget *parent)
setFixedSize(W + M * 2, H + M * 2);
setLayout(centralLayout);
connect(m_closeButton, &QPushButton::clicked, this, &PreviewWidget::closeWindow);
QTimer::singleShot(1, this, &PreviewWidget::refershImage);
}
@ -45,9 +47,11 @@ void PreviewWidget::setTitle(const QString &title)
void PreviewWidget::refershImage()
{
const auto display = QX11Info::display();
XWindowAttributes attrs;
XGetWindowAttributes(QX11Info::display(), m_wid, &attrs);
XImage *ximage = XGetImage(QX11Info::display(), m_wid, 0, 0, attrs.width, attrs.height, AllPlanes, ZPixmap);
XGetWindowAttributes(display, m_wid, &attrs);
XImage *ximage = XGetImage(display, m_wid, 0, 0, attrs.width, attrs.height, AllPlanes, ZPixmap);
const QImage qimage((const uchar*)(ximage->data), ximage->width, ximage->height, ximage->bytes_per_line, QImage::Format_RGB32);
m_image = qimage.scaled(W, H, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
@ -57,6 +61,14 @@ void PreviewWidget::refershImage()
update();
}
void PreviewWidget::closeWindow()
{
const auto display = QX11Info::display();
XDestroyWindow(display, m_wid);
XFlush(display);
}
void PreviewWidget::paintEvent(QPaintEvent *e)
{
const QRect r = rect().marginsRemoved(QMargins(M, M, M, M));

View File

@ -18,6 +18,7 @@ signals:
private slots:
void refershImage();
void closeWindow();
private:
void paintEvent(QPaintEvent *e);