diff --git a/frame/frame.pro b/frame/frame.pro index 6e28a5e33..e19964ee0 100644 --- a/frame/frame.pro +++ b/frame/frame.pro @@ -28,7 +28,8 @@ SOURCES += main.cpp \ dbus/dbusmenumanager.cpp \ dbus/dbusmenu.cpp \ item/pluginsitem.cpp \ - controller/dockpluginscontroller.cpp + controller/dockpluginscontroller.cpp \ + util/imagefactory.cpp HEADERS += \ window/mainwindow.h \ @@ -48,7 +49,8 @@ HEADERS += \ dbus/dbusmenumanager.h \ dbus/dbusmenu.h \ item/pluginsitem.h \ - controller/dockpluginscontroller.h + controller/dockpluginscontroller.h \ + util/imagefactory.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 b7eecbe0d..41e6efaf9 100644 --- a/frame/item/appitem.cpp +++ b/frame/item/appitem.cpp @@ -1,6 +1,7 @@ #include "appitem.h" #include "util/themeappicon.h" +#include "util/imagefactory.h" #include #include @@ -130,11 +131,14 @@ void AppItem::paintEvent(QPaintEvent *e) } } + // icon + QPixmap pixmap = DockDisplayMode == Efficient ? m_smallIcon : m_largeIcon; + // ligher icon + if (m_hover) + pixmap = ImageFactory::lighter(pixmap); + // draw icon - if (DockDisplayMode == Efficient) - painter.drawPixmap(itemRect.center() - m_smallIcon.rect().center(), m_smallIcon); - else - painter.drawPixmap(itemRect.center() - m_largeIcon.rect().center(), m_largeIcon); + painter.drawPixmap(itemRect.center() - pixmap.rect().center(), pixmap); } void AppItem::mouseReleaseEvent(QMouseEvent *e) diff --git a/frame/item/dockitem.cpp b/frame/item/dockitem.cpp index 988331dbd..8d312c66a 100644 --- a/frame/item/dockitem.cpp +++ b/frame/item/dockitem.cpp @@ -12,6 +12,7 @@ DisplayMode DockItem::DockDisplayMode = DisplayMode::Efficient; DockItem::DockItem(const ItemType type, QWidget *parent) : QWidget(parent), m_type(type), + m_hover(false), m_menuManagerInter(new DBusMenuManager(this)) { @@ -43,6 +44,24 @@ void DockItem::mousePressEvent(QMouseEvent *e) return showContextMenu(); } +void DockItem::enterEvent(QEvent *e) +{ + m_hover = true; + + update(); + + return QWidget::enterEvent(e); +} + +void DockItem::leaveEvent(QEvent *e) +{ + m_hover = false; + + update(); + + return QWidget::leaveEvent(e); +} + const QRect DockItem::perfectIconRect() const { const QRect itemRect = rect(); diff --git a/frame/item/dockitem.h b/frame/item/dockitem.h index 37dc50dfd..be245cb86 100644 --- a/frame/item/dockitem.h +++ b/frame/item/dockitem.h @@ -33,6 +33,8 @@ signals: protected: void paintEvent(QPaintEvent *e); void mousePressEvent(QMouseEvent *e); + void enterEvent(QEvent *e); + void leaveEvent(QEvent *e); const QRect perfectIconRect() const; @@ -42,6 +44,7 @@ protected: protected: ItemType m_type; + bool m_hover; DBusMenuManager *m_menuManagerInter; diff --git a/frame/item/launcheritem.cpp b/frame/item/launcheritem.cpp index eba20a6a5..4b5cd79d0 100644 --- a/frame/item/launcheritem.cpp +++ b/frame/item/launcheritem.cpp @@ -1,5 +1,6 @@ #include "launcheritem.h" #include "util/themeappicon.h" +#include "util/imagefactory.h" #include #include @@ -18,10 +19,11 @@ void LauncherItem::paintEvent(QPaintEvent *e) return; QPainter painter(this); - if (DockDisplayMode == Fashion) - painter.drawPixmap(rect().center() - m_largeIcon.rect().center(), m_largeIcon); - else - painter.drawPixmap(rect().center() - m_smallIcon.rect().center(), m_smallIcon); + + QPixmap pixmap = DockDisplayMode == Fashion ? m_largeIcon : m_smallIcon; + if (m_hover) + pixmap = ImageFactory::lighter(pixmap); + painter.drawPixmap(rect().center() - pixmap.rect().center(), pixmap); } void LauncherItem::resizeEvent(QResizeEvent *e) diff --git a/frame/item/pluginsitem.cpp b/frame/item/pluginsitem.cpp index 4a6e6d0a0..f508d04d5 100644 --- a/frame/item/pluginsitem.cpp +++ b/frame/item/pluginsitem.cpp @@ -1,7 +1,8 @@ #include "pluginsitem.h" - #include "pluginsiteminterface.h" +#include "util/imagefactory.h" + #include #include #include @@ -92,7 +93,8 @@ void PluginsItem::paintEvent(QPaintEvent *e) const QIcon icon = m_pluginInter->itemIcon(m_itemKey); const QRect iconRect = perfectIconRect(); const QPixmap pixmap = icon.pixmap(iconRect.size()); - painter.drawPixmap(iconRect, pixmap); + + painter.drawPixmap(iconRect, m_hover ? ImageFactory::lighter(pixmap) : pixmap); } bool PluginsItem::eventFilter(QObject *o, QEvent *e) diff --git a/frame/util/imagefactory.cpp b/frame/util/imagefactory.cpp new file mode 100644 index 000000000..eebbd58b8 --- /dev/null +++ b/frame/util/imagefactory.cpp @@ -0,0 +1,32 @@ +#include "imagefactory.h" + +#include + +ImageFactory::ImageFactory(QObject *parent) + : QObject(parent) +{ + +} + +QPixmap ImageFactory::lighter(const QPixmap pixmap, const int delta) +{ + QImage image = pixmap.toImage(); + + const int width = image.width(); + const int height = image.height(); + const int bytesPerPixel = image.bytesPerLine() / image.width(); + + for (int i(0); i != height; ++i) + { + uchar *scanLine = image.scanLine(i); + for (int j(0); j != width; ++j) + { + QRgb &rgba = *(QRgb*)scanLine; + if (qAlpha(rgba) && (qRed(rgba) || qGreen(rgba) || qBlue(rgba))) + rgba = QColor::fromRgba(rgba).lighter(delta).rgba(); + scanLine += bytesPerPixel; + } + } + + return QPixmap::fromImage(image); +} diff --git a/frame/util/imagefactory.h b/frame/util/imagefactory.h new file mode 100644 index 000000000..c5d4f549d --- /dev/null +++ b/frame/util/imagefactory.h @@ -0,0 +1,18 @@ +#ifndef IMAGEFACTORY_H +#define IMAGEFACTORY_H + +#include +#include +#include + +class ImageFactory : public QObject +{ + Q_OBJECT + +public: + explicit ImageFactory(QObject *parent = 0); + + static QPixmap lighter(const QPixmap pixmap, const int delta = 120); +}; + +#endif // IMAGEFACTORY_H