author | nemo |
Wed, 19 Oct 2011 21:53:39 -0400 | |
changeset 6155 | 930c3be58e1e |
parent 4477 | 63a21fac8bf7 |
permissions | -rw-r--r-- |
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); |
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:
4458
diff
changeset
|
14 |
//ui->graphicsView->setScene(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:
4458
diff
changeset
|
15 |
ui->drawMapWidget->setScene(scene); |
4426 | 16 |
|
17 |
connect(ui->pbUndo, SIGNAL(clicked()), scene, SLOT(undo())); |
|
4427 | 18 |
connect(scene, SIGNAL(pathChanged()), this, SLOT(scene_pathChanged())); |
4425 | 19 |
} |
20 |
||
21 |
MainWindow::~MainWindow() |
|
22 |
{ |
|
23 |
delete ui; |
|
24 |
} |
|
25 |
||
26 |
void MainWindow::changeEvent(QEvent *e) |
|
27 |
{ |
|
28 |
QMainWindow::changeEvent(e); |
|
29 |
switch (e->type()) { |
|
30 |
case QEvent::LanguageChange: |
|
31 |
ui->retranslateUi(this); |
|
32 |
break; |
|
33 |
default: |
|
34 |
break; |
|
35 |
} |
|
36 |
} |
|
37 |
||
4427 | 38 |
void MainWindow::scene_pathChanged() |
39 |
{ |
|
4439 | 40 |
QString str = scene->encode().toBase64(); |
41 |
ui->plainTextEdit->setPlainText(str); |
|
42 |
ui->sbBytes->setValue(str.size()); |
|
4427 | 43 |
} |
4434 | 44 |
|
4442 | 45 |
void MainWindow::on_pbSave_clicked() |
46 |
{ |
|
47 |
QString fileName = QFileDialog::getSaveFileName(this, tr("Save map"), "."); |
|
48 |
||
49 |
if(!fileName.isEmpty()) |
|
50 |
{ |
|
51 |
QFile f(fileName); |
|
52 |
||
53 |
f.open(QIODevice::WriteOnly); |
|
4458 | 54 |
f.write(scene->encode()); |
4442 | 55 |
} |
56 |
} |
|
57 |
||
58 |
void MainWindow::on_pbLoad_clicked() |
|
59 |
{ |
|
60 |
QString fileName = QFileDialog::getOpenFileName(this, tr("Open map file"), "."); |
|
61 |
||
62 |
if(!fileName.isEmpty()) |
|
63 |
{ |
|
64 |
QFile f(fileName); |
|
65 |
||
66 |
f.open(QIODevice::ReadOnly); |
|
4458 | 67 |
QByteArray data = f.readAll(); |
4442 | 68 |
scene->decode(data); |
69 |
} |
|
70 |
} |