//
-// 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);
editToolBar->addAction(cutAct);
editToolBar->addAction(copyAct);
editToolBar->addAction(pasteAct);
+#else
+ CreateActions();
+ CreateMenus();
+ CreateToolbars();
#endif
// Create status bar
((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();
((TTEdit *)qApp)->charWnd->move(pos);
}
-void TTEMainWindow::WriteSettings(void)
+
+void MainWindow::WriteSettings(void)
{
QSettings settings("Underground Software", "TTEdit");
settings.setValue("pos", pos());