mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
support preview without composite
Change-Id: I212cbb0eb5f833a8a19f53dd729cd1da028118c9
This commit is contained in:
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
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#define SPACING 0
|
#define SPACING 0
|
||||||
#define MARGIN 0
|
#define MARGIN 0
|
||||||
|
#define SNAP_HEIGHT_WITHOUT_COMPOSITE 30
|
||||||
|
|
||||||
_PreviewContainer::_PreviewContainer(QWidget *parent)
|
_PreviewContainer::_PreviewContainer(QWidget *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
@ -92,15 +93,19 @@ void _PreviewContainer::checkMouseLeave()
|
|||||||
|
|
||||||
void _PreviewContainer::adjustSize()
|
void _PreviewContainer::adjustSize()
|
||||||
{
|
{
|
||||||
const bool horizontal = m_windowListLayout->direction() == QBoxLayout::LeftToRight;
|
|
||||||
const int count = m_snapshots.size();
|
const int count = m_snapshots.size();
|
||||||
|
const bool composite = m_wmHelper->hasComposite();
|
||||||
if (!count)
|
if (!composite)
|
||||||
|
{
|
||||||
|
const int h = SNAP_HEIGHT_WITHOUT_COMPOSITE * count + MARGIN * 2 + SPACING * (count - 1);
|
||||||
|
setFixedSize(SNAP_WIDTH, h);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const QRect r = qApp->primaryScreen()->geometry();
|
const QRect r = qApp->primaryScreen()->geometry();
|
||||||
const int padding = 20;
|
const int padding = 20;
|
||||||
|
|
||||||
|
const bool horizontal = m_windowListLayout->direction() == QBoxLayout::LeftToRight;
|
||||||
if (horizontal)
|
if (horizontal)
|
||||||
{
|
{
|
||||||
const int h = SNAP_HEIGHT + MARGIN * 2;
|
const int h = SNAP_HEIGHT + MARGIN * 2;
|
||||||
@ -147,6 +152,9 @@ void _PreviewContainer::leaveEvent(QEvent *e)
|
|||||||
|
|
||||||
void _PreviewContainer::previewEntered(const WId wid)
|
void _PreviewContainer::previewEntered(const WId wid)
|
||||||
{
|
{
|
||||||
|
if (!m_wmHelper->hasComposite())
|
||||||
|
return;
|
||||||
|
|
||||||
AppSnapshot *snap = static_cast<AppSnapshot *>(sender());
|
AppSnapshot *snap = static_cast<AppSnapshot *>(sender());
|
||||||
|
|
||||||
m_floatingPreview->trackWindow(snap);
|
m_floatingPreview->trackWindow(snap);
|
||||||
|
@ -8,12 +8,36 @@
|
|||||||
|
|
||||||
#include <QX11Info>
|
#include <QX11Info>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QVBoxLayout>
|
||||||
|
|
||||||
AppSnapshot::AppSnapshot(const WId wid, QWidget *parent)
|
AppSnapshot::AppSnapshot(const WId wid, QWidget *parent)
|
||||||
: 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);
|
// QTimer::singleShot(1, this, &AppSnapshot::fetchSnapshot);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,13 +59,24 @@ void AppSnapshot::closeWindow() const
|
|||||||
XFlush(display);
|
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)
|
void AppSnapshot::setWindowTitle(const QString &title)
|
||||||
{
|
{
|
||||||
m_title = title;
|
m_title->setText(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppSnapshot::fetchSnapshot()
|
void AppSnapshot::fetchSnapshot()
|
||||||
{
|
{
|
||||||
|
if (!m_wmHelper->hasComposite())
|
||||||
|
return;
|
||||||
|
|
||||||
const auto display = QX11Info::display();
|
const auto display = QX11Info::display();
|
||||||
|
|
||||||
XWindowAttributes attrs;
|
XWindowAttributes attrs;
|
||||||
@ -84,7 +119,17 @@ void AppSnapshot::enterEvent(QEvent *e)
|
|||||||
{
|
{
|
||||||
QWidget::enterEvent(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)
|
void AppSnapshot::paintEvent(QPaintEvent *e)
|
||||||
@ -93,6 +138,12 @@ void AppSnapshot::paintEvent(QPaintEvent *e)
|
|||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
|
if (!m_wmHelper->hasComposite() && underMouse())
|
||||||
|
{
|
||||||
|
painter.fillRect(rect(), QColor(255, 255, 255, 255 * .2));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_snapshot.isNull())
|
if (m_snapshot.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -4,6 +4,12 @@
|
|||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
|
#include <dimagebutton.h>
|
||||||
|
#include <DWindowManagerHelper>
|
||||||
|
|
||||||
|
DWIDGET_USE_NAMESPACE
|
||||||
|
|
||||||
class AppSnapshot : public QWidget
|
class AppSnapshot : public QWidget
|
||||||
{
|
{
|
||||||
@ -14,7 +20,7 @@ public:
|
|||||||
|
|
||||||
WId wid() const { return m_wid; }
|
WId wid() const { return m_wid; }
|
||||||
const QImage snapshot() const { return m_snapshot; }
|
const QImage snapshot() const { return m_snapshot; }
|
||||||
const QString title() const { return m_title; }
|
const QString title() const { return m_title->text(); }
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void entered(const WId wid) const;
|
void entered(const WId wid) const;
|
||||||
@ -23,18 +29,23 @@ signals:
|
|||||||
public slots:
|
public slots:
|
||||||
void fetchSnapshot();
|
void fetchSnapshot();
|
||||||
void closeWindow() const;
|
void closeWindow() const;
|
||||||
|
void compositeChanged() const;
|
||||||
void setWindowTitle(const QString &title);
|
void setWindowTitle(const QString &title);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void enterEvent(QEvent *e);
|
void enterEvent(QEvent *e);
|
||||||
|
void leaveEvent(QEvent *e);
|
||||||
void paintEvent(QPaintEvent *e);
|
void paintEvent(QPaintEvent *e);
|
||||||
void mousePressEvent(QMouseEvent *e);
|
void mousePressEvent(QMouseEvent *e);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const WId m_wid;
|
const WId m_wid;
|
||||||
|
|
||||||
QString m_title;
|
|
||||||
QImage m_snapshot;
|
QImage m_snapshot;
|
||||||
|
QLabel *m_title;
|
||||||
|
DImageButton *m_closeBtn;
|
||||||
|
|
||||||
|
DWindowManagerHelper *m_wmHelper;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APPSNAPSHOT_H
|
#endif // APPSNAPSHOT_H
|
||||||
|
@ -49,6 +49,7 @@ void FloatingPreview::paintEvent(QPaintEvent *e)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
const QRect r = rect().marginsRemoved(QMargins(8, 8, 8, 8));
|
const QRect r = rect().marginsRemoved(QMargins(8, 8, 8, 8));
|
||||||
const QImage snapshot = m_tracked->snapshot();
|
const QImage snapshot = m_tracked->snapshot();
|
||||||
@ -69,7 +70,6 @@ void FloatingPreview::paintEvent(QPaintEvent *e)
|
|||||||
// draw border
|
// draw border
|
||||||
const QRect br = r.marginsAdded(QMargins(1, 1, 1, 1));
|
const QRect br = r.marginsAdded(QMargins(1, 1, 1, 1));
|
||||||
painter.setBrush(Qt::transparent);
|
painter.setBrush(Qt::transparent);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
|
||||||
painter.drawRoundedRect(br, 3, 3);
|
painter.drawRoundedRect(br, 3, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user