#ifndef ANIMATEICON_H
#define ANIMATEICON_H
#include <QObject>
#include <QGraphicsItem>
#include <QRectF>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QWidget>
#include <QTimeLine>
#include <QGraphicsItemAnimation>
{
Q_OBJECT
public:
_width = width;
_height = height;
_animation->setItem(this);
_animation->setTimeLine(_timeLine);
for (int i = 0; i <= 360; i+=18)
_animation->setRotationAt(i/360.0, i);
_timeLine
->setCurveShape
(QTimeLine::LinearCurve);
_timeLine->setLoopCount(0);
_timeLine->start();
}
~AnimateIcon(void){}
QRectF boundingRect
(void) const{ return QRectF(0,
0, _width, _height
);
}
painter
->drawPixmap
(0,
0, _width, _height,
QPixmap(":/icons/action.png"));
}
private:
int _width;
int _height;
};
#endif
#ifndef ANIMATEICON_H
#define ANIMATEICON_H
#include <QObject>
#include <QGraphicsItem>
#include <QRectF>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QWidget>
#include <QTimeLine>
#include <QGraphicsItemAnimation>
class AnimateIcon : public QObject, public QGraphicsItem
{
Q_OBJECT
public:
AnimateIcon(QGraphicsItem *parent = 0, int width = 48, int height = 48) : QGraphicsItem(parent){
_width = width;
_height = height;
_animation = new QGraphicsItemAnimation(this);
_timeLine = new QTimeLine(10000, this);
_animation->setItem(this);
_animation->setTimeLine(_timeLine);
for (int i = 0; i <= 360; i+=18)
_animation->setRotationAt(i/360.0, i);
_timeLine->setCurveShape(QTimeLine::LinearCurve);
_timeLine->setLoopCount(0);
_timeLine->start();
}
~AnimateIcon(void){}
QRectF boundingRect(void) const{
return QRectF(0, 0, _width, _height);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem * option, QWidget *widget = 0){
painter->drawPixmap(0, 0, _width, _height,QPixmap(":/icons/action.png"));
}
private:
int _width;
int _height;
QGraphicsItemAnimation *_animation;
QTimeLine *_timeLine;
};
#endif
To copy to clipboard, switch view to plain text mode
Bookmarks