4442
|
1 |
#include <QFileDialog>
|
|
2 |
|
4425
|
3 |
#include "mainwindow.h"
|
|
4 |
#include "ui_mainwindow.h"
|
|
5 |
#include "drawmapscene.h"
|
|
6 |
|
|
7 |
MainWindow::MainWindow(QWidget *parent) :
|
|
8 |
QMainWindow(parent),
|
|
9 |
ui(new Ui::MainWindow)
|
|
10 |
{
|
|
11 |
ui->setupUi(this);
|
|
12 |
|
4427
|
13 |
scene = new DrawMapScene(this);
|
4425
|
14 |
ui->graphicsView->setScene(scene);
|
4426
|
15 |
|
|
16 |
connect(ui->pbUndo, SIGNAL(clicked()), scene, SLOT(undo()));
|
4427
|
17 |
connect(scene, SIGNAL(pathChanged()), this, SLOT(scene_pathChanged()));
|
4425
|
18 |
}
|
|
19 |
|
|
20 |
MainWindow::~MainWindow()
|
|
21 |
{
|
|
22 |
delete ui;
|
|
23 |
}
|
|
24 |
|
|
25 |
void MainWindow::changeEvent(QEvent *e)
|
|
26 |
{
|
|
27 |
QMainWindow::changeEvent(e);
|
|
28 |
switch (e->type()) {
|
|
29 |
case QEvent::LanguageChange:
|
|
30 |
ui->retranslateUi(this);
|
|
31 |
break;
|
|
32 |
default:
|
|
33 |
break;
|
|
34 |
}
|
|
35 |
}
|
|
36 |
|
|
37 |
void MainWindow::resizeEvent(QResizeEvent * event)
|
|
38 |
{
|
|
39 |
Q_UNUSED(event);
|
|
40 |
|
|
41 |
if(ui->graphicsView)
|
|
42 |
ui->graphicsView->fitInView(ui->graphicsView->scene()->sceneRect(), Qt::KeepAspectRatio);
|
|
43 |
}
|
4427
|
44 |
|
|
45 |
void MainWindow::scene_pathChanged()
|
|
46 |
{
|
4439
|
47 |
QString str = scene->encode().toBase64();
|
|
48 |
ui->plainTextEdit->setPlainText(str);
|
|
49 |
ui->sbBytes->setValue(str.size());
|
4427
|
50 |
}
|
4434
|
51 |
|
|
52 |
void MainWindow::on_pbSimplify_clicked()
|
|
53 |
{
|
4439
|
54 |
scene->simplifyLast();
|
4434
|
55 |
}
|
4442
|
56 |
|
|
57 |
void MainWindow::on_pbSave_clicked()
|
|
58 |
{
|
|
59 |
QString fileName = QFileDialog::getSaveFileName(this, tr("Save map"), ".");
|
|
60 |
|
|
61 |
if(!fileName.isEmpty())
|
|
62 |
{
|
|
63 |
QFile f(fileName);
|
|
64 |
|
|
65 |
f.open(QIODevice::WriteOnly);
|
4458
|
66 |
f.write(scene->encode());
|
4442
|
67 |
}
|
|
68 |
}
|
|
69 |
|
|
70 |
void MainWindow::on_pbLoad_clicked()
|
|
71 |
{
|
|
72 |
QString fileName = QFileDialog::getOpenFileName(this, tr("Open map file"), ".");
|
|
73 |
|
|
74 |
if(!fileName.isEmpty())
|
|
75 |
{
|
|
76 |
QFile f(fileName);
|
|
77 |
|
|
78 |
f.open(QIODevice::ReadOnly);
|
4458
|
79 |
QByteArray data = f.readAll();
|
4442
|
80 |
scene->decode(data);
|
|
81 |
}
|
|
82 |
}
|