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::HelpAbout(void)
101 void ApplicationWindow::CreateActions(void)
103 exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."),
104 QIcon(":/res/quit.png"), QKeySequence(tr("Ctrl+q")));
105 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
107 fixAngleAct = CreateAction(tr("Fix &Angle"), tr("Fix Angle"), tr("Fixes the angle of an object."),
108 QIcon(":/res/fix-angle.png"), QKeySequence(tr("F,A")), true);
109 connect(fixAngleAct, SIGNAL(triggered()), this, SLOT(FixAngle()));
111 fixLengthAct = CreateAction(tr("Fix &Length"), tr("Fix Length"), tr("Fixes the length of an object."),
112 QIcon(":/res/fix-length.png"), QKeySequence(tr("F,L")), true);
113 connect(fixLengthAct, SIGNAL(triggered()), this, SLOT(FixLength()));
115 deleteAct = CreateAction(tr("&Delete"), tr("Delete Object"), tr("Deletes selected objects."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
116 connect(deleteAct, SIGNAL(triggered()), this, SLOT(DeleteTool()));
118 addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/dimension-tool.png"), QKeySequence("D, I"), true);
119 connect(addDimensionAct, SIGNAL(triggered()), this, SLOT(DimensionTool()));
121 addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds a line to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
123 addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds a circle to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
125 addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds an arc to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
127 aboutAct = CreateAction(tr("About &Architektonas"), tr("About Architektonas"), tr("Gives information about this program."), QIcon(":/res/generic-tool.png"), QKeySequence());
128 connect(aboutAct, SIGNAL(triggered()), this, SLOT(HelpAbout()));
131 /* QActionGroup * group = new QActionGroup(this);
132 group->addAction(deleteAct);
133 group->addAction(addDimensionAct);
134 group->addAction(addLineAct);
135 group->addAction(addCircleAct);
136 group->addAction(addArcAct);//*/
140 // Consolidates action creation from a multi-step process to a single-step one.
142 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
143 QIcon icon, QKeySequence key, bool checkable/*= false*/)
145 QAction * action = new QAction(icon, name, this);
146 action->setToolTip(tooltip);
147 action->setStatusTip(statustip);
148 action->setShortcut(key);
149 action->setCheckable(checkable);
155 // This is essentially the same as the previous function, but this allows more
156 // than one key sequence to be added as key shortcuts.
158 QAction * ApplicationWindow::CreateAction2(QString name, QString tooltip, QString statustip,
159 QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/)
161 QAction * action = new QAction(icon, name, this);
162 action->setToolTip(tooltip);
163 action->setStatusTip(statustip);
164 QList<QKeySequence> keyList;
165 keyList.append(key1);
166 keyList.append(key2);
167 action->setShortcuts(keyList);
168 action->setCheckable(checkable);
173 void ApplicationWindow::CreateMenus(void)
175 QMenu * menu = menuBar()->addMenu(tr("&File"));
176 // fileMenu->addAction(newAct);
177 // fileMenu->addAction(openAct);
178 // fileMenu->addAction(saveAct);
179 // fileMenu->addAction(saveAsAct);
180 // fileMenu->addSeparator();
181 menu->addAction(exitAct);
183 menu = menuBar()->addMenu(tr("&Edit"));
184 menu->addAction(fixAngleAct);
185 menu->addAction(fixLengthAct);
186 menu->addSeparator();
187 menu->addAction(deleteAct);
188 menu->addSeparator();
189 menu->addAction(addLineAct);
190 menu->addAction(addCircleAct);
191 menu->addAction(addArcAct);
192 menu->addAction(addDimensionAct);
194 // editMenu = menuBar()->addMenu(tr("&Edit"));
195 // editMenu->addAction(cutAct);
196 // editMenu->addAction(copyAct);
197 // editMenu->addAction(pasteAct);
199 // menuBar()->addSeparator();
201 menu = menuBar()->addMenu(tr("&Help"));
202 menu->addAction(aboutAct);
203 // helpMenu->addAction(aboutQtAct);
206 void ApplicationWindow::CreateToolbars(void)
208 QToolBar * toolbar = addToolBar(tr("File"));
209 toolbar->addAction(exitAct);
211 toolbar = addToolBar(tr("Edit"));
212 toolbar->addAction(fixAngleAct);
213 toolbar->addAction(fixLengthAct);
214 toolbar->addAction(deleteAct);
215 toolbar->addAction(addLineAct);
216 toolbar->addAction(addCircleAct);
217 toolbar->addAction(addArcAct);
218 toolbar->addAction(addDimensionAct);
221 void ApplicationWindow::ReadSettings(void)
223 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
224 QSize size = settings.value("size", QSize(400, 400)).toSize();
227 // pos = settings.value("charWndPos", QPoint(0, 0)).toPoint();
228 // size = settings.value("charWndSize", QSize(200, 200)).toSize();
229 // ((TTEdit *)qApp)->charWnd->resize(size);
230 // ((TTEdit *)qApp)->charWnd->move(pos);
233 void ApplicationWindow::WriteSettings(void)
235 settings.setValue("pos", pos());
236 settings.setValue("size", size());
237 // settings.setValue("charWndPos", ((TTEdit *)qApp)->charWnd->pos());
238 // settings.setValue("charWndSize", ((TTEdit *)qApp)->charWnd->size());