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