X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmainwindow.cpp;h=173c977a8a04a0fe4cad8e6791d4ace2e418147b;hb=HEAD;hp=dea9087af7bf9496ed81a93fd60475091567f55e;hpb=0c01fa32c7e0629ae61992e0419f03724fc18487;p=ttedit diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index dea9087..173c977 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -6,7 +6,7 @@ // JLH = James L. Hammons // // Who When What -// --- ---------- ------------------------------------------------------------- +// --- ---------- ----------------------------------------------------------- // JLH 04/10/2002 Created this file // JLH 05/10/2004 Translated file from ASM to CPP // JLH 05/14/2004 Added rudimentary editing capability to tool palette tools @@ -18,7 +18,8 @@ // FIXED: // -// - Fix problem with tool palette not getting focus 1st time it's called up [DONE] +// - Fix problem with tool palette not getting focus 1st time it's called up +// [DONE] // - Split out windows/classes defined here into their own files [DONE] // // STILL TO BE DONE: @@ -37,71 +38,27 @@ #include "mainwindow.h" #include "charwindow.h" #include "editwindow.h" +#include "global.h" +#include "previewfiledialog.h" #include "ttedit.h" MainWindow::MainWindow() { - ((TTEdit *)qApp)->charWnd = new CharWindow(this); + Global::charWnd = new CharWindow(this); editWnd = new EditWindow(this); setCentralWidget(editWnd); editWnd->setFocus(); setWindowIcon(QIcon(":/res/ttedit.png")); - setWindowTitle("TTEdit!"); + setWindowTitle("TTEdit! - Untitled"); -#if 0 -// createActions(); - newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this); - newAct->setShortcuts(QKeySequence::New); - newAct->setStatusTip(tr("Create a new file")); - connect(newAct, SIGNAL(triggered()), this, SLOT(newFile())); - - openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this); - openAct->setShortcuts(QKeySequence::Open); - openAct->setStatusTip(tr("Open an existing file")); - connect(openAct, SIGNAL(triggered()), this, SLOT(open())); - - aboutQtAct = new QAction(tr("About &Qt"), this); - aboutQtAct->setStatusTip(tr("Show the Qt library's About box")); - connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt())); - -// createMenus(); - fileMenu = menuBar()->addMenu(tr("&File")); - fileMenu->addAction(newAct); - fileMenu->addAction(openAct); - fileMenu->addAction(saveAct); - fileMenu->addAction(saveAsAct); - fileMenu->addSeparator(); - fileMenu->addAction(exitAct); - - editMenu = menuBar()->addMenu(tr("&Edit")); - editMenu->addAction(cutAct); - editMenu->addAction(copyAct); - editMenu->addAction(pasteAct); - - menuBar()->addSeparator(); - - helpMenu = menuBar()->addMenu(tr("&Help")); - helpMenu->addAction(aboutAct); - helpMenu->addAction(aboutQtAct); - -// createToolBars(); - fileToolBar = addToolBar(tr("File")); - fileToolBar->addAction(newAct); - fileToolBar->addAction(openAct); - fileToolBar->addAction(saveAct); - - editToolBar = addToolBar(tr("Edit")); - editToolBar->addAction(cutAct); - editToolBar->addAction(copyAct); - editToolBar->addAction(pasteAct); -#else CreateActions(); CreateMenus(); CreateToolbars(); -#endif // Create status bar + scaleIndicator = new QLabel("Scale: 100%"); + statusBar()->addPermanentWidget(scaleIndicator); statusBar()->showMessage(tr("Ready")); ReadSettings(); @@ -112,15 +69,15 @@ MainWindow::MainWindow() // setCurrentFile(""); setUnifiedTitleAndToolBarOnMac(true); - ((TTEdit *)qApp)->charWnd->show();//eh? + Global::charWnd->show(); } // // Consolidates action creation from a multi-step process to a single-step one. // -QAction * MainWindow::CreateAction(QString name, QString tooltip, QString statustip, - QIcon icon, QKeySequence key, bool checkable/*= false*/) +QAction * MainWindow::CreateAction(QString name, QString tooltip, QString + statustip, QIcon icon, QKeySequence key, bool checkable/*= false*/) { QAction * action = new QAction(icon, name, this); action->setToolTip(tooltip); @@ -136,8 +93,9 @@ QAction * MainWindow::CreateAction(QString name, QString tooltip, QString status // This is essentially the same as the previous function, but this allows more // than one key sequence to be added as key shortcuts. // -QAction * MainWindow::CreateAction(QString name, QString tooltip, QString statustip, - QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/) +QAction * MainWindow::CreateAction(QString name, QString tooltip, QString + statustip, QIcon icon, QKeySequence key1, QKeySequence key2, bool + checkable/*= false*/) { QAction * action = new QAction(icon, name, this); action->setToolTip(tooltip); @@ -155,12 +113,18 @@ QAction * MainWindow::CreateAction(QString name, QString tooltip, QString status void MainWindow::CreateActions(void) { newGlyphAct = CreateAction("&New Glyph", "New Glyph", "Create a new glyph", QIcon(), QKeySequence()); - openFileAct = CreateAction("&Open File", "Open File", "Open a glyph file", QIcon(), QKeySequence()); - saveFileAct = CreateAction("&Save File", "Save File", "Save a glyph file", QIcon(), QKeySequence()); + openFileAct = CreateAction("&Open File", "Open File", "Open a glyph file", QIcon(), QKeySequence("ctrl+o")); + 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 the canvas", QIcon(), QKeySequence("-")); connect(newGlyphAct, SIGNAL(triggered()), this, SLOT(NewGlyph())); connect(openFileAct, SIGNAL(triggered()), this, SLOT(OpenFile())); connect(saveFileAct, SIGNAL(triggered()), this, SLOT(SaveFile())); + connect(quitAct, SIGNAL(triggered()), this, SLOT(close())); + connect(zoomInAct, SIGNAL(triggered()), this, SLOT(ZoomIn())); + connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(ZoomOut())); } @@ -170,8 +134,13 @@ void MainWindow::CreateMenus(void) menu->addAction(newGlyphAct); menu->addAction(openFileAct); menu->addAction(saveFileAct); + menu->addSeparator(); + menu->addAction(quitAct); // menu->addAction(fileSaveAsAct); // menu->addAction(fileCloseAct); + menu = menuBar()->addMenu(tr("&View")); + menu->addAction(zoomInAct); + menu->addAction(zoomOutAct); } @@ -190,17 +159,31 @@ void MainWindow::closeEvent(QCloseEvent * event) void MainWindow::NewGlyph(void) { editWnd->pts.Clear(); - ((TTEdit *)qApp)->charWnd->MakePathFromPoints(&(editWnd->pts)); - ((TTEdit *)qApp)->charWnd->update(); + Global::charWnd->MakePathFromPoints(&(editWnd->pts)); + Global::charWnd->update(); + filename.clear(); // editWnd->polyFirstPoint = true; editWnd->update(); + setWindowTitle("TTEdit! - Untitled"); + editWnd->setFocus(); } void MainWindow::OpenFile(void) { - QString filename = QFileDialog::getOpenFileName(this, tr("Open Glyph File"), +#if 0 + filename = QFileDialog::getOpenFileName(this, tr("Open Glyph File"), + "./", tr("Glyph files (*.glyph)")); +#else + PreviewFileDialog * pfd = new PreviewFileDialog(this, tr("Open Glyph File"), "./", tr("Glyph files (*.glyph)")); + pfd->setAcceptMode(QFileDialog::AcceptOpen); + + if (pfd->exec() == false) + return; + + filename = pfd->selectedFiles().at(0); +#endif FILE * file = fopen(filename.toUtf8().data(), "r"); //need to pop an error box here... @@ -210,16 +193,20 @@ void MainWindow::OpenFile(void) editWnd->pts.LoadGlyphFromFile(file); fclose(file); - ((TTEdit *)qApp)->charWnd->MakePathFromPoints(&(editWnd->pts)); - ((TTEdit *)qApp)->charWnd->update(); + Global::charWnd->MakePathFromPoints(&(editWnd->pts)); + Global::charWnd->update(); editWnd->update(); + setWindowTitle(QString("TTEdit! - %1").arg(filename)); + editWnd->setFocus(); } 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... @@ -228,6 +215,43 @@ 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 (Global::zoom == 4.0) + return; + + // 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 (Global::zoom == 0.25) + return; + + 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(); } @@ -240,8 +264,8 @@ void MainWindow::ReadSettings(void) move(pos); pos = settings.value("charWndPos", QPoint(0, 0)).toPoint(); size = settings.value("charWndSize", QSize(200, 200)).toSize(); - ((TTEdit *)qApp)->charWnd->resize(size); - ((TTEdit *)qApp)->charWnd->move(pos); + Global::charWnd->resize(size); + Global::charWnd->move(pos); } @@ -250,8 +274,8 @@ void MainWindow::WriteSettings(void) QSettings settings("Underground Software", "TTEdit"); settings.setValue("pos", pos()); settings.setValue("size", size()); - settings.setValue("charWndPos", ((TTEdit *)qApp)->charWnd->pos()); - settings.setValue("charWndSize", ((TTEdit *)qApp)->charWnd->size()); + settings.setValue("charWndPos", Global::charWnd->pos()); + settings.setValue("charWndSize", Global::charWnd->size()); }