mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
pass get image for unchanged window
Change-Id: Id71b3b01aa783397b7a0b7a8d797bbad602af9c0
This commit is contained in:
parent
0785cd9623
commit
825b5695b1
Notes:
Deepin Code Review
2017-05-04 17:16:47 +08:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Thu, 04 May 2017 17:16:45 +0800 Reviewed-on: https://cr.deepin.io/22803 Project: dde/dde-dock Branch: refs/heads/master
@ -43,7 +43,7 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
|
||||
|
||||
setAccessibleName(m_itemEntry->name());
|
||||
setAcceptDrops(true);
|
||||
setMouseTracking(true);
|
||||
// setMouseTracking(true);
|
||||
setLayout(centralLayout);
|
||||
|
||||
m_itemView->setScene(m_itemScene);
|
||||
@ -71,7 +71,7 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
|
||||
m_appPreviewTips->setVisible(false);
|
||||
|
||||
connect(m_itemEntry, &DBusDockEntry::ActiveChanged, this, &AppItem::activeChanged);
|
||||
connect(m_itemEntry, &DBusDockEntry::TitlesChanged, this, &AppItem::updateTitle);
|
||||
connect(m_itemEntry, &DBusDockEntry::TitlesChanged, this, &AppItem::updateTitle, Qt::QueuedConnection);
|
||||
connect(m_itemEntry, &DBusDockEntry::IconChanged, this, &AppItem::refershIcon);
|
||||
connect(m_itemEntry, &DBusDockEntry::ActiveChanged, this, static_cast<void (AppItem::*)()>(&AppItem::update));
|
||||
|
||||
@ -328,8 +328,8 @@ void AppItem::mouseMoveEvent(QMouseEvent *e)
|
||||
e->accept();
|
||||
|
||||
// handle preview
|
||||
if (e->buttons() == Qt::NoButton)
|
||||
return showPreview();
|
||||
// if (e->buttons() == Qt::NoButton)
|
||||
// return showPreview();
|
||||
|
||||
// handle drag
|
||||
if (e->buttons() != Qt::LeftButton)
|
||||
@ -393,6 +393,14 @@ void AppItem::dropEvent(QDropEvent *e)
|
||||
m_itemEntry->HandleDragDrop(uriList);
|
||||
}
|
||||
|
||||
void AppItem::showHoverTips()
|
||||
{
|
||||
if (!m_titles.isEmpty())
|
||||
return showPreview();
|
||||
|
||||
DockItem::showHoverTips();
|
||||
}
|
||||
|
||||
void AppItem::invokedMenuItem(const QString &itemId, const bool checked)
|
||||
{
|
||||
Q_UNUSED(checked);
|
||||
@ -450,8 +458,6 @@ void AppItem::startDrag()
|
||||
void AppItem::updateTitle()
|
||||
{
|
||||
m_titles = m_itemEntry->titles();
|
||||
|
||||
// TODO: optimize
|
||||
m_appPreviewTips->setWindowInfos(m_titles);
|
||||
|
||||
update();
|
||||
@ -485,18 +491,19 @@ void AppItem::showPreview()
|
||||
return;
|
||||
|
||||
// test cursor position
|
||||
const QRect r = rect();
|
||||
const QPoint p = mapFromGlobal(QCursor::pos());
|
||||
// const QRect r = rect();
|
||||
// const QPoint p = mapFromGlobal(QCursor::pos());
|
||||
|
||||
switch (DockPosition)
|
||||
{
|
||||
case Top: if (p.y() != r.top()) return; break;
|
||||
case Left: if (p.x() != r.left()) return; break;
|
||||
case Right: if (p.x() != r.right()) return; break;
|
||||
case Bottom: if (p.y() != r.bottom()) return; break;
|
||||
default: return;
|
||||
}
|
||||
// switch (DockPosition)
|
||||
// {
|
||||
// case Top: if (p.y() != r.top()) return; break;
|
||||
// case Left: if (p.x() != r.left()) return; break;
|
||||
// case Right: if (p.x() != r.right()) return; break;
|
||||
// case Bottom: if (p.y() != r.bottom()) return; break;
|
||||
// default: return;
|
||||
// }
|
||||
|
||||
m_appPreviewTips->setWindowInfos(m_titles);
|
||||
m_appPreviewTips->updateLayoutDirection(DockPosition);
|
||||
|
||||
qApp->processEvents();
|
||||
|
@ -42,6 +42,7 @@ private:
|
||||
void dragMoveEvent(QDragMoveEvent *e);
|
||||
void dropEvent(QDropEvent *e);
|
||||
|
||||
void showHoverTips();
|
||||
void invokedMenuItem(const QString &itemId, const bool checked);
|
||||
const QString contextMenu() const;
|
||||
QWidget *popupTips();
|
||||
|
@ -6,25 +6,24 @@
|
||||
#include <QDebug>
|
||||
|
||||
PreviewContainer::PreviewContainer(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
: QWidget(parent),
|
||||
|
||||
m_mouseLeaveTimer(new QTimer(this))
|
||||
{
|
||||
m_windowListLayout = new QBoxLayout(QBoxLayout::LeftToRight);
|
||||
m_windowListLayout->setMargin(5);
|
||||
m_windowListLayout->setSpacing(3);
|
||||
|
||||
m_mouseLeaveTimer->setSingleShot(true);
|
||||
m_mouseLeaveTimer->setInterval(100);
|
||||
|
||||
setLayout(m_windowListLayout);
|
||||
setMouseTracking(true);
|
||||
|
||||
connect(m_mouseLeaveTimer, &QTimer::timeout, this, &PreviewContainer::checkMouseLeave, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void PreviewContainer::setWindowInfos(const WindowDict &infos)
|
||||
{
|
||||
// TODO: optimize
|
||||
while (QLayoutItem *item = m_windowListLayout->takeAt(0))
|
||||
{
|
||||
item->widget()->deleteLater();
|
||||
delete item;
|
||||
}
|
||||
|
||||
if (infos.isEmpty())
|
||||
{
|
||||
emit requestCancelPreview();
|
||||
@ -33,8 +32,26 @@ void PreviewContainer::setWindowInfos(const WindowDict &infos)
|
||||
return;
|
||||
}
|
||||
|
||||
QList<WId> removedWindows;
|
||||
|
||||
// remove desroyed window
|
||||
for (auto it(m_windows.cbegin()); it != m_windows.cend(); ++it)
|
||||
{
|
||||
if (infos.contains(it.key()))
|
||||
continue;
|
||||
|
||||
removedWindows << it.key();
|
||||
m_windowListLayout->removeWidget(it.value());
|
||||
it.value()->deleteLater();
|
||||
}
|
||||
for (auto id : removedWindows)
|
||||
m_windows.remove(id);
|
||||
|
||||
for (auto it(infos.cbegin()); it != infos.cend(); ++it)
|
||||
{
|
||||
if (m_windows.contains(it.key()))
|
||||
continue;
|
||||
|
||||
PreviewWidget *w = new PreviewWidget(it.key());
|
||||
w->setTitle(it.value());
|
||||
|
||||
@ -44,11 +61,9 @@ void PreviewContainer::setWindowInfos(const WindowDict &infos)
|
||||
connect(w, &PreviewWidget::requestHidePreview, this, &PreviewContainer::requestHidePreview);
|
||||
|
||||
m_windowListLayout->addWidget(w);
|
||||
m_windows.insert(it.key(), w);
|
||||
}
|
||||
|
||||
if (!isVisible())
|
||||
return;
|
||||
|
||||
// update geometry
|
||||
QMetaObject::invokeMethod(this, "updateContainerSize", Qt::QueuedConnection);
|
||||
}
|
||||
@ -73,13 +88,25 @@ void PreviewContainer::leaveEvent(QEvent *e)
|
||||
{
|
||||
QWidget::leaveEvent(e);
|
||||
|
||||
const QPoint p = mapFromGlobal(QCursor::pos()) + pos();
|
||||
m_mouseLeaveTimer->start();
|
||||
}
|
||||
|
||||
if (!rect().contains(p))
|
||||
emit requestCancelPreview();
|
||||
void PreviewContainer::enterEvent(QEvent *e)
|
||||
{
|
||||
QWidget::enterEvent(e);
|
||||
|
||||
m_mouseLeaveTimer->stop();
|
||||
}
|
||||
|
||||
void PreviewContainer::updateContainerSize()
|
||||
{
|
||||
resize(sizeHint());
|
||||
}
|
||||
|
||||
void PreviewContainer::checkMouseLeave()
|
||||
{
|
||||
const QPoint p = mapFromGlobal(QCursor::pos());
|
||||
|
||||
if (!rect().contains(p))
|
||||
emit requestCancelPreview();
|
||||
}
|
||||
|
@ -28,12 +28,18 @@ public slots:
|
||||
|
||||
protected:
|
||||
void leaveEvent(QEvent *e);
|
||||
void enterEvent(QEvent *e);
|
||||
|
||||
private slots:
|
||||
void updateContainerSize();
|
||||
void checkMouseLeave();
|
||||
|
||||
private:
|
||||
QBoxLayout *m_windowListLayout;
|
||||
|
||||
QTimer *m_mouseLeaveTimer;
|
||||
|
||||
QMap<WId, QWidget *> m_windows;
|
||||
};
|
||||
|
||||
#endif // PREVIEWCONTAINER_H
|
||||
|
@ -17,6 +17,8 @@ PreviewWidget::PreviewWidget(const WId wid, QWidget *parent)
|
||||
: QWidget(parent),
|
||||
|
||||
m_wid(wid),
|
||||
m_mouseEnterTimer(new QTimer(this)),
|
||||
|
||||
m_hovered(false)
|
||||
{
|
||||
m_closeButton = new QPushButton;
|
||||
@ -28,6 +30,9 @@ PreviewWidget::PreviewWidget(const WId wid, QWidget *parent)
|
||||
m_droppedDelay->setSingleShot(true);
|
||||
m_droppedDelay->setInterval(100);
|
||||
|
||||
m_mouseEnterTimer->setInterval(200);
|
||||
m_mouseEnterTimer->setSingleShot(true);
|
||||
|
||||
QVBoxLayout *centralLayout = new QVBoxLayout;
|
||||
centralLayout->setSpacing(0);
|
||||
centralLayout->setMargin(0);
|
||||
@ -39,6 +44,9 @@ PreviewWidget::PreviewWidget(const WId wid, QWidget *parent)
|
||||
setAcceptDrops(true);
|
||||
|
||||
connect(m_closeButton, &QPushButton::clicked, this, &PreviewWidget::closeWindow);
|
||||
connect(m_mouseEnterTimer, &QTimer::timeout, this, &PreviewWidget::showPreview, Qt::QueuedConnection);
|
||||
|
||||
QTimer::singleShot(1, this, &PreviewWidget::refreshImage);
|
||||
}
|
||||
|
||||
void PreviewWidget::setTitle(const QString &title)
|
||||
@ -48,7 +56,7 @@ void PreviewWidget::setTitle(const QString &title)
|
||||
update();
|
||||
}
|
||||
|
||||
void PreviewWidget::refershImage()
|
||||
void PreviewWidget::refreshImage()
|
||||
{
|
||||
const auto display = QX11Info::display();
|
||||
|
||||
@ -83,12 +91,9 @@ void PreviewWidget::closeWindow()
|
||||
XFlush(display);
|
||||
}
|
||||
|
||||
void PreviewWidget::setVisible(const bool visible)
|
||||
void PreviewWidget::showPreview()
|
||||
{
|
||||
QWidget::setVisible(visible);
|
||||
|
||||
if (visible)
|
||||
QTimer::singleShot(1, this, &PreviewWidget::refershImage);
|
||||
emit requestPreviewWindow(m_wid);
|
||||
}
|
||||
|
||||
void PreviewWidget::paintEvent(QPaintEvent *e)
|
||||
@ -133,18 +138,18 @@ void PreviewWidget::enterEvent(QEvent *e)
|
||||
|
||||
m_hovered = true;
|
||||
m_closeButton->setVisible(true);
|
||||
m_mouseEnterTimer->start();
|
||||
|
||||
update();
|
||||
|
||||
QWidget::enterEvent(e);
|
||||
|
||||
emit requestPreviewWindow(m_wid);
|
||||
}
|
||||
|
||||
void PreviewWidget::leaveEvent(QEvent *e)
|
||||
{
|
||||
m_hovered = false;
|
||||
m_closeButton->setVisible(false);
|
||||
m_mouseEnterTimer->stop();
|
||||
|
||||
update();
|
||||
|
||||
|
@ -22,9 +22,9 @@ signals:
|
||||
void requestHidePreview() const;
|
||||
|
||||
private slots:
|
||||
void refershImage();
|
||||
void refreshImage();
|
||||
void closeWindow();
|
||||
void setVisible(const bool visible);
|
||||
void showPreview();
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
@ -43,6 +43,7 @@ private:
|
||||
QPushButton *m_closeButton;
|
||||
|
||||
QTimer *m_droppedDelay;
|
||||
QTimer *m_mouseEnterTimer;
|
||||
|
||||
bool m_hovered;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user