]> rtime.felk.cvut.cz Git - orte.git/blob - orte/contrib/shape/ViewFrm.cpp
OCERA SF CVS tree of ORTE framework updated to
[orte.git] / orte / contrib / shape / ViewFrm.cpp
1 /****************************************************************
2 **
3 ** Implementation View_Frame class
4 **
5 ****************************************************************/
6
7 #include "ViewFrm.h"
8 #include <qpainter.h>
9 #include <qstring.h>
10
11 View_Frame::View_Frame( QWidget *parent, const char *name )
12         : QWidget( parent, name )
13 {
14         setBackgroundColor(QColor( 255, 255, 255)  );
15         m_mousePressed=0;
16 }
17
18 void View_Frame::SetActiveObject(char object)
19 {
20   active_object[object]=1;
21 }
22
23
24 void View_Frame::ShapeColorRect(char object,char shape,char color,QRect rect)
25 {
26         m_shape[object]=shape;
27
28         switch(color)
29         {
30         case BLUE:
31                 m_shapeColor[object]=QColor(0,0,255);
32                 break;
33         case GREEN:
34                 m_shapeColor[object]=QColor(0,255,0);
35                 break;
36         case RED:
37                 m_shapeColor[object]=QColor(255,0,0);
38                 break;
39         case BLACK:
40                 m_shapeColor[object]=QColor(0,0,0);
41                 break;
42         }
43
44         m_shapeRect[object]=rect;
45         repaint();
46 }
47
48 void View_Frame::paintEvent(QPaintEvent*)
49 {
50         QPainter p(this);
51         
52         for(int i=0;i<5;i++) {
53             if (!active_object[i]) continue;
54             p.setBrush(m_shapeColor[i]);
55             p.setPen(NoPen);
56             switch(m_shape[i])
57             {
58             case RECTANGLE:
59                 p.drawRect(m_shapeRect[i]);
60                 break;
61             case ELLIPSE:
62                 p.drawEllipse(m_shapeRect[i]);
63                 break;
64             case TRIANGLE:
65                 QPointArray pt(3);
66                 pt.putPoints(0,3, m_shapeRect[i].center().x(),m_shapeRect[i].top(), 
67                                   m_shapeRect[i].right(),m_shapeRect[i].bottom(), 
68                                   m_shapeRect[i].left(),m_shapeRect[i].bottom());
69                 p.drawPolygon(pt);
70                 break;
71             }
72             QString strPos;
73             strPos="X:" + QString::number(m_shapeRect[i].center().x())+
74                    "  Y:"+QString::number(m_shapeRect[i].center().y());
75             p.drawText(m_shapeRect[i].left()-(70-m_shapeRect[i].width())/2,m_shapeRect[i].top()-1,strPos);
76         }
77
78 }
79
80 void View_Frame::mouseMoveEvent(QMouseEvent *e)
81 {
82         if(m_mousePressed==0) return;
83         
84         m_mouseX=e->pos().x();
85         m_mouseY=e->pos().y();
86 }
87
88 void View_Frame::mousePressEvent ( QMouseEvent * e)
89 {
90         m_mousePressed=1;
91         m_mouseX=e->pos().x();
92         m_mouseY=e->pos().y();
93 }
94
95 void View_Frame::mouseReleaseEvent ( QMouseEvent * )
96 {
97         m_mousePressed=0;
98 }