]> Shamusworld >> Repos - architektonas/blob - src/applicationwindow.cpp
Added Settings dialog.
[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 #include "settingsdialog.h"
32 #include "generaltab.h"
33
34
35 ApplicationWindow::ApplicationWindow(): settings("Underground Software", "Architektonas")
36 {
37         drawing = new DrawingView(this);
38         drawing->setMouseTracking(true);                // We want *all* mouse events...!
39         setCentralWidget(drawing);
40
41         aboutWin = new AboutWindow(this);
42
43 //      ((TTEdit *)qApp)->charWnd = new CharWindow(this);
44
45         setWindowIcon(QIcon(":/res/atns-icon.png"));
46         setWindowTitle("Architektonas");
47
48         CreateActions();
49         CreateMenus();
50         CreateToolbars();
51
52         //      Create status bar
53         statusBar()->showMessage(tr("Ready"));
54
55         ReadSettings();
56
57 //      connect(textEdit->document(), SIGNAL(contentsChanged()),
58 //                      this, SLOT(documentWasModified()));
59
60 //      setCurrentFile("");
61         setUnifiedTitleAndToolBarOnMac(true);
62
63 //      ((TTEdit *)qApp)->charWnd->show();//eh?
64         Object::SetFont(new QFont("Verdana", 15, QFont::Bold));
65 }
66
67 void ApplicationWindow::closeEvent(QCloseEvent * event)
68 {
69         WriteSettings();
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???
72 }
73
74 //void ApplicationWindow::FileOpen(void)
75 //{
76 //}
77
78 void ApplicationWindow::FixAngle(void)
79 {
80         Object::SetFixedAngle(fixAngleAct->isChecked());
81 }
82
83 void ApplicationWindow::FixLength(void)
84 {
85         Object::SetFixedLength(fixLengthAct->isChecked());
86 }
87
88 void ApplicationWindow::DeleteTool(void)
89 {
90         Object::SetDeleteActive(deleteAct->isChecked());
91 }
92
93 void ApplicationWindow::DimensionTool(void)
94 {
95         Object::SetDimensionActive(addDimensionAct->isChecked());
96 }
97
98 void ApplicationWindow::RotateTool(void)
99 {
100         drawing->SetRotateToolActive(rotateAct->isChecked());
101 }
102
103 void ApplicationWindow::HelpAbout(void)
104 {
105         aboutWin->show();
106 }
107
108 void ApplicationWindow::Settings(void)
109 {
110         SettingsDialog dlg(this);
111         dlg.generalTab->antialiasChk->setChecked(drawing->useAntialiasing);
112
113         if (dlg.exec() == false)
114                 return;
115
116         // Deal with stuff here (since user hit "OK" button...)
117         drawing->useAntialiasing = dlg.generalTab->antialiasChk->isChecked();
118         WriteSettings();
119 }
120
121 void ApplicationWindow::CreateActions(void)
122 {
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()));
126
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()));
130
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()));
134
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()));
137
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()));
140
141         addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds a line to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
142
143         addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds a circle to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
144
145         addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds an arc to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
146
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()));
149
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()));
152
153         fileNewAct = CreateAction(tr("&New Drawing"), tr("New Drawing"), tr("Creates a new drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+n")));
154
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")));
156
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")));
158
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")));
160
161         fileCloseAct = CreateAction(tr("&Close Drawing"), tr("Close Drawing"), tr("Closes the current drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+w")));
162
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()));
165
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);//*/
173 }
174
175 //
176 // Consolidates action creation from a multi-step process to a single-step one.
177 //
178 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
179         QIcon icon, QKeySequence key, bool checkable/*= false*/)
180 {
181         QAction * action = new QAction(icon, name, this);
182         action->setToolTip(tooltip);
183         action->setStatusTip(statustip);
184         action->setShortcut(key);
185         action->setCheckable(checkable);
186
187         return action;
188 }
189
190 //
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.
193 //
194 QAction * ApplicationWindow::CreateAction2(QString name, QString tooltip, QString statustip,
195         QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/)
196 {
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);
205
206         return action;
207 }
208
209 void ApplicationWindow::CreateMenus(void)
210 {
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);
219
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);
233
234 //      editMenu = menuBar()->addMenu(tr("&Edit"));
235 //      editMenu->addAction(cutAct);
236 //      editMenu->addAction(copyAct);
237 //      editMenu->addAction(pasteAct);
238
239 //      menuBar()->addSeparator();
240
241         menu = menuBar()->addMenu(tr("&Help"));
242         menu->addAction(aboutAct);
243 //      helpMenu->addAction(aboutQtAct);
244 }
245
246 void ApplicationWindow::CreateToolbars(void)
247 {
248         QToolBar * toolbar = addToolBar(tr("File"));
249         toolbar->addAction(exitAct);
250
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);
260 }
261
262 void ApplicationWindow::ReadSettings(void)
263 {
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();
267         resize(size);
268         move(pos);
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);
273 }
274
275 void ApplicationWindow::WriteSettings(void)
276 {
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());
282 }