1 /****************************************************************
3 ** Implementation MyQFrame class
5 ****************************************************************/
10 #include <QPaintEvent>
11 #include <QWheelEvent>
14 MyQFrame::MyQFrame( QWidget *parent)
18 objects[0]=objects[1]=objects[2]=objects[3]=objects[4]=0;
19 rotations[0]=rotations[1]=rotations[2]=rotations[3]=rotations[4]=0;
20 zooms[0]=zooms[1]=zooms[2]=zooms[3]=zooms[4]=1;
25 setFocusPolicy(Qt::StrongFocus);
27 connect(this,SIGNAL(changed()),this,SLOT(update()));
31 void MyQFrame::activateObject(int object,int color, int shape) {
35 case 0:colors[object]=QColor(0,0,255);break;
36 case 1:colors[object]=QColor(0,255,0);break;
37 case 2:colors[object]=QColor(255,0,0);break;
38 case 3:colors[object]=QColor(0,0,0);break;
39 case 4:colors[object]=QColor(255,255,0);break;
44 void MyQFrame::deactivateObject(int object) {
50 void MyQFrame::setPosition(int object,QRect position) {
51 positions[object]=position;
55 void MyQFrame::setZoom(int object,double zoom) {
60 void MyQFrame::setRotation(int object,int rotation) {
61 rotations[object]=rotation;
65 void MyQFrame::paintEvent(QPaintEvent*)
69 for(int i=0;i<5;i++) {
70 if (!objects[i]) continue;
71 p.setBrush(colors[i]);
75 p.translate(positions[i].center().x(),positions[i].center().y());
76 p.rotate(rotations[i]);
77 p.scale(zooms[i],zooms[i]);
81 p.drawRect(positions[i].topLeft().x()-positions[i].center().x(),
82 positions[i].topLeft().y()-positions[i].center().y(),
83 positions[i].width(), positions[i].height());
86 p.drawEllipse(positions[i].topLeft().x()-positions[i].center().x(),
87 positions[i].topLeft().y()-positions[i].center().y(),
88 positions[i].width(), positions[i].height());
92 pt.putPoints(0,3, 0, positions[i].top()-positions[i].center().y(),
93 positions[i].right()-positions[i].center().x(),positions[i].bottom()-positions[i].center().y(),
94 positions[i].left()-positions[i].center().x(),positions[i].bottom()-positions[i].center().y());
101 strPos="X:" + QString::number(positions[i].center().x())+" " +
102 "Y:"+QString::number(positions[i].center().y());
103 p.drawText(positions[i].left()-(70-positions[i].width())/2,positions[i].top()-1,strPos);
108 void MyQFrame::mouseMoveEvent(QMouseEvent *e)
110 if(mousePressed==0) return;
115 void MyQFrame::mousePressEvent (QMouseEvent *e)
122 void MyQFrame::mouseReleaseEvent (QMouseEvent *)
127 void MyQFrame::wheelEvent (QWheelEvent *e)
130 wheel_delta += e->delta()/12;
132 scale_factor += (double)e->delta()/600;
136 void MyQFrame::keyPressEvent (QKeyEvent *e)
138 if (e->key() == Qt::Key_Control)
141 QFrame::keyPressEvent(e);
144 void MyQFrame::keyReleaseEvent (QKeyEvent *e)
146 if (e->key() == Qt::Key_Control)
149 QFrame::keyPressEvent(e);