tools/drawMapTest/mainwindow.cpp
author jose1711
Thu, 23 Dec 2010 21:45:50 +0100
changeset 4654 1cc14ece1486
parent 4477 63a21fac8bf7
permissions -rw-r--r--
Updated lua Slovak translation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
     1
#include <QFileDialog>
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
     2
4425
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
     3
#include "mainwindow.h"
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
     4
#include "ui_mainwindow.h"
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
     5
#include "drawmapscene.h"
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
     6
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
     7
MainWindow::MainWindow(QWidget *parent) :
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
     8
    QMainWindow(parent),
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
     9
    ui(new Ui::MainWindow)
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    10
{
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    11
    ui->setupUi(this);
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    12
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    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
969e411c72aa Improve map editor a bit
unc0rr
parents: 4425
diff changeset
    16
969e411c72aa Improve map editor a bit
unc0rr
parents: 4425
diff changeset
    17
    connect(ui->pbUndo, SIGNAL(clicked()), scene, SLOT(undo()));
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    18
    connect(scene, SIGNAL(pathChanged()), this, SLOT(scene_pathChanged()));
4425
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    19
}
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    20
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    21
MainWindow::~MainWindow()
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    22
{
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    23
    delete ui;
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    24
}
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    25
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    26
void MainWindow::changeEvent(QEvent *e)
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    27
{
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    28
    QMainWindow::changeEvent(e);
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    29
    switch (e->type()) {
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    30
    case QEvent::LanguageChange:
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    31
        ui->retranslateUi(this);
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    32
        break;
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    33
    default:
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    34
        break;
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    35
    }
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    36
}
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    37
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    38
void MainWindow::scene_pathChanged()
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    39
{
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
    40
    QString str = scene->encode().toBase64();
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
    41
    ui->plainTextEdit->setPlainText(str);
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
    42
    ui->sbBytes->setValue(str.size());
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    43
}
4434
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
    44
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    45
void MainWindow::on_pbSave_clicked()
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    46
{
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    47
    QString fileName = QFileDialog::getSaveFileName(this, tr("Save map"), ".");
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    48
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    49
    if(!fileName.isEmpty())
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    50
    {
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    51
        QFile f(fileName);
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    52
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    53
        f.open(QIODevice::WriteOnly);
4458
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4442
diff changeset
    54
        f.write(scene->encode());
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    55
    }
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    56
}
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    57
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    58
void MainWindow::on_pbLoad_clicked()
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    59
{
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    60
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open map file"), ".");
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    61
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    62
    if(!fileName.isEmpty())
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    63
    {
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    64
        QFile f(fileName);
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    65
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    66
        f.open(QIODevice::ReadOnly);
4458
7351e6f1ee28 Halfplement decode/drawing routine
unc0rr
parents: 4442
diff changeset
    67
        QByteArray data = f.readAll();
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    68
        scene->decode(data);
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    69
    }
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    70
}