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