-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.cpp
62 lines (46 loc) · 1.32 KB
/
view.cpp
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
#include "view.h"
#include <QDebug>
View::View(QObject *parent, QGraphicsView *view, qreal width, qreal height) :
QObject(parent)
{
this->view = view;
Viewheight = height;
Viewwidth = width;
//view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers))); //GPU rendering :)
scene = new QGraphicsScene();
scene->setSceneRect( 0, 0, 800, 600 );
view->setScene(scene);
scene->addRect(scene->sceneRect(), QPen(QBrush(QColor("White")),2));
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()),scene, SLOT(advance()));
timer->start(200);
//view->setRenderHints( QPainter::Antialiasing );
#ifndef YOCTO
resizeHandler();
#endif
}
void View::setBackground(QColor color){
view->setBackgroundBrush(QBrush(color));
}
void View::addItem(QGraphicsItem * item){
scene->addItem(item);
}
void View::removeItem(QGraphicsItem * item){
scene->removeItem(item);
}
void View::resizeHandler(){
view->fitInView( scene->sceneRect(), Qt::KeepAspectRatio );
}
void View::resizeView(qreal width, qreal height){
Viewwidth = width;
Viewheight = height;
scene->setSceneRect( 0.0, 0.0, width, height );
rectangleView->setRect(0,0,width,height);
resizeHandler();
}
qreal View::getViewHeight(){
return Viewheight;
}
qreal View::getViewWidth(){
return Viewwidth;
}