author | koda |
Mon, 01 Jun 2015 14:39:25 +0200 | |
branch | 0.9.20 |
changeset 9934 | 57f9ce8b2854 |
parent 9551 | 61f160dfd0f1 |
child 9998 | 736015b847e3 |
permissions | -rw-r--r-- |
4976 | 1 |
/* |
2 |
* Hedgewars, a free turn based strategy game |
|
9080 | 3 |
* Copyright (c) 2004-2013 Andrey Korotaev <unC0Rr@gmail.com> |
4976 | 4 |
* |
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*/ |
|
18 |
||
4560
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
19 |
#include <QFile> |
4586
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
20 |
#include <QMessageBox> |
5252 | 21 |
#include <QEvent> |
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
22 |
#include <QDebug> |
4560
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
23 |
|
4477
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
24 |
#include "drawmapwidget.h" |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
25 |
|
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
26 |
DrawMapWidget::DrawMapWidget(QWidget *parent) : |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
27 |
QWidget(parent), |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
28 |
ui(new Ui::DrawMapWidget) |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
29 |
{ |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
30 |
ui->setupUi(this); |
4560
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
31 |
|
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
32 |
m_scene = 0; |
4477
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
33 |
} |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
34 |
|
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
35 |
DrawMapWidget::~DrawMapWidget() |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
36 |
{ |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
37 |
delete ui; |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
38 |
} |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
39 |
|
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
40 |
void DrawMapWidget::changeEvent(QEvent *e) |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
41 |
{ |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
42 |
QWidget::changeEvent(e); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
43 |
switch (e->type()) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
44 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
45 |
case QEvent::LanguageChange: |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
46 |
ui->retranslateUi(this); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
47 |
break; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
48 |
default: |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
49 |
break; |
4477
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
50 |
} |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
51 |
} |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
52 |
|
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
53 |
void DrawMapWidget::setScene(DrawMapScene * scene) |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
54 |
{ |
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
55 |
m_scene = scene; |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
56 |
|
4477
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
57 |
ui->graphicsView->setScene(scene); |
6935 | 58 |
connect(scene, SIGNAL(pathChanged()), this, SLOT(pathChanged())); |
4477
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
59 |
} |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
60 |
|
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
61 |
void DrawMapWidget::resizeEvent(QResizeEvent * event) |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
62 |
{ |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
63 |
Q_UNUSED(event); |
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
64 |
|
9128 | 65 |
int height = this->height(); |
66 |
int width = this->width(); |
|
67 |
||
68 |
if ((m_scene->height() > 0) && (m_scene->width() > 0) && (height > 0)) |
|
69 |
{ |
|
70 |
qreal saspect = m_scene->width() / m_scene->height(); |
|
71 |
||
72 |
qreal h = height; |
|
73 |
qreal w = width; |
|
74 |
qreal waspect = w / h; |
|
75 |
||
76 |
if (waspect < saspect) |
|
77 |
{ |
|
78 |
h = w / saspect; |
|
79 |
} |
|
80 |
else if (waspect > saspect) |
|
81 |
{ |
|
82 |
w = saspect * h; |
|
83 |
} |
|
84 |
||
85 |
int fixedh = (int)h; |
|
86 |
int fixedw = (int)w; |
|
87 |
||
88 |
if (ui->graphicsView->width() != fixedw) |
|
89 |
{ |
|
90 |
ui->graphicsView->setFixedWidth(fixedw); |
|
91 |
} |
|
92 |
||
93 |
if (ui->graphicsView->height() != fixedh) |
|
94 |
{ |
|
95 |
ui->graphicsView->setFixedHeight(fixedh); |
|
96 |
} |
|
97 |
||
98 |
} |
|
99 |
||
4477
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
100 |
if(ui->graphicsView && ui->graphicsView->scene()) |
9128 | 101 |
ui->graphicsView->fitInView(m_scene->sceneRect(), Qt::KeepAspectRatio); |
4477
63a21fac8bf7
Add QAspectRatioLayout borrowed from http://wiki.forum.nokia.com/index.php/CS001309_-_Maintaining_square_form_for_a_widget_in_Qt to maintain width == height * 2 aspect ratio for map drawing widget
unc0rr
parents:
diff
changeset
|
102 |
} |
4556
c7f4eb6cbd0c
Make use of showEvent, so there's no more need in manual resizing of draw map widget
unc0rr
parents:
4520
diff
changeset
|
103 |
|
c7f4eb6cbd0c
Make use of showEvent, so there's no more need in manual resizing of draw map widget
unc0rr
parents:
4520
diff
changeset
|
104 |
void DrawMapWidget::showEvent(QShowEvent * event) |
c7f4eb6cbd0c
Make use of showEvent, so there's no more need in manual resizing of draw map widget
unc0rr
parents:
4520
diff
changeset
|
105 |
{ |
c7f4eb6cbd0c
Make use of showEvent, so there's no more need in manual resizing of draw map widget
unc0rr
parents:
4520
diff
changeset
|
106 |
Q_UNUSED(event); |
c7f4eb6cbd0c
Make use of showEvent, so there's no more need in manual resizing of draw map widget
unc0rr
parents:
4520
diff
changeset
|
107 |
|
c7f4eb6cbd0c
Make use of showEvent, so there's no more need in manual resizing of draw map widget
unc0rr
parents:
4520
diff
changeset
|
108 |
resizeEvent(0); |
c7f4eb6cbd0c
Make use of showEvent, so there's no more need in manual resizing of draw map widget
unc0rr
parents:
4520
diff
changeset
|
109 |
} |
4560
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
110 |
|
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
111 |
void DrawMapWidget::undo() |
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
112 |
{ |
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
113 |
if(m_scene) m_scene->undo(); |
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
114 |
} |
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
115 |
|
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
116 |
void DrawMapWidget::clear() |
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
117 |
{ |
4586
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
118 |
if(m_scene) m_scene->clearMap(); |
4560
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
119 |
} |
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
120 |
|
6873 | 121 |
void DrawMapWidget::setErasing(bool erasing) |
122 |
{ |
|
123 |
if(m_scene) m_scene->setErasing(erasing); |
|
124 |
} |
|
125 |
||
9551 | 126 |
void DrawMapWidget::setPathType(DrawMapScene::PathType pathType) |
127 |
{ |
|
128 |
if(m_scene) m_scene->setPathType(pathType); |
|
129 |
} |
|
130 |
||
4560
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
131 |
void DrawMapWidget::save(const QString & fileName) |
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
132 |
{ |
4586
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
133 |
if(m_scene) |
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
134 |
{ |
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
135 |
QFile file(fileName); |
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
136 |
|
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
137 |
if(!file.open(QIODevice::WriteOnly)) |
7794
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
138 |
{ |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
139 |
QMessageBox errorMsg(this); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
140 |
errorMsg.setIcon(QMessageBox::Warning); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
141 |
errorMsg.setWindowTitle(QMessageBox::tr("File error")); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
142 |
errorMsg.setText(QMessageBox::tr("Cannot open '%1' for writing").arg(fileName)); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
143 |
errorMsg.setWindowModality(Qt::WindowModal); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
144 |
errorMsg.exec(); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
145 |
} |
4586
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
146 |
else |
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
147 |
file.write(qCompress(m_scene->encode()).toBase64()); |
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
148 |
} |
4560
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
149 |
} |
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
150 |
|
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
151 |
void DrawMapWidget::load(const QString & fileName) |
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
152 |
{ |
4586
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
153 |
if(m_scene) |
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
154 |
{ |
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
155 |
QFile f(fileName); |
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
156 |
|
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
157 |
if(!f.open(QIODevice::ReadOnly)) |
7794
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
158 |
{ |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
159 |
QMessageBox errorMsg(this); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
160 |
errorMsg.setIcon(QMessageBox::Warning); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
161 |
errorMsg.setWindowTitle(QMessageBox::tr("File error")); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
162 |
errorMsg.setText(QMessageBox::tr("Cannot open '%1' for reading").arg(fileName)); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
163 |
errorMsg.setWindowModality(Qt::WindowModal); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
164 |
errorMsg.exec(); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
6952
diff
changeset
|
165 |
} |
4586
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
166 |
else |
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
167 |
m_scene->decode(qUncompress(QByteArray::fromBase64(f.readAll()))); |
9472
265e5997580e
Incomplete implementation of 'special points' in drawn maps (crashes engine)
unc0rr
parents:
9128
diff
changeset
|
168 |
//m_scene->decode(f.readAll()); |
4586
4ba4f021070f
- Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents:
4560
diff
changeset
|
169 |
} |
4560
5d6c7f88db73
- Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents:
4556
diff
changeset
|
170 |
} |
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
171 |
|
6935 | 172 |
void DrawMapWidget::pathChanged() |
173 |
{ |
|
174 |
ui->lblPoints->setNum(m_scene->pointsCount()); |
|
175 |
} |
|
176 |
||
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
177 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
178 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
179 |
DrawMapView::DrawMapView(QWidget *parent) : |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
180 |
QGraphicsView(parent) |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
181 |
{ |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
182 |
setMouseTracking(true); |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
183 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
184 |
m_scene = 0; |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
185 |
} |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
186 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
187 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
188 |
DrawMapView::~DrawMapView() |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
189 |
{ |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
190 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
191 |
} |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
192 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
193 |
void DrawMapView::setScene(DrawMapScene *scene) |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
194 |
{ |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
195 |
m_scene = scene; |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
196 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
197 |
QGraphicsView::setScene(scene); |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
198 |
} |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
199 |
|
9551 | 200 |
// Why don't I ever receive this event? |
6934
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
201 |
void DrawMapView::enterEvent(QEvent *event) |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
202 |
{ |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
203 |
if(m_scene) |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
204 |
m_scene->showCursor(); |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
205 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
206 |
QGraphicsView::enterEvent(event); |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
207 |
} |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
208 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
209 |
void DrawMapView::leaveEvent(QEvent *event) |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
210 |
{ |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
211 |
if(m_scene) |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
212 |
m_scene->hideCursor(); |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
213 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
214 |
QGraphicsView::leaveEvent(event); |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
215 |
} |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
216 |
|
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
217 |
bool DrawMapView::viewportEvent(QEvent *event) |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
218 |
{ |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
219 |
return QGraphicsView::viewportEvent(event); |
14a230552c2e
Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents:
6873
diff
changeset
|
220 |
} |