]> Shamusworld >> Repos - architektonas/blob - src/applicationwindow.cpp
Added gratuitous About screen.
[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::HelpAbout(void)
97 {
98         aboutWin->show();
99 }
100
101 void ApplicationWindow::CreateActions(void)
102 {
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()));
106
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()));
110
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()));
114
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()));
117
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()));
120
121         addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds a line to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
122
123         addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds a circle to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
124
125         addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds an arc to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
126
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()));
129
130         //Hm.
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);//*/
137 }
138
139 //
140 // Consolidates action creation from a multi-step process to a single-step one.
141 //
142 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
143         QIcon icon, QKeySequence key, bool checkable/*= false*/)
144 {
145         QAction * action = new QAction(icon, name, this);
146         action->setToolTip(tooltip);
147         action->setStatusTip(statustip);
148         action->setShortcut(key);
149         action->setCheckable(checkable);
150
151         return action;
152 }
153
154 //
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.
157 //
158 QAction * ApplicationWindow::CreateAction2(QString name, QString tooltip, QString statustip,
159         QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/)
160 {
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);
169
170         return action;
171 }
172
173 void ApplicationWindow::CreateMenus(void)
174 {
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);
182
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);
193
194 //      editMenu = menuBar()->addMenu(tr("&Edit"));
195 //      editMenu->addAction(cutAct);
196 //      editMenu->addAction(copyAct);
197 //      editMenu->addAction(pasteAct);
198
199 //      menuBar()->addSeparator();
200
201         menu = menuBar()->addMenu(tr("&Help"));
202         menu->addAction(aboutAct);
203 //      helpMenu->addAction(aboutQtAct);
204 }
205
206 void ApplicationWindow::CreateToolbars(void)
207 {
208         QToolBar * toolbar = addToolBar(tr("File"));
209         toolbar->addAction(exitAct);
210
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);
219 }
220
221 void ApplicationWindow::ReadSettings(void)
222 {
223         QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
224         QSize size = settings.value("size", QSize(400, 400)).toSize();
225         resize(size);
226         move(pos);
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);
231 }
232
233 void ApplicationWindow::WriteSettings(void)
234 {
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());
239 }