mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-03 00:15:21 +00:00
add preview widget
Change-Id: Ibf9df14c26acf58e14fc90e7f1bcc51c2186b227
This commit is contained in:
parent
1f5052cf53
commit
3595af6faa
Notes:
Deepin Code Review
2017-03-28 17:05:03 +08:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Tue, 28 Mar 2017 17:05:02 +0800 Reviewed-on: https://cr.deepin.io/21887 Project: dde/dde-dock Branch: refs/heads/master
@ -178,7 +178,13 @@ DockItemController::DockItemController(QObject *parent)
|
||||
|
||||
m_itemList.append(new LauncherItem);
|
||||
for (auto entry : m_appInter->entries())
|
||||
m_itemList.append(new AppItem(entry));
|
||||
{
|
||||
AppItem *it = new AppItem(entry);
|
||||
|
||||
connect(it, &AppItem::requestActivateWindow, m_appInter, &DBusDock::ActivateWindow);
|
||||
|
||||
m_itemList.append(it);
|
||||
}
|
||||
m_itemList.append(m_placeholderItem);
|
||||
m_itemList.append(m_containerItem);
|
||||
|
||||
@ -211,6 +217,9 @@ void DockItemController::appItemAdded(const QDBusObjectPath &path, const int ind
|
||||
}
|
||||
|
||||
AppItem *item = new AppItem(path);
|
||||
|
||||
connect(item, &AppItem::requestActivateWindow, m_appInter, &DBusDock::ActivateWindow);
|
||||
|
||||
m_itemList.insert(insertIndex, item);
|
||||
emit itemInserted(insertIndex, item);
|
||||
}
|
||||
|
@ -37,7 +37,8 @@ SOURCES += main.cpp \
|
||||
item/containeritem.cpp \
|
||||
item/components/containerwidget.cpp \
|
||||
dbus/dbusdockadaptors.cpp \
|
||||
item/components/previewcontainer.cpp
|
||||
item/components/previewcontainer.cpp \
|
||||
item/components/previewwidget.cpp
|
||||
|
||||
HEADERS += \
|
||||
window/mainwindow.h \
|
||||
@ -66,7 +67,8 @@ HEADERS += \
|
||||
item/containeritem.h \
|
||||
item/components/containerwidget.h \
|
||||
dbus/dbusdockadaptors.h \
|
||||
item/components/previewcontainer.h
|
||||
item/components/previewcontainer.h \
|
||||
item/components/previewwidget.h
|
||||
|
||||
dbus_service.files += com.deepin.dde.Dock.service
|
||||
dbus_service.path = /usr/share/dbus-1/services
|
||||
|
@ -4,11 +4,10 @@
|
||||
#include "util/imagefactory.h"
|
||||
#include "xcb/xcb_misc.h"
|
||||
|
||||
#include <dapplication.h>
|
||||
|
||||
#include <QPainter>
|
||||
#include <QDrag>
|
||||
#include <QMouseEvent>
|
||||
#include <QApplication>
|
||||
|
||||
#define APP_DRAG_THRESHOLD 20
|
||||
|
||||
@ -51,6 +50,8 @@ AppItem::AppItem(const QDBusObjectPath &entry, QWidget *parent)
|
||||
connect(m_itemEntry, &DBusDockEntry::IconChanged, this, &AppItem::refershIcon);
|
||||
connect(m_itemEntry, &DBusDockEntry::ActiveChanged, this, static_cast<void (AppItem::*)()>(&AppItem::update));
|
||||
|
||||
connect(m_appPreviewTips, &PreviewContainer::requestActivateWindow, this, &AppItem::requestActivateWindow);
|
||||
|
||||
connect(m_updateIconGeometryTimer, &QTimer::timeout, this, &AppItem::updateWindowIconGeometries);
|
||||
|
||||
updateTitle();
|
||||
@ -244,19 +245,19 @@ void AppItem::mouseReleaseEvent(QMouseEvent *e)
|
||||
if (e->button() == Qt::MiddleButton) {
|
||||
m_itemEntry->NewInstance();
|
||||
} else if (e->button() == Qt::LeftButton) {
|
||||
const QPoint distance = MousePressPos - e->pos();
|
||||
if (distance.manhattanLength() > APP_DRAG_THRESHOLD)
|
||||
return;
|
||||
// const QPoint distance = MousePressPos - e->pos();
|
||||
// if (distance.manhattanLength() > APP_DRAG_THRESHOLD)
|
||||
// return;
|
||||
|
||||
#ifdef QT_DEBUG
|
||||
//#ifdef QT_DEBUG
|
||||
const int windowCount = m_titles.size();
|
||||
if (windowCount < 2)
|
||||
m_itemEntry->Activate();
|
||||
else
|
||||
showPreview();
|
||||
#else
|
||||
m_itemEntry->Activate();
|
||||
#endif
|
||||
togglePreview();
|
||||
//#else
|
||||
// m_itemEntry->Activate();
|
||||
//#endif
|
||||
|
||||
// if (!m_titles.isEmpty())
|
||||
// return;
|
||||
@ -271,7 +272,7 @@ void AppItem::mouseReleaseEvent(QMouseEvent *e)
|
||||
void AppItem::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
m_updateIconGeometryTimer->stop();
|
||||
hidePopup();
|
||||
// hidePopup();
|
||||
|
||||
if (e->button() == Qt::RightButton)
|
||||
{
|
||||
@ -423,9 +424,15 @@ void AppItem::activeChanged()
|
||||
m_active = !m_active;
|
||||
}
|
||||
|
||||
void AppItem::showPreview()
|
||||
void AppItem::togglePreview()
|
||||
{
|
||||
if (PopupWindow->isVisible())
|
||||
return hidePopup();
|
||||
|
||||
m_appPreviewTips->updateLayoutDirection(DockPosition);
|
||||
m_appPreviewTips->setWindowInfos(m_titles);
|
||||
|
||||
QTimer::singleShot(100, this, [=] { showPopupApplet(m_appPreviewTips); });
|
||||
qApp->processEvents();
|
||||
|
||||
showPopupApplet(m_appPreviewTips);
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ public:
|
||||
|
||||
inline ItemType itemType() const {return App;}
|
||||
|
||||
signals:
|
||||
void requestActivateWindow(const WId wid) const;
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
@ -42,7 +45,7 @@ private slots:
|
||||
void updateTitle();
|
||||
void refershIcon();
|
||||
void activeChanged();
|
||||
void showPreview();
|
||||
void togglePreview();
|
||||
|
||||
private:
|
||||
QLabel *m_appNameTips;
|
||||
|
@ -1,12 +1,8 @@
|
||||
#include "previewcontainer.h"
|
||||
#include "previewwidget.h"
|
||||
|
||||
#include <QLabel>
|
||||
#include <QWindow>
|
||||
#include <QX11Info>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
PreviewContainer::PreviewContainer(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
@ -29,16 +25,11 @@ void PreviewContainer::setWindowInfos(const WindowDict &infos)
|
||||
|
||||
for (auto it(infos.cbegin()); it != infos.cend(); ++it)
|
||||
{
|
||||
XWindowAttributes attrs;
|
||||
XGetWindowAttributes(QX11Info::display(), it.key(), &attrs);
|
||||
XImage *ximage = XGetImage(QX11Info::display(), it.key(), 0, 0, attrs.width, attrs.height, AllPlanes, ZPixmap);
|
||||
const QImage qimage((uchar*)(ximage->data), attrs.width, attrs.height, QImage::Format_ARGB32);
|
||||
XDestroyImage(ximage);
|
||||
PreviewWidget *w = new PreviewWidget(it.key());
|
||||
|
||||
QLabel *l = new QLabel;
|
||||
l->setFixedSize(250, 200);
|
||||
l->setPixmap(QPixmap::fromImage(qimage).scaled(250, 200, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
||||
m_windowListLayout->addWidget(l);
|
||||
connect(w, &PreviewWidget::requestActivateWindow, this, &PreviewContainer::requestActivateWindow);
|
||||
|
||||
m_windowListLayout->addWidget(w);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,9 @@ class PreviewContainer : public QWidget
|
||||
public:
|
||||
explicit PreviewContainer(QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
void requestActivateWindow(const WId wid) const;
|
||||
|
||||
public:
|
||||
void setWindowInfos(const WindowDict &infos);
|
||||
|
||||
|
51
frame/item/components/previewwidget.cpp
Normal file
51
frame/item/components/previewwidget.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
#include "previewwidget.h"
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/X.h>
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
#include <QX11Info>
|
||||
|
||||
#include <QPainter>
|
||||
#include <QTimer>
|
||||
|
||||
#define W 250
|
||||
#define H 200
|
||||
|
||||
PreviewWidget::PreviewWidget(const WId wid, QWidget *parent)
|
||||
: QWidget(parent),
|
||||
|
||||
m_wid(wid)
|
||||
{
|
||||
setFixedSize(W, H);
|
||||
|
||||
QTimer::singleShot(1, this, &PreviewWidget::refershImage);
|
||||
}
|
||||
|
||||
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((uchar*)(ximage->data), attrs.width, attrs.height, QImage::Format_ARGB32);
|
||||
XDestroyImage(ximage);
|
||||
|
||||
m_pixmap = QPixmap::fromImage(qimage).scaled(W, H, Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void PreviewWidget::paintEvent(QPaintEvent *e)
|
||||
{
|
||||
QWidget::paintEvent(e);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.drawPixmap(rect().center() - m_pixmap.rect().center(), m_pixmap);
|
||||
}
|
||||
|
||||
void PreviewWidget::mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
QWidget::mouseReleaseEvent(e);
|
||||
|
||||
emit requestActivateWindow(m_wid);
|
||||
}
|
27
frame/item/components/previewwidget.h
Normal file
27
frame/item/components/previewwidget.h
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef PREVIEWWIDGET_H
|
||||
#define PREVIEWWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class PreviewWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PreviewWidget(const WId wid, QWidget *parent = 0);
|
||||
|
||||
signals:
|
||||
void requestActivateWindow(const WId wid) const;
|
||||
|
||||
private slots:
|
||||
void refershImage();
|
||||
|
||||
private:
|
||||
void paintEvent(QPaintEvent *e);
|
||||
void mouseReleaseEvent(QMouseEvent *e);
|
||||
|
||||
private:
|
||||
const WId m_wid;
|
||||
QPixmap m_pixmap;
|
||||
};
|
||||
|
||||
#endif // PREVIEWWIDGET_H
|
@ -129,7 +129,9 @@ bool DockPopupWindow::eventFilter(QObject *o, QEvent *e)
|
||||
|
||||
void DockPopupWindow::globalMouseRelease(int button, int x, int y, const QString &id)
|
||||
{
|
||||
Q_UNUSED(button);
|
||||
// button_left
|
||||
if (button != 1)
|
||||
return;
|
||||
|
||||
if (id != m_mouseAreaKey)
|
||||
return;
|
||||
@ -149,11 +151,13 @@ void DockPopupWindow::globalMouseRelease(int button, int x, int y, const QString
|
||||
|
||||
void DockPopupWindow::registerMouseEvent()
|
||||
{
|
||||
if (!m_mouseAreaKey.isEmpty())
|
||||
return;
|
||||
|
||||
// only regist mouse button event
|
||||
m_mouseAreaKey = m_mouseInter->RegisterArea(0, 0, m_displayInter->screenWidth(), m_displayInter->screenHeight(), MOUSE_BUTTON);
|
||||
// m_mouseAreaKey = m_mouseInter->RegisterFullScreen();
|
||||
|
||||
connect(m_mouseInter, &DBusXMouseArea::ButtonRelease, this, &DockPopupWindow::globalMouseRelease, Qt::UniqueConnection);
|
||||
connect(m_mouseInter, &DBusXMouseArea::ButtonRelease, this, &DockPopupWindow::globalMouseRelease, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void DockPopupWindow::unRegisterMouseEvent()
|
||||
@ -163,6 +167,6 @@ void DockPopupWindow::unRegisterMouseEvent()
|
||||
|
||||
disconnect(m_mouseInter, &DBusXMouseArea::ButtonRelease, this, &DockPopupWindow::globalMouseRelease);
|
||||
|
||||
m_mouseInter->UnregisterArea(m_mouseAreaKey).waitForFinished();
|
||||
m_mouseInter->UnregisterArea(m_mouseAreaKey);
|
||||
m_mouseAreaKey.clear();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user