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