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 Hammons <jlhamm@acm.org>
11 // --- ---------- -------------------------------------------------------------
12 // JLH 03/22/2011 Created this file
13 // JLH 09/29/2011 Added simple zoom in/out functionality
14 // JLH 10/03/2011 Fixed zoom tool to zoom in/out from center of screen
24 // Uncomment this for debugging...
26 //#define DEBUGFOO // Various tool debugging...
27 //#define DEBUGTP // Toolpalette debugging...
29 #include "applicationwindow.h"
32 #include "blockwidget.h"
33 #include "drawingview.h"
34 #include "drawarcaction.h"
35 #include "drawcircleaction.h"
36 #include "drawdimensionaction.h"
37 #include "drawlineaction.h"
39 #include "generaltab.h"
40 #include "layerwidget.h"
41 #include "mirroraction.h"
43 #include "rotateaction.h"
44 #include "settingsdialog.h"
48 DrawingView * ApplicationWindow::drawing;
51 ApplicationWindow::ApplicationWindow():
52 baseUnitInput(new QLineEdit),
53 dimensionSizeInput(new QLineEdit),
54 settings("Underground Software", "Architektonas")
56 drawing = new DrawingView(this);
57 drawing->setMouseTracking(true); // We want *all* mouse events...!
58 drawing->setFocusPolicy(Qt::StrongFocus);
59 setCentralWidget(drawing);
61 aboutWin = new AboutWindow(this);
63 // ((TTEdit *)qApp)->charWnd = new CharWindow(this);
65 setWindowIcon(QIcon(":/res/atns-icon.png"));
66 setWindowTitle("Architektonas");
72 // Create Dock widgets
73 QDockWidget * dock1 = new QDockWidget(tr("Layers"), this);
74 LayerWidget * lw = new LayerWidget;
76 addDockWidget(Qt::RightDockWidgetArea, dock1);
77 QDockWidget * dock2 = new QDockWidget(tr("Blocks"), this);
78 BlockWidget * bw = new BlockWidget;
80 addDockWidget(Qt::RightDockWidgetArea, dock2);
81 // Needed for saveState()
82 dock1->setObjectName("Layers");
83 dock2->setObjectName("Blocks");
86 zoomIndicator = new QLabel("Grid: 12.0\" Zoom: 12.5%");
87 statusBar()->addPermanentWidget(zoomIndicator);
88 statusBar()->showMessage(tr("Ready"));
91 setUnifiedTitleAndToolBarOnMac(true);
92 Object::SetFont(new QFont("Verdana", 15, QFont::Bold));
94 connect(lw, SIGNAL(LayerSelected(int)), drawing, SLOT(SetCurrentLayer(int)));
98 void ApplicationWindow::closeEvent(QCloseEvent * event)
101 event->accept(); // Use ignore() if can't close for some reason
102 //Do we have a memory leak here if we don't delete the font in the Object???
106 void ApplicationWindow::FileNew(void)
108 // Should warn the user if drawing hasn't been saved...
109 drawing->document.Clear();
111 documentName.clear();
112 setWindowTitle("Architektonas - Untitled");
113 statusBar()->showMessage(tr("New drawing is ready."));
117 void ApplicationWindow::FileOpen(void)
119 QString filename = QFileDialog::getOpenFileName(this, tr("Open Drawing"),
120 "", tr("Architektonas files (*.drawing)"));
121 FILE * file = fopen(filename.toAscii().data(), "r");
126 msg.setText(QString(tr("Could not open file \"%1\" for loading!")).arg(filename));
127 msg.setIcon(QMessageBox::Critical);
132 Container container(Vector(0, 0));
133 bool successful = FileIO::LoadAtnsFile(file, &container);
139 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(filename));
140 msg.setIcon(QMessageBox::Critical);
145 printf("FileOpen: container size = %li\n", container.objects.size());
146 drawing->document = container;
148 documentName = filename;
149 setWindowTitle(QString("Architektonas - %1").arg(documentName));
150 statusBar()->showMessage(tr("Drawing loaded."));
154 void ApplicationWindow::FileSave(void)
156 if (documentName.isEmpty())
157 documentName = QFileDialog::getSaveFileName(this, tr("Save Drawing"),
158 "", tr("Architektonas drawings (*.drawing)"));
160 FILE * file = fopen(documentName.toAscii().data(), "w");
165 msg.setText(QString(tr("Could not open file \"%1\" for saving!")).arg(documentName));
166 msg.setIcon(QMessageBox::Critical);
171 bool successful = FileIO::SaveAtnsFile(file, &drawing->document);
177 msg.setText(QString(tr("Could not save file \"%1\"!")).arg(documentName));
178 msg.setIcon(QMessageBox::Critical);
180 // In this case, we should unlink the created file, since it's not right...
181 // unlink(documentName.toAscii().data());
182 QFile::remove(documentName);
186 setWindowTitle(QString("Architektonas - %1").arg(documentName));
187 statusBar()->showMessage(tr("Drawing saved."));
191 void ApplicationWindow::FileSaveAs(void)
193 QString filename = QFileDialog::getSaveFileName(this, tr("Save Drawing As"),
194 documentName, tr("Architektonas drawings (*.drawing)"));
196 if (!filename.isEmpty())
198 documentName = filename;
204 void ApplicationWindow::SnapToGridTool(void)
206 Object::SetSnapMode(snapToGridAct->isChecked());
210 void ApplicationWindow::FixAngle(void)
212 Object::SetFixedAngle(fixAngleAct->isChecked());
216 void ApplicationWindow::FixLength(void)
218 Object::SetFixedLength(fixLengthAct->isChecked());
222 // We want certain tools to be exclusive, and this approach isn't working correctly...
223 void ApplicationWindow::DeleteTool(void)
225 // For this tool, we check first to see if anything is selected. If so, we
226 // delete those and *don't* select the delete tool.
227 if (drawing->document.ItemsSelected() > 0)
229 drawing->document.DeleteSelectedItems();
231 deleteAct->setChecked(false);
235 // Otherwise, toggle the state of the tool
236 ClearUIToolStatesExcept(deleteAct);
237 SetInternalToolStates();
241 void ApplicationWindow::DimensionTool(void)
243 ClearUIToolStatesExcept(addDimensionAct);
244 SetInternalToolStates();
248 void ApplicationWindow::RotateTool(void)
250 ClearUIToolStatesExcept(rotateAct);
251 SetInternalToolStates();
255 void ApplicationWindow::MirrorTool(void)
257 ClearUIToolStatesExcept(mirrorAct);
258 SetInternalToolStates();
262 void ApplicationWindow::AddLineTool(void)
264 ClearUIToolStatesExcept(addLineAct);
265 SetInternalToolStates();
269 void ApplicationWindow::AddCircleTool(void)
271 ClearUIToolStatesExcept(addCircleAct);
272 SetInternalToolStates();
276 void ApplicationWindow::AddArcTool(void)
278 ClearUIToolStatesExcept(addArcAct);
279 SetInternalToolStates();
283 void ApplicationWindow::AddPolygonTool(void)
285 ClearUIToolStatesExcept(addPolygonAct);
286 SetInternalToolStates();
290 void ApplicationWindow::ZoomInTool(void)
292 double zoomFactor = 2.0;
294 We need to find the center of the screen, then figure out where the new corner
295 will be in the zoomed in window.
297 So we know in Qt coords, the center is found via:
298 size.width() / 2 --> xCenter
299 size.height() / 2 --> yCenter
301 transform x/yCenter to Cartesian coordinates. So far, so good.
303 when zooming in, new origin will be (xCenter - origin.x) / 2, (yCenter - origin.y) / 2
304 (after subtracting from center, that is...)
306 QSize size = drawing->size();
307 Vector center(size.width() / 2.0, size.height() / 2.0);
308 //printf("Zoom in... Center=%.2f,%.2f; ", center.x, center.y);
309 center = Painter::QtToCartesianCoords(center);
310 //printf("(%.2f,%.2f); origin=%.2f,%.2f; ", center.x, center.y, Painter::origin.x, Painter::origin.y);
311 Vector newOrigin = center - ((center - Painter::origin) / zoomFactor);
312 //printf("newOrigin=%.2f,%.2f;\n", newOrigin.x, newOrigin.y);
313 Painter::origin = newOrigin;
315 //printf("Zoom in... level going from %02f to ", Painter::zoom);
316 // This just zooms leaving origin intact... should zoom in at the current
318 Painter::zoom *= zoomFactor;
319 Object::gridSpacing = drawing->gridPixels / Painter::zoom;
320 drawing->UpdateGridBackground();
323 zoomIndicator->setText(QString("Grid: %1\", BU: Inch").arg(Object::gridSpacing));
324 baseUnitInput->setText(QString("%1").arg(Object::gridSpacing));
328 void ApplicationWindow::ZoomOutTool(void)
333 origin = (223, 160.5)
334 newOrigin should be (-10, -10)
337 center - origin = (213, 150.5)
338 origin - center = (-213, -150.5)
340 + center = (-10, -10)
343 double zoomFactor = 2.0;
344 QSize size = drawing->size();
345 Vector center(size.width() / 2.0, size.height() / 2.0);
346 //printf("Zoom out... Center=%.2f,%.2f; ", center.x, center.y);
347 center = Painter::QtToCartesianCoords(center);
348 //printf("(%.2f,%.2f); origin=%.2f,%.2f; ", center.x, center.y, Painter::origin.x, Painter::origin.y);
349 // Vector newOrigin = (center - Painter::origin) * zoomFactor;
350 // Vector newOrigin = center - (Painter::origin * zoomFactor);
351 Vector newOrigin = center + ((Painter::origin - center) * zoomFactor);
352 //printf("newOrigin=%.2f,%.2f;\n", newOrigin.x, newOrigin.y);
353 Painter::origin = newOrigin;
354 //printf("Zoom out...\n");
355 // This just zooms leaving origin intact... should zoom out at the current
357 Painter::zoom /= zoomFactor;
358 Object::gridSpacing = drawing->gridPixels / Painter::zoom;
359 drawing->UpdateGridBackground();
362 zoomIndicator->setText(QString("Grid: %1\", BU: Inch").arg(Object::gridSpacing));
363 baseUnitInput->setText(QString("%1").arg(Object::gridSpacing));
367 void ApplicationWindow::ClearUIToolStatesExcept(QAction * exception)
369 if (exception != addArcAct)
370 addArcAct->setChecked(false);
372 if (exception != addCircleAct)
373 addCircleAct->setChecked(false);
375 if (exception != addDimensionAct)
376 addDimensionAct->setChecked(false);
378 if (exception != addLineAct)
379 addLineAct->setChecked(false);
381 if (exception != addPolygonAct)
382 addPolygonAct->setChecked(false);
384 if (exception != deleteAct)
385 deleteAct->setChecked(false);
387 if (exception != rotateAct)
388 rotateAct->setChecked(false);
390 if (exception != mirrorAct)
391 mirrorAct->setChecked(false);
395 void ApplicationWindow::SetInternalToolStates(void)
397 Object::SetDeleteActive(deleteAct->isChecked());
398 Object::SetDimensionActive(addDimensionAct->isChecked());
400 // We can be sure that if we've come here, then either an active tool is
401 // being deactivated, or a new tool is being created. In either case, the
402 // old tool needs to be deleted.
403 if (drawing->toolAction)
405 delete drawing->toolAction;
406 drawing->toolAction = NULL;
407 Object::ignoreClicks = false;
410 drawing->SetToolActive(addLineAct->isChecked() ? new DrawLineAction() : NULL);
411 drawing->SetToolActive(addCircleAct->isChecked() ? new DrawCircleAction() : NULL);
412 drawing->SetToolActive(addArcAct->isChecked() ? new DrawArcAction() : NULL);
413 drawing->SetToolActive(addDimensionAct->isChecked() ? new DrawDimensionAction() : NULL);
414 drawing->SetToolActive(mirrorAct->isChecked() ? new MirrorAction() : NULL);
415 drawing->SetToolActive(rotateAct->isChecked() ? new RotateAction() : NULL);
417 if (drawing->toolAction)
418 Object::ignoreClicks = true;
424 void ApplicationWindow::HelpAbout(void)
430 void ApplicationWindow::Settings(void)
432 SettingsDialog dlg(this);
433 dlg.generalTab->antialiasChk->setChecked(drawing->useAntialiasing);
435 if (dlg.exec() == false)
438 // Deal with stuff here (since user hit "OK" button...)
439 drawing->useAntialiasing = dlg.generalTab->antialiasChk->isChecked();
445 // Group a bunch of selected objects (which can include other groups) together
446 // or ungroup a selected group.
448 void ApplicationWindow::HandleGrouping(void)
450 int itemsSelected = drawing->document.ItemsSelected();
452 // If nothing selected, do nothing
453 if (itemsSelected == 0)
455 statusBar()->showMessage(tr("No objects selected to make a group from."));
459 // If it's a group that's selected, ungroup it and leave the objects in a
461 if (itemsSelected == 1)
463 Object * object = drawing->document.SelectedItem(0);
467 printf("SelectedItem = NULL!\n");
469 printf("SelectedItem = %08X, type = %i\n", object, object->type);
472 if (object == NULL || object->type != OTContainer)
474 statusBar()->showMessage(tr("A group requires two or more selected objects."));
478 // Need the parent of the group, we're assuming here that the parent is
479 // the drawing's document. Does it matter? Maybe...
480 // Could just stipulate that grouping like this only takes place where the
481 // parent of the group is the drawing's document. Makes life much simpler.
482 ((Container *)object)->SelectAll();
483 ((Container *)object)->MoveContentsTo(&(drawing->document));
484 drawing->document.Delete(object);
485 statusBar()->showMessage(tr("Objects ungrouped."));
487 // Otherwise, if it's a group of 2 or more objects (which can be groups too)
488 // group them and select the group
489 else if (itemsSelected > 1)
491 Container * container = new Container(Vector(), &(drawing->document));
492 drawing->document.MoveSelectedContentsTo(container);
493 drawing->document.Add(container);
494 container->DeselectAll();
495 container->state = OSSelected;
496 statusBar()->showMessage(QString(tr("Grouped %1 objects.")).arg(itemsSelected));
503 void ApplicationWindow::HandleGridSizeInPixels(int size)
505 drawing->SetGridSize(size);
510 void ApplicationWindow::HandleGridSizeInBaseUnits(QString text)
514 double value = text.toDouble(&ok);
516 // Nothing parsable to a double, so quit...
517 if (!ok || value == 0)
520 // drawing->gridSpacing = value;
521 // Painter::zoom = drawing->gridPixels / drawing->gridSpacing;
522 Object::gridSpacing = value;
523 Painter::zoom = drawing->gridPixels / Object::gridSpacing;
524 drawing->UpdateGridBackground();
529 void ApplicationWindow::HandleDimensionSize(QString text)
533 double value = text.toDouble(&ok);
535 // Nothing parsable to a double, so quit...
536 if (!ok || value == 0)
539 drawing->document.ResizeAllDimensions(value);
540 // drawing->gridSpacing = value;
541 // Painter::zoom = drawing->gridPixels / drawing->gridSpacing;
542 // drawing->UpdateGridBackground();
547 void ApplicationWindow::CreateActions(void)
549 exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."),
550 QIcon(":/res/quit.png"), QKeySequence(tr("Ctrl+q")));
551 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
553 snapToGridAct = CreateAction(tr("Snap To &Grid"), tr("Snap To Grid"), tr("Snaps mouse cursor to the visible grid when moving/creating objects."), QIcon(":/res/snap-to-grid-tool.png"), QKeySequence(tr("S")), true);
554 connect(snapToGridAct, SIGNAL(triggered()), this, SLOT(SnapToGridTool()));
556 fixAngleAct = CreateAction(tr("Fix &Angle"), tr("Fix Angle"), tr("Fixes the angle of an object."),
557 QIcon(":/res/fix-angle.png"), QKeySequence(tr("F,A")), true);
558 connect(fixAngleAct, SIGNAL(triggered()), this, SLOT(FixAngle()));
560 fixLengthAct = CreateAction(tr("Fix &Length"), tr("Fix Length"), tr("Fixes the length of an object."),
561 QIcon(":/res/fix-length.png"), QKeySequence(tr("F,L")), true);
562 connect(fixLengthAct, SIGNAL(triggered()), this, SLOT(FixLength()));
564 deleteAct = CreateAction(tr("&Delete"), tr("Delete Object"), tr("Deletes selected objects."), QIcon(":/res/delete-tool.png"), QKeySequence(tr("Delete")), true);
565 connect(deleteAct, SIGNAL(triggered()), this, SLOT(DeleteTool()));
567 addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/dimension-tool.png"), QKeySequence("D,I"), true);
568 connect(addDimensionAct, SIGNAL(triggered()), this, SLOT(DimensionTool()));
570 addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds lines to the drawing."), QIcon(":/res/add-line-tool.png"), QKeySequence("A,L"), true);
571 connect(addLineAct, SIGNAL(triggered()), this, SLOT(AddLineTool()));
573 addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds circles to the drawing."), QIcon(":/res/add-circle-tool.png"), QKeySequence("A,C"), true);
574 connect(addCircleAct, SIGNAL(triggered()), this, SLOT(AddCircleTool()));
576 addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds arcs to the drawing."), QIcon(":/res/add-arc-tool.png"), QKeySequence("A,A"), true);
577 connect(addArcAct, SIGNAL(triggered()), this, SLOT(AddArcTool()));
579 addPolygonAct = CreateAction(tr("Add &Polygon"), tr("Add Polygon"), tr("Add polygons to the drawing."), QIcon(":/res/add-polygon-tool.png"), QKeySequence("A,P"), true);
580 connect(addPolygonAct, SIGNAL(triggered()), this, SLOT(AddPolygonTool()));
582 aboutAct = CreateAction(tr("About &Architektonas"), tr("About Architektonas"), tr("Gives information about this program."), QIcon(":/res/generic-tool.png"), QKeySequence());
583 connect(aboutAct, SIGNAL(triggered()), this, SLOT(HelpAbout()));
585 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);
586 connect(rotateAct, SIGNAL(triggered()), this, SLOT(RotateTool()));
588 zoomInAct = CreateAction(tr("Zoom &In"), tr("Zoom In"), tr("Zoom in on the document."), QIcon(":/res/zoom-in.png"), QKeySequence(tr("+")), QKeySequence(tr("=")));
589 connect(zoomInAct, SIGNAL(triggered()), this, SLOT(ZoomInTool()));
591 zoomOutAct = CreateAction(tr("Zoom &Out"), tr("Zoom Out"), tr("Zoom out of the document."), QIcon(":/res/zoom-out.png"), QKeySequence(tr("-")));
592 connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(ZoomOutTool()));
594 fileNewAct = CreateAction(tr("&New Drawing"), tr("New Drawing"), tr("Creates a new drawing."), QIcon(":/res/file-new.png"), QKeySequence(tr("Ctrl+n")));
595 connect(fileNewAct, SIGNAL(triggered()), this, SLOT(FileNew()));
597 fileOpenAct = CreateAction(tr("&Open Drawing"), tr("Open Drawing"), tr("Opens an existing drawing from a file."), QIcon(":/res/file-open.png"), QKeySequence(tr("Ctrl+o")));
598 connect(fileOpenAct, SIGNAL(triggered()), this, SLOT(FileOpen()));
600 fileSaveAct = CreateAction(tr("&Save Drawing"), tr("Save Drawing"), tr("Saves the current drawing to a file."), QIcon(":/res/file-save.png"), QKeySequence(tr("Ctrl+s")));
601 connect(fileSaveAct, SIGNAL(triggered()), this, SLOT(FileSave()));
603 fileSaveAsAct = CreateAction(tr("Save Drawing &As"), tr("Save As"), tr("Saves the current drawing to a file with a different name."), QIcon(":/res/file-save-as.png"), QKeySequence(tr("Ctrl+Shift+s")));
604 connect(fileSaveAsAct, SIGNAL(triggered()), this, SLOT(FileSaveAs()));
606 fileCloseAct = CreateAction(tr("&Close Drawing"), tr("Close Drawing"), tr("Closes the current drawing."), QIcon(":/res/file-close.png"), QKeySequence(tr("Ctrl+w")));
608 settingsAct = CreateAction(tr("&Settings"), tr("Settings"), tr("Change certain defaults for Architektonas."), QIcon(":/res/settings.png"), QKeySequence());
609 connect(settingsAct, SIGNAL(triggered()), this, SLOT(Settings()));
611 groupAct = CreateAction(tr("&Group"), tr("Group"), tr("Group/ungroup selected objects."), QIcon(":/res/group-tool.png"), QKeySequence("g"));
612 connect(groupAct, SIGNAL(triggered()), this, SLOT(HandleGrouping()));
614 connectAct = CreateAction(tr("&Connect"), tr("Connect"), tr("Connect objects at point."), QIcon(":/res/connect-tool.png"), QKeySequence("c,c"));
616 disconnectAct = CreateAction(tr("&Disconnect"), tr("Disconnect"), tr("Disconnect objects joined at point."), QIcon(":/res/disconnect-tool.png"), QKeySequence("d,d"));
618 mirrorAct = CreateAction(tr("&Mirror"), tr("Mirror"), tr("Mirror selected objects around a line."), QIcon(":/res/mirror-tool.png"), QKeySequence("m,i"), true);
619 connect(mirrorAct, SIGNAL(triggered()), this, SLOT(MirrorTool()));
622 //Hm. I think we'll have to have separate logic to do the "Radio Group Toolbar" thing...
623 // Yup, in order to turn them off, we'd have to have an "OFF" toolbar button. Ick.
624 /* QActionGroup * group = new QActionGroup(this);
625 group->addAction(deleteAct);
626 group->addAction(addDimensionAct);
627 group->addAction(addLineAct);
628 group->addAction(addCircleAct);
629 group->addAction(addArcAct);//*/
634 // Consolidates action creation from a multi-step process to a single-step one.
636 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
637 QIcon icon, QKeySequence key, bool checkable/*= false*/)
639 QAction * action = new QAction(icon, name, this);
640 action->setToolTip(tooltip);
641 action->setStatusTip(statustip);
642 action->setShortcut(key);
643 action->setCheckable(checkable);
650 // This is essentially the same as the previous function, but this allows more
651 // than one key sequence to be added as key shortcuts.
653 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
654 QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/)
656 QAction * action = new QAction(icon, name, this);
657 action->setToolTip(tooltip);
658 action->setStatusTip(statustip);
659 QList<QKeySequence> keyList;
660 keyList.append(key1);
661 keyList.append(key2);
662 action->setShortcuts(keyList);
663 action->setCheckable(checkable);
669 void ApplicationWindow::CreateMenus(void)
671 QMenu * menu = menuBar()->addMenu(tr("&File"));
672 menu->addAction(fileNewAct);
673 menu->addAction(fileOpenAct);
674 menu->addAction(fileSaveAct);
675 menu->addAction(fileSaveAsAct);
676 menu->addAction(fileCloseAct);
677 menu->addSeparator();
678 menu->addAction(exitAct);
680 menu = menuBar()->addMenu(tr("&View"));
681 menu->addAction(zoomInAct);
682 menu->addAction(zoomOutAct);
684 menu = menuBar()->addMenu(tr("&Edit"));
685 menu->addAction(snapToGridAct);
686 menu->addAction(groupAct);
687 menu->addAction(fixAngleAct);
688 menu->addAction(fixLengthAct);
689 menu->addAction(rotateAct);
690 menu->addAction(mirrorAct);
691 menu->addAction(connectAct);
692 menu->addAction(disconnectAct);
693 menu->addSeparator();
694 menu->addAction(deleteAct);
695 menu->addSeparator();
696 menu->addAction(addLineAct);
697 menu->addAction(addCircleAct);
698 menu->addAction(addArcAct);
699 menu->addAction(addPolygonAct);
700 menu->addAction(addDimensionAct);
701 menu->addSeparator();
702 menu->addAction(settingsAct);
704 menu = menuBar()->addMenu(tr("&Help"));
705 menu->addAction(aboutAct);
709 void ApplicationWindow::CreateToolbars(void)
711 QToolBar * toolbar = addToolBar(tr("File"));
712 toolbar->setObjectName("File"); // Needed for saveState()
713 toolbar->addAction(fileNewAct);
714 toolbar->addAction(fileOpenAct);
715 toolbar->addAction(fileSaveAct);
716 toolbar->addAction(fileSaveAsAct);
717 toolbar->addAction(fileCloseAct);
718 // toolbar->addAction(exitAct);
720 toolbar = addToolBar(tr("View"));
721 toolbar->setObjectName("View");
722 toolbar->addAction(zoomInAct);
723 toolbar->addAction(zoomOutAct);
725 QSpinBox * spinbox = new QSpinBox;
726 toolbar->addWidget(spinbox);
727 // QLineEdit * lineedit = new QLineEdit;
728 toolbar->addWidget(baseUnitInput);
729 toolbar->addWidget(dimensionSizeInput);
731 toolbar = addToolBar(tr("Edit"));
732 toolbar->setObjectName("Edit");
733 toolbar->addAction(snapToGridAct);
734 toolbar->addAction(groupAct);
735 toolbar->addAction(fixAngleAct);
736 toolbar->addAction(fixLengthAct);
737 toolbar->addAction(rotateAct);
738 toolbar->addAction(mirrorAct);
739 toolbar->addAction(deleteAct);
740 toolbar->addAction(connectAct);
741 toolbar->addAction(disconnectAct);
742 toolbar->addSeparator();
743 toolbar->addAction(addLineAct);
744 toolbar->addAction(addCircleAct);
745 toolbar->addAction(addArcAct);
746 toolbar->addAction(addPolygonAct);
747 toolbar->addAction(addDimensionAct);
749 spinbox->setRange(4, 256);
750 spinbox->setValue(12);
751 baseUnitInput->setText("12");
752 connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(HandleGridSizeInPixels(int)));
753 connect(baseUnitInput, SIGNAL(textChanged(QString)), this, SLOT(HandleGridSizeInBaseUnits(QString)));
754 connect(dimensionSizeInput, SIGNAL(textChanged(QString)), this, SLOT(HandleDimensionSize(QString)));
758 void ApplicationWindow::ReadSettings(void)
760 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
761 QSize size = settings.value("size", QSize(400, 400)).toSize();
762 drawing->useAntialiasing = settings.value("useAntialiasing", true).toBool();
763 snapToGridAct->setChecked(settings.value("snapToGrid", true).toBool());
766 restoreState(settings.value("windowState").toByteArray());
770 void ApplicationWindow::WriteSettings(void)
772 settings.setValue("pos", pos());
773 settings.setValue("size", size());
774 settings.setValue("windowState", saveState());
775 settings.setValue("useAntialiasing", drawing->useAntialiasing);
776 settings.setValue("snapToGrid", snapToGridAct->isChecked());