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