-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage.cpp
More file actions
111 lines (95 loc) · 2.73 KB
/
page.cpp
File metadata and controls
111 lines (95 loc) · 2.73 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include "page.h"
#include <QPainter>
#include <QGraphicsSceneMouseEvent>
#include "commonitemmecs.h"
#include "project.h"
#include "pageproperties.h"
#include <QMetaProperty>
#ifndef QT_NO_OPENGL
#include <QtOpenGLDepends>
#include <QtWidgets/QWidget>
#include <QtOpenGLExtensions/QOpenGLExtensions>
#endif
Page::Page():
m_name("Main")
{
Refresh();
}
void Page::Refresh()
{
SCENE_HEIGHT = 900;
SCENE_WIDTH = 1800;
addRect(0, 0, SCENE_WIDTH, SCENE_HEIGHT);
for (int i = CommonItemMECS::stepOfGrid; i < SCENE_WIDTH; i += CommonItemMECS::stepOfGrid)
addLine(i, 0, i, SCENE_HEIGHT);
for (int i = CommonItemMECS::stepOfGrid; i < SCENE_HEIGHT; i += CommonItemMECS::stepOfGrid)
addLine(0, i, SCENE_WIDTH, i);
}
Page::Page(QString Name, QString Background)
{
Refresh();
SetName(Name);
SetBackground(Background);
}
QGraphicsView *Page::GenerateGraphicsView()
{
QGraphicsView *graphicsView = new QGraphicsView();
graphicsView->setRenderHint(QPainter::Antialiasing, false);
graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
graphicsView->setOptimizationFlags(QGraphicsView::DontSavePainterState);
graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
#ifndef QT_NO_OPENGL
//graphicsView->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
#endif
graphicsView->setRenderHint(QPainter::Antialiasing, true);
return graphicsView;
}
void Page::drawBackground(QPainter *painter, const QRectF &)
{
if (m_background.isEmpty())
return;
painter->drawImage(QRect(0, 0, SCENE_WIDTH, SCENE_HEIGHT), *m_backgroundImage);
// QGraphicsScene::drawBackground(painter, rect);
// painter->setBackground(QBrush(*m_backgroundImage));
}
void Page::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsScene::mouseDoubleClickEvent(event);
if (selectedItems().count() > 0)
return;
PageProperties *properties = new PageProperties(this);
properties->setWindowModality(Qt::ApplicationModal);
properties->show();
}
void Page::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsScene::mousePressEvent(event);
m_newPos = event->buttonDownScenePos(Qt::RightButton);
}
void Page::UpdateBackground()
{
SetBackground(m_background);
}
QString Page::GetName()
{
return m_name;
}
void Page::SetName(QString newName)
{
m_name = newName;
emit selectionChanged();
// emit nameChanged();
}
void Page::SetBackground(QString path)
{
m_background = path;
QString backgroundImagePath =
Project::PathToProject + m_background;
m_backgroundImage = new QImage(backgroundImagePath);
}
QString Page::Save()
{
return QString("[Page]\n" \
"Name = %0\n" \
"Background = %1\n\n").arg(GetName()).arg(m_background);
}