use DArrowRectangle for preview to show gloweffect

Change-Id: I7ccf195a588b80edc84bb4983902fcee1b0fb318
This commit is contained in:
杨万青 2015-09-23 15:01:20 +08:00 committed by yangwanqing
parent ad377421a6
commit 047f069cef
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: Wed, 23 Sep 2015 15:33:40 +0800
Reviewed-on: https://cr.deepin.io/7304
Project: dde/dde-dock
Branch: refs/heads/master
12 changed files with 24 additions and 773 deletions

View File

@ -58,13 +58,11 @@ HEADERS += \
src/widgets/appicon.h \
src/widgets/appitem.h \
src/widgets/apppreviews.h \
src/widgets/arrowrectangle.h \
src/widgets/docklayout.h \
src/widgets/dockmodel.h \
src/widgets/dockview.h \
src/widgets/highlighteffect.h \
src/widgets/launcheritem.h \
src/widgets/previewarrowrectangle.h \
src/widgets/reflectioneffect.h \
src/widgets/screenmask.h \
src/widgets/windowpreview.h \
@ -95,13 +93,11 @@ SOURCES += \
src/widgets/appicon.cpp \
src/widgets/appitem.cpp \
src/widgets/apppreviews.cpp \
src/widgets/arrowrectangle.cpp \
src/widgets/docklayout.cpp \
src/widgets/dockmodel.cpp \
src/widgets/dockview.cpp \
src/widgets/highlighteffect.cpp \
src/widgets/launcheritem.cpp \
src/widgets/previewarrowrectangle.cpp \
src/widgets/reflectioneffect.cpp \
src/widgets/screenmask.cpp \
src/widgets/windowpreview.cpp \

View File

@ -308,7 +308,7 @@ void Panel::onNeedPreviewShow(QPoint pos)
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);
m_globalPreview->showPreview(pos.x(), pos.y() + 10, DELAY_SHOW_PREVIEW_INTERVAL);
}
}

View File

@ -75,7 +75,7 @@ private:
void setY(int value); //for hide and show animation
private:
PreviewFrame *m_globalPreview = new PreviewFrame;
PreviewFrame *m_globalPreview = new PreviewFrame(DArrowRectangle::ArrowBottom);
DBusDockedAppManager *m_ddam = new DBusDockedAppManager(this);
DockModeData *m_dockModeData = DockModeData::instance();
QPropertyAnimation *m_widthAnimation = NULL;

View File

@ -25,7 +25,7 @@ AbstractDockItem::AbstractDockItem(QWidget * parent) :
{
this->setAttribute(Qt::WA_TranslucentBackground);
m_titlePreview = new PreviewFrame;
m_titlePreview = new PreviewFrame(DArrowRectangle::ArrowBottom);
}
AbstractDockItem::~AbstractDockItem()
@ -137,10 +137,10 @@ void AbstractDockItem::showPreview()
if (!title.isEmpty()) {
m_titleLabel->setTitle(title);
m_titlePreview->setArrowX(-1); //reset position
m_titlePreview->setContent(m_titleLabel);
m_titlePreview->showPreview(ArrowRectangle::ArrowBottom,
globalX() + width() / 2,
globalY() - 5,
m_titlePreview->showPreview(globalX() + width() / 2,
globalY() + 18,
0);
}
}

View File

@ -13,8 +13,6 @@
#include "previewframe.h"
#include "highlighteffect.h"
#include "dbus/dbusmenumanager.h"
#include "previewarrowrectangle.h"
#include "widgets/arrowrectangle.h"
#include "interfaces/dockconstants.h"
class ItemTitleLabel : public QLabel

View File

@ -1,391 +0,0 @@
#include "arrowrectangle.h"
ArrowRectangle::ArrowRectangle(QWidget * parent) :
QWidget(parent)
{
setWindowFlags(Qt::SplashScreen);
setAttribute(Qt::WA_TranslucentBackground);
}
void ArrowRectangle::show(ArrowDirection direction, int x, int y)
{
m_lastPos = QPoint(x, y);
setArrorDirection(direction);
move(x,y);//Overload function
if (isHidden())
QWidget::show();
resizeWithContent();
repaint();
}
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)
{
case ArrowLeft:
m_content->move(arrowHeight + m_margin,m_margin);
break;
case ArrowRight:
m_content->move(m_margin,m_margin);
break;
case ArrowTop:
m_content->move(m_margin,m_margin + arrowHeight);
break;
case ArrowBottom:
m_content->move(m_margin,m_margin);
break;
}
}
void ArrowRectangle::resizeWithContent()
{
setFixedSize(getFixedSize());
move(m_lastPos.x(), m_lastPos.y());
repaint();
}
QSize ArrowRectangle::getFixedSize()
{
if (m_content)
{
switch(arrowDirection)
{
case ArrowLeft:
case ArrowRight:
return QSize(m_content->width() + m_margin * 2 + arrowHeight,m_content->height() + m_margin * 2);
case ArrowTop:
case ArrowBottom:
return QSize(m_content->width() + m_margin * 2,m_content->height() + m_margin * 2 + arrowHeight);
}
}
else
return QSize(0, 0);
}
void ArrowRectangle::move(int x, int y)
{
QDesktopWidget dw;
QRect rec = dw.screenGeometry();
int xLeftValue = x - width() / 2;
int xRightValue = x + width() / 2 - rec.width();
int yTopValue = y - height() / 2;
int yBottomValue = y + height() / 2 - rec.height();
switch (arrowDirection)
{
case ArrowLeft:
if (yTopValue < rec.y())
{
setArrowY(height() / 2 + yTopValue);
yTopValue = rec.y();
}
else if (yBottomValue > 0)
{
setArrowY(height() / 2 + yBottomValue);
yTopValue = rec.height() - height();
}
QWidget::move(x,yTopValue);
break;
case ArrowRight:
if (yTopValue < rec.y())
{
setArrowY(height() / 2 + yTopValue);
yTopValue = rec.y();
}
else if (yBottomValue > 0)
{
setArrowY(height() / 2 + yBottomValue);
yTopValue = rec.height() - height();
}
QWidget::move(x - width(),yTopValue);
break;
case ArrowTop:
if (xLeftValue < rec.x())//out of screen in left side
{
setArrowX(width() / 2 + xLeftValue);
xLeftValue = rec.x();
}
else if(xRightValue > 0)//out of screen in right side
{
setArrowX(width() / 2 + xRightValue);
xLeftValue = rec.width() - width();
}
QWidget::move(xLeftValue,y);
break;
case ArrowBottom:
if (xLeftValue < rec.x())//out of screen in left side
{
setArrowX(width() / 2 + xLeftValue);
xLeftValue = rec.x();
}
else if(xRightValue > 0)//out of screen in right side
{
setArrowX(width() / 2 + xRightValue);
xLeftValue = rec.width() - width();
}
QWidget::move(xLeftValue,y - height());
break;
default:
QWidget::move(x,y);
break;
}
}
// override methods
void ArrowRectangle::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
QPainterPath border;
switch (arrowDirection)
{
case ArrowRectangle::ArrowLeft:
border = getLeftCornerPath();
break;
case ArrowRectangle::ArrowRight:
border = getRightCornerPath();
break;
case ArrowRectangle::ArrowTop:
border = getTopCornerPath();
break;
case ArrowRectangle::ArrowBottom:
border = getBottomCornerPath();
break;
default:
border = getRightCornerPath();
}
QPen strokePen;
strokePen.setColor(strokeColor);
strokePen.setWidth(strokeWidth);
painter.strokePath(border, strokePen);
painter.fillPath(border, QBrush(backgroundColor == "" ? QColor(0,0,0,200) : QColor(backgroundColor)));
}
int ArrowRectangle::getRadius() const
{
return this->radius;
}
int ArrowRectangle::getArrowHeight() const
{
return this->arrowHeight;
}
int ArrowRectangle::getArrowWidth() const
{
return this->arrowWidth;
}
int ArrowRectangle::getArrowX() const
{
return this->m_arrowX;
}
int ArrowRectangle::getArrowY() const
{
return this->m_arrowY;
}
int ArrowRectangle::getMargin() const
{
return this->m_margin;
}
QString ArrowRectangle::getBackgroundColor()
{
return this->backgroundColor;
}
void ArrowRectangle::setArrorDirection(ArrowDirection value)
{
arrowDirection = value;
}
void ArrowRectangle::setWidth(int value)
{
this->setMinimumWidth(value);
this->setMaximumWidth(value);
}
void ArrowRectangle::setHeight(int value)
{
this->setMinimumHeight(value);
this->setMaximumHeight(value);
}
void ArrowRectangle::setRadius(int value)
{
this->radius = value;
}
void ArrowRectangle::setArrowHeight(int value)
{
this->arrowHeight = value;
}
void ArrowRectangle::setArrowWidth(int value)
{
this->arrowWidth = value;
}
void ArrowRectangle::setArrowX(int value)
{
this->m_arrowX = value;
}
void ArrowRectangle::setArrowY(int value)
{
if (value < arrowWidth / 2)
this->m_arrowY = arrowWidth / 2;
else if (value > (height() - arrowWidth / 2))
this->m_arrowY = height() - arrowWidth / 2;
else
this->m_arrowY = value;
}
void ArrowRectangle::setMargin(int value)
{
this->m_margin = value;
}
void ArrowRectangle::setBackgroundColor(QString value)
{
this->backgroundColor = value;
}
QPainterPath ArrowRectangle::getLeftCornerPath()
{
QRect rect = this->rect().marginsRemoved(QMargins(shadowWidth,shadowWidth,shadowWidth,shadowWidth));
QPoint cornerPoint(rect.x(), rect.y() + (m_arrowY > 0 ? m_arrowY : rect.height() / 2));
QPoint topLeft(rect.x() + arrowHeight, rect.y());
QPoint topRight(rect.x() + rect.width(), rect.y());
QPoint bottomRight(rect.x() + rect.width(), rect.y() + rect.height());
QPoint bottomLeft(rect.x() + arrowHeight, rect.y() + rect.height());
int radius = this->radius > (rect.height() / 2) ? rect.height() / 2 : this->radius;
QPainterPath border;
border.moveTo(topLeft.x() - radius,topLeft.y());
border.lineTo(topRight.x() - radius, topRight.y());
border.arcTo(topRight.x() - 2 * radius, topRight.y(), 2 * radius, 2 * radius, 90, -90);
border.lineTo(bottomRight.x(), bottomRight.y() - radius);
border.arcTo(bottomRight.x() - 2 * radius, bottomRight.y() - 2 * radius, 2 * radius, 2 * radius, 0, -90);
border.lineTo(bottomLeft.x() - radius,bottomLeft.y());
border.arcTo(bottomLeft.x(),bottomLeft.y() - 2 * radius,2 * radius,2 * radius,-90,-90);
border.lineTo(cornerPoint.x() + arrowHeight,cornerPoint.y() + arrowWidth / 2);
border.lineTo(cornerPoint);
border.lineTo(cornerPoint.x() + arrowHeight,cornerPoint.y() - arrowWidth / 2);
border.lineTo(topLeft.x(),topLeft.y() + radius);
border.arcTo(topLeft.x(),topLeft.y(),2 * radius,2 * radius,-180,-90);
border.lineTo(topLeft.x() - radius,topLeft.y());
return border;
}
QPainterPath ArrowRectangle::getRightCornerPath()
{
QRect rect = this->rect().marginsRemoved(QMargins(shadowWidth,shadowWidth,shadowWidth,shadowWidth));
QPoint cornerPoint(rect.x() + rect.width(), rect.y() + (m_arrowY > 0 ? m_arrowY : rect.height() / 2));
QPoint topLeft(rect.x(), rect.y());
QPoint topRight(rect.x() + rect.width() - arrowHeight, rect.y());
QPoint bottomRight(rect.x() + rect.width() - arrowHeight, rect.y() + rect.height());
QPoint bottomLeft(rect.x(), rect.y() + rect.height());
int radius = this->radius > (rect.height() / 2) ? rect.height() / 2 : this->radius;
QPainterPath border;
border.moveTo(topLeft.x() + radius, topLeft.y());
border.lineTo(topRight.x() - radius,topRight.y());
border.arcTo(topRight.x() - 2 * radius,topRight.y(),2 * radius,2 * radius,90,-90);
border.lineTo(cornerPoint.x() - arrowHeight,cornerPoint.y() - arrowWidth / 2);
border.lineTo(cornerPoint);
border.lineTo(cornerPoint.x() - arrowHeight,cornerPoint.y() + arrowWidth / 2);
border.lineTo(bottomRight.x(),bottomRight.y() - radius);
border.arcTo(bottomRight.x() - 2 * radius,bottomRight.y() - 2 * radius,2 * radius,2 * radius,0,-90);
border.lineTo(bottomLeft.x() + radius, bottomLeft.y());
border.arcTo(bottomLeft.x(), bottomLeft.y() - 2 * radius, 2 * radius, 2 * radius, -90, -90);
border.lineTo(topLeft.x(), topLeft.y() + radius);
border.arcTo(topLeft.x(), topLeft.y(), 2 * radius, 2 * radius, 180, -90);
return border;
}
QPainterPath ArrowRectangle::getTopCornerPath()
{
QRect rect = this->rect().marginsRemoved(QMargins(shadowWidth,shadowWidth,shadowWidth,shadowWidth));
QPoint cornerPoint(rect.x() + (m_arrowX > 0 ? m_arrowX : rect.width() / 2), rect.y());
QPoint topLeft(rect.x(), rect.y() + arrowHeight);
QPoint topRight(rect.x() + rect.width(), rect.y() + arrowHeight);
QPoint bottomRight(rect.x() + rect.width(), rect.y() + rect.height());
QPoint bottomLeft(rect.x(), rect.y() + rect.height());
int radius = this->radius > (rect.height() / 2 - arrowHeight) ? rect.height() / 2 -arrowHeight : this->radius;
QPainterPath border;
border.moveTo(topLeft.x() + radius, topLeft.y());
border.lineTo(cornerPoint.x() - arrowWidth / 2, cornerPoint.y() + arrowHeight);
border.lineTo(cornerPoint);
border.lineTo(cornerPoint.x() + arrowWidth / 2, cornerPoint.y() + arrowHeight);
border.lineTo(topRight.x() - radius, topRight.y());
border.arcTo(topRight.x() - 2 * radius, topRight.y(), 2 * radius, 2 * radius, 90, -90);
border.lineTo(bottomRight.x(), bottomRight.y() - radius);
border.arcTo(bottomRight.x() - 2 * radius, bottomRight.y() - 2 * radius, 2 * radius, 2 * radius, 0, -90);
border.lineTo(bottomLeft.x() + radius, bottomLeft.y());
border.arcTo(bottomLeft.x(), bottomLeft.y() - 2 * radius, 2 * radius, 2 * radius, - 90, -90);
border.lineTo(topLeft.x(), topLeft.y() + radius);
border.arcTo(topLeft.x(), topLeft.y(), 2 * radius, 2 * radius, 180, -90);
return border;
}
QPainterPath ArrowRectangle::getBottomCornerPath()
{
QRect rect = this->rect().marginsRemoved(QMargins(shadowWidth,shadowWidth,shadowWidth,shadowWidth));
QPoint cornerPoint(rect.x() + (m_arrowX > 0 ? m_arrowX : rect.width() / 2), rect.y() + rect.height());
QPoint topLeft(rect.x(), rect.y());
QPoint topRight(rect.x() + rect.width(), rect.y());
QPoint bottomRight(rect.x() + rect.width(), rect.y() + rect.height() - arrowHeight);
QPoint bottomLeft(rect.x(), rect.y() + rect.height() - arrowHeight);
int radius = this->radius > (rect.height() / 2 - arrowHeight) ? rect.height() / 2 -arrowHeight : this->radius;
QPainterPath border;
border.moveTo(topLeft.x() + radius, topLeft.y());
border.lineTo(topRight.x() - radius, topRight.y());
border.arcTo(topRight.x() - 2 * radius, topRight.y(), 2 * radius, 2 * radius, 90, -90);
border.lineTo(bottomRight.x(), bottomRight.y() - radius);
border.arcTo(bottomRight.x() - 2 * radius, bottomRight.y() - 2 * radius, 2 * radius, 2 * radius, 0, -90);
border.lineTo(cornerPoint.x() + arrowWidth / 2, cornerPoint.y() - arrowHeight);
border.lineTo(cornerPoint);
border.lineTo(cornerPoint.x() - arrowWidth / 2, cornerPoint.y() - arrowHeight);
border.lineTo(bottomLeft.x() + radius, bottomLeft.y());
border.arcTo(bottomLeft.x(), bottomLeft.y() - 2 * radius, 2 * radius, 2 * radius, -90, -90);
border.lineTo(topLeft.x(), topLeft.y() + radius);
border.arcTo(topLeft.x(), topLeft.y(), 2 * radius, 2 * radius, 180, -90);
return border;
}
ArrowRectangle::~ArrowRectangle()
{
}

View File

@ -1,84 +0,0 @@
#ifndef ARROWRECTANGLE_H
#define ARROWRECTANGLE_H
#include <QDebug>
#include <QTimer>
#include <QLabel>
#include <QWidget>
#include <QPainter>
#include <QTextLine>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QDesktopWidget>
class ArrowRectangle : public QWidget
{
Q_OBJECT
public:
enum ArrowDirection {
ArrowLeft,
ArrowRight,
ArrowTop,
ArrowBottom
};
explicit ArrowRectangle(QWidget * parent = 0);
~ArrowRectangle();
int getRadius() const;
int getArrowHeight() const;
int getArrowWidth() const;
int getArrowX() const;
int getArrowY() const;
int getMargin() const;
QString getBackgroundColor();
void setArrorDirection(ArrowDirection value);
void setWidth(int value);
void setHeight(int value);
void setRadius(int value);
void setArrowHeight(int value);
void setArrowWidth(int value);
void setArrowX(int value);
void setArrowY(int value);
void setMargin(int value);
void setBackgroundColor(QString value);
virtual void show(ArrowDirection direction, int x,int y);
void setContent(QWidget *content);
void resizeWithContent();
QSize getFixedSize();
void move(int x,int y);
protected:
void paintEvent(QPaintEvent *);
private:
int radius = 3;
int arrowHeight = 8;
int arrowWidth = 12;
int m_margin = 5;
int m_arrowX = 0;
int m_arrowY = 0;
QString backgroundColor;
int strokeWidth = 1;
QColor strokeColor = QColor(255,255,255,130);
int shadowWidth = 2;
QColor shadowColor = Qt::black;
ArrowDirection arrowDirection = ArrowRectangle::ArrowRight;
QWidget *m_content = NULL;
QPoint m_lastPos = QPoint(0, 0);
private:
QPainterPath getLeftCornerPath();
QPainterPath getRightCornerPath();
QPainterPath getTopCornerPath();
QPainterPath getBottomCornerPath();
};
#endif // ARROWRECTANGLE_H

View File

@ -8,7 +8,6 @@
#include <QProcess>
#include "appicon.h"
#include "arrowrectangle.h"
#include "abstractdockitem.h"
#include "controller/dockmodedata.h"
#include "interfaces/dockconstants.h"

View File

@ -1,189 +0,0 @@
#include "previewarrowrectangle.h"
MirrorLabel::MirrorLabel(QWidget *parent) : QLabel(parent)
{
}
void MirrorLabel::storagePixmap(QPixmap pixmap)
{
m_pixmap = pixmap;
QLabel::setFixedSize(0, 0);
}
void MirrorLabel::setFixedSize(QSize size)
{
setPixmap(m_pixmap.scaled(size));
QLabel::setFixedSize(size);
}
MirrorFrame::MirrorFrame(QWidget *parent) : QLabel(parent)
{
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setAlignment(Qt::AlignHCenter | Qt::AlignBottom);
mainLayout->setMargin(0);
m_mirrorLabel = new MirrorLabel(this);
mainLayout->addStretch();
mainLayout->addWidget(m_mirrorLabel);
setWindowFlags(Qt::SplashScreen);
setAttribute(Qt::WA_TranslucentBackground);
}
void MirrorFrame::showWithAnimation(QPixmap mirror, QRect rect)
{
setFixedSize(rect.size());
move(rect.x(), rect.y());
m_mirrorLabel->storagePixmap(mirror);
QPropertyAnimation *animation = new QPropertyAnimation(m_mirrorLabel, "size");
animation->setDuration(SHOW_ANIMATION_DURATION);
animation->setEasingCurve(SHOW_EASING_CURVE);
animation->setEndValue(rect.size());
connect(animation, &QPropertyAnimation::finished, [=]{
emit showFinish();
animation->deleteLater();
hide();
});
connect(this, &MirrorFrame::needStopShow, animation, &QPropertyAnimation::stop);
animation->start();
show();
}
void MirrorFrame::hideWithAnimation(QPixmap mirror, QRect rect)
{
setFixedSize(rect.size());
move(rect.x(), rect.y());
m_mirrorLabel->storagePixmap(mirror);
QPropertyAnimation *animation = new QPropertyAnimation(m_mirrorLabel, "size");
animation->setDuration(HIDE_ANIMATION_DURATION);
animation->setEasingCurve(HIDE_EASING_CURVE);
animation->setStartValue(rect.size());
animation->setEndValue(QSize(width() / 4, height() / 3));
connect(animation, &QPropertyAnimation::finished, [=]{
emit hideFinish();
animation->deleteLater();
hide();
setFixedSize(0,0);
});
animation->start();
show();
}
PreviewArrowRectangle::PreviewArrowRectangle(QWidget *parent)
:ArrowRectangle(parent)
{
initShowFrame();
initHideFrame();
initDelayHideTimer();
initDelayShowTimer();
}
void PreviewArrowRectangle::enterEvent(QEvent *)
{
cancelHide();
ArrowRectangle::show(m_lastArrowDirection, m_lastX, m_lastY);
}
void PreviewArrowRectangle::leaveEvent(QEvent *)
{
cancelShow();
doHide();
}
void PreviewArrowRectangle::showPreview(ArrowDirection direction, int x, int y, int interval)
{
if (m_delayShowTImer->isActive())
return;
m_lastArrowDirection = direction;
m_lastX = x;
m_lastY = y;
m_delayShowTImer->start(interval);
}
void PreviewArrowRectangle::hidePreview(int interval)
{
cancelShow();
if (m_delayHideTimer->isActive() || isHidden())
return;
if (interval <= 0)
ArrowRectangle::hide();
else
m_delayHideTimer->start(interval);
}
void PreviewArrowRectangle::cancelHide()
{
m_delayHideTimer->stop();
}
void PreviewArrowRectangle::cancelShow()
{
m_delayShowTImer->stop();
emit needStopShow();
//show has been cancel but preview got content and need clear up
if (isHidden())
emit hideFinish();
}
void PreviewArrowRectangle::initDelayHideTimer()
{
m_delayHideTimer = new QTimer(this);
m_delayHideTimer->setSingleShot(true);
connect(m_delayHideTimer, &QTimer::timeout, this, &PreviewArrowRectangle::doHide);
}
void PreviewArrowRectangle::initDelayShowTimer()
{
m_delayShowTImer = new QTimer(this);
m_delayShowTImer->setSingleShot(true);
connect(m_delayShowTImer, &QTimer::timeout, this, &PreviewArrowRectangle::doShow);
}
void PreviewArrowRectangle::initHideFrame()
{
m_hideFrame = new MirrorFrame();
}
void PreviewArrowRectangle::initShowFrame()
{
m_showFrame = new MirrorFrame();
connect(m_showFrame, &MirrorFrame::showFinish, [=]{
ArrowRectangle::show(m_lastArrowDirection, m_lastX, m_lastY);
});
connect(this, &PreviewArrowRectangle::needStopShow,[=]{
m_showFrame->hide();
m_showFrame->needStopShow();
});
}
void PreviewArrowRectangle::doHide()
{
//update geometry
ArrowRectangle::show(m_lastArrowDirection, m_lastX, m_lastY);
ArrowRectangle::move(m_lastX, m_lastY);
ArrowRectangle::hide();
QPixmap widgetImg = this->grab();
m_hideFrame->hideWithAnimation(widgetImg, geometry());
ArrowRectangle::hide();
emit hideFinish();
}
void PreviewArrowRectangle::doShow()
{
//update geometry
ArrowRectangle::show(m_lastArrowDirection, m_lastX, m_lastY);
ArrowRectangle::move(m_lastX, m_lastY);
ArrowRectangle::hide();
QPixmap widgetImg = this->grab();
m_showFrame->showWithAnimation(widgetImg, geometry());
}

View File

@ -1,85 +0,0 @@
#ifndef PREVIEWARROWRECTANGLE_H
#define PREVIEWARROWRECTANGLE_H
#include <QTimer>
#include <QVBoxLayout>
#include <QPropertyAnimation>
#include "arrowrectangle.h"
class MirrorLabel : public QLabel
{
Q_OBJECT
Q_PROPERTY(QSize size READ size WRITE setFixedSize)
public:
MirrorLabel(QWidget *parent = 0);
void storagePixmap(QPixmap pixmap);
void setFixedSize(QSize size);
private:
QPixmap m_pixmap;
};
class MirrorFrame : public QLabel
{
Q_OBJECT
public:
MirrorFrame(QWidget *parent = 0);
void showWithAnimation(QPixmap mirror, QRect rect);
void hideWithAnimation(QPixmap mirror, QRect rect);
signals:
void showFinish();
void hideFinish();
void needStopShow();
private:
MirrorLabel *m_mirrorLabel = NULL;
const int SHOW_ANIMATION_DURATION = 200;
const int HIDE_ANIMATION_DURATION = 200;
const QEasingCurve SHOW_EASING_CURVE = QEasingCurve::InCirc;
const QEasingCurve HIDE_EASING_CURVE = QEasingCurve::InCirc;
};
class PreviewArrowRectangle : public ArrowRectangle
{
Q_OBJECT
public:
PreviewArrowRectangle(QWidget *parent = 0);
void showPreview(ArrowDirection direction, int x, int y, int interval = 800);
void hidePreview(int interval);
void cancelHide();
void cancelShow();
signals:
void needStopShow();
void hideFinish();
protected:
void enterEvent(QEvent *);
void leaveEvent(QEvent *);
private:
void initDelayHideTimer();
void initDelayShowTimer();
void initShowFrame();
void initHideFrame();
void doHide();
void doShow();
private:
QTimer *m_delayHideTimer = NULL;
QTimer *m_delayShowTImer = NULL;
MirrorFrame *m_showFrame = NULL;
MirrorFrame *m_hideFrame = NULL;
ArrowDirection m_lastArrowDirection = ArrowBottom;
int m_lastX = 0;
int m_lastY = 0;
};
#endif // PREVIEWARROWRECTANGLE_H

View File

@ -1,7 +1,11 @@
#include "previewframe.h"
PreviewFrame::PreviewFrame(QWidget *parent) : ArrowRectangle(parent)
PreviewFrame::PreviewFrame(ArrowDirection direction, QWidget *parent) : DArrowRectangle(direction, parent)
{
setWindowFlags(Qt::X11BypassWindowManagerHint);
setArrowWidth(ARROW_WIDTH);
setArrowHeight(ARROW_HEIGHT);
m_showTimer = new QTimer(this);
m_showTimer->setSingleShot(true);
connect(m_showTimer, &QTimer::timeout, this, &PreviewFrame::onShowTimerTriggered);
@ -20,14 +24,13 @@ PreviewFrame::~PreviewFrame()
}
void PreviewFrame::showPreview(ArrowRectangle::ArrowDirection direction, int x, int y, int interval)
void PreviewFrame::showPreview(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;
@ -49,7 +52,7 @@ void PreviewFrame::setContent(QWidget *content)
void PreviewFrame::setArrowPos(const QPoint &pos)
{
show(m_direction, pos.x(), pos.y());
show(pos.x(), pos.y());
}
void PreviewFrame::enterEvent(QEvent *)
@ -64,10 +67,10 @@ void PreviewFrame::leaveEvent(QEvent *)
void PreviewFrame::onShowTimerTriggered()
{
ArrowRectangle::setContent(m_tmpContent);
DArrowRectangle::setContent(m_tmpContent);
if (isHidden())
show(m_direction, m_x, m_y);
show(m_x, m_y);
else{
m_animation->setStartValue(m_lastPos);
m_animation->setEndValue(QPoint(m_x, m_y));

View File

@ -3,17 +3,20 @@
#include <QTimer>
#include <QPropertyAnimation>
#include "arrowrectangle.h"
class PreviewFrame : public ArrowRectangle
#include <libdui/darrowrectangle.h>
DUI_USE_NAMESPACE
class PreviewFrame : public DArrowRectangle
{
Q_OBJECT
Q_PROPERTY(QPoint arrowPos READ QPoint(0, 0) WRITE setArrowPos)
public:
explicit PreviewFrame(QWidget *parent = 0);
explicit PreviewFrame(DArrowRectangle::ArrowDirection direction, QWidget *parent = 0);
~PreviewFrame();
void showPreview(ArrowDirection direction, int x, int y, int interval);
void showPreview(int x, int y, int interval);
void hidePreview(int interval = 0);
void setContent(QWidget *content);
void setArrowPos(const QPoint &pos);
@ -34,10 +37,11 @@ private:
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 ARROW_WIDTH = 18;
const int ARROW_HEIGHT = 11;
const int MOVE_ANIMATION_DURATION = 300;
const QEasingCurve MOVE_ANIMATION_CURVE = QEasingCurve::OutCirc;
};