]> Shamusworld >> Repos - architektonas/blob - src/applicationwindow.cpp
Added base units & display style to drawing.
[architektonas] / src / applicationwindow.cpp
1 //
2 // applicationwindow.cpp: Architektonas
3 //
4 // Part of the Architektonas Project
5 // (C) 2011 Underground Software
6 // See the README and GPLv3 files for licensing and warranty information
7 //
8 // JLH = James Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
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
15 //
16
17 // FIXED:
18 //
19 //
20 // STILL TO BE DONE:
21 //
22 //
23
24 // Uncomment this for debugging...
25 //#define DEBUG
26 //#define DEBUGFOO                      // Various tool debugging...
27 //#define DEBUGTP                               // Toolpalette debugging...
28
29 #include "applicationwindow.h"
30
31 #include <QPrintPreviewDialog>
32 #include "about.h"
33 #include "blockwidget.h"
34 #include "commandprocessor.h"
35 #include "consolewidget.h"
36 #include "drawingsettingsdlg.h"
37 #include "drawingview.h"
38 #include "fileio.h"
39 #include "generaltab.h"
40 #include "global.h"
41 #include "layerwidget.h"
42 #include "objectwidget.h"
43 #include "painter.h"
44 #include "penwidget.h"
45 #include "settingsdialog.h"
46 #include "structs.h"
47 #include "utils.h"
48
49 // Class variables
50 DrawingView * ApplicationWindow::drawing;
51
52 ApplicationWindow::ApplicationWindow():
53         baseUnitInput(new QLineEdit),
54         dimensionSizeInput(new QLineEdit),
55         settings("Underground Software", "Architektonas")
56 {
57         drawing = new DrawingView(this);
58         drawing->setMouseTracking(true);                // We want *all* mouse events...!
59         drawing->setFocusPolicy(Qt::StrongFocus);
60         setCentralWidget(drawing);
61
62         aboutWin = new AboutWindow(this);
63
64         setWindowIcon(QIcon(":/res/atns-icon.png"));
65 //      setWindowTitle("Architektonas");
66
67         CreateActions();
68         CreateMenus();
69         CreateToolbars();
70
71         // Create Dock widgets
72         QDockWidget * dock1 = new QDockWidget(tr("Layers"), this);
73         LayerWidget * lw = new LayerWidget;
74         dock1->setWidget(lw);
75         addDockWidget(Qt::RightDockWidgetArea, dock1);
76         QDockWidget * dock2 = new QDockWidget(tr("Blocks"), this);
77         BlockWidget * bw = new BlockWidget;
78         dock2->setWidget(bw);
79         addDockWidget(Qt::RightDockWidgetArea, dock2);
80         QDockWidget * dock3 = new QDockWidget(tr("Object"), this);
81         ObjectWidget * ow = new ObjectWidget;
82         dock3->setWidget(ow);
83         addDockWidget(Qt::RightDockWidgetArea, dock3);
84         QDockWidget * dock4 = new QDockWidget(tr("Command"), this);
85         cw = new ConsoleWidget;
86         dock4->setWidget(cw);
87         addDockWidget(Qt::BottomDockWidgetArea, dock4);
88
89         // Needed for saveState()
90         dock1->setObjectName("Layers");
91         dock2->setObjectName("Blocks");
92         dock3->setObjectName("Object");
93         dock4->setObjectName("Commands");
94
95         // Create status bar
96         zoomIndicator = new QLabel("Zoom: 100% Grid: 12.0\" BU: Inch");
97         statusBar()->addPermanentWidget(zoomIndicator);
98         statusBar()->showMessage(tr("Ready"));
99
100         ReadSettings();
101         // Make sure the bottom left corner gets owned by the right side:
102         setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
103         setUnifiedTitleAndToolBarOnMac(true);
104         Global::font =  new QFont("Verdana", 15, QFont::Bold);
105
106         connect(lw, SIGNAL(LayerDeleted(int)), drawing, SLOT(DeleteCurrentLayer(int)));
107         connect(lw, SIGNAL(LayerToggled()), drawing, SLOT(HandleLayerToggle()));
108         connect(lw, SIGNAL(LayersSwapped(int, int)), drawing, SLOT(HandleLayerSwap(int, int)));
109         connect(this, SIGNAL(ReloadLayers()), lw, SLOT(Reload()));
110
111         connect(drawing, SIGNAL(ObjectHovered(Object *)), ow, SLOT(ShowInfo(Object *)));
112         connect(drawing, SIGNAL(NeedZoomUpdate()), this, SLOT(UpdateZoom()));
113
114         connect(cw->cmdProc, SIGNAL(UpdateNeeded()), this, SLOT(UpdateFromCommand()));
115 }
116
117 void ApplicationWindow::closeEvent(QCloseEvent * event)
118 {
119         WriteSettings();
120         event->accept();                // Use ignore() if can't close for some reason
121         //Do we have a memory leak here if we don't delete the font in the Object???
122 }
123
124 void ApplicationWindow::FileNew(void)
125 {
126         // Warn the user if drawing has changed and hasn't been saved...
127         if (drawing->dirty)
128         {
129                 QMessageBox msg;
130
131                 msg.setText("The document has been modified.");
132                 msg.setInformativeText("Do you want to save your changes?");
133                 msg.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
134                 msg.setDefaultButton(QMessageBox::Save);
135                 int response = msg.exec();
136
137                 switch (response)
138                 {
139                 case QMessageBox::Save:
140                         // Save was clicked
141                         FileSave();
142                         break;
143                 case QMessageBox::Discard:
144                         // Don't Save was clicked
145                         break;
146                 case QMessageBox::Cancel:
147                         // Cancel was clicked
148                         return;
149 //                      break;
150                 }
151         }
152
153         FileIO::ResetLayerVectors();
154         emit ReloadLayers();
155         DeleteContents(drawing->document.objects);
156         drawing->document.objects.clear();
157         drawing->dirty = false;
158         drawing->update();
159         documentName.clear();
160 //      setWindowTitle("Architektonas - Untitled");
161         setWindowFilePath(documentName);
162         statusBar()->showMessage(tr("New drawing is ready."));
163 }
164
165 void ApplicationWindow::FileOpen(void)
166 {
167         QString filename = QFileDialog::getOpenFileName(this, tr("Open Drawing"),
168                 "", tr("Architektonas files (*.drawing)"));
169
170         // User cancelled open
171         if (filename.isEmpty())
172                 return;
173
174         LoadFile(filename);
175 }
176
177 void ApplicationWindow::FileOpenRecent(void)
178 {
179         QAction * action = qobject_cast<QAction *>(sender());
180
181         if (!action)
182                 return;
183
184         LoadFile(action->data().toString());
185 }
186
187 void ApplicationWindow::LoadFile(QString filename)
188 {
189         FILE * file = fopen(filename.toUtf8().data(), "r");
190
191         if (file == 0)
192         {
193                 QMessageBox msg;
194                 msg.setText(QString(tr("Could not open file \"%1\" for loading!")).arg(filename));
195                 msg.setIcon(QMessageBox::Critical);
196                 msg.exec();
197                 return;
198         }
199
200         Container container(true);      // Make sure it's a top level container...
201         bool successful = FileIO::LoadAtnsFile(file, &container);
202         fclose(file);
203
204         if (!successful)
205         {
206                 QMessageBox msg;
207                 msg.setText(QString(tr("Could not load file \"%1\"!")).arg(filename));
208                 msg.setIcon(QMessageBox::Critical);
209                 msg.exec();
210                 // Make sure to delete any hanging objects in the container...
211                 DeleteContents(container.objects);
212                 return;
213         }
214
215         // Keep memory leaks from happening by getting rid of the old document
216         DeleteContents(drawing->document.objects);
217         emit ReloadLayers();
218         // We can do this because the vector is just a bunch of pointers to our
219         // Objects, and the Containers (non-empty) can be moved this way with no
220         // problem.
221         drawing->document = container;
222         drawing->dirty = false;
223         drawing->update();
224         documentName = filename;
225 //      setWindowTitle(QString("Architektonas - %1").arg(documentName));
226         AdjustMRU(filename);
227         statusBar()->showMessage(tr("Drawing loaded."));
228 }
229
230 void ApplicationWindow::FileSave(void)
231 {
232         if (documentName.isEmpty())
233                 documentName = QFileDialog::getSaveFileName(this, tr("Save Drawing"),
234                         "", tr("Architektonas drawings (*.drawing)"));
235
236         FILE * file = fopen(documentName.toUtf8().data(), "w");
237
238         if (file == 0)
239         {
240                 QMessageBox msg;
241                 msg.setText(QString(tr("Could not open file \"%1\" for saving!")).arg(documentName));
242                 msg.setIcon(QMessageBox::Critical);
243                 msg.exec();
244                 return;
245         }
246
247         bool successful = FileIO::SaveAtnsFile(file, &drawing->document);
248         fclose(file);
249
250         if (!successful)
251         {
252                 QMessageBox msg;
253                 msg.setText(QString(tr("Could not save file \"%1\"!")).arg(documentName));
254                 msg.setIcon(QMessageBox::Critical);
255                 msg.exec();
256                 // In this case, we should unlink the created file, since it's not
257                 // right...
258 //              unlink(documentName.toUtf8().data());
259                 QFile::remove(documentName);
260                 return;
261         }
262
263         drawing->dirty = false;
264 //      setWindowTitle(QString("Architektonas - %1").arg(documentName));
265         AdjustMRU(documentName);
266         statusBar()->showMessage(tr("Drawing saved."));
267 }
268
269 void ApplicationWindow::FileSaveAs(void)
270 {
271         QString filename = QFileDialog::getSaveFileName(this, tr("Save Drawing As"),
272                 documentName, tr("Architektonas drawings (*.drawing)"));
273
274         if (!filename.isEmpty())
275         {
276                 documentName = filename;
277                 FileSave();
278         }
279 }
280
281 void ApplicationWindow::PrintPreview(void)
282 {
283         QPrintPreviewDialog * dlg = new QPrintPreviewDialog(this);
284
285         connect(dlg, SIGNAL(paintRequested(QPrinter *)), this, SLOT(HandlePrintRequest(QPrinter *)));
286
287         dlg->exec();
288 }
289
290 void ApplicationWindow::HandlePrintRequest(QPrinter * printer)
291 {
292         QPainter qtPainter(printer);
293         Painter painter(&qtPainter);
294
295         // Save vars for screen
296         Point originSave = Global::origin;
297         double zoomSave = Global::zoom;
298         Vector screenSizeSave = Global::screenSize;
299
300         // Adjust zoom + origin to fit the paper (or NxM pages if we have 'em)
301         Rect r = drawing->GetObjectExtents((Object *)(&(drawing->document)));
302
303         QPageLayout pageLayout = printer->pageLayout();
304         QRect pageRect = pageLayout.paintRectPixels(printer->resolution());
305
306         Global::origin = r.BottomLeft();
307         Global::screenSize.x = pageRect.width();
308         Global::screenSize.y = pageRect.height();
309
310         double xScale = (double)pageRect.width() / r.Width();
311         double yScale = (double)pageRect.height() / r.Height();
312         Global::zoom = qMin(xScale, yScale);
313
314         if (xScale < yScale)
315                 Global::origin.y -= (((double)pageRect.height() / Global::zoom) - r.Height()) / 2.0;
316         else
317                 Global::origin.x -= (((double)pageRect.width() / Global::zoom) - r.Width()) / 2.0;
318
319         // Do object rendering...
320         for(int i=0; i<Global::numLayers; i++)
321                 drawing->RenderObjects(&painter, drawing->document.objects, i);
322
323         // Restore vars
324         Global::origin = originSave;
325         Global::zoom = zoomSave;
326         Global::screenSize = screenSizeSave;
327 }
328
329 //
330 // Right-click menu
331 //
332 void ApplicationWindow::contextMenuEvent(QContextMenuEvent * event)
333 {
334         // Proof of concept, still need to code up the real thing
335         QMenu menu(this);
336
337         VPVector hovered = drawing->GetHovered();
338
339         if ((drawing->select.size() > 0) || (hovered.size() > 0))
340         {
341                 QMenu * layerMenu = menu.addMenu("To layer");
342
343                 layerAct.clear();
344
345                 for(int i=0; i<Global::numLayers; i++)
346                 {
347                         QAction * act = new QAction(QIcon(), Global::layerName[i].c_str(), this);
348                         act->setData(i);
349                         layerMenu->addAction(act);
350                         layerAct.append(act);
351                         connect(act, SIGNAL(triggered()), this, SLOT(MoveToLayer()));
352                 }
353         }
354
355         menu.addAction(mirrorAct);
356         menu.addAction(rotateAct);
357         menu.addAction(trimAct);
358         menu.exec(event->globalPos());
359 }
360
361 void ApplicationWindow::MoveToLayer(void)
362 {
363         QAction * act = qobject_cast<QAction *>(sender());
364
365         drawing->MoveSelectedToLayer(act->data().toInt());
366         drawing->update();
367 }
368
369 void ApplicationWindow::UpdateFromCommand(void)
370 {
371         cw->SetToolPrompt();
372         drawing->update();
373 }
374
375 void ApplicationWindow::SnapToGridTool(void)
376 {
377         Global::snapToGrid = snapToGridAct->isChecked();
378 }
379
380 void ApplicationWindow::FixAngle(void)
381 {
382         Global::fixedAngle = fixAngleAct->isChecked();
383 }
384
385 void ApplicationWindow::FixLength(void)
386 {
387         Global::fixedLength = fixLengthAct->isChecked();
388 }
389
390 void ApplicationWindow::DeleteTool(void)
391 {
392         // For this tool, we check first to see if anything is selected. If so, we
393         // delete those and *don't* select the delete tool.
394         if (drawing->select.size() > 0)
395         {
396                 DeleteSelectedObjects(drawing->document.objects);
397                 drawing->update();
398                 deleteAct->setChecked(false);
399                 return;
400         }
401
402         // Otherwise, toggle the state of the tool
403         ClearUIToolStatesExcept(deleteAct);
404         SetInternalToolStates();
405         Global::toolSuppressCrosshair = true;
406 }
407
408 void ApplicationWindow::DimensionTool(void)
409 {
410         ClearUIToolStatesExcept(addDimensionAct);
411         SetInternalToolStates();
412 }
413
414 void ApplicationWindow::RotateTool(void)
415 {
416         ClearUIToolStatesExcept(rotateAct);
417
418         // Do tear-down if Rotate tool has been turned off
419         if (!rotateAct->isChecked())
420                 drawing->RotateHandler(ToolCleanup, Point(0, 0));
421
422         SetInternalToolStates();
423 }
424
425 void ApplicationWindow::MirrorTool(void)
426 {
427         ClearUIToolStatesExcept(mirrorAct);
428
429         // Do tear-down if Rotate tool has been turned off
430         if (!mirrorAct->isChecked())
431                 drawing->MirrorHandler(ToolCleanup, Point(0, 0));
432
433         SetInternalToolStates();
434 }
435
436 void ApplicationWindow::TrimTool(void)
437 {
438         ClearUIToolStatesExcept(trimAct);
439         SetInternalToolStates();
440         Global::toolSuppressCrosshair = true;
441 }
442
443 void ApplicationWindow::ParallelTool(void)
444 {
445         ClearUIToolStatesExcept(parallelAct);
446         SetInternalToolStates();
447         Global::toolSuppressCrosshair = true;
448 }
449
450 void ApplicationWindow::TriangulateTool(void)
451 {
452         ClearUIToolStatesExcept(triangulateAct);
453         SetInternalToolStates();
454 }
455
456 void ApplicationWindow::AddLineTool(void)
457 {
458         ClearUIToolStatesExcept(addLineAct);
459         SetInternalToolStates();
460 }
461
462 void ApplicationWindow::AddCircleTool(void)
463 {
464         ClearUIToolStatesExcept(addCircleAct);
465         SetInternalToolStates();
466 }
467
468 void ApplicationWindow::AddArcTool(void)
469 {
470         ClearUIToolStatesExcept(addArcAct);
471         SetInternalToolStates();
472 }
473
474 void ApplicationWindow::AddPolygonTool(void)
475 {
476         ClearUIToolStatesExcept(addPolygonAct);
477         SetInternalToolStates();
478 }
479
480 void ApplicationWindow::AddSplineTool(void)
481 {
482         ClearUIToolStatesExcept(addSplineAct);
483         SetInternalToolStates();
484 }
485
486 void ApplicationWindow::ZoomInTool(void)
487 {
488         double zoomFactor = 1.20;
489         QSize size = drawing->size();
490         Vector center = Painter::QtToCartesianCoords(Vector(size.width() / 2.0, size.height() / 2.0));
491
492         Global::origin = center - ((center - Global::origin) / zoomFactor);
493         Global::zoom *= zoomFactor;
494
495         UpdateZoom();
496 }
497
498 void ApplicationWindow::ZoomOutTool(void)
499 {
500         double zoomFactor = 1.20;
501         QSize size = drawing->size();
502         Vector center = Painter::QtToCartesianCoords(Vector(size.width() / 2.0, size.height() / 2.0));
503
504         Global::origin = center + ((Global::origin - center) * zoomFactor);
505         Global::zoom /= zoomFactor;
506
507         UpdateZoom();
508 }
509
510 void ApplicationWindow::UpdateZoom(void)
511 {
512         // And now, a bunch of heuristics to select the right grid size--autogrid!
513         // :-P
514         if (Global::zoom < 0.25)
515                 Global::gridSpacing = 48.0;
516         else if (Global::zoom >= 0.25 && Global::zoom < 0.50)
517                 Global::gridSpacing = 36.0;
518         else if (Global::zoom >= 0.50 && Global::zoom < 1.00)
519                 Global::gridSpacing = 24.0;
520         else if (Global::zoom >= 1.00 && Global::zoom < 2.00)
521                 Global::gridSpacing = 12.0;
522         else if (Global::zoom >= 2.00 && Global::zoom < 4.00)
523                 Global::gridSpacing = 6.0;
524         else if (Global::zoom >= 4.00 && Global::zoom < 8.00)
525                 Global::gridSpacing = 3.0;
526         else if (Global::zoom >= 8.00 && Global::zoom < 16.00)
527                 Global::gridSpacing = 1.0;
528         else if (Global::zoom >= 16.00 && Global::zoom < 32.00)
529                 Global::gridSpacing = 0.5;
530         else if (Global::zoom >= 32.00 && Global::zoom < 64.00)
531                 Global::gridSpacing = 0.25;
532         else if (Global::zoom >= 64.00 && Global::zoom < 128.00)
533                 Global::gridSpacing = 0.125;
534         else if (Global::zoom >= 128.00 && Global::zoom < 256.00)
535                 Global::gridSpacing = 0.0625;
536         else if (Global::zoom >= 256.00 && Global::zoom < 512.00)
537                 Global::gridSpacing = 0.03125;
538         else
539                 Global::gridSpacing = 0.015625;
540
541         drawing->update();
542
543         zoomIndicator->setText(QString("Zoom: %1% Grid: %2\" BU: Inch").arg(Global::zoom * 100.0).arg(Global::gridSpacing));
544
545         // This is the problem...  Changing this causes the state to update itself again, screwing up the origin...  !!! FIX !!! (commented out for now)
546 //      baseUnitInput->setText(QString("%1").arg(Global::gridSpacing));
547 }
548
549 void ApplicationWindow::ClearUIToolStatesExcept(QAction * exception)
550 {
551         QAction * actionList[] = {
552                 addArcAct, addLineAct, addCircleAct, addDimensionAct, addPolygonAct,
553                 addSplineAct, deleteAct, rotateAct, mirrorAct, trimAct,
554                 triangulateAct, parallelAct, 0
555         };
556
557         for(int i=0; actionList[i]!=0; i++)
558         {
559                 if (actionList[i] != exception)
560                         actionList[i]->setChecked(false);
561         }
562 }
563
564 void ApplicationWindow::SetInternalToolStates(void)
565 {
566         // We can be sure that if we've come here, then either an active tool is
567         // being deactivated, or a new tool is being activated.  In either case,
568         // the tool state needs to be reset.  Also, we reset the crosshair
569         // suppression flag.
570         Global::toolState = TSNone;
571         Global::toolSuppressCrosshair = false;
572
573         if (addLineAct->isChecked())
574                 Global::tool = TTLine;
575         else if (addCircleAct->isChecked())
576                 Global::tool = TTCircle;
577         else if (addArcAct->isChecked())
578                 Global::tool = TTArc;
579         else if (addDimensionAct->isChecked())
580                 Global::tool = TTDimension;
581         else if (addSplineAct->isChecked())
582                 Global::tool = TTSpline;
583         else if (addPolygonAct->isChecked())
584                 Global::tool = TTPolygon;
585         else if (deleteAct->isChecked())
586                 Global::tool = TTDelete;
587         else if (mirrorAct->isChecked())
588                 Global::tool = TTMirror;
589         else if (rotateAct->isChecked())
590                 Global::tool = TTRotate;
591         else if (trimAct->isChecked())
592                 Global::tool = TTTrim;
593         else if (parallelAct->isChecked())
594                 Global::tool = TTParallel;
595         else if (triangulateAct->isChecked())
596                 Global::tool = TTTriangulate;
597         else
598                 Global::tool = TTNone;
599
600         cw->SetToolPrompt();
601         drawing->update();
602 }
603
604 void ApplicationWindow::HelpAbout(void)
605 {
606         aboutWin->show();
607 }
608
609 void ApplicationWindow::Settings(void)
610 {
611         SettingsDialog dlg(this);
612         dlg.generalTab->antialiasChk->setChecked(drawing->useAntialiasing);
613
614         if (dlg.exec() == false)
615                 return;
616
617         // Deal with stuff here (since user hit "OK" button...)
618         drawing->useAntialiasing = dlg.generalTab->antialiasChk->isChecked();
619         WriteSettings();
620 }
621
622 void ApplicationWindow::DrawingSettings(void)
623 {
624         DrawingSettingsDlg dlg(this);
625         dlg.baseUnit->setCurrentIndex(drawing->document.baseUnit);
626         dlg.unitStyle->setCurrentIndex(drawing->document.unitStyle);
627         dlg.decimalPrecision->setCurrentIndex(drawing->document.decimalPrecision);
628         dlg.fractionalPrecision->setCurrentIndex(drawing->document.fractionalPrecision);
629
630         if (dlg.exec() == false)
631                 return;
632
633         // Deal with stuff here (since user hit "OK" button...)
634         drawing->document.baseUnit = dlg.baseUnit->currentIndex();
635         drawing->document.unitStyle = dlg.unitStyle->currentIndex();
636         drawing->document.decimalPrecision= dlg.decimalPrecision->currentIndex();
637         drawing->document.fractionalPrecision = dlg.fractionalPrecision->currentIndex();
638         drawing->update();
639 }
640
641 //
642 // Group a bunch of selected objects (which can include other groups) together
643 // or ungroup a selected group.
644 //
645 void ApplicationWindow::HandleGrouping(void)
646 {
647         int numSelected = drawing->select.size();
648
649         // If nothing selected, do nothing
650         if (numSelected == 0)
651         {
652                 statusBar()->showMessage(tr("No objects selected to make a group from."));
653                 return;
654         }
655
656         // If it's a group that's selected, ungroup it and leave the objects in a
657         // selected state
658         if (numSelected == 1)
659         {
660                 Object * obj = (Object *)drawing->select[0];
661
662                 if (obj->type != OTContainer)
663                 {
664                         statusBar()->showMessage(tr("A group requires two or more selected objects."));
665                         return;
666                 }
667
668                 // Need the parent of the group, we're assuming here that the parent is
669                 // the drawing's document. Does it matter? Maybe...
670                 // Could just stipulate that grouping like this only takes place where
671                 // the parent of the group is the drawing's document. Makes life much
672                 // simpler.
673                 Container * c = (Container *)obj;
674                 SelectAll(c->objects);
675                 RemoveSelectedObjects(drawing->document.objects);
676                 AddObjectsTo(drawing->document.objects, c->objects);
677                 drawing->select.clear();
678                 AddObjectsTo(drawing->select, c->objects);
679                 delete c;
680                 statusBar()->showMessage(tr("Objects ungrouped."));
681 //printf("Ungroup: document size = %li\n", drawing->document.objects.size());
682         }
683         // Otherwise, if it's a group of 2 or more objects (which can be groups too)
684         // group them and select the group
685         else if (numSelected > 1)
686         {
687                 Container * c = new Container();
688                 MoveSelectedObjectsTo(c->objects, drawing->document.objects);
689                 drawing->document.objects.push_back(c);
690                 ClearSelected(c->objects);
691                 c->selected = true;
692                 c->layer = Global::activeLayer;
693
694                 Rect r = drawing->GetObjectExtents((Object *)c);
695                 c->p[0] = r.TopLeft();
696                 c->p[1] = r.BottomRight();
697
698                 drawing->select.clear();
699                 drawing->select.push_back(c);
700                 statusBar()->showMessage(QString(tr("Grouped %1 objects.")).arg(numSelected));
701 //printf("Group: document size = %li\n", drawing->document.objects.size());
702         }
703
704         drawing->update();
705 }
706
707 void ApplicationWindow::HandleConnection(void)
708 {
709 #if 0
710 //double tt = Geometry::ParameterOfLineAndPoint(Vector(0, 0), Vector(10, 0), Vector(8, 2));
711 //printf("Parameter of point @ (8,2) of line (0,0), (10,0): %lf\n", tt);
712         int itemsSelected = drawing->document.ItemsSelected();
713
714         // If nothing selected, do nothing
715         if (itemsSelected == 0)
716         {
717                 statusBar()->showMessage(tr("No objects selected to connect."));
718                 return;
719         }
720
721         // If one thing selected, do nothing
722         if (itemsSelected == 1)
723         {
724                 statusBar()->showMessage(tr("Nothing to connect object to."));
725                 return;
726         }
727
728         // This is O(n^2 / 2) :-P
729         for(int i=0; i<itemsSelected; i++)
730         {
731                 Object * obj1 = drawing->document.SelectedItem(i);
732
733                 for(int j=i+1; j<itemsSelected; j++)
734                 {
735                         Object * obj2 = drawing->document.SelectedItem(j);
736                         double t, u, v, w;
737
738 //                      if ((obj1->type != OTLine) || (obj2->type != OTLine))
739 //                              continue;
740
741                         if ((obj1->type == OTLine) && (obj2->type == OTLine))
742                         {
743 //printf("Testing objects for intersection (%X, %X)...\n", obj1, obj2);
744                                 int intersects = Geometry::Intersects((Line *)obj1, (Line *)obj2, &t, &u);
745 //printf("  (%s) --> t=%lf, u=%lf\n", (intersects ? "true" : "FALSE"), t, u);
746
747                                 if (intersects)
748                                 {
749         //printf("Connecting objects (%X, %X)...\n", obj1, obj2);
750                                         obj1->Connect(obj2, u);
751                                         obj2->Connect(obj1, t);
752                                 }
753                         }
754                         else if (((obj1->type == OTLine) && (obj2->type == OTDimension))
755                                 || ((obj2->type == OTLine) && (obj1->type == OTDimension)))
756                         {
757 printf("Testing Line<->Dimension intersection...\n");
758                                 Line * line = (Line *)(obj1->type == OTLine ? obj1 : obj2);
759                                 Dimension * dim = (Dimension *)(obj1->type == OTDimension ? obj1 : obj2);
760
761                                 int intersects = Geometry::Intersects(line, dim, &t, &u);
762 printf("   -> intersects = %i, t=%lf, u=%lf\n", intersects, t, u);
763
764                                 if (intersects)
765                                 {
766                                         obj1->Connect(obj2, u);
767                                         obj2->Connect(obj1, t);
768                                 }
769                         }
770                 }
771         }
772 #else
773 #endif
774 }
775
776 void ApplicationWindow::HandleDisconnection(void)
777 {
778 }
779
780 void ApplicationWindow::HandleGridSizeInPixels(int /*size*/)
781 {
782 //      drawing->SetGridSize((uint32_t)size);
783         drawing->update();
784 }
785
786 void ApplicationWindow::HandleGridSizeInBaseUnits(QString text)
787 {
788         // Parse the text...
789         bool ok;
790         double value = text.toDouble(&ok);
791
792         // Nothing parsable to a double, so quit...
793         if (!ok || value == 0)
794                 return;
795
796         Global::gridSpacing = value;
797         Global::zoom = drawing->gridPixels / Global::gridSpacing;
798         drawing->update();
799 }
800
801 void ApplicationWindow::HandleDimensionSize(QString text)
802 {
803 /*
804 This is the third input on the view toolbar; not sure what it was supposed to do... (resize all dimensions in the drawing?)
805 */
806         // Parse the text...
807         bool ok;
808         double value = text.toDouble(&ok);
809
810         // Nothing parsable to a double, so quit...
811         if (!ok || value == 0)
812                 return;
813
814 //      drawing->document.ResizeAllDimensions(value);
815         drawing->update();
816 }
817
818 void ApplicationWindow::EditCopy(void)
819 {
820         if (drawing->select.size() > 0)
821         {
822                 DeleteContents(clipboard);
823                 clipboard = CopySelectedObjects(drawing->document.objects);
824         }
825 }
826
827 void ApplicationWindow::EditCut(void)
828 {
829         if (drawing->select.size() > 0)
830         {
831                 DeleteContents(clipboard);
832                 clipboard = MoveSelectedObjectsFrom(drawing->document.objects);
833                 drawing->update();
834         }
835 }
836
837 void ApplicationWindow::EditPaste(void)
838 {
839         if (clipboard.size() > 0)
840         {
841                 // We want to maybe make it so that the pasted objects are being moved in a "mouse drag" state...
842                 ClearSelected(drawing->document.objects);
843                 SelectAll(clipboard);
844                 drawing->document.Add(CopyObjects(clipboard));
845                 drawing->update();
846         }
847 }
848
849 //
850 // Select all *visible* objects.  If an object is on a layer that is not
851 // visible, skip it.
852 //
853 void ApplicationWindow::SelectAllObjects(void)
854 {
855         // Set object's state & update the drawing
856         SelectAll(drawing->document.objects);
857         drawing->update();
858 }
859
860 void ApplicationWindow::CreateActions(void)
861 {
862         exitAct = CreateAction(tr("&Quit"), tr("Quit"), tr("Exits the application."),
863                 QIcon(":/res/quit.png"), QKeySequence(tr("Ctrl+q")));
864         connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
865
866         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);
867         connect(snapToGridAct, SIGNAL(triggered()), this, SLOT(SnapToGridTool()));
868
869         fixAngleAct = CreateAction(tr("Fix &Angle"), tr("Fix Angle"), tr("Fixes the angle of an object."),
870                 QIcon(":/res/fix-angle.png"), QKeySequence(tr("F,A")), true);
871         connect(fixAngleAct, SIGNAL(triggered()), this, SLOT(FixAngle()));
872
873         fixLengthAct = CreateAction(tr("Fix &Length"), tr("Fix Length"), tr("Fixes the length of an object."),
874                 QIcon(":/res/fix-length.png"), QKeySequence(tr("F,L")), true);
875         connect(fixLengthAct, SIGNAL(triggered()), this, SLOT(FixLength()));
876
877         deleteAct = CreateAction(tr("&Delete"), tr("Delete Object"), tr("Deletes selected objects."), QIcon(":/res/delete-tool.png"), QKeySequence(tr("Delete")), true);
878         connect(deleteAct, SIGNAL(triggered()), this, SLOT(DeleteTool()));
879
880         addDimensionAct = CreateAction(tr("Add &Dimension"), tr("Add Dimension"), tr("Adds a dimension to the drawing."), QIcon(":/res/dimension-tool.png"), QKeySequence("D,I"), true);
881         connect(addDimensionAct, SIGNAL(triggered()), this, SLOT(DimensionTool()));
882
883         addLineAct = CreateAction(tr("Add &Line"), tr("Add Line"), tr("Adds lines to the drawing."), QIcon(":/res/add-line-tool.png"), QKeySequence("A,L"), true);
884         connect(addLineAct, SIGNAL(triggered()), this, SLOT(AddLineTool()));
885
886         addCircleAct = CreateAction(tr("Add &Circle"), tr("Add Circle"), tr("Adds circles to the drawing."), QIcon(":/res/add-circle-tool.png"), QKeySequence("A,C"), true);
887         connect(addCircleAct, SIGNAL(triggered()), this, SLOT(AddCircleTool()));
888
889         addArcAct = CreateAction(tr("Add &Arc"), tr("Add Arc"), tr("Adds arcs to the drawing."), QIcon(":/res/add-arc-tool.png"), QKeySequence("A,A"), true);
890         connect(addArcAct, SIGNAL(triggered()), this, SLOT(AddArcTool()));
891
892         addPolygonAct = CreateAction(tr("Add &Polygon"), tr("Add Polygon"), tr("Add polygons to the drawing."), QIcon(":/res/add-polygon-tool.png"), QKeySequence("A,P"), true);
893         connect(addPolygonAct, SIGNAL(triggered()), this, SLOT(AddPolygonTool()));
894
895         addSplineAct = CreateAction(tr("Add &Spline"), tr("Add Spline"), tr("Add a NURB spline to the drawing."), QIcon(":/res/add-spline-tool.png"), QKeySequence("A,S"), true);
896         connect(addSplineAct, SIGNAL(triggered()), this, SLOT(AddSplineTool()));
897
898         aboutAct = CreateAction(tr("About &Architektonas"), tr("About Architektonas"), tr("Gives information about this program."), QIcon(":/res/generic-tool.png"), QKeySequence());
899         connect(aboutAct, SIGNAL(triggered()), this, SLOT(HelpAbout()));
900
901         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);
902         connect(rotateAct, SIGNAL(triggered()), this, SLOT(RotateTool()));
903
904         zoomInAct = CreateAction(tr("Zoom &In"), tr("Zoom In"), tr("Zoom in on the document."), QIcon(":/res/zoom-in.png"), QKeySequence(tr("+")), QKeySequence(tr("=")));
905         connect(zoomInAct, SIGNAL(triggered()), this, SLOT(ZoomInTool()));
906
907         zoomOutAct = CreateAction(tr("Zoom &Out"), tr("Zoom Out"), tr("Zoom out of the document."), QIcon(":/res/zoom-out.png"), QKeySequence(tr("-")));
908         connect(zoomOutAct, SIGNAL(triggered()), this, SLOT(ZoomOutTool()));
909
910         fileNewAct = CreateAction(tr("&New Drawing"), tr("New Drawing"), tr("Creates a new drawing."), QIcon(":/res/file-new.png"), QKeySequence(tr("Ctrl+n")));
911         connect(fileNewAct, SIGNAL(triggered()), this, SLOT(FileNew()));
912
913         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")));
914         connect(fileOpenAct, SIGNAL(triggered()), this, SLOT(FileOpen()));
915
916         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")));
917         connect(fileSaveAct, SIGNAL(triggered()), this, SLOT(FileSave()));
918
919         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")));
920         connect(fileSaveAsAct, SIGNAL(triggered()), this, SLOT(FileSaveAs()));
921
922         fileCloseAct = CreateAction(tr("&Close Drawing"), tr("Close Drawing"), tr("Closes the current drawing."), QIcon(":/res/file-close.png"), QKeySequence(tr("Ctrl+w")));
923
924         settingsAct = CreateAction(tr("&Settings"), tr("Settings"), tr("Change certain defaults for Architektonas."), QIcon(":/res/settings.png"), QKeySequence());
925         connect(settingsAct, SIGNAL(triggered()), this, SLOT(Settings()));
926
927         drawingSettingsAct = CreateAction(tr("&Drawing Settings"), tr("Drawing settings"), tr("Change certain defaults for the current drawing."), QIcon(":/res/settings.png"), QKeySequence());
928         connect(drawingSettingsAct, SIGNAL(triggered()), this, SLOT(DrawingSettings()));
929
930         groupAct = CreateAction(tr("&Group"), tr("Group"), tr("Group/ungroup selected objects."), QIcon(":/res/group-tool.png"), QKeySequence("g"));
931         connect(groupAct, SIGNAL(triggered()), this, SLOT(HandleGrouping()));
932
933         connectAct = CreateAction(tr("&Connect"), tr("Connect"), tr("Connect objects at point."), QIcon(":/res/connect-tool.png"), QKeySequence("c,c"));
934         connect(connectAct, SIGNAL(triggered()), this, SLOT(HandleConnection()));
935
936         disconnectAct = CreateAction(tr("&Disconnect"), tr("Disconnect"), tr("Disconnect objects joined at point."), QIcon(":/res/disconnect-tool.png"), QKeySequence("d,d"));
937         connect(disconnectAct, SIGNAL(triggered()), this, SLOT(HandleDisconnection()));
938
939         mirrorAct = CreateAction(tr("&Mirror"), tr("Mirror"), tr("Mirror selected objects around a line."), QIcon(":/res/mirror-tool.png"), QKeySequence("m,i"), true);
940         connect(mirrorAct, SIGNAL(triggered()), this, SLOT(MirrorTool()));
941
942         trimAct = CreateAction(tr("&Trim"), tr("Trim"), tr("Trim extraneous lines from selected objects."), QIcon(":/res/trim-tool.png"), QKeySequence("t,r"), true);
943         connect(trimAct, SIGNAL(triggered()), this, SLOT(TrimTool()));
944
945         parallelAct = CreateAction(tr("&Parallel"), tr("Parallel"), tr("Create copies of objects parallel to the original."), QIcon(":/res/parallel-tool.png"), QKeySequence("p,l"), true);
946         connect(parallelAct, SIGNAL(triggered()), this, SLOT(ParallelTool()));
947
948         triangulateAct = CreateAction(tr("&Triangulate"), tr("Triangulate"), tr("Make triangles from selected lines, preserving their lengths."), QIcon(":/res/triangulate-tool.png"), QKeySequence("t,g"), true);
949         connect(triangulateAct, SIGNAL(triggered()), this, SLOT(TriangulateTool()));
950
951         editCutAct = CreateAction(tr("&Cut Objects"), tr("Cut Objects"), tr("Cut objects from the drawing to the clipboard."), QIcon(":/res/editcut2.png"), QKeySequence(tr("Ctrl+x")));
952         connect(editCutAct, SIGNAL(triggered()), this, SLOT(EditCut()));
953
954         editCopyAct = CreateAction(tr("&Copy Objects"), tr("Copy Objects"), tr("Copy objects from the drawing to the clipboard."), QIcon(":/res/editcopy2.png"), QKeySequence(tr("Ctrl+c")));
955         connect(editCopyAct, SIGNAL(triggered()), this, SLOT(EditCopy()));
956
957         editPasteAct = CreateAction(tr("&Paste Objects"), tr("Paste Objects"), tr("Paste objects from the clipboard to the drawing."), QIcon(":/res/editpaste2.png"), QKeySequence(tr("Ctrl+v")));
958         connect(editPasteAct, SIGNAL(triggered()), this, SLOT(EditPaste()));
959
960         selectAllAct = CreateAction(tr("Select &All"), tr("Select All Objects"), tr("Select all objects in the drawing."), QIcon(), QKeySequence(tr("Ctrl+a")));
961         connect(selectAllAct, SIGNAL(triggered()), this, SLOT(SelectAllObjects()));
962
963         printPreviewAct = CreateAction(tr("&Print Preview"), tr("Print Preview"), tr("Shows preview of printing operation."), QIcon(":/res/print-preview.png"), QKeySequence(tr("Ctrl+p")));
964         connect(printPreviewAct, SIGNAL(triggered()), this, SLOT(PrintPreview()));
965
966 //Hm. I think we'll have to have separate logic to do the "Radio Group Toolbar" thing...
967 // Yup, in order to turn them off, we'd have to have an "OFF" toolbar button. Ick.
968 /*      QActionGroup * group = new QActionGroup(this);
969         group->addAction(deleteAct);
970         group->addAction(addDimensionAct);
971         group->addAction(addLineAct);
972         group->addAction(addCircleAct);
973         group->addAction(addArcAct);//*/
974
975         for(int i=0; i<MRU_MAX; i++)
976         {
977                 QAction * rfa = new QAction(this);
978                 rfa->setVisible(false);
979                 connect(rfa, SIGNAL(triggered()), this, SLOT(FileOpenRecent()));
980                 mruAct.append(rfa);
981         }
982 }
983
984 //
985 // Consolidates action creation from a multi-step process to a single-step one.
986 //
987 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip,
988         QString statustip, QIcon icon, QKeySequence key, bool checkable/*= false*/)
989 {
990         QAction * action = new QAction(icon, name, this);
991         action->setToolTip(tooltip);
992         action->setStatusTip(statustip);
993         action->setShortcut(key);
994         action->setCheckable(checkable);
995
996         return action;
997 }
998
999 //
1000 // This is essentially the same as the previous function, but this allows more
1001 // than one key sequence to be added as key shortcuts.
1002 //
1003 QAction * ApplicationWindow::CreateAction(QString name, QString tooltip,
1004         QString statustip, QIcon icon, QKeySequence key1, QKeySequence key2,
1005         bool checkable/*= false*/)
1006 {
1007         QAction * action = new QAction(icon, name, this);
1008         action->setToolTip(tooltip);
1009         action->setStatusTip(statustip);
1010         QList<QKeySequence> keyList;
1011         keyList.append(key1);
1012         keyList.append(key2);
1013         action->setShortcuts(keyList);
1014         action->setCheckable(checkable);
1015
1016         return action;
1017 }
1018
1019 void ApplicationWindow::CreateMenus(void)
1020 {
1021         QMenu * menu = menuBar()->addMenu(tr("&File"));
1022         menu->addAction(fileNewAct);
1023         menu->addAction(fileOpenAct);
1024
1025         QMenu * recentMenu = menu->addMenu(tr("Open &Recent"));
1026
1027         for(int i=0; i<MRU_MAX; i++)
1028                 recentMenu->addAction(mruAct.at(i));
1029
1030         UpdateMRUActionList();
1031
1032         menu->addAction(fileSaveAct);
1033         menu->addAction(fileSaveAsAct);
1034         menu->addAction(fileCloseAct);
1035         menu->addSeparator();
1036         menu->addAction(printPreviewAct);
1037         menu->addSeparator();
1038         menu->addAction(exitAct);
1039
1040         menu = menuBar()->addMenu(tr("&View"));
1041         menu->addAction(zoomInAct);
1042         menu->addAction(zoomOutAct);
1043
1044         menu = menuBar()->addMenu(tr("&Edit"));
1045         menu->addAction(snapToGridAct);
1046         menu->addAction(groupAct);
1047         menu->addAction(fixAngleAct);
1048         menu->addAction(fixLengthAct);
1049         menu->addAction(rotateAct);
1050         menu->addAction(mirrorAct);
1051         menu->addAction(trimAct);
1052         menu->addAction(parallelAct);
1053         menu->addAction(triangulateAct);
1054         menu->addAction(connectAct);
1055         menu->addAction(disconnectAct);
1056         menu->addSeparator();
1057         menu->addAction(selectAllAct);
1058         menu->addAction(editCutAct);
1059         menu->addAction(editCopyAct);
1060         menu->addAction(editPasteAct);
1061         menu->addAction(deleteAct);
1062         menu->addSeparator();
1063         menu->addAction(addLineAct);
1064         menu->addAction(addCircleAct);
1065         menu->addAction(addArcAct);
1066         menu->addAction(addPolygonAct);
1067         menu->addAction(addSplineAct);
1068         menu->addAction(addDimensionAct);
1069         menu->addSeparator();
1070         menu->addAction(drawingSettingsAct);
1071         menu->addAction(settingsAct);
1072
1073         menu = menuBar()->addMenu(tr("&Help"));
1074         menu->addAction(aboutAct);
1075 }
1076
1077 void ApplicationWindow::CreateToolbars(void)
1078 {
1079         QToolBar * toolbar = addToolBar(tr("File"));
1080         toolbar->setObjectName("File"); // Needed for saveState()
1081         toolbar->addAction(fileNewAct);
1082         toolbar->addAction(fileOpenAct);
1083         toolbar->addAction(fileSaveAct);
1084         toolbar->addAction(fileSaveAsAct);
1085         toolbar->addAction(fileCloseAct);
1086
1087         toolbar = addToolBar(tr("View"));
1088         toolbar->setObjectName("View");
1089         toolbar->addAction(zoomInAct);
1090         toolbar->addAction(zoomOutAct);
1091
1092         QSpinBox * spinbox = new QSpinBox;
1093         toolbar->addWidget(spinbox);
1094         toolbar->addWidget(baseUnitInput);
1095         toolbar->addWidget(dimensionSizeInput);
1096
1097         toolbar = addToolBar(tr("Edit"));
1098         toolbar->setObjectName("Edit");
1099         toolbar->addAction(snapToGridAct);
1100         toolbar->addAction(groupAct);
1101         toolbar->addAction(fixAngleAct);
1102         toolbar->addAction(fixLengthAct);
1103         toolbar->addAction(rotateAct);
1104         toolbar->addAction(mirrorAct);
1105         toolbar->addAction(trimAct);
1106         toolbar->addAction(parallelAct);
1107         toolbar->addAction(triangulateAct);
1108         toolbar->addAction(editCutAct);
1109         toolbar->addAction(editCopyAct);
1110         toolbar->addAction(editPasteAct);
1111         toolbar->addAction(deleteAct);
1112         toolbar->addAction(connectAct);
1113         toolbar->addAction(disconnectAct);
1114         toolbar->addSeparator();
1115         toolbar->addAction(addLineAct);
1116         toolbar->addAction(addCircleAct);
1117         toolbar->addAction(addArcAct);
1118         toolbar->addAction(addPolygonAct);
1119         toolbar->addAction(addSplineAct);
1120         toolbar->addAction(addDimensionAct);
1121
1122         spinbox->setRange(4, 256);
1123         spinbox->setValue(12);
1124         baseUnitInput->setText("12");
1125         connect(spinbox, SIGNAL(valueChanged(int)), this, SLOT(HandleGridSizeInPixels(int)));
1126         connect(baseUnitInput, SIGNAL(textChanged(QString)), this, SLOT(HandleGridSizeInBaseUnits(QString)));
1127         connect(dimensionSizeInput, SIGNAL(textChanged(QString)), this, SLOT(HandleDimensionSize(QString)));
1128
1129         PenWidget * pw = new PenWidget();
1130         toolbar = addToolBar(tr("Pen"));
1131         toolbar->setObjectName(tr("Pen"));
1132         toolbar->addWidget(pw);
1133         connect(drawing, SIGNAL(ObjectSelected(Object *)), pw, SLOT(SetFields(Object *)));
1134         connect(pw->tbStamp, SIGNAL(triggered(QAction *)), drawing, SLOT(HandlePenStamp(QAction *)));
1135         connect(pw->tbDropper, SIGNAL(triggered(QAction *)), drawing, SLOT(HandlePenDropper(QAction *)));
1136 }
1137
1138 void ApplicationWindow::ReadSettings(void)
1139 {
1140         QPoint pos = settings.value("pos", QPoint(200, 200)).toPoint();
1141         QSize size = settings.value("size", QSize(400, 400)).toSize();
1142         drawing->useAntialiasing = settings.value("useAntialiasing", true).toBool();
1143         snapToGridAct->setChecked(settings.value("snapToGrid", true).toBool());
1144         resize(size);
1145         move(pos);
1146         restoreState(settings.value("windowState").toByteArray());
1147 }
1148
1149 void ApplicationWindow::WriteSettings(void)
1150 {
1151         settings.setValue("pos", pos());
1152         settings.setValue("size", size());
1153         settings.setValue("windowState", saveState());
1154         settings.setValue("useAntialiasing", drawing->useAntialiasing);
1155         settings.setValue("snapToGrid", snapToGridAct->isChecked());
1156 }
1157
1158 void ApplicationWindow::UpdateMRUActionList(void)
1159 {
1160         QStringList mruFilePaths = settings.value("recentFiles").toStringList();
1161
1162         int mruSize = (mruFilePaths.size() <= MRU_MAX ? mruFilePaths.size() : MRU_MAX);
1163
1164         for(int i=0; i<mruSize; i++)
1165         {
1166                 QString filename = QFileInfo(mruFilePaths.at(i)).fileName();
1167                 mruAct.at(i)->setText(filename);
1168                 mruAct.at(i)->setData(mruFilePaths.at(i));
1169                 mruAct.at(i)->setVisible(true);
1170         }
1171
1172         for(int i=mruSize; i<MRU_MAX; i++)
1173                 mruAct.at(i)->setVisible(false);
1174 }
1175
1176 void ApplicationWindow::AdjustMRU(const QString & filePath)
1177 {
1178         documentName = filePath;
1179         setWindowFilePath(documentName);
1180
1181         QStringList mruFilePaths = settings.value("recentFiles").toStringList();
1182         mruFilePaths.removeAll(filePath);
1183         mruFilePaths.prepend(filePath);
1184
1185         while (mruFilePaths.size() > MRU_MAX)
1186                 mruFilePaths.removeLast();
1187
1188         settings.setValue("recentFiles", mruFilePaths);
1189
1190         UpdateMRUActionList();
1191 }