diff options
author | Stijn Buys <ingar@osirion.org> | 2012-02-23 21:47:29 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2012-02-23 21:47:29 +0000 |
commit | 2413b21baf332133a3aeb0a45bc934d9feafb85d (patch) | |
tree | 9ea841f7845d7ee27ac5f6d5e9268de7f3703f80 | |
parent | e6347f3747a746151f1f67c7a508c5e2fc9091a8 (diff) |
Prevent the map from freezing by not drawing or updating if it becomes smaller than 16x16 pixels.
-rw-r--r-- | src/mainwindow.cc | 25 | ||||
-rw-r--r-- | src/mapwidget.cc | 10 |
2 files changed, 24 insertions, 11 deletions
diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 4c79fd7..260a630 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -105,16 +105,16 @@ EditorWindow *MainWindow::add_child() { // create a child widget EditorWindow *child_widget = new EditorWindow(); - + // add the widget to the MDI area, // this will wrap an QMdiSubWindow around it QMdiSubWindow *subwindow = mainwindow_mdiarea->addSubWindow(child_widget); + subwindow->resize(768, 512); child_widget->show(); // FIXME check if maximized - subwindow->resize(768, 512); - mainwindow_mdiarea->setActiveSubWindow(subwindow); + return child_widget; } @@ -134,11 +134,17 @@ void MainWindow::slot_open() mainwindow_mdiarea->setActiveSubWindow(subwindow); } else { EditorWindow *editorwindow = add_child(); - editorwindow->loadFile(filename); - + + if (!editorwindow->loadFile(filename)) { + subwindow = find_child(filename); + subwindow->close(); + return; + } + subwindow = find_child(filename); if (subwindow) { - subwindow->setWindowTitle(editorwindow->filename()); + subwindow->setWindowTitle(filename); + mainwindow_mdiarea->setActiveSubWindow(subwindow); } } } @@ -151,11 +157,12 @@ void MainWindow::slot_save_as() QString filename = QFileDialog::getSaveFileName(this, tr("Save as...")); if (!filename.isEmpty()) { - editorwindow->saveFile(filename); + if (!editorwindow->saveFile(filename)) + return; QMdiSubWindow *subwindow = find_child(filename); if (subwindow) { - subwindow->setWindowTitle(editorwindow->filename()); + subwindow->setWindowTitle(filename); } } } @@ -165,7 +172,7 @@ void MainWindow::slot_save() { /* if (active_child()) { - if (!active_child()->filename().size()) { + if (active_child()->filename().isEmpty()) { slot_save_as(); return; } else { diff --git a/src/mapwidget.cc b/src/mapwidget.cc index b855040..d2c5676 100644 --- a/src/mapwidget.cc +++ b/src/mapwidget.cc @@ -31,6 +31,8 @@ MapWidget::MapWidget(QWidget *parent) : QWidget(parent) dragstart_x = 0; dragstart_y = 0; + is_dragging = false; + setFocusPolicy(Qt::ClickFocus); } @@ -97,6 +99,9 @@ void MapWidget::mouseMoveEvent(QMouseEvent *event) void MapWidget::resizeChildren() { + if ((width() < 16) || (height() < 16)) + return; + const float scale = (float) width() / (float) (mapwidget_zoom * 256); for (int i = 0; i < mapwidget_enties.size(); ++i) { @@ -178,6 +183,9 @@ void MapWidget::resizeEvent(QResizeEvent *event) void MapWidget::paintEvent(QPaintEvent *event) { + if ((width() < 16) || (height() < 16)) + return; + const QColor gridlinecolor(0, 0, 128); const QColor axislinecolor(128, 0, 0); @@ -229,8 +237,6 @@ void MapWidget::paintEvent(QPaintEvent *event) painter.drawLine(0, y, width(), y); y += gridsize; } - - QWidget::paintEvent(event); } EntityWidget *MapWidget::addEntity() |