]> Shamusworld >> Repos - ttedit/blobdiff - src/mainwindow.cpp
Added rotation tool, save/load capability.
[ttedit] / src / mainwindow.cpp
similarity index 76%
rename from src/ttemainwindow.cpp
rename to src/mainwindow.cpp
index 2e155d385fd5aa0f522273a49d3b66770e51e1b2..8c7524f500a1d37f9e409920cb9fd8d6df901c6f 100644 (file)
@@ -1,5 +1,5 @@
 //
-// TTEMAINWINDOW.CPP - The TrueType Editor
+// MAINWINDOW.CPP - The TrueType Editor
 // by James L. Hammons
 // (C) 2004 Underground Software
 //
 #define DEBUGFOO                       // Various tool debugging...
 //#define DEBUGTP                              // Toolpalette debugging...
 
-//#include <QtGui>
-#include "ttemainwindow.h"
-#include "editwindow.h"
+#include "mainwindow.h"
 #include "charwindow.h"
+#include "editwindow.h"
 #include "ttedit.h"
 
-TTEMainWindow::TTEMainWindow()
+
+MainWindow::MainWindow()
 {
        ((TTEdit *)qApp)->charWnd = new CharWindow(this);
        editWnd = new EditWindow(this);
@@ -94,6 +94,10 @@ TTEMainWindow::TTEMainWindow()
        editToolBar->addAction(cutAct);
        editToolBar->addAction(copyAct);
        editToolBar->addAction(pasteAct);
+#else
+       CreateActions();
+       CreateMenus();
+       CreateToolbars();
 #endif
 
        //      Create status bar
@@ -110,17 +114,122 @@ TTEMainWindow::TTEMainWindow()
        ((TTEdit *)qApp)->charWnd->show();//eh?
 }
 
-void TTEMainWindow::closeEvent(QCloseEvent * event)
+
+//
+// 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 * action = new QAction(icon, name, this);
+       action->setToolTip(tooltip);
+       action->setStatusTip(statustip);
+       action->setShortcut(key);
+       action->setCheckable(checkable);
+
+       return action;
+}
+
+
+//
+// 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 * action = new QAction(icon, name, this);
+       action->setToolTip(tooltip);
+       action->setStatusTip(statustip);
+       QList<QKeySequence> keyList;
+       keyList.append(key1);
+       keyList.append(key2);
+       action->setShortcuts(keyList);
+       action->setCheckable(checkable);
+
+       return action;
+}
+
+
+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());
+
+       connect(newGlyphAct, SIGNAL(triggered()), this, SLOT(NewGlyph()));
+       connect(openFileAct, SIGNAL(triggered()), this, SLOT(OpenFile()));
+       connect(saveFileAct, SIGNAL(triggered()), this, SLOT(SaveFile()));
+}
+
+
+void MainWindow::CreateMenus(void)
+{
+       QMenu * menu = menuBar()->addMenu(tr("&File"));
+       menu->addAction(newGlyphAct);
+       menu->addAction(openFileAct);
+       menu->addAction(saveFileAct);
+//     menu->addAction(fileSaveAsAct);
+//     menu->addAction(fileCloseAct);
+}
+
+
+void MainWindow::CreateToolbars(void)
+{
+}
+
+
+void MainWindow::closeEvent(QCloseEvent * event)
 {
        WriteSettings();
        event->accept(); // ignore() if can't close for some reason
 }
 
-void TTEMainWindow::Open(void)
+
+void MainWindow::NewGlyph(void)
 {
+       editWnd->pts.Clear();
+       ((TTEdit *)qApp)->charWnd->MakePathFromPoints(&(editWnd->pts));
+       ((TTEdit *)qApp)->charWnd->update();
+       editWnd->update();
 }
 
-void TTEMainWindow::ReadSettings(void)
+
+void MainWindow::OpenFile(void)
+{
+       QString filename = QFileDialog::getOpenFileName(this, tr("Open Glyph File"),
+               "./", tr("Glyph files (*.glyph)"));
+       FILE * file = fopen(filename.toAscii().data(), "r");
+
+       //need to pop an error box here...
+       if (file == 0)
+               return;
+
+       editWnd->pts.LoadGlyphFromFile(file);
+       fclose(file);
+
+       ((TTEdit *)qApp)->charWnd->MakePathFromPoints(&(editWnd->pts));
+       ((TTEdit *)qApp)->charWnd->update();
+       editWnd->update();
+}
+
+
+void MainWindow::SaveFile(void)
+{
+       QString filename = QFileDialog::getSaveFileName(this, tr("Save Glyph File"),
+               "./", tr("Glyph files (*.glyph)"));
+       FILE * file = fopen(filename.toAscii().data(), "w");
+
+       //need to pop an error box here...
+       if (file == 0)
+               return;
+
+       editWnd->pts.SaveGlyphToFile(file);
+       fclose(file);
+}
+
+
+void MainWindow::ReadSettings(void)
 {
        QSettings settings("Underground Software", "TTEdit");
        QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
@@ -133,7 +242,8 @@ void TTEMainWindow::ReadSettings(void)
        ((TTEdit *)qApp)->charWnd->move(pos);
 }
 
-void TTEMainWindow::WriteSettings(void)
+
+void MainWindow::WriteSettings(void)
 {
        QSettings settings("Underground Software", "TTEdit");
        settings.setValue("pos", pos());