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