// (C) 2011 Underground Software
// See the README and GPLv3 files for licensing and warranty information
//
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
//
// Who When What
// --- ---------- -------------------------------------------------------------
// JLH 03/22/2011 Created this file
+// JLH 09/29/2011 Added simple zoom in/out functionality
+// JLH 10/03/2011 Fixed zoom tool to zoom in/out from center of screen
//
// FIXED:
#include "applicationwindow.h"
+#include "about.h"
#include "drawingview.h"
+#include "generaltab.h"
+#include "painter.h"
+#include "settingsdialog.h"
ApplicationWindow::ApplicationWindow(): settings("Underground Software", "Architektonas")
drawing->setMouseTracking(true); // We want *all* mouse events...!
setCentralWidget(drawing);
+ aboutWin = new AboutWindow(this);
+
// ((TTEdit *)qApp)->charWnd = new CharWindow(this);
setWindowIcon(QIcon(":/res/atns-icon.png"));
Object::SetDimensionActive(addDimensionAct->isChecked());
}
+void ApplicationWindow::RotateTool(void)
+{
+ drawing->SetRotateToolActive(rotateAct->isChecked());
+}
+
+void ApplicationWindow::AddLineTool(void)
+{
+ addCircleAct->setChecked(false);
+ addArcAct->setChecked(false);
+ rotateAct->setChecked(false);
+ RotateTool();
+ drawing->SetAddLineToolActive(addLineAct->isChecked());
+}
+
+void ApplicationWindow::AddCircleTool(void)
+{
+ addLineAct->setChecked(false);
+ addArcAct->setChecked(false);
+ rotateAct->setChecked(false);
+ RotateTool();
+ drawing->SetAddCircleToolActive(addCircleAct->isChecked());
+}
+
+void ApplicationWindow::ZoomInTool(void)
+{
+ double zoomFactor = 2.0;
+/*
+We need to find the center of the screen, then figure out where the new corner
+will be in the zoomed in window.
+
+So we know in Qt coords, the center is found via:
+size.width() / 2 --> xCenter
+size.height() / 2 --> yCenter
+
+transform x/yCenter to Cartesian coordinates. So far, so good.
+
+when zooming in, new origin will be (xCenter - origin.x) / 2, (yCenter - origin.y) / 2
+(after subtracting from center, that is...)
+*/
+ QSize size = drawing->size();
+ Vector center(size.width() / 2.0, size.height() / 2.0);
+//printf("Zoom in... Center=%.2f,%.2f; ", center.x, center.y);
+ center = Painter::QtToCartesianCoords(center);
+//printf("(%.2f,%.2f); origin=%.2f,%.2f; ", center.x, center.y, Painter::origin.x, Painter::origin.y);
+ Vector newOrigin = center - ((center - Painter::origin) / zoomFactor);
+//printf("newOrigin=%.2f,%.2f;\n", newOrigin.x, newOrigin.y);
+ Painter::origin = newOrigin;
+
+//printf("Zoom in... level going from %02f to ", Painter::zoom);
+ // This just zooms leaving origin intact... should zoom in at the current center! [DONE]
+ Painter::zoom *= zoomFactor;
+ drawing->update();
+}
+
+void ApplicationWindow::ZoomOutTool(void)
+{
+/*
+Ok, real example.
+center = (436, 311)
+origin = (223, 160.5)
+newOrigin should be (-10, -10)
+Why isn't it?
+
+center - origin = (213, 150.5)
+origin - center = (-213, -150.5)
+x 2 = (-426, -301)
++ center = (-10, -10)
+
+*/
+ double zoomFactor = 2.0;
+ QSize size = drawing->size();
+ Vector center(size.width() / 2.0, size.height() / 2.0);
+//printf("Zoom out... Center=%.2f,%.2f; ", center.x, center.y);
+ center = Painter::QtToCartesianCoords(center);
+//printf("(%.2f,%.2f); origin=%.2f,%.2f; ", center.x, center.y, Painter::origin.x, Painter::origin.y);
+// Vector newOrigin = (center - Painter::origin) * zoomFactor;
+// Vector newOrigin = center - (Painter::origin * zoomFactor);
+ Vector newOrigin = center + ((Painter::origin - center) * zoomFactor);
+//printf("newOrigin=%.2f,%.2f;\n", newOrigin.x, newOrigin.y);
+ Painter::origin = newOrigin;
+//printf("Zoom out...\n");
+ // This just zooms leaving origin intact... should zoom out at the current center! [DONE]
+ Painter::zoom /= zoomFactor;
+ drawing->update();
+}
+
+void ApplicationWindow::HelpAbout(void)
+{
+ aboutWin->show();
+}
+
+void ApplicationWindow::Settings(void)
+{
+ SettingsDialog dlg(this);
+ dlg.generalTab->antialiasChk->setChecked(drawing->useAntialiasing);
+
+ if (dlg.exec() == false)
+ return;
+
+ // Deal with stuff here (since user hit "OK" button...)
+ drawing->useAntialiasing = dlg.generalTab->antialiasChk->isChecked();
+ WriteSettings();
+}
+
void ApplicationWindow::CreateActions(void)
{
exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."),
QIcon(":/res/fix-length.png"), QKeySequence(tr("F,L")), true);
connect(fixLengthAct, SIGNAL(triggered()), this, SLOT(FixLength()));
- deleteAct = CreateAction(tr("&Delete"), tr("Delete Object"), tr("Deletes selected objects."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
+ deleteAct = CreateAction(tr("&Delete"), tr("Delete Object"), tr("Deletes selected objects."), QIcon(":/res/delete-tool.png"), QKeySequence(), true);
connect(deleteAct, SIGNAL(triggered()), this, SLOT(DeleteTool()));
- addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
+ addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/dimension-tool.png"), QKeySequence("D,I"), true);
connect(addDimensionAct, SIGNAL(triggered()), this, SLOT(DimensionTool()));
- addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds a line to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
+ addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds lines to the drawing."), QIcon(":/res/add-line-tool.png"), QKeySequence("A,L"), true);
+ connect(addLineAct, SIGNAL(triggered()), this, SLOT(AddLineTool()));
+
+ addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds circles to the drawing."), QIcon(":/res/add-circle-tool.png"), QKeySequence("A,C"), true);
+ connect(addCircleAct, SIGNAL(triggered()), this, SLOT(AddCircleTool()));
+
+ addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds arcs to the drawing."), QIcon(":/res/add-arc-tool.png"), QKeySequence("A,A"), true);
+
+ addPolygonAct = CreateAction(tr("Add &Polygon"), tr("Add Polygon"), tr("Add polygons to the drawing."), QIcon(":/res/add-polygon-tool.png"), QKeySequence("A,P"), true);
+
+ aboutAct = CreateAction(tr("About &Architektonas"), tr("About Architektonas"), tr("Gives information about this program."), QIcon(":/res/generic-tool.png"), QKeySequence());
+ connect(aboutAct, SIGNAL(triggered()), this, SLOT(HelpAbout()));
+
+ rotateAct = CreateAction(tr("&Rotate Objects"), tr("Rotate"), tr("Rotate object(s) around an arbitrary center."), QIcon(":/res/rotate-tool.png"), QKeySequence(tr("R,O")), true);
+ connect(rotateAct, SIGNAL(triggered()), this, SLOT(RotateTool()));
+
+ zoomInAct = CreateAction(tr("Zoom &In"), tr("Zoom In"), tr("Zoom in on the document."), QIcon(":/res/zoom-in.png"), QKeySequence(tr("+")), QKeySequence(tr("=")));
+ connect(zoomInAct, SIGNAL(triggered()), this, SLOT(ZoomInTool()));
+
+ zoomOutAct = CreateAction(tr("Zoom &Out"), tr("Zoom Out"), tr("Zoom out of the document."), QIcon(":/res/zoom-out.png"), QKeySequence(tr("-")));
+ connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(ZoomOutTool()));
+
+ fileNewAct = CreateAction(tr("&New Drawing"), tr("New Drawing"), tr("Creates a new drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+n")));
- addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds a circle to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
+ fileOpenAct = CreateAction(tr("&Open Drawing"), tr("Open Drawing"), tr("Opens an existing drawing from a file."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+o")));
- addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds an arc to the drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(), true);
+ fileSaveAct = CreateAction(tr("&Save Drawing"), tr("Save Drawing"), tr("Saves the current drawing to a file."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+s")));
- //Hm.
+ fileSaveAsAct = CreateAction(tr("Save Drawing &As"), tr("Save As"), tr("Saves the current drawing to a file with a different name."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+Shift+s")));
+
+ fileCloseAct = CreateAction(tr("&Close Drawing"), tr("Close Drawing"), tr("Closes the current drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+w")));
+
+ settingsAct = CreateAction(tr("&Settings"), tr("Settings"), tr("Change certain defaults for Architektonas."), QIcon(":/res/generic-tool.png"), QKeySequence());
+ connect(settingsAct, SIGNAL(triggered()), this, SLOT(Settings()));
+
+//Hm. I think we'll have to have separate logic to do the "Radio Group Toolbar" thing...
/* QActionGroup * group = new QActionGroup(this);
group->addAction(deleteAct);
group->addAction(addDimensionAct);
// This is essentially the same as the previous function, but this allows more
// than one key sequence to be added as key shortcuts.
//
-QAction * ApplicationWindow::CreateAction2(QString name, QString tooltip, QString statustip,
+QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/)
{
QAction * action = new QAction(icon, name, this);
void ApplicationWindow::CreateMenus(void)
{
QMenu * menu = menuBar()->addMenu(tr("&File"));
-// fileMenu->addAction(newAct);
-// fileMenu->addAction(openAct);
-// fileMenu->addAction(saveAct);
-// fileMenu->addAction(saveAsAct);
-// fileMenu->addSeparator();
+ menu->addAction(fileNewAct);
+ menu->addAction(fileOpenAct);
+ menu->addAction(fileSaveAct);
+ menu->addAction(fileSaveAsAct);
+ menu->addAction(fileCloseAct);
+ menu->addSeparator();
menu->addAction(exitAct);
+ menu = menuBar()->addMenu(tr("&View"));
+ menu->addAction(zoomInAct);
+ menu->addAction(zoomOutAct);
+
menu = menuBar()->addMenu(tr("&Edit"));
menu->addAction(fixAngleAct);
menu->addAction(fixLengthAct);
+ menu->addAction(rotateAct);
menu->addSeparator();
menu->addAction(deleteAct);
menu->addSeparator();
menu->addAction(addLineAct);
menu->addAction(addCircleAct);
menu->addAction(addArcAct);
+ menu->addAction(addPolygonAct);
menu->addAction(addDimensionAct);
+ menu->addSeparator();
+ menu->addAction(settingsAct);
-// editMenu = menuBar()->addMenu(tr("&Edit"));
-// editMenu->addAction(cutAct);
-// editMenu->addAction(copyAct);
-// editMenu->addAction(pasteAct);
-
-// menuBar()->addSeparator();
-
-// helpMenu = menuBar()->addMenu(tr("&Help"));
-// helpMenu->addAction(aboutAct);
-// helpMenu->addAction(aboutQtAct);
+ menu = menuBar()->addMenu(tr("&Help"));
+ menu->addAction(aboutAct);
}
void ApplicationWindow::CreateToolbars(void)
QToolBar * toolbar = addToolBar(tr("File"));
toolbar->addAction(exitAct);
+ toolbar = addToolBar(tr("View"));
+ toolbar->addAction(zoomInAct);
+ toolbar->addAction(zoomOutAct);
+
toolbar = addToolBar(tr("Edit"));
toolbar->addAction(fixAngleAct);
toolbar->addAction(fixLengthAct);
+ toolbar->addAction(rotateAct);
toolbar->addAction(deleteAct);
toolbar->addAction(addLineAct);
toolbar->addAction(addCircleAct);
{
QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
QSize size = settings.value("size", QSize(400, 400)).toSize();
+ drawing->useAntialiasing = settings.value("useAntialiasing", true).toBool();
resize(size);
move(pos);
// pos = settings.value("charWndPos", QPoint(0, 0)).toPoint();
{
settings.setValue("pos", pos());
settings.setValue("size", size());
+ settings.setValue("useAntialiasing", drawing->useAntialiasing);
// settings.setValue("charWndPos", ((TTEdit *)qApp)->charWnd->pos());
// settings.setValue("charWndSize", ((TTEdit *)qApp)->charWnd->size());
}