2 // applicationwindow.cpp: Architektonas
4 // Part of the Architektonas Project
5 // (C) 2011 Underground Software
6 // See the README and GPLv3 files for licensing and warranty information
8 // JLH = James L. Hammons <jlhamm@acm.org>
11 // --- ---------- -------------------------------------------------------------
12 // JLH 03/22/2011 Created this file
22 // Uncomment this for debugging...
24 //#define DEBUGFOO // Various tool debugging...
25 //#define DEBUGTP // Toolpalette debugging...
27 #include "applicationwindow.h"
29 #include "drawingview.h"
32 ApplicationWindow::ApplicationWindow(): settings("Underground Software", "Architektonas")
34 drawing = new DrawingView(this);
35 drawing->setMouseTracking(true); // We want *all* mouse events...!
36 setCentralWidget(drawing);
38 // ((TTEdit *)qApp)->charWnd = new CharWindow(this);
40 setWindowIcon(QIcon(":/res/atns-icon.png"));
41 setWindowTitle("Architektonas");
48 statusBar()->showMessage(tr("Ready"));
52 // connect(textEdit->document(), SIGNAL(contentsChanged()),
53 // this, SLOT(documentWasModified()));
55 // setCurrentFile("");
56 setUnifiedTitleAndToolBarOnMac(true);
58 // ((TTEdit *)qApp)->charWnd->show();//eh?
59 Object::SetFont(new QFont("Verdana", 15, QFont::Bold));
62 void ApplicationWindow::closeEvent(QCloseEvent * event)
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???
69 //void ApplicationWindow::FileOpen(void)
73 void ApplicationWindow::FixAngle(void)
75 Object::SetFixedAngle(fixAngleAct->isChecked());
78 void ApplicationWindow::FixLength(void)
80 Object::SetFixedLength(fixLengthAct->isChecked());
83 void ApplicationWindow::DeleteTool(void)
85 Object::SetDeleteActive(deleteAct->isChecked());
88 void ApplicationWindow::DimensionTool(void)
90 Object::SetDimensionActive(addDimensionAct->isChecked());
93 void ApplicationWindow::CreateActions(void)
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()));
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()));
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()));
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()));
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()));
113 addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds a line to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
115 addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds a circle to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
117 addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds an arc to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
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);//*/
129 // Consolidates action creation from a multi-step process to a single-step one.
131 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
132 QIcon icon, QKeySequence key, bool checkable/*= false*/)
134 QAction * action = new QAction(icon, name, this);
135 action->setToolTip(tooltip);
136 action->setStatusTip(statustip);
137 action->setShortcut(key);
138 action->setCheckable(checkable);
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.
147 QAction * ApplicationWindow::CreateAction2(QString name, QString tooltip, QString statustip,
148 QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/)
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);
162 void ApplicationWindow::CreateMenus(void)
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);
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);
183 // editMenu = menuBar()->addMenu(tr("&Edit"));
184 // editMenu->addAction(cutAct);
185 // editMenu->addAction(copyAct);
186 // editMenu->addAction(pasteAct);
188 // menuBar()->addSeparator();
190 // helpMenu = menuBar()->addMenu(tr("&Help"));
191 // helpMenu->addAction(aboutAct);
192 // helpMenu->addAction(aboutQtAct);
195 void ApplicationWindow::CreateToolbars(void)
197 QToolBar * toolbar = addToolBar(tr("File"));
198 toolbar->addAction(exitAct);
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);
210 void ApplicationWindow::ReadSettings(void)
212 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
213 QSize size = settings.value("size", QSize(400, 400)).toSize();
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);
222 void ApplicationWindow::WriteSettings(void)
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());