-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwireframefield.cpp
More file actions
77 lines (61 loc) · 2.39 KB
/
wireframefield.cpp
File metadata and controls
77 lines (61 loc) · 2.39 KB
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
#include "wireframefield.h"
#include <iostream>
#include <QMouseEvent>
#include <QScrollBar>
#include <QGraphicsItem>
WireFrameField::WireFrameField(QWidget* parent, WireFrameRModel* model):
QGraphicsView(parent), model(model), scene(new QGraphicsScene(this)), item_on_scene(nullptr),
current_width(model->getImage()->width()), current_height(model->getImage()->height()), isMousePressed(false)
{
model->setView(this);
this->setScene(scene);
scene->setSceneRect(0, 0, current_width, current_height);
QPixmap pic = QPixmap::fromImage(*model->getImage());
item_on_scene = reinterpret_cast<QGraphicsItem*>(scene->addPixmap(pic));
}
void WireFrameField::mousePressEvent(QMouseEvent *event){
int posX = event->x() + this->horizontalScrollBar()->value();
int posY = event->y() + this->verticalScrollBar()->value();
if (event->button() == Qt::MouseButton::LeftButton){
isMousePressed = true;
prevMouseX = posX;
prevMouseY = posY;
}
QGraphicsView::mousePressEvent(event);
}
void WireFrameField::mouseReleaseEvent(QMouseEvent *event){
if (event->button() == Qt::MouseButton::LeftButton){
isMousePressed = false;
}
QGraphicsView::mouseReleaseEvent(event);
}
void WireFrameField::mouseMoveEvent(QMouseEvent *event){
if (isMousePressed){
int posX = event->x() + this->horizontalScrollBar()->value();
int posY = event->y() + this->verticalScrollBar()->value();
model->moveEngleByMouse(-posX + prevMouseX, -posY + prevMouseY);
prevMouseX = posX;
prevMouseY = posY;
}
QGraphicsView::mouseMoveEvent(event);
}
void WireFrameField::onModelChange(){
int width = model->getImage()->width();
int height = model->getImage()->height();
if (current_height != height || current_width != width){
current_width = width;
current_height = height;
scene->setSceneRect(0,0, current_width + 2, current_height + 2);
}
scene->removeItem(item_on_scene);
delete item_on_scene;
QPixmap pic = QPixmap::fromImage(*model->getImage());
item_on_scene = reinterpret_cast<QGraphicsItem*>(scene->addPixmap(pic));
}
void WireFrameField::resizeEvent(QResizeEvent *event){
model->setSize(event->size().height() - 2, event->size().width() - 2);
}
void WireFrameField::wheelEvent(QWheelEvent* event){
QPoint delta = event->angleDelta() / 8;
model->zoom(delta.y());
}