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 setCentralWidget(drawing);
37 // ((TTEdit *)qApp)->charWnd = new CharWindow(this);
39 setWindowIcon(QIcon(":/res/atns-icon.png"));
40 setWindowTitle("Architektonas");
47 statusBar()->showMessage(tr("Ready"));
51 // connect(textEdit->document(), SIGNAL(contentsChanged()),
52 // this, SLOT(documentWasModified()));
54 // setCurrentFile("");
55 setUnifiedTitleAndToolBarOnMac(true);
57 // ((TTEdit *)qApp)->charWnd->show();//eh?
58 Object::SetFont(new QFont("Verdana", 15, QFont::Bold));
61 void ApplicationWindow::closeEvent(QCloseEvent * event)
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???
68 //void ApplicationWindow::FileOpen(void)
72 void ApplicationWindow::FixAngle(void)
74 Object::SetFixedAngle(fixAngleAct->isChecked());
77 void ApplicationWindow::FixLength(void)
79 Object::SetFixedLength(fixLengthAct->isChecked());
82 void ApplicationWindow::DeleteTool(void)
84 Object::SetDeleteActive(deleteAct->isChecked());
87 void ApplicationWindow::CreateActions(void)
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()));
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()));
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()));
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()));
104 addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence());
106 addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds a line to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence());
108 addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds a circle to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence());
110 addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds an arc to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence());
114 // Consolidates action creation from a multi-step process to a single-step one.
116 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
117 QIcon icon, QKeySequence key, bool checkable/*= false*/)
119 QAction * action = new QAction(icon, name, this);
120 action->setToolTip(tooltip);
121 action->setStatusTip(statustip);
122 action->setShortcut(key);
123 action->setCheckable(checkable);
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.
132 QAction * ApplicationWindow::CreateAction2(QString name, QString tooltip, QString statustip,
133 QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/)
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);
147 void ApplicationWindow::CreateMenus(void)
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);
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);
168 // editMenu = menuBar()->addMenu(tr("&Edit"));
169 // editMenu->addAction(cutAct);
170 // editMenu->addAction(copyAct);
171 // editMenu->addAction(pasteAct);
173 // menuBar()->addSeparator();
175 // helpMenu = menuBar()->addMenu(tr("&Help"));
176 // helpMenu->addAction(aboutAct);
177 // helpMenu->addAction(aboutQtAct);
180 void ApplicationWindow::CreateToolbars(void)
182 QToolBar * toolbar = addToolBar(tr("File"));
183 toolbar->addAction(exitAct);
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);
195 void ApplicationWindow::ReadSettings(void)
197 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
198 QSize size = settings.value("size", QSize(400, 400)).toSize();
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);
207 void ApplicationWindow::WriteSettings(void)
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());