]> Shamusworld >> Repos - architektonas/blob - src/applicationwindow.cpp
Major refactor of Architektonas: Jettisoning old cruft.
[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 "drawingview.h"
30
31
32 ApplicationWindow::ApplicationWindow(): settings("Underground Software", "Architektonas")
33 {
34         drawing = new DrawingView(this);
35         setCentralWidget(drawing);
36
37 //      ((TTEdit *)qApp)->charWnd = new CharWindow(this);
38 //      editWnd = new EditWindow(this);
39 //      setCentralWidget(editWnd);
40         setWindowIcon(QIcon(":/res/atns-icon.png"));
41         setWindowTitle("Architektonas");
42
43         CreateActions();
44         CreateMenus();
45         CreateToolbars();
46 #if 0
47 //      createActions();
48         newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
49         newAct->setShortcuts(QKeySequence::New);
50         newAct->setStatusTip(tr("Create a new file"));
51         connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
52
53         openAct = new QAction(QIcon(":/images/open.png"), tr("&Open..."), this);
54         openAct->setShortcuts(QKeySequence::Open);
55         openAct->setStatusTip(tr("Open an existing file"));
56         connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
57
58         aboutQtAct = new QAction(tr("About &Qt"), this);
59         aboutQtAct->setStatusTip(tr("Show the Qt library's About box"));
60         connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
61
62 //      createMenus();
63         fileMenu = menuBar()->addMenu(tr("&File"));
64         fileMenu->addAction(newAct);
65         fileMenu->addAction(openAct);
66         fileMenu->addAction(saveAct);
67         fileMenu->addAction(saveAsAct);
68         fileMenu->addSeparator();
69         fileMenu->addAction(exitAct);
70
71         editMenu = menuBar()->addMenu(tr("&Edit"));
72         editMenu->addAction(cutAct);
73         editMenu->addAction(copyAct);
74         editMenu->addAction(pasteAct);
75
76         menuBar()->addSeparator();
77
78         helpMenu = menuBar()->addMenu(tr("&Help"));
79         helpMenu->addAction(aboutAct);
80         helpMenu->addAction(aboutQtAct);
81
82 //      createToolBars();
83         fileToolBar = addToolBar(tr("File"));
84         fileToolBar->addAction(newAct);
85         fileToolBar->addAction(openAct);
86         fileToolBar->addAction(saveAct);
87
88         editToolBar = addToolBar(tr("Edit"));
89         editToolBar->addAction(cutAct);
90         editToolBar->addAction(copyAct);
91         editToolBar->addAction(pasteAct);
92 #endif
93
94         //      Create status bar
95         statusBar()->showMessage(tr("Ready"));
96
97         ReadSettings();
98
99 //      connect(textEdit->document(), SIGNAL(contentsChanged()),
100 //                      this, SLOT(documentWasModified()));
101
102 //      setCurrentFile("");
103         setUnifiedTitleAndToolBarOnMac(true);
104
105 //      ((TTEdit *)qApp)->charWnd->show();//eh?
106         Object::SetFont(new QFont("Verdana", 15, QFont::Bold));
107 }
108
109 void ApplicationWindow::closeEvent(QCloseEvent * event)
110 {
111         WriteSettings();
112         event->accept();                                                        // Use ignore() if can't close for some reason
113         //Do we have a memory leak here if we don't delete the font in the Object???
114 }
115
116 //void ApplicationWindow::FileOpen(void)
117 //{
118 //}
119
120 void ApplicationWindow::FixAngle(void)
121 {
122         Object::SetFixedAngle(fixAngleAct->isChecked());
123 }
124
125 void ApplicationWindow::FixLength(void)
126 {
127         Object::SetFixedLength(fixLengthAct->isChecked());
128 }
129
130 void ApplicationWindow::CreateActions(void)
131 {
132         exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."),
133                 QIcon(":/res/quit.png"), QKeySequence(tr("Ctrl+q")));
134         connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
135
136         fixAngleAct = CreateAction(tr("Fix &Angle"), tr("Fix Angle"), tr("Fixes the angle of an object."),
137                 QIcon(":/res/fix-angle.png"), QKeySequence(tr("F,A")), true);
138         connect(fixAngleAct, SIGNAL(triggered()), this, SLOT(FixAngle()));
139
140         fixLengthAct = CreateAction(tr("Fix &Length"), tr("Fix Length"), tr("Fixes the length of an object."),
141                 QIcon(":/res/fix-length.png"), QKeySequence(tr("F,L")), true);
142         connect(fixLengthAct, SIGNAL(triggered()), this, SLOT(FixLength()));
143 }
144
145 //
146 // Consolidates action creation from a multi-step process to a single-step one.
147 //
148 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
149         QIcon icon, QKeySequence key, bool checkable/*= false*/)
150 {
151         QAction * action = new QAction(icon, name, this);
152         action->setToolTip(tooltip);
153         action->setStatusTip(statustip);
154         action->setShortcut(key);
155         action->setCheckable(checkable);
156
157         return action;
158 }
159
160 //
161 // This is essentially the same as the previous function, but this allows more
162 // than one key sequence to be added as key shortcuts.
163 //
164 QAction * ApplicationWindow::CreateAction2(QString name, QString tooltip, QString statustip,
165         QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/)
166 {
167         QAction * action = new QAction(icon, name, this);
168         action->setToolTip(tooltip);
169         action->setStatusTip(statustip);
170         QList<QKeySequence> keyList;
171         keyList.append(key1);
172         keyList.append(key2);
173         action->setShortcuts(keyList);
174         action->setCheckable(checkable);
175
176         return action;
177 }
178
179 void ApplicationWindow::CreateMenus(void)
180 {
181         QMenu * menu = menuBar()->addMenu(tr("&File"));
182 //      fileMenu->addAction(newAct);
183 //      fileMenu->addAction(openAct);
184 //      fileMenu->addAction(saveAct);
185 //      fileMenu->addAction(saveAsAct);
186 //      fileMenu->addSeparator();
187         menu->addAction(exitAct);
188
189         menu = menuBar()->addMenu(tr("&Edit"));
190         menu->addAction(fixAngleAct);
191         menu->addAction(fixLengthAct);
192 //      editMenu = menuBar()->addMenu(tr("&Edit"));
193 //      editMenu->addAction(cutAct);
194 //      editMenu->addAction(copyAct);
195 //      editMenu->addAction(pasteAct);
196
197 //      menuBar()->addSeparator();
198
199 //      helpMenu = menuBar()->addMenu(tr("&Help"));
200 //      helpMenu->addAction(aboutAct);
201 //      helpMenu->addAction(aboutQtAct);
202 }
203
204 void ApplicationWindow::CreateToolbars(void)
205 {
206         QToolBar * toolbar = addToolBar(tr("File"));
207         toolbar->addAction(exitAct);
208
209         toolbar = addToolBar(tr("Edit"));
210         toolbar->addAction(fixAngleAct);
211         toolbar->addAction(fixLengthAct);
212 }
213
214 void ApplicationWindow::ReadSettings(void)
215 {
216         QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
217         QSize size = settings.value("size", QSize(400, 400)).toSize();
218         resize(size);
219         move(pos);
220 //      pos = settings.value("charWndPos", QPoint(0, 0)).toPoint();
221 //      size = settings.value("charWndSize", QSize(200, 200)).toSize();
222 //      ((TTEdit *)qApp)->charWnd->resize(size);
223 //      ((TTEdit *)qApp)->charWnd->move(pos);
224 }
225
226 void ApplicationWindow::WriteSettings(void)
227 {
228         settings.setValue("pos", pos());
229         settings.setValue("size", size());
230 //      settings.setValue("charWndPos", ((TTEdit *)qApp)->charWnd->pos());
231 //      settings.setValue("charWndSize", ((TTEdit *)qApp)->charWnd->size());
232 }