tools/drawMapTest/mainwindow.cpp
author nemo
Thu, 02 Dec 2010 19:19:34 -0500
changeset 4450 b8d30b0e4829
parent 4442 f8424e1bc936
child 4458 7351e6f1ee28
permissions -rw-r--r--
forgot the passed in uid
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);
4425
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    14
    ui->graphicsView->setScene(scene);
4426
969e411c72aa Improve map editor a bit
unc0rr
parents: 4425
diff changeset
    15
969e411c72aa Improve map editor a bit
unc0rr
parents: 4425
diff changeset
    16
    connect(ui->pbUndo, SIGNAL(clicked()), scene, SLOT(undo()));
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    17
    connect(scene, SIGNAL(pathChanged()), this, SLOT(scene_pathChanged()));
4425
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    18
}
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    19
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    20
MainWindow::~MainWindow()
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    21
{
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    22
    delete ui;
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    23
}
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    24
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    25
void MainWindow::changeEvent(QEvent *e)
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    26
{
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    27
    QMainWindow::changeEvent(e);
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    28
    switch (e->type()) {
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    29
    case QEvent::LanguageChange:
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    30
        ui->retranslateUi(this);
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    31
        break;
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    32
    default:
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    33
        break;
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    34
    }
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
void MainWindow::resizeEvent(QResizeEvent * event)
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    38
{
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    39
    Q_UNUSED(event);
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    40
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    41
    if(ui->graphicsView)
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    42
        ui->graphicsView->fitInView(ui->graphicsView->scene()->sceneRect(), Qt::KeepAspectRatio);
2314bb0c433d Small testing app for DrawMap scene
unc0rr
parents:
diff changeset
    43
}
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    44
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    45
void MainWindow::scene_pathChanged()
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    46
{
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
    47
    QString str = scene->encode().toBase64();
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
    48
    ui->plainTextEdit->setPlainText(str);
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
    49
    ui->sbBytes->setValue(str.size());
4427
c5193713055f Basic encoding of drawn map
unc0rr
parents: 4426
diff changeset
    50
}
4434
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
    51
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
    52
void MainWindow::on_pbSimplify_clicked()
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
    53
{
4439
27a896207aae Some more improvements
unC0Rr
parents: 4434
diff changeset
    54
    scene->simplifyLast();
4434
34c305fbc63c Simple simplify() function
unc0rr
parents: 4427
diff changeset
    55
}
4442
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    56
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    57
void MainWindow::on_pbSave_clicked()
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    58
{
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    59
    QString fileName = QFileDialog::getSaveFileName(this, tr("Save map"), ".");
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    60
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    61
    if(!fileName.isEmpty())
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    62
    {
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    63
        QFile f(fileName);
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    64
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    65
        f.open(QIODevice::WriteOnly);
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    66
        f.write(qCompress(scene->encode()).toBase64());
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    67
    }
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    68
}
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    69
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    70
void MainWindow::on_pbLoad_clicked()
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    71
{
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    72
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open map file"), ".");
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    73
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    74
    if(!fileName.isEmpty())
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    75
    {
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    76
        QFile f(fileName);
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    77
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    78
        f.open(QIODevice::ReadOnly);
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    79
        QByteArray data = qUncompress(QByteArray::fromBase64(f.readAll()));
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    80
        scene->decode(data);
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    81
    }
f8424e1bc936 - Implement decode() function.
unc0rr
parents: 4439
diff changeset
    82
}