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