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"
42 #include "settingsdialog.h"
45 ApplicationWindow::ApplicationWindow():
46 baseUnitInput(new QLineEdit),
47 dimensionSizeInput(new QLineEdit),
48 settings("Underground Software", "Architektonas")
50 drawing = new DrawingView(this);
51 drawing->setMouseTracking(true); // We want *all* mouse events...!
52 setCentralWidget(drawing);
54 aboutWin = new AboutWindow(this);
56 // ((TTEdit *)qApp)->charWnd = new CharWindow(this);
58 setWindowIcon(QIcon(":/res/atns-icon.png"));
59 setWindowTitle("Architektonas");
65 // Create Dock widgets
66 QDockWidget * dock1 = new QDockWidget(tr("Layers"), this);
67 LayerWidget * lw = new LayerWidget;
69 addDockWidget(Qt::RightDockWidgetArea, dock1);
70 QDockWidget * dock2 = new QDockWidget(tr("Blocks"), this);
71 BlockWidget * bw = new BlockWidget;
73 addDockWidget(Qt::RightDockWidgetArea, dock2);
74 // Needed for saveState()
75 dock1->setObjectName("Layers");
76 dock2->setObjectName("Blocks");
79 zoomIndicator = new QLabel("Grid: 12.0\" Zoom: 12.5%");
80 statusBar()->addPermanentWidget(zoomIndicator);
81 statusBar()->showMessage(tr("Ready"));
84 setUnifiedTitleAndToolBarOnMac(true);
85 Object::SetFont(new QFont("Verdana", 15, QFont::Bold));
89 void ApplicationWindow::closeEvent(QCloseEvent * event)
92 event->accept(); // Use ignore() if can't close for some reason
93 //Do we have a memory leak here if we don't delete the font in the Object???
97 void ApplicationWindow::FileNew(void)
99 // Should warn the user if drawing hasn't been saved...
100 drawing->document.Clear();
102 documentName.clear();
103 setWindowTitle("Architektonas - Untitled");
104 statusBar()->showMessage(tr("New drawing is ready."));
108 void ApplicationWindow::FileOpen(void)
110 QString filename = QFileDialog::getOpenFileName(this, tr("Open Drawing"),
111 "", tr("Architektonas files (*.drawing)"));
112 FILE * file = fopen(filename.toAscii().data(), "r");
117 msg.setText(QString(tr("Could not open file \"%1\" for loading!")).arg(filename));
118 msg.setIcon(QMessageBox::Critical);
123 Container container(Vector(0, 0));
124 bool successful = FileIO::LoadAtnsFile(file, &container);
130 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(filename));
131 msg.setIcon(QMessageBox::Critical);
136 printf("FileOpen: container size = %li\n", container.objects.size());
137 drawing->document = container;
139 documentName = filename;
140 setWindowTitle(QString("Architektonas - %1").arg(documentName));
141 statusBar()->showMessage(tr("Drawing loaded."));
145 void ApplicationWindow::FileSave(void)
147 if (documentName.isEmpty())
148 documentName = QFileDialog::getSaveFileName(this, tr("Save Drawing"),
149 "", tr("Architektonas drawings (*.drawing)"));
151 FILE * file = fopen(documentName.toAscii().data(), "w");
156 msg.setText(QString(tr("Could not open file \"%1\" for saving!")).arg(documentName));
157 msg.setIcon(QMessageBox::Critical);
162 bool successful = FileIO::SaveAtnsFile(file, &drawing->document);
168 msg.setText(QString(tr("Could not save file \"%1\"!")).arg(documentName));
169 msg.setIcon(QMessageBox::Critical);
171 // In this case, we should unlink the created file, since it's not right...
172 unlink(documentName.toAscii().data());
176 setWindowTitle(QString("Architektonas - %1").arg(documentName));
177 statusBar()->showMessage(tr("Drawing saved."));
181 void ApplicationWindow::FileSaveAs(void)
183 QString filename = QFileDialog::getSaveFileName(this, tr("Save Drawing As"),
184 documentName, tr("Architektonas drawings (*.drawing)"));
186 if (!filename.isEmpty())
188 documentName = filename;
194 void ApplicationWindow::SnapToGridTool(void)
196 Object::SetSnapMode(snapToGridAct->isChecked());
200 void ApplicationWindow::FixAngle(void)
202 Object::SetFixedAngle(fixAngleAct->isChecked());
206 void ApplicationWindow::FixLength(void)
208 Object::SetFixedLength(fixLengthAct->isChecked());
212 // We want certain tools to be exclusive, and this approach isn't working correctly...
213 void ApplicationWindow::DeleteTool(void)
215 // For this tool, we check first to see if anything is selected. If so, we
216 // delete those and *don't* select the delete tool.
217 if (drawing->document.ItemsSelected() > 0)
219 drawing->document.DeleteSelectedItems();
221 deleteAct->setChecked(false);
225 // Otherwise, toggle the state of the tool
226 ClearUIToolStatesExcept(deleteAct);
227 SetInternalToolStates();
231 void ApplicationWindow::DimensionTool(void)
233 ClearUIToolStatesExcept(addDimensionAct);
234 SetInternalToolStates();
238 void ApplicationWindow::RotateTool(void)
240 ClearUIToolStatesExcept(rotateAct);
241 SetInternalToolStates();
245 void ApplicationWindow::AddLineTool(void)
247 ClearUIToolStatesExcept(addLineAct);
248 SetInternalToolStates();
252 void ApplicationWindow::AddCircleTool(void)
254 ClearUIToolStatesExcept(addCircleAct);
255 SetInternalToolStates();
259 void ApplicationWindow::AddArcTool(void)
261 ClearUIToolStatesExcept(addArcAct);
262 SetInternalToolStates();
266 void ApplicationWindow::AddPolygonTool(void)
268 ClearUIToolStatesExcept(addPolygonAct);
269 SetInternalToolStates();
273 void ApplicationWindow::ZoomInTool(void)
275 double zoomFactor = 2.0;
277 We need to find the center of the screen, then figure out where the new corner
278 will be in the zoomed in window.
280 So we know in Qt coords, the center is found via:
281 size.width() / 2 --> xCenter
282 size.height() / 2 --> yCenter
284 transform x/yCenter to Cartesian coordinates. So far, so good.
286 when zooming in, new origin will be (xCenter - origin.x) / 2, (yCenter - origin.y) / 2
287 (after subtracting from center, that is...)
289 QSize size = drawing->size();
290 Vector center(size.width() / 2.0, size.height() / 2.0);
291 //printf("Zoom in... Center=%.2f,%.2f; ", center.x, center.y);
292 center = Painter::QtToCartesianCoords(center);
293 //printf("(%.2f,%.2f); origin=%.2f,%.2f; ", center.x, center.y, Painter::origin.x, Painter::origin.y);
294 Vector newOrigin = center - ((center - Painter::origin) / zoomFactor);
295 //printf("newOrigin=%.2f,%.2f;\n", newOrigin.x, newOrigin.y);
296 Painter::origin = newOrigin;
298 //printf("Zoom in... level going from %02f to ", Painter::zoom);
299 // This just zooms leaving origin intact... should zoom in at the current center! [DONE]
300 // This should actually be calculated by drawing->gridPixels / grid size.
301 Painter::zoom *= zoomFactor;
302 drawing->gridSpacing = drawing->gridPixels / Painter::zoom;
303 // zoomIndicator->setText(QString("Grid: %2\" Zoom: %1%").arg(Painter::zoom * 100.0 * SCREEN_ZOOM).arg(drawing->gridSpacing));
304 zoomIndicator->setText(QString("Grid: %1\", BU: Inch").arg(drawing->gridSpacing));
305 drawing->UpdateGridBackground();
308 baseUnitInput->setText(QString("%1").arg(drawing->gridSpacing));
312 void ApplicationWindow::ZoomOutTool(void)
317 origin = (223, 160.5)
318 newOrigin should be (-10, -10)
321 center - origin = (213, 150.5)
322 origin - center = (-213, -150.5)
324 + center = (-10, -10)
327 double zoomFactor = 2.0;
328 QSize size = drawing->size();
329 Vector center(size.width() / 2.0, size.height() / 2.0);
330 //printf("Zoom out... Center=%.2f,%.2f; ", center.x, center.y);
331 center = Painter::QtToCartesianCoords(center);
332 //printf("(%.2f,%.2f); origin=%.2f,%.2f; ", center.x, center.y, Painter::origin.x, Painter::origin.y);
333 // Vector newOrigin = (center - Painter::origin) * zoomFactor;
334 // Vector newOrigin = center - (Painter::origin * zoomFactor);
335 Vector newOrigin = center + ((Painter::origin - center) * zoomFactor);
336 //printf("newOrigin=%.2f,%.2f;\n", newOrigin.x, newOrigin.y);
337 Painter::origin = newOrigin;
338 //printf("Zoom out...\n");
339 // This just zooms leaving origin intact... should zoom out at the current center! [DONE]
340 Painter::zoom /= zoomFactor;
341 drawing->gridSpacing = drawing->gridPixels / Painter::zoom;
342 // zoomIndicator->setText(QString("Grid: %2\" Zoom: %1%").arg(Painter::zoom * 100.0 * SCREEN_ZOOM).arg(drawing->gridSpacing));
343 zoomIndicator->setText(QString("Grid: %1\", BU: Inch").arg(drawing->gridSpacing));
344 drawing->UpdateGridBackground();
347 baseUnitInput->setText(QString("%1").arg(drawing->gridSpacing));
351 void ApplicationWindow::ClearUIToolStatesExcept(QAction * exception)
353 if (exception != addArcAct)
354 addArcAct->setChecked(false);
356 if (exception != addCircleAct)
357 addCircleAct->setChecked(false);
359 if (exception != addDimensionAct)
360 addDimensionAct->setChecked(false);
362 if (exception != addLineAct)
363 addLineAct->setChecked(false);
365 if (exception != addPolygonAct)
366 addPolygonAct->setChecked(false);
368 if (exception != deleteAct)
369 deleteAct->setChecked(false);
371 if (exception != rotateAct)
372 rotateAct->setChecked(false);
376 void ApplicationWindow::SetInternalToolStates(void)
378 Object::SetDeleteActive(deleteAct->isChecked());
379 Object::SetDimensionActive(addDimensionAct->isChecked());
380 drawing->SetRotateToolActive(rotateAct->isChecked());
382 // We can be sure that if we've come here, then either an active tool is
383 // being deactivated, or a new tool is being created. In either case, the
384 // old tool needs to be deleted.
385 if (drawing->toolAction)
387 delete drawing->toolAction;
388 drawing->toolAction = NULL;
392 drawing->SetAddLineToolActive(addLineAct->isChecked());
393 drawing->SetAddCircleToolActive(addCircleAct->isChecked());
394 drawing->SetAddArcToolActive(addArcAct->isChecked());
395 drawing->SetAddDimensionToolActive(addDimensionAct->isChecked());
397 drawing->SetToolActive(addLineAct->isChecked() ? new DrawLineAction() : NULL);
398 drawing->SetToolActive(addCircleAct->isChecked() ? new DrawCircleAction() : NULL);
399 drawing->SetToolActive(addArcAct->isChecked() ? new DrawArcAction() : NULL);
400 drawing->SetToolActive(addDimensionAct->isChecked() ? new DrawDimensionAction() : NULL);
407 void ApplicationWindow::HelpAbout(void)
413 void ApplicationWindow::Settings(void)
415 SettingsDialog dlg(this);
416 dlg.generalTab->antialiasChk->setChecked(drawing->useAntialiasing);
418 if (dlg.exec() == false)
421 // Deal with stuff here (since user hit "OK" button...)
422 drawing->useAntialiasing = dlg.generalTab->antialiasChk->isChecked();
428 // Group a bunch of selected objects (which can include other groups) together
429 // or ungroup a selected group.
431 void ApplicationWindow::HandleGrouping(void)
433 int itemsSelected = drawing->document.ItemsSelected();
435 // If nothing selected, do nothing
436 if (itemsSelected == 0)
438 statusBar()->showMessage(tr("No objects selected to make a group from."));
442 // If it's a group that's selected, ungroup it and leave the objects in a
444 if (itemsSelected == 1)
446 Object * object = drawing->document.SelectedItem(0);
450 printf("SelectedItem = NULL!\n");
452 printf("SelectedItem = %08X, type = %i\n", object, object->type);
455 if (object == NULL || object->type != OTContainer)
457 statusBar()->showMessage(tr("A group requires two or more selected objects."));
461 // Need the parent of the group, we're assuming here that the parent is
462 // the drawing's document. Does it matter? Maybe...
463 // Could just stipulate that grouping like this only takes place where the
464 // parent of the group is the drawing's document. Makes life much simpler.
465 ((Container *)object)->SelectAll();
466 ((Container *)object)->MoveContentsTo(&(drawing->document));
467 drawing->document.Delete(object);
468 statusBar()->showMessage(tr("Objects ungrouped."));
470 // Otherwise, if it's a group of 2 or more objects (which can be groups too)
471 // group them and select the group
472 else if (itemsSelected > 1)
474 Container * container = new Container(Vector(), &(drawing->document));
475 drawing->document.MoveSelectedContentsTo(container);
476 drawing->document.Add(container);
477 container->DeselectAll();
478 container->state = OSSelected;
479 statusBar()->showMessage(QString(tr("Grouped %1 objects.")).arg(itemsSelected));
486 void ApplicationWindow::HandleGridSizeInPixels(int size)
488 drawing->SetGridSize(size);
493 void ApplicationWindow::HandleGridSizeInBaseUnits(QString text)
497 double value = text.toDouble(&ok);
499 // Nothing parsable to a double, so quit...
500 if (!ok || value == 0)
503 drawing->gridSpacing = value;
504 Painter::zoom = drawing->gridPixels / drawing->gridSpacing;
505 drawing->UpdateGridBackground();
510 void ApplicationWindow::HandleDimensionSize(QString text)
514 double value = text.toDouble(&ok);
516 // Nothing parsable to a double, so quit...
517 if (!ok || value == 0)
520 drawing->document.ResizeAllDimensions(value);
521 // drawing->gridSpacing = value;
522 // Painter::zoom = drawing->gridPixels / drawing->gridSpacing;
523 // drawing->UpdateGridBackground();
528 void ApplicationWindow::CreateActions(void)
530 exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."),
531 QIcon(":/res/quit.png"), QKeySequence(tr("Ctrl+q")));
532 connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
534 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);
535 connect(snapToGridAct, SIGNAL(triggered()), this, SLOT(SnapToGridTool()));
537 fixAngleAct = CreateAction(tr("Fix &Angle"), tr("Fix Angle"), tr("Fixes the angle of an object."),
538 QIcon(":/res/fix-angle.png"), QKeySequence(tr("F,A")), true);
539 connect(fixAngleAct, SIGNAL(triggered()), this, SLOT(FixAngle()));
541 fixLengthAct = CreateAction(tr("Fix &Length"), tr("Fix Length"), tr("Fixes the length of an object."),
542 QIcon(":/res/fix-length.png"), QKeySequence(tr("F,L")), true);
543 connect(fixLengthAct, SIGNAL(triggered()), this, SLOT(FixLength()));
545 deleteAct = CreateAction(tr("&Delete"), tr("Delete Object"), tr("Deletes selected objects."), QIcon(":/res/delete-tool.png"), QKeySequence(tr("Delete")), true);
546 connect(deleteAct, SIGNAL(triggered()), this, SLOT(DeleteTool()));
548 addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/dimension-tool.png"), QKeySequence("D,I"), true);
549 connect(addDimensionAct, SIGNAL(triggered()), this, SLOT(DimensionTool()));
551 addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds lines to the drawing."), QIcon(":/res/add-line-tool.png"), QKeySequence("A,L"), true);
552 connect(addLineAct, SIGNAL(triggered()), this, SLOT(AddLineTool()));
554 addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds circles to the drawing."), QIcon(":/res/add-circle-tool.png"), QKeySequence("A,C"), true);
555 connect(addCircleAct, SIGNAL(triggered()), this, SLOT(AddCircleTool()));
557 addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds arcs to the drawing."), QIcon(":/res/add-arc-tool.png"), QKeySequence("A,A"), true);
558 connect(addArcAct, SIGNAL(triggered()), this, SLOT(AddArcTool()));
560 addPolygonAct = CreateAction(tr("Add &Polygon"), tr("Add Polygon"), tr("Add polygons to the drawing."), QIcon(":/res/add-polygon-tool.png"), QKeySequence("A,P"), true);
561 connect(addPolygonAct, SIGNAL(triggered()), this, SLOT(AddPolygonTool()));
563 aboutAct = CreateAction(tr("About &Architektonas"), tr("About Architektonas"), tr("Gives information about this program."), QIcon(":/res/generic-tool.png"), QKeySequence());
564 connect(aboutAct, SIGNAL(triggered()), this, SLOT(HelpAbout()));
566 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);
567 connect(rotateAct, SIGNAL(triggered()), this, SLOT(RotateTool()));
569 zoomInAct = CreateAction(tr("Zoom &In"), tr("Zoom In"), tr("Zoom in on the document."), QIcon(":/res/zoom-in.png"), QKeySequence(tr("+")), QKeySequence(tr("=")));
570 connect(zoomInAct, SIGNAL(triggered()), this, SLOT(ZoomInTool()));
572 zoomOutAct = CreateAction(tr("Zoom &Out"), tr("Zoom Out"), tr("Zoom out of the document."), QIcon(":/res/zoom-out.png"), QKeySequence(tr("-")));
573 connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(ZoomOutTool()));
575 fileNewAct = CreateAction(tr("&New Drawing"), tr("New Drawing"), tr("Creates a new drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+n")));
576 connect(fileNewAct, SIGNAL(triggered()), this, SLOT(FileNew()));
578 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")));
579 connect(fileOpenAct, SIGNAL(triggered()), this, SLOT(FileOpen()));
581 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")));
582 connect(fileSaveAct, SIGNAL(triggered()), this, SLOT(FileSave()));
584 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")));
585 connect(fileSaveAsAct, SIGNAL(triggered()), this, SLOT(FileSaveAs()));
587 fileCloseAct = CreateAction(tr("&Close Drawing"), tr("Close Drawing"), tr("Closes the current drawing."), QIcon(":/res/generic-tool.png"), QKeySequence(tr("Ctrl+w")));
589 settingsAct = CreateAction(tr("&Settings"), tr("Settings"), tr("Change certain defaults for Architektonas."), QIcon(":/res/generic-tool.png"), QKeySequence());
590 connect(settingsAct, SIGNAL(triggered()), this, SLOT(Settings()));
592 groupAct = CreateAction(tr("&Group"), tr("Group"), tr("Group/ungroup selected objects."), QIcon(":/res/group-tool.png"), QKeySequence("g"));
593 connect(groupAct, SIGNAL(triggered()), this, SLOT(HandleGrouping()));
595 connectAct = CreateAction(tr("&Connect"), tr("Connect"), tr("Connect objects at point."), QIcon(":/res/connect-tool.png"), QKeySequence("c,c"));
597 disconnectAct = CreateAction(tr("&Disconnect"), tr("Disconnect"), tr("Disconnect objects joined at point."), QIcon(":/res/disconnect-tool.png"), QKeySequence("d,d"));
599 //Hm. I think we'll have to have separate logic to do the "Radio Group Toolbar" thing...
600 // Yup, in order to turn them off, we'd have to have an "OFF" toolbar button. Ick.
601 /* QActionGroup * group = new QActionGroup(this);
602 group->addAction(deleteAct);
603 group->addAction(addDimensionAct);
604 group->addAction(addLineAct);
605 group->addAction(addCircleAct);
606 group->addAction(addArcAct);//*/
611 // Consolidates action creation from a multi-step process to a single-step one.
613 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
614 QIcon icon, QKeySequence key, bool checkable/*= false*/)
616 QAction * action = new QAction(icon, name, this);
617 action->setToolTip(tooltip);
618 action->setStatusTip(statustip);
619 action->setShortcut(key);
620 action->setCheckable(checkable);
627 // This is essentially the same as the previous function, but this allows more
628 // than one key sequence to be added as key shortcuts.
630 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip, QString statustip,
631 QIcon icon, QKeySequence key1, QKeySequence key2, bool checkable/*= false*/)
633 QAction * action = new QAction(icon, name, this);
634 action->setToolTip(tooltip);
635 action->setStatusTip(statustip);
636 QList<QKeySequence> keyList;
637 keyList.append(key1);
638 keyList.append(key2);
639 action->setShortcuts(keyList);
640 action->setCheckable(checkable);
646 void ApplicationWindow::CreateMenus(void)
648 QMenu * menu = menuBar()->addMenu(tr("&File"));
649 menu->addAction(fileNewAct);
650 menu->addAction(fileOpenAct);
651 menu->addAction(fileSaveAct);
652 menu->addAction(fileSaveAsAct);
653 menu->addAction(fileCloseAct);
654 menu->addSeparator();
655 menu->addAction(exitAct);
657 menu = menuBar()->addMenu(tr("&View"));
658 menu->addAction(zoomInAct);
659 menu->addAction(zoomOutAct);
661 menu = menuBar()->addMenu(tr("&Edit"));
662 menu->addAction(snapToGridAct);
663 menu->addAction(groupAct);
664 menu->addAction(fixAngleAct);
665 menu->addAction(fixLengthAct);
666 menu->addAction(rotateAct);
667 menu->addAction(connectAct);
668 menu->addAction(disconnectAct);
669 menu->addSeparator();
670 menu->addAction(deleteAct);
671 menu->addSeparator();
672 menu->addAction(addLineAct);
673 menu->addAction(addCircleAct);
674 menu->addAction(addArcAct);
675 menu->addAction(addPolygonAct);
676 menu->addAction(addDimensionAct);
677 menu->addSeparator();
678 menu->addAction(settingsAct);
680 menu = menuBar()->addMenu(tr("&Help"));
681 menu->addAction(aboutAct);
685 void ApplicationWindow::CreateToolbars(void)
687 QToolBar * toolbar = addToolBar(tr("File"));
688 toolbar->setObjectName("File"); // Needed for saveState()
689 toolbar->addAction(exitAct);
691 toolbar = addToolBar(tr("View"));
692 toolbar->setObjectName("View");
693 toolbar->addAction(zoomInAct);
694 toolbar->addAction(zoomOutAct);
696 QSpinBox * spinbox = new QSpinBox;
697 toolbar->addWidget(spinbox);
698 // QLineEdit * lineedit = new QLineEdit;
699 toolbar->addWidget(baseUnitInput);
700 toolbar->addWidget(dimensionSizeInput);
702 toolbar = addToolBar(tr("Edit"));
703 toolbar->setObjectName("Edit");
704 toolbar->addAction(snapToGridAct);
705 toolbar->addAction(groupAct);
706 toolbar->addAction(fixAngleAct);
707 toolbar->addAction(fixLengthAct);
708 toolbar->addAction(rotateAct);
709 toolbar->addAction(deleteAct);
710 toolbar->addAction(connectAct);
711 toolbar->addAction(disconnectAct);
712 toolbar->addSeparator();
713 toolbar->addAction(addLineAct);
714 toolbar->addAction(addCircleAct);
715 toolbar->addAction(addArcAct);
716 toolbar->addAction(addPolygonAct);
717 toolbar->addAction(addDimensionAct);
719 spinbox->setRange(4, 256);
720 spinbox->setValue(12);
721 baseUnitInput->setText("12");
722 connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(HandleGridSizeInPixels(int)));
723 connect(baseUnitInput, SIGNAL(textChanged(QString)), this, SLOT(HandleGridSizeInBaseUnits(QString)));
724 connect(dimensionSizeInput, SIGNAL(textChanged(QString)), this, SLOT(HandleDimensionSize(QString)));
728 void ApplicationWindow::ReadSettings(void)
730 QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
731 QSize size = settings.value("size", QSize(400, 400)).toSize();
732 drawing->useAntialiasing = settings.value("useAntialiasing", true).toBool();
733 snapToGridAct->setChecked(settings.value("snapToGrid", true).toBool());
736 restoreState(settings.value("windowState").toByteArray());
740 void ApplicationWindow::WriteSettings(void)
742 settings.setValue("pos", pos());
743 settings.setValue("size", size());
744 settings.setValue("windowState", saveState());
745 settings.setValue("useAntialiasing", drawing->useAntialiasing);
746 settings.setValue("snapToGrid", snapToGridAct->isChecked());