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