mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
add hover effects
Change-Id: I4bcdceb7c3a8b41e6c8b64c0e72ade11a1e4fd81
This commit is contained in:
parent
218ad40609
commit
8b479bbf14
@ -28,7 +28,8 @@ SOURCES += main.cpp \
|
|||||||
dbus/dbusmenumanager.cpp \
|
dbus/dbusmenumanager.cpp \
|
||||||
dbus/dbusmenu.cpp \
|
dbus/dbusmenu.cpp \
|
||||||
item/pluginsitem.cpp \
|
item/pluginsitem.cpp \
|
||||||
controller/dockpluginscontroller.cpp
|
controller/dockpluginscontroller.cpp \
|
||||||
|
util/imagefactory.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
window/mainwindow.h \
|
window/mainwindow.h \
|
||||||
@ -48,7 +49,8 @@ HEADERS += \
|
|||||||
dbus/dbusmenumanager.h \
|
dbus/dbusmenumanager.h \
|
||||||
dbus/dbusmenu.h \
|
dbus/dbusmenu.h \
|
||||||
item/pluginsitem.h \
|
item/pluginsitem.h \
|
||||||
controller/dockpluginscontroller.h
|
controller/dockpluginscontroller.h \
|
||||||
|
util/imagefactory.h
|
||||||
|
|
||||||
dbus_service.files += com.deepin.dde.dock.service
|
dbus_service.files += com.deepin.dde.dock.service
|
||||||
dbus_service.path = /usr/share/dbus-1/services
|
dbus_service.path = /usr/share/dbus-1/services
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "appitem.h"
|
#include "appitem.h"
|
||||||
|
|
||||||
#include "util/themeappicon.h"
|
#include "util/themeappicon.h"
|
||||||
|
#include "util/imagefactory.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QDrag>
|
#include <QDrag>
|
||||||
@ -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
|
// draw icon
|
||||||
if (DockDisplayMode == Efficient)
|
painter.drawPixmap(itemRect.center() - pixmap.rect().center(), pixmap);
|
||||||
painter.drawPixmap(itemRect.center() - m_smallIcon.rect().center(), m_smallIcon);
|
|
||||||
else
|
|
||||||
painter.drawPixmap(itemRect.center() - m_largeIcon.rect().center(), m_largeIcon);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppItem::mouseReleaseEvent(QMouseEvent *e)
|
void AppItem::mouseReleaseEvent(QMouseEvent *e)
|
||||||
|
@ -12,6 +12,7 @@ DisplayMode DockItem::DockDisplayMode = DisplayMode::Efficient;
|
|||||||
DockItem::DockItem(const ItemType type, QWidget *parent)
|
DockItem::DockItem(const ItemType type, QWidget *parent)
|
||||||
: QWidget(parent),
|
: QWidget(parent),
|
||||||
m_type(type),
|
m_type(type),
|
||||||
|
m_hover(false),
|
||||||
|
|
||||||
m_menuManagerInter(new DBusMenuManager(this))
|
m_menuManagerInter(new DBusMenuManager(this))
|
||||||
{
|
{
|
||||||
@ -43,6 +44,24 @@ void DockItem::mousePressEvent(QMouseEvent *e)
|
|||||||
return showContextMenu();
|
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 DockItem::perfectIconRect() const
|
||||||
{
|
{
|
||||||
const QRect itemRect = rect();
|
const QRect itemRect = rect();
|
||||||
|
@ -33,6 +33,8 @@ signals:
|
|||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *e);
|
void paintEvent(QPaintEvent *e);
|
||||||
void mousePressEvent(QMouseEvent *e);
|
void mousePressEvent(QMouseEvent *e);
|
||||||
|
void enterEvent(QEvent *e);
|
||||||
|
void leaveEvent(QEvent *e);
|
||||||
|
|
||||||
const QRect perfectIconRect() const;
|
const QRect perfectIconRect() const;
|
||||||
|
|
||||||
@ -42,6 +44,7 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
ItemType m_type;
|
ItemType m_type;
|
||||||
|
bool m_hover;
|
||||||
|
|
||||||
DBusMenuManager *m_menuManagerInter;
|
DBusMenuManager *m_menuManagerInter;
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "launcheritem.h"
|
#include "launcheritem.h"
|
||||||
#include "util/themeappicon.h"
|
#include "util/themeappicon.h"
|
||||||
|
#include "util/imagefactory.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
@ -18,10 +19,11 @@ void LauncherItem::paintEvent(QPaintEvent *e)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
if (DockDisplayMode == Fashion)
|
|
||||||
painter.drawPixmap(rect().center() - m_largeIcon.rect().center(), m_largeIcon);
|
QPixmap pixmap = DockDisplayMode == Fashion ? m_largeIcon : m_smallIcon;
|
||||||
else
|
if (m_hover)
|
||||||
painter.drawPixmap(rect().center() - m_smallIcon.rect().center(), m_smallIcon);
|
pixmap = ImageFactory::lighter(pixmap);
|
||||||
|
painter.drawPixmap(rect().center() - pixmap.rect().center(), pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LauncherItem::resizeEvent(QResizeEvent *e)
|
void LauncherItem::resizeEvent(QResizeEvent *e)
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#include "pluginsitem.h"
|
#include "pluginsitem.h"
|
||||||
|
|
||||||
#include "pluginsiteminterface.h"
|
#include "pluginsiteminterface.h"
|
||||||
|
|
||||||
|
#include "util/imagefactory.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
@ -92,7 +93,8 @@ void PluginsItem::paintEvent(QPaintEvent *e)
|
|||||||
const QIcon icon = m_pluginInter->itemIcon(m_itemKey);
|
const QIcon icon = m_pluginInter->itemIcon(m_itemKey);
|
||||||
const QRect iconRect = perfectIconRect();
|
const QRect iconRect = perfectIconRect();
|
||||||
const QPixmap pixmap = icon.pixmap(iconRect.size());
|
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)
|
bool PluginsItem::eventFilter(QObject *o, QEvent *e)
|
||||||
|
32
frame/util/imagefactory.cpp
Normal file
32
frame/util/imagefactory.cpp
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#include "imagefactory.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
18
frame/util/imagefactory.h
Normal file
18
frame/util/imagefactory.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#ifndef IMAGEFACTORY_H
|
||||||
|
#define IMAGEFACTORY_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QPixmap>
|
||||||
|
#include <QImage>
|
||||||
|
|
||||||
|
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
|
Loading…
x
Reference in New Issue
Block a user