Merge branch 'dde-dock' of gitcafe.com:Hualet/dde-workspace-2015 into dde-dock

Conflicts:
	dde-dock/dde-dock.pro
This commit is contained in:
杨万青 2015-07-22 16:58:13 +08:00
commit c7cf1b4a07
5 changed files with 157 additions and 2 deletions

View File

@ -44,7 +44,9 @@ SOURCES += \
src/Widgets/closebutton.cpp \
src/DBus/dbushidestatemanager.cpp \
../libs/xcb_misc.cpp \
src/Widgets/launcheritem.cpp
src/Widgets/launcheritem.cpp \
src/Widgets/reflectioneffect.cpp \
src/Widgets/highlighteffect.cpp
HEADERS += \
src/abstractdockitem.h \
@ -78,7 +80,9 @@ HEADERS += \
src/Widgets/closebutton.h \
src/DBus/dbushidestatemanager.h \
../libs/xcb_misc.h \
src/Widgets/launcheritem.h
src/Widgets/launcheritem.h \
src/Widgets/reflectioneffect.h \
src/Widgets/highlighteffect.h
RESOURCES += \
images.qrc \

View File

@ -0,0 +1,60 @@
#include <QColor>
#include <QPainter>
#include <QBitmap>
#include "highlighteffect.h"
HighlightEffect::HighlightEffect(QWidget * source, QWidget *parent) :
QWidget(parent),
m_source(source),
m_lighter(150)
{
setFixedSize(m_source->size());
}
int HighlightEffect::lighter() const
{
return m_lighter;
}
void HighlightEffect::setLighter(int lighter)
{
m_lighter = lighter;
this->repaint();
}
void HighlightEffect::paintEvent(QPaintEvent *)
{
if (m_source) {
QPixmap pixmap = m_source->grab();
this->pixmapLigher(&pixmap, 150);
QPainter painter;
painter.begin(this);
painter.setClipRect(rect());
painter.drawPixmap(0, 0, pixmap);
painter.end();
}
}
void HighlightEffect::pixmapLigher(QPixmap *pixmap, int lighter)
{
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.lighter(lighter);
img.setPixel(x, y, qRgba(col.red(), col.green(), col.blue(), qAlpha(pix)));
}
}
pixmap->convertFromImage(img); // slow
}

View File

@ -0,0 +1,25 @@
#ifndef HIGHLIGHTEFFECT_H
#define HIGHLIGHTEFFECT_H
#include <QWidget>
class HighlightEffect : public QWidget
{
Q_OBJECT
public:
HighlightEffect(QWidget * source, QWidget *parent = 0);
int lighter() const;
void setLighter(int lighter);
protected:
void paintEvent(QPaintEvent * event) Q_DECL_OVERRIDE;
private:
QWidget * m_source;
int m_lighter;
void pixmapLigher(QPixmap * pixmap, int lighter);
};
#endif // HIGHLIGHTEFFECT_H

View File

@ -0,0 +1,42 @@
#include <QPainter>
#include "reflectioneffect.h"
ReflectionEffect::ReflectionEffect(QWidget * source, QWidget *parent) :
QWidget(parent),
m_source(source),
m_opacity(0.1)
{
this->setFixedWidth(m_source->width());
}
qreal ReflectionEffect::opacity() const
{
return m_opacity;
}
void ReflectionEffect::setOpacity(const qreal &opacity)
{
m_opacity = opacity;
}
void ReflectionEffect::paintEvent(QPaintEvent *)
{
if (m_source) {
QPixmap pixmap = m_source->grab();
// flip the pixmap
pixmap = pixmap.transformed(QTransform().scale(1, -1));
if (!pixmap.isNull()) {
QPainter painter;
painter.begin(this);
painter.setClipRect(rect());
painter.setOpacity(m_opacity);
painter.drawPixmap(0, 0, pixmap);
painter.end();
}
}
}

View File

@ -0,0 +1,24 @@
#ifndef REFLECTIONEFFECT_H
#define REFLECTIONEFFECT_H
#include <QWidget>
class QPaintEvent;
class ReflectionEffect : public QWidget
{
Q_OBJECT
public:
ReflectionEffect(QWidget * source, QWidget *parent = 0);
qreal opacity() const;
void setOpacity(const qreal &opacity);
protected:
void paintEvent(QPaintEvent * event) Q_DECL_OVERRIDE;
private:
QWidget * m_source;
qreal m_opacity;
};
#endif // REFLECTIONEFFECT_H