mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
optimize ligher effect
Change-Id: I130ad12e15ebb6d720294b922d9d556352224595
This commit is contained in:
parent
5d014c4642
commit
1adeef359b
@ -132,13 +132,12 @@ void AppItem::paintEvent(QPaintEvent *e)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// icon
|
// icon
|
||||||
QPixmap pixmap = DockDisplayMode == Efficient ? m_smallIcon : m_largeIcon;
|
const QPixmap pixmap = DockDisplayMode == Efficient ? m_smallIcon : m_largeIcon;
|
||||||
// ligher icon
|
|
||||||
if (m_hover)
|
|
||||||
pixmap = ImageFactory::lighter(pixmap);
|
|
||||||
|
|
||||||
// draw icon
|
// draw icon
|
||||||
painter.drawPixmap(itemRect.center() - pixmap.rect().center(), pixmap);
|
painter.drawPixmap(itemRect.center() - pixmap.rect().center(), pixmap);
|
||||||
|
// draw ligher
|
||||||
|
if (m_hover)
|
||||||
|
painter.drawPixmap(itemRect.center() - pixmap.rect().center(), ImageFactory::lighterEffect(pixmap));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AppItem::mouseReleaseEvent(QMouseEvent *e)
|
void AppItem::mouseReleaseEvent(QMouseEvent *e)
|
||||||
|
@ -20,10 +20,11 @@ void LauncherItem::paintEvent(QPaintEvent *e)
|
|||||||
|
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
|
|
||||||
QPixmap pixmap = DockDisplayMode == Fashion ? m_largeIcon : m_smallIcon;
|
const QPixmap pixmap = DockDisplayMode == Fashion ? m_largeIcon : m_smallIcon;
|
||||||
if (m_hover)
|
|
||||||
pixmap = ImageFactory::lighter(pixmap);
|
|
||||||
painter.drawPixmap(rect().center() - pixmap.rect().center(), pixmap);
|
painter.drawPixmap(rect().center() - pixmap.rect().center(), pixmap);
|
||||||
|
|
||||||
|
if (m_hover)
|
||||||
|
painter.drawPixmap(rect().center() - pixmap.rect().center(), ImageFactory::lighterEffect(pixmap));
|
||||||
}
|
}
|
||||||
|
|
||||||
void LauncherItem::resizeEvent(QResizeEvent *e)
|
void LauncherItem::resizeEvent(QResizeEvent *e)
|
||||||
|
@ -94,7 +94,10 @@ void PluginsItem::paintEvent(QPaintEvent *e)
|
|||||||
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, m_hover ? ImageFactory::lighter(pixmap) : pixmap);
|
painter.drawPixmap(iconRect, pixmap);
|
||||||
|
|
||||||
|
if (m_hover)
|
||||||
|
painter.drawPixmap(iconRect, ImageFactory::lighterEffect(pixmap));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PluginsItem::eventFilter(QObject *o, QEvent *e)
|
bool PluginsItem::eventFilter(QObject *o, QEvent *e)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "imagefactory.h"
|
#include "imagefactory.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
ImageFactory::ImageFactory(QObject *parent)
|
ImageFactory::ImageFactory(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
@ -8,25 +9,12 @@ ImageFactory::ImageFactory(QObject *parent)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QPixmap ImageFactory::lighter(const QPixmap pixmap, const int delta)
|
QPixmap ImageFactory::lighterEffect(const QPixmap pixmap, const int delta)
|
||||||
{
|
{
|
||||||
QImage image = pixmap.toImage();
|
QPixmap result(pixmap);
|
||||||
|
QPainter painter(&result);
|
||||||
|
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
|
||||||
|
painter.fillRect(result.rect(), QColor::fromRgb(255, 255, 255, delta));
|
||||||
|
|
||||||
const int width = image.width();
|
return result;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ class ImageFactory : public QObject
|
|||||||
public:
|
public:
|
||||||
explicit ImageFactory(QObject *parent = 0);
|
explicit ImageFactory(QObject *parent = 0);
|
||||||
|
|
||||||
static QPixmap lighter(const QPixmap pixmap, const int delta = 120);
|
static QPixmap lighterEffect(const QPixmap pixmap, const int delta = 50);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // IMAGEFACTORY_H
|
#endif // IMAGEFACTORY_H
|
||||||
|
Loading…
x
Reference in New Issue
Block a user