preview: adjust preview window ui

Change-Id: I53dd2837f436310f38bc3d1c2ce772e8d8f86f01
This commit is contained in:
石博文 2017-04-18 15:07:00 +08:00
parent 1a008a27f0
commit f8f4509d72
Notes: Deepin Code Review 2017-04-18 15:44:14 +08:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: 石博文 <sbw@sbw.so>
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Tue, 18 Apr 2017 15:44:13 +0800
Reviewed-on: https://cr.deepin.io/22389
Project: dde/dde-dock
Branch: refs/heads/master
6 changed files with 102 additions and 15 deletions

View File

@ -256,11 +256,12 @@ void AppItem::mouseReleaseEvent(QMouseEvent *e)
// if (distance.manhattanLength() > APP_DRAG_THRESHOLD)
// return;
const int windowCount = m_titles.size();
if (windowCount < 2)
m_itemEntry->Activate();
else
togglePreview();
// const int windowCount = m_titles.size();
// if (windowCount < 2)
// m_itemEntry->Activate();
// else
// togglePreview();
m_itemEntry->Activate();
// if (!m_titles.isEmpty())
// return;
@ -344,6 +345,25 @@ void AppItem::dropEvent(QDropEvent *e)
m_itemEntry->HandleDragDrop(uriList);
}
void AppItem::showHoverTips()
{
// another model popup window is alread exists
// if (PopupWindow->isVisible() && PopupWindow->model())
// return;
// QWidget * const content = popupTips();
// if (!content)
// return;
// showPopupWindow(content);
const int count = m_titles.size();
if (count <= 1)
return DockItem::showHoverTips();
togglePreview();
}
void AppItem::invokedMenuItem(const QString &itemId, const bool checked)
{
Q_UNUSED(checked);

View File

@ -36,6 +36,7 @@ private:
void dragEnterEvent(QDragEnterEvent *e);
void dropEvent(QDropEvent *e);
void showHoverTips();
void invokedMenuItem(const QString &itemId, const bool checked);
const QString contextMenu() const;
QWidget *popupTips();

View File

@ -3,13 +3,14 @@
#include <QLabel>
#include <QWindow>
#include <QDebug>
PreviewContainer::PreviewContainer(QWidget *parent)
: QWidget(parent)
{
m_windowListLayout = new QBoxLayout(QBoxLayout::LeftToRight);
m_windowListLayout->setMargin(0);
m_windowListLayout->setSpacing(5);
m_windowListLayout->setMargin(5);
m_windowListLayout->setSpacing(3);
setLayout(m_windowListLayout);
}
@ -26,6 +27,7 @@ void PreviewContainer::setWindowInfos(const WindowDict &infos)
for (auto it(infos.cbegin()); it != infos.cend(); ++it)
{
PreviewWidget *w = new PreviewWidget(it.key());
w->setTitle(it.value());
connect(w, &PreviewWidget::requestActivateWindow, this, &PreviewContainer::requestActivateWindow);

View File

@ -7,27 +7,49 @@
#include <QX11Info>
#include <QPainter>
#include <QTimer>
#include <QVBoxLayout>
#define W 250
#define H 200
#define W 200
#define H 130
#define M 8
PreviewWidget::PreviewWidget(const WId wid, QWidget *parent)
: QWidget(parent),
m_wid(wid)
m_wid(wid),
m_hovered(false)
{
setFixedSize(W, H);
m_closeButton = new QPushButton;
m_closeButton->setFixedSize(16, 16);
m_closeButton->setText("x");
m_closeButton->setVisible(false);
QVBoxLayout *centralLayout = new QVBoxLayout;
centralLayout->setSpacing(0);
centralLayout->setMargin(0);
centralLayout->addWidget(m_closeButton);
centralLayout->setAlignment(m_closeButton, Qt::AlignTop | Qt::AlignRight);
setFixedSize(W + M * 2, H + M * 2);
setLayout(centralLayout);
QTimer::singleShot(1, this, &PreviewWidget::refershImage);
}
void PreviewWidget::setTitle(const QString &title)
{
m_title = title;
update();
}
void PreviewWidget::refershImage()
{
XWindowAttributes attrs;
XGetWindowAttributes(QX11Info::display(), m_wid, &attrs);
XImage *ximage = XGetImage(QX11Info::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_ARGB32_Premultiplied);
const QImage qimage((const uchar*)(ximage->data), ximage->width, ximage->height, ximage->bytes_per_line, QImage::Format_ARGB32);
m_image = qimage.scaled(W, H, Qt::KeepAspectRatio, Qt::SmoothTransformation);
update();
@ -36,10 +58,41 @@ void PreviewWidget::refershImage()
void PreviewWidget::paintEvent(QPaintEvent *e)
{
QWidget::paintEvent(e);
const QRect r = rect().marginsRemoved(QMargins(M, M, M, M));
QPainter painter(this);
painter.drawImage(rect().center() - m_image.rect().center(), m_image);
#ifdef QT_DEBUG
painter.fillRect(r, Qt::red);
#endif
// draw image
const QRect ir = m_image.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_image);
QWidget::paintEvent(e);
}
void PreviewWidget::enterEvent(QEvent *e)
{
m_hovered = true;
m_closeButton->setVisible(true);
update();
QWidget::enterEvent(e);
}
void PreviewWidget::leaveEvent(QEvent *e)
{
m_hovered = false;
m_closeButton->setVisible(false);
update();
QWidget::leaveEvent(e);
}
void PreviewWidget::mouseReleaseEvent(QMouseEvent *e)

View File

@ -2,6 +2,8 @@
#define PREVIEWWIDGET_H
#include <QWidget>
#include <QDebug>
#include <QPushButton>
class PreviewWidget : public QWidget
{
@ -9,6 +11,8 @@ class PreviewWidget : public QWidget
public:
explicit PreviewWidget(const WId wid, QWidget *parent = 0);
void setTitle(const QString &title);
signals:
void requestActivateWindow(const WId wid) const;
@ -17,11 +21,18 @@ private slots:
private:
void paintEvent(QPaintEvent *e);
void enterEvent(QEvent *e);
void leaveEvent(QEvent *e);
void mouseReleaseEvent(QMouseEvent *e);
private:
const WId m_wid;
QImage m_image;
QString m_title;
QPushButton *m_closeButton;
bool m_hovered;
};
#endif // PREVIEWWIDGET_H

View File

@ -54,9 +54,9 @@ protected:
const QPoint popupMarkPoint();
void hidePopup();
void showHoverTips();
void popupWindowAccept();
void showPopupApplet(QWidget * const applet);
virtual void showHoverTips();
virtual void invokedMenuItem(const QString &itemId, const bool checked);
virtual const QString contextMenu() const;
virtual QWidget *popupTips();