]> rtime.felk.cvut.cz Git - orte.git/blob - orte/contrib/shape/ViewFrm.cpp
Added prerelease of ORTE-0.2 (Real Time Publisher Subscriber communication protocol...
[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::SetShape(char shape)
19 {
20         m_shape=shape;
21 }
22
23 void View_Frame::SetShapeColor(char color)
24 {
25         switch(color)
26         {
27         case BLUE:
28                 m_shapeColor=QColor(0,0,255);
29                 break;
30         case GREEN:
31                 m_shapeColor=QColor(0,255,0);
32                 break;
33         case RED:
34                 m_shapeColor=QColor(255,0,0);
35                 break;
36         case BLACK:
37                 m_shapeColor=QColor(0,0,0);
38                 break;
39         }
40 }
41
42 void View_Frame::SetShapeRect(QRect rect)
43 {
44         m_shapeRect=rect;
45         repaint();
46 }
47
48 void View_Frame::paintEvent(QPaintEvent*)
49 {
50         QPainter p(this);
51         
52         p.setBrush(m_shapeColor);
53         p.setPen(NoPen);
54
55
56         switch(m_shape)
57         {
58         case RECTANGLE:
59                 p.drawRect(m_shapeRect);
60                 break;
61         case ELLIPSE:
62                 p.drawEllipse(m_shapeRect);
63                 break;
64         case TRIANGLE:
65                 QPointArray pt(3);
66                 pt.putPoints(0,3, m_shapeRect.center().x(),m_shapeRect.top(), m_shapeRect.right(),m_shapeRect.bottom(), m_shapeRect.left(),m_shapeRect.bottom());
67                 p.drawPolygon(pt);
68                 break;
69         }
70
71         QString strPos;
72         
73         strPos="X:" + QString::number(m_shapeRect.center().x())+"  Y:"+QString::number(m_shapeRect.center().y());
74         
75         p.drawText(m_shapeRect.left()-(70-m_shapeRect.width())/2,m_shapeRect.top()-1,strPos);
76 }
77
78 void View_Frame::mouseMoveEvent(QMouseEvent *e)
79 {
80         if(m_mousePressed==0) return;
81         
82         m_mouseX=e->pos().x();
83         m_mouseY=e->pos().y();
84 }
85
86 void View_Frame::mousePressEvent ( QMouseEvent * e)
87 {
88         m_mousePressed=1;
89         m_mouseX=e->pos().x();
90         m_mouseY=e->pos().y();
91 }
92
93 void View_Frame::mouseReleaseEvent ( QMouseEvent * )
94 {
95         m_mousePressed=0;
96 }