s/pulsershadow/widgetsnapshot

svn path=/trunk/KDE/kdelibs/; revision=1115254
This commit is contained in:
Bruno de Oliveira Abinader 2010-04-15 18:51:26 +00:00
parent ec3d3774bc
commit daffafb9fe
5 changed files with 41 additions and 34 deletions

View File

@ -56,7 +56,7 @@ set(plasma_LIB_SRCS
animations/slide.cpp animations/slide.cpp
animations/pixmaptransition.cpp animations/pixmaptransition.cpp
animations/pulser.cpp animations/pulser.cpp
animations/pulsershadow.cpp animations/widgetsnapshot.cpp
animations/rotation.cpp animations/rotation.cpp
animations/rotationstacked.cpp animations/rotationstacked.cpp
animations/stackedlayout.cpp animations/stackedlayout.cpp

View File

@ -15,6 +15,7 @@
* Free Software Foundation, Inc., * Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include "widgetsnapshot_p.h"
#include "pulser_p.h" #include "pulser_p.h"
#include <QEvent> #include <QEvent>
@ -25,8 +26,6 @@
#include <kdebug.h> #include <kdebug.h>
#include "pulsershadow_p.h"
namespace Plasma namespace Plasma
{ {
@ -63,7 +62,7 @@ void PulseAnimation::setCopy()
} }
if (!m_under.data()) { if (!m_under.data()) {
m_under = new ShadowFake; m_under = new WidgetSnapShot;
} }
m_under.data()->setTarget(target); m_under.data()->setTarget(target);

View File

@ -29,7 +29,7 @@
namespace Plasma namespace Plasma
{ {
class ShadowFake; class WidgetSnapShot;
/** /**
* @class PulseAnimation plasma/animations/pulser_p.h * @class PulseAnimation plasma/animations/pulser_p.h
@ -96,7 +96,7 @@ private:
/** The shadow copy (it really is a QGraphicsWidget with a pixmap /** The shadow copy (it really is a QGraphicsWidget with a pixmap
* copy of the original widget). * copy of the original widget).
*/ */
QWeakPointer<ShadowFake> m_under; QWeakPointer<WidgetSnapShot> m_under;
}; };
} }

View File

@ -15,18 +15,20 @@
License along with this library. If not, see <http://www.gnu.org/licenses/>. License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "pulsershadow_p.h" #include "widgetsnapshot_p.h"
#include <QPainter> #include <QPainter>
#include <QImage> #include <QImage>
#include <QPixmap> #include <QPixmap>
#include <QStyleOptionGraphicsItem> #include <QStyleOptionGraphicsItem>
#include <QDebug> #include <QDebug>
static const int RECURSION_MAX = 20; static const int RECURSION_MAX = 20;
namespace Plasma namespace Plasma
{ {
ShadowFake::ShadowFake(QGraphicsItem *parent) WidgetSnapShot::WidgetSnapShot(QGraphicsItem *parent)
: QGraphicsWidget(parent), : QGraphicsWidget(parent),
m_iconBig(false), m_iconBig(false),
stack(0), stack(0),
@ -34,19 +36,19 @@ ShadowFake::ShadowFake(QGraphicsItem *parent)
{ {
} }
ShadowFake::~ShadowFake() WidgetSnapShot::~WidgetSnapShot()
{ {
} }
void ShadowFake::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) void WidgetSnapShot::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{ {
Q_UNUSED(widget); Q_UNUSED(widget);
painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::Antialiasing);
painter->drawPixmap(option->exposedRect, m_photo, option->exposedRect); painter->drawPixmap(option->exposedRect, m_snapShot, option->exposedRect);
} }
void ShadowFake::paintSubChildren(QPainter *painter, void WidgetSnapShot::paintSubChildren(QPainter *painter,
const QStyleOptionGraphicsItem *option, const QStyleOptionGraphicsItem *option,
QGraphicsItem *target) QGraphicsItem *target)
{ {
@ -69,7 +71,7 @@ void ShadowFake::paintSubChildren(QPainter *painter,
--stack; --stack;
} }
void ShadowFake::setTarget(QGraphicsWidget *target) void WidgetSnapShot::setTarget(QGraphicsWidget *target)
{ {
stack = 0; stack = 0;
m_target = target; m_target = target;
@ -79,10 +81,10 @@ void ShadowFake::setTarget(QGraphicsWidget *target)
if (m_target->property("iconRepresentation").isValid()) { if (m_target->property("iconRepresentation").isValid()) {
m_iconBig = true; m_iconBig = true;
m_photo = QPixmap::fromImage( m_snapShot = QPixmap::fromImage(
m_target->property("iconRepresentation").value<QImage>()); m_target->property("iconRepresentation").value<QImage>());
if ((m_photo.height() > 0) && (m_photo.width() > 0)) { if ((m_snapShot.height() > 0) && (m_snapShot.width() > 0)) {
resize(m_photo.size()); resize(m_snapShot.size());
setTransformOriginPoint(target->geometry().center()); setTransformOriginPoint(target->geometry().center());
return; return;
} }
@ -90,10 +92,10 @@ void ShadowFake::setTarget(QGraphicsWidget *target)
resize(target->size()); resize(target->size());
m_photo = QPixmap(size); m_snapShot = QPixmap(size);
m_photo.fill(Qt::transparent); m_snapShot.fill(Qt::transparent);
QPainter painter(&m_photo); QPainter painter(&m_snapShot);
painter.setCompositionMode(QPainter::CompositionMode_SourceOver); painter.setCompositionMode(QPainter::CompositionMode_SourceOver);
painter.fillRect(target->rect(), Qt::transparent); painter.fillRect(target->rect(), Qt::transparent);
@ -107,17 +109,20 @@ void ShadowFake::setTarget(QGraphicsWidget *target)
setTransformOriginPoint(geometry().center()); setTransformOriginPoint(geometry().center());
} }
QGraphicsWidget *ShadowFake::target() const QGraphicsWidget *WidgetSnapShot::target() const
{ {
return m_target; return m_target;
} }
bool ShadowFake::isIconBigger() bool WidgetSnapShot::isIconBigger() const
{ {
return m_iconBig; return m_iconBig;
} }
QPixmap WidgetSnapShot::snapShot() const
{
return m_snapShot;
} }
}

View File

@ -15,42 +15,45 @@
License along with this library. If not, see <http://www.gnu.org/licenses/>. License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef PLASMA_PULSERSHADOW_P_H #ifndef PLASMA_WIDGETSNAPSHOT_P_H
#define PLASMA_PULSERSHADOW_P_H #define PLASMA_WIDGETSNAPSHOT_P_H
#include <QGraphicsWidget> #include <QGraphicsWidget>
namespace Plasma namespace Plasma
{ {
class ShadowFake: public QGraphicsWidget class WidgetSnapShot : public QGraphicsWidget
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QGraphicsWidget *target READ target WRITE setTarget) Q_PROPERTY(QGraphicsWidget *target READ target WRITE setTarget)
public: public:
explicit ShadowFake(QGraphicsItem *parent = 0); explicit WidgetSnapShot(QGraphicsItem *parent = 0);
~ShadowFake(); virtual ~WidgetSnapShot();
void setTarget(QGraphicsWidget *target); virtual void setTarget(QGraphicsWidget *target);
QGraphicsWidget *target() const; QGraphicsWidget *target() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, virtual void paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget); QWidget *widget);
bool isIconBigger(); bool isIconBigger() const;
QPixmap snapShot() const;
private: private:
void paintSubChildren(QPainter *painter, void paintSubChildren(QPainter *painter,
const QStyleOptionGraphicsItem *option, const QStyleOptionGraphicsItem *option,
QGraphicsItem *target); QGraphicsItem *target);
bool m_iconBig; bool m_iconBig;
int stack; int stack;
QPixmap m_photo; QPixmap m_snapShot;
QGraphicsWidget *m_target; QGraphicsWidget *m_target;
}; };
} // namespace Plasma
} #endif // PLASMA_WIDGETSNAPSHOT_P_H
#endif // PLASMA_PULSERSHADOW_P_H