Fix validity check to account for drop moves.
[tagua/yd.git] / tests / test_canvas.cpp
blobf1775e3691559c3d4b752b64a9c054f7638add99
1 #include <QApplication>
2 #include <QMouseEvent>
3 #include <QPainter>
4 #include "canvas.h"
7 class Puppas : public Canvas
9 CanvasItem *ppp;
10 QPoint delta;
11 public:
12 Puppas(QWidget *p = NULL) : Canvas(p), ppp(NULL) {}
13 virtual ~Puppas(){}
14 virtual void keyPressEvent ( QKeyEvent * event )
16 if(event->key() == Qt::Key_Tab)
17 (*items())[0]->raise();
19 virtual void mousePressEvent ( QMouseEvent * event )
21 ppp = itemAt(event->pos());
22 if(ppp)
24 delta = ppp->pos() - event->pos();
25 if(event->button() == Qt::LeftButton)
26 ppp->raise();
29 virtual void mouseMoveEvent ( QMouseEvent * event )
31 if(ppp)
32 ppp->moveTo(event->pos() + delta );
36 QPicture make_pic()
38 QPicture pic;
39 QPainter p(&pic);
40 p.setPen(Qt::yellow);
41 p.setBrush(Qt::darkGreen);
42 p.drawEllipse(0,0,200,100);
44 return pic;
47 /*QPixmap tp(QPixmap px)
49 QPixmap retv(px.size);
50 QPainter p(retv);
52 return retv;
53 }*/
55 int main(int argc, char *argv[])
57 QApplication app(argc, argv);
59 Canvas *c = new Puppas();
60 c->resize(500,500);
62 CanvasGroup *cg = new CanvasGroup( c );
63 cg->moveTo(0,0);
64 cg->show();
66 CanvasPixmap *p = new CanvasPixmap( QPixmap(
67 "/home/monge/chess_pieces/out/img_fantasy/kboard_theme/white_rook.png"), cg );
68 p->moveTo(0,0);
69 p->show();
71 CanvasPixmap *p2 = new CanvasPixmap( QPixmap(
72 "/home/monge/chess_pieces/out/img_skulls/kboard_theme/black_bishop.png"), cg );
73 p2->moveTo(200,50);
74 p2->show();
76 CanvasPixmap *p3 = new CanvasPixmap( QPixmap(
77 "/home/monge/chess_pieces/out/img_freak/kboard_theme/white_knight.png"), c );
78 p3->moveTo(100,250);
79 p3->show();
81 CanvasPixmap *p4 = new CanvasPixmap( QPixmap(
82 "/home/monge/chess_pieces/out/img_spatial/kboard_theme/black_king.png"), c );
83 p4->moveTo(20,150);
84 p4->show();
86 CanvasPixmap *p5 = new CanvasPixmap( QPixmap(
87 "/home/monge/chess_pieces/out/img_prmi/kboard_theme/white_queen.png"), c );
88 p5->moveTo(300,200);
89 p5->show();
91 CanvasTiledPixmap *p6 = new CanvasTiledPixmap( QPixmap(
92 "/home/monge/chess_pieces/out/icons/20/r.png"),
93 QSize(200,150), QPoint(0,0), false, c );
94 p6->moveTo(200,100);
95 p6->show();
97 CanvasRectangle *p7 = new CanvasRectangle( QColor(255,0,0,192), QSize(200,150), c );
98 p7->moveTo(50,350);
99 p7->show();
101 CanvasRectangle *p8a = new CanvasRectangle( QColor(128,128,0,255), QSize(1,200), c );
102 p8a->moveTo(200,0);
103 p8a->show();
105 CanvasRectangle *p8b = new CanvasRectangle( QColor(0,128,0,255), QSize(300,1), c );
106 p8b->moveTo(100,80);
107 p8b->show();
109 CanvasText *p8 = new CanvasText( "Fuck", QColor(0,0,255,192),
110 QFont("Sans", 70, QFont::Bold),
111 CanvasText::HCenter, CanvasText::VCenter, c );
112 p8->moveTo(200,80);
113 p8->show();
115 CanvasPicture *p9 = new CanvasPicture( make_pic(), c );
116 p9->moveTo(200,100);
117 p9->show();
119 c->show();
121 return app.exec();