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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#include "MainWindow.h"
#include "MapScene.h"
#include "MapView.h"
MainWindow::MainWindow(QWidget* widgetParent) : QWidget(widgetParent)
{
this->setWindowTitle("Test_Qt");
this->resize(200, 200);
nbCall = 0;
this->initMapScene();
this->initMapView();
QHBoxLayout* layout = new QHBoxLayout(this);
layout->addWidget(vue);
QTimer* timer = new QTimer(this);
timer->setSingleShot(false);
timer->setInterval(1000);
timer->start();
QObject::connect(timer, SIGNAL(timeout()), this, SLOT(drawWords()));
this->setLayout(layout);
this->show();
}
MainWindow::~MainWindow()
{
}
bool MainWindow::initMapScene()
{
scene = new MapScene(this);
QRectF surfacescene(-25, -25, 50, 50);
scene->setSceneRect(surfacescene);
QPointF pointOrigin(0, 0);
scene->setPointOrigin(pointOrigin);
return true;
}
bool MainWindow::initMapView()
{
vue = new MapView(scene, this);
vue->setFixedSize(50, 50);
vue->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
vue->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
return true;
}
void MainWindow::drawWords()
{
if (nbCall == 0)
{
QLineF line(0, 0, 0, 10);
this->drawLine(line);
}
else if (nbCall == 1)
{
QLineF line(0, 0, -10, 0);
this->drawLine(line);
}
else if (nbCall == 2)
{
QLineF line(0, 0, 0, -10);
this->drawLine(line);
}
else if (nbCall == 3)
{
QLineF line(0, 0, 10, 0);
this->drawLine(line);
}
else
{
QLineF line(0, 0, 0, 10);
this->drawLine(line);
}
++nbCall;
}
void MainWindow::drawLine(QLineF &line)
{
QPointF linePoint1 = line.p1();
QPointF linePoint2 = line.p2();
QPointF point1 = scene->pointStandart(linePoint1);
QPointF point2 = scene->pointStandart(linePoint2);
QLineF line2(point1, point2);
//QPen pen(Qt::blue, 5, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin);
scene->addLine(line2);
} |
Partager