#include <QApplication>
#include <QGraphicsEllipseItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <qdatetime.h>
#include <qmainwindow.h>
#include <qstatusbar.h>
#include <qmessagebox.h>
#include <qmenubar.h>
#include <qapplication.h>
#include <qpainter.h>
#include <qprinter.h>
#include <qlabel.h>
#include <qimage.h>
#include <qpixmap.h>
#include <QMouseEvent>
#include <QStyleOptionGraphicsItem>
#include <qdebug.h>
#include <stdlib.h>
#include <qtimer.h>
int xOffset;
int yOffset;
static const int imageRTTI = 984376;
{
qDebug(s.toAscii());
}
{
public:
mapScene();
protected:
void dragMoveEvent ( QGraphicsSceneDragDropEvent * event );
};
mapScene::mapScene()
{
xOffset =0;
yOffset =0;
}
void mapScene::dragMoveEvent( QGraphicsSceneDragDropEvent * event)
{
debug("I vus here!");
xOffset = 1;
yOffset = 1;
}
{
public:
int rtti () const { return imageRTTI; }
void advance(int phase);
protected:
private:
int state;
};
void ImageItem::advance(int phase)
{
moveBy(xOffset,yOffset);
}
ImageItem
::ImageItem( QImage img
) : image(img)
{
state = 0;
setRect(0, 0, image.width(), image.height());
setFlag(ItemIsMovable);
#if !defined(Q_WS_QWS)
pixmap = pixmap.fromImage(image, Qt::OrderedAlphaDither);
#endif
}
{
// On Qt/Embedded, we can paint a QImage as fast as a QPixmap,
// but on other platforms, we need to use a QPixmap.
#if defined(Q_WS_QWS)
p->drawImage( option->exposedRect, image, option->exposedRect, Qt::OrderedAlphaDither );
#else
p->drawPixmap( option->exposedRect, pixmap, option->exposedRect );
#endif
}
int main( int argc, char **argv )
{
mapScene scene;
scene.setSceneRect( -100.0, -100.0, 200.0, 200.0 );
myImg->load(myImgName);
scene.addItem(i);
i->setPos(-50,-50);
QObject::connect(&timer,
SIGNAL(timeout
()),
&scene,
SLOT(advance
()));
timer.start(100);
view.
setRenderHints( QPainter::Antialiasing );
view.show();
return app.exec();
}
#include <QApplication>
#include <QGraphicsEllipseItem>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <qdatetime.h>
#include <qmainwindow.h>
#include <qstatusbar.h>
#include <qmessagebox.h>
#include <qmenubar.h>
#include <qapplication.h>
#include <qpainter.h>
#include <qprinter.h>
#include <qlabel.h>
#include <qimage.h>
#include <qpixmap.h>
#include <QMouseEvent>
#include <QStyleOptionGraphicsItem>
#include <qdebug.h>
#include <stdlib.h>
#include <qtimer.h>
QString myImgName = "myimg.png";
static QImage *myImg;
int xOffset;
int yOffset;
static const int imageRTTI = 984376;
void debug(QString s)
{
qDebug(s.toAscii());
}
class mapScene: public QGraphicsScene
{
public:
mapScene();
QPoint prevMousePoint;
QPoint currMousePoint;
protected:
void dragMoveEvent ( QGraphicsSceneDragDropEvent * event );
};
mapScene::mapScene()
{
xOffset =0;
yOffset =0;
}
void mapScene::dragMoveEvent( QGraphicsSceneDragDropEvent * event)
{
debug("I vus here!");
xOffset = 1;
yOffset = 1;
}
class ImageItem: public QGraphicsRectItem
{
public:
ImageItem( QImage img );
int rtti () const { return imageRTTI; }
void advance(int phase);
protected:
void paint( QPainter *, const QStyleOptionGraphicsItem *option, QWidget *widget );
private:
QImage image;
QPixmap pixmap;
int state;
};
void ImageItem::advance(int phase)
{
moveBy(xOffset,yOffset);
}
ImageItem::ImageItem( QImage img )
: image(img)
{
state = 0;
setRect(0, 0, image.width(), image.height());
setFlag(ItemIsMovable);
#if !defined(Q_WS_QWS)
pixmap = pixmap.fromImage(image, Qt::OrderedAlphaDither);
#endif
}
void ImageItem::paint( QPainter *p, const QStyleOptionGraphicsItem *option, QWidget * )
{
// On Qt/Embedded, we can paint a QImage as fast as a QPixmap,
// but on other platforms, we need to use a QPixmap.
#if defined(Q_WS_QWS)
p->drawImage( option->exposedRect, image, option->exposedRect, Qt::OrderedAlphaDither );
#else
p->drawPixmap( option->exposedRect, pixmap, option->exposedRect );
#endif
}
int main( int argc, char **argv )
{
QApplication app(argc, argv);
mapScene scene;
scene.setSceneRect( -100.0, -100.0, 200.0, 200.0 );
myImg = new QImage;
myImg->load(myImgName);
QAbstractGraphicsShapeItem* i = new ImageItem(*myImg);
scene.addItem(i);
i->setPos(-50,-50);
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), &scene, SLOT(advance()));
timer.start(100);
QGraphicsView view( &scene );
view.setRenderHints( QPainter::Antialiasing );
view.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks