#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsScene>
#include <QGraphicsLineItem>
#include <QEvent>
#include <QDropEvent>
#include <QSignalMapper>
#include <QMouseEvent>
#include <QtDebug>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
view = new QGV;
MainWindow::setCentralWidget(view);
view->setMouseTracking(true);
QObject::connect(ui
->action_Line,
SIGNAL(triggered
()),
this,
SLOT(criarLinha
()));
QObject::connect(view,
SIGNAL(changeFinalPosition
(qreal,qreal
)),
this,
SLOT(FinalPosition
(qreal,qreal
)));
i = 0;
x1 = 0;
y1 = 0;
x2 = 0;
y2 = 0;
//scene->installEventFilter(view);
view->setScene(scene);
}
MainWindow::~MainWindow()
{
delete ui;
}
// Pulbic Functions
void MainWindow::createLine()
{
int chave = 1;
scene->addItem(linha);
qDebug() << "Entrei" << i;
while((chave == 1))
{
if(i == 1)
{
linha->setLine(x1,y1,x2,y2);
}
else if (i == 2)
{
linha->setLine(x1,y1,x2,y2);
chave = false;
i=0;
}
}
qDebug() << "saÃ*";
}
{
if((event->button() == Qt::LeftButton))
{
if(i == 0)
{
x1 = dynamic_cast<QMouseEvent*>(event)->x();
y1 = dynamic_cast<QMouseEvent*>(event)->y();
i=1;
}
else if (i == 1)
{
x2 = dynamic_cast<QMouseEvent*>(event)->x();
y2 = dynamic_cast<QMouseEvent*>(event)->y();
i=2;
}
}
}
//Public Slots
void MainWindow::criarLinha()
{
x1 = 0;
y1 = 0;
x2 = 0;
y2 = 0;
i = 0;
qDebug() << "pronto pra começar:" << x1 << y1 << x2 << y2;
createLine();
}
void MainWindow::FinalPosition(qreal x, qreal y)
{
if (!(x2 == x))
x2 = x;
else if (!(y2 == y))
y2 = y;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QGraphicsScene>
#include <QGraphicsLineItem>
#include <QEvent>
#include <QDropEvent>
#include <QSignalMapper>
#include <QMouseEvent>
#include <QtDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
view = new QGV;
MainWindow::setCentralWidget(view);
view->setMouseTracking(true);
QObject::connect(ui->action_Line,SIGNAL(triggered()),this,SLOT(criarLinha()));
QObject::connect(view,SIGNAL(changeFinalPosition(qreal,qreal)),this,SLOT(FinalPosition(qreal,qreal)));
i = 0;
x1 = 0;
y1 = 0;
x2 = 0;
y2 = 0;
scene = new QGraphicsScene;
//scene->installEventFilter(view);
view->setScene(scene);
}
MainWindow::~MainWindow()
{
delete ui;
}
// Pulbic Functions
void MainWindow::createLine()
{
int chave = 1;
QGraphicsLineItem *linha = new QGraphicsLineItem(x1,y1,x2,y2);
scene->addItem(linha);
qDebug() << "Entrei" << i;
while((chave == 1))
{
if(i == 1)
{
linha->setLine(x1,y1,x2,y2);
}
else if (i == 2)
{
linha->setLine(x1,y1,x2,y2);
chave = false;
i=0;
}
}
qDebug() << "saÃ*";
}
void MainWindow::mousePressEvent(QMouseEvent *qme1)
{
QMouseEvent *event = static_cast<QMouseEvent *>(qme1);
if((event->button() == Qt::LeftButton))
{
if(i == 0)
{
x1 = dynamic_cast<QMouseEvent*>(event)->x();
y1 = dynamic_cast<QMouseEvent*>(event)->y();
i=1;
}
else if (i == 1)
{
x2 = dynamic_cast<QMouseEvent*>(event)->x();
y2 = dynamic_cast<QMouseEvent*>(event)->y();
i=2;
}
}
}
//Public Slots
void MainWindow::criarLinha()
{
x1 = 0;
y1 = 0;
x2 = 0;
y2 = 0;
i = 0;
qDebug() << "pronto pra começar:" << x1 << y1 << x2 << y2;
createLine();
}
void MainWindow::FinalPosition(qreal x, qreal y)
{
if (!(x2 == x))
x2 = x;
else if (!(y2 == y))
y2 = y;
}
To copy to clipboard, switch view to plain text mode
Bookmarks