]> Shamusworld >> Repos - architektonas/blob - src/mainapp/applicationwindow.cpp
In the middle of chasing down MDI not activating bug, renaming of Graphic to
[architektonas] / src / mainapp / applicationwindow.cpp
1 // applicationwindow.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  05/17/2010  Added this text. :-)
15 // JLH  05/27/2010  Finished refactoring old Qt3 based action handling code to
16 //                  Qt4's much more sensible action handling
17 //
18
19 #include "applicationwindow.h"
20
21 #include <fstream>
22 #include <stdint.h>
23 #include "actiondrawlinefree.h"
24 #include "actionlibraryinsert.h"
25 #include "actionprintpreview.h"
26 #include "creation.h"
27 #include "dialogfactory.h"
28 #include "dimaligned.h"
29 #include "dimlinear.h"
30 #include "dimradial.h"
31 #include "ellipse.h"
32 #include "fileio.h"
33 #include "hatch.h"
34 #include "insert.h"
35 #include "image.h"
36 #include "paintinterface.h"
37 #include "script.h"
38 #include "scriptlist.h"
39 #include "settings.h"
40 #include "solid.h"
41 #include "staticgraphicview.h"
42 #include "system.h"
43 #include "text.h"
44 #include "units.h"
45
46 #ifdef RS_CAM
47 #include "camdialog.h"
48 #include "simulationcontrols.h"
49 #endif
50
51 #include "colorbox.h"
52 #include "filedialog.h"
53 #include "pentoolbar.h"
54 #include "recentfiles.h"
55 #include "cadtoolbar.h"
56 #include "cadtoolbarmain.h"
57 #include "coordinatewidget.h"
58 #include "dlgimageoptions.h"
59 #include "mousewidget.h"
60 #include "selectionwidget.h"
61
62 #include "createqtactions.h"
63 #include "qc_dialogfactory.h"
64 #include "qg_graphicview.h"
65 #include "main.h"
66 #include "mdiwindow.h"
67
68 ApplicationWindow * ApplicationWindow::appWindow = NULL;
69
70 #ifndef QC_APP_ICON
71 # define QC_APP_ICON "qcad.png"
72 #endif
73 #ifndef QC_APP_ICON16
74 # define QC_APP_ICON16 "qcad16.png"
75 #endif
76
77 extern QSplashScreen * splash;
78
79 /**
80  * Constructor. Initializes the app.
81  */
82 ApplicationWindow::ApplicationWindow():
83         QMainWindow((QWidget *)NULL/*,this is not a Qt::WindowFlags --> Qt::WA_DeleteOnClose*/), QG_MainWindowInterface()
84 {
85         DEBUG->print("ApplicationWindow::ApplicationWindow");
86
87         appWindow = this;
88         workspace = NULL;
89
90 #warning "!!! Need to create new application icon !!!"
91         DEBUG->print("ApplicationWindow::ApplicationWindow: setting icon");
92         setWindowIcon(QIcon(":/res/" QC_APP_ICON));
93         CreateQtActions(this);
94
95         DEBUG->print("ApplicationWindow::ApplicationWindow: creating action handler");
96         actionHandler = new ActionHandler(this);
97         DEBUG->print("ApplicationWindow::ApplicationWindow: creating action handler: OK");
98
99 #ifdef SCRIPTING
100         DEBUG->print("ApplicationWindow::ApplicationWindow: creating scripter");
101         scripter = new QS_Scripter(this, this);
102         DEBUG->print("ApplicationWindow::ApplicationWindow: creating scripter: OK");
103 #endif
104
105         DEBUG->print("ApplicationWindow::ApplicationWindow: init view");
106         initView();
107         DEBUG->print("ApplicationWindow::ApplicationWindow: init toolbar");
108         initToolBar();
109         DEBUG->print("ApplicationWindow::ApplicationWindow: init actions");
110         initActions();
111         DEBUG->print("ApplicationWindow::ApplicationWindow: init menu bar");
112         initMenuBar();
113         DEBUG->print("ApplicationWindow::ApplicationWindow: init status bar");
114         initStatusBar();
115
116         DEBUG->print("ApplicationWindow::ApplicationWindow: creating dialogFactory");
117         dialogFactory = new QC_DialogFactory(this, optionWidget);
118         DEBUG->print("ApplicationWindow::ApplicationWindow: creating dialogFactory: OK");
119         DEBUG->print("setting dialog factory object");
120         DEBUG->print("%s DialogFactory instance", (DialogFactory::instance() ? "got" : "no"));
121         DialogFactory::instance()->setFactoryObject(dialogFactory);
122         DEBUG->print("setting dialog factory object: OK");
123
124         DEBUG->print("ApplicationWindow::ApplicationWindow: init settings");
125         initSettings();
126         DEBUG->print("ApplicationWindow::ApplicationWindow: init MDI");
127         initMDI();
128
129         // Disable menu and toolbar items
130         emit windowsChanged(false);
131
132         statusBar()->showMessage("Architektonas Ready", 2000);
133         //setFocusPolicy(WheelFocus);
134 }
135
136 /**
137  * Destructor.
138  */
139 ApplicationWindow::~ApplicationWindow()
140 {
141         DEBUG->print("ApplicationWindow::~ApplicationWindow");
142 #ifdef SCRIPTING
143         DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting scripter");
144         delete scripter;
145         DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting scripter: OK");
146 #endif
147
148         DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting action handler");
149         delete actionHandler;
150         DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting action handler: OK");
151
152         DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting dialog factory");
153         delete dialogFactory;
154         DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting dialog factory: OK");
155         
156         DEBUG->print("ApplicationWindow::~ApplicationWindow: OK");
157 }
158
159 /**
160  * Runs the start script if scripting is available.
161  */
162 void ApplicationWindow::slotRunStartScript()
163 {
164         slotRunScript("autostart.qs");
165 }
166
167 /**
168  * Runs a script. The action that triggers this slot has to carry the
169  * name of the script file.
170  */
171 void ApplicationWindow::slotRunScript()
172 {
173         DEBUG->print("ApplicationWindow::slotRunScript");
174
175         const QObject * s = sender();
176
177         if (s != NULL)
178         {
179                 QString script = ((QAction *)s)->text();
180                 DEBUG->print("ApplicationWindow::slotRunScript: %s", script.toLatin1().data());
181                 slotRunScript(script);
182         }
183 }
184
185 /**
186  * Runs the script with the given name.
187  */
188 void ApplicationWindow::slotRunScript(const QString & name)
189 {
190 #ifdef SCRIPTING
191         DEBUG->print("ApplicationWindow::slotRunScript");
192
193         if (scripter == NULL)
194         {
195                 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotRunScript: scripter not initialized");
196                 return;
197         }
198
199     statusBar()->showMessage(tr("Running script '%1'").arg(name), 2000);
200
201         QStringList scriptList = SYSTEM->getScriptList();
202         scriptList.append(SYSTEM->getHomeDir() + "/.architektonas/" + name);
203
204         for (QStringList::Iterator it = scriptList.begin(); it!=scriptList.end(); ++it)
205         {
206                 DEBUG->print("ApplicationWindow::slotRunScript: checking script '%s'", (*it).toLatin1().data();
207                 QFileInfo fi(*it);
208
209                 if (fi.exists() && fi.fileName() == name)
210                 {
211                         DEBUG->print("ApplicationWindow::slotRunScript: running '%s'", (*it).toLatin1().data());
212                         scripter->runScript(*it, "main");
213                 }
214         }
215 #endif
216 }
217
218 /**
219  * Called from toolbar buttons that were added by scripts to
220  * insert blocks.
221  */
222 void ApplicationWindow::slotInsertBlock()
223 {
224         const QObject * s = sender();
225
226         if (s != NULL)
227         {
228                 QString block = ((QAction *)s)->text();
229                 DEBUG->print("ApplicationWindow::slotInsertBlock: %s", block.toLatin1().data());
230                 slotInsertBlock(block);
231         }
232 }
233
234 /**
235  * Called to insert blocks.
236  */
237 void ApplicationWindow::slotInsertBlock(const QString & name)
238 {
239         DEBUG->print("ApplicationWindow::slotInsertBlock: '%s'", name.toLatin1().data());
240
241         statusBar()->showMessage(tr("Inserting block '%1'").arg(name), 2000);
242
243         GraphicView * graphicView = getGraphicView();
244         Document * document = getDocument();
245
246         if (graphicView && document)
247         {
248                 ActionLibraryInsert * action = new ActionLibraryInsert(*document, *graphicView);
249                 action->setFile(name);
250                 graphicView->setCurrentAction(action);
251         }
252 }
253
254 /**
255  * Shows the main application window and a splash screen.
256  */
257 void ApplicationWindow::show()
258 {
259 #ifdef QSPLASHSCREEN_H
260         if (splash)
261                 splash->raise();
262 #endif
263
264         QMainWindow::show();
265
266 #ifdef QSPLASHSCREEN_H
267         if (splash)
268         {
269                 splash->raise();
270                 qApp->processEvents();
271                 splash->clearMessage();
272 # ifdef QC_DELAYED_SPLASH_SCREEN
273                 QTimer::singleShot(1000 * 2, this, SLOT(finishSplashScreen()));
274 # else
275                 finishSplashScreen();
276 # endif
277         }
278 #endif
279 }
280
281 /**
282  * Called when the splash screen has to terminate.
283  */
284 void ApplicationWindow::finishSplashScreen()
285 {
286 #ifdef QSPLASHSCREEN_H
287         if (splash)
288         {
289                 splash->finish(this);
290                 delete splash;
291                 splash = 0;
292         }
293 #endif
294 }
295
296 /**
297  * Close Event. Called when the user tries to close the app.
298  */
299 void ApplicationWindow::closeEvent(QCloseEvent * /*ce*/)
300 {
301         DEBUG->print("ApplicationWindow::closeEvent()");
302         slotFileQuit();
303         DEBUG->print("ApplicationWindow::closeEvent(): OK");
304 }
305
306 /**
307  * Handles right-clicks for moving back to the last cad tool bar.
308  */
309 void ApplicationWindow::mouseReleaseEvent(QMouseEvent * e)
310 {
311         if (e->button() == Qt::RightButton && cadToolBar != NULL)
312                 cadToolBar->showToolBarMain();
313
314         e->accept();
315 }
316
317 /**
318  * Initializes the MDI workspace.
319  */
320 void ApplicationWindow::initMDI()
321 {
322         DEBUG->print("ApplicationWindow::initMDI() begin");
323
324 /* Could use QVBoxLayout instead of Q3VBox, but do we even need to? */
325 //      Q3VBox * vb = new Q3VBox(this);
326 //      vb->setFrameStyle(Q3Frame::StyledPanel | Q3Frame::Sunken);
327 //      workspace = new QMdiArea(vb);
328         workspace = new QMdiArea(this);
329 //      workspace->setScrollBarsEnabled(true);
330 //      setCentralWidget(vb);
331         setCentralWidget(workspace);//JLH:hmm. (Yes, it works! \o/)
332         DEBUG->print("ApplicationWindow::initMDI(): workspace=%08X", workspace);
333
334 //#warning "Object::connect: No such signal QMdiArea::windowActivated(QWidget *)"
335 //      connect(workspace, SIGNAL(windowActivated(QWidget *)), this, SLOT(slotWindowActivated(QWidget *)));
336         connect(workspace, SIGNAL(subWindowActivated(QMdiSubWindow *)), this,
337                 SLOT(slotWindowActivated(QMdiSubWindow *)));
338
339         DEBUG->print("ApplicationWindow::initMDI() end");
340 }
341
342 /**
343  * Initializes all QActions of the application.
344  * (Actually, it creates all application menus & toolbars. All actions are
345  *  created in CreateQtActions() and simply referenced here.)
346  */
347 void ApplicationWindow::initActions()
348 {
349         DEBUG->print("ApplicationWindow::initActions()");
350
351         //
352         // File actions:
353         //
354         QMenu * menu = new QMenu(tr("&File"), this);
355         QToolBar * tb = fileToolBar;
356         tb->setWindowTitle("File");
357 //      tb->setCloseMode(Q3DockWindow::Undocked);
358
359         menu->addAction(actionFileNew);
360         tb->addAction(actionFileNew);
361         connect(actionFileNew, SIGNAL(activated()), this, SLOT(slotFileNew()));
362         menu->addAction(actionFileOpen);
363         tb->addAction(actionFileOpen);
364         connect(actionFileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen()));
365         menu->addAction(actionFileSave);
366         tb->addAction(actionFileSave);
367         connect(actionFileSave, SIGNAL(activated()), this, SLOT(slotFileSave()));
368         connect(this, SIGNAL(windowsChanged(bool)), actionFileSave, SLOT(setEnabled(bool)));
369         menu->addAction(actionFileSaveAs);
370         connect(actionFileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs()));
371         connect(this, SIGNAL(windowsChanged(bool)), actionFileSaveAs, SLOT(setEnabled(bool)));
372         menu->addAction(actionFileExport);
373         connect(actionFileExport, SIGNAL(activated()), this, SLOT(slotFileExport()));
374         connect(this, SIGNAL(windowsChanged(bool)), actionFileExport, SLOT(setEnabled(bool)));
375
376         menu->addSeparator();
377
378         menu->addAction(actionFileClose);
379         connect(actionFileClose, SIGNAL(activated()), this, SLOT(slotFileClose()));
380         connect(this, SIGNAL(windowsChanged(bool)), actionFileClose, SLOT(setEnabled(bool)));
381
382         menu->addSeparator();
383
384         menu->addAction(actionFilePrint);
385         tb->addAction(actionFilePrint);
386         connect(actionFilePrint, SIGNAL(activated()), this, SLOT(slotFilePrint()));
387         connect(this, SIGNAL(windowsChanged(bool)), actionFilePrint, SLOT(setEnabled(bool)));
388         menu->addAction(actionFilePrintPreview);
389         tb->addAction(actionFilePrintPreview);
390         connect(actionFilePrintPreview, SIGNAL(toggled(bool)), this, SLOT(slotFilePrintPreview(bool)));
391 //???   connect(this, SIGNAL(printPreviewChanged(bool)), actionFilePrintPreview, SLOT(setOn(bool)));
392         connect(this, SIGNAL(windowsChanged(bool)), actionFilePrintPreview, SLOT(setEnabled(bool)));
393
394         menu->addSeparator();
395
396         menu->addAction(actionFileQuit);
397         connect(actionFileQuit, SIGNAL(activated()), this, SLOT(slotFileQuit()));
398
399         menu->addSeparator();
400
401         menuBar()->addMenu(menu);
402         addToolBar(Qt::TopToolBarArea, tb);
403         fileMenu = menu;
404
405         //
406         // Editing actions:
407         //
408         menu = new QMenu(tr("&Edit"), this);
409         tb = editToolBar;
410         tb->setWindowTitle("Edit");
411 //      tb->setCloseMode(Q3DockWindow::Undocked);
412
413 //      action = actionFactory.createAction(RS2::ActionEditUndo, actionHandler);
414         menu->addAction(actionEditUndo);
415         tb->addAction(actionEditUndo);
416         connect(actionEditUndo, SIGNAL(activated()), actionHandler, SLOT(slotEditUndo()));
417         connect(this, SIGNAL(windowsChanged(bool)), actionEditUndo, SLOT(setEnabled(bool)));
418 //      action = actionFactory.createAction(RS2::ActionEditRedo, actionHandler);
419         menu->addAction(actionEditRedo);
420         tb->addAction(actionEditRedo);
421         connect(actionEditRedo, SIGNAL(activated()), actionHandler, SLOT(slotEditRedo()));
422         connect(this, SIGNAL(windowsChanged(bool)), actionEditRedo, SLOT(setEnabled(bool)));
423
424         tb->addSeparator();
425         menu->addSeparator();
426
427 //      action = actionFactory.createAction(RS2::ActionEditCut, actionHandler);
428         menu->addAction(actionEditCut);
429         tb->addAction(actionEditCut);
430         connect(actionEditCut, SIGNAL(activated()), actionHandler, SLOT(slotEditCut()));
431         connect(this, SIGNAL(windowsChanged(bool)), actionEditCut, SLOT(setEnabled(bool)));
432 //      action = actionFactory.createAction(RS2::ActionEditCopy, actionHandler);
433         menu->addAction(actionEditCopy);
434         tb->addAction(actionEditCopy);
435         connect(actionEditCopy, SIGNAL(activated()), actionHandler, SLOT(slotEditCopy()));
436         connect(this, SIGNAL(windowsChanged(bool)), actionEditCopy, SLOT(setEnabled(bool)));
437 //      action = actionFactory.createAction(RS2::ActionEditPaste, actionHandler);
438         menu->addAction(actionEditPaste);
439         tb->addAction(actionEditPaste);
440         connect(actionEditPaste, SIGNAL(activated()), actionHandler, SLOT(slotEditPaste()));
441         connect(this, SIGNAL(windowsChanged(bool)), actionEditPaste, SLOT(setEnabled(bool)));
442
443         menu->addSeparator();
444
445         menu->addAction(actionOptionsGeneral);
446         connect(actionOptionsGeneral, SIGNAL(activated()), this, SLOT(slotOptionsGeneral()));
447         menu->addAction(actionOptionsDrawing);
448         connect(actionOptionsDrawing, SIGNAL(activated()), actionHandler, SLOT(slotOptionsDrawing()));
449         connect(this, SIGNAL(windowsChanged(bool)), actionOptionsDrawing, SLOT(setEnabled(bool)));
450
451         menuBar()->addMenu(menu);
452         addToolBar(Qt::TopToolBarArea, tb);
453
454         // Options menu:
455         //
456         //menu = new QPopupMenu(this);
457         //menuBar()->insertItem(tr("&Options"), menu);
458
459         // Viewing / Zooming actions:
460         //
461 //      menu = new Q3PopupMenu(this);
462         menu = new QMenu(tr("&View"), this);
463 //obsolete:     menu->setCheckable(true);
464         tb = zoomToolBar;
465         tb->setWindowTitle("View");
466 //      tb->setCloseMode(Q3DockWindow::Undocked);
467
468 //      action = actionFactory.createAction(RS2::ActionViewGrid, this);
469         menu->addAction(actionViewGrid);
470         tb->addAction(actionViewGrid);
471         actionViewGrid->setChecked(true);
472         connect(actionViewGrid, SIGNAL(toggled(bool)), this, SLOT(slotViewGrid(bool)));
473 //???   connect(this, SIGNAL(gridChanged(bool)), actionViewGrid, SLOT(setOn(bool)));
474         connect(this, SIGNAL(windowsChanged(bool)), actionViewGrid, SLOT(setEnabled(bool)));
475
476         settings.beginGroup("Appearance");
477         bool draftMode = settings.value("DraftMode", false).toBool();
478         settings.endGroup();
479
480 //      action = actionFactory.createAction(RS2::ActionViewDraft, this);
481         menu->addAction(actionViewDraft);
482         tb->addAction(actionViewDraft);
483         actionViewDraft->setChecked(draftMode);
484         connect(actionViewDraft, SIGNAL(toggled(bool)), this, SLOT(slotViewDraft(bool)));
485 //???   connect(this, SIGNAL(draftChanged(bool)), actionViewDraft, SLOT(setOn(bool)));
486         connect(this, SIGNAL(windowsChanged(bool)), actionViewDraft, SLOT(setEnabled(bool)));
487
488 //      action = actionFactory.createAction(RS2::ActionZoomRedraw, actionHandler);
489         menu->addAction(actionZoomRedraw);
490         tb->addAction(actionZoomRedraw);
491         connect(actionZoomRedraw, SIGNAL(activated()), actionHandler, SLOT(slotZoomRedraw()));
492         connect(this, SIGNAL(windowsChanged(bool)), actionZoomRedraw, SLOT(setEnabled(bool)));
493 //      action = actionFactory.createAction(RS2::ActionZoomIn, actionHandler);
494         menu->addAction(actionZoomIn);
495         tb->addAction(actionZoomIn);
496         connect(actionZoomIn, SIGNAL(activated()), actionHandler, SLOT(slotZoomIn()));
497         connect(this, SIGNAL(windowsChanged(bool)), actionZoomIn, SLOT(setEnabled(bool)));
498 //      action = actionFactory.createAction(RS2::ActionZoomOut, actionHandler);
499         menu->addAction(actionZoomOut);
500         tb->addAction(actionZoomOut);
501         connect(actionZoomOut, SIGNAL(activated()), actionHandler, SLOT(slotZoomOut()));
502         connect(this, SIGNAL(windowsChanged(bool)), actionZoomOut, SLOT(setEnabled(bool)));
503 //      action = actionFactory.createAction(RS2::ActionZoomAuto, actionHandler);
504         menu->addAction(actionZoomAuto);
505         tb->addAction(actionZoomAuto);
506         connect(actionZoomAuto, SIGNAL(activated()), actionHandler, SLOT(slotZoomAuto()));
507         connect(this, SIGNAL(windowsChanged(bool)), actionZoomAuto, SLOT(setEnabled(bool)));
508 //      action = actionFactory.createAction(RS2::ActionZoomPrevious, actionHandler);
509         menu->addAction(actionZoomPrevious);
510         tb->addAction(actionZoomPrevious);
511         connect(actionZoomPrevious, SIGNAL(activated()), actionHandler, SLOT(slotZoomPrevious()));
512         connect(this, SIGNAL(windowsChanged(bool)), actionZoomPrevious, SLOT(setEnabled(bool)));
513 //      action = actionFactory.createAction(RS2::ActionZoomWindow, actionHandler);
514         menu->addAction(actionZoomWindow);
515         tb->addAction(actionZoomWindow);
516         connect(actionZoomWindow, SIGNAL(activated()), actionHandler, SLOT(slotZoomWindow()));
517         connect(this, SIGNAL(windowsChanged(bool)), actionZoomWindow, SLOT(setEnabled(bool)));
518 //      action = actionFactory.createAction(RS2::ActionZoomPan, actionHandler);
519         menu->addAction(actionZoomPan);
520         tb->addAction(actionZoomPan);
521         connect(actionZoomPan, SIGNAL(activated()), actionHandler, SLOT(slotZoomPan()));
522         connect(this, SIGNAL(windowsChanged(bool)), actionZoomPan, SLOT(setEnabled(bool)));
523
524         menu->addSeparator();
525
526 //      action = actionFactory.createAction(RS2::ActionViewStatusBar, this);
527         menu->addAction(actionViewStatusbar);
528         actionViewStatusbar->setChecked(true);
529         connect(actionViewStatusbar, SIGNAL(toggled(bool)), this, SLOT(slotViewStatusBar(bool)));
530
531 #if 0
532         menu->insertItem(tr("Vie&ws"), createDockWindowMenu(NoToolBars));
533         menu->insertItem(tr("Tool&bars"), createDockWindowMenu(OnlyToolBars));
534 #else
535 //Actually, this isn't really needed... This crap is maintained by Qt...
536 //#warning "!!! More stuff to port to Qt4 !!!"
537 #endif
538
539         menu->addAction(actionFocusCommandLine);
540         connect(actionFocusCommandLine, SIGNAL(activated()), this, SLOT(slotFocusCommandLine()));
541         connect(this, SIGNAL(windowsChanged(bool)), actionFocusCommandLine, SLOT(setEnabled(bool)));
542         menuBar()->addMenu(menu);
543         //addToolBar(tb, tr("View"));
544 //      addDockWindow(tb, tr("View"), Qt::DockTop);
545         addToolBar(Qt::TopToolBarArea, tb);
546
547         // Selecting actions:
548         //
549         menu = new QMenu(tr("&Select"), this);
550 //      action = actionFactory.createAction(RS2::ActionDeselectAll, actionHandler);
551         menu->addAction(actionDeselectAll);
552         connect(actionDeselectAll, SIGNAL(activated()), actionHandler, SLOT(slotDeselectAll()));
553         connect(this, SIGNAL(windowsChanged(bool)), actionDeselectAll, SLOT(setEnabled(bool)));
554 //      action = actionFactory.createAction(RS2::ActionSelectAll, actionHandler);
555         menu->addAction(actionSelectAll);
556         connect(actionSelectAll, SIGNAL(activated()), actionHandler, SLOT(slotSelectAll()));
557         connect(this, SIGNAL(windowsChanged(bool)), actionSelectAll, SLOT(setEnabled(bool)));
558 //      action = actionFactory.createAction(RS2::ActionSelectSingle, actionHandler);
559         menu->addAction(actionSelectSingle);
560         connect(actionSelectSingle, SIGNAL(activated()), actionHandler, SLOT(slotSelectSingle()));
561         connect(this, SIGNAL(windowsChanged(bool)), actionSelectSingle, SLOT(setEnabled(bool)));
562 //      action = actionFactory.createAction(RS2::ActionSelectContour, actionHandler);
563         menu->addAction(actionSelectContour);
564         connect(actionSelectContour, SIGNAL(activated()), actionHandler, SLOT(slotSelectContour()));
565         connect(this, SIGNAL(windowsChanged(bool)), actionSelectContour, SLOT(setEnabled(bool)));
566 //      action = actionFactory.createAction(RS2::ActionDeselectWindow, actionHandler);
567         menu->addAction(actionDeselectWindow);
568         connect(actionDeselectWindow, SIGNAL(activated()), actionHandler, SLOT(slotDeselectWindow()));
569         connect(this, SIGNAL(windowsChanged(bool)), actionDeselectWindow, SLOT(setEnabled(bool)));
570 //      action = actionFactory.createAction(RS2::ActionSelectWindow, actionHandler);
571         menu->addAction(actionSelectWindow);
572         connect(actionSelectWindow, SIGNAL(activated()), actionHandler, SLOT(slotSelectWindow()));
573         connect(this, SIGNAL(windowsChanged(bool)), actionSelectWindow, SLOT(setEnabled(bool)));
574 //      action = actionFactory.createAction(RS2::ActionSelectInvert, actionHandler);
575         menu->addAction(actionSelectInvert);
576         connect(actionSelectInvert, SIGNAL(activated()), actionHandler, SLOT(slotSelectInvert()));
577         connect(this, SIGNAL(windowsChanged(bool)), actionSelectInvert, SLOT(setEnabled(bool)));
578 //      action = actionFactory.createAction(RS2::ActionSelectIntersected, actionHandler);
579         menu->addAction(actionSelectIntersected);
580         connect(actionSelectIntersected, SIGNAL(activated()), actionHandler, SLOT(slotSelectIntersected()));
581         connect(this, SIGNAL(windowsChanged(bool)), actionSelectIntersected, SLOT(setEnabled(bool)));
582 //      action = actionFactory.createAction(RS2::ActionDeselectIntersected, actionHandler);
583         menu->addAction(actionDeselectIntersected);
584         connect(actionDeselectIntersected, SIGNAL(activated()), actionHandler, SLOT(slotDeselectIntersected()));
585         connect(this, SIGNAL(windowsChanged(bool)), actionDeselectIntersected, SLOT(setEnabled(bool)));
586 //      action = actionFactory.createAction(RS2::ActionSelectLayer, actionHandler);
587         menu->addAction(actionSelectLayer);
588         connect(actionSelectLayer, SIGNAL(activated()), actionHandler, SLOT(slotSelectLayer()));
589         connect(this, SIGNAL(windowsChanged(bool)), actionSelectLayer, SLOT(setEnabled(bool)));
590         menuBar()->addMenu(menu);
591
592         // Drawing actions:
593         //
594         menu = new QMenu(tr("&Draw"), this);
595
596         // Points:
597         QMenu * subMenu = new QMenu(tr("&Point"), this);
598 //      action = actionFactory.createAction(RS2::ActionDrawPoint, actionHandler);
599         subMenu->addAction(actionDrawPoint);
600         connect(actionDrawPoint, SIGNAL(activated()), actionHandler, SLOT(slotDrawPoint()));
601         connect(this, SIGNAL(windowsChanged(bool)), actionDrawPoint, SLOT(setEnabled(bool)));
602         menu->addMenu(subMenu);
603
604         // Lines:
605         subMenu = new QMenu(tr("&Line"), this);
606 //      action = actionFactory.createAction(RS2::ActionDrawLine, actionHandler);
607         subMenu->addAction(actionDrawLine);
608         connect(actionDrawLine, SIGNAL(activated()), actionHandler, SLOT(slotDrawLine()));
609         connect(this, SIGNAL(windowsChanged(bool)), actionDrawLine, SLOT(setEnabled(bool)));
610 //      action = actionFactory.createAction(RS2::ActionDrawLineAngle, actionHandler);
611         subMenu->addAction(actionDrawLineAngle);
612         connect(actionDrawLineAngle, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineAngle()));
613         connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineAngle, SLOT(setEnabled(bool)));
614 //      action = actionFactory.createAction(RS2::ActionDrawLineHorizontal, actionHandler);
615         subMenu->addAction(actionDrawLineHorizontal);
616         connect(actionDrawLineHorizontal, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineHorizontal()));
617         connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineHorizontal, SLOT(setEnabled(bool)));
618 //      action = actionFactory.createAction(RS2::ActionDrawLineVertical, actionHandler);
619         subMenu->addAction(actionDrawLineVertical);
620         connect(actionDrawLineVertical, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineVertical()));
621         connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineVertical, SLOT(setEnabled(bool)));
622 //      action = actionFactory.createAction(RS2::ActionDrawLineRectangle, actionHandler);
623         subMenu->addAction(actionDrawLineRectangle);
624         connect(actionDrawLineRectangle, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineRectangle()));
625         connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineRectangle, SLOT(setEnabled(bool)));
626 //      action = actionFactory.createAction(RS2::ActionDrawLineParallel, actionHandler);
627         subMenu->addAction(actionDrawLineParallel);
628         connect(actionDrawLineParallel, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineParallel()));
629         connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineParallel, SLOT(setEnabled(bool)));
630 //      action = actionFactory.createAction(RS2::ActionDrawLineParallelThrough, actionHandler);
631         subMenu->addAction(actionDrawLineParallelThrough);
632         connect(actionDrawLineParallelThrough, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineParallelThrough()));
633         connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineParallelThrough, SLOT(setEnabled(bool)));
634 //      action = actionFactory.createAction(RS2::ActionDrawLineBisector, actionHandler);
635         subMenu->addAction(actionDrawLineBisector);
636         connect(actionDrawLineBisector, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineBisector()));
637         connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineBisector, SLOT(setEnabled(bool)));
638 //      action = actionFactory.createAction(RS2::ActionDrawLineTangent1, actionHandler);
639         subMenu->addAction(actionDrawLineTangent1);
640         connect(actionDrawLineTangent1, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineTangent1()));
641         connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineTangent1, SLOT(setEnabled(bool)));
642 //      action = actionFactory.createAction(RS2::ActionDrawLineTangent2, actionHandler);
643         subMenu->addAction(actionDrawLineTangent2);
644         connect(actionDrawLineTangent2, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineTangent2()));
645         connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineTangent2, SLOT(setEnabled(bool)));
646 //      action = actionFactory.createAction(RS2::ActionDrawLineOrthogonal, actionHandler);
647         subMenu->addAction(actionDrawLineOrthogonal);
648         connect(actionDrawLineOrthogonal, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineOrthogonal()));
649         connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineOrthogonal, SLOT(setEnabled(bool)));
650 //      action = actionFactory.createAction(RS2::ActionDrawLineRelAngle, actionHandler);
651         subMenu->addAction(actionDrawLineRelAngle);
652         connect(actionDrawLineRelAngle, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineRelAngle()));
653         connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineRelAngle, SLOT(setEnabled(bool)));
654 //      action = actionFactory.createAction(RS2::ActionDrawLinePolygon, actionHandler);
655         subMenu->addAction(actionDrawLinePolygon);
656         connect(actionDrawLinePolygon, SIGNAL(activated()), actionHandler, SLOT(slotDrawLinePolygon()));
657         connect(this, SIGNAL(windowsChanged(bool)), actionDrawLinePolygon, SLOT(setEnabled(bool)));
658 //      action = actionFactory.createAction(RS2::ActionDrawLinePolygon2, actionHandler);
659         subMenu->addAction(actionDrawLinePolygon2);
660         connect(actionDrawLinePolygon2, SIGNAL(activated()), actionHandler, SLOT(slotDrawLinePolygon2()));
661         connect(this, SIGNAL(windowsChanged(bool)), actionDrawLinePolygon2, SLOT(setEnabled(bool)));
662 //      action = actionFactory.createAction(RS2::ActionDrawLineFree, actionHandler);
663         subMenu->addAction(actionDrawLineFree);
664         connect(actionDrawLineFree, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineFree()));
665         connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineFree, SLOT(setEnabled(bool)));
666         menu->addMenu(subMenu);
667
668         // Arcs:
669         subMenu = new QMenu(tr("&Arc"), this);
670         subMenu->addAction(actionDrawArc);
671         connect(actionDrawArc, SIGNAL(activated()), actionHandler, SLOT(slotDrawArc()));
672         connect(this, SIGNAL(windowsChanged(bool)), actionDrawArc, SLOT(setEnabled(bool)));
673         subMenu->addAction(actionDrawArc3P);
674         connect(actionDrawArc3P, SIGNAL(activated()), actionHandler, SLOT(slotDrawArc3P()));
675         connect(this, SIGNAL(windowsChanged(bool)), actionDrawArc3P, SLOT(setEnabled(bool)));
676         subMenu->addAction(actionDrawArcParallel);
677         connect(actionDrawArcParallel, SIGNAL(activated()), actionHandler, SLOT(slotDrawArcParallel()));
678         connect(this, SIGNAL(windowsChanged(bool)), actionDrawArcParallel, SLOT(setEnabled(bool)));
679         subMenu->addAction(actionDrawArcTangential);
680         connect(actionDrawArcTangential, SIGNAL(activated()), actionHandler, SLOT(slotDrawArcTangential()));
681         connect(this, SIGNAL(windowsChanged(bool)), actionDrawArcTangential, SLOT(setEnabled(bool)));
682         menu->addMenu(subMenu);
683
684         // Circles:
685         subMenu = new QMenu(tr("&Circle"), this);
686 //      action = actionFactory.createAction(RS2::ActionDrawCircle, actionHandler);
687         subMenu->addAction(actionDrawCircle);
688         connect(actionDrawCircle, SIGNAL(activated()), actionHandler, SLOT(slotDrawCircle()));
689         connect(this, SIGNAL(windowsChanged(bool)), actionDrawCircle, SLOT(setEnabled(bool)));
690 //      action = actionFactory.createAction(RS2::ActionDrawCircleCR, actionHandler);
691         subMenu->addAction(actionDrawCircleCR);
692         connect(actionDrawCircleCR, SIGNAL(activated()), actionHandler, SLOT(slotDrawCircleCR()));
693         connect(this, SIGNAL(windowsChanged(bool)), actionDrawCircleCR, SLOT(setEnabled(bool)));
694 //      action = actionFactory.createAction(RS2::ActionDrawCircle2P, actionHandler);
695         subMenu->addAction(actionDrawCircle2P);
696         connect(actionDrawCircle2P, SIGNAL(activated()), actionHandler, SLOT(slotDrawCircle2P()));
697         connect(this, SIGNAL(windowsChanged(bool)), actionDrawCircle2P, SLOT(setEnabled(bool)));
698 //      action = actionFactory.createAction(RS2::ActionDrawCircle3P, actionHandler);
699         subMenu->addAction(actionDrawCircle3P);
700         connect(actionDrawCircle3P, SIGNAL(activated()), actionHandler, SLOT(slotDrawCircle3P()));
701         connect(this, SIGNAL(windowsChanged(bool)), actionDrawCircle3P, SLOT(setEnabled(bool)));
702 //      action = actionFactory.createAction(RS2::ActionDrawCircleParallel, actionHandler);
703         subMenu->addAction(actionDrawCircleParallel);
704         connect(actionDrawCircleParallel, SIGNAL(activated()), actionHandler, SLOT(slotDrawCircleParallel()));
705         connect(this, SIGNAL(windowsChanged(bool)), actionDrawCircleParallel, SLOT(setEnabled(bool)));
706         menu->addMenu(subMenu);
707
708         // Ellipses:
709         subMenu = new QMenu(tr("&Ellipse"), this);
710 //      action = actionFactory.createAction(RS2::ActionDrawEllipseAxis, actionHandler);
711         subMenu->addAction(actionDrawEllipseAxis);
712         connect(actionDrawEllipseAxis, SIGNAL(activated()), actionHandler, SLOT(slotDrawEllipseAxis()));
713         connect(this, SIGNAL(windowsChanged(bool)), actionDrawEllipseAxis, SLOT(setEnabled(bool)));
714 //      action = actionFactory.createAction(RS2::ActionDrawEllipseArcAxis, actionHandler);
715         subMenu->addAction(actionDrawEllipseArcAxis);
716         connect(actionDrawEllipseArcAxis, SIGNAL(activated()), actionHandler, SLOT(slotDrawEllipseArcAxis()));
717         connect(this, SIGNAL(windowsChanged(bool)), actionDrawEllipseArcAxis, SLOT(setEnabled(bool)));
718         menu->addMenu(subMenu);
719
720         // Splines:
721         subMenu = new QMenu(tr("&Spline"), this);
722 //      action = actionFactory.createAction(RS2::ActionDrawSpline, actionHandler);
723         subMenu->addAction(actionDrawSpline);
724         connect(actionDrawSpline, SIGNAL(activated()), actionHandler, SLOT(slotDrawSpline()));
725         connect(this, SIGNAL(windowsChanged(bool)), actionDrawSpline, SLOT(setEnabled(bool)));
726         menu->addMenu(subMenu);
727
728         // Polylines:
729         subMenu = new QMenu(tr("&Polyline"), this);
730 //      action = actionFactory.createAction(RS2::ActionDrawPolyline, actionHandler);
731         subMenu->addAction(actionDrawPolyline);
732         connect(actionDrawPolyline, SIGNAL(activated()), actionHandler, SLOT(slotDrawPolyline()));
733         connect(this, SIGNAL(windowsChanged(bool)), actionDrawPolyline, SLOT(setEnabled(bool)));
734 //      action = actionFactory.createAction(RS2::ActionPolylineAdd, actionHandler);
735         subMenu->addAction(actionPolylineAdd);
736         connect(actionPolylineAdd, SIGNAL(activated()), actionHandler, SLOT(slotPolylineAdd()));
737         connect(this, SIGNAL(windowsChanged(bool)), actionPolylineAdd, SLOT(setEnabled(bool)));
738         subMenu->addAction(actionPolylineAppend);
739         connect(actionPolylineAppend, SIGNAL(activated()), actionHandler, SLOT(slotPolylineAppend()));
740         connect(this, SIGNAL(windowsChanged(bool)), actionPolylineAppend, SLOT(setEnabled(bool)));
741 //      action = actionFactory.createAction(RS2::ActionPolylineDel, actionHandler);
742         subMenu->addAction(actionPolylineDel);
743         connect(actionPolylineDel, SIGNAL(activated()), actionHandler, SLOT(slotPolylineDel()));
744         connect(this, SIGNAL(windowsChanged(bool)), actionPolylineDel, SLOT(setEnabled(bool)));
745 //      action = actionFactory.createAction(RS2::ActionPolylineDelBetween, actionHandler);
746         subMenu->addAction(actionPolylineDelBetween);
747         connect(actionPolylineDelBetween, SIGNAL(activated()), actionHandler, SLOT(slotPolylineDelBetween()));
748         connect(this, SIGNAL(windowsChanged(bool)), actionPolylineDelBetween, SLOT(setEnabled(bool)));
749 //      action = actionFactory.createAction(RS2::ActionPolylineTrim, actionHandler);
750         subMenu->addAction(actionPolylineTrim);
751         connect(actionPolylineTrim, SIGNAL(activated()), actionHandler, SLOT(slotPolylineTrim()));
752         connect(this, SIGNAL(windowsChanged(bool)), actionPolylineTrim, SLOT(setEnabled(bool)));
753         menu->addMenu(subMenu);
754
755         // Text:
756 //      action = actionFactory.createAction(RS2::ActionDrawText, actionHandler);
757         menu->addAction(actionDrawText);
758         connect(actionDrawText, SIGNAL(activated()), actionHandler, SLOT(slotDrawText()));
759         connect(this, SIGNAL(windowsChanged(bool)), actionDrawText, SLOT(setEnabled(bool)));
760         // Hatch:
761 //      action = actionFactory.createAction(RS2::ActionDrawHatch, actionHandler);
762         menu->addAction(actionDrawHatch);
763         connect(actionDrawHatch, SIGNAL(activated()), actionHandler, SLOT(slotDrawHatch()));
764         connect(this, SIGNAL(windowsChanged(bool)), actionDrawHatch, SLOT(setEnabled(bool)));
765         // Image:
766 //      action = actionFactory.createAction(RS2::ActionDrawImage, actionHandler);
767         menu->addAction(actionDrawImage);
768         connect(actionDrawImage, SIGNAL(activated()), actionHandler, SLOT(slotDrawImage()));
769         connect(this, SIGNAL(windowsChanged(bool)), actionDrawImage, SLOT(setEnabled(bool)));
770 //      menuBar()->insertItem(tr("&Draw"), menu);
771         menuBar()->addMenu(menu);
772
773         // Dimensioning actions:
774         //
775 #ifdef __APPLE__
776         QMenu * m = menu;
777 #endif
778
779         menu = new QMenu(tr("&Dimension"), this);
780         menu->addAction(actionDimAligned);
781         connect(actionDimAligned, SIGNAL(activated()), actionHandler, SLOT(slotDimAligned()));
782         connect(this, SIGNAL(windowsChanged(bool)), actionDimAligned, SLOT(setEnabled(bool)));
783         menu->addAction(actionDimLinear);
784         connect(actionDimLinear, SIGNAL(activated()), actionHandler, SLOT(slotDimLinear()));
785         connect(this, SIGNAL(windowsChanged(bool)), actionDimLinear, SLOT(setEnabled(bool)));
786         menu->addAction(actionDimLinearHor);
787         connect(actionDimLinearHor, SIGNAL(activated()), actionHandler, SLOT(slotDimLinearHor()));
788         connect(this, SIGNAL(windowsChanged(bool)), actionDimLinearHor, SLOT(setEnabled(bool)));
789         menu->addAction(actionDimLinearVer);
790         connect(actionDimLinearVer, SIGNAL(activated()), actionHandler, SLOT(slotDimLinearVer()));
791         connect(this, SIGNAL(windowsChanged(bool)), actionDimLinearVer, SLOT(setEnabled(bool)));
792         menu->addAction(actionDimRadial);
793         connect(actionDimRadial, SIGNAL(activated()), actionHandler, SLOT(slotDimRadial()));
794         connect(this, SIGNAL(windowsChanged(bool)), actionDimRadial, SLOT(setEnabled(bool)));
795         menu->addAction(actionDimDiametric);
796         connect(actionDimDiametric, SIGNAL(activated()), actionHandler, SLOT(slotDimDiametric()));
797         connect(this, SIGNAL(windowsChanged(bool)), actionDimDiametric, SLOT(setEnabled(bool)));
798         menu->addAction(actionDimAngular);
799         connect(actionDimAngular, SIGNAL(activated()), actionHandler, SLOT(slotDimAngular()));
800         connect(this, SIGNAL(windowsChanged(bool)), actionDimAngular, SLOT(setEnabled(bool)));
801         menu->addAction(actionDimLeader);
802         connect(actionDimLeader, SIGNAL(activated()), actionHandler, SLOT(slotDimLeader()));
803         connect(this, SIGNAL(windowsChanged(bool)), actionDimLeader, SLOT(setEnabled(bool)));
804 #ifdef __APPLE__
805         m->insertItem(tr("&Dimension"), menu);
806 #else
807         menuBar()->addMenu(menu);
808 #endif
809
810         // Modifying actions:
811         //
812         menu = new QMenu(tr("&Modify"), this);
813         menu->addAction(actionModifyMove);
814         connect(actionModifyMove, SIGNAL(activated()), actionHandler, SLOT(slotModifyMove()));
815         connect(this, SIGNAL(windowsChanged(bool)), actionModifyMove, SLOT(setEnabled(bool)));
816         menu->addAction(actionModifyRotate);
817         connect(actionModifyRotate, SIGNAL(activated()), actionHandler, SLOT(slotModifyRotate()));
818         connect(this, SIGNAL(windowsChanged(bool)), actionModifyRotate, SLOT(setEnabled(bool)));
819         menu->addAction(actionModifyScale);
820         connect(actionModifyScale, SIGNAL(activated()), actionHandler, SLOT(slotModifyScale()));
821         connect(this, SIGNAL(windowsChanged(bool)), actionModifyScale, SLOT(setEnabled(bool)));
822         menu->addAction(actionModifyMirror);
823         connect(actionModifyMirror, SIGNAL(activated()), actionHandler, SLOT(slotModifyMirror()));
824         connect(this, SIGNAL(windowsChanged(bool)), actionModifyMirror, SLOT(setEnabled(bool)));
825         menu->addAction(actionModifyMoveRotate);
826         connect(actionModifyMoveRotate, SIGNAL(activated()), actionHandler, SLOT(slotModifyMoveRotate()));
827         connect(this, SIGNAL(windowsChanged(bool)), actionModifyMoveRotate, SLOT(setEnabled(bool)));
828         menu->addAction(actionModifyRotate2);
829         connect(actionModifyRotate2, SIGNAL(activated()), actionHandler, SLOT(slotModifyRotate2()));
830         connect(this, SIGNAL(windowsChanged(bool)), actionModifyRotate2, SLOT(setEnabled(bool)));
831         menu->addAction(actionModifyTrim);
832         connect(actionModifyTrim, SIGNAL(activated()), actionHandler, SLOT(slotModifyTrim()));
833         connect(this, SIGNAL(windowsChanged(bool)), actionModifyTrim, SLOT(setEnabled(bool)));
834         menu->addAction(actionModifyTrim2);
835         connect(actionModifyTrim2, SIGNAL(activated()), actionHandler, SLOT(slotModifyTrim2()));
836         connect(this, SIGNAL(windowsChanged(bool)), actionModifyTrim2, SLOT(setEnabled(bool)));
837         menu->addAction(actionModifyTrimAmount);
838         connect(actionModifyTrimAmount, SIGNAL(activated()), actionHandler, SLOT(slotModifyTrimAmount()));
839         connect(this, SIGNAL(windowsChanged(bool)), actionModifyTrimAmount, SLOT(setEnabled(bool)));
840         menu->addAction(actionModifyBevel);
841         connect(actionModifyBevel, SIGNAL(activated()), actionHandler, SLOT(slotModifyBevel()));
842         connect(this, SIGNAL(windowsChanged(bool)), actionModifyBevel, SLOT(setEnabled(bool)));
843         menu->addAction(actionModifyRound);
844         connect(actionModifyRound, SIGNAL(activated()), actionHandler, SLOT(slotModifyRound()));
845         connect(this, SIGNAL(windowsChanged(bool)), actionModifyRound, SLOT(setEnabled(bool)));
846         menu->addAction(actionModifyCut);
847         connect(actionModifyCut, SIGNAL(activated()), actionHandler, SLOT(slotModifyCut()));
848         connect(this, SIGNAL(windowsChanged(bool)), actionModifyCut, SLOT(setEnabled(bool)));
849         menu->addAction(actionModifyStretch);
850         connect(actionModifyStretch, SIGNAL(activated()), actionHandler, SLOT(slotModifyStretch()));
851         connect(this, SIGNAL(windowsChanged(bool)), actionModifyStretch, SLOT(setEnabled(bool)));
852         menu->addAction(actionModifyEntity);
853         connect(actionModifyEntity, SIGNAL(activated()), actionHandler, SLOT(slotModifyEntity()));
854         connect(this, SIGNAL(windowsChanged(bool)), actionModifyEntity, SLOT(setEnabled(bool)));
855         menu->addAction(actionModifyAttributes);
856         connect(actionModifyAttributes, SIGNAL(activated()), actionHandler, SLOT(slotModifyAttributes()));
857         connect(this, SIGNAL(windowsChanged(bool)), actionModifyAttributes, SLOT(setEnabled(bool)));
858         menu->addAction(actionModifyDelete);
859         connect(actionModifyDelete, SIGNAL(activated()), actionHandler, SLOT(slotModifyDelete()));
860         connect(this, SIGNAL(windowsChanged(bool)), actionModifyDelete, SLOT(setEnabled(bool)));
861         menu->addAction(actionModifyDeleteQuick);
862         connect(actionModifyDeleteQuick, SIGNAL(activated()), actionHandler, SLOT(slotModifyDeleteQuick()));
863         connect(this, SIGNAL(windowsChanged(bool)), actionModifyDeleteQuick, SLOT(setEnabled(bool)));
864         menu->addAction(actionModifyExplodeText);
865         connect(actionModifyExplodeText, SIGNAL(activated()), actionHandler, SLOT(slotModifyExplodeText()));
866         connect(this, SIGNAL(windowsChanged(bool)), actionModifyExplodeText, SLOT(setEnabled(bool)));
867         menu->addAction(actionBlocksExplode);
868         connect(actionBlocksExplode, SIGNAL(activated()), actionHandler, SLOT(slotBlocksExplode()));
869         connect(this, SIGNAL(windowsChanged(bool)), actionBlocksExplode, SLOT(setEnabled(bool)));
870         menuBar()->addMenu(menu);
871
872         // Snapping actions:
873         //
874         menu = new QMenu(tr("&Snap"), this);
875         menu->addAction(actionSnapFree);
876         actionHandler->setActionSnapFree(actionSnapFree); // ???Why???
877         connect(actionSnapFree, SIGNAL(activated()), actionHandler, SLOT(slotSnapFree()));
878         connect(this, SIGNAL(windowsChanged(bool)), actionSnapFree, SLOT(setEnabled(bool)));
879         actionSnapFree->setChecked(true);
880         menu->addAction(actionSnapGrid);
881         actionHandler->setActionSnapGrid(actionSnapGrid); // ???Why???
882         connect(actionSnapGrid, SIGNAL(activated()), actionHandler, SLOT(slotSnapGrid()));
883         connect(this, SIGNAL(windowsChanged(bool)), actionSnapGrid, SLOT(setEnabled(bool)));
884         menu->addAction(actionSnapEndpoint);
885         actionHandler->setActionSnapEndpoint(actionSnapEndpoint); // ???Why???
886         connect(actionSnapEndpoint, SIGNAL(activated()), actionHandler, SLOT(slotSnapEndpoint()));
887         connect(this, SIGNAL(windowsChanged(bool)), actionSnapEndpoint, SLOT(setEnabled(bool)));
888         menu->addAction(actionSnapOnEntity);
889         actionHandler->setActionSnapOnEntity(actionSnapOnEntity); // ???Why???
890         connect(actionSnapOnEntity, SIGNAL(activated()), actionHandler, SLOT(slotSnapOnEntity()));
891         connect(this, SIGNAL(windowsChanged(bool)), actionSnapOnEntity, SLOT(setEnabled(bool)));
892         menu->addAction(actionSnapCenter);
893         actionHandler->setActionSnapCenter(actionSnapCenter); // ???Why???
894         connect(actionSnapCenter, SIGNAL(activated()), actionHandler, SLOT(slotSnapCenter()));
895         connect(this, SIGNAL(windowsChanged(bool)), actionSnapCenter, SLOT(setEnabled(bool)));
896         menu->addAction(actionSnapMiddle);
897         actionHandler->setActionSnapMiddle(actionSnapMiddle); // ???Why???
898         connect(actionSnapMiddle, SIGNAL(activated()), actionHandler, SLOT(slotSnapMiddle()));
899         connect(this, SIGNAL(windowsChanged(bool)), actionSnapMiddle, SLOT(setEnabled(bool)));
900         menu->addAction(actionSnapDist);
901         actionHandler->setActionSnapDist(actionSnapDist); // ???Why???
902         connect(actionSnapDist, SIGNAL(activated()), actionHandler, SLOT(slotSnapDist()));
903         connect(this, SIGNAL(windowsChanged(bool)), actionSnapDist, SLOT(setEnabled(bool)));
904         menu->addAction(actionSnapIntersection);
905         actionHandler->setActionSnapIntersection(actionSnapIntersection); // ???Why???
906         connect(actionSnapIntersection, SIGNAL(activated()), actionHandler, SLOT(slotSnapIntersection()));
907         connect(this, SIGNAL(windowsChanged(bool)), actionSnapIntersection, SLOT(setEnabled(bool)));
908         menu->addAction(actionSnapIntersectionManual);
909         actionHandler->setActionSnapIntersectionManual(actionSnapIntersectionManual); // ???Why???
910         connect(actionSnapIntersectionManual, SIGNAL(activated()), actionHandler, SLOT(slotSnapIntersectionManual()));
911         connect(this, SIGNAL(windowsChanged(bool)), actionSnapIntersectionManual, SLOT(setEnabled(bool)));
912
913         menu->addSeparator();
914
915         menu->addAction(actionRestrictNothing);
916         actionHandler->setActionRestrictNothing(actionRestrictNothing); // ???WHY???
917         connect(actionRestrictNothing, SIGNAL(activated()), actionHandler, SLOT(slotRestrictNothing()));
918         connect(this, SIGNAL(windowsChanged(bool)), actionRestrictNothing, SLOT(setEnabled(bool)));
919         actionRestrictNothing->setChecked(true);
920         menu->addAction(actionRestrictOrthogonal);
921         actionHandler->setActionRestrictOrthogonal(actionRestrictOrthogonal); // ???WHY???
922         connect(actionRestrictOrthogonal, SIGNAL(activated()), actionHandler, SLOT(slotRestrictOrthogonal()));
923         connect(this, SIGNAL(windowsChanged(bool)), actionRestrictOrthogonal, SLOT(setEnabled(bool)));
924         menu->addAction(actionRestrictHorizontal);
925         actionHandler->setActionRestrictHorizontal(actionRestrictHorizontal); // ???WHY???
926         connect(actionRestrictHorizontal, SIGNAL(activated()), actionHandler, SLOT(slotRestrictHorizontal()));
927         connect(this, SIGNAL(windowsChanged(bool)), actionRestrictHorizontal, SLOT(setEnabled(bool)));
928         menu->addAction(actionRestrictVertical);
929         actionHandler->setActionRestrictVertical(actionRestrictVertical); // ???WHY???
930         connect(actionRestrictVertical, SIGNAL(activated()), actionHandler, SLOT(slotRestrictVertical()));
931         connect(this, SIGNAL(windowsChanged(bool)), actionRestrictVertical, SLOT(setEnabled(bool)));
932
933         menu->addSeparator();
934
935         menu->addAction(actionSetRelativeZero);
936         connect(actionSetRelativeZero, SIGNAL(activated()), actionHandler, SLOT(slotSetRelativeZero()));
937         connect(this, SIGNAL(windowsChanged(bool)), actionSetRelativeZero, SLOT(setEnabled(bool)));
938         menu->addAction(actionLockRelativeZero);
939         actionHandler->setActionLockRelativeZero(actionLockRelativeZero);
940         connect(actionLockRelativeZero, SIGNAL(toggled(bool)), actionHandler, SLOT(slotLockRelativeZero(bool))); // ???WHY???
941         connect(this, SIGNAL(windowsChanged(bool)), actionLockRelativeZero, SLOT(setEnabled(bool)));
942         menuBar()->addMenu(menu);
943
944         //
945         // Info actions:
946         //
947         menu = new QMenu(tr("&Info"), this);
948         menu->addAction(actionInfoDist);
949         connect(actionInfoDist, SIGNAL(activated()), actionHandler, SLOT(slotInfoDist()));
950         connect(this, SIGNAL(windowsChanged(bool)), actionInfoDist, SLOT(setEnabled(bool)));
951         menu->addAction(actionInfoDist2);
952         connect(actionInfoDist2, SIGNAL(activated()), actionHandler, SLOT(slotInfoDist2()));
953         connect(this, SIGNAL(windowsChanged(bool)), actionInfoDist2, SLOT(setEnabled(bool)));
954         menu->addAction(actionInfoAngle);
955         connect(actionInfoAngle, SIGNAL(activated()), actionHandler, SLOT(slotInfoAngle()));
956         connect(this, SIGNAL(windowsChanged(bool)), actionInfoAngle, SLOT(setEnabled(bool)));
957         menu->addAction(actionInfoTotalLength);
958         connect(actionInfoTotalLength, SIGNAL(activated()), actionHandler, SLOT(slotInfoTotalLength()));
959         connect(this, SIGNAL(windowsChanged(bool)), actionInfoTotalLength, SLOT(setEnabled(bool)));
960         menu->addAction(actionInfoArea);
961         connect(actionInfoArea, SIGNAL(activated()), actionHandler, SLOT(slotInfoArea()));
962         connect(this, SIGNAL(windowsChanged(bool)), actionInfoArea, SLOT(setEnabled(bool)));
963         menuBar()->addMenu(menu);
964
965         //
966         // Layer actions:
967         //
968         menu = new QMenu(tr("&Layer"), this);
969         menu->addAction(actionLayersDefreezeAll);
970         connect(actionLayersDefreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotLayersDefreezeAll()));
971         connect(this, SIGNAL(windowsChanged(bool)), actionLayersDefreezeAll, SLOT(setEnabled(bool)));
972         menu->addAction(actionLayersFreezeAll);
973         connect(actionLayersFreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotLayersFreezeAll()));
974         connect(this, SIGNAL(windowsChanged(bool)), actionLayersFreezeAll, SLOT(setEnabled(bool)));
975         menu->addAction(actionLayersAdd);
976         connect(actionLayersAdd, SIGNAL(activated()), actionHandler, SLOT(slotLayersAdd()));
977         connect(this, SIGNAL(windowsChanged(bool)), actionLayersAdd, SLOT(setEnabled(bool)));
978         menu->addAction(actionLayersRemove);
979         connect(actionLayersRemove, SIGNAL(activated()), actionHandler, SLOT(slotLayersRemove()));
980         connect(this, SIGNAL(windowsChanged(bool)), actionLayersRemove, SLOT(setEnabled(bool)));
981         menu->addAction(actionLayersEdit);
982         connect(actionLayersEdit, SIGNAL(activated()), actionHandler, SLOT(slotLayersEdit()));
983         connect(this, SIGNAL(windowsChanged(bool)), actionLayersEdit, SLOT(setEnabled(bool)));
984         menu->addAction(actionLayersToggleView);
985         connect(actionLayersToggleView, SIGNAL(activated()), actionHandler, SLOT(slotLayersToggleView()));
986         connect(this, SIGNAL(windowsChanged(bool)), actionLayersToggleView, SLOT(setEnabled(bool)));
987         menuBar()->addMenu(menu);
988
989         // Block actions:
990         //
991         menu = new QMenu(tr("&Block"), this);
992         menu->addAction(actionBlocksDefreezeAll);
993         connect(actionBlocksDefreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotBlocksDefreezeAll()));
994         connect(this, SIGNAL(windowsChanged(bool)), actionBlocksDefreezeAll, SLOT(setEnabled(bool)));
995         menu->addAction(actionBlocksFreezeAll);
996         connect(actionBlocksFreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotBlocksFreezeAll()));
997         connect(this, SIGNAL(windowsChanged(bool)), actionBlocksFreezeAll, SLOT(setEnabled(bool)));
998         menu->addAction(actionBlocksAdd);
999         connect(actionBlocksAdd, SIGNAL(activated()), actionHandler, SLOT(slotBlocksAdd()));
1000         connect(this, SIGNAL(windowsChanged(bool)), actionBlocksAdd, SLOT(setEnabled(bool)));
1001         menu->addAction(actionBlocksRemove);
1002         connect(actionBlocksRemove, SIGNAL(activated()), actionHandler, SLOT(slotBlocksRemove()));
1003         connect(this, SIGNAL(windowsChanged(bool)), actionBlocksRemove, SLOT(setEnabled(bool)));
1004         menu->addAction(actionBlocksAttributes);
1005         connect(actionBlocksAttributes, SIGNAL(activated()), actionHandler, SLOT(slotBlocksAttributes()));
1006         connect(this, SIGNAL(windowsChanged(bool)), actionBlocksAttributes, SLOT(setEnabled(bool)));
1007         menu->addAction(actionBlocksInsert);
1008         connect(actionBlocksInsert, SIGNAL(activated()), actionHandler, SLOT(slotBlocksInsert()));
1009         connect(this, SIGNAL(windowsChanged(bool)), actionBlocksInsert, SLOT(setEnabled(bool)));
1010         menu->addAction(actionBlocksEdit);
1011         connect(actionBlocksEdit, SIGNAL(activated()), actionHandler, SLOT(slotBlocksEdit()));
1012         connect(this, SIGNAL(windowsChanged(bool)), actionBlocksEdit, SLOT(setEnabled(bool)));
1013         menu->addAction(actionBlocksCreate);
1014         connect(actionBlocksCreate, SIGNAL(activated()), actionHandler, SLOT(slotBlocksCreate()));
1015         connect(this, SIGNAL(windowsChanged(bool)), actionBlocksCreate, SLOT(setEnabled(bool)));
1016         menu->addAction(actionBlocksExplode);
1017         connect(actionBlocksExplode, SIGNAL(activated()), actionHandler, SLOT(slotBlocksExplode()));
1018         connect(this, SIGNAL(windowsChanged(bool)), actionBlocksExplode, SLOT(setEnabled(bool)));
1019         menuBar()->addMenu(menu);
1020
1021 //will *this* make a toolbar break for us???
1022         addToolBarBreak(Qt::TopToolBarArea);
1023 //      addDockWindow(penToolBar, tr("Pen"), Qt::DockTop);
1024 //      addDockWindow(optionWidget, tr("Tool Options"), Qt::DockTop, true);
1025         addToolBar(Qt::TopToolBarArea, (QToolBar *)penToolBar); // hmm.
1026         addToolBar(Qt::TopToolBarArea, optionWidget);
1027
1028 #ifdef SCRIPTING
1029         // Scripts menu:
1030         //
1031         scriptMenu = new QMenu(this);
1032         scriptOpenIDE = actionFactory.createAction(RS2::ActionScriptOpenIDE, this);
1033         scriptOpenIDE->addTo(scriptMenu);
1034         scriptRun = actionFactory.createAction(RS2::ActionScriptRun, this);
1035         scriptRun->addTo(scriptMenu);
1036 #else
1037         scriptMenu = NULL;
1038         scriptOpenIDE = NULL;
1039         scriptRun = NULL;
1040 #endif
1041
1042 #ifdef RS_CAM
1043         // CAM menu:
1044         menu = new QMenu(tr("&CAM"), this);
1045         action = actionFactory.createAction(RS2::ActionCamExportAuto, actionHandler);
1046         menu->addAction(action);
1047         connect(this, SIGNAL(windowsChanged(bool)), action, SLOT(setEnabled(bool)));
1048         action = actionFactory.createAction(RS2::ActionCamReorder, actionHandler);
1049         menu->addAction(action);
1050         connect(this, SIGNAL(windowsChanged(bool)), action, SLOT(setEnabled(bool)));
1051         menuBar()->addMenu(menu);
1052 #endif
1053
1054         // Help menu:
1055         //
1056         helpAboutApp = new QAction(QIcon(QC_APP_ICON16), tr("&About Architektonas"), this);
1057 //    helpAboutApp = new QAction(tr("About"), qPixmapFromMimeSource(QC_APP_ICON16), tr("&About %1").arg(QC_APPNAME), 0, this);
1058         helpAboutApp->setStatusTip(tr("About the application"));
1059         //helpAboutApp->setWhatsThis(tr("About\n\nAbout the application"));
1060         connect(helpAboutApp, SIGNAL(activated()), this, SLOT(slotHelpAbout()));
1061
1062         helpManual = new QAction(QIcon(":/res/contents.png"), tr("&Manual"), this);
1063         helpManual->setShortcut(Qt::Key_F1);
1064 //    helpManual = new QAction(qPixmapFromMimeSource("contents.png"), tr("&Manual"), Qt::Key_F1, this);
1065         helpManual->setStatusTip(tr("Launch the online manual"));
1066         connect(helpManual, SIGNAL(activated()), this, SLOT(slotHelpManual()));
1067
1068         testDumpEntities = new QAction("Dump &Entities", this);
1069         connect(testDumpEntities, SIGNAL(activated()), this, SLOT(slotTestDumpEntities()));
1070         testDumpUndo = new QAction("Undo Info", this);
1071         connect(testDumpUndo, SIGNAL(activated()), this, SLOT(slotTestDumpUndo()));
1072         testUpdateInserts = new QAction("&Update Inserts", this);
1073         connect(testUpdateInserts, SIGNAL(activated()), this, SLOT(slotTestUpdateInserts()));
1074         testDrawFreehand = new QAction("Draw Freehand", this);
1075         connect(testDrawFreehand, SIGNAL(activated()), this, SLOT(slotTestDrawFreehand()));
1076         testInsertBlock = new QAction("Insert Block", this);
1077         connect(testInsertBlock, SIGNAL(activated()), this, SLOT(slotTestInsertBlock()));
1078         testInsertText = new QAction("Insert Text", this);
1079         connect(testInsertText, SIGNAL(activated()), this, SLOT(slotTestInsertText()));
1080         testInsertImage = new QAction("Insert Image", this);
1081         connect(testInsertImage, SIGNAL(activated()), this, SLOT(slotTestInsertImage()));
1082         testUnicode = new QAction("Unicode", this);
1083         connect(testUnicode, SIGNAL(activated()), this, SLOT(slotTestUnicode()));
1084         testInsertEllipse = new QAction("Insert Ellipse", this);
1085         connect(testInsertEllipse, SIGNAL(activated()), this, SLOT(slotTestInsertEllipse()));
1086         testMath01 = new QAction("Math01", this);
1087         connect(testMath01, SIGNAL(activated()), this, SLOT(slotTestMath01()));
1088         testResize640 = new QAction("Resize 1", this);
1089         connect(testResize640, SIGNAL(activated()), this, SLOT(slotTestResize640()));
1090         testResize800 = new QAction("Resize 2", this);
1091         connect(testResize800, SIGNAL(activated()), this, SLOT(slotTestResize800()));
1092         testResize1024 = new QAction("Resize 3", this);
1093         connect(testResize1024, SIGNAL(activated()), this, SLOT(slotTestResize1024()));
1094 }
1095
1096 /**
1097  * Initializes the menu bar.
1098  */
1099 void ApplicationWindow::initMenuBar()
1100 {
1101         DEBUG->print("ApplicationWindow::initMenuBar()");
1102
1103         // menuBar entry windowsMenu
1104         windowsMenu = new QMenu(tr("&Window"), this);
1105 //according to docs, this is obsolete:  windowsMenu->setCheckable(true);
1106         connect(windowsMenu, SIGNAL(aboutToShow()), this, SLOT(slotWindowsMenuAboutToShow()));
1107
1108         // menuBar entry scriptMenu
1109         //scriptMenu = new QPopupMenu(this);
1110         //scriptMenu->setCheckable(true);
1111         //scriptOpenIDE->addTo(scriptMenu);
1112         //scriptRun->addTo(scriptMenu);
1113         //connect(scriptMenu, SIGNAL(aboutToShow()), this, SLOT(slotScriptMenuAboutToShow()));
1114
1115         // menuBar entry helpMenu
1116         helpMenu = new QMenu(tr("&Help"), this);
1117         helpMenu->addAction(helpManual);
1118         helpMenu->addSeparator();
1119         helpMenu->addAction(helpAboutApp);
1120
1121         // menuBar entry test menu
1122         testMenu = new QMenu(tr("De&bugging"), this);
1123         testMenu->addAction(testDumpEntities);
1124         testMenu->addAction(testDumpUndo);
1125         testMenu->addAction(testUpdateInserts);
1126         testMenu->addAction(testDrawFreehand);
1127         testMenu->addAction(testInsertBlock);
1128         testMenu->addAction(testInsertText);
1129         testMenu->addAction(testInsertImage);
1130         testMenu->addAction(testInsertEllipse);
1131         testMenu->addAction(testUnicode);
1132         testMenu->addAction(testMath01);
1133         testMenu->addAction(testResize640);
1134         testMenu->addAction(testResize800);
1135         testMenu->addAction(testResize1024);
1136
1137         // menuBar configuration
1138 #ifdef SCRIPTING
1139         menuBar()->addMenu(scriptMenu);
1140 #endif
1141         menuBar()->addMenu(windowsMenu);
1142 #warning "!!!"
1143         menuBar()->addMenu(helpMenu);
1144
1145         if (QC_DEBUGGING)
1146                 menuBar()->addMenu(testMenu);
1147
1148         recentFiles = new RecentFiles(this, fileMenu);
1149 }
1150
1151 /**
1152  * Initializes the tool bars (file tool bar and pen tool bar).
1153  */
1154 void ApplicationWindow::initToolBar()
1155 {
1156         DEBUG->print("ApplicationWindow::initToolBar()");
1157
1158         fileToolBar = addToolBar(tr("File Operations"));
1159         fileToolBar->setObjectName("file");
1160         editToolBar = addToolBar(tr("Edit Operations"));
1161         editToolBar->setObjectName("edit");
1162         zoomToolBar = addToolBar(tr("Zoom Operations"));
1163         zoomToolBar->setObjectName("zoom");
1164         penToolBar = new PenToolBar(this, "Pen Selection");
1165         penToolBar->setObjectName("pen");
1166
1167         connect(penToolBar, SIGNAL(penChanged(Pen)), this, SLOT(slotPenChanged(Pen)));
1168
1169 //      optionWidget = new Q3ToolBar(this, "Tool Options");
1170 //addToolBarBreak() does nothing...
1171 #warning "!!! add/insertToolBarBreak() does nothing !!!"
1172 //      addToolBarBreak(Qt::TopToolBarArea);
1173         optionWidget = addToolBar(tr("Tool Options"));
1174         optionWidget->setObjectName("tooloptions");
1175         optionWidget->setMinimumHeight(26);
1176         optionWidget->setMaximumHeight(26);
1177 #warning "!!! No analogue found for setHorizontallyStretchable yet !!!"
1178 //Maybe sizePolicy or somesuch??
1179         optionWidget->setMinimumWidth(150);
1180         optionWidget->setMaximumWidth(800);
1181 #warning "Following line commented out..."
1182 //      optionWidget->setFixedExtentHeight(26);
1183 //      optionWidget->setHorizontallyStretchable(true);
1184 //      addDockWindow(optionWidget, DockTop, true);
1185
1186         // CAD toolbar left:
1187 //      Q3ToolBar * t = new Q3ToolBar(this, "CAD Tools");
1188         QToolBar * t = addToolBar(tr("CAD Tools"));
1189         t->setObjectName("cadtools");
1190 #warning "Following two lines commented out..."
1191 //      t->setFixedExtentWidth(59);
1192         t->setMinimumWidth(59);
1193         t->setMaximumWidth(59);
1194 //      t->setVerticallyStretchable(true);
1195 //      addDockWindow(t, Qt::DockLeft, false);
1196         addToolBar(Qt::LeftToolBarArea, t);
1197
1198         cadToolBar = new CadToolBar(t);//, "CAD Tools");
1199         cadToolBar->createSubToolBars(actionHandler);
1200
1201         connect(cadToolBar, SIGNAL(signalBack()), this, SLOT(slotBack()));
1202         connect(this, SIGNAL(windowsChanged(bool)), cadToolBar, SLOT(setEnabled(bool)));
1203
1204 //      QG_CadToolBarMain * cadToolBarMain = new QG_CadToolBarMain(cadToolBar);
1205 //No, no break inserted here either...
1206 //      insertToolBarBreak(optionWidget);
1207 }
1208
1209 /**
1210  * Initializes the status bar at the bottom.
1211  */
1212 void ApplicationWindow::initStatusBar()
1213 {
1214         DEBUG->print("ApplicationWindow::initStatusBar()");
1215
1216         statusBar()->setMinimumHeight(32);
1217         coordinateWidget = new CoordinateWidget(statusBar());
1218         statusBar()->addWidget(coordinateWidget);
1219         mouseWidget = new MouseWidget(statusBar());
1220         statusBar()->addWidget(mouseWidget);
1221         selectionWidget = new SelectionWidget(statusBar());
1222         statusBar()->addWidget(selectionWidget);
1223 }
1224
1225 /**
1226  * Initializes the global application settings from the
1227  * config file (unix, mac) or registry (windows).
1228  * (Actually, this uses the Qt settings subsystem, so we don't have to worry
1229  * about that crap.)
1230  */
1231 void ApplicationWindow::initSettings()
1232 {
1233         DEBUG->print("ApplicationWindow::initSettings()");
1234         settings.beginGroup("RecentFiles");
1235
1236         for(int i=0; i<recentFiles->Maximum(); ++i)
1237         {
1238                 QString filename = settings.value(QString("File") + QString::number(i + 1)).toString();
1239
1240                 if (!filename.isEmpty())
1241                         recentFiles->add(filename);
1242         }
1243
1244         settings.endGroup();
1245
1246         if (recentFiles->count() > 0)
1247                 recentFiles->UpdateGUI();
1248
1249         settings.beginGroup("Geometry");
1250         QSize windowSize = settings.value("WindowSize", QSize(950, 700)).toSize();
1251         QPoint windowPos = settings.value("WindowPos", QPoint(0, 30)).toPoint();
1252         restoreState(settings.value("DockWindows").toByteArray());
1253         settings.endGroup();
1254
1255 #ifdef __APPLE__
1256         if (windowSize.y() < 30)
1257                 windowSize.y() = 30;
1258 #endif
1259
1260         resize(windowSize);
1261         move(windowPos);
1262 }
1263
1264 /**
1265  * Stores the global application settings to file or registry.
1266  */
1267 void ApplicationWindow::storeSettings()
1268 {
1269         DEBUG->print("ApplicationWindow::storeSettings()");
1270
1271         settings.beginGroup("RecentFiles");
1272
1273         for(int i=0; i<recentFiles->count(); ++i)
1274                 settings.setValue(QString("File") + QString::number(i + 1), recentFiles->get(i));
1275
1276         settings.endGroup();
1277
1278         settings.beginGroup("Geometry");
1279         settings.setValue("WindowSize", size());
1280         settings.setValue("WindowPos", pos());
1281         settings.setValue("DockWindows", saveState());
1282         settings.endGroup();
1283
1284         DEBUG->print("ApplicationWindow::storeSettings(): OK");
1285 }
1286
1287 /**
1288  * Initializes the view.
1289  */
1290 void ApplicationWindow::initView()
1291 {
1292         DEBUG->print("ApplicationWindow::initView()");
1293
1294         DEBUG->print("init view..");
1295         QDockWidget * dw;
1296         layerWidget = NULL;
1297         blockWidget = NULL;
1298         libraryWidget = NULL;
1299         commandWidget = NULL;
1300 #ifdef RS_CAM
1301         simulationControls = NULL;
1302 #endif
1303
1304 #ifdef RS_CAM
1305         DEBUG->print("  simulation widget..");
1306         dw = new QDockWidget(QDockWidget::InDock, this, "Simulation");
1307         simulationControls = new RS_SimulationControls(dw, "Simulation");
1308         simulationControls->setFocusPolicy(Qt::NoFocus);
1309         connect(simulationControls, SIGNAL(escape()), this, SLOT(slotFocus()));
1310         connect(this, SIGNAL(windowsChanged(bool)), simulationControls, SLOT(setEnabled(bool)));
1311         dw->setWidget(simulationControls);
1312         dw->resize(240, 80);
1313         dw->setResizeEnabled(true);
1314         dw->setFixedExtentWidth(120);
1315         dw->setFixedHeight(80);
1316         dw->setCaption(tr("Simulation Controls"));
1317         dw->setCloseMode(Q3DockWindow::Always);
1318         addDockWindow(dw, Qt::DockRight);
1319         simulationDockWindow = dw;
1320         //simulationDockWindow->hide();
1321 #endif
1322
1323         DEBUG->print("  layer widget..");
1324 //      dw = new QDockWidget(QDockWidget::InDock, this, "Layer");
1325         dw = new QDockWidget(tr("Layer List"), this);
1326         dw->setObjectName("layer");
1327         layerWidget = new LayerWidget(actionHandler, dw, "Layer");
1328         layerWidget->setFocusPolicy(Qt::NoFocus);
1329         connect(layerWidget, SIGNAL(escape()), this, SLOT(slotFocus()));
1330         connect(this, SIGNAL(windowsChanged(bool)), layerWidget, SLOT(setEnabled(bool)));
1331         dw->setWidget(layerWidget);
1332 #warning "following four lines commented out..."
1333 //      dw->setFixedExtentWidth(120);
1334 //      dw->setResizeEnabled(true);
1335 //      dw->setCloseMode(Q3DockWindow::Always);
1336 //      dw->setCaption(tr("Layer List"));
1337         addDockWidget(Qt::RightDockWidgetArea, dw);
1338         layerDockWindow = dw;
1339
1340         DEBUG->print("  block widget..");
1341 //      dw = new QDockWidget(QDockWidget::InDock, this, "Block");
1342         dw = new QDockWidget(tr("Block List"), this);
1343         dw->setObjectName("block");
1344         blockWidget = new BlockWidget(actionHandler, dw, "Block");
1345         blockWidget->setFocusPolicy(Qt::NoFocus);
1346         connect(blockWidget, SIGNAL(escape()), this, SLOT(slotFocus()));
1347         connect(this, SIGNAL(windowsChanged(bool)), blockWidget, SLOT(setEnabled(bool)));
1348         dw->setWidget(blockWidget);
1349 #warning "following four lines commented out..."
1350 //      dw->setFixedExtentWidth(120);
1351 //      dw->setResizeEnabled(true);
1352 //      dw->setCloseMode(Q3DockWindow::Always);
1353 //      dw->setCaption(tr("Block List"));
1354         addDockWidget(Qt::RightDockWidgetArea, dw);
1355         blockDockWindow = dw;
1356
1357         DEBUG->print("  library widget..");
1358 //      dw = new QDockWidget(QDockWidget::OutsideDock, this, "Library");
1359         dw = new QDockWidget(tr("Library Browser"), this);
1360         dw->setObjectName("library");
1361         libraryWidget = new LibraryWidget(dw);//WAS:, "Library");
1362         libraryWidget->setActionHandler(actionHandler);
1363         libraryWidget->setFocusPolicy(Qt::NoFocus);
1364         connect(libraryWidget, SIGNAL(escape()), this, SLOT(slotFocus()));
1365 #warning "!!!"
1366 //      connect(this, SIGNAL(windowsChanged(bool)), (QObject *)libraryWidget->bInsert, SLOT(setEnabled(bool)));
1367         dw->setWidget(libraryWidget);
1368         dw->resize(240, 400);
1369 #warning "following three lines commented out..."
1370 //      dw->setResizeEnabled(true);
1371 //      dw->setCloseMode(Q3DockWindow::Always);
1372 //      dw->setCaption(tr("Library Browser"));
1373 //not sure how to fix this one
1374 #warning "QMainWindow::addDockWidget: invalid 'area' argument"
1375 //      addDockWidget(Qt::NoDockWidgetArea, dw);
1376 //This works, but sux
1377         addDockWidget(Qt::RightDockWidgetArea, dw);
1378         libraryDockWindow = dw;
1379 //      libraryDockWindow->hide();
1380
1381         DEBUG->print("  command widget..");
1382 //      dw = new QDockWidget(QDockWidget::InDock, this, "Command");
1383         dw = new QDockWidget(tr("Command line"), this);
1384         dw->setObjectName("command");
1385         commandWidget = new CommandWidget(dw);//WAS:, "Command");
1386         commandWidget->setActionHandler(actionHandler);
1387 //      commandWidget->redirectStderr();
1388 //      std::cerr << "Ready.\n";
1389 //      commandWidget->processStderr();
1390         connect(this, SIGNAL(windowsChanged(bool)), commandWidget, SLOT(setEnabled(bool)));
1391         dw->setWidget(commandWidget);
1392 #warning "following four lines commented out..."
1393 //      dw->setFixedExtentHeight(45);
1394 //      dw->setResizeEnabled(true);
1395 //      dw->setCloseMode(QDockWidget::Always);
1396 //      dw->setCaption(tr("Command line"));
1397         commandDockWindow = dw;
1398         addDockWidget(Qt::BottomDockWidgetArea, dw);
1399
1400         DEBUG->print("  done");
1401 }
1402
1403 /**
1404  * Goes back to the previous menu or one step in the current action.
1405  */
1406 void ApplicationWindow::slotBack()
1407 {
1408         GraphicView * graphicView = getGraphicView();
1409
1410         if (graphicView)
1411                 graphicView->back();
1412         else
1413         {
1414                 if (cadToolBar)
1415                         cadToolBar->showToolBar(RS2::ToolBarMain);
1416         }
1417 }
1418
1419 /**
1420  * Goes one step further in the current action.
1421  */
1422 void ApplicationWindow::slotEnter()
1423 {
1424         if (!commandWidget || !commandWidget->checkFocus())
1425         {
1426                 if (cadToolBar)
1427                         cadToolBar->forceNext();
1428                 else
1429                 {
1430                         GraphicView * graphicView = getGraphicView();
1431
1432                         if (graphicView)
1433                                 graphicView->enter();
1434                 }
1435         }
1436 }
1437
1438 /**
1439  * Sets the keyboard focus on the command line.
1440  */
1441 void ApplicationWindow::slotFocusCommandLine()
1442 {
1443         if (commandWidget->isVisible())
1444                 commandWidget->setFocus();
1445 }
1446
1447 /**
1448  * Shows the given error on the command line.
1449  */
1450 void ApplicationWindow::slotError(const QString & msg)
1451 {
1452         commandWidget->appendHistory(msg);
1453 }
1454
1455 /**
1456  * Hands focus back to the application window. In the rare event of a escape
1457  * press from the layer widget (e.g after switching desktops in XP).
1458  */
1459 void ApplicationWindow::slotFocus()
1460 {
1461         setFocus();
1462 }
1463
1464 /**
1465  * Called when a document window was activated.
1466  */
1467 //void ApplicationWindow::slotWindowActivated(QMdiSubWindow * /*w*/)
1468 void ApplicationWindow::slotWindowActivated(QMdiSubWindow * sw)
1469 {
1470 //This passes in a QMdiSubWindow, so why don't we use it???
1471 // Now, we do. :-)
1472 //#warning "!!! ApplicationWindow::slotWindowActivated() ignores passed in value !!!"
1473         DEBUG->print("ApplicationWindow::slotWindowActivated begin");
1474
1475 //the following does: return (MDIWindow *)workspace->activeSubWindow();
1476 //which means the subwindow is NOT being activated!!!
1477 //      MDIWindow * m = getMDIWindow();
1478         MDIWindow * m = (MDIWindow *)sw;
1479         DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::slotWindowActivated m=%08X", m);
1480         DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::slotWindowActivated m->getDoc=%08X",
1481                 (m ? m->getDocument() : 0));
1482
1483         if (m && m->getDocument())
1484         {
1485                 //m->setWindowState(WindowMaximized);
1486
1487                 DEBUG->print("ApplicationWindow::slotWindowActivated: document: %d", m->getDocument()->getId());
1488
1489                 bool showByBlock = m->getDocument()->rtti() == RS2::EntityBlock;
1490                 layerWidget->setLayerList(m->getDocument()->getLayerList(), showByBlock);
1491                 coordinateWidget->setGraphic(m->GetDrawing());
1492
1493 #ifdef RS_CAM
1494                 simulationControls->setGraphicView(m->getGraphicView());
1495 #endif
1496
1497                 // Only graphics show blocks. (blocks don't)
1498 //              if (m->getDocument()->rtti() == RS2::EntityDrawing)
1499 //                      blockWidget->setBlockList(m->getDocument()->getBlockList());
1500 //              else
1501 //                      blockWidget->setBlockList(NULL);
1502                 blockWidget->setBlockList(m->getDocument()->rtti() == RS2::EntityDrawing
1503                         ? m->getDocument()->getBlockList() : NULL);
1504
1505                 // Update all inserts in this graphic (blocks might have changed):
1506                 m->getDocument()->updateInserts();
1507                 m->getGraphicView()->redraw();
1508
1509                 // set snapmode from snapping menu
1510                 actionHandler->updateSnapMode();
1511
1512                 // set pen from pen toolbar
1513                 slotPenChanged(penToolBar->getPen());
1514
1515                 // update toggle button status:
1516                 if (m->GetDrawing())
1517                 {
1518 //This is odd... why do this when you can just call the function directly? It's
1519 //IN this class after all...
1520 //                      emit(gridChanged(m->GetDrawing()->isGridOn()));
1521 //                      emit(printPreviewChanged(m->getGraphicView()->isPrintPreview()));
1522                         actionViewGrid->setChecked(m->GetDrawing()->isGridOn());
1523                         actionFilePrintPreview->setChecked(m->getGraphicView()->isPrintPreview());
1524                 }
1525         }
1526
1527 //This works, but for some reason after this function is over, the subwindow is no
1528 //longer activated. Need to find out why.
1529 //OK, I can see that the workspace isn't getting this window as activated or current.
1530 //Which means that something is definitely wrong here...
1531
1532 //Seems to work now.
1533 //#warning "This is failing... !!! FIX !!!"
1534 printf("slotWindowActivated(QMdiSubWindow *): m=%08X, m->getDocument()=%08X...\n", (uint)m, (uint)(m ? m->getDocument() : 0));
1535 printf("slotWindowActivated(QMdiSubWindow *): activeWindow=%08X...\n", (uint)workspace->activeSubWindow());
1536 printf("slotWindowActivated(QMdiSubWindow *): currentWindow=%08X...\n", (uint)workspace->currentSubWindow());
1537 // slotWindowActivated(QMdiSubWindow * /*w*/): m=00000000, m->getDocument()=00000000...
1538
1539         // Disable/Enable menu and toolbar items
1540 //This is odd... why do this when you can just call the function directly? It's
1541 //IN this class after all...
1542         emit(windowsChanged(m != NULL && m->getDocument() != NULL));
1543
1544         DEBUG->print("ApplicationWindow::slotWindowActivated end");
1545 }
1546
1547 /**
1548  * Called when the menu 'windows' is about to be shown.
1549  * This is used to update the window list in the menu.
1550  */
1551 void ApplicationWindow::slotWindowsMenuAboutToShow()
1552 {
1553         DEBUG->print("ApplicationWindow::slotWindowsMenuAboutToShow");
1554
1555         windowsMenu->clear();
1556 #if 0
1557         int cascadeId = windowsMenu->insertItem(tr("&Cascade"), workspace, SLOT(cascade()));
1558         int tileId = windowsMenu->insertItem(tr("&Tile"), this, SLOT(slotTileVertical()));
1559         int horTileId = windowsMenu->insertItem(tr("Tile &Horizontally"), this, SLOT(slotTileHorizontal()));
1560
1561         if (workspace->subWindowList().isEmpty())
1562         {
1563                 windowsMenu->setItemEnabled(cascadeId, false);
1564                 windowsMenu->setItemEnabled(tileId, false);
1565                 windowsMenu->setItemEnabled(horTileId, false);
1566         }
1567
1568         windowsMenu->insertSeparator();
1569 #else
1570 #warning "!!! Qt4 implementation of insertItem is vastly different from Qt3--FIX !!!"
1571 #endif
1572         QList<QMdiSubWindow *> windows = workspace->subWindowList();
1573 //printf("ApplicationWindow::slotWindowsMenuAboutToShow(): workspace->activeSubWindow = %08X\n", workspace->activeSubWindow());
1574 //printf("ApplicationWindow::slotWindowsMenuAboutToShow(): workspace->currentSubWindow = %08X\n", workspace->currentSubWindow());
1575
1576 //#warning "Need to add window numbers underlined so can access windows via keyboard. !!! FIX !!!"
1577 //[DONE]
1578         for(int i=0; i<int(windows.count()); i++)
1579         {
1580 //printf("--> Windows.at(i) = %08X\n", windows.at(i));
1581 //              int id = windowsMenu->insertItem(windows.at(i)->caption(), this, SLOT(slotWindowsMenuActivated(int)));
1582 //For some reason the triggered() signal created here is type bool... Dunno why...
1583 //It's signalling using the QAction signal, which is type bool (checked or not).
1584 #if 1
1585                 QString actionName = QString("&%1 %2").arg(i + 1).arg(windows.at(i)->windowTitle());
1586 //              QAction * action = new QAction(windows.at(i)->windowTitle(), this);
1587                 QAction * action = new QAction(actionName, this);
1588                 action->setCheckable(true);
1589                 action->setData(i);
1590 //Neither of these work...
1591 //              action->setChecked(workspace->activeSubWindow() == windows.at(i));
1592                 action->setChecked(workspace->currentSubWindow() == windows.at(i));
1593                 windowsMenu->addAction(action);
1594                 connect(windowsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotWindowsMenuActivated(QAction *)));
1595 //      connect(blockWidget, SIGNAL(escape()), this, SLOT(slotFocus()));
1596 #else
1597                 QAction * id = windowsMenu->addAction(windows.at(i)->windowTitle(), this,
1598 //                      SLOT(slotWindowsMenuActivated(int)));
1599                         SLOT(slotWindowsMenuActivated(QAction *)));
1600 #warning "!!! !!!"
1601 //              windowsMenu->setItemParameter(id, i);
1602 //              windowsMenu->setItemChecked(id, workspace->activeSubWindow() == windows.at(i));
1603                 id->setData(i);
1604                 id->setChecked(workspace->activeSubWindow() == windows.at(i));
1605 #endif
1606         }
1607 }
1608
1609 /**
1610  * Called when the user selects a document window from the
1611  * window list.
1612  */
1613 void ApplicationWindow::slotWindowsMenuActivated(QAction * id)
1614 {
1615         DEBUG->print("ApplicationWindow::slotWindowsMenuActivated");
1616
1617 //      QMdiSubWindow * w = workspace->subWindowList().at(id);
1618         QMdiSubWindow * w = workspace->subWindowList().at(id->data().toInt());
1619 printf("ApplicationWindow::slotWindowsMenuActivated: QMdiSubWindow * w = %08X\n", (uint32_t)w);
1620
1621         if (w != NULL)
1622                 workspace->setActiveSubWindow(w);
1623 //              w->showMaximized();
1624 //              w->setFocus();
1625 printf("--> w is%s activated (activeSW=%08X)\n", (workspace->activeSubWindow() ? "" : " NOT"), (uint32_t)(workspace->activeSubWindow()));
1626 }
1627
1628 /**
1629  * Tiles MDI windows horizontally.
1630  */
1631 void ApplicationWindow::slotTileHorizontal()
1632 {
1633         DEBUG->print("ApplicationWindow::slotTileHorizontal");
1634
1635 #if 0
1636         // primitive horizontal tiling
1637         QWidgetList windows = workspace->windowList();
1638
1639         if (windows.count() == 0)
1640                 return;
1641
1642         int heightForEach = workspace->height() / windows.count();
1643         int y = 0;
1644
1645         for(int i=0; i<int(windows.count()); ++i)
1646         {
1647                 QWidget * window = windows.at(i);
1648
1649 #warning "Need to port to Qt4... !!! FIX !!!"
1650 #if 0
1651                 if (window->testWState(WState_Maximized))
1652                 {
1653                         // prevent flicker
1654                         window->hide();
1655                         window->showNormal();
1656                 }
1657 #endif
1658
1659                 int preferredHeight = window->minimumHeight() + window->parentWidget()->baseSize().height();
1660                 int actHeight = QMAX(heightForEach, preferredHeight);
1661
1662 //              window->parentWidget()->resize(workspace->width(), actHeight);
1663                 window->parentWidget()->setGeometry(0, y, workspace->width(), actHeight);
1664                 y += actHeight;
1665         }
1666 #else
1667         workspace->tileSubWindows();
1668 #endif
1669 }
1670
1671 /**
1672  * Tiles MDI windows vertically.
1673  */
1674 void ApplicationWindow::slotTileVertical()
1675 {
1676 #if 0
1677         workspace->tile();
1678
1679     /*
1680        QWidgetList windows = workspace->windowList();
1681        if (windows.count()==0) {
1682            return;
1683        }
1684
1685        //int heightForEach = workspace->height() / windows.count();
1686        //int y = 0;
1687        for (int i=0; i<int(windows.count()); ++i) {
1688            QWidget *window = windows.at(i);
1689         if (window->testWState(WState_Maximized)) {
1690                // prevent flicker
1691                window->hide();
1692                window->showNormal();
1693            }
1694            //int preferredHeight = window->minimumHeight()
1695            //                      + window->parentWidget()->baseSize().height();
1696            //int actHeight = QMAX(heightForEach, preferredHeight);
1697
1698            //window->parentWidget()->setGeometry(0, y,
1699            //                                    workspace->width(), actHeight);
1700            //window->parentWidget()->resize(window->parentWidget()->width(),
1701         //        window->parentWidget()->height());
1702            //window->resize(window->width(), window->height());
1703            //y+=actHeight;
1704        }
1705     */
1706 #else
1707         workspace->tileSubWindows();
1708 #endif
1709 }
1710
1711 /**
1712  * CAM
1713  */
1714 /*
1715 #ifdef RS_CAM
1716 void ApplicationWindow::slotCamExportAuto() {
1717     printf("CAM export..\n");
1718
1719     Document* d = getDocument();
1720     if (d!=NULL) {
1721         Drawing* graphic = (Drawing*)d;
1722
1723         RS_CamDialog dlg(graphic, this);
1724         dlg.exec();
1725     }
1726 }
1727 #endif
1728 */
1729
1730 /**
1731  * Called when something changed in the pen tool bar (e.g. color, width,
1732  * style).
1733  */
1734 void ApplicationWindow::slotPenChanged(Pen pen)
1735 {
1736         DEBUG->print("ApplicationWindow::slotPenChanged() begin");
1737         DEBUG->print("Setting active pen...");
1738         MDIWindow * m = getMDIWindow();
1739
1740         if (m != NULL)
1741                 m->slotPenChanged(pen);
1742
1743         DEBUG->print("ApplicationWindow::slotPenChanged() end");
1744 }
1745
1746 /**
1747  * Creates a new MDI window with the given document or a new document if 'doc'
1748  * is NULL.
1749  */
1750 MDIWindow * ApplicationWindow::slotFileNew(Document * doc/*= NULL*/)
1751 {
1752         DEBUG->print("ApplicationWindow::slotFileNew() begin");
1753
1754         static int id = 0;
1755         id++;
1756
1757         statusBar()->showMessage(tr("Creating new file..."));
1758
1759 //#warning "QWidget::setMinimumSize: (/QMdi::ControlLabel) Negative sizes (-1,-1) are not possible"
1760         DEBUG->print("  creating MDI window");
1761 //      MDIWindow * w = new MDIWindow(doc, workspace, 0, Qt::WA_DeleteOnClose);
1762         MDIWindow * w = new MDIWindow(doc, workspace, 0, Qt::SubWindow);
1763         w->setAttribute(Qt::WA_DeleteOnClose);
1764 //      w->setWindowState(WindowMaximized);
1765         connect(w, SIGNAL(signalClosing()), this, SLOT(slotFileClosing()));
1766
1767         if (w->getDocument()->rtti() == RS2::EntityBlock)
1768                 w->setWindowTitle(tr("Block '%1'").arg(((Block *)(w->getDocument()))->getName()));
1769         else
1770                 w->setWindowTitle(tr("Untitled Document %1").arg(id));
1771
1772         w->setWindowIcon(QIcon(":/res/document.png"));
1773
1774 #if 0
1775         // only graphics offer block lists, blocks don't
1776         DEBUG->print("  adding listeners");
1777         Drawing * graphic = w->getDocument()->getGraphic();
1778
1779         if (graphic != NULL)
1780         {
1781                 // Link the graphic's layer list to the pen tool bar
1782                 graphic->addLayerListListener(penToolBar);
1783                 // Link the layer list to the layer widget
1784                 graphic->addLayerListListener(layerWidget);
1785                 // Link the block list to the block widget
1786                 graphic->addBlockListListener(blockWidget);
1787         }
1788 #endif
1789
1790         // Link the dialog factory to the mouse widget:
1791         QG_DIALOGFACTORY->setMouseWidget(mouseWidget);
1792         // Link the dialog factory to the coordinate widget:
1793         QG_DIALOGFACTORY->setCoordinateWidget(coordinateWidget);
1794         QG_DIALOGFACTORY->setSelectionWidget(selectionWidget);
1795         // Link the dialog factory to the option widget:
1796 //      QG_DIALOGFACTORY->setOptionWidget(optionWidget);
1797         // Link the dialog factory to the cad tool bar:
1798         QG_DIALOGFACTORY->setCadToolBar(cadToolBar);
1799         // Link the dialog factory to the command widget:
1800         QG_DIALOGFACTORY->setCommandWidget(commandWidget);
1801         // Link the dialog factory to the main app window:
1802         QG_DIALOGFACTORY->setMainWindow(this);
1803
1804 #if 1 //bugfix for Qt3->4 conversion
1805         DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::slotFileNew: adding window to workspace...");
1806 //      workspace->addWindow(w);
1807         QMdiSubWindow * sw = workspace->addSubWindow(w);
1808 printf("MDIWindow=%08X, QMdiSubWindow=%08X\n", (uint)w, (uint)sw);
1809 #endif
1810
1811         DEBUG->print("  showing MDI window");
1812
1813 #if 0
1814 #warning "w->showMaximized() doesn't seem to do anything here..."
1815 //but then again, the subWindowList isn't going to be empty at this point either...
1816         if (workspace->subWindowList().isEmpty())
1817                 w->showMaximized();
1818         else
1819                 w->show();
1820 #else
1821         w->showMaximized();
1822 #warning "!!! SubWindow is not being activated !!!"
1823 //neither of these is working... Is the event being eaten somewhere???
1824 //      workspace->activateNextSubWindow();
1825 //      w->setFocus();
1826 //printf("--> ApplicationWindow::slotFileNew(): w %s focus...\n", (w->hasFocus() ? "has" : "DOES NOT HAVE"));
1827 #endif
1828 //neither of these work either
1829 //w->activateWindow();
1830 //w->setFocus();
1831 //w->activateWindow();
1832 //w->raise();
1833
1834 //not anymore... #warning "!!! Parameter to slotWindowActivated() is ignored !!!"
1835 //Hm, this should be called when the window is actually activated by the QMdiArea...
1836 //Not sure why this isn't happening...
1837 //      slotWindowActivated(w);
1838         statusBar()->showMessage(tr("New Drawing created."), 2000);
1839
1840         DEBUG->print("ApplicationWindow::slotFileNew() OK");
1841 //      setFocus();
1842
1843         return w;
1844 }
1845
1846 /**
1847  * Menu file -> open.
1848  */
1849 void ApplicationWindow::slotFileOpen()
1850 {
1851         DEBUG->print("ApplicationWindow::slotFileOpen()");
1852
1853         DEBUG->print("ApplicationWindow::slotFileOpen() 001");
1854         RS2::FormatType type = RS2::FormatUnknown;
1855         DEBUG->print("ApplicationWindow::slotFileOpen() 002");
1856         QString fileName = FileDialog::getOpenFileName(this, &type);
1857         DEBUG->print("ApplicationWindow::slotFileOpen() 003");
1858         slotFileOpen(fileName, type);
1859         DEBUG->print("ApplicationWindow::slotFileOpen(): OK");
1860 }
1861
1862 /**
1863  * Called when a recently opened file is chosen from the list in the
1864  * file menu.
1865  */
1866 void ApplicationWindow::slotFileOpenRecent(void)
1867 {
1868 #if 0
1869         DEBUG->print("ApplicationWindow::slotFileOpenRecent()");
1870
1871         statusBar()->showMessage(tr("Opening recent file..."));
1872         QString fileName = recentFiles->get(id);
1873
1874         if (fileName.endsWith(" (DXF 1)"))
1875                 slotFileOpen(fileName.left(fileName.length() - 8), RS2::FormatDXF1);
1876         else
1877                 slotFileOpen(fileName, RS2::FormatUnknown);
1878 #else
1879         statusBar()->showMessage(tr("Opening recent file..."));
1880
1881         QAction * action = qobject_cast<QAction *>(sender());
1882
1883         if (!action)
1884                 return;
1885
1886         QString fileName = action->data().toString();
1887
1888         if (fileName.endsWith(" (DXF 1)"))
1889                 slotFileOpen(fileName.left(fileName.length() - 8), RS2::FormatDXF1);
1890         else
1891                 slotFileOpen(fileName, RS2::FormatUnknown);
1892 #endif
1893 }
1894
1895 /**
1896  * Menu file -> open.
1897  */
1898 void ApplicationWindow::slotFileOpen(const QString & fileName, RS2::FormatType type)
1899 {
1900         DEBUG->print("ApplicationWindow::slotFileOpen(..)");
1901         QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1902
1903         if (!fileName.isEmpty())
1904         {
1905                 DEBUG->print("ApplicationWindow::slotFileOpen: creating new doc window");
1906                 // Create new document window:
1907                 MDIWindow * w = slotFileNew();
1908                 DEBUG->print("ApplicationWindow::slotFileOpen: linking layer list");
1909                 // link the layer widget to the new document:
1910                 layerWidget->setLayerList(w->getDocument()->getLayerList(), false);
1911                 // link the block widget to the new document:
1912                 blockWidget->setBlockList(w->getDocument()->getBlockList());
1913                 // link coordinate widget to graphic
1914                 coordinateWidget->setGraphic(w->GetDrawing());
1915 #ifdef RS_CAM
1916                 // link the layer widget to the new document:
1917                 simulationControls->setGraphicView(w->getGraphicView());
1918 #endif
1919                 DEBUG->print("ApplicationWindow::slotFileOpen: open file");
1920
1921                 // Open the file in the new view:
1922                 if (!w->slotFileOpen(fileName, type))
1923                 {
1924                         // error
1925                         QApplication::restoreOverrideCursor();
1926                         QMessageBox::information(this, QMessageBox::tr("Warning"),
1927                                 tr("Cannot open the file\n%1\nPlease check the permissions.") .arg(fileName), QMessageBox::Ok);
1928 //                      w->setForceClosing(true);
1929                         w->close();
1930                         return;
1931                 }
1932
1933                 DEBUG->print("ApplicationWindow::slotFileOpen: open file: OK");
1934                 DEBUG->print("ApplicationWindow::slotFileOpen: update recent file menu: 1");
1935
1936                 // update recent files menu:
1937                 if (type == RS2::FormatDXF1)
1938                         recentFiles->add(fileName + " (DXF 1)");
1939                 else
1940                         recentFiles->add(fileName);
1941
1942                 DEBUG->print("ApplicationWindow::slotFileOpen: update recent file menu: 2");
1943                 recentFiles->UpdateGUI();
1944                 DEBUG->print("ApplicationWindow::slotFileOpen: update recent file menu: OK");
1945                 DEBUG->print("ApplicationWindow::slotFileOpen: set caption");
1946                 // update caption:
1947                 w->setWindowTitle(fileName);
1948                 DEBUG->print("ApplicationWindow::slotFileOpen: set caption: OK");
1949                 DEBUG->print("ApplicationWindow::slotFileOpen: update coordinate widget");
1950                 // update coordinate widget format:
1951                 DIALOGFACTORY->updateCoordinateWidget(Vector(0.0, 0.0), Vector(0.0, 0.0), true);
1952                 DEBUG->print("ApplicationWindow::slotFileOpen: update coordinate widget: OK");
1953                 // Update the layer and block widgets (document just loaded may have some)
1954                 layerWidget->update();
1955                 blockWidget->update();
1956                 // show output of filter (if any):
1957                 QString message = tr("Loaded document: ") + fileName;
1958                 commandWidget->appendHistory(message);
1959                 statusBar()->showMessage(message, 2000);
1960         }
1961         else
1962         {
1963                 statusBar()->showMessage(tr("Opening aborted"), 2000);
1964         }
1965
1966         QApplication::restoreOverrideCursor();
1967         DEBUG->print("ApplicationWindow::slotFileOpen(..) OK");
1968 }
1969
1970 /**
1971  * Menu file -> save.
1972  */
1973 void ApplicationWindow::slotFileSave()
1974 {
1975         DEBUG->print("ApplicationWindow::slotFileSave()");
1976
1977         statusBar()->showMessage(tr("Saving drawing..."));
1978
1979         MDIWindow * w = getMDIWindow();
1980         QString name;
1981
1982         if (w != NULL)
1983         {
1984                 if (w->getDocument()->getFilename().isEmpty())
1985                         slotFileSaveAs();
1986                 else
1987                 {
1988                         bool cancelled;
1989
1990                         if (w->slotFileSave(cancelled))
1991                         {
1992                                 if (!cancelled)
1993                                 {
1994                                         name = w->getDocument()->getFilename();
1995                                         statusBar()->showMessage(tr("Saved drawing: %1").arg(name), 2000);
1996                                 }
1997                         }
1998                         else
1999                         {
2000                                 // error
2001                                 QMessageBox::information(this, QMessageBox::tr("Warning"),
2002                                         tr("Cannot save the file\n%1\nPlease check the permissions.")
2003                                         .arg(w->getDocument()->getFilename()), QMessageBox::Ok);
2004                         }
2005                 }
2006         }
2007 }
2008
2009 /**
2010  * Menu file -> save as.
2011  */
2012 void ApplicationWindow::slotFileSaveAs()
2013 {
2014         DEBUG->print("ApplicationWindow::slotFileSaveAs()");
2015
2016         statusBar()->showMessage(tr("Saving drawing under new filename..."));
2017
2018         MDIWindow * w = getMDIWindow();
2019         QString name;
2020
2021         if (w != NULL)
2022         {
2023                 bool cancelled;
2024
2025                 if (w->slotFileSaveAs(cancelled))
2026                 {
2027                         if (!cancelled)
2028                         {
2029                                 name = w->getDocument()->getFilename();
2030                                 recentFiles->add(name);
2031                                 w->setWindowTitle(name);
2032                         }
2033                 }
2034                 else
2035                 {
2036                         // error
2037                         QMessageBox::information(this, QMessageBox::tr("Warning"),
2038                                 tr("Cannot save the file\n%1\nPlease check the permissions.")
2039                                 .arg(w->getDocument()->getFilename()), QMessageBox::Ok);
2040                 }
2041         }
2042
2043 //      updateRecentFilesMenu();
2044         recentFiles->UpdateGUI();
2045
2046         QString message = tr("Saved drawing: %1").arg(name);
2047         statusBar()->showMessage(message, 2000);
2048         commandWidget->appendHistory(message);
2049 }
2050
2051 /**
2052  * Menu file -> export.
2053  */
2054 void ApplicationWindow::slotFileExport()
2055 {
2056         DEBUG->print("ApplicationWindow::slotFileExport()");
2057         statusBar()->showMessage(tr("Exporting drawing..."));
2058         MDIWindow * w = getMDIWindow();
2059
2060         if (w)
2061         {
2062                 QString fn;
2063                 // read default settings:
2064                 settings.beginGroup("Paths");
2065                 QString defDir = settings.value("ExportImage", SYSTEM->getHomeDir()).toString();
2066                 QString defFilter = settings.value("ExportImageFilter", "Portable Network Graphic (*.png)").toString();
2067                 settings.endGroup();
2068
2069                 bool cancel = false;
2070
2071 //              Q3FileDialog fileDlg(NULL, "", true);
2072                 QFileDialog fileDlg(NULL, "", "", "");
2073
2074 #warning "Need to port to Qt4... !!! FIX !!!"
2075 #if 0
2076                 Q3StrList f = QImageIO::outputFormats();
2077                 QStringList formats = QStringList::fromStrList(f);
2078                 QStringList filters;
2079                 //QString all = "";
2080
2081                 for (QStringList::Iterator it = formats.begin();
2082                                 it!=formats.end(); ++it)
2083                 {
2084                         QString st;
2085                         if ((*it)=="JPEG")
2086                         {
2087                                 st = QString("%1 (*.%2 *.jpg)")
2088                                                 .arg(QG_DialogFactory::extToFormat(*it))
2089                                                 .arg(QString(*it).lower());
2090                         }
2091                         else
2092                         {
2093                                 st = QString("%1 (*.%2)")
2094                                                 .arg(QG_DialogFactory::extToFormat(*it))
2095                                                 .arg(QString(*it).lower());
2096                         }
2097
2098                         filters.append(st);
2099
2100                         //if (!all.isEmpty()) {
2101                         //    all += " ";
2102                         //}
2103                         //all += QString("*.%1").arg(QString(*it).lower());
2104                 }
2105 #else
2106                 QStringList filters;
2107 #endif
2108
2109                 fileDlg.setFilters(filters);
2110 //              fileDlg.setMode(Q3FileDialog::AnyFile);
2111                 fileDlg.setFileMode(QFileDialog::AnyFile);
2112 //              fileDlg.setCaption(QObject::tr("Export Image"));
2113                 fileDlg.setWindowTitle(QObject::tr("Export Image"));
2114 //              fileDlg.setDir(defDir);
2115                 fileDlg.setDirectory(defDir);
2116                 fileDlg.selectNameFilter(defFilter);
2117
2118                 if (fileDlg.exec() == QDialog::Accepted)
2119                 {
2120 //                      fn = fileDlg.selectedFile();
2121                         QStringList files = fileDlg.selectedFiles();
2122
2123                         if (!files.isEmpty())
2124                                 fn = files[0];
2125
2126                         cancel = false;
2127                 }
2128                 else
2129                         cancel = true;
2130
2131                 // store new default settings:
2132                 if (!cancel)
2133                 {
2134                         settings.beginGroup("Paths");
2135 //                      settings.writeEntry("/ExportImage", QFileInfo(fn).dirPath(true));
2136                         settings.setValue("ExportImage", QFileInfo(fn).absolutePath());
2137                         settings.setValue("ExportImageFilter", fileDlg.selectedFilter());
2138                         settings.endGroup();
2139
2140                         // find out extension:
2141                         QString filter = fileDlg.selectedFilter();
2142                         QString format = "";
2143 //                      int i = filter.find("(*.");
2144                         int i = filter.indexOf("(*.");
2145
2146                         if (i != -1)
2147                         {
2148 //                              int i2 = filter.find(QRegExp("[) ]"), i);
2149                                 int i2 = filter.indexOf(QRegExp("[) ]"), i);
2150                                 format = filter.mid(i + 3, i2 - (i + 3));
2151                                 format = format.toUpper();
2152                         }
2153
2154                         // append extension to file:
2155                         if (!QFileInfo(fn).fileName().contains("."))
2156                                 fn.append("." + format.toLower());
2157
2158                         // show options dialog:
2159                         ImageOptionsDialog dlg(this);
2160                         dlg.setGraphicSize(w->GetDrawing()->getSize());
2161
2162                         if (dlg.exec())
2163                         {
2164                                 bool ret = slotFileExport(fn, format, dlg.getSize(), dlg.isBackgroundBlack());
2165
2166                                 if (ret)
2167                                 {
2168                                         QString message = tr("Exported: %1").arg(fn);
2169                                         statusBar()->showMessage(message, 2000);
2170                                         commandWidget->appendHistory(message);
2171                                 }
2172                         }
2173                 }
2174         }
2175 }
2176
2177 /**
2178  * Exports the drawing as a bitmap.
2179  *
2180  * @param name File name.
2181  * @param format File format (e.g. "png")
2182  * @param size Size of the bitmap in pixel
2183  * @param black true: Black background, false: white
2184  * @param bw true: black/white export, false: color
2185  */
2186 bool ApplicationWindow::slotFileExport(const QString & name, const QString & format, QSize size, bool black, bool bw)
2187 {
2188         MDIWindow * w = getMDIWindow();
2189
2190         if (!w)
2191         {
2192                 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFileExport: no window opened");
2193                 return false;
2194         }
2195
2196         Drawing * drawing = w->getDocument()->GetDrawing();
2197
2198         if (!drawing)
2199         {
2200                 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFileExport: no drawing");
2201                 return false;
2202         }
2203
2204         statusBar()->showMessage(tr("Exporting..."));
2205         QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
2206
2207         bool ret = false;
2208         QPixmap * buffer = new QPixmap(size);
2209 //      RS_PainterQt * painter = new RS_PainterQt(buffer);
2210         QPainter qpntr(buffer);
2211         PaintInterface * painter = new PaintInterface(&qpntr);
2212
2213         // black background:
2214         if (black)
2215 //              painter->setBackgroundColor(Color(0, 0, 0));
2216 //              qpntr.setBackgroundColor(Color(0, 0, 0));
2217                 qpntr.setBackground(QBrush(QColor(0, 0, 0)));
2218         // white background:
2219         else
2220 //              painter->setBackgroundColor(Color(255, 255, 255));
2221 //              qpntr.setBackgroundColor(Color(255, 255, 255));
2222                 qpntr.setBackground(QBrush(QColor(255, 255, 255)));
2223
2224         // black/white:
2225         if (bw)
2226                 painter->setDrawingMode(RS2::ModeBW);
2227
2228 //      painter->eraseRect(0, 0, size.width(), size.height());
2229         qpntr.eraseRect(0, 0, size.width(), size.height());
2230
2231         StaticGraphicView gv(size.width(), size.height(), painter);
2232
2233         if (black)
2234                 gv.setBackground(Color(0, 0, 0));
2235         else
2236                 gv.setBackground(Color(255, 255, 255));
2237
2238         gv.setContainer(drawing);
2239         gv.zoomAuto(false);
2240         gv.drawEntity(drawing, true);
2241
2242 #if 0
2243         QImageIO iio;
2244         QImage img;
2245         img = *buffer;
2246         iio.setImage(img);
2247         iio.setFileName(name);
2248         iio.setFormat(format);
2249
2250         if (iio.write())
2251         {
2252                 ret = true;
2253         }
2254 #else
2255 //      QImage image = buffer->toImage();
2256 //      QImageWriter writer;
2257 //      writer.setFileName(name);
2258 //      writer.setFormat(format.toAscii().data());
2259         QImageWriter writer(name, format.toAscii().data());
2260
2261 //      if (writer.write(image))
2262         if (writer.write(buffer->toImage()))
2263                 ret = true;
2264 #endif
2265
2266         QApplication::restoreOverrideCursor();
2267
2268         delete painter;
2269         delete buffer;
2270
2271         if (ret)
2272                 statusBar()->showMessage(tr("Export complete"), 2000);
2273         else
2274                 statusBar()->showMessage(tr("Export failed!"), 2000);
2275
2276         return ret;
2277 }
2278
2279 /**
2280  * Menu file -> close.
2281  */
2282 void ApplicationWindow::slotFileClose()
2283 {
2284         DEBUG->print("ApplicationWindow::slotFileClose()");
2285
2286         MDIWindow * m = getMDIWindow();
2287
2288         if (m)
2289 //              m->close(true);
2290                 m->close();
2291
2292 /*
2293         m = getMDIWindow();
2294     if (m!=NULL) {
2295                 //m->showMaximized();
2296                 m->setWindowState(WindowMaximized);
2297         }
2298 */
2299 }
2300
2301 /**
2302  * Called when a MDI window is actually about to close. Used to
2303  * detach widgets from the document.
2304  */
2305 void ApplicationWindow::slotFileClosing()
2306 {
2307         DEBUG->print("ApplicationWindow::slotFileClosing()");
2308
2309         DEBUG->print("detaching lists");
2310         layerWidget->setLayerList(NULL, false);
2311         blockWidget->setBlockList(NULL);
2312         coordinateWidget->setGraphic(NULL);
2313 #ifdef RS_CAM
2314         simulationControls->setGraphicView(NULL);
2315 #endif
2316 }
2317
2318 /**
2319  * Menu file -> print.
2320  */
2321 void ApplicationWindow::slotFilePrint()
2322 {
2323         DEBUG->print("ApplicationWindow::slotFilePrint()");
2324
2325         MDIWindow * w = getMDIWindow();
2326
2327         if (w == NULL)
2328         {
2329                 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFilePrint: no window opened");
2330                 return;
2331         }
2332
2333         Drawing * drawing = w->getDocument()->GetDrawing();
2334
2335         if (drawing == NULL)
2336         {
2337                 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFilePrint: no drawing");
2338                 return;
2339         }
2340
2341         statusBar()->showMessage(tr("Printing..."));
2342         QPrinter * printer = new QPrinter(QPrinter::HighResolution);
2343         bool landscape = false;
2344         printer->setPageSize(RS2::rsToQtPaperFormat(drawing->getPaperFormat(&landscape)));
2345
2346         if (landscape)
2347                 printer->setOrientation(QPrinter::Landscape);
2348         else
2349                 printer->setOrientation(QPrinter::Portrait);
2350
2351         settings.beginGroup("Print");
2352         printer->setOutputFileName(settings.value("FileName", "").toString());
2353         printer->setColorMode((QPrinter::ColorMode)settings.value("/ColorMode", (int)QPrinter::Color).toInt());
2354 #warning "!!! Need to port QPrinter::setOutputToFile() to Qt4 !!!"
2355 //      printer->setOutputToFile((bool)RS_SETTINGS->readNumEntry("/PrintToFile", 0));
2356         settings.endGroup();
2357
2358         // printer setup:
2359 //      if (printer->setup(this))
2360         QPrintDialog dialog(printer, this);
2361
2362         if (dialog.exec())
2363         {
2364                 //printer->setOutputToFile(true);
2365                 //printer->setOutputFileName(outputFile);
2366
2367                 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
2368                 printer->setFullPage(true);
2369 //Can call these functions directly from the QPaintDevice...
2370 //              Q3PaintDeviceMetrics metr(printer);
2371
2372 //              RS_PainterQt * painter = new RS_PainterQt(printer);
2373                 QPainter qpntr(printer);
2374                 PaintInterface * painter = new PaintInterface(&qpntr);
2375                 painter->setDrawingMode(w->getGraphicView()->getDrawingMode());
2376
2377 //              StaticGraphicView gv(metr.width(), metr.height(), painter);
2378                 StaticGraphicView gv(printer->width(), printer->height(), painter);
2379                 gv.setPrinting(true);
2380                 gv.setBorders(0, 0, 0, 0);
2381
2382 //              double fx = (double)metr.width() / metr.widthMM() * Units::getFactorToMM(graphic->getUnit());
2383 //              double fy = (double)metr.height() / metr.heightMM() * Units::getFactorToMM(graphic->getUnit());
2384                 double fx = (double)printer->width() / printer->widthMM() * Units::getFactorToMM(drawing->getUnit());
2385                 double fy = (double)printer->height() / printer->heightMM() * Units::getFactorToMM(drawing->getUnit());
2386                 double f = (fx + fy) / 2;
2387                 double scale = drawing->getPaperScale();
2388
2389                 gv.setOffset((int)(drawing->getPaperInsertionBase().x * f),
2390                         (int)(drawing->getPaperInsertionBase().y * f));
2391                 gv.setFactor(f * scale);
2392                 gv.setContainer(drawing);
2393                 gv.drawEntity(drawing, true);
2394
2395                 delete painter;
2396
2397                 settings.beginGroup("Print");
2398 #warning "!!! Need to port QPrinter::outputToFile() to Qt4 !!!"
2399 //              settings.writeEntry("/PrintToFile", (int)printer->outputToFile());
2400                 settings.setValue("ColorMode", (int)printer->colorMode());
2401                 settings.setValue("FileName", printer->outputFileName());
2402                 settings.endGroup();
2403                 QApplication::restoreOverrideCursor();
2404         }
2405
2406         delete printer;
2407
2408         statusBar()->showMessage(tr("Printing complete"), 2000);
2409 }
2410
2411 /**
2412  * Menu file -> print preview.
2413  */
2414 void ApplicationWindow::slotFilePrintPreview(bool on)
2415 {
2416         DEBUG->print("ApplicationWindow::slotFilePrintPreview()");
2417
2418         DEBUG->print("  creating MDI window");
2419         MDIWindow * parent = getMDIWindow();
2420
2421         if (!parent)
2422         {
2423                 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFilePrintPreview: no window opened");
2424                 return;
2425         }
2426
2427         // Close print preview:
2428         if (!on)
2429         {
2430                 DEBUG->print("ApplicationWindow::slotFilePrintPreview(): off");
2431
2432                 if (parent->getGraphicView()->isPrintPreview())
2433                 {
2434                         DEBUG->print("ApplicationWindow::slotFilePrintPreview(): close");
2435                         slotFileClose();
2436                 }
2437         }
2438         // Open print preview:
2439         else
2440         {
2441                 // look for an existing print preview:
2442                 MDIWindow * ppv = parent->getPrintPreview();
2443
2444                 if (ppv != NULL)
2445                 {
2446                         DEBUG->print("ApplicationWindow::slotFilePrintPreview(): show existing");
2447                         slotWindowActivated(ppv);
2448                         ppv->showNormal();
2449                 }
2450                 else
2451                 {
2452                         if (!parent->getGraphicView()->isPrintPreview())
2453                         {
2454                                 DEBUG->print("ApplicationWindow::slotFilePrintPreview(): create");
2455
2456                                 MDIWindow * w = new MDIWindow(parent->getDocument(), workspace, 0, Qt::SubWindow);
2457                                 w->setAttribute(Qt::WA_DeleteOnClose);
2458                                 parent->addChildWindow(w);
2459
2460 //                              w->setCaption(tr("Print preview for %1").arg(parent->caption()));
2461                                 w->setWindowTitle(tr("Print preview for %1").arg(parent->windowTitle()));
2462 //                              w->setIcon(qPixmapFromMimeSource("document.png"));
2463 //                              w->setWindowIcon(qPixmapFromMimeSource("document.png"));
2464                                 w->setWindowIcon(QIcon(":/res/document.png"));
2465                                 w->getGraphicView()->setPrintPreview(true);
2466                                 w->getGraphicView()->setBackground(Color(255, 255, 255));
2467                                 w->getGraphicView()->setDefaultAction(new ActionPrintPreview(*w->getDocument(), *w->getGraphicView()));
2468
2469                                 // Only drawings offer block lists; blocks themselves don't
2470 //                              DEBUG->print("  adding listeners");
2471                                 Drawing * drawing = w->getDocument()->GetDrawing();
2472
2473                                 if (drawing)
2474                                 {
2475                                         // Center by default:
2476                                         drawing->centerToPage();
2477                                 }
2478
2479                                 // Link the graphic view to the mouse widget:
2480                                 QG_DIALOGFACTORY->setMouseWidget(mouseWidget);
2481                                 // Link the graphic view to the coordinate widget:
2482                                 QG_DIALOGFACTORY->setCoordinateWidget(coordinateWidget);
2483                                 QG_DIALOGFACTORY->setSelectionWidget(selectionWidget);
2484                                 // Link the graphic view to the option widget:
2485                                 //QG_DIALOGFACTORY->setOptionWidget(optionWidget);
2486                                 // Link the graphic view to the cad tool bar:
2487                                 QG_DIALOGFACTORY->setCadToolBar(cadToolBar);
2488                                 // Link the graphic view to the command widget:
2489                                 QG_DIALOGFACTORY->setCommandWidget(commandWidget);
2490
2491                                 DEBUG->print("  showing MDI window");
2492
2493                                 if (workspace->subWindowList().isEmpty())
2494                                         w->showMaximized();
2495                                 else
2496                                         w->show();
2497
2498                                 w->getGraphicView()->zoomPage();
2499                                 setFocus();
2500
2501                                 slotWindowActivated(w);
2502                         }
2503                 }
2504         }
2505 }
2506
2507 /**
2508  * Menu file -> quit.
2509  */
2510 void ApplicationWindow::slotFileQuit()
2511 {
2512         DEBUG->print("ApplicationWindow::slotFileQuit()");
2513
2514         statusBar()->showMessage(tr("Exiting application..."));
2515
2516         if (QueryExit())
2517                 qApp->exit(0);
2518 }
2519
2520 /**
2521  * Shows/hides the grid.
2522  *
2523  * @param toggle true: show, false: hide.
2524  */
2525 void ApplicationWindow::slotViewGrid(bool toggle)
2526 {
2527         DEBUG->print("ApplicationWindow::slotViewGrid()");
2528
2529         MDIWindow * m = getMDIWindow();
2530
2531         if (m != NULL)
2532         {
2533                 Drawing * d = m->GetDrawing();
2534
2535                 if (d != NULL)
2536                         d->setGridOn(toggle);
2537         }
2538
2539         updateGrids();
2540         redrawAll();
2541
2542         DEBUG->print("ApplicationWindow::slotViewGrid() OK");
2543 }
2544
2545 /**
2546  * Enables/disables draft mode.
2547  *
2548  * @param toggle true: enable, false: disable.
2549  */
2550 void ApplicationWindow::slotViewDraft(bool toggle)
2551 {
2552         DEBUG->print("ApplicationWindow::slotViewDraft()");
2553
2554         settings.beginGroup("Appearance");
2555         settings.setValue("DraftMode", toggle);
2556         settings.endGroup();
2557
2558         redrawAll();
2559 }
2560
2561 /**
2562  * Redraws all MDI windows.
2563  */
2564 void ApplicationWindow::redrawAll()
2565 {
2566         if (workspace == NULL)
2567                 return;
2568
2569         QList<QMdiSubWindow *> windows = workspace->subWindowList();
2570
2571         for(int i=0; i<windows.count(); i++)
2572         {
2573                 QG_GraphicView * gv = ((MDIWindow *)windows.at(i))->getGraphicView();
2574
2575                 if (gv)
2576                         gv->redraw();
2577         }
2578 }
2579
2580 /**
2581  * Updates all grids of all graphic views.
2582  */
2583 void ApplicationWindow::updateGrids()
2584 {
2585         if (workspace == NULL)
2586                 return;
2587
2588         QList<QMdiSubWindow *> windows = workspace->subWindowList();
2589
2590         for(int i=0; i<windows.count(); i++)
2591         {
2592                 QG_GraphicView * gv = ((MDIWindow *)windows.at(i))->getGraphicView();
2593
2594                 if (gv)
2595                         gv->updateGrid();
2596         }
2597 }
2598
2599 /**
2600  * Shows / hides the status bar.
2601  *
2602  * @param showSB true: show, false: hide.
2603  */
2604 void ApplicationWindow::slotViewStatusBar(bool showSB)
2605 {
2606         DEBUG->print("ApplicationWindow::slotViewStatusBar()");
2607
2608         if (showSB)
2609                 statusBar()->show();
2610         else
2611                 statusBar()->hide();
2612 }
2613
2614 /**
2615  * Shows the dialog for general application preferences.
2616  */
2617 void ApplicationWindow::slotOptionsGeneral()
2618 {
2619         DIALOGFACTORY->requestOptionsGeneralDialog();
2620
2621         // Update background color of all open drawings:
2622         settings.beginGroup("Appearance");
2623         QColor color(settings.value("BackgroundColor", "#000000").toString());
2624         QColor gridColor(settings.value("GridColor", "Gray").toString());
2625         QColor metaGridColor(settings.value("MetaGridColor", "Darkgray").toString());
2626         QColor selectedColor(settings.value("SelectedColor", "#A54747").toString());
2627         QColor highlightedColor(settings.value("HighlightedColor", "#739373").toString());
2628         settings.endGroup();
2629
2630         QList<QMdiSubWindow *> windows = workspace->subWindowList();
2631
2632         for(int i=0; i<int(windows.count()); i++)
2633         {
2634                 MDIWindow * m = (MDIWindow *)windows.at(i);
2635
2636                 if (m)
2637                 {
2638                         QG_GraphicView * gv = m->getGraphicView();
2639
2640                         if (gv)
2641                         {
2642                                 gv->setBackground(color);
2643                                 gv->setGridColor(gridColor);
2644                                 gv->setMetaGridColor(metaGridColor);
2645                                 gv->setSelectedColor(selectedColor);
2646                                 gv->setHighlightedColor(highlightedColor);
2647                                 gv->updateGrid();
2648                                 gv->redraw();
2649                         }
2650                 }
2651         }
2652 }
2653
2654 /**
2655  * Menu script -> show ide
2656  */
2657 void ApplicationWindow::slotScriptOpenIDE()
2658 {
2659 #ifdef SCRIPTING
2660         scripter->openIDE();
2661 #endif
2662 }
2663
2664 /**
2665  * Menu script -> run
2666  */
2667 void ApplicationWindow::slotScriptRun()
2668 {
2669 #ifdef SCRIPTING
2670         scripter->runScript();
2671 #endif
2672 }
2673
2674 /**
2675  * Menu help -> about.
2676  */
2677 void ApplicationWindow::slotHelpAbout()
2678 {
2679         DEBUG->print("ApplicationWindow::slotHelpAbout()");
2680 #if 0
2681         QStringList modules;
2682
2683 #ifdef RS_CAM
2684         modules += "CAM";
2685 #endif
2686
2687 #ifdef SCRIPTING
2688         modules += "Scripting";
2689 #endif
2690
2691         QString modulesString;
2692
2693         if (!modules.empty())
2694                 modulesString = modules.join(", ");
2695         else
2696                 modulesString = tr("None");
2697 #endif
2698
2699         QMessageBox box(this);
2700         box.setWindowTitle(tr("About..."));
2701         box.setText(QString("<center>")
2702                 + "<h2>Architektonas</h2>"
2703                 + tr("Version: %1").arg("1.0.0") + "<br>"
2704                 + tr("Date: %1").arg(__DATE__) + "<br>"
2705                 + QString("&copy; 2010 Underground Software,<br>James Hammons") + "<br>"
2706                 + QString("Portions &copy; 2001-2003 RibbonSoft") + "<br>"
2707                 + QString("</center>")
2708                 );
2709 #ifndef QC_ABOUT_HEADER
2710 #warning "Failure..."
2711 //      box.setIcon(qPixmapFromMimeSource(QC_APP_ICON));
2712         box.setFixedWidth(340);
2713         box.setFixedHeight(250);
2714 #endif
2715         box.exec();
2716 }
2717
2718 /**
2719  * Menu help -> help.
2720  */
2721 void ApplicationWindow::slotHelpManual()
2722 {
2723 #warning "No help system ported to Qt4... !!! FIX !!!"
2724 #if 0
2725     DEBUG->print("ApplicationWindow::slotHelpManual()");
2726
2727     if (assistant == NULL)
2728         {
2729         DEBUG->print("ApplicationWindow::slotHelpManual(): appdir: %s", SYSTEM->getAppDir().toLatin1().data());
2730         DEBUG->print("ApplicationWindow::slotHelpManual(): appdir: %s", SYSTEM->getAppDir().toLatin1().data());
2731         assistant = new QAssistantClient(SYSTEM->getAppDir()+"/bin", this);
2732                 connect(assistant, SIGNAL(error(const QString&)), this, SLOT(slotError(const QString&)));
2733         QStringList args;
2734         args << "-profile";
2735         args << QDir::convertSeparators(SYSTEM->getDocPath() + "/qcaddoc.adp");
2736 //        args << QString("doc") + QDir::separator() + QString("qcaddoc.adp");
2737
2738 #if QT_VERSION>=0x030200
2739         assistant->setArguments(args);
2740 #endif
2741     }
2742     assistant->openAssistant();
2743     //assistant->showPage("index.html");
2744 #endif
2745 }
2746
2747 /**
2748  * Testing function.
2749  */
2750 void ApplicationWindow::slotTestDumpEntities(EntityContainer * d)
2751 {
2752         DEBUG->print("ApplicationWindow::slotTestDumpEntities()");
2753         static int level = 0;
2754         std::ofstream dumpFile;
2755
2756         if (d==NULL)
2757         {
2758                 d = getDocument();
2759                 dumpFile.open("debug_entities.html");
2760                 level = 0;
2761         }
2762         else
2763         {
2764                 dumpFile.open("debug_entities.html", std::ios::app);
2765                 level++;
2766         }
2767
2768         if (d!=NULL)
2769         {
2770                 if (level==0)
2771                 {
2772                         dumpFile << "<html>\n";
2773                         dumpFile << "<body>\n";
2774                 }
2775
2776                 for (Entity* e=d->firstEntity();
2777                                 e!=NULL;
2778                                 e=d->nextEntity())
2779                 {
2780
2781                         dumpFile << "<table border=\"1\">\n";
2782                         dumpFile << "<tr><td>Entity: " << e->getId()
2783                         << "</td></tr>\n";
2784
2785                         dumpFile
2786                         << "<tr><td><table><tr>"
2787                         << "<td>VIS:" << e->isVisible() << "</td>"
2788                         << "<td>UND:" << e->isUndone() << "</td>"
2789                         << "<td>SEL:" << e->isSelected() << "</td>"
2790                         << "<td>TMP:" << e->getFlag(RS2::FlagTemp) << "</td>";
2791                         QString lay = "NULL";
2792                         if (e->getLayer()!=NULL) {
2793                                 lay = e->getLayer()->getName();
2794                         }
2795                         dumpFile
2796 //fail            << "<td>Layer: " << lay << "</td>"
2797                         << "<td>Width: " << (int)e->getPen(false).getWidth() << "</td>"
2798                         << "<td>Parent: " << e->getParent()->getId() << "</td>"
2799                         << "</tr></table>";
2800
2801                         dumpFile
2802                         << "<tr><td>\n";
2803
2804                         switch (e->rtti())
2805                         {
2806                         case RS2::EntityPoint:
2807                         {
2808                                         Point* p = (Point*)e;
2809                                         dumpFile
2810                                         << "<table><tr><td>"
2811                                         << "<b>Point:</b>"
2812                                         << "</td></tr>";
2813                                         dumpFile
2814                                         << "<tr>"
2815                                         << "<td>"
2816                                         << p->getPos()
2817                                         << "</td>"
2818                                         << "</tr></table>";
2819                                 }
2820                                 break;
2821
2822                         case RS2::EntityLine:
2823                         {
2824                                         Line* l = (Line*)e;
2825                                         dumpFile
2826                                         << "<table><tr><td>"
2827                                         << "<b>Line:</b>"
2828                                         << "</td></tr>";
2829                                         dumpFile
2830                                         << "<tr>"
2831                                         << "<td>"
2832                                         << l->getStartpoint()
2833                                         << "</td>"
2834                                         << "<td>"
2835                                         << l->getEndpoint()
2836                                         << "</td>"
2837                                         << "</tr></table>";
2838                                 }
2839                                 break;
2840
2841                         case RS2::EntityArc: {
2842                                         Arc* a = (Arc*)e;
2843                                         dumpFile
2844                                         << "<table><tr><td>"
2845                                         << "<b>Arc:</b>"
2846                                         << "</td></tr>";
2847                                         dumpFile
2848                                         << "<tr>"
2849                                         << "<td>Center: "
2850                                         << a->getCenter()
2851                                         << "</td>"
2852                                         << "<td>Radius: "
2853                                         << a->getRadius()
2854                                         << "</td>"
2855                                         << "<td>Angle 1: "
2856                                         << a->getAngle1()
2857                                         << "</td>"
2858                                         << "<td>Angle 2: "
2859                                         << a->getAngle2()
2860                                         << "</td>"
2861                                         << "<td>Startpoint: "
2862                                         << a->getStartpoint()
2863                                         << "</td>"
2864                                         << "<td>Endpoint: "
2865                                         << a->getEndpoint()
2866                                         << "</td>"
2867                                         << "<td>reversed: "
2868                                         << (int)a->isReversed()
2869                                         << "</td>"
2870                                         << "</tr></table>";
2871                                 }
2872                                 break;
2873
2874                         case RS2::EntityCircle: {
2875                                         Circle* c = (Circle*)e;
2876                                         dumpFile
2877                                         << "<table><tr><td>"
2878                                         << "<b>Circle:</b>"
2879                                         << "</td></tr>";
2880                                         dumpFile
2881                                         << "<tr>"
2882                                         << "<td>Center: "
2883                                         << c->getCenter()
2884                                         << "</td>"
2885                                         << "<td>Radius: "
2886                                         << c->getRadius()
2887                                         << "</td>"
2888                                         << "</tr></table>";
2889                                 }
2890                                 break;
2891
2892                         case RS2::EntityDimAligned: {
2893                                         DimAligned* d = (DimAligned*)e;
2894                                         dumpFile
2895                                         << "<table><tr><td>"
2896                                         << "<b>Dimension / Aligned:</b>"
2897                                         << "</td></tr>";
2898                                         dumpFile
2899                                         << "<tr>"
2900                                         << "<td>"
2901                                         << d->getDefinitionPoint()
2902                                         << "</td>"
2903                                         << "<td>"
2904                                         << d->getExtensionPoint1()
2905                                         << "</td>"
2906                                         << "<td>"
2907                                         << d->getExtensionPoint2()
2908                                         << "</td>"
2909                                         << "<td>Text: "
2910                                         << d->getText().toLatin1().data()
2911                                         << "</td>"
2912                                         << "<td>Label: "
2913                                         << d->getLabel().toLatin1().data()
2914                                         << "</td>"
2915                                         << "</tr></table>";
2916                                 }
2917                                 break;
2918
2919                         case RS2::EntityDimLinear:
2920                         {
2921                                         DimLinear* d = (DimLinear*)e;
2922                                         dumpFile
2923                                         << "<table><tr><td>"
2924                                         << "<b>Dimension / Linear:</b>"
2925                                         << "</td></tr>";
2926                                         dumpFile
2927                                         << "<tr>"
2928                                         << "<td>"
2929                                         << d->getDefinitionPoint()
2930                                         << "</td>"
2931                                         << "<td>"
2932                                         << d->getExtensionPoint1()
2933                                         << "</td>"
2934                                         << "<td>"
2935                                         << d->getExtensionPoint2()
2936                                         << "</td>"
2937                                         << "<td>Text: "
2938 //fail                    << d->getText()
2939                                         << "</td>"
2940                                         << "<td>Label: "
2941 //fail                    << d->getLabel()
2942                                         << "</td>"
2943                                         << "</tr></table>";
2944                                 }
2945                                 break;
2946
2947                         case RS2::EntityInsert: {
2948                                         Insert* i = (Insert*)e;
2949                                         dumpFile
2950                                         << "<table><tr><td>"
2951                                         << "<b>Insert:</b>"
2952                                         << "</td></tr>";
2953                                         dumpFile
2954                                         << "<tr>"
2955                                         << "<td>Insertion point:"
2956                                         << i->getInsertionPoint()
2957                                         << "</td>"
2958                                         << "</tr></table>";
2959                                 }
2960                                 break;
2961
2962                         case RS2::EntityText: {
2963                                         Text* t = (Text*)e;
2964                                         dumpFile
2965                                         << "<table><tr><td>"
2966                                         << "<b>Text:</b>"
2967                                         << "</td></tr>";
2968                                         dumpFile
2969                                         << "<tr>"
2970                                         << "<td>Text:"
2971                                         << t->getText().toLatin1().data()
2972                                         << "</td>"
2973                                         << "<td>Height:"
2974                                         << t->getHeight()
2975                                         << "</td>"
2976                                         << "</tr></table>";
2977                                 }
2978                                 break;
2979
2980                         case RS2::EntityHatch: {
2981                                         Hatch* h = (Hatch*)e;
2982                                         dumpFile
2983                                         << "<table><tr><td>"
2984                                         << "<b>Hatch:</b>"
2985                                         << "</td></tr>";
2986                                         dumpFile
2987                                         << "<tr>"
2988                                         << "<td>Pattern:"
2989                                         << h->getPattern().toLatin1().data()
2990                                         << "</td>"
2991                                         << "<td>Scale:"
2992                                         << h->getScale()
2993                                         << "</td>"
2994                                         << "<td>Solid:"
2995                                         << (int)h->isSolid()
2996                                         << "</td>"
2997                                         << "</tr></table>";
2998                                 }
2999                                 break;
3000
3001                         default:
3002                                 dumpFile
3003                                 << "<tr><td>"
3004                                 << "<b>Unknown Entity: " << e->rtti() << "</b>"
3005                                 << "</td></tr>";
3006                                 break;
3007                         }
3008
3009                         if (e->isContainer() || e->rtti()==RS2::EntityHatch) {
3010                                 EntityContainer* ec = (EntityContainer*)e;
3011                                 dumpFile << "<table><tr><td valign=\"top\">&nbsp;&nbsp;&nbsp;&nbsp;Contents:</td><td>\n";
3012                                 dumpFile.close();
3013                                 slotTestDumpEntities(ec);
3014                                 dumpFile.open("debug_entities.html", std::ios::app);
3015                                 dumpFile << "</td></tr></table>\n";
3016                         }
3017
3018                         dumpFile
3019                         << "</td></tr>"
3020                         << "</table>\n"
3021                         << "<br><br>";
3022                 }
3023
3024                 if (level==0) {
3025                         dumpFile << "</body>\n";
3026                         dumpFile << "</html>\n";
3027                 } else {
3028                         level--;
3029                 }
3030         }
3031 }
3032
3033 /**
3034  * Testing function.
3035  */
3036 void ApplicationWindow::slotTestDumpUndo()
3037 {
3038         DEBUG->print("ApplicationWindow::slotTestDumpUndo()");
3039
3040         Document * d = getDocument();
3041
3042         if (d != NULL)
3043         {
3044                 std::cout << *(Undo*)d;
3045                 std::cout << std::endl;
3046         }
3047 }
3048
3049 /**
3050  * Testing function.
3051  */
3052 void ApplicationWindow::slotTestUpdateInserts()
3053 {
3054         DEBUG->print("ApplicationWindow::slotTestUpdateInserts()");
3055
3056         Document * d = getDocument();
3057
3058         if (d != NULL)
3059                 d->updateInserts();
3060 }
3061
3062 /**
3063  * Testing function.
3064  */
3065 void ApplicationWindow::slotTestDrawFreehand()
3066 {
3067         DEBUG->print("ApplicationWindow::slotTestDrawFreehand()");
3068
3069     //Drawing* g = document->getMarking();
3070     /*
3071
3072        ActionDrawLineFree* action =
3073           new ActionDrawLineFree(*document->getGraphic(),
3074                                     *graphicView);
3075
3076        for (int i=0; i<100; ++i) {
3077
3078            int posx = (random()%600);
3079            int posy = (random()%400);
3080
3081            //RS_MouseEvent rsm1(posx, posy, LEFT);
3082         RS_MouseEvent rsm1(QEvent::MouseButtonPress,
3083                            QPoint(posx,posy),
3084                            RS2::LeftButton,
3085                            RS2::LeftButton);
3086            action->mousePressEvent(&rsm1);
3087
3088            int speedx = 0;
3089            int speedy = 0;
3090
3091            for (int k=0; k<100; ++k) {
3092                int accx = (random()%40)-20;
3093                int accy = (random()%40)-20;
3094
3095                speedx+=accx;
3096                speedy+=accy;
3097
3098                posx+=speedx;
3099                posy+=speedy;
3100
3101                //RS_MouseEvent rsm2(posx, posy, LEFT);
3102
3103             RS_MouseEvent rsm2(QEvent::MouseMove,
3104                            QPoint(posx,posy),
3105                            RS2::LeftButton,
3106                            RS2::LeftButton);
3107                action->mouseMoveEvent(&rsm2);
3108            }
3109
3110            action->mouseReleaseEvent(NULL);
3111
3112            slotFileSave();
3113        }
3114
3115        delete action;
3116     */
3117 }
3118
3119 /**
3120  * Testing function.
3121  */
3122 void ApplicationWindow::slotTestInsertBlock()
3123 {
3124         DEBUG->print("ApplicationWindow::slotTestInsertBlock()");
3125
3126         Document * d = getDocument();
3127
3128         if (d != NULL && d->rtti() == RS2::EntityDrawing)
3129         {
3130                 Drawing * graphic = (Drawing *)d;
3131
3132                 if (graphic == NULL)
3133                         return;
3134
3135                 graphic->addLayer(new Layer("default"));
3136                 Block * block = new Block(graphic, BlockData("debugblock", Vector(0.0, 0.0), true));
3137
3138                 Line * line;
3139                 Arc * arc;
3140                 Circle * circle;
3141
3142                 // Add one red line:
3143                 line = new Line(block, LineData(Vector(0.0, 0.0), Vector(50.0, 0.0)));
3144                 line->setLayerToActive();
3145                 line->setPen(Pen(Color(255, 0, 0), RS2::Width01, RS2::SolidLine));
3146                 block->addEntity(line);
3147
3148                 // Add one line with attributes from block:
3149                 line = new Line(block, LineData(Vector(50.0, 0.0), Vector(50.0, 50.0)));
3150                 line->setPen(Pen(Color(RS2::FlagByBlock), RS2::WidthByBlock, RS2::LineByBlock));
3151                 block->addEntity(line);
3152
3153                 // Add one arc with attributes from block:
3154                 ArcData d(Vector(50.0, 0.0), 50.0, M_PI / 2.0, M_PI, false);
3155                 arc = new Arc(block, d);
3156                 arc->setPen(Pen(Color(RS2::FlagByBlock), RS2::WidthByBlock, RS2::LineByBlock));
3157                 block->addEntity(arc);
3158
3159                 // Add one blue circle:
3160                 CircleData circleData(Vector(20.0, 15.0), 12.5);
3161                 circle = new Circle(block, circleData);
3162                 circle->setLayerToActive();
3163                 circle->setPen(Pen(Color(0, 0, 255), RS2::Width01, RS2::SolidLine));
3164                 block->addEntity(circle);
3165
3166                 graphic->addBlock(block);
3167
3168                 Insert * ins;
3169                 InsertData insData("debugblock", Vector(0.0, 0.0), Vector(1.0, 1.0), 0.0, 1, 1, Vector(0.0, 0.0), NULL, RS2::NoUpdate);
3170
3171                 // insert one magenta instance of the block (original):
3172                 ins = new Insert(graphic, insData);
3173                 ins->setLayerToActive();
3174                 ins->setPen(Pen(Color(255, 0, 255), RS2::Width02, RS2::SolidLine));
3175                 ins->update();
3176                 graphic->addEntity(ins);
3177
3178                 // insert one green instance of the block (rotate):
3179                 insData = InsertData("debugblock", Vector(-50.0, 20.0), Vector(1.0, 1.0), 30.0 / ARAD, 1, 1, Vector(0.0, 0.0), NULL, RS2::NoUpdate);
3180                 ins = new Insert(graphic, insData);
3181                 ins->setLayerToActive();
3182                 ins->setPen(Pen(Color(0, 255, 0), RS2::Width02, RS2::SolidLine));
3183                 ins->update();
3184                 graphic->addEntity(ins);
3185
3186                 // insert one cyan instance of the block (move):
3187                 insData = InsertData("debugblock", Vector(10.0, 20.0), Vector(1.0, 1.0), 0.0, 1, 1, Vector(0.0, 0.0), NULL, RS2::NoUpdate);
3188                 ins = new Insert(graphic, insData);
3189                 ins->setLayerToActive();
3190                 ins->setPen(Pen(Color(0, 255, 255), RS2::Width02, RS2::SolidLine));
3191                 ins->update();
3192                 graphic->addEntity(ins);
3193
3194                 // insert one blue instance of the block:
3195                 for(double a=0.0; a<360.0; a+=45.0)
3196                 {
3197                         insData = InsertData("debugblock", Vector(60.0, 0.0), Vector(2.0 / 5, 2.0 / 5), a/ARAD, 1, 1, Vector(0.0, 0.0), NULL, RS2::NoUpdate);
3198                         ins = new Insert(graphic, insData);
3199                         ins->setLayerToActive();
3200                         ins->setPen(Pen(Color(0, 0, 255), RS2::Width05, RS2::SolidLine));
3201                         ins->update();
3202                         graphic->addEntity(ins);
3203                 }
3204
3205                 // insert an array of yellow instances of the block:
3206                 insData = InsertData("debugblock", Vector(-100.0, -100.0), Vector(0.2, 0.2), M_PI / 6.0, 6, 4, Vector(100.0, 100.0), NULL, RS2::NoUpdate);
3207                 ins = new Insert(graphic, insData);
3208                 ins->setLayerToActive();
3209                 ins->setPen(Pen(Color(255, 255, 0), RS2::Width01, RS2::SolidLine));
3210                 ins->update();
3211                 graphic->addEntity(ins);
3212
3213                 GraphicView * v = getGraphicView();
3214
3215                 if (v)
3216                         v->redraw();
3217         }
3218 }
3219
3220 /**
3221  * Testing function.
3222  */
3223 void ApplicationWindow::slotTestInsertEllipse()
3224 {
3225         DEBUG->print("ApplicationWindow::slotTestInsertEllipse()");
3226
3227         Document * d = getDocument();
3228
3229         if (d != NULL)
3230         {
3231                 Drawing * graphic = (Drawing *)d;
3232
3233                 if (graphic == NULL)
3234                         return;
3235
3236                 Ellipse * ellipse;
3237                 Line * line;
3238
3239                 for (double a=0.0; a<2*M_PI; a+=0.1)
3240                 {
3241                         Vector v;
3242                         v.setPolar(50.0, a);
3243                         double xp = 1000.0*a;
3244
3245                         EllipseData ellipseData(Vector(xp, 0.0), v, 0.5, 0.0, 2 * M_PI, false);
3246                         ellipse = new Ellipse(graphic, ellipseData);
3247
3248                         ellipse->setPen(Pen(Color(255, 0, 255), RS2::Width01, RS2::SolidLine));
3249
3250                         graphic->addEntity(ellipse);
3251                         //graphic->addEntity(new Point(graphic, ellipse->getMax()));
3252                         //graphic->addEntity(new Point(graphic, ellipse->getMin()));
3253
3254                         line = new Line(graphic, LineData(Vector(xp, 0.0), Vector(xp, 0.0) + v));
3255                         line->setPen(Pen(Color(128, 128, 128), RS2::Width01, RS2::SolidLine));
3256                         graphic->addEntity(line);
3257
3258 /*
3259                         for (double mx=-60.0; mx<60.0; mx+=1.0) {
3260                                 //for (double mx=0.0; mx<1.0; mx+=2.5) {
3261                                 VectorSolutions sol = ellipse->mapX(xp + mx);
3262                                 //graphic->addEntity(new Point(graphic,
3263                                 //                   sol.vector2 + Vector(a*500.0, 0.0)));
3264                                 //graphic->addEntity(new Point(graphic,
3265                                 //                   sol.vector3 + Vector(a*500.0, 0.0)));
3266                                 //graphic->addEntity(new Point(graphic,
3267                                 //                   sol.vector4 + Vector(a*500.0, 0.0)));
3268
3269                                 line = new Line(graphic,
3270                                                                 LineData(Vector(xp+mx,-50.0),
3271                                                                                         Vector(xp+mx,50.0)));
3272                                 line->setPen(Pen(Color(60, 60, 60),
3273                                                                         RS2::Width01,
3274                                                                         RS2::SolidLine));
3275                                 graphic->addEntity(line);
3276
3277                                 graphic->addEntity(new Point(graphic,
3278                                                                                                 sol.get(0)));
3279                         }
3280 */
3281                 }
3282
3283                 // different minor/minor relations
3284                 /*
3285                                 double x, y;
3286                                 for (y=-250.0; y<=250.0; y+=50.0) {
3287                                         for (x=-250.0; x<=250.0; x+=50.0) {
3288                                                 Vector v(x, y);
3289
3290                                                 ellipse = new Ellipse(graphic,
3291                                                                                                 v,
3292                                                                                                 Vector((x/5+50.0)/2.0, 0.0),
3293                                                                                         fabs(x/y),
3294                                                                                                 0.0, 2*M_PI,
3295                                                                                                 false);
3296
3297                                 ellipse->setPen(Pen(Color(255, 255, 0),
3298                                                                                 RS2::Width01,
3299                                                                                 RS2::DashDotLine));
3300
3301                                                 graphic->addEntity(ellipse);
3302                                                 graphic->addEntity(new Point(graphic, ellipse->getMax()));
3303                                                 graphic->addEntity(new Point(graphic, ellipse->getMin()));
3304
3305                                 ellipse = new Ellipse(graphic,
3306                                                                                                 v + Vector(750.0, 0.0),
3307                                                                                                 Vector((x/5+50.0)/2.0, 0.0),
3308                                                                                                 fabs(x/y),
3309                                                                                                 2*M_PI, 0.0,
3310                                                                                                 true);
3311
3312                                                 graphic->addEntity(ellipse);
3313                                                 graphic->addEntity(new Point(graphic, ellipse->getMax()));
3314                                                 graphic->addEntity(new Point(graphic, ellipse->getMin()));
3315                                         }
3316                                 }
3317                 */
3318
3319                 /*
3320                                 // different rotation angles:
3321                                 double rot;
3322                                 for (rot=0.0; rot<=2*M_PI+0.1; rot+=(M_PI/8)) {
3323                                         ellipse = new Ellipse(graphic,
3324                                                                                         Vector(rot*200, 500.0),
3325                                                                                         Vector(50.0, 0.0).rotate(rot),
3326                                                                                         0.3,
3327                                                                                         0.0, 2*M_PI,
3328                                                                                         false);
3329                                         graphic->addEntity(ellipse);
3330                                         graphic->addEntity(new Point(graphic, ellipse->getMax()));
3331                                         graphic->addEntity(new Point(graphic, ellipse->getMin()));
3332                                 }
3333
3334
3335                                 // different arc angles:
3336                                 double a1, a2;
3337                                 for (rot=0.0; rot<=2*M_PI+0.1; rot+=(M_PI/8)) {
3338                                         for (a1=0.0; a1<=2*M_PI+0.1; a1+=(M_PI/8)) {
3339                                                 for (a2=a1+M_PI/8; a2<=2*M_PI+a1+0.1; a2+=(M_PI/8)) {
3340                                                         ellipse = new Ellipse(graphic,
3341                                                                                                         Vector(-500.0-a1*200.0-5000.0*rot,
3342                                                                                                                                 500.0-a2*200.0),
3343                                                                                                         Vector(50.0, 0.0).rotate(rot),
3344                                                                                                         0.3,
3345                                                                                                         a1, a2,
3346                                                                                                         false);
3347                                                         graphic->addEntity(ellipse);
3348                                                         graphic->addEntity(new Point(graphic, ellipse->getMax()));
3349                                                         graphic->addEntity(new Point(graphic, ellipse->getMin()));
3350                                                 }
3351                                         }
3352                                 }
3353                 */
3354
3355                 GraphicView * v = getGraphicView();
3356
3357                 if (v != NULL)
3358                         v->redraw();
3359         }
3360 }
3361
3362 /**
3363  * Testing function.
3364  */
3365 void ApplicationWindow::slotTestInsertText()
3366 {
3367         DEBUG->print("ApplicationWindow::slotTestInsertText()");
3368
3369         Document * d = getDocument();
3370
3371         if (d != NULL)
3372         {
3373                 Drawing * graphic = (Drawing *)d;
3374
3375                 if (graphic == NULL)
3376                         return;
3377
3378                 Text * text;
3379                 TextData textData;
3380
3381                 textData = TextData(Vector(10.0, 10.0), 10.0, 100.0, RS2::VAlignTop, RS2::HAlignLeft, RS2::LeftToRight, RS2::Exact, 1.0, "Andrew", "normal", 0.0);
3382                 text = new Text(graphic, textData);
3383                 text->setLayerToActive();
3384                 text->setPen(Pen(Color(255, 0, 0), RS2::Width01, RS2::SolidLine));
3385                 graphic->addEntity(text);
3386
3387 /*
3388                 double x, y;
3389                 for (y=-250.0; y<=250.0; y+=50.0) {
3390                         for (x=-250.0; x<=250.0; x+=50.0) {
3391                                 Vector v(x, y);
3392
3393                                 textData = TextData(v,
3394                                                                                 10.0, 100.0,
3395                                                                                 RS2::VAlignTop,
3396                                                                                 RS2::HAlignLeft,
3397                                                                                 RS2::LeftToRight,
3398                                                                                 RS2::Exact,
3399                                                                                 1.0,
3400                                                                                 "Andrew",
3401                                                                                 "normal",
3402                                                                                 0.0);
3403
3404                                 text = new Text(graphic, textData);
3405
3406                                 text->setLayerToActive();
3407                                 text->setPen(Pen(Color(255, 0, 0),
3408                                                                         RS2::Width01,
3409                                                                         RS2::SolidLine));
3410                                 graphic->addEntity(text);
3411                         }
3412                 }
3413
3414                 Line* line;
3415                 for (x=0.0; x<M_PI*2.0; x+=0.2) {
3416                         Vector v(600.0+cos(x)*50.0, 0.0+sin(x)*50.0);
3417
3418                         line = new Line(graphic,
3419                                                                 LineData(Vector(600.0,0.0),
3420                                                                                         v));
3421                         line->setLayerToActive();
3422                         line->setPenToActive();
3423                         graphic->addEntity(line);
3424
3425                         textData = TextData(v,
3426                                                                         5.0, 50.0,
3427                                                                         RS2::VAlignTop,
3428                                                                         RS2::HAlignLeft,
3429                                                                         RS2::LeftToRight,
3430                                                                         RS2::Exact,
3431                                                                         1.0,
3432                                                                         "Andrew",
3433                                                                         "normal",
3434                                                                         x);
3435
3436                         text = new Text(graphic, textData);
3437
3438                         text->setLayerToActive();
3439                         text->setPen(Pen(Color(255, 0, 0),
3440                                                                 RS2::Width01,
3441                                                                 RS2::SolidLine));
3442                         graphic->addEntity(text);
3443                 }
3444
3445                 SolidData solidData = SolidData(Vector(5.0, 10.0),
3446                                                                                         Vector(25.0, 15.0),
3447                                                                                         Vector(15.0, 30.0));
3448
3449                 Solid* s = new Solid(graphic, solidData);
3450
3451                 s->setLayerToActive();
3452                 s->setPen(Pen(Color(255, 255, 0),
3453                                                 RS2::Width01,
3454                                                 RS2::SolidLine));
3455                 graphic->addEntity(s);
3456
3457                 GraphicView* v = getGraphicView();
3458                 if (v!=NULL) {
3459                         v->redraw();
3460                 }
3461 */
3462     }
3463 }
3464
3465 /**
3466  * Testing function.
3467  */
3468 void ApplicationWindow::slotTestInsertImage()
3469 {
3470         DEBUG->print("ApplicationWindow::slotTestInsertImage()");
3471
3472         Document * d = getDocument();
3473
3474         if (d == NULL)
3475                 return;
3476
3477         Drawing * drawing = (Drawing *)d;
3478
3479         if (drawing == NULL)
3480                 return;
3481
3482         Image * image;
3483         ImageData imageData;
3484
3485         imageData = ImageData(0, Vector(50.0, 30.0), Vector(0.5, 0.5), Vector(-0.5, 0.5), Vector(640, 480), "/home/andrew/data/image.png", 50, 50, 0);
3486         image = new Image(drawing, imageData);
3487
3488         image->setLayerToActive();
3489         image->setPen(Pen(Color(255, 0, 0), RS2::Width01, RS2::SolidLine));
3490         drawing->addEntity(image);
3491 }
3492
3493 /**
3494  * Testing function.
3495  */
3496 void ApplicationWindow::slotTestUnicode()
3497 {
3498     DEBUG->print("ApplicationWindow::slotTestUnicode()");
3499
3500     slotFileOpen("./fonts/unicode.cxf", RS2::FormatCXF);
3501     Document* d = getDocument();
3502     if (d!=NULL) {
3503         Drawing* graphic = (Drawing*)d;
3504         if (graphic==NULL) {
3505             return;
3506         }
3507
3508         Insert* ins;
3509
3510         int col;
3511         int row;
3512         QChar uCode;       // e.g. 65 (or 'A')
3513         QString strCode;   // unicde as string e.g. '[0041] A'
3514
3515         graphic->setAutoUpdateBorders(false);
3516
3517         for (col=0x0000; col<=0xFFF0; col+=0x10) {
3518             printf("col: %X\n", col);
3519             for (row=0x0; row<=0xF; row++) {
3520                 //printf("  row: %X\n", row);
3521
3522                 uCode = QChar(col+row);
3523                 //printf("  code: %X\n", uCode.unicode());
3524
3525                 strCode.setNum(uCode.unicode(), 16);
3526                 while (strCode.length()<4) {
3527                     strCode="0"+strCode;
3528                 }
3529                 strCode = "[" + strCode + "] " + uCode;
3530
3531                 if (graphic->findBlock(strCode)!=NULL) {
3532                     InsertData d(strCode,
3533                                     Vector(col/0x10*20.0,row*20.0),
3534                                     Vector(1.0,1.0), 0.0,
3535                                     1, 1, Vector(0.0, 0.0),
3536                                     NULL, RS2::NoUpdate);
3537                     ins = new Insert(graphic, d);
3538                     ins->setLayerToActive();
3539                     ins->setPen(Pen(Color(255, 255, 255),
3540                                        RS2::Width01,
3541                                        RS2::SolidLine));
3542                     ins->update();
3543                     graphic->addEntity(ins);
3544                 }
3545             }
3546         }
3547         graphic->setAutoUpdateBorders(true);
3548         graphic->calculateBorders();
3549     }
3550 }
3551
3552 /**
3553  * Testing function.
3554  */
3555 void ApplicationWindow::slotTestMath01()
3556 {
3557     DEBUG->print("ApplicationWindow::slotTestMath01()");
3558
3559     Document* d = getDocument();
3560     if (d!=NULL) {
3561         Drawing* graphic = (Drawing*)d;
3562         if (graphic==NULL) {
3563             return;
3564         }
3565
3566         // axis
3567         graphic->addEntity(new Line(graphic,
3568                                        LineData(Vector(0.0,0.0),
3569                                                    Vector(2*M_PI,0.0))));
3570         graphic->addEntity(new Line(graphic,
3571                                        LineData(Vector(0.0,-1.0),
3572                                                    Vector(0.0,1.0))));
3573
3574         // cos
3575         double a;
3576         double x = 59.0/ARAD;
3577         double x_0 = 60.0/ARAD;
3578         for (a=0.01; a<2*M_PI; a+=0.01) {
3579             // cos curve:
3580             Line* line = new Line(graphic,
3581                                         LineData(Vector(a-0.01, cos(a-0.01)),
3582                                                     Vector(a, cos(a))));
3583             graphic->addEntity(line);
3584
3585             // tangent:
3586             graphic->addEntity(new Line(graphic,
3587                                            LineData(Vector(a-0.01,cos(x_0)-sin(x_0)*(a-0.01-x_0)),
3588                                                        Vector(a,cos(x_0)-sin(x_0)*(a-x_0)))));
3589         }
3590
3591         // 59.0 deg
3592         graphic->addEntity(new Line(graphic,
3593                                        LineData(Vector(x,0.0),
3594                                                    Vector(x,1.0))));
3595
3596         // 60.0 deg
3597         graphic->addEntity(new Line(graphic,
3598                                        LineData(Vector(x_0,0.0),
3599                                                    Vector(x_0,1.0))));
3600
3601         // tangent
3602         //graphic->addEntity(new Line(graphic,
3603         //                   Vector(0.0,cos(x_0)-sin(x_0)*(0.0-x_0)),
3604         //                   Vector(6.0,cos(x_0)-sin(x_0)*(6.0-x_0))));
3605
3606
3607         GraphicView* v = getGraphicView();
3608         if (v!=NULL) {
3609             v->redraw();
3610         }
3611     }
3612 }
3613
3614 /**
3615  * Testing function.
3616  */
3617 void ApplicationWindow::slotTestResize640()
3618 {
3619     DEBUG->print("ApplicationWindow::slotTestResize640()");
3620
3621     resize(640, 480);
3622 }
3623
3624 /**
3625  * Testing function.
3626  */
3627 void ApplicationWindow::slotTestResize800()
3628 {
3629     DEBUG->print("ApplicationWindow::slotTestResize800()");
3630
3631     resize(800, 600);
3632 }
3633
3634 /**
3635  * Testing function.
3636  */
3637 void ApplicationWindow::slotTestResize1024()
3638 {
3639     DEBUG->print("ApplicationWindow::slotTestResize1024()");
3640
3641     resize(1024, 768);
3642 }
3643
3644 /**
3645  * overloaded for Message box on last window exit.
3646  */
3647 bool ApplicationWindow::QueryExit(void)
3648 {
3649         DEBUG->print("ApplicationWindow::queryExit()");
3650
3651         bool success = true;
3652         QList<QMdiSubWindow *> list = workspace->subWindowList();
3653
3654         for(int i=0; i<list.size(); i++)
3655         {
3656                 success = ((MDIWindow *)list[i])->CloseMDI();
3657
3658                 if (!success)
3659                         break;
3660         }
3661
3662         if (success)
3663                 storeSettings();
3664
3665         DEBUG->print("ApplicationWindow::queryExit(): OK");
3666
3667         return success;
3668 }
3669
3670 /**
3671  * Handle hotkeys. Don't let it to the default handler of Qt.
3672  * it will consume them also if a text field is active
3673  * which means it's impossible to enter a command.
3674  */
3675 void ApplicationWindow::keyPressEvent(QKeyEvent * e)
3676 {
3677 #warning "!!! keyPressEvent(): Do we need this anymore? !!!"
3678         // timer
3679         static QTime ts = QTime();
3680         static QString firstKey = "";
3681
3682         // single key codes:
3683         switch (e->key())
3684         {
3685         case Qt::Key_Shift:
3686         case Qt::Key_Control:
3687         case Qt::Key_Meta:
3688         case Qt::Key_Alt:
3689         case Qt::Key_CapsLock:
3690         {
3691                 QMainWindow::keyPressEvent(e);
3692
3693                 // forward to actions:
3694                 GraphicView * graphicView = getGraphicView();
3695
3696                 if (graphicView)
3697                         graphicView->_keyPressEvent(e);
3698
3699                 e->accept();
3700         }
3701                 break;
3702
3703         case Qt::Key_Escape:
3704                 firstKey = "";
3705                 slotBack();
3706                 e->accept();
3707                 break;
3708
3709         case Qt::Key_Return:
3710                 if (firstKey.isEmpty())
3711                 {
3712                         slotEnter();
3713                         e->accept();
3714                 }
3715                 break;
3716
3717         case Qt::Key_Plus:
3718                 if (firstKey.isEmpty())
3719                 {
3720                         actionHandler->slotZoomIn();
3721                         e->accept();
3722                 }
3723                 break;
3724
3725         case Qt::Key_Minus:
3726                 if (firstKey.isEmpty())
3727                 {
3728                         actionHandler->slotZoomOut();
3729                         e->accept();
3730                 }
3731                 break;
3732
3733         default:
3734                 e->ignore();
3735                 break;
3736         }
3737
3738         if (e->isAccepted())
3739                 return;
3740
3741         QTime now = QTime::currentTime();
3742
3743         // multi key codes:
3744         if (ts.msecsTo(now) < 2000)
3745         {
3746                 QString code = QString("%1%2").arg(firstKey).arg(QChar(e->key())).toLower();
3747
3748                 if (actionHandler->keycode(code) == false)
3749                 {
3750                         ts = now;
3751
3752                         if (QChar(e->key()).isPrint())
3753                                 firstKey += e->key();
3754                 }
3755                 else
3756                         firstKey = "";
3757         }
3758         else
3759         {
3760                 ts = now;
3761
3762                 if (QChar(e->key()).isPrint())
3763                         firstKey = e->key();
3764         }
3765
3766 //      Q3MainWindow::keyPressEvent(e);
3767         QMainWindow::keyPressEvent(e);
3768 }
3769
3770 void ApplicationWindow::keyReleaseEvent(QKeyEvent * e)
3771 {
3772         switch (e->key())
3773         {
3774         case Qt::Key_Shift:
3775         case Qt::Key_Control:
3776         case Qt::Key_Meta:
3777         case Qt::Key_Alt:
3778         case Qt::Key_CapsLock:
3779         {
3780 //              Q3MainWindow::keyReleaseEvent(e);
3781                 QMainWindow::keyReleaseEvent(e);
3782
3783                 // forward to actions:
3784                 GraphicView * graphicView = getGraphicView();
3785
3786                 if (graphicView)
3787                         graphicView->_keyReleaseEvent(e);
3788
3789                 e->accept();
3790         }
3791                 break;
3792         }
3793
3794 // THIS LOOKS LIKE A BUG TO ME...
3795 #warning "!!! keyPressEvent called in keyReleaseEvent !!!"
3796 //      Q3MainWindow::keyPressEvent(e);
3797         QMainWindow::keyPressEvent(e);
3798 }
3799
3800 /**
3801  * @return Pointer to application window.
3802  */
3803 /*static*/ ApplicationWindow * ApplicationWindow::getAppWindow()
3804 {
3805         return appWindow;
3806 }
3807
3808 /**
3809  * @return Pointer to workspace.
3810  */
3811 QMdiArea * ApplicationWindow::getWorkspace()
3812 {
3813         return workspace;
3814 }
3815
3816 /**
3817  * @return Pointer to the currently active MDI Window or NULL if no MDI Window
3818  * is active.
3819  */
3820 MDIWindow * ApplicationWindow::getMDIWindow()
3821 {
3822         DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::getMDIWindow: workspace=%08X", workspace);
3823
3824 // Here is the problem: Window isn't active...
3825         if (workspace)
3826         {
3827 printf("ApplicationWindow::getMDIWindow: activeSubWindow =%08X\n", (uint)workspace->activeSubWindow());
3828 printf("ApplicationWindow::getMDIWindow: currentSubWindow=%08X\n", (uint)workspace->currentSubWindow());
3829                 DEBUG->print("ApplicationWindow::getMDIWindow: activeSubWindow=%08X", workspace->activeSubWindow());
3830                 return (MDIWindow *)workspace->activeSubWindow();
3831         }
3832
3833         DEBUG->print("ApplicationWindow::getMDIWindow: activeSubWindow=??? (workspace == NULL)");
3834         return NULL;
3835 }
3836
3837 /**
3838  * Implementation from MainWindowInterface (and QS_ScripterHostInterface).
3839  *
3840  * @return Pointer to the graphic view of the currently active document
3841  * window or NULL if no window is available.
3842  */
3843 /*virtual*/ GraphicView * ApplicationWindow::getGraphicView()
3844 {
3845         MDIWindow * m = getMDIWindow();
3846
3847         return (m ? m->getGraphicView() : NULL);
3848 }
3849
3850 /**
3851  * Implementation from MainWindowInterface (and QS_ScripterHostInterface).
3852  *
3853  * @return Pointer to the graphic document of the currently active document
3854  * window or NULL if no window is available.
3855  */
3856 /*virtual*/ Document * ApplicationWindow::getDocument()
3857 {
3858         MDIWindow * m = getMDIWindow();
3859
3860         return (m ? m->getDocument() : NULL);
3861 }
3862
3863 /**
3864  * Creates a new document. Implementation from MainWindowInterface.
3865  */
3866 /*virtual*/ void ApplicationWindow::createNewDocument(const QString & fileName/*= QString::null*/,
3867         Document * doc/*= NULL*/)
3868 {
3869         slotFileNew(doc);
3870
3871         if (fileName != QString::null && getDocument())
3872                 getDocument()->setFilename(fileName);
3873 }
3874
3875 #if 0
3876 /**
3877  * Implementation from QG_MainWindowInterface.
3878  *
3879  * @return Pointer to this.
3880  */
3881 /*virtual*/ QMainWindow * ApplicationWindow::GetMainWindow()
3882 {
3883         return this;
3884 }
3885
3886 /**
3887  * @return Pointer to action handler. Implementation from QG_MainWindowInterface.
3888  */
3889 /*virtual*/ ActionHandler * ApplicationWindow::getActionHandler()
3890 {
3891         return actionHandler;
3892 }
3893 #endif
3894
3895 /**
3896  * Implementation from QG_MainWindowInterface.
3897  */
3898 /*virtual*/ void ApplicationWindow::showSimulationControls()
3899 {
3900 #ifdef RS_CAM
3901         simulationDockWindow->show();
3902 #endif
3903 }
3904
3905 #ifdef SCRIPTING
3906 /**
3907  * @return Pointer to the qsa object.
3908  */
3909 QSProject * ApplicationWindow::getQSAProject()
3910 {
3911         if (scripter != NULL)
3912                 return scripter->getQSAProject();
3913         else
3914                 return NULL;
3915 }
3916 #endif
3917
3918 /**
3919  * Implementation from QG_MainWindowInterface.
3920  */
3921 /*virtual*/ void ApplicationWindow::setFocus2()
3922 {
3923         setFocus();
3924 }