]> Shamusworld >> Repos - ttedit/blobdiff - src/mainwindow.cpp
Fix zoom to zoom in/out from the center.
[ttedit] / src / mainwindow.cpp
index ef738e95102f56ae4ec784ecc84b86949b297f2d..2c9b45d1024d27a29540d537771b802ca6afa945 100644 (file)
@@ -38,6 +38,7 @@
 #include "mainwindow.h"
 #include "charwindow.h"
 #include "editwindow.h"
+#include "global.h"
 #include "ttedit.h"
 
 
@@ -163,7 +164,7 @@ void MainWindow::CreateActions(void)
        saveFileAct = CreateAction("&Save File", "Save File", "Save a glyph file", QIcon(), QKeySequence("ctrl+s"));
        quitAct = CreateAction("&Quit", "Quit", "Exits from the TTEdit application", QIcon(), QKeySequence("ctrl+q"));
        zoomInAct = CreateAction("Zoom In", "Zoom In", "Zoom into the canvas", QIcon(), QKeySequence("+"), QKeySequence("="));
-       zoomOutAct = CreateAction("Zoom Out", "Zoom Out", "Zoom out of canvas", QIcon(), QKeySequence("-"));
+       zoomOutAct = CreateAction("Zoom Out", "Zoom Out", "Zoom out of the canvas", QIcon(), QKeySequence("-"));
 
        connect(newGlyphAct, SIGNAL(triggered()), this, SLOT(NewGlyph()));
        connect(openFileAct, SIGNAL(triggered()), this, SLOT(OpenFile()));
@@ -207,6 +208,7 @@ void MainWindow::NewGlyph(void)
        editWnd->pts.Clear();
        ((TTEdit *)qApp)->charWnd->MakePathFromPoints(&(editWnd->pts));
        ((TTEdit *)qApp)->charWnd->update();
+       filename.clear();
 //     editWnd->polyFirstPoint = true;
        editWnd->update();
        setWindowTitle("TTEdit! - Untitled");
@@ -216,7 +218,7 @@ void MainWindow::NewGlyph(void)
 
 void MainWindow::OpenFile(void)
 {
-       QString filename = QFileDialog::getOpenFileName(this, tr("Open Glyph File"),
+       filename = QFileDialog::getOpenFileName(this, tr("Open Glyph File"),
                "./", tr("Glyph files (*.glyph)"));
        FILE * file = fopen(filename.toUtf8().data(), "r");
 
@@ -237,8 +239,10 @@ void MainWindow::OpenFile(void)
 
 void MainWindow::SaveFile(void)
 {
-       QString filename = QFileDialog::getSaveFileName(this, tr("Save Glyph File"),
+       if (filename.isEmpty())
+               filename = QFileDialog::getSaveFileName(this, tr("Save Glyph File"),
                "./", tr("Glyph files (*.glyph)"));
+
        FILE * file = fopen(filename.toUtf8().data(), "w");
 
        //need to pop an error box here...
@@ -248,28 +252,41 @@ void MainWindow::SaveFile(void)
        editWnd->pts.SaveGlyphToFile(file);
        fclose(file);
        setWindowTitle(QString("TTEdit! - %1").arg(filename));
+       statusBar()->showMessage(tr("File saved."));
        editWnd->setFocus();
 }
 
 
 void MainWindow::ZoomIn(void)
 {
-       if (editWnd->scale == 4.0)
+       if (Global::zoom == 4.0)
                return;
 
-       editWnd->scale *= 2.0;
-       scaleIndicator->setText(QString("Scale: %1%").arg(editWnd->scale * 100.0));
+       // Adjust the origin by the width/height by 1/4 (half of the scaled size).
+       // Also, need to adjust for the current zoom level...
+       Vector adjustment = (Global::screenSize / Global::zoom) * 0.25;
+       Global::origin += adjustment;
+
+       Global::zoom *= 2.0;
+
+       scaleIndicator->setText(QString("Scale: %1%").arg(Global::zoom * 100.0));
        editWnd->update();
 }
 
 
 void MainWindow::ZoomOut(void)
 {
-       if (editWnd->scale == 0.25)
+       if (Global::zoom == 0.25)
                return;
 
-       editWnd->scale *= 0.5;
-       scaleIndicator->setText(QString("Scale: %1%").arg(editWnd->scale * 100.0));
+       Global::zoom *= 0.5;
+
+       // Adjust the origin by the width/height by 1/4 (half of the scaled size).
+       // Also, need to adjust for the current zoom level...
+       Vector adjustment = (Global::screenSize / Global::zoom) * 0.25;
+       Global::origin -= adjustment;
+
+       scaleIndicator->setText(QString("Scale: %1%").arg(Global::zoom * 100.0));
        editWnd->update();
 }