mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
change preview show style
Change-Id: I424e457073e893dcc69469dd736337c0d16538c0
This commit is contained in:
parent
22af83e083
commit
79f1630578
Notes:
Deepin Code Review
2016-06-14 07:19:47 +00:00
Verified+1: Anonymous Coward #1000004 Code-Review+2: <mr.asianwang@gmail.com> Submitted-by: <mr.asianwang@gmail.com> Submitted-at: Thu, 17 Sep 2015 17:03:14 +0800 Reviewed-on: https://cr.deepin.io/7147 Project: dde/dde-dock Branch: refs/heads/master
@ -68,7 +68,8 @@ HEADERS += \
|
||||
src/widgets/reflectioneffect.h \
|
||||
src/widgets/screenmask.h \
|
||||
src/widgets/windowpreview.h \
|
||||
src/mainwidget.h
|
||||
src/mainwidget.h \
|
||||
src/widgets/previewframe.h
|
||||
|
||||
SOURCES += \
|
||||
libs/xcb_misc.cpp \
|
||||
@ -105,4 +106,5 @@ SOURCES += \
|
||||
src/widgets/screenmask.cpp \
|
||||
src/widgets/windowpreview.cpp \
|
||||
src/main.cpp \
|
||||
src/mainwidget.cpp
|
||||
src/mainwidget.cpp \
|
||||
src/widgets/previewframe.cpp
|
||||
|
@ -80,7 +80,6 @@ void DockPluginProxy::appletSizeChangedEvent(QString id)
|
||||
qWarning() << "Applet size changed on plugin " << m_plugin->getPluginName() << id;
|
||||
|
||||
AbstractDockItem * item = m_items.value(id);
|
||||
if (item) {
|
||||
item->resizePreview();
|
||||
}
|
||||
if (item)
|
||||
item->needPreviewUpdate();
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ void PluginItemWrapper::leaveEvent(QEvent *)
|
||||
|
||||
void PluginItemWrapper::mousePressEvent(QMouseEvent * event)
|
||||
{
|
||||
hidePreview(0);
|
||||
hidePreview();
|
||||
|
||||
if (event->button() == Qt::RightButton) {
|
||||
this->showMenu();
|
||||
|
@ -103,12 +103,20 @@ void Panel::initPluginManager()
|
||||
DockPluginManager *pluginManager = new DockPluginManager(this);
|
||||
|
||||
connect(m_dockModeData, &DockModeData::dockModeChanged, pluginManager, &DockPluginManager::onDockModeChanged);
|
||||
connect(pluginManager, &DockPluginManager::itemAppend, m_pluginLayout, &DockLayout::addItem);
|
||||
connect(pluginManager, &DockPluginManager::itemMove, [=](AbstractDockItem *baseItem, AbstractDockItem *targetItem){
|
||||
m_pluginLayout->moveItem(m_pluginLayout->indexOf(targetItem), m_pluginLayout->indexOf(baseItem));
|
||||
});
|
||||
connect(pluginManager, &DockPluginManager::itemAppend, [=](AbstractDockItem *targetItem){
|
||||
m_pluginLayout->addItem(targetItem);
|
||||
connect(targetItem, &AbstractDockItem::needPreviewShow, this, &Panel::onNeedPreviewShow);
|
||||
connect(targetItem, &AbstractDockItem::needPreviewHide, this, &Panel::onNeedPreviewHide);
|
||||
connect(targetItem, &AbstractDockItem::needPreviewUpdate, m_globalPreview, &PreviewFrame::resizeWithContent);
|
||||
});
|
||||
connect(pluginManager, &DockPluginManager::itemInsert, [=](AbstractDockItem *baseItem, AbstractDockItem *targetItem){
|
||||
m_pluginLayout->insertItem(targetItem, m_pluginLayout->indexOf(baseItem));
|
||||
connect(targetItem, &AbstractDockItem::needPreviewShow, this, &Panel::onNeedPreviewShow);
|
||||
connect(targetItem, &AbstractDockItem::needPreviewHide, this, &Panel::onNeedPreviewHide);
|
||||
connect(targetItem, &AbstractDockItem::needPreviewUpdate, m_globalPreview, &PreviewFrame::resizeWithContent);
|
||||
});
|
||||
connect(pluginManager, &DockPluginManager::itemRemoved, [=](AbstractDockItem* item) {
|
||||
m_pluginLayout->removeItem(item);
|
||||
@ -232,6 +240,9 @@ void Panel::onLayoutContentsWidthChanged()
|
||||
void Panel::onAppItemAdd(AbstractDockItem *item)
|
||||
{
|
||||
m_appLayout->addItem(item);
|
||||
connect(item, &AbstractDockItem::needPreviewShow, this, &Panel::onNeedPreviewShow);
|
||||
connect(item, &AbstractDockItem::needPreviewHide, this, &Panel::onNeedPreviewHide);
|
||||
connect(item, &AbstractDockItem::needPreviewUpdate, m_globalPreview, &PreviewFrame::resizeWithContent);
|
||||
}
|
||||
|
||||
void Panel::onAppItemRemove(const QString &id)
|
||||
@ -281,6 +292,21 @@ void Panel::onHidePanelFinished()
|
||||
emit panelHasHidden();
|
||||
}
|
||||
|
||||
void Panel::onNeedPreviewHide()
|
||||
{
|
||||
m_globalPreview->hidePreview(DELAY_HIDE_PREVIEW_INTERVAL);
|
||||
}
|
||||
|
||||
void Panel::onNeedPreviewShow(QPoint pos)
|
||||
{
|
||||
AbstractDockItem *item = qobject_cast<AbstractDockItem *>(sender());
|
||||
if (item && item->getApplet()) {
|
||||
m_globalPreview->setArrowX(-1);//reset x to move arrow to horizontal-center
|
||||
m_globalPreview->setContent(item->getApplet());
|
||||
m_globalPreview->showPreview(PreviewFrame::ArrowBottom, pos.x(), pos.y(), DELAY_SHOW_PREVIEW_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
void Panel::reanchorsLayout(Dock::DockMode mode)
|
||||
{
|
||||
if (mode == Dock::FashionMode)
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "widgets/appitem.h"
|
||||
#include "widgets/docklayout.h"
|
||||
#include "widgets/screenmask.h"
|
||||
#include "widgets/previewframe.h"
|
||||
#include "widgets/reflectioneffect.h"
|
||||
#include "panelmenu.h"
|
||||
|
||||
@ -60,6 +61,8 @@ private:
|
||||
void onHideStateChanged(int dockState);
|
||||
void onShowPanelFinished();
|
||||
void onHidePanelFinished();
|
||||
void onNeedPreviewHide();
|
||||
void onNeedPreviewShow(QPoint pos);
|
||||
|
||||
void reanchorsLayout(Dock::DockMode mode);
|
||||
void updateRightReflection();
|
||||
@ -71,6 +74,7 @@ private:
|
||||
void setY(int value); //for hide and show animation
|
||||
|
||||
private:
|
||||
PreviewFrame *m_globalPreview = new PreviewFrame;
|
||||
DockModeData *m_dockModeData = DockModeData::instance();
|
||||
QPropertyAnimation *m_widthAnimation = NULL;
|
||||
DBusHideStateManager *m_HSManager = NULL;
|
||||
@ -90,6 +94,8 @@ private:
|
||||
const int FASHION_PANEL_RPADDING = 21;
|
||||
const int WIDTH_ANIMATION_DURATION = 200;
|
||||
const int SHOW_HIDE_ANIMATION_DURATION = 200;
|
||||
const int DELAY_HIDE_PREVIEW_INTERVAL = 200;
|
||||
const int DELAY_SHOW_PREVIEW_INTERVAL = 200;
|
||||
const QEasingCurve SHOW_HIDE_EASINGCURVE = QEasingCurve::InSine;
|
||||
};
|
||||
|
||||
|
@ -25,9 +25,7 @@ AbstractDockItem::AbstractDockItem(QWidget * parent) :
|
||||
{
|
||||
|
||||
this->setAttribute(Qt::WA_TranslucentBackground);
|
||||
m_previewAR = new PreviewArrowRectangle();
|
||||
|
||||
connect(m_previewAR, &PreviewArrowRectangle::hideFinish, this, &AbstractDockItem::previewHidden);
|
||||
m_titlePreview = new PreviewFrame;
|
||||
}
|
||||
|
||||
AbstractDockItem::~AbstractDockItem()
|
||||
@ -127,59 +125,44 @@ QPoint AbstractDockItem::globalPos()
|
||||
|
||||
void AbstractDockItem::showPreview()
|
||||
{
|
||||
if (!m_previewAR->isHidden())
|
||||
if (!m_titlePreview->isHidden())
|
||||
{
|
||||
m_previewAR->resizeWithContent();
|
||||
m_titlePreview->resizeWithContent();
|
||||
return;
|
||||
}
|
||||
|
||||
QWidget *tmpContent = getApplet();
|
||||
|
||||
if (tmpContent == NULL) {
|
||||
m_previewPos = QPoint(globalX() + width() / 2, globalY() - 5);
|
||||
if (getApplet() == NULL) {
|
||||
QString title = getTitle();
|
||||
|
||||
if (!title.isEmpty()) {
|
||||
m_titleLabel->setTitle(title);
|
||||
|
||||
tmpContent = m_titleLabel;
|
||||
m_titlePreview->setContent(m_titleLabel);
|
||||
m_titlePreview->showPreview(ArrowRectangle::ArrowBottom,
|
||||
globalX() + width() / 2,
|
||||
globalY() - 5,
|
||||
0);
|
||||
}
|
||||
}
|
||||
|
||||
if (tmpContent) {
|
||||
else {
|
||||
m_titleLabel->setParent(NULL);
|
||||
m_previewAR->setContent(tmpContent);
|
||||
m_previewAR->showPreview(ArrowRectangle::ArrowBottom,
|
||||
globalX() + width() / 2,
|
||||
globalY() - 5);
|
||||
m_previewPos = QPoint(globalX() + width() / 2,globalY() - 5);
|
||||
|
||||
emit needPreviewShow(m_previewPos);
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractDockItem::hidePreview(int interval)
|
||||
void AbstractDockItem::hidePreview()
|
||||
{
|
||||
m_previewAR->hidePreview(interval);
|
||||
}
|
||||
m_titlePreview->hidePreview();
|
||||
|
||||
void AbstractDockItem::cancelHide()
|
||||
{
|
||||
m_previewAR->showPreview(ArrowRectangle::ArrowBottom, m_previewPos.x(), m_previewPos.y());
|
||||
}
|
||||
|
||||
void AbstractDockItem::resizePreview()
|
||||
{
|
||||
m_previewAR->resizeWithContent();
|
||||
if (!m_previewAR->isHidden())
|
||||
{
|
||||
m_previewAR->resizeWithContent();
|
||||
return;
|
||||
}
|
||||
emit needPreviewHide();
|
||||
}
|
||||
|
||||
void AbstractDockItem::showMenu()
|
||||
{
|
||||
if (getMenuContent().isEmpty()) return;
|
||||
|
||||
hidePreview(0);
|
||||
hidePreview();
|
||||
|
||||
if (m_dbusMenuManager == NULL) {
|
||||
m_dbusMenuManager = new DBusMenuManager(this);
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "dbus/dbusmenu.h"
|
||||
#include "previewframe.h"
|
||||
#include "highlighteffect.h"
|
||||
#include "dbus/dbusmenumanager.h"
|
||||
#include "previewarrowrectangle.h"
|
||||
@ -47,10 +48,8 @@ public:
|
||||
void resize(const QSize &size);
|
||||
void resize(int width,int height);
|
||||
void showMenu();
|
||||
void cancelHide();
|
||||
void showPreview();
|
||||
void resizePreview();
|
||||
void hidePreview(int interval = 150);
|
||||
void hidePreview();
|
||||
void setParent(QWidget * parent);
|
||||
|
||||
int globalX();
|
||||
@ -69,13 +68,15 @@ signals:
|
||||
void widthChanged();
|
||||
void posChanged();
|
||||
void frameUpdate();
|
||||
void previewHidden();
|
||||
void moveAnimationFinished();
|
||||
void needPreviewHide();
|
||||
void needPreviewShow(QPoint pos);
|
||||
void needPreviewUpdate();
|
||||
|
||||
protected:
|
||||
bool m_moveable = true;
|
||||
bool m_isActived = false;
|
||||
PreviewArrowRectangle *m_previewAR = NULL;
|
||||
PreviewFrame *m_titlePreview = NULL;
|
||||
HighlightEffect * m_highlight = NULL;
|
||||
ItemTitleLabel *m_titleLabel = NULL;
|
||||
|
||||
@ -90,6 +91,8 @@ protected:
|
||||
|
||||
private:
|
||||
const int TITLE_HEIGHT = 20;
|
||||
const int CONTENT_PREVIEW_INTERVAL = 200;
|
||||
const int TITLE_PREVIEW_INTERVAL = 0;
|
||||
};
|
||||
|
||||
#endif // ABSTRACTDOCKITEM_H
|
||||
|
@ -184,8 +184,7 @@ void AppItem::initPreview()
|
||||
{
|
||||
m_preview = new AppPreviews();
|
||||
connect(m_preview,&AppPreviews::requestHide, [=]{hidePreview();});
|
||||
connect(m_preview,&AppPreviews::sizeChanged, this, &AppItem::resizePreview);
|
||||
connect(this, &AppItem::previewHidden, m_preview, &AppPreviews::clearUpPreview);
|
||||
connect(m_preview,&AppPreviews::sizeChanged, this, &AppItem::needPreviewUpdate);
|
||||
}
|
||||
|
||||
void AppItem::initAppIcon()
|
||||
@ -289,7 +288,7 @@ void AppItem::onMousePress(QMouseEvent *event)
|
||||
{
|
||||
//qWarning() << "mouse press...";
|
||||
emit mousePress(event);
|
||||
hidePreview(0);
|
||||
hidePreview();
|
||||
}
|
||||
|
||||
void AppItem::onMouseRelease(QMouseEvent *event)
|
||||
|
@ -22,12 +22,14 @@ void ArrowRectangle::show(ArrowDirection direction, int x, int y)
|
||||
void ArrowRectangle::setContent(QWidget *content)
|
||||
{
|
||||
if (!content)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_content)
|
||||
m_content->setParent(NULL);
|
||||
|
||||
m_content = content;
|
||||
m_content->setParent(this);
|
||||
m_content->show();
|
||||
|
||||
resizeWithContent();
|
||||
switch(arrowDirection)
|
||||
@ -244,12 +246,7 @@ void ArrowRectangle::setArrowWidth(int value)
|
||||
|
||||
void ArrowRectangle::setArrowX(int value)
|
||||
{
|
||||
if (value < arrowWidth / 2)
|
||||
this->m_arrowX = arrowWidth / 2;
|
||||
else if (value > (width() - arrowWidth / 2))
|
||||
this->m_arrowX = width() - arrowWidth / 2;
|
||||
else
|
||||
this->m_arrowX = value;
|
||||
this->m_arrowX = value;
|
||||
}
|
||||
|
||||
void ArrowRectangle::setArrowY(int value)
|
||||
|
@ -50,7 +50,7 @@ void LauncherItem::slotMousePress(QMouseEvent *event)
|
||||
{
|
||||
emit mousePress(event);
|
||||
|
||||
hidePreview(0);
|
||||
hidePreview();
|
||||
}
|
||||
|
||||
void LauncherItem::slotMouseRelease(QMouseEvent *event)
|
||||
|
84
dde-dock/src/widgets/previewframe.cpp
Normal file
84
dde-dock/src/widgets/previewframe.cpp
Normal file
@ -0,0 +1,84 @@
|
||||
#include "previewframe.h"
|
||||
|
||||
PreviewFrame::PreviewFrame(QWidget *parent) : ArrowRectangle(parent)
|
||||
{
|
||||
m_showTimer = new QTimer(this);
|
||||
m_showTimer->setSingleShot(true);
|
||||
connect(m_showTimer, &QTimer::timeout, this, &PreviewFrame::onShowTimerTriggered);
|
||||
|
||||
m_hideTimer = new QTimer(this);
|
||||
m_hideTimer->setSingleShot(true);
|
||||
connect(m_hideTimer, &QTimer::timeout, this, &PreviewFrame::hide);
|
||||
|
||||
m_animation = new QPropertyAnimation(this, "arrowPos");
|
||||
m_animation->setDuration(MOVE_ANIMATION_DURATION);
|
||||
m_animation->setEasingCurve(MOVE_ANIMATION_CURVE);
|
||||
}
|
||||
|
||||
PreviewFrame::~PreviewFrame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PreviewFrame::showPreview(ArrowRectangle::ArrowDirection direction, int x, int y, int interval)
|
||||
{
|
||||
m_hideTimer->stop();
|
||||
|
||||
if (m_showTimer->isActive())
|
||||
return;
|
||||
|
||||
m_direction = direction;
|
||||
m_lastPos = QPoint(m_x, m_y);
|
||||
m_x = x;
|
||||
m_y = y;
|
||||
|
||||
m_showTimer->start(interval);
|
||||
}
|
||||
|
||||
void PreviewFrame::hidePreview(int interval)
|
||||
{
|
||||
m_showTimer->stop();
|
||||
|
||||
m_hideTimer->start(interval);
|
||||
}
|
||||
|
||||
void PreviewFrame::setContent(QWidget *content)
|
||||
{
|
||||
m_tmpContent = content;
|
||||
}
|
||||
|
||||
void PreviewFrame::setArrowPos(const QPoint &pos)
|
||||
{
|
||||
show(m_direction, pos.x(), pos.y());
|
||||
}
|
||||
|
||||
void PreviewFrame::enterEvent(QEvent *)
|
||||
{
|
||||
m_hideTimer->stop();
|
||||
}
|
||||
|
||||
void PreviewFrame::leaveEvent(QEvent *)
|
||||
{
|
||||
m_hideTimer->start();
|
||||
}
|
||||
|
||||
void PreviewFrame::onShowTimerTriggered()
|
||||
{
|
||||
ArrowRectangle::setContent(m_tmpContent);
|
||||
|
||||
if (isHidden())
|
||||
show(m_direction, m_x, m_y);
|
||||
else{
|
||||
m_animation->setStartValue(m_lastPos);
|
||||
m_animation->setEndValue(QPoint(m_x, m_y));
|
||||
m_animation->start();
|
||||
}
|
||||
}
|
||||
|
||||
void PreviewFrame::onHideTimerTriggered()
|
||||
{
|
||||
hide();
|
||||
|
||||
emit hideFinish();
|
||||
}
|
||||
|
45
dde-dock/src/widgets/previewframe.h
Normal file
45
dde-dock/src/widgets/previewframe.h
Normal file
@ -0,0 +1,45 @@
|
||||
#ifndef PREVIEWFRAME_H
|
||||
#define PREVIEWFRAME_H
|
||||
|
||||
#include <QTimer>
|
||||
#include <QPropertyAnimation>
|
||||
#include "arrowrectangle.h"
|
||||
|
||||
class PreviewFrame : public ArrowRectangle
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QPoint arrowPos READ QPoint(0, 0) WRITE setArrowPos)
|
||||
public:
|
||||
explicit PreviewFrame(QWidget *parent = 0);
|
||||
~PreviewFrame();
|
||||
|
||||
void showPreview(ArrowDirection direction, int x, int y, int interval);
|
||||
void hidePreview(int interval = 0);
|
||||
void setContent(QWidget *content);
|
||||
void setArrowPos(const QPoint &pos);
|
||||
|
||||
signals:
|
||||
void hideFinish();
|
||||
|
||||
protected:
|
||||
void enterEvent(QEvent *);
|
||||
void leaveEvent(QEvent *);
|
||||
|
||||
private:
|
||||
void onShowTimerTriggered();
|
||||
void onHideTimerTriggered();
|
||||
|
||||
private:
|
||||
QTimer *m_showTimer = NULL;
|
||||
QTimer *m_hideTimer = NULL;
|
||||
QWidget *m_tmpContent = NULL;
|
||||
QPropertyAnimation *m_animation = NULL;
|
||||
ArrowDirection m_direction = ArrowBottom;
|
||||
QPoint m_lastPos = QPoint(0, 0);
|
||||
int m_x = 0;
|
||||
int m_y = 0;
|
||||
const int MOVE_ANIMATION_DURATION = 300;
|
||||
const QEasingCurve MOVE_ANIMATION_CURVE = QEasingCurve::OutCirc;
|
||||
};
|
||||
|
||||
#endif // PREVIEWFRAME_H
|
Loading…
x
Reference in New Issue
Block a user