File: test_canvas.cpp

package info (click to toggle)
tagua 1.0~alpha2-15
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 8,028 kB
  • ctags: 7,178
  • sloc: cpp: 26,149; ansic: 13,039; makefile: 182; ruby: 87; sh: 39
file content (122 lines) | stat: -rw-r--r-- 3,154 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <QApplication>
#include <QMouseEvent>
#include <QPainter>
#include "canvas.h"


class Puppas : public Canvas
{
    CanvasItem *ppp;
    QPoint delta;
public:
    Puppas(QWidget *p = NULL) : Canvas(p), ppp(NULL) {}
    virtual ~Puppas(){}
    virtual void keyPressEvent ( QKeyEvent * event )
    {
        if(event->key() == Qt::Key_Tab)
            (*items())[0]->raise();
    }
    virtual void mousePressEvent ( QMouseEvent * event )
    {
        ppp = itemAt(event->pos());
        if(ppp)
        {
            delta = ppp->pos() - event->pos();
            if(event->button() == Qt::LeftButton)
                ppp->raise();
        }
    }
    virtual void mouseMoveEvent ( QMouseEvent * event )
    {
        if(ppp)
          ppp->moveTo(event->pos() + delta );
    }
};

QPicture make_pic()
{
    QPicture pic;
    QPainter p(&pic);
    p.setPen(Qt::yellow);
    p.setBrush(Qt::darkGreen);
    p.drawEllipse(0,0,200,100);

    return pic;
}

/*QPixmap tp(QPixmap px)
{
    QPixmap retv(px.size);
    QPainter p(retv);

    return retv;
}*/

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    Canvas *c = new Puppas();
    c->resize(500,500);

    CanvasGroup *cg = new CanvasGroup( c );
    cg->moveTo(0,0);
    cg->show();

    CanvasPixmap *p = new CanvasPixmap( QPixmap(
        "/home/monge/chess_pieces/out/img_fantasy/kboard_theme/white_rook.png"), cg );
    p->moveTo(0,0);
    p->show();

    CanvasPixmap *p2 = new CanvasPixmap( QPixmap(
        "/home/monge/chess_pieces/out/img_skulls/kboard_theme/black_bishop.png"), cg );
    p2->moveTo(200,50);
    p2->show();

    CanvasPixmap *p3 = new CanvasPixmap( QPixmap(
        "/home/monge/chess_pieces/out/img_freak/kboard_theme/white_knight.png"), c );
    p3->moveTo(100,250);
    p3->show();

    CanvasPixmap *p4 = new CanvasPixmap( QPixmap(
        "/home/monge/chess_pieces/out/img_spatial/kboard_theme/black_king.png"), c );
    p4->moveTo(20,150);
    p4->show();

    CanvasPixmap *p5 = new CanvasPixmap( QPixmap(
        "/home/monge/chess_pieces/out/img_prmi/kboard_theme/white_queen.png"), c );
    p5->moveTo(300,200);
    p5->show();

    CanvasTiledPixmap *p6 = new CanvasTiledPixmap( QPixmap(
        "/home/monge/chess_pieces/out/icons/20/r.png"),
        QSize(200,150), QPoint(0,0), false, c );
    p6->moveTo(200,100);
    p6->show();

    CanvasRectangle *p7 = new CanvasRectangle( QColor(255,0,0,192), QSize(200,150), c );
    p7->moveTo(50,350);
    p7->show();
/*
    CanvasRectangle *p8a = new CanvasRectangle( QColor(128,128,0,255), QSize(1,200), c );
    p8a->moveTo(200,0);
    p8a->show();

    CanvasRectangle *p8b = new CanvasRectangle( QColor(0,128,0,255), QSize(300,1), c );
    p8b->moveTo(100,80);
    p8b->show();
*/
    CanvasText *p8 = new CanvasText( "Fuck", QColor(0,0,255,192),
                                    QFont("Sans", 70, QFont::Bold),
                                    CanvasText::HCenter, CanvasText::VCenter, c );
    p8->moveTo(200,80);
    p8->show();

    CanvasPicture *p9 = new CanvasPicture( make_pic(), c );
    p9->moveTo(200,100);
    p9->show();

    c->show();

    return app.exec();
}