]> rtime.felk.cvut.cz Git - orte.git/blob - orte/contrib/shape/MyQFrame.cpp
orte 0.3.2 release
[orte.git] / orte / contrib / shape / MyQFrame.cpp
1 /****************************************************************
2 **
3 ** Implementation MyQFrame class
4 **
5 ****************************************************************/
6
7 #include "MyQFrame.h"
8 #include <QPolygon>
9 #include <QMouseEvent>
10 #include <QPaintEvent>
11
12 MyQFrame::MyQFrame( QWidget *parent)
13         : QFrame( parent)
14 {
15     mousePressed=0;
16     objects[0]=objects[1]=objects[2]=objects[3]=objects[4]=0;
17 }
18
19
20 void MyQFrame::activateObject(int object,int color, int shape) {
21     if (object>4) return;
22     objects[object]=1;
23     switch(color) {
24         case 0:colors[object]=QColor(0,0,255);break;
25         case 1:colors[object]=QColor(0,255,0);break;
26         case 2:colors[object]=QColor(255,0,0);break;
27         case 3:colors[object]=QColor(0,0,0);break;
28         case 4:colors[object]=QColor(255,255,0);break;
29     }
30     shapes[object]=shape;
31 }
32
33 void MyQFrame::deactivateObject(int object) {
34     if (object>4) return;
35     objects[object]=0;
36     update();
37 }
38
39 void MyQFrame::setPosition(int object,QRect position) {
40     positions[object]=position;
41     update();
42 }
43
44 void MyQFrame::paintEvent(QPaintEvent*)
45 {
46     QPainter p(this);
47         
48     for(int i=0;i<5;i++) {
49         if (!objects[i]) continue;
50         p.setBrush(colors[i]);
51         p.setPen(Qt::NoPen);
52         switch(shapes[i]){
53             case 0://rectangle
54                 p.drawRect(positions[i]);
55                 break;
56             case 1: //ellipse
57                 p.drawEllipse(positions[i]);
58                 break;
59             case 2: //triangle
60                 QPolygon pt;
61                 pt.putPoints(0,3, positions[i].center().x(),positions[i].top(), 
62                                   positions[i].right(),positions[i].bottom(), 
63                                   positions[i].left(),positions[i].bottom());
64                 p.drawPolygon(pt);
65                 break;
66         }
67         QString strPos;
68         strPos="X:" + QString::number(positions[i].center().x())+" " +
69                "Y:"+QString::number(positions[i].center().y());
70         p.drawText(positions[i].left()-(70-positions[i].width())/2,positions[i].top()-1,strPos);
71     }
72
73 }
74
75 void MyQFrame::mouseMoveEvent(QMouseEvent *e)
76 {
77     if(mousePressed==0) return; 
78     mouseX=e->pos().x();
79     mouseY=e->pos().y();
80 }
81
82 void MyQFrame::mousePressEvent (QMouseEvent *e)
83 {
84     mousePressed=1;
85     mouseX=e->pos().x();
86     mouseY=e->pos().y();
87 }
88
89 void MyQFrame::mouseReleaseEvent (QMouseEvent *)
90 {
91     mousePressed=0;
92 }