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"
33 ApplicationWindow::ApplicationWindow(): settings("Underground Software", "Architektonas")
35 drawing = new DrawingView(this);
36 drawing->setMouseTracking(true); // We want *all* mouse events...!
37 setCentralWidget(drawing);
39 aboutWin = new AboutWindow(this);
41 // ((TTEdit *)qApp)->charWnd = new CharWindow(this);
43 setWindowIcon(QIcon(":/res/atns-icon.png"));
44 setWindowTitle("Architektonas");
51 statusBar()->showMessage(tr("Ready"));
55 // connect(textEdit->document(), SIGNAL(contentsChanged()),
56 // this, SLOT(documentWasModified()));
58 // setCurrentFile("");
59 setUnifiedTitleAndToolBarOnMac(true);
61 // ((TTEdit *)qApp)->charWnd->show();//eh?
62 Object::SetFont(new QFont("Verdana", 15, QFont::Bold));
65 void ApplicationWindow::closeEvent(QCloseEvent * event)
68 event->accept(); // Use ignore() if can't close for some reason
69 //Do we have a memory leak here if we don't delete the font in the Object???
72 //void ApplicationWindow::FileOpen(void)
76 void ApplicationWindow::FixAngle(void)
78 Object::SetFixedAngle(fixAngleAct->isChecked());
81 void ApplicationWindow::FixLength(void)
83 Object::SetFixedLength(fixLengthAct->isChecked());
86 void ApplicationWindow::DeleteTool(void)
88 Object::SetDeleteActive(deleteAct->isChecked());
91 void ApplicationWindow::DimensionTool(void)
93 Object::SetDimensionActive(addDimensionAct->isChecked());
96 void ApplicationWindow::RotateTool(void)
98 drawing->SetRotateToolActive(rotateAct->isChecked());
101 void ApplicationWindow::HelpAbout(void)
106 void ApplicationWindow::CreateActions(void)
108 exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."),
109 QIcon(":/res/quit.png"), QKeySequence(tr("Ctrl+q")));
110 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
112 fixAngleAct = CreateAction(tr("Fix &Angle"), tr("Fix Angle"), tr("Fixes the angle of an object."),
113 QIcon(":/res/fix-angle.png"), QKeySequence(tr("F,A")), true);
114 connect(fixAngleAct, SIGNAL(triggered()), this, SLOT(FixAngle()));
116 fixLengthAct = CreateAction(tr("Fix &Length"), tr("Fix Length"), tr("Fixes the length of an object."),
117 QIcon(":/res/fix-length.png"), QKeySequence(tr("F,L")), true);
118 connect(fixLengthAct, SIGNAL(triggered()), this, SLOT(FixLength()));
120 deleteAct = CreateAction(tr("&Delete"), tr("Delete Object"), tr("Deletes selected objects."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
121 connect(deleteAct, SIGNAL(triggered()), this, SLOT(DeleteTool()));
123 addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/dimension-tool.png"), QKeySequence("D,I"), true);
124 connect(addDimensionAct, SIGNAL(triggered()), this, SLOT(DimensionTool()));
126 addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds a line to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
128 addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds a circle to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
130 addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds an arc to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
132 aboutAct = CreateAction(tr("About &Architektonas"), tr("About Architektonas"), tr("Gives information about this program."), QIcon(":/res/generic-tool.png"), QKeySequence());
133 connect(aboutAct, SIGNAL(triggered()), this, SLOT(HelpAbout()));
135 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);
136 connect(rotateAct, SIGNAL(triggered()), this, SLOT(RotateTool()));
138 fileNewAct = CreateAction(tr("&New Drawing"), tr("New Drawing"), tr("Creates a new drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+n")));
140 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")));
142 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")));
144 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")));
146 fileCloseAct = CreateAction(tr("&Close Drawing"), tr("Close Drawing"), tr("Closes the current drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+w")));
148 settingsAct = CreateAction(tr("&Settings"), tr("Settings"), tr("Change certain defaults for Architektonas."), QIcon(":/res/generic-tool.png"), QKeySequence());
150 //Hm. I think we'll have to have separate logic to do the "Radio Group Toolbar" thing...
151 /* QActionGroup * group = new QActionGroup(this);
152 group->addAction(deleteAct);
153 group->addAction(addDimensionAct);
154 group->addAction(addLineAct);
155 group->addAction(addCircleAct);
156 group->addAction(addArcAct);//*/
160 // Consolidates action creation from a multi-step process to a single-step one.
162 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
163 QIcon icon, QKeySequence key, bool checkable/*= false*/)
165 QAction * action = new QAction(icon, name, this);
166 action->setToolTip(tooltip);
167 action->setStatusTip(statustip);
168 action->setShortcut(key);
169 action->setCheckable(checkable);
175 // This is essentially the same as the previous function, but this allows more
176 // than one key sequence to be added as key shortcuts.
178 QAction * ApplicationWindow::CreateAction2(QString name, QString tooltip, QString statustip,
179 QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/)
181 QAction * action = new QAction(icon, name, this);
182 action->setToolTip(tooltip);
183 action->setStatusTip(statustip);
184 QList<QKeySequence> keyList;
185 keyList.append(key1);
186 keyList.append(key2);
187 action->setShortcuts(keyList);
188 action->setCheckable(checkable);
193 void ApplicationWindow::CreateMenus(void)
195 QMenu * menu = menuBar()->addMenu(tr("&File"));
196 menu->addAction(fileNewAct);
197 menu->addAction(fileOpenAct);
198 menu->addAction(fileSaveAct);
199 menu->addAction(fileSaveAsAct);
200 menu->addAction(fileCloseAct);
201 menu->addSeparator();
202 menu->addAction(exitAct);
204 menu = menuBar()->addMenu(tr("&Edit"));
205 menu->addAction(fixAngleAct);
206 menu->addAction(fixLengthAct);
207 menu->addAction(rotateAct);
208 menu->addSeparator();
209 menu->addAction(deleteAct);
210 menu->addSeparator();
211 menu->addAction(addLineAct);
212 menu->addAction(addCircleAct);
213 menu->addAction(addArcAct);
214 menu->addAction(addDimensionAct);
215 menu->addSeparator();
216 menu->addAction(settingsAct);
218 // editMenu = menuBar()->addMenu(tr("&Edit"));
219 // editMenu->addAction(cutAct);
220 // editMenu->addAction(copyAct);
221 // editMenu->addAction(pasteAct);
223 // menuBar()->addSeparator();
225 menu = menuBar()->addMenu(tr("&Help"));
226 menu->addAction(aboutAct);
227 // helpMenu->addAction(aboutQtAct);
230 void ApplicationWindow::CreateToolbars(void)
232 QToolBar * toolbar = addToolBar(tr("File"));
233 toolbar->addAction(exitAct);
235 toolbar = addToolBar(tr("Edit"));
236 toolbar->addAction(fixAngleAct);
237 toolbar->addAction(fixLengthAct);
238 toolbar->addAction(rotateAct);
239 toolbar->addAction(deleteAct);
240 toolbar->addAction(addLineAct);
241 toolbar->addAction(addCircleAct);
242 toolbar->addAction(addArcAct);
243 toolbar->addAction(addDimensionAct);
246 void ApplicationWindow::ReadSettings(void)
248 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
249 QSize size = settings.value("size", QSize(400, 400)).toSize();
250 drawing->useAntialiasing = settings.value("useAntialiasing", true).toBool();
253 // pos = settings.value("charWndPos", QPoint(0, 0)).toPoint();
254 // size = settings.value("charWndSize", QSize(200, 200)).toSize();
255 // ((TTEdit *)qApp)->charWnd->resize(size);
256 // ((TTEdit *)qApp)->charWnd->move(pos);
259 void ApplicationWindow::WriteSettings(void)
261 settings.setValue("pos", pos());
262 settings.setValue("size", size());
263 settings.setValue("useAntialiasing", drawing->useAntialiasing);
264 // settings.setValue("charWndPos", ((TTEdit *)qApp)->charWnd->pos());
265 // settings.setValue("charWndSize", ((TTEdit *)qApp)->charWnd->size());