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"
30 #include "drawingview.h"
31 #include "settingsdialog.h"
32 #include "generaltab.h"
35 ApplicationWindow::ApplicationWindow(): settings("Underground Software", "Architektonas")
37 drawing = new DrawingView(this);
38 drawing->setMouseTracking(true); // We want *all* mouse events...!
39 setCentralWidget(drawing);
41 aboutWin = new AboutWindow(this);
43 // ((TTEdit *)qApp)->charWnd = new CharWindow(this);
45 setWindowIcon(QIcon(":/res/atns-icon.png"));
46 setWindowTitle("Architektonas");
53 statusBar()->showMessage(tr("Ready"));
57 // connect(textEdit->document(), SIGNAL(contentsChanged()),
58 // this, SLOT(documentWasModified()));
60 // setCurrentFile("");
61 setUnifiedTitleAndToolBarOnMac(true);
63 // ((TTEdit *)qApp)->charWnd->show();//eh?
64 Object::SetFont(new QFont("Verdana", 15, QFont::Bold));
67 void ApplicationWindow::closeEvent(QCloseEvent * event)
70 event->accept(); // Use ignore() if can't close for some reason
71 //Do we have a memory leak here if we don't delete the font in the Object???
74 //void ApplicationWindow::FileOpen(void)
78 void ApplicationWindow::FixAngle(void)
80 Object::SetFixedAngle(fixAngleAct->isChecked());
83 void ApplicationWindow::FixLength(void)
85 Object::SetFixedLength(fixLengthAct->isChecked());
88 void ApplicationWindow::DeleteTool(void)
90 Object::SetDeleteActive(deleteAct->isChecked());
93 void ApplicationWindow::DimensionTool(void)
95 Object::SetDimensionActive(addDimensionAct->isChecked());
98 void ApplicationWindow::RotateTool(void)
100 drawing->SetRotateToolActive(rotateAct->isChecked());
103 void ApplicationWindow::HelpAbout(void)
108 void ApplicationWindow::Settings(void)
110 SettingsDialog dlg(this);
111 dlg.generalTab->antialiasChk->setChecked(drawing->useAntialiasing);
113 if (dlg.exec() == false)
116 // Deal with stuff here (since user hit "OK" button...)
117 drawing->useAntialiasing = dlg.generalTab->antialiasChk->isChecked();
121 void ApplicationWindow::CreateActions(void)
123 exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."),
124 QIcon(":/res/quit.png"), QKeySequence(tr("Ctrl+q")));
125 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
127 fixAngleAct = CreateAction(tr("Fix &Angle"), tr("Fix Angle"), tr("Fixes the angle of an object."),
128 QIcon(":/res/fix-angle.png"), QKeySequence(tr("F,A")), true);
129 connect(fixAngleAct, SIGNAL(triggered()), this, SLOT(FixAngle()));
131 fixLengthAct = CreateAction(tr("Fix &Length"), tr("Fix Length"), tr("Fixes the length of an object."),
132 QIcon(":/res/fix-length.png"), QKeySequence(tr("F,L")), true);
133 connect(fixLengthAct, SIGNAL(triggered()), this, SLOT(FixLength()));
135 deleteAct = CreateAction(tr("&Delete"), tr("Delete Object"), tr("Deletes selected objects."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
136 connect(deleteAct, SIGNAL(triggered()), this, SLOT(DeleteTool()));
138 addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/dimension-tool.png"), QKeySequence("D,I"), true);
139 connect(addDimensionAct, SIGNAL(triggered()), this, SLOT(DimensionTool()));
141 addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds a line to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
143 addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds a circle to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
145 addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds an arc to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
147 aboutAct = CreateAction(tr("About &Architektonas"), tr("About Architektonas"), tr("Gives information about this program."), QIcon(":/res/generic-tool.png"), QKeySequence());
148 connect(aboutAct, SIGNAL(triggered()), this, SLOT(HelpAbout()));
150 rotateAct = CreateAction(tr("&Rotate Objects"), tr("Rotate"), tr("Rotate object(s) around an arbitrary center."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("R,O")), true);
151 connect(rotateAct, SIGNAL(triggered()), this, SLOT(RotateTool()));
153 fileNewAct = CreateAction(tr("&New Drawing"), tr("New Drawing"), tr("Creates a new drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+n")));
155 fileOpenAct = CreateAction(tr("&Open Drawing"), tr("Open Drawing"), tr("Opens an existing drawing from a file."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+o")));
157 fileSaveAct = CreateAction(tr("&Save Drawing"), tr("Save Drawing"), tr("Saves the current drawing to a file."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+s")));
159 fileSaveAsAct = CreateAction(tr("Save Drawing &As"), tr("Save As"), tr("Saves the current drawing to a file with a different name."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+Shift+s")));
161 fileCloseAct = CreateAction(tr("&Close Drawing"), tr("Close Drawing"), tr("Closes the current drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+w")));
163 settingsAct = CreateAction(tr("&Settings"), tr("Settings"), tr("Change certain defaults for Architektonas."), QIcon(":/res/generic-tool.png"), QKeySequence());
164 connect(settingsAct, SIGNAL(triggered()), this, SLOT(Settings()));
166 //Hm. I think we'll have to have separate logic to do the "Radio Group Toolbar" thing...
167 /* QActionGroup * group = new QActionGroup(this);
168 group->addAction(deleteAct);
169 group->addAction(addDimensionAct);
170 group->addAction(addLineAct);
171 group->addAction(addCircleAct);
172 group->addAction(addArcAct);//*/
176 // Consolidates action creation from a multi-step process to a single-step one.
178 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
179 QIcon icon, QKeySequence key, bool checkable/*= false*/)
181 QAction * action = new QAction(icon, name, this);
182 action->setToolTip(tooltip);
183 action->setStatusTip(statustip);
184 action->setShortcut(key);
185 action->setCheckable(checkable);
191 // This is essentially the same as the previous function, but this allows more
192 // than one key sequence to be added as key shortcuts.
194 QAction * ApplicationWindow::CreateAction2(QString name, QString tooltip, QString statustip,
195 QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/)
197 QAction * action = new QAction(icon, name, this);
198 action->setToolTip(tooltip);
199 action->setStatusTip(statustip);
200 QList<QKeySequence> keyList;
201 keyList.append(key1);
202 keyList.append(key2);
203 action->setShortcuts(keyList);
204 action->setCheckable(checkable);
209 void ApplicationWindow::CreateMenus(void)
211 QMenu * menu = menuBar()->addMenu(tr("&File"));
212 menu->addAction(fileNewAct);
213 menu->addAction(fileOpenAct);
214 menu->addAction(fileSaveAct);
215 menu->addAction(fileSaveAsAct);
216 menu->addAction(fileCloseAct);
217 menu->addSeparator();
218 menu->addAction(exitAct);
220 menu = menuBar()->addMenu(tr("&Edit"));
221 menu->addAction(fixAngleAct);
222 menu->addAction(fixLengthAct);
223 menu->addAction(rotateAct);
224 menu->addSeparator();
225 menu->addAction(deleteAct);
226 menu->addSeparator();
227 menu->addAction(addLineAct);
228 menu->addAction(addCircleAct);
229 menu->addAction(addArcAct);
230 menu->addAction(addDimensionAct);
231 menu->addSeparator();
232 menu->addAction(settingsAct);
234 // editMenu = menuBar()->addMenu(tr("&Edit"));
235 // editMenu->addAction(cutAct);
236 // editMenu->addAction(copyAct);
237 // editMenu->addAction(pasteAct);
239 // menuBar()->addSeparator();
241 menu = menuBar()->addMenu(tr("&Help"));
242 menu->addAction(aboutAct);
243 // helpMenu->addAction(aboutQtAct);
246 void ApplicationWindow::CreateToolbars(void)
248 QToolBar * toolbar = addToolBar(tr("File"));
249 toolbar->addAction(exitAct);
251 toolbar = addToolBar(tr("Edit"));
252 toolbar->addAction(fixAngleAct);
253 toolbar->addAction(fixLengthAct);
254 toolbar->addAction(rotateAct);
255 toolbar->addAction(deleteAct);
256 toolbar->addAction(addLineAct);
257 toolbar->addAction(addCircleAct);
258 toolbar->addAction(addArcAct);
259 toolbar->addAction(addDimensionAct);
262 void ApplicationWindow::ReadSettings(void)
264 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
265 QSize size = settings.value("size", QSize(400, 400)).toSize();
266 drawing->useAntialiasing = settings.value("useAntialiasing", true).toBool();
269 // pos = settings.value("charWndPos", QPoint(0, 0)).toPoint();
270 // size = settings.value("charWndSize", QSize(200, 200)).toSize();
271 // ((TTEdit *)qApp)->charWnd->resize(size);
272 // ((TTEdit *)qApp)->charWnd->move(pos);
275 void ApplicationWindow::WriteSettings(void)
277 settings.setValue("pos", pos());
278 settings.setValue("size", size());
279 settings.setValue("useAntialiasing", drawing->useAntialiasing);
280 // settings.setValue("charWndPos", ((TTEdit *)qApp)->charWnd->pos());
281 // settings.setValue("charWndSize", ((TTEdit *)qApp)->charWnd->size());