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