refactor: move highlight effect to dock item base class

Change-Id: I80c162b4af84718f533d006768bc33f1023064c1
This commit is contained in:
石博文 2018-01-23 13:35:42 +08:00
parent 5528cc16df
commit 782ad6e08d
Notes: Deepin Code Review 2018-01-23 14:16:48 +08:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: 石博文 <sbw@sbw.so>
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Tue, 23 Jan 2018 14:16:48 +0800
Reviewed-on: https://cr.deepin.io/30946
Project: dde/dde-dock
Branch: refs/heads/master
6 changed files with 52 additions and 12 deletions

View File

@ -39,7 +39,8 @@ SOURCES += main.cpp \
dbus/dbusdockadaptors.cpp \
item/components/appsnapshot.cpp \
item/components/floatingpreview.cpp \
item/components/previewcontainer.cpp
item/components/previewcontainer.cpp \
item/components/hoverhighlighteffect.cpp
HEADERS += \
window/mainwindow.h \
@ -69,7 +70,8 @@ HEADERS += \
dbus/dbusdockadaptors.h \
item/components/appsnapshot.h \
item/components/floatingpreview.h \
item/components/previewcontainer.h
item/components/previewcontainer.h \
item/components/hoverhighlighteffect.h
dbus_service.files += com.deepin.dde.Dock.service
dbus_service.path = /usr/share/dbus-1/services

View File

@ -280,11 +280,7 @@ void AppItem::paintEvent(QPaintEvent *e)
const int iconX = itemRect.center().x() - pixmap.rect().center().x() / ratio;
const int iconY = itemRect.center().y() - pixmap.rect().center().y() / ratio;
// draw ligher/normal icon
if (!m_hover)
painter.drawPixmap(iconX, iconY, pixmap);
else
painter.drawPixmap(iconX, iconY, ImageFactory::lighterEffect(pixmap));
painter.drawPixmap(iconX, iconY, pixmap);
}
void AppItem::mouseReleaseEvent(QMouseEvent *e)

View File

@ -0,0 +1,23 @@
#include "hoverhighlighteffect.h"
#include "util/imagefactory.h"
#include <QPainter>
#include <QDebug>
HoverHighlightEffect::HoverHighlightEffect(QObject *parent)
: QGraphicsEffect(parent)
{
}
void HoverHighlightEffect::draw(QPainter *painter)
{
const QPixmap pix = sourcePixmap(Qt::DeviceCoordinates);
if (isEnabled())
{
painter->drawPixmap(0, 0, ImageFactory::lighterEffect(pix));
} else {
painter->drawPixmap(0, 0, pix);
}
}

View File

@ -0,0 +1,17 @@
#ifndef HOVERHIGHLIGHTEFFECT_H
#define HOVERHIGHLIGHTEFFECT_H
#include <QGraphicsEffect>
class HoverHighlightEffect : public QGraphicsEffect
{
Q_OBJECT
public:
explicit HoverHighlightEffect(QObject *parent = nullptr);
protected:
void draw(QPainter *painter);
};
#endif // HOVERHIGHLIGHTEFFECT_H

View File

@ -22,6 +22,7 @@
#include "dockitem.h"
#include "dbus/dbusmenu.h"
#include "dbus/dbusmenumanager.h"
#include "components/hoverhighlighteffect.h"
#include <QMouseEvent>
#include <QJsonObject>
@ -58,6 +59,9 @@ DockItem::DockItem(QWidget *parent)
m_popupAdjustDelayTimer->setInterval(100);
m_popupAdjustDelayTimer->setSingleShot(true);
setGraphicsEffect(new HoverHighlightEffect(this));
graphicsEffect()->setEnabled(false);
connect(m_popupTipsDelayTimer, &QTimer::timeout, this, &DockItem::showHoverTips);
connect(m_popupAdjustDelayTimer, &QTimer::timeout, this, &DockItem::updatePopupPosition);
}
@ -114,6 +118,7 @@ void DockItem::enterEvent(QEvent *e)
{
m_hover = true;
m_popupTipsDelayTimer->start();
graphicsEffect()->setEnabled(true);
update();
@ -126,6 +131,7 @@ void DockItem::leaveEvent(QEvent *e)
m_hover = false;
m_popupTipsDelayTimer->stop();
graphicsEffect()->setEnabled(false);
// auto hide if popup is not model window
if (m_popupShown && !PopupWindow->model())

View File

@ -70,11 +70,7 @@ void LauncherItem::paintEvent(QPaintEvent *e)
const int iconX = rect().center().x() - pixmap.rect().center().x() / ratio;
const int iconY = rect().center().y() - pixmap.rect().center().y() / ratio;
// draw ligher/normal icon
if (!m_hover)
painter.drawPixmap(iconX, iconY, pixmap);
else
painter.drawPixmap(iconX, iconY, ImageFactory::lighterEffect(pixmap));
painter.drawPixmap(iconX, iconY, pixmap);
}
void LauncherItem::resizeEvent(QResizeEvent *e)