mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
Add item highlight effect (unfinished)
This commit is contained in:
parent
c7cf1b4a07
commit
ea0e018bd6
@ -104,6 +104,17 @@ void Panel::changeDockMode(Dock::DockMode newMode, Dock::DockMode oldMode)
|
||||
{
|
||||
updateBackground();
|
||||
|
||||
if (dockCons->getDockMode() == Dock::FashionMode)
|
||||
{
|
||||
leftLayout->setVerticalAlignment(DockLayout::AlignTop);
|
||||
rightLayout->setVerticalAlignment(DockLayout::AlignTop);
|
||||
}
|
||||
else
|
||||
{
|
||||
leftLayout->setVerticalAlignment(DockLayout::AlignVCenter);
|
||||
rightLayout->setVerticalAlignment(DockLayout::AlignVCenter);
|
||||
}
|
||||
|
||||
leftLayout->relayout();
|
||||
rightLayout->relayout();
|
||||
|
||||
|
@ -6,7 +6,9 @@ AppItem::AppItem(QWidget *parent) :
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
resize(dockCons->getNormalItemWidth(), dockCons->getItemHeight());
|
||||
m_appIcon = new AppIcon(this);
|
||||
initBackground();
|
||||
initHighlight();
|
||||
initClientManager();
|
||||
connect(dockCons, &DockModeData::dockModeChanged,this, &AppItem::slotDockModeChanged);
|
||||
|
||||
@ -126,7 +128,6 @@ void AppItem::resizeResources()
|
||||
{
|
||||
if (m_appIcon != NULL)
|
||||
{
|
||||
m_appIcon->resize(dockCons->getAppIconSize(),dockCons->getAppIconSize());
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
@ -155,6 +156,16 @@ void AppItem::initBackground()
|
||||
}
|
||||
}
|
||||
|
||||
void AppItem::initHighlight()
|
||||
{
|
||||
m_highlight = new HighlightEffect(m_appIcon,this);
|
||||
m_highlight->move(m_appIcon->pos());
|
||||
connect(this, &AppItem::mouseEntered, m_highlight, &HighlightEffect::showLighter);
|
||||
connect(this, &AppItem::mouseExited, m_highlight, &HighlightEffect::showNormal);
|
||||
connect(this, &AppItem::mousePress, m_highlight, &HighlightEffect::showDarker);
|
||||
connect(this, &AppItem::mouseRelease, m_highlight, &HighlightEffect::showLighter);
|
||||
}
|
||||
|
||||
void AppItem::initClientManager()
|
||||
{
|
||||
m_clientmanager = new DBusClientManager(this);
|
||||
@ -190,11 +201,7 @@ void AppItem::initData()
|
||||
|
||||
void AppItem::updateIcon()
|
||||
{
|
||||
if (m_appIcon == NULL)
|
||||
{
|
||||
m_appIcon = new AppIcon(this);
|
||||
}
|
||||
m_appIcon->resize(height(), height());
|
||||
m_appIcon->resize(dockCons->getAppIconSize(),dockCons->getAppIconSize());
|
||||
m_appIcon->setIcon(m_itemData.iconPath);
|
||||
|
||||
reanchorIcon();
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "appicon.h"
|
||||
#include "appbackground.h"
|
||||
#include "arrowrectangle.h"
|
||||
#include "highlighteffect.h"
|
||||
#include "../dockconstants.h"
|
||||
|
||||
struct AppItemData {
|
||||
@ -74,6 +75,7 @@ private slots:
|
||||
private:
|
||||
void resizeResources();
|
||||
void initBackground();
|
||||
void initHighlight();
|
||||
void initClientManager();
|
||||
void setActived(bool value);
|
||||
|
||||
@ -91,6 +93,7 @@ private:
|
||||
AppItemData m_itemData;
|
||||
DockModeData *dockCons = DockModeData::instance();
|
||||
AppBackground * appBackground = NULL;
|
||||
HighlightEffect * m_highlight = NULL;
|
||||
AppIcon * m_appIcon = NULL;
|
||||
QLabel * m_appTitle = NULL;
|
||||
|
||||
|
@ -6,8 +6,7 @@
|
||||
|
||||
HighlightEffect::HighlightEffect(QWidget * source, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
m_source(source),
|
||||
m_lighter(150)
|
||||
m_source(source)
|
||||
{
|
||||
setFixedSize(m_source->size());
|
||||
}
|
||||
@ -21,15 +20,55 @@ int HighlightEffect::lighter() const
|
||||
void HighlightEffect::setLighter(int lighter)
|
||||
{
|
||||
m_lighter = lighter;
|
||||
}
|
||||
|
||||
int HighlightEffect::darker() const
|
||||
{
|
||||
return m_darker;
|
||||
}
|
||||
|
||||
void HighlightEffect::setDarker(int darker)
|
||||
{
|
||||
m_darker = darker;
|
||||
}
|
||||
|
||||
void HighlightEffect::showDarker()
|
||||
{
|
||||
m_effectState = ESDarker;
|
||||
|
||||
this->repaint();
|
||||
}
|
||||
|
||||
void HighlightEffect::showLighter()
|
||||
{
|
||||
m_effectState = ESLighter;
|
||||
|
||||
this->repaint();
|
||||
}
|
||||
|
||||
void HighlightEffect::showNormal()
|
||||
{
|
||||
m_effectState = ESNormal;
|
||||
|
||||
this->repaint();
|
||||
}
|
||||
|
||||
void HighlightEffect::paintEvent(QPaintEvent *)
|
||||
{
|
||||
if (m_source) {
|
||||
if (m_source)
|
||||
{
|
||||
QPixmap pixmap = m_source->grab();
|
||||
this->pixmapLigher(&pixmap, 150);
|
||||
|
||||
switch (m_effectState)
|
||||
{
|
||||
case ESDarker:
|
||||
pixmapDarker(&pixmap);
|
||||
break;
|
||||
case ESLighter:
|
||||
pixmapLigher(&pixmap);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
QPainter painter;
|
||||
painter.begin(this);
|
||||
@ -42,7 +81,7 @@ void HighlightEffect::paintEvent(QPaintEvent *)
|
||||
}
|
||||
}
|
||||
|
||||
void HighlightEffect::pixmapLigher(QPixmap *pixmap, int lighter)
|
||||
void HighlightEffect::pixmapLigher(QPixmap *pixmap)
|
||||
{
|
||||
QImage img = pixmap->toImage(); // slow
|
||||
|
||||
@ -52,7 +91,24 @@ void HighlightEffect::pixmapLigher(QPixmap *pixmap, int lighter)
|
||||
{
|
||||
QRgb pix = img.pixel(x,y);
|
||||
QColor col(pix);
|
||||
col = col.lighter(lighter);
|
||||
col = col.lighter(m_lighter);
|
||||
img.setPixel(x, y, qRgba(col.red(), col.green(), col.blue(), qAlpha(pix)));
|
||||
}
|
||||
}
|
||||
pixmap->convertFromImage(img); // slow
|
||||
}
|
||||
|
||||
void HighlightEffect::pixmapDarker(QPixmap *pixmap)
|
||||
{
|
||||
QImage img = pixmap->toImage(); // slow
|
||||
|
||||
for (int y=0; y < img.height(); y++)
|
||||
{
|
||||
for (int x = 0; x < img.width(); x++)
|
||||
{
|
||||
QRgb pix = img.pixel(x,y);
|
||||
QColor col(pix);
|
||||
col = col.darker(m_darker);
|
||||
img.setPixel(x, y, qRgba(col.red(), col.green(), col.blue(), qAlpha(pix)));
|
||||
}
|
||||
}
|
||||
|
@ -9,17 +9,33 @@ class HighlightEffect : public QWidget
|
||||
public:
|
||||
HighlightEffect(QWidget * source, QWidget *parent = 0);
|
||||
|
||||
enum EffectState {
|
||||
ESNormal,
|
||||
ESLighter,
|
||||
ESDarker
|
||||
};
|
||||
|
||||
int lighter() const;
|
||||
void setLighter(int lighter);
|
||||
int darker() const;
|
||||
void setDarker(int darker);
|
||||
|
||||
void showDarker();
|
||||
void showLighter();
|
||||
void showNormal();
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent * event) Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
QWidget * m_source;
|
||||
int m_lighter;
|
||||
int m_lighter = 110;
|
||||
int m_darker = 150;
|
||||
EffectState m_effectState = ESNormal;
|
||||
|
||||
void pixmapLigher(QPixmap * pixmap, int lighter);
|
||||
|
||||
void pixmapLigher(QPixmap * pixmap);
|
||||
void pixmapDarker(QPixmap * pixmap);
|
||||
};
|
||||
|
||||
#endif // HIGHLIGHTEFFECT_H
|
||||
|
@ -20,7 +20,7 @@ const int APP_PREVIEW_WIDTH = 160;
|
||||
const int APP_PREVIEW_HEIGHT = 100;
|
||||
const int APP_PREVIEW_MARGIN = 18 ;
|
||||
|
||||
const int APP_ITEM_FASHION_HEIGHT = 48;
|
||||
const int APP_ITEM_FASHION_HEIGHT = 70;
|
||||
const int APP_ITEM_FASHION_NORMAL_WIDTH = 48;
|
||||
const int APP_ITEM_FASHION_ACTIVE_WIDTH = 48;
|
||||
const int APP_ITEM_FASHION_SPACING = 3;
|
||||
@ -39,7 +39,7 @@ const int APP_ITEM_CLASSIC_SPACING = 4;
|
||||
const int APP_ITEM_CLASSIC_ICON_SIZE = 24;
|
||||
|
||||
//////////////// APpplet ////////////////////////////
|
||||
const int APPLET_FASHION_ITEM_HEIGHT = 48;
|
||||
const int APPLET_FASHION_ITEM_HEIGHT = 70;
|
||||
const int APPLET_FASHION_ITEM_WIDTH = 48;
|
||||
const int APPLET_FASHION_ITEM_SPACING = 3;
|
||||
const int APPLET_FASHION_ICON_SIZE = 48;
|
||||
|
Loading…
x
Reference in New Issue
Block a user