diff --git a/frame/frame.pro b/frame/frame.pro index 5bcd99592..10755f369 100644 --- a/frame/frame.pro +++ b/frame/frame.pro @@ -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 diff --git a/frame/item/appitem.cpp b/frame/item/appitem.cpp index 496e62afe..b4be35c49 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -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) diff --git a/frame/item/components/hoverhighlighteffect.cpp b/frame/item/components/hoverhighlighteffect.cpp new file mode 100644 index 000000000..4472cc346 --- /dev/null +++ b/frame/item/components/hoverhighlighteffect.cpp @@ -0,0 +1,23 @@ +#include "hoverhighlighteffect.h" +#include "util/imagefactory.h" + +#include +#include + +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); + } +} diff --git a/frame/item/components/hoverhighlighteffect.h b/frame/item/components/hoverhighlighteffect.h new file mode 100644 index 000000000..02803498d --- /dev/null +++ b/frame/item/components/hoverhighlighteffect.h @@ -0,0 +1,17 @@ +#ifndef HOVERHIGHLIGHTEFFECT_H +#define HOVERHIGHLIGHTEFFECT_H + +#include + +class HoverHighlightEffect : public QGraphicsEffect +{ + Q_OBJECT + +public: + explicit HoverHighlightEffect(QObject *parent = nullptr); + +protected: + void draw(QPainter *painter); +}; + +#endif // HOVERHIGHLIGHTEFFECT_H diff --git a/frame/item/dockitem.cpp b/frame/item/dockitem.cpp index 820c110e4..043c39fe0 100644 --- a/frame/item/dockitem.cpp +++ b/frame/item/dockitem.cpp @@ -22,6 +22,7 @@ #include "dockitem.h" #include "dbus/dbusmenu.h" #include "dbus/dbusmenumanager.h" +#include "components/hoverhighlighteffect.h" #include #include @@ -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()) diff --git a/frame/item/launcheritem.cpp b/frame/item/launcheritem.cpp index d51f33154..5003ea599 100644 --- a/frame/item/launcheritem.cpp +++ b/frame/item/launcheritem.cpp @@ -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)