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 "generaltab.h"
33 #include "settingsdialog.h"
36 ApplicationWindow::ApplicationWindow(): settings("Underground Software", "Architektonas")
38 drawing = new DrawingView(this);
39 drawing->setMouseTracking(true); // We want *all* mouse events...!
40 setCentralWidget(drawing);
42 aboutWin = new AboutWindow(this);
44 // ((TTEdit *)qApp)->charWnd = new CharWindow(this);
46 setWindowIcon(QIcon(":/res/atns-icon.png"));
47 setWindowTitle("Architektonas");
54 statusBar()->showMessage(tr("Ready"));
58 // connect(textEdit->document(), SIGNAL(contentsChanged()),
59 // this, SLOT(documentWasModified()));
61 // setCurrentFile("");
62 setUnifiedTitleAndToolBarOnMac(true);
64 // ((TTEdit *)qApp)->charWnd->show();//eh?
65 Object::SetFont(new QFont("Verdana", 15, QFont::Bold));
68 void ApplicationWindow::closeEvent(QCloseEvent * event)
71 event->accept(); // Use ignore() if can't close for some reason
72 //Do we have a memory leak here if we don't delete the font in the Object???
75 //void ApplicationWindow::FileOpen(void)
79 void ApplicationWindow::FixAngle(void)
81 Object::SetFixedAngle(fixAngleAct->isChecked());
84 void ApplicationWindow::FixLength(void)
86 Object::SetFixedLength(fixLengthAct->isChecked());
89 void ApplicationWindow::DeleteTool(void)
91 Object::SetDeleteActive(deleteAct->isChecked());
94 void ApplicationWindow::DimensionTool(void)
96 Object::SetDimensionActive(addDimensionAct->isChecked());
99 void ApplicationWindow::RotateTool(void)
101 drawing->SetRotateToolActive(rotateAct->isChecked());
104 void ApplicationWindow::ZoomInTool(void)
106 //printf("Zoom in... level going from %02f to ", Painter::zoom);
107 // This just zooms leaving origin intact... should zoom in at the current center!
108 // drawing->ZoomIn();
109 Painter::zoom *= 2.0;
113 void ApplicationWindow::ZoomOutTool(void)
115 //printf("Zoom out...\n");
116 // This just zooms leaving origin intact... should zoom out at the current center!
117 // drawing->ZoomOut();
118 Painter::zoom /= 2.0;
122 void ApplicationWindow::HelpAbout(void)
127 void ApplicationWindow::Settings(void)
129 SettingsDialog dlg(this);
130 dlg.generalTab->antialiasChk->setChecked(drawing->useAntialiasing);
132 if (dlg.exec() == false)
135 // Deal with stuff here (since user hit "OK" button...)
136 drawing->useAntialiasing = dlg.generalTab->antialiasChk->isChecked();
140 void ApplicationWindow::CreateActions(void)
142 exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."),
143 QIcon(":/res/quit.png"), QKeySequence(tr("Ctrl+q")));
144 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
146 fixAngleAct = CreateAction(tr("Fix &Angle"), tr("Fix Angle"), tr("Fixes the angle of an object."),
147 QIcon(":/res/fix-angle.png"), QKeySequence(tr("F,A")), true);
148 connect(fixAngleAct, SIGNAL(triggered()), this, SLOT(FixAngle()));
150 fixLengthAct = CreateAction(tr("Fix &Length"), tr("Fix Length"), tr("Fixes the length of an object."),
151 QIcon(":/res/fix-length.png"), QKeySequence(tr("F,L")), true);
152 connect(fixLengthAct, SIGNAL(triggered()), this, SLOT(FixLength()));
154 deleteAct = CreateAction(tr("&Delete"), tr("Delete Object"), tr("Deletes selected objects."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
155 connect(deleteAct, SIGNAL(triggered()), this, SLOT(DeleteTool()));
157 addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/dimension-tool.png"), QKeySequence("D,I"), true);
158 connect(addDimensionAct, SIGNAL(triggered()), this, SLOT(DimensionTool()));
160 addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds a line to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
162 addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds a circle to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
164 addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds an arc to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
166 aboutAct = CreateAction(tr("About &Architektonas"), tr("About Architektonas"), tr("Gives information about this program."), QIcon(":/res/generic-tool.png"), QKeySequence());
167 connect(aboutAct, SIGNAL(triggered()), this, SLOT(HelpAbout()));
169 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);
170 connect(rotateAct, SIGNAL(triggered()), this, SLOT(RotateTool()));
172 zoomInAct = CreateAction(tr("Zoom &In"), tr("Zoom In"), tr("Zoom in on the document."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("=")));
173 connect(zoomInAct, SIGNAL(triggered()), this, SLOT(ZoomInTool()));
175 zoomOutAct = CreateAction(tr("Zoom &Out"), tr("Zoom Out"), tr("Zoom out of the document."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("-")));
176 connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(ZoomOutTool()));
178 fileNewAct = CreateAction(tr("&New Drawing"), tr("New Drawing"), tr("Creates a new drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+n")));
180 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")));
182 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")));
184 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")));
186 fileCloseAct = CreateAction(tr("&Close Drawing"), tr("Close Drawing"), tr("Closes the current drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+w")));
188 settingsAct = CreateAction(tr("&Settings"), tr("Settings"), tr("Change certain defaults for Architektonas."), QIcon(":/res/generic-tool.png"), QKeySequence());
189 connect(settingsAct, SIGNAL(triggered()), this, SLOT(Settings()));
191 //Hm. I think we'll have to have separate logic to do the "Radio Group Toolbar" thing...
192 /* QActionGroup * group = new QActionGroup(this);
193 group->addAction(deleteAct);
194 group->addAction(addDimensionAct);
195 group->addAction(addLineAct);
196 group->addAction(addCircleAct);
197 group->addAction(addArcAct);//*/
201 // Consolidates action creation from a multi-step process to a single-step one.
203 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
204 QIcon icon, QKeySequence key, bool checkable/*= false*/)
206 QAction * action = new QAction(icon, name, this);
207 action->setToolTip(tooltip);
208 action->setStatusTip(statustip);
209 action->setShortcut(key);
210 action->setCheckable(checkable);
216 // This is essentially the same as the previous function, but this allows more
217 // than one key sequence to be added as key shortcuts.
219 QAction * ApplicationWindow::CreateAction2(QString name, QString tooltip, QString statustip,
220 QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/)
222 QAction * action = new QAction(icon, name, this);
223 action->setToolTip(tooltip);
224 action->setStatusTip(statustip);
225 QList<QKeySequence> keyList;
226 keyList.append(key1);
227 keyList.append(key2);
228 action->setShortcuts(keyList);
229 action->setCheckable(checkable);
234 void ApplicationWindow::CreateMenus(void)
236 QMenu * menu = menuBar()->addMenu(tr("&File"));
237 menu->addAction(fileNewAct);
238 menu->addAction(fileOpenAct);
239 menu->addAction(fileSaveAct);
240 menu->addAction(fileSaveAsAct);
241 menu->addAction(fileCloseAct);
242 menu->addSeparator();
243 menu->addAction(exitAct);
245 menu = menuBar()->addMenu(tr("&View"));
246 menu->addAction(zoomInAct);
247 menu->addAction(zoomOutAct);
249 menu = menuBar()->addMenu(tr("&Edit"));
250 menu->addAction(fixAngleAct);
251 menu->addAction(fixLengthAct);
252 menu->addAction(rotateAct);
253 menu->addSeparator();
254 menu->addAction(deleteAct);
255 menu->addSeparator();
256 menu->addAction(addLineAct);
257 menu->addAction(addCircleAct);
258 menu->addAction(addArcAct);
259 menu->addAction(addDimensionAct);
260 menu->addSeparator();
261 menu->addAction(settingsAct);
263 // editMenu = menuBar()->addMenu(tr("&Edit"));
264 // editMenu->addAction(cutAct);
265 // editMenu->addAction(copyAct);
266 // editMenu->addAction(pasteAct);
268 // menuBar()->addSeparator();
270 menu = menuBar()->addMenu(tr("&Help"));
271 menu->addAction(aboutAct);
272 // helpMenu->addAction(aboutQtAct);
275 void ApplicationWindow::CreateToolbars(void)
277 QToolBar * toolbar = addToolBar(tr("File"));
278 toolbar->addAction(exitAct);
280 toolbar = addToolBar(tr("View"));
281 toolbar->addAction(zoomInAct);
282 toolbar->addAction(zoomOutAct);
284 toolbar = addToolBar(tr("Edit"));
285 toolbar->addAction(fixAngleAct);
286 toolbar->addAction(fixLengthAct);
287 toolbar->addAction(rotateAct);
288 toolbar->addAction(deleteAct);
289 toolbar->addAction(addLineAct);
290 toolbar->addAction(addCircleAct);
291 toolbar->addAction(addArcAct);
292 toolbar->addAction(addDimensionAct);
295 void ApplicationWindow::ReadSettings(void)
297 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
298 QSize size = settings.value("size", QSize(400, 400)).toSize();
299 drawing->useAntialiasing = settings.value("useAntialiasing", true).toBool();
302 // pos = settings.value("charWndPos", QPoint(0, 0)).toPoint();
303 // size = settings.value("charWndSize", QSize(200, 200)).toSize();
304 // ((TTEdit *)qApp)->charWnd->resize(size);
305 // ((TTEdit *)qApp)->charWnd->move(pos);
308 void ApplicationWindow::WriteSettings(void)
310 settings.setValue("pos", pos());
311 settings.setValue("size", size());
312 settings.setValue("useAntialiasing", drawing->useAntialiasing);
313 // settings.setValue("charWndPos", ((TTEdit *)qApp)->charWnd->pos());
314 // settings.setValue("charWndSize", ((TTEdit *)qApp)->charWnd->size());