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