QTfrontend/ui/widget/drawmapwidget.cpp
author nemo
Wed, 21 Nov 2018 15:47:40 -0500
changeset 14267 b6c24abb247b
parent 13240 950186baa764
child 14836 b9437746bffb
permissions -rw-r--r--
add cfg for mutant
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
     1
/*
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
     2
 * Hedgewars, a free turn based strategy game
11046
47a8c19ecb60 more copyright fixes
sheepluva
parents: 10235
diff changeset
     3
 * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
     4
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
     7
 * the Free Software Foundation; version 2 of the License
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
     8
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
    12
 * GNU General Public License for more details.
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
    13
 *
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
    14
 * You should have received a copy of the GNU General Public License
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
    15
 * along with this program; if not, write to the Free Software
10108
c68cf030eded update FSF address. note: two sdl include files (by Sam Lantinga) still have the old FSF address in their copyright - but I ain't gonna touch their copyright headers
sheepluva
parents: 9998
diff changeset
    16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
4976
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
    17
 */
088d40d8aba2 Happy 2011 :)
koda
parents: 4586
diff changeset
    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
ded882439548 file association for mac!
koda
parents: 4976
diff changeset
    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
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
    58
    connect(scene, SIGNAL(pathChanged()), this, SLOT(pathChanged()));
13209
f5d36be88c61 Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents: 11046
diff changeset
    59
    connect(scene, SIGNAL(brushSizeChanged(int)), this, SLOT(brushSizeChanged_slot(int)));
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
    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
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
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
    63
{
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
    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
    65
13240
950186baa764 Fix crasher
unC0Rr
parents: 13209
diff changeset
    66
	if(!m_scene)
950186baa764 Fix crasher
unC0Rr
parents: 13209
diff changeset
    67
		return;
950186baa764 Fix crasher
unC0Rr
parents: 13209
diff changeset
    68
		
9128
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    69
    int height = this->height();
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    70
    int width = this->width();
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    71
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    72
    if ((m_scene->height() > 0) && (m_scene->width() > 0) && (height > 0))
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    73
    {
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    74
        qreal saspect = m_scene->width() / m_scene->height();
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    75
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    76
        qreal h = height;
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    77
        qreal w = width;
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    78
        qreal waspect = w / h;
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    79
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    80
        if (waspect < saspect)
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    81
        {
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    82
            h = w / saspect;
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    83
        }
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    84
        else if (waspect > saspect)
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    85
        {
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    86
            w = saspect * h;
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    87
        }
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    88
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    89
        int fixedh = (int)h;
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    90
        int fixedw = (int)w;
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    91
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    92
        if (ui->graphicsView->width() != fixedw)
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    93
        {
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    94
            ui->graphicsView->setFixedWidth(fixedw);
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    95
        }
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    96
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    97
        if (ui->graphicsView->height() != fixedh)
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    98
        {
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
    99
            ui->graphicsView->setFixedHeight(fixedh);
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
   100
        }
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
   101
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
   102
    }
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
   103
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
   104
    if(ui->graphicsView && ui->graphicsView->scene())
9128
19596777eb7a good-bye QAspectRatioLayout
sheepluva
parents: 9080
diff changeset
   105
        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
   106
}
4556
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
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
   109
{
c7f4eb6cbd0c Make use of showEvent, so there's no more need in manual resizing of draw map widget
unc0rr
parents: 4520
diff changeset
   110
    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
   111
c7f4eb6cbd0c Make use of showEvent, so there's no more need in manual resizing of draw map widget
unc0rr
parents: 4520
diff changeset
   112
    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
   113
}
4560
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
void DrawMapWidget::undo()
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4556
diff changeset
   116
{
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4556
diff changeset
   117
    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
   118
}
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
void DrawMapWidget::clear()
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4556
diff changeset
   121
{
4586
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   122
    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
   123
}
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4556
diff changeset
   124
10235
bafca1686867 Drawn maps optimizer - first steps:
unc0rr
parents: 10108
diff changeset
   125
void DrawMapWidget::optimize()
bafca1686867 Drawn maps optimizer - first steps:
unc0rr
parents: 10108
diff changeset
   126
{
bafca1686867 Drawn maps optimizer - first steps:
unc0rr
parents: 10108
diff changeset
   127
    if(m_scene) m_scene->optimize();
bafca1686867 Drawn maps optimizer - first steps:
unc0rr
parents: 10108
diff changeset
   128
}
bafca1686867 Drawn maps optimizer - first steps:
unc0rr
parents: 10108
diff changeset
   129
6873
30840365af0a Eraser tool
unc0rr
parents: 6700
diff changeset
   130
void DrawMapWidget::setErasing(bool erasing)
30840365af0a Eraser tool
unc0rr
parents: 6700
diff changeset
   131
{
30840365af0a Eraser tool
unc0rr
parents: 6700
diff changeset
   132
    if(m_scene) m_scene->setErasing(erasing);
30840365af0a Eraser tool
unc0rr
parents: 6700
diff changeset
   133
}
30840365af0a Eraser tool
unc0rr
parents: 6700
diff changeset
   134
9551
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
   135
void DrawMapWidget::setPathType(DrawMapScene::PathType pathType)
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
   136
{
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
   137
    if(m_scene) m_scene->setPathType(pathType);
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
   138
}
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
   139
13209
f5d36be88c61 Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents: 11046
diff changeset
   140
void DrawMapWidget::setBrushSize(int brushSize)
f5d36be88c61 Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents: 11046
diff changeset
   141
{
f5d36be88c61 Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents: 11046
diff changeset
   142
    if(m_scene) m_scene->setBrushSize(brushSize);
f5d36be88c61 Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents: 11046
diff changeset
   143
}
f5d36be88c61 Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents: 11046
diff changeset
   144
4560
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4556
diff changeset
   145
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
   146
{
4586
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   147
    if(m_scene)
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   148
    {
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   149
        QFile file(fileName);
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   150
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   151
        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
   152
        {
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
   153
            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
   154
            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
   155
            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
   156
            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
   157
            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
   158
            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
   159
        }
4586
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   160
        else
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   161
            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
   162
    }
4560
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4556
diff changeset
   163
}
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4556
diff changeset
   164
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4556
diff changeset
   165
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
   166
{
4586
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   167
    if(m_scene)
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   168
    {
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   169
        QFile f(fileName);
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   170
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   171
        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
   172
        {
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
   173
            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
   174
            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
   175
            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
   176
            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
   177
            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
   178
            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
   179
        }
4586
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   180
        else
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   181
            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
   182
            //m_scene->decode(f.readAll());
4586
4ba4f021070f - Allow user to use undo, to clear, save and load drawn maps
unc0rr
parents: 4560
diff changeset
   183
    }
4560
5d6c7f88db73 - Some work on drawMap widget and scene to allow undo, clear, save and load operations
unc0rr
parents: 4556
diff changeset
   184
}
6934
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   185
6935
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
   186
void DrawMapWidget::pathChanged()
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
   187
{
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
   188
    ui->lblPoints->setNum(m_scene->pointsCount());
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
   189
}
472ed92c4173 Show number of points in drawn map
unc0rr
parents: 6934
diff changeset
   190
13209
f5d36be88c61 Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents: 11046
diff changeset
   191
void DrawMapWidget::brushSizeChanged_slot(int brushSize)
f5d36be88c61 Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents: 11046
diff changeset
   192
{
f5d36be88c61 Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents: 11046
diff changeset
   193
    emit brushSizeChanged(brushSize);
f5d36be88c61 Drawn map menu: Add spin box to change brush size by hand
Wuzzy <Wuzzy2@mail.ru>
parents: 11046
diff changeset
   194
}
6934
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   195
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   196
DrawMapView::DrawMapView(QWidget *parent) :
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   197
    QGraphicsView(parent)
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
   setMouseTracking(true);
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   200
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   201
    m_scene = 0;
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
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   204
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   205
DrawMapView::~DrawMapView()
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   206
{
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
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   210
void DrawMapView::setScene(DrawMapScene *scene)
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   211
{
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   212
    m_scene = scene;
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::setScene(scene);
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
9551
61f160dfd0f1 Draw rectangles and ellipses!
unc0rr
parents: 9472
diff changeset
   217
// Why don't I ever receive this event?
6934
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   218
void DrawMapView::enterEvent(QEvent *event)
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   219
{
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   220
    if(m_scene)
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   221
        m_scene->showCursor();
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   222
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   223
    QGraphicsView::enterEvent(event);
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   224
}
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   225
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   226
void DrawMapView::leaveEvent(QEvent *event)
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   227
{
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   228
    if(m_scene)
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   229
        m_scene->hideCursor();
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   230
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   231
    QGraphicsView::leaveEvent(event);
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   232
}
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   233
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   234
bool DrawMapView::viewportEvent(QEvent *event)
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   235
{
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   236
    return QGraphicsView::viewportEvent(event);
14a230552c2e Cursor for DrawMapScene. Feel free to ajust its look.
unc0rr
parents: 6873
diff changeset
   237
}