]> Shamusworld >> Repos - architektonas/blob - src/applicationwindow.cpp
Added new About logo, beginnings of generic rotation tool.
[architektonas] / src / applicationwindow.cpp
1 //
2 // applicationwindow.cpp: Architektonas
3 //
4 // Part of the Architektonas Project
5 // (C) 2011 Underground Software
6 // See the README and GPLv3 files for licensing and warranty information
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -------------------------------------------------------------
12 // JLH  03/22/2011  Created this file
13 //
14
15 // FIXED:
16 //
17 //
18 // STILL TO BE DONE:
19 //
20 //
21
22 // Uncomment this for debugging...
23 //#define DEBUG
24 //#define DEBUGFOO                      // Various tool debugging...
25 //#define DEBUGTP                               // Toolpalette debugging...
26
27 #include "applicationwindow.h"
28
29 #include "about.h"
30 #include "drawingview.h"
31
32
33 ApplicationWindow::ApplicationWindow(): settings("Underground Software", "Architektonas")
34 {
35         drawing = new DrawingView(this);
36         drawing->setMouseTracking(true);                // We want *all* mouse events...!
37         setCentralWidget(drawing);
38
39         aboutWin = new AboutWindow(this);
40
41 //      ((TTEdit *)qApp)->charWnd = new CharWindow(this);
42
43         setWindowIcon(QIcon(":/res/atns-icon.png"));
44         setWindowTitle("Architektonas");
45
46         CreateActions();
47         CreateMenus();
48         CreateToolbars();
49
50         //      Create status bar
51         statusBar()->showMessage(tr("Ready"));
52
53         ReadSettings();
54
55 //      connect(textEdit->document(), SIGNAL(contentsChanged()),
56 //                      this, SLOT(documentWasModified()));
57
58 //      setCurrentFile("");
59         setUnifiedTitleAndToolBarOnMac(true);
60
61 //      ((TTEdit *)qApp)->charWnd->show();//eh?
62         Object::SetFont(new QFont("Verdana", 15, QFont::Bold));
63 }
64
65 void ApplicationWindow::closeEvent(QCloseEvent * event)
66 {
67         WriteSettings();
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???
70 }
71
72 //void ApplicationWindow::FileOpen(void)
73 //{
74 //}
75
76 void ApplicationWindow::FixAngle(void)
77 {
78         Object::SetFixedAngle(fixAngleAct->isChecked());
79 }
80
81 void ApplicationWindow::FixLength(void)
82 {
83         Object::SetFixedLength(fixLengthAct->isChecked());
84 }
85
86 void ApplicationWindow::DeleteTool(void)
87 {
88         Object::SetDeleteActive(deleteAct->isChecked());
89 }
90
91 void ApplicationWindow::DimensionTool(void)
92 {
93         Object::SetDimensionActive(addDimensionAct->isChecked());
94 }
95
96 void ApplicationWindow::RotateTool(void)
97 {
98         drawing->SetRotateToolActive(rotateAct->isChecked());
99 }
100
101 void ApplicationWindow::HelpAbout(void)
102 {
103         aboutWin->show();
104 }
105
106 void ApplicationWindow::CreateActions(void)
107 {
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()));
111
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()));
115
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()));
119
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()));
122
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()));
125
126         addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds a line to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
127
128         addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds a circle to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
129
130         addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds an arc to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
131
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()));
134
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()));
137
138         fileNewAct = CreateAction(tr("&New Drawing"), tr("New Drawing"), tr("Creates a new drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+n")));
139
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")));
141
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")));
143
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")));
145
146         fileCloseAct = CreateAction(tr("&Close Drawing"), tr("Close Drawing"), tr("Closes the current drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+w")));
147
148         settingsAct = CreateAction(tr("&Settings"), tr("Settings"), tr("Change certain defaults for Architektonas."), QIcon(":/res/generic-tool.png"), QKeySequence());
149
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);//*/
157 }
158
159 //
160 // Consolidates action creation from a multi-step process to a single-step one.
161 //
162 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
163         QIcon icon, QKeySequence key, bool checkable/*= false*/)
164 {
165         QAction * action = new QAction(icon, name, this);
166         action->setToolTip(tooltip);
167         action->setStatusTip(statustip);
168         action->setShortcut(key);
169         action->setCheckable(checkable);
170
171         return action;
172 }
173
174 //
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.
177 //
178 QAction * ApplicationWindow::CreateAction2(QString name, QString tooltip, QString statustip,
179         QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/)
180 {
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);
189
190         return action;
191 }
192
193 void ApplicationWindow::CreateMenus(void)
194 {
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);
203
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);
217
218 //      editMenu = menuBar()->addMenu(tr("&Edit"));
219 //      editMenu->addAction(cutAct);
220 //      editMenu->addAction(copyAct);
221 //      editMenu->addAction(pasteAct);
222
223 //      menuBar()->addSeparator();
224
225         menu = menuBar()->addMenu(tr("&Help"));
226         menu->addAction(aboutAct);
227 //      helpMenu->addAction(aboutQtAct);
228 }
229
230 void ApplicationWindow::CreateToolbars(void)
231 {
232         QToolBar * toolbar = addToolBar(tr("File"));
233         toolbar->addAction(exitAct);
234
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);
244 }
245
246 void ApplicationWindow::ReadSettings(void)
247 {
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();
251         resize(size);
252         move(pos);
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);
257 }
258
259 void ApplicationWindow::WriteSettings(void)
260 {
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());
266 }