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