support preview without composite

Change-Id: I212cbb0eb5f833a8a19f53dd729cd1da028118c9
This commit is contained in:
石博文 2017-05-24 14:12:50 +08:00
parent 25ee81a6c1
commit 9f5dc17cc0
Notes: Deepin Code Review 2017-05-24 14:15: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 14:15:50 +0800
Reviewed-on: https://cr.deepin.io/23380
Project: dde/dde-dock
Branch: refs/heads/master
4 changed files with 79 additions and 9 deletions

View File

@ -6,6 +6,7 @@
#define SPACING 0
#define MARGIN 0
#define SNAP_HEIGHT_WITHOUT_COMPOSITE 30
_PreviewContainer::_PreviewContainer(QWidget *parent)
: QWidget(parent),
@ -92,15 +93,19 @@ void _PreviewContainer::checkMouseLeave()
void _PreviewContainer::adjustSize()
{
const bool horizontal = m_windowListLayout->direction() == QBoxLayout::LeftToRight;
const int count = m_snapshots.size();
if (!count)
const bool composite = m_wmHelper->hasComposite();
if (!composite)
{
const int h = SNAP_HEIGHT_WITHOUT_COMPOSITE * count + MARGIN * 2 + SPACING * (count - 1);
setFixedSize(SNAP_WIDTH, h);
return;
}
const QRect r = qApp->primaryScreen()->geometry();
const int padding = 20;
const bool horizontal = m_windowListLayout->direction() == QBoxLayout::LeftToRight;
if (horizontal)
{
const int h = SNAP_HEIGHT + MARGIN * 2;
@ -147,6 +152,9 @@ void _PreviewContainer::leaveEvent(QEvent *e)
void _PreviewContainer::previewEntered(const WId wid)
{
if (!m_wmHelper->hasComposite())
return;
AppSnapshot *snap = static_cast<AppSnapshot *>(sender());
m_floatingPreview->trackWindow(snap);

View File

@ -8,12 +8,36 @@
#include <QX11Info>
#include <QPainter>
#include <QVBoxLayout>
AppSnapshot::AppSnapshot(const WId wid, QWidget *parent)
: QWidget(parent),
m_wid(wid)
m_wid(wid),
m_title(new QLabel),
m_closeBtn(new DImageButton),
m_wmHelper(DWindowManagerHelper::instance())
{
m_closeBtn->setFixedSize(24, 24);
m_closeBtn->setNormalPic(":/icons/resources/close_round_normal.png");
m_closeBtn->setHoverPic(":/icons/resources/close_round_hover.png");
m_closeBtn->setPressPic(":/icons/resources/close_round_press.png");
m_closeBtn->setVisible(false);
QHBoxLayout *centralLayout = new QHBoxLayout;
centralLayout->addWidget(m_title);
centralLayout->addWidget(m_closeBtn);
centralLayout->setSpacing(5);
centralLayout->setMargin(0);
setLayout(centralLayout);
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);
}
@ -35,13 +59,24 @@ void AppSnapshot::closeWindow() const
XFlush(display);
}
void AppSnapshot::compositeChanged() const
{
const bool composite = m_wmHelper->hasComposite();
m_title->setVisible(!composite);
// m_closeBtn->setVisible(!composite);
}
void AppSnapshot::setWindowTitle(const QString &title)
{
m_title = title;
m_title->setText(title);
}
void AppSnapshot::fetchSnapshot()
{
if (!m_wmHelper->hasComposite())
return;
const auto display = QX11Info::display();
XWindowAttributes attrs;
@ -84,7 +119,17 @@ void AppSnapshot::enterEvent(QEvent *e)
{
QWidget::enterEvent(e);
emit entered(m_wid);
if (!m_wmHelper->hasComposite())
m_closeBtn->setVisible(true);
else
emit entered(m_wid);
}
void AppSnapshot::leaveEvent(QEvent *e)
{
QWidget::leaveEvent(e);
m_closeBtn->setVisible(false);
}
void AppSnapshot::paintEvent(QPaintEvent *e)
@ -93,6 +138,12 @@ void AppSnapshot::paintEvent(QPaintEvent *e)
QPainter painter(this);
if (!m_wmHelper->hasComposite() && underMouse())
{
painter.fillRect(rect(), QColor(255, 255, 255, 255 * .2));
return;
}
if (m_snapshot.isNull())
return;

View File

@ -4,6 +4,12 @@
#include <QWidget>
#include <QDebug>
#include <QTimer>
#include <QLabel>
#include <dimagebutton.h>
#include <DWindowManagerHelper>
DWIDGET_USE_NAMESPACE
class AppSnapshot : public QWidget
{
@ -14,7 +20,7 @@ public:
WId wid() const { return m_wid; }
const QImage snapshot() const { return m_snapshot; }
const QString title() const { return m_title; }
const QString title() const { return m_title->text(); }
signals:
void entered(const WId wid) const;
@ -23,18 +29,23 @@ signals:
public slots:
void fetchSnapshot();
void closeWindow() const;
void compositeChanged() const;
void setWindowTitle(const QString &title);
private:
void enterEvent(QEvent *e);
void leaveEvent(QEvent *e);
void paintEvent(QPaintEvent *e);
void mousePressEvent(QMouseEvent *e);
private:
const WId m_wid;
QString m_title;
QImage m_snapshot;
QLabel *m_title;
DImageButton *m_closeBtn;
DWindowManagerHelper *m_wmHelper;
};
#endif // APPSNAPSHOT_H

View File

@ -49,6 +49,7 @@ void FloatingPreview::paintEvent(QPaintEvent *e)
return;
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
const QRect r = rect().marginsRemoved(QMargins(8, 8, 8, 8));
const QImage snapshot = m_tracked->snapshot();
@ -69,7 +70,6 @@ void FloatingPreview::paintEvent(QPaintEvent *e)
// 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);
}