2 // applicationwindow.cpp: Architektonas
4 // Part of the Architektonas Project
5 // (C) 2011 Underground Software
6 // See the README and GPLv3 files for licensing and warranty information
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -------------------------------------------------------------
12 // JLH 03/22/2011 Created this file
22 // Uncomment this for debugging...
24 //#define DEBUGFOO // Various tool debugging...
25 //#define DEBUGTP // Toolpalette debugging...
27 #include "applicationwindow.h"
29 #include "drawingview.h"
32 ApplicationWindow::ApplicationWindow(): settings("Underground Software", "Architektonas")
34 drawing = new DrawingView(this);
35 setCentralWidget(drawing);
37 // ((TTEdit *)qApp)->charWnd = new CharWindow(this);
38 // editWnd = new EditWindow(this);
39 // setCentralWidget(editWnd);
40 setWindowIcon(QIcon(":/res/atns-icon.png"));
41 setWindowTitle("Architektonas");
48 newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
49 newAct->setShortcuts(QKeySequence::New);
50 newAct->setStatusTip(tr("Create a new file"));
51 connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
53 openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
54 openAct->setShortcuts(QKeySequence::Open);
55 openAct->setStatusTip(tr("Open an existing file"));
56 connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
58 aboutQtAct = new QAction(tr("About &Qt"), this);
59 aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
60 connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
63 fileMenu = menuBar()->addMenu(tr("&File"));
64 fileMenu->addAction(newAct);
65 fileMenu->addAction(openAct);
66 fileMenu->addAction(saveAct);
67 fileMenu->addAction(saveAsAct);
68 fileMenu->addSeparator();
69 fileMenu->addAction(exitAct);
71 editMenu = menuBar()->addMenu(tr("&Edit"));
72 editMenu->addAction(cutAct);
73 editMenu->addAction(copyAct);
74 editMenu->addAction(pasteAct);
76 menuBar()->addSeparator();
78 helpMenu = menuBar()->addMenu(tr("&Help"));
79 helpMenu->addAction(aboutAct);
80 helpMenu->addAction(aboutQtAct);
83 fileToolBar = addToolBar(tr("File"));
84 fileToolBar->addAction(newAct);
85 fileToolBar->addAction(openAct);
86 fileToolBar->addAction(saveAct);
88 editToolBar = addToolBar(tr("Edit"));
89 editToolBar->addAction(cutAct);
90 editToolBar->addAction(copyAct);
91 editToolBar->addAction(pasteAct);
95 statusBar()->showMessage(tr("Ready"));
99 // connect(textEdit->document(), SIGNAL(contentsChanged()),
100 // this, SLOT(documentWasModified()));
102 // setCurrentFile("");
103 setUnifiedTitleAndToolBarOnMac(true);
105 // ((TTEdit *)qApp)->charWnd->show();//eh?
106 Object::SetFont(new QFont("Verdana", 15, QFont::Bold));
109 void ApplicationWindow::closeEvent(QCloseEvent * event)
112 event->accept(); // Use ignore() if can't close for some reason
113 //Do we have a memory leak here if we don't delete the font in the Object???
116 //void ApplicationWindow::FileOpen(void)
120 void ApplicationWindow::FixAngle(void)
122 Object::SetFixedAngle(fixAngleAct->isChecked());
125 void ApplicationWindow::FixLength(void)
127 Object::SetFixedLength(fixLengthAct->isChecked());
130 void ApplicationWindow::CreateActions(void)
132 exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."),
133 QIcon(":/res/quit.png"), QKeySequence(tr("Ctrl+q")));
134 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
136 fixAngleAct = CreateAction(tr("Fix &Angle"), tr("Fix Angle"), tr("Fixes the angle of an object."),
137 QIcon(":/res/fix-angle.png"), QKeySequence(tr("F,A")), true);
138 connect(fixAngleAct, SIGNAL(triggered()), this, SLOT(FixAngle()));
140 fixLengthAct = CreateAction(tr("Fix &Length"), tr("Fix Length"), tr("Fixes the length of an object."),
141 QIcon(":/res/fix-length.png"), QKeySequence(tr("F,L")), true);
142 connect(fixLengthAct, SIGNAL(triggered()), this, SLOT(FixLength()));
146 // Consolidates action creation from a multi-step process to a single-step one.
148 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
149 QIcon icon, QKeySequence key, bool checkable/*= false*/)
151 QAction * action = new QAction(icon, name, this);
152 action->setToolTip(tooltip);
153 action->setStatusTip(statustip);
154 action->setShortcut(key);
155 action->setCheckable(checkable);
161 // This is essentially the same as the previous function, but this allows more
162 // than one key sequence to be added as key shortcuts.
164 QAction * ApplicationWindow::CreateAction2(QString name, QString tooltip, QString statustip,
165 QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/)
167 QAction * action = new QAction(icon, name, this);
168 action->setToolTip(tooltip);
169 action->setStatusTip(statustip);
170 QList<QKeySequence> keyList;
171 keyList.append(key1);
172 keyList.append(key2);
173 action->setShortcuts(keyList);
174 action->setCheckable(checkable);
179 void ApplicationWindow::CreateMenus(void)
181 QMenu * menu = menuBar()->addMenu(tr("&File"));
182 // fileMenu->addAction(newAct);
183 // fileMenu->addAction(openAct);
184 // fileMenu->addAction(saveAct);
185 // fileMenu->addAction(saveAsAct);
186 // fileMenu->addSeparator();
187 menu->addAction(exitAct);
189 menu = menuBar()->addMenu(tr("&Edit"));
190 menu->addAction(fixAngleAct);
191 menu->addAction(fixLengthAct);
192 // editMenu = menuBar()->addMenu(tr("&Edit"));
193 // editMenu->addAction(cutAct);
194 // editMenu->addAction(copyAct);
195 // editMenu->addAction(pasteAct);
197 // menuBar()->addSeparator();
199 // helpMenu = menuBar()->addMenu(tr("&Help"));
200 // helpMenu->addAction(aboutAct);
201 // helpMenu->addAction(aboutQtAct);
204 void ApplicationWindow::CreateToolbars(void)
206 QToolBar * toolbar = addToolBar(tr("File"));
207 toolbar->addAction(exitAct);
209 toolbar = addToolBar(tr("Edit"));
210 toolbar->addAction(fixAngleAct);
211 toolbar->addAction(fixLengthAct);
214 void ApplicationWindow::ReadSettings(void)
216 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
217 QSize size = settings.value("size", QSize(400, 400)).toSize();
220 // pos = settings.value("charWndPos", QPoint(0, 0)).toPoint();
221 // size = settings.value("charWndSize", QSize(200, 200)).toSize();
222 // ((TTEdit *)qApp)->charWnd->resize(size);
223 // ((TTEdit *)qApp)->charWnd->move(pos);
226 void ApplicationWindow::WriteSettings(void)
228 settings.setValue("pos", pos());
229 settings.setValue("size", size());
230 // settings.setValue("charWndPos", ((TTEdit *)qApp)->charWnd->pos());
231 // settings.setValue("charWndSize", ((TTEdit *)qApp)->charWnd->size());