1 // applicationwindow.cpp
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
10 // JLH = James L. Hammons <jlhamm@acm.org>
13 // --- ---------- -----------------------------------------------------------
14 // JLH 05/17/2010 Added this text. :-)
15 // JLH 05/27/2010 Finished refactoring old Qt3 based action handling code to
16 // Qt4's much more sensible action handling
19 #include "applicationwindow.h"
23 #include "actiondrawlinefree.h"
24 #include "actionlibraryinsert.h"
25 #include "actionprintpreview.h"
27 #include "dialogfactory.h"
28 #include "dimaligned.h"
29 #include "dimlinear.h"
30 #include "dimradial.h"
36 #include "paintinterface.h"
38 #include "scriptlist.h"
41 #include "staticgraphicview.h"
47 #include "camdialog.h"
48 #include "simulationcontrols.h"
52 #include "filedialog.h"
53 #include "pentoolbar.h"
54 #include "recentfiles.h"
55 #include "cadtoolbar.h"
56 #include "cadtoolbarmain.h"
57 #include "coordinatewidget.h"
58 #include "dlgimageoptions.h"
59 #include "mousewidget.h"
60 #include "selectionwidget.h"
62 #include "createqtactions.h"
63 #include "qc_dialogfactory.h"
64 #include "qg_graphicview.h"
66 #include "mdiwindow.h"
68 ApplicationWindow * ApplicationWindow::appWindow = NULL;
71 # define QC_APP_ICON "qcad.png"
74 # define QC_APP_ICON16 "qcad16.png"
77 extern QSplashScreen * splash;
80 * Constructor. Initializes the app.
82 ApplicationWindow::ApplicationWindow():
83 QMainWindow((QWidget *)NULL/*,this is not a Qt::WindowFlags --> Qt::WA_DeleteOnClose*/), QG_MainWindowInterface()
85 DEBUG->print("ApplicationWindow::ApplicationWindow");
90 #warning "!!! Need to create new application icon !!!"
91 DEBUG->print("ApplicationWindow::ApplicationWindow: setting icon");
92 setWindowIcon(QIcon(":/res/" QC_APP_ICON));
93 CreateQtActions(this);
95 DEBUG->print("ApplicationWindow::ApplicationWindow: creating action handler");
96 actionHandler = new ActionHandler(this);
97 DEBUG->print("ApplicationWindow::ApplicationWindow: creating action handler: OK");
100 DEBUG->print("ApplicationWindow::ApplicationWindow: creating scripter");
101 scripter = new QS_Scripter(this, this);
102 DEBUG->print("ApplicationWindow::ApplicationWindow: creating scripter: OK");
105 DEBUG->print("ApplicationWindow::ApplicationWindow: init view");
107 DEBUG->print("ApplicationWindow::ApplicationWindow: init toolbar");
109 DEBUG->print("ApplicationWindow::ApplicationWindow: init actions");
111 DEBUG->print("ApplicationWindow::ApplicationWindow: init menu bar");
113 DEBUG->print("ApplicationWindow::ApplicationWindow: init status bar");
116 DEBUG->print("ApplicationWindow::ApplicationWindow: creating dialogFactory");
117 dialogFactory = new QC_DialogFactory(this, optionWidget);
118 DEBUG->print("ApplicationWindow::ApplicationWindow: creating dialogFactory: OK");
119 DEBUG->print("setting dialog factory object");
120 DEBUG->print("%s DialogFactory instance", (DialogFactory::instance() ? "got" : "no"));
121 DialogFactory::instance()->setFactoryObject(dialogFactory);
122 DEBUG->print("setting dialog factory object: OK");
124 DEBUG->print("ApplicationWindow::ApplicationWindow: init settings");
126 DEBUG->print("ApplicationWindow::ApplicationWindow: init MDI");
129 // Disable menu and toolbar items
130 emit windowsChanged(false);
132 statusBar()->showMessage("Architektonas Ready", 2000);
133 //setFocusPolicy(WheelFocus);
139 ApplicationWindow::~ApplicationWindow()
141 DEBUG->print("ApplicationWindow::~ApplicationWindow");
143 DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting scripter");
145 DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting scripter: OK");
148 DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting action handler");
149 delete actionHandler;
150 DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting action handler: OK");
152 DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting dialog factory");
153 delete dialogFactory;
154 DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting dialog factory: OK");
156 DEBUG->print("ApplicationWindow::~ApplicationWindow: OK");
160 * Runs the start script if scripting is available.
162 void ApplicationWindow::slotRunStartScript()
164 slotRunScript("autostart.qs");
168 * Runs a script. The action that triggers this slot has to carry the
169 * name of the script file.
171 void ApplicationWindow::slotRunScript()
173 DEBUG->print("ApplicationWindow::slotRunScript");
175 const QObject * s = sender();
179 QString script = ((QAction *)s)->text();
180 DEBUG->print("ApplicationWindow::slotRunScript: %s", script.toLatin1().data());
181 slotRunScript(script);
186 * Runs the script with the given name.
188 void ApplicationWindow::slotRunScript(const QString & name)
191 DEBUG->print("ApplicationWindow::slotRunScript");
193 if (scripter == NULL)
195 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotRunScript: scripter not initialized");
199 statusBar()->showMessage(tr("Running script '%1'").arg(name), 2000);
201 QStringList scriptList = SYSTEM->getScriptList();
202 scriptList.append(SYSTEM->getHomeDir() + "/.architektonas/" + name);
204 for (QStringList::Iterator it = scriptList.begin(); it!=scriptList.end(); ++it)
206 DEBUG->print("ApplicationWindow::slotRunScript: checking script '%s'", (*it).toLatin1().data();
209 if (fi.exists() && fi.fileName() == name)
211 DEBUG->print("ApplicationWindow::slotRunScript: running '%s'", (*it).toLatin1().data());
212 scripter->runScript(*it, "main");
219 * Called from toolbar buttons that were added by scripts to
222 void ApplicationWindow::slotInsertBlock()
224 const QObject * s = sender();
228 QString block = ((QAction *)s)->text();
229 DEBUG->print("ApplicationWindow::slotInsertBlock: %s", block.toLatin1().data());
230 slotInsertBlock(block);
235 * Called to insert blocks.
237 void ApplicationWindow::slotInsertBlock(const QString & name)
239 DEBUG->print("ApplicationWindow::slotInsertBlock: '%s'", name.toLatin1().data());
241 statusBar()->showMessage(tr("Inserting block '%1'").arg(name), 2000);
243 GraphicView * graphicView = getGraphicView();
244 Document * document = getDocument();
246 if (graphicView && document)
248 ActionLibraryInsert * action = new ActionLibraryInsert(*document, *graphicView);
249 action->setFile(name);
250 graphicView->setCurrentAction(action);
255 * Shows the main application window and a splash screen.
257 void ApplicationWindow::show()
259 #ifdef QSPLASHSCREEN_H
266 #ifdef QSPLASHSCREEN_H
270 qApp->processEvents();
271 splash->clearMessage();
272 # ifdef QC_DELAYED_SPLASH_SCREEN
273 QTimer::singleShot(1000 * 2, this, SLOT(finishSplashScreen()));
275 finishSplashScreen();
282 * Called when the splash screen has to terminate.
284 void ApplicationWindow::finishSplashScreen()
286 #ifdef QSPLASHSCREEN_H
289 splash->finish(this);
297 * Close Event. Called when the user tries to close the app.
299 void ApplicationWindow::closeEvent(QCloseEvent * /*ce*/)
301 DEBUG->print("ApplicationWindow::closeEvent()");
303 DEBUG->print("ApplicationWindow::closeEvent(): OK");
307 * Handles right-clicks for moving back to the last cad tool bar.
309 void ApplicationWindow::mouseReleaseEvent(QMouseEvent * e)
311 if (e->button() == Qt::RightButton && cadToolBar != NULL)
312 cadToolBar->showToolBarMain();
318 * Initializes the MDI workspace.
320 void ApplicationWindow::initMDI()
322 DEBUG->print("ApplicationWindow::initMDI() begin");
324 /* Could use QVBoxLayout instead of Q3VBox, but do we even need to? */
325 // Q3VBox * vb = new Q3VBox(this);
326 // vb->setFrameStyle(Q3Frame::StyledPanel | Q3Frame::Sunken);
327 // workspace = new QMdiArea(vb);
328 workspace = new QMdiArea(this);
329 // workspace->setScrollBarsEnabled(true);
330 // setCentralWidget(vb);
331 setCentralWidget(workspace);//JLH:hmm. (Yes, it works! \o/)
332 DEBUG->print("ApplicationWindow::initMDI(): workspace=%08X", workspace);
334 //#warning "Object::connect: No such signal QMdiArea::windowActivated(QWidget *)"
335 // connect(workspace, SIGNAL(windowActivated(QWidget *)), this, SLOT(slotWindowActivated(QWidget *)));
336 connect(workspace, SIGNAL(subWindowActivated(QMdiSubWindow *)), this,
337 SLOT(slotWindowActivated(QMdiSubWindow *)));
339 DEBUG->print("ApplicationWindow::initMDI() end");
343 * Initializes all QActions of the application.
344 * (Actually, it creates all application menus & toolbars. All actions are
345 * created in CreateQtActions() and simply referenced here.)
347 void ApplicationWindow::initActions()
349 DEBUG->print("ApplicationWindow::initActions()");
354 QMenu * menu = new QMenu(tr("&File"), this);
355 QToolBar * tb = fileToolBar;
356 tb->setWindowTitle("File");
357 // tb->setCloseMode(Q3DockWindow::Undocked);
359 menu->addAction(actionFileNew);
360 tb->addAction(actionFileNew);
361 connect(actionFileNew, SIGNAL(activated()), this, SLOT(slotFileNew()));
362 menu->addAction(actionFileOpen);
363 tb->addAction(actionFileOpen);
364 connect(actionFileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen()));
365 menu->addAction(actionFileSave);
366 tb->addAction(actionFileSave);
367 connect(actionFileSave, SIGNAL(activated()), this, SLOT(slotFileSave()));
368 connect(this, SIGNAL(windowsChanged(bool)), actionFileSave, SLOT(setEnabled(bool)));
369 menu->addAction(actionFileSaveAs);
370 connect(actionFileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs()));
371 connect(this, SIGNAL(windowsChanged(bool)), actionFileSaveAs, SLOT(setEnabled(bool)));
372 menu->addAction(actionFileExport);
373 connect(actionFileExport, SIGNAL(activated()), this, SLOT(slotFileExport()));
374 connect(this, SIGNAL(windowsChanged(bool)), actionFileExport, SLOT(setEnabled(bool)));
376 menu->addSeparator();
378 menu->addAction(actionFileClose);
379 connect(actionFileClose, SIGNAL(activated()), this, SLOT(slotFileClose()));
380 connect(this, SIGNAL(windowsChanged(bool)), actionFileClose, SLOT(setEnabled(bool)));
382 menu->addSeparator();
384 menu->addAction(actionFilePrint);
385 tb->addAction(actionFilePrint);
386 connect(actionFilePrint, SIGNAL(activated()), this, SLOT(slotFilePrint()));
387 connect(this, SIGNAL(windowsChanged(bool)), actionFilePrint, SLOT(setEnabled(bool)));
388 menu->addAction(actionFilePrintPreview);
389 tb->addAction(actionFilePrintPreview);
390 connect(actionFilePrintPreview, SIGNAL(toggled(bool)), this, SLOT(slotFilePrintPreview(bool)));
391 //??? connect(this, SIGNAL(printPreviewChanged(bool)), actionFilePrintPreview, SLOT(setOn(bool)));
392 connect(this, SIGNAL(windowsChanged(bool)), actionFilePrintPreview, SLOT(setEnabled(bool)));
394 menu->addSeparator();
396 menu->addAction(actionFileQuit);
397 connect(actionFileQuit, SIGNAL(activated()), this, SLOT(slotFileQuit()));
399 menu->addSeparator();
401 menuBar()->addMenu(menu);
402 addToolBar(Qt::TopToolBarArea, tb);
408 menu = new QMenu(tr("&Edit"), this);
410 tb->setWindowTitle("Edit");
411 // tb->setCloseMode(Q3DockWindow::Undocked);
413 // action = actionFactory.createAction(RS2::ActionEditUndo, actionHandler);
414 menu->addAction(actionEditUndo);
415 tb->addAction(actionEditUndo);
416 connect(actionEditUndo, SIGNAL(activated()), actionHandler, SLOT(slotEditUndo()));
417 connect(this, SIGNAL(windowsChanged(bool)), actionEditUndo, SLOT(setEnabled(bool)));
418 // action = actionFactory.createAction(RS2::ActionEditRedo, actionHandler);
419 menu->addAction(actionEditRedo);
420 tb->addAction(actionEditRedo);
421 connect(actionEditRedo, SIGNAL(activated()), actionHandler, SLOT(slotEditRedo()));
422 connect(this, SIGNAL(windowsChanged(bool)), actionEditRedo, SLOT(setEnabled(bool)));
425 menu->addSeparator();
427 // action = actionFactory.createAction(RS2::ActionEditCut, actionHandler);
428 menu->addAction(actionEditCut);
429 tb->addAction(actionEditCut);
430 connect(actionEditCut, SIGNAL(activated()), actionHandler, SLOT(slotEditCut()));
431 connect(this, SIGNAL(windowsChanged(bool)), actionEditCut, SLOT(setEnabled(bool)));
432 // action = actionFactory.createAction(RS2::ActionEditCopy, actionHandler);
433 menu->addAction(actionEditCopy);
434 tb->addAction(actionEditCopy);
435 connect(actionEditCopy, SIGNAL(activated()), actionHandler, SLOT(slotEditCopy()));
436 connect(this, SIGNAL(windowsChanged(bool)), actionEditCopy, SLOT(setEnabled(bool)));
437 // action = actionFactory.createAction(RS2::ActionEditPaste, actionHandler);
438 menu->addAction(actionEditPaste);
439 tb->addAction(actionEditPaste);
440 connect(actionEditPaste, SIGNAL(activated()), actionHandler, SLOT(slotEditPaste()));
441 connect(this, SIGNAL(windowsChanged(bool)), actionEditPaste, SLOT(setEnabled(bool)));
443 menu->addSeparator();
445 menu->addAction(actionOptionsGeneral);
446 connect(actionOptionsGeneral, SIGNAL(activated()), this, SLOT(slotOptionsGeneral()));
447 menu->addAction(actionOptionsDrawing);
448 connect(actionOptionsDrawing, SIGNAL(activated()), actionHandler, SLOT(slotOptionsDrawing()));
449 connect(this, SIGNAL(windowsChanged(bool)), actionOptionsDrawing, SLOT(setEnabled(bool)));
451 menuBar()->addMenu(menu);
452 addToolBar(Qt::TopToolBarArea, tb);
456 //menu = new QPopupMenu(this);
457 //menuBar()->insertItem(tr("&Options"), menu);
459 // Viewing / Zooming actions:
461 // menu = new Q3PopupMenu(this);
462 menu = new QMenu(tr("&View"), this);
463 //obsolete: menu->setCheckable(true);
465 tb->setWindowTitle("View");
466 // tb->setCloseMode(Q3DockWindow::Undocked);
468 // action = actionFactory.createAction(RS2::ActionViewGrid, this);
469 menu->addAction(actionViewGrid);
470 tb->addAction(actionViewGrid);
471 actionViewGrid->setChecked(true);
472 connect(actionViewGrid, SIGNAL(toggled(bool)), this, SLOT(slotViewGrid(bool)));
473 //??? connect(this, SIGNAL(gridChanged(bool)), actionViewGrid, SLOT(setOn(bool)));
474 connect(this, SIGNAL(windowsChanged(bool)), actionViewGrid, SLOT(setEnabled(bool)));
476 settings.beginGroup("Appearance");
477 bool draftMode = settings.value("DraftMode", false).toBool();
480 // action = actionFactory.createAction(RS2::ActionViewDraft, this);
481 menu->addAction(actionViewDraft);
482 tb->addAction(actionViewDraft);
483 actionViewDraft->setChecked(draftMode);
484 connect(actionViewDraft, SIGNAL(toggled(bool)), this, SLOT(slotViewDraft(bool)));
485 //??? connect(this, SIGNAL(draftChanged(bool)), actionViewDraft, SLOT(setOn(bool)));
486 connect(this, SIGNAL(windowsChanged(bool)), actionViewDraft, SLOT(setEnabled(bool)));
488 // action = actionFactory.createAction(RS2::ActionZoomRedraw, actionHandler);
489 menu->addAction(actionZoomRedraw);
490 tb->addAction(actionZoomRedraw);
491 connect(actionZoomRedraw, SIGNAL(activated()), actionHandler, SLOT(slotZoomRedraw()));
492 connect(this, SIGNAL(windowsChanged(bool)), actionZoomRedraw, SLOT(setEnabled(bool)));
493 // action = actionFactory.createAction(RS2::ActionZoomIn, actionHandler);
494 menu->addAction(actionZoomIn);
495 tb->addAction(actionZoomIn);
496 connect(actionZoomIn, SIGNAL(activated()), actionHandler, SLOT(slotZoomIn()));
497 connect(this, SIGNAL(windowsChanged(bool)), actionZoomIn, SLOT(setEnabled(bool)));
498 // action = actionFactory.createAction(RS2::ActionZoomOut, actionHandler);
499 menu->addAction(actionZoomOut);
500 tb->addAction(actionZoomOut);
501 connect(actionZoomOut, SIGNAL(activated()), actionHandler, SLOT(slotZoomOut()));
502 connect(this, SIGNAL(windowsChanged(bool)), actionZoomOut, SLOT(setEnabled(bool)));
503 // action = actionFactory.createAction(RS2::ActionZoomAuto, actionHandler);
504 menu->addAction(actionZoomAuto);
505 tb->addAction(actionZoomAuto);
506 connect(actionZoomAuto, SIGNAL(activated()), actionHandler, SLOT(slotZoomAuto()));
507 connect(this, SIGNAL(windowsChanged(bool)), actionZoomAuto, SLOT(setEnabled(bool)));
508 // action = actionFactory.createAction(RS2::ActionZoomPrevious, actionHandler);
509 menu->addAction(actionZoomPrevious);
510 tb->addAction(actionZoomPrevious);
511 connect(actionZoomPrevious, SIGNAL(activated()), actionHandler, SLOT(slotZoomPrevious()));
512 connect(this, SIGNAL(windowsChanged(bool)), actionZoomPrevious, SLOT(setEnabled(bool)));
513 // action = actionFactory.createAction(RS2::ActionZoomWindow, actionHandler);
514 menu->addAction(actionZoomWindow);
515 tb->addAction(actionZoomWindow);
516 connect(actionZoomWindow, SIGNAL(activated()), actionHandler, SLOT(slotZoomWindow()));
517 connect(this, SIGNAL(windowsChanged(bool)), actionZoomWindow, SLOT(setEnabled(bool)));
518 // action = actionFactory.createAction(RS2::ActionZoomPan, actionHandler);
519 menu->addAction(actionZoomPan);
520 tb->addAction(actionZoomPan);
521 connect(actionZoomPan, SIGNAL(activated()), actionHandler, SLOT(slotZoomPan()));
522 connect(this, SIGNAL(windowsChanged(bool)), actionZoomPan, SLOT(setEnabled(bool)));
524 menu->addSeparator();
526 // action = actionFactory.createAction(RS2::ActionViewStatusBar, this);
527 menu->addAction(actionViewStatusbar);
528 actionViewStatusbar->setChecked(true);
529 connect(actionViewStatusbar, SIGNAL(toggled(bool)), this, SLOT(slotViewStatusBar(bool)));
532 menu->insertItem(tr("Vie&ws"), createDockWindowMenu(NoToolBars));
533 menu->insertItem(tr("Tool&bars"), createDockWindowMenu(OnlyToolBars));
535 //Actually, this isn't really needed... This crap is maintained by Qt...
536 //#warning "!!! More stuff to port to Qt4 !!!"
539 menu->addAction(actionFocusCommandLine);
540 connect(actionFocusCommandLine, SIGNAL(activated()), this, SLOT(slotFocusCommandLine()));
541 connect(this, SIGNAL(windowsChanged(bool)), actionFocusCommandLine, SLOT(setEnabled(bool)));
542 menuBar()->addMenu(menu);
543 //addToolBar(tb, tr("View"));
544 // addDockWindow(tb, tr("View"), Qt::DockTop);
545 addToolBar(Qt::TopToolBarArea, tb);
547 // Selecting actions:
549 menu = new QMenu(tr("&Select"), this);
550 // action = actionFactory.createAction(RS2::ActionDeselectAll, actionHandler);
551 menu->addAction(actionDeselectAll);
552 connect(actionDeselectAll, SIGNAL(activated()), actionHandler, SLOT(slotDeselectAll()));
553 connect(this, SIGNAL(windowsChanged(bool)), actionDeselectAll, SLOT(setEnabled(bool)));
554 // action = actionFactory.createAction(RS2::ActionSelectAll, actionHandler);
555 menu->addAction(actionSelectAll);
556 connect(actionSelectAll, SIGNAL(activated()), actionHandler, SLOT(slotSelectAll()));
557 connect(this, SIGNAL(windowsChanged(bool)), actionSelectAll, SLOT(setEnabled(bool)));
558 // action = actionFactory.createAction(RS2::ActionSelectSingle, actionHandler);
559 menu->addAction(actionSelectSingle);
560 connect(actionSelectSingle, SIGNAL(activated()), actionHandler, SLOT(slotSelectSingle()));
561 connect(this, SIGNAL(windowsChanged(bool)), actionSelectSingle, SLOT(setEnabled(bool)));
562 // action = actionFactory.createAction(RS2::ActionSelectContour, actionHandler);
563 menu->addAction(actionSelectContour);
564 connect(actionSelectContour, SIGNAL(activated()), actionHandler, SLOT(slotSelectContour()));
565 connect(this, SIGNAL(windowsChanged(bool)), actionSelectContour, SLOT(setEnabled(bool)));
566 // action = actionFactory.createAction(RS2::ActionDeselectWindow, actionHandler);
567 menu->addAction(actionDeselectWindow);
568 connect(actionDeselectWindow, SIGNAL(activated()), actionHandler, SLOT(slotDeselectWindow()));
569 connect(this, SIGNAL(windowsChanged(bool)), actionDeselectWindow, SLOT(setEnabled(bool)));
570 // action = actionFactory.createAction(RS2::ActionSelectWindow, actionHandler);
571 menu->addAction(actionSelectWindow);
572 connect(actionSelectWindow, SIGNAL(activated()), actionHandler, SLOT(slotSelectWindow()));
573 connect(this, SIGNAL(windowsChanged(bool)), actionSelectWindow, SLOT(setEnabled(bool)));
574 // action = actionFactory.createAction(RS2::ActionSelectInvert, actionHandler);
575 menu->addAction(actionSelectInvert);
576 connect(actionSelectInvert, SIGNAL(activated()), actionHandler, SLOT(slotSelectInvert()));
577 connect(this, SIGNAL(windowsChanged(bool)), actionSelectInvert, SLOT(setEnabled(bool)));
578 // action = actionFactory.createAction(RS2::ActionSelectIntersected, actionHandler);
579 menu->addAction(actionSelectIntersected);
580 connect(actionSelectIntersected, SIGNAL(activated()), actionHandler, SLOT(slotSelectIntersected()));
581 connect(this, SIGNAL(windowsChanged(bool)), actionSelectIntersected, SLOT(setEnabled(bool)));
582 // action = actionFactory.createAction(RS2::ActionDeselectIntersected, actionHandler);
583 menu->addAction(actionDeselectIntersected);
584 connect(actionDeselectIntersected, SIGNAL(activated()), actionHandler, SLOT(slotDeselectIntersected()));
585 connect(this, SIGNAL(windowsChanged(bool)), actionDeselectIntersected, SLOT(setEnabled(bool)));
586 // action = actionFactory.createAction(RS2::ActionSelectLayer, actionHandler);
587 menu->addAction(actionSelectLayer);
588 connect(actionSelectLayer, SIGNAL(activated()), actionHandler, SLOT(slotSelectLayer()));
589 connect(this, SIGNAL(windowsChanged(bool)), actionSelectLayer, SLOT(setEnabled(bool)));
590 menuBar()->addMenu(menu);
594 menu = new QMenu(tr("&Draw"), this);
597 QMenu * subMenu = new QMenu(tr("&Point"), this);
598 // action = actionFactory.createAction(RS2::ActionDrawPoint, actionHandler);
599 subMenu->addAction(actionDrawPoint);
600 connect(actionDrawPoint, SIGNAL(activated()), actionHandler, SLOT(slotDrawPoint()));
601 connect(this, SIGNAL(windowsChanged(bool)), actionDrawPoint, SLOT(setEnabled(bool)));
602 menu->addMenu(subMenu);
605 subMenu = new QMenu(tr("&Line"), this);
606 // action = actionFactory.createAction(RS2::ActionDrawLine, actionHandler);
607 subMenu->addAction(actionDrawLine);
608 connect(actionDrawLine, SIGNAL(activated()), actionHandler, SLOT(slotDrawLine()));
609 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLine, SLOT(setEnabled(bool)));
610 // action = actionFactory.createAction(RS2::ActionDrawLineAngle, actionHandler);
611 subMenu->addAction(actionDrawLineAngle);
612 connect(actionDrawLineAngle, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineAngle()));
613 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineAngle, SLOT(setEnabled(bool)));
614 // action = actionFactory.createAction(RS2::ActionDrawLineHorizontal, actionHandler);
615 subMenu->addAction(actionDrawLineHorizontal);
616 connect(actionDrawLineHorizontal, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineHorizontal()));
617 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineHorizontal, SLOT(setEnabled(bool)));
618 // action = actionFactory.createAction(RS2::ActionDrawLineVertical, actionHandler);
619 subMenu->addAction(actionDrawLineVertical);
620 connect(actionDrawLineVertical, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineVertical()));
621 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineVertical, SLOT(setEnabled(bool)));
622 // action = actionFactory.createAction(RS2::ActionDrawLineRectangle, actionHandler);
623 subMenu->addAction(actionDrawLineRectangle);
624 connect(actionDrawLineRectangle, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineRectangle()));
625 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineRectangle, SLOT(setEnabled(bool)));
626 // action = actionFactory.createAction(RS2::ActionDrawLineParallel, actionHandler);
627 subMenu->addAction(actionDrawLineParallel);
628 connect(actionDrawLineParallel, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineParallel()));
629 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineParallel, SLOT(setEnabled(bool)));
630 // action = actionFactory.createAction(RS2::ActionDrawLineParallelThrough, actionHandler);
631 subMenu->addAction(actionDrawLineParallelThrough);
632 connect(actionDrawLineParallelThrough, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineParallelThrough()));
633 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineParallelThrough, SLOT(setEnabled(bool)));
634 // action = actionFactory.createAction(RS2::ActionDrawLineBisector, actionHandler);
635 subMenu->addAction(actionDrawLineBisector);
636 connect(actionDrawLineBisector, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineBisector()));
637 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineBisector, SLOT(setEnabled(bool)));
638 // action = actionFactory.createAction(RS2::ActionDrawLineTangent1, actionHandler);
639 subMenu->addAction(actionDrawLineTangent1);
640 connect(actionDrawLineTangent1, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineTangent1()));
641 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineTangent1, SLOT(setEnabled(bool)));
642 // action = actionFactory.createAction(RS2::ActionDrawLineTangent2, actionHandler);
643 subMenu->addAction(actionDrawLineTangent2);
644 connect(actionDrawLineTangent2, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineTangent2()));
645 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineTangent2, SLOT(setEnabled(bool)));
646 // action = actionFactory.createAction(RS2::ActionDrawLineOrthogonal, actionHandler);
647 subMenu->addAction(actionDrawLineOrthogonal);
648 connect(actionDrawLineOrthogonal, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineOrthogonal()));
649 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineOrthogonal, SLOT(setEnabled(bool)));
650 // action = actionFactory.createAction(RS2::ActionDrawLineRelAngle, actionHandler);
651 subMenu->addAction(actionDrawLineRelAngle);
652 connect(actionDrawLineRelAngle, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineRelAngle()));
653 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineRelAngle, SLOT(setEnabled(bool)));
654 // action = actionFactory.createAction(RS2::ActionDrawLinePolygon, actionHandler);
655 subMenu->addAction(actionDrawLinePolygon);
656 connect(actionDrawLinePolygon, SIGNAL(activated()), actionHandler, SLOT(slotDrawLinePolygon()));
657 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLinePolygon, SLOT(setEnabled(bool)));
658 // action = actionFactory.createAction(RS2::ActionDrawLinePolygon2, actionHandler);
659 subMenu->addAction(actionDrawLinePolygon2);
660 connect(actionDrawLinePolygon2, SIGNAL(activated()), actionHandler, SLOT(slotDrawLinePolygon2()));
661 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLinePolygon2, SLOT(setEnabled(bool)));
662 // action = actionFactory.createAction(RS2::ActionDrawLineFree, actionHandler);
663 subMenu->addAction(actionDrawLineFree);
664 connect(actionDrawLineFree, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineFree()));
665 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineFree, SLOT(setEnabled(bool)));
666 menu->addMenu(subMenu);
669 subMenu = new QMenu(tr("&Arc"), this);
670 subMenu->addAction(actionDrawArc);
671 connect(actionDrawArc, SIGNAL(activated()), actionHandler, SLOT(slotDrawArc()));
672 connect(this, SIGNAL(windowsChanged(bool)), actionDrawArc, SLOT(setEnabled(bool)));
673 subMenu->addAction(actionDrawArc3P);
674 connect(actionDrawArc3P, SIGNAL(activated()), actionHandler, SLOT(slotDrawArc3P()));
675 connect(this, SIGNAL(windowsChanged(bool)), actionDrawArc3P, SLOT(setEnabled(bool)));
676 subMenu->addAction(actionDrawArcParallel);
677 connect(actionDrawArcParallel, SIGNAL(activated()), actionHandler, SLOT(slotDrawArcParallel()));
678 connect(this, SIGNAL(windowsChanged(bool)), actionDrawArcParallel, SLOT(setEnabled(bool)));
679 subMenu->addAction(actionDrawArcTangential);
680 connect(actionDrawArcTangential, SIGNAL(activated()), actionHandler, SLOT(slotDrawArcTangential()));
681 connect(this, SIGNAL(windowsChanged(bool)), actionDrawArcTangential, SLOT(setEnabled(bool)));
682 menu->addMenu(subMenu);
685 subMenu = new QMenu(tr("&Circle"), this);
686 // action = actionFactory.createAction(RS2::ActionDrawCircle, actionHandler);
687 subMenu->addAction(actionDrawCircle);
688 connect(actionDrawCircle, SIGNAL(activated()), actionHandler, SLOT(slotDrawCircle()));
689 connect(this, SIGNAL(windowsChanged(bool)), actionDrawCircle, SLOT(setEnabled(bool)));
690 // action = actionFactory.createAction(RS2::ActionDrawCircleCR, actionHandler);
691 subMenu->addAction(actionDrawCircleCR);
692 connect(actionDrawCircleCR, SIGNAL(activated()), actionHandler, SLOT(slotDrawCircleCR()));
693 connect(this, SIGNAL(windowsChanged(bool)), actionDrawCircleCR, SLOT(setEnabled(bool)));
694 // action = actionFactory.createAction(RS2::ActionDrawCircle2P, actionHandler);
695 subMenu->addAction(actionDrawCircle2P);
696 connect(actionDrawCircle2P, SIGNAL(activated()), actionHandler, SLOT(slotDrawCircle2P()));
697 connect(this, SIGNAL(windowsChanged(bool)), actionDrawCircle2P, SLOT(setEnabled(bool)));
698 // action = actionFactory.createAction(RS2::ActionDrawCircle3P, actionHandler);
699 subMenu->addAction(actionDrawCircle3P);
700 connect(actionDrawCircle3P, SIGNAL(activated()), actionHandler, SLOT(slotDrawCircle3P()));
701 connect(this, SIGNAL(windowsChanged(bool)), actionDrawCircle3P, SLOT(setEnabled(bool)));
702 // action = actionFactory.createAction(RS2::ActionDrawCircleParallel, actionHandler);
703 subMenu->addAction(actionDrawCircleParallel);
704 connect(actionDrawCircleParallel, SIGNAL(activated()), actionHandler, SLOT(slotDrawCircleParallel()));
705 connect(this, SIGNAL(windowsChanged(bool)), actionDrawCircleParallel, SLOT(setEnabled(bool)));
706 menu->addMenu(subMenu);
709 subMenu = new QMenu(tr("&Ellipse"), this);
710 // action = actionFactory.createAction(RS2::ActionDrawEllipseAxis, actionHandler);
711 subMenu->addAction(actionDrawEllipseAxis);
712 connect(actionDrawEllipseAxis, SIGNAL(activated()), actionHandler, SLOT(slotDrawEllipseAxis()));
713 connect(this, SIGNAL(windowsChanged(bool)), actionDrawEllipseAxis, SLOT(setEnabled(bool)));
714 // action = actionFactory.createAction(RS2::ActionDrawEllipseArcAxis, actionHandler);
715 subMenu->addAction(actionDrawEllipseArcAxis);
716 connect(actionDrawEllipseArcAxis, SIGNAL(activated()), actionHandler, SLOT(slotDrawEllipseArcAxis()));
717 connect(this, SIGNAL(windowsChanged(bool)), actionDrawEllipseArcAxis, SLOT(setEnabled(bool)));
718 menu->addMenu(subMenu);
721 subMenu = new QMenu(tr("&Spline"), this);
722 // action = actionFactory.createAction(RS2::ActionDrawSpline, actionHandler);
723 subMenu->addAction(actionDrawSpline);
724 connect(actionDrawSpline, SIGNAL(activated()), actionHandler, SLOT(slotDrawSpline()));
725 connect(this, SIGNAL(windowsChanged(bool)), actionDrawSpline, SLOT(setEnabled(bool)));
726 menu->addMenu(subMenu);
729 subMenu = new QMenu(tr("&Polyline"), this);
730 // action = actionFactory.createAction(RS2::ActionDrawPolyline, actionHandler);
731 subMenu->addAction(actionDrawPolyline);
732 connect(actionDrawPolyline, SIGNAL(activated()), actionHandler, SLOT(slotDrawPolyline()));
733 connect(this, SIGNAL(windowsChanged(bool)), actionDrawPolyline, SLOT(setEnabled(bool)));
734 // action = actionFactory.createAction(RS2::ActionPolylineAdd, actionHandler);
735 subMenu->addAction(actionPolylineAdd);
736 connect(actionPolylineAdd, SIGNAL(activated()), actionHandler, SLOT(slotPolylineAdd()));
737 connect(this, SIGNAL(windowsChanged(bool)), actionPolylineAdd, SLOT(setEnabled(bool)));
738 subMenu->addAction(actionPolylineAppend);
739 connect(actionPolylineAppend, SIGNAL(activated()), actionHandler, SLOT(slotPolylineAppend()));
740 connect(this, SIGNAL(windowsChanged(bool)), actionPolylineAppend, SLOT(setEnabled(bool)));
741 // action = actionFactory.createAction(RS2::ActionPolylineDel, actionHandler);
742 subMenu->addAction(actionPolylineDel);
743 connect(actionPolylineDel, SIGNAL(activated()), actionHandler, SLOT(slotPolylineDel()));
744 connect(this, SIGNAL(windowsChanged(bool)), actionPolylineDel, SLOT(setEnabled(bool)));
745 // action = actionFactory.createAction(RS2::ActionPolylineDelBetween, actionHandler);
746 subMenu->addAction(actionPolylineDelBetween);
747 connect(actionPolylineDelBetween, SIGNAL(activated()), actionHandler, SLOT(slotPolylineDelBetween()));
748 connect(this, SIGNAL(windowsChanged(bool)), actionPolylineDelBetween, SLOT(setEnabled(bool)));
749 // action = actionFactory.createAction(RS2::ActionPolylineTrim, actionHandler);
750 subMenu->addAction(actionPolylineTrim);
751 connect(actionPolylineTrim, SIGNAL(activated()), actionHandler, SLOT(slotPolylineTrim()));
752 connect(this, SIGNAL(windowsChanged(bool)), actionPolylineTrim, SLOT(setEnabled(bool)));
753 menu->addMenu(subMenu);
756 // action = actionFactory.createAction(RS2::ActionDrawText, actionHandler);
757 menu->addAction(actionDrawText);
758 connect(actionDrawText, SIGNAL(activated()), actionHandler, SLOT(slotDrawText()));
759 connect(this, SIGNAL(windowsChanged(bool)), actionDrawText, SLOT(setEnabled(bool)));
761 // action = actionFactory.createAction(RS2::ActionDrawHatch, actionHandler);
762 menu->addAction(actionDrawHatch);
763 connect(actionDrawHatch, SIGNAL(activated()), actionHandler, SLOT(slotDrawHatch()));
764 connect(this, SIGNAL(windowsChanged(bool)), actionDrawHatch, SLOT(setEnabled(bool)));
766 // action = actionFactory.createAction(RS2::ActionDrawImage, actionHandler);
767 menu->addAction(actionDrawImage);
768 connect(actionDrawImage, SIGNAL(activated()), actionHandler, SLOT(slotDrawImage()));
769 connect(this, SIGNAL(windowsChanged(bool)), actionDrawImage, SLOT(setEnabled(bool)));
770 // menuBar()->insertItem(tr("&Draw"), menu);
771 menuBar()->addMenu(menu);
773 // Dimensioning actions:
779 menu = new QMenu(tr("&Dimension"), this);
780 menu->addAction(actionDimAligned);
781 connect(actionDimAligned, SIGNAL(activated()), actionHandler, SLOT(slotDimAligned()));
782 connect(this, SIGNAL(windowsChanged(bool)), actionDimAligned, SLOT(setEnabled(bool)));
783 menu->addAction(actionDimLinear);
784 connect(actionDimLinear, SIGNAL(activated()), actionHandler, SLOT(slotDimLinear()));
785 connect(this, SIGNAL(windowsChanged(bool)), actionDimLinear, SLOT(setEnabled(bool)));
786 menu->addAction(actionDimLinearHor);
787 connect(actionDimLinearHor, SIGNAL(activated()), actionHandler, SLOT(slotDimLinearHor()));
788 connect(this, SIGNAL(windowsChanged(bool)), actionDimLinearHor, SLOT(setEnabled(bool)));
789 menu->addAction(actionDimLinearVer);
790 connect(actionDimLinearVer, SIGNAL(activated()), actionHandler, SLOT(slotDimLinearVer()));
791 connect(this, SIGNAL(windowsChanged(bool)), actionDimLinearVer, SLOT(setEnabled(bool)));
792 menu->addAction(actionDimRadial);
793 connect(actionDimRadial, SIGNAL(activated()), actionHandler, SLOT(slotDimRadial()));
794 connect(this, SIGNAL(windowsChanged(bool)), actionDimRadial, SLOT(setEnabled(bool)));
795 menu->addAction(actionDimDiametric);
796 connect(actionDimDiametric, SIGNAL(activated()), actionHandler, SLOT(slotDimDiametric()));
797 connect(this, SIGNAL(windowsChanged(bool)), actionDimDiametric, SLOT(setEnabled(bool)));
798 menu->addAction(actionDimAngular);
799 connect(actionDimAngular, SIGNAL(activated()), actionHandler, SLOT(slotDimAngular()));
800 connect(this, SIGNAL(windowsChanged(bool)), actionDimAngular, SLOT(setEnabled(bool)));
801 menu->addAction(actionDimLeader);
802 connect(actionDimLeader, SIGNAL(activated()), actionHandler, SLOT(slotDimLeader()));
803 connect(this, SIGNAL(windowsChanged(bool)), actionDimLeader, SLOT(setEnabled(bool)));
805 m->insertItem(tr("&Dimension"), menu);
807 menuBar()->addMenu(menu);
810 // Modifying actions:
812 menu = new QMenu(tr("&Modify"), this);
813 menu->addAction(actionModifyMove);
814 connect(actionModifyMove, SIGNAL(activated()), actionHandler, SLOT(slotModifyMove()));
815 connect(this, SIGNAL(windowsChanged(bool)), actionModifyMove, SLOT(setEnabled(bool)));
816 menu->addAction(actionModifyRotate);
817 connect(actionModifyRotate, SIGNAL(activated()), actionHandler, SLOT(slotModifyRotate()));
818 connect(this, SIGNAL(windowsChanged(bool)), actionModifyRotate, SLOT(setEnabled(bool)));
819 menu->addAction(actionModifyScale);
820 connect(actionModifyScale, SIGNAL(activated()), actionHandler, SLOT(slotModifyScale()));
821 connect(this, SIGNAL(windowsChanged(bool)), actionModifyScale, SLOT(setEnabled(bool)));
822 menu->addAction(actionModifyMirror);
823 connect(actionModifyMirror, SIGNAL(activated()), actionHandler, SLOT(slotModifyMirror()));
824 connect(this, SIGNAL(windowsChanged(bool)), actionModifyMirror, SLOT(setEnabled(bool)));
825 menu->addAction(actionModifyMoveRotate);
826 connect(actionModifyMoveRotate, SIGNAL(activated()), actionHandler, SLOT(slotModifyMoveRotate()));
827 connect(this, SIGNAL(windowsChanged(bool)), actionModifyMoveRotate, SLOT(setEnabled(bool)));
828 menu->addAction(actionModifyRotate2);
829 connect(actionModifyRotate2, SIGNAL(activated()), actionHandler, SLOT(slotModifyRotate2()));
830 connect(this, SIGNAL(windowsChanged(bool)), actionModifyRotate2, SLOT(setEnabled(bool)));
831 menu->addAction(actionModifyTrim);
832 connect(actionModifyTrim, SIGNAL(activated()), actionHandler, SLOT(slotModifyTrim()));
833 connect(this, SIGNAL(windowsChanged(bool)), actionModifyTrim, SLOT(setEnabled(bool)));
834 menu->addAction(actionModifyTrim2);
835 connect(actionModifyTrim2, SIGNAL(activated()), actionHandler, SLOT(slotModifyTrim2()));
836 connect(this, SIGNAL(windowsChanged(bool)), actionModifyTrim2, SLOT(setEnabled(bool)));
837 menu->addAction(actionModifyTrimAmount);
838 connect(actionModifyTrimAmount, SIGNAL(activated()), actionHandler, SLOT(slotModifyTrimAmount()));
839 connect(this, SIGNAL(windowsChanged(bool)), actionModifyTrimAmount, SLOT(setEnabled(bool)));
840 menu->addAction(actionModifyBevel);
841 connect(actionModifyBevel, SIGNAL(activated()), actionHandler, SLOT(slotModifyBevel()));
842 connect(this, SIGNAL(windowsChanged(bool)), actionModifyBevel, SLOT(setEnabled(bool)));
843 menu->addAction(actionModifyRound);
844 connect(actionModifyRound, SIGNAL(activated()), actionHandler, SLOT(slotModifyRound()));
845 connect(this, SIGNAL(windowsChanged(bool)), actionModifyRound, SLOT(setEnabled(bool)));
846 menu->addAction(actionModifyCut);
847 connect(actionModifyCut, SIGNAL(activated()), actionHandler, SLOT(slotModifyCut()));
848 connect(this, SIGNAL(windowsChanged(bool)), actionModifyCut, SLOT(setEnabled(bool)));
849 menu->addAction(actionModifyStretch);
850 connect(actionModifyStretch, SIGNAL(activated()), actionHandler, SLOT(slotModifyStretch()));
851 connect(this, SIGNAL(windowsChanged(bool)), actionModifyStretch, SLOT(setEnabled(bool)));
852 menu->addAction(actionModifyEntity);
853 connect(actionModifyEntity, SIGNAL(activated()), actionHandler, SLOT(slotModifyEntity()));
854 connect(this, SIGNAL(windowsChanged(bool)), actionModifyEntity, SLOT(setEnabled(bool)));
855 menu->addAction(actionModifyAttributes);
856 connect(actionModifyAttributes, SIGNAL(activated()), actionHandler, SLOT(slotModifyAttributes()));
857 connect(this, SIGNAL(windowsChanged(bool)), actionModifyAttributes, SLOT(setEnabled(bool)));
858 menu->addAction(actionModifyDelete);
859 connect(actionModifyDelete, SIGNAL(activated()), actionHandler, SLOT(slotModifyDelete()));
860 connect(this, SIGNAL(windowsChanged(bool)), actionModifyDelete, SLOT(setEnabled(bool)));
861 menu->addAction(actionModifyDeleteQuick);
862 connect(actionModifyDeleteQuick, SIGNAL(activated()), actionHandler, SLOT(slotModifyDeleteQuick()));
863 connect(this, SIGNAL(windowsChanged(bool)), actionModifyDeleteQuick, SLOT(setEnabled(bool)));
864 menu->addAction(actionModifyExplodeText);
865 connect(actionModifyExplodeText, SIGNAL(activated()), actionHandler, SLOT(slotModifyExplodeText()));
866 connect(this, SIGNAL(windowsChanged(bool)), actionModifyExplodeText, SLOT(setEnabled(bool)));
867 menu->addAction(actionBlocksExplode);
868 connect(actionBlocksExplode, SIGNAL(activated()), actionHandler, SLOT(slotBlocksExplode()));
869 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksExplode, SLOT(setEnabled(bool)));
870 menuBar()->addMenu(menu);
874 menu = new QMenu(tr("&Snap"), this);
875 menu->addAction(actionSnapFree);
876 actionHandler->setActionSnapFree(actionSnapFree); // ???Why???
877 connect(actionSnapFree, SIGNAL(activated()), actionHandler, SLOT(slotSnapFree()));
878 connect(this, SIGNAL(windowsChanged(bool)), actionSnapFree, SLOT(setEnabled(bool)));
879 actionSnapFree->setChecked(true);
880 menu->addAction(actionSnapGrid);
881 actionHandler->setActionSnapGrid(actionSnapGrid); // ???Why???
882 connect(actionSnapGrid, SIGNAL(activated()), actionHandler, SLOT(slotSnapGrid()));
883 connect(this, SIGNAL(windowsChanged(bool)), actionSnapGrid, SLOT(setEnabled(bool)));
884 menu->addAction(actionSnapEndpoint);
885 actionHandler->setActionSnapEndpoint(actionSnapEndpoint); // ???Why???
886 connect(actionSnapEndpoint, SIGNAL(activated()), actionHandler, SLOT(slotSnapEndpoint()));
887 connect(this, SIGNAL(windowsChanged(bool)), actionSnapEndpoint, SLOT(setEnabled(bool)));
888 menu->addAction(actionSnapOnEntity);
889 actionHandler->setActionSnapOnEntity(actionSnapOnEntity); // ???Why???
890 connect(actionSnapOnEntity, SIGNAL(activated()), actionHandler, SLOT(slotSnapOnEntity()));
891 connect(this, SIGNAL(windowsChanged(bool)), actionSnapOnEntity, SLOT(setEnabled(bool)));
892 menu->addAction(actionSnapCenter);
893 actionHandler->setActionSnapCenter(actionSnapCenter); // ???Why???
894 connect(actionSnapCenter, SIGNAL(activated()), actionHandler, SLOT(slotSnapCenter()));
895 connect(this, SIGNAL(windowsChanged(bool)), actionSnapCenter, SLOT(setEnabled(bool)));
896 menu->addAction(actionSnapMiddle);
897 actionHandler->setActionSnapMiddle(actionSnapMiddle); // ???Why???
898 connect(actionSnapMiddle, SIGNAL(activated()), actionHandler, SLOT(slotSnapMiddle()));
899 connect(this, SIGNAL(windowsChanged(bool)), actionSnapMiddle, SLOT(setEnabled(bool)));
900 menu->addAction(actionSnapDist);
901 actionHandler->setActionSnapDist(actionSnapDist); // ???Why???
902 connect(actionSnapDist, SIGNAL(activated()), actionHandler, SLOT(slotSnapDist()));
903 connect(this, SIGNAL(windowsChanged(bool)), actionSnapDist, SLOT(setEnabled(bool)));
904 menu->addAction(actionSnapIntersection);
905 actionHandler->setActionSnapIntersection(actionSnapIntersection); // ???Why???
906 connect(actionSnapIntersection, SIGNAL(activated()), actionHandler, SLOT(slotSnapIntersection()));
907 connect(this, SIGNAL(windowsChanged(bool)), actionSnapIntersection, SLOT(setEnabled(bool)));
908 menu->addAction(actionSnapIntersectionManual);
909 actionHandler->setActionSnapIntersectionManual(actionSnapIntersectionManual); // ???Why???
910 connect(actionSnapIntersectionManual, SIGNAL(activated()), actionHandler, SLOT(slotSnapIntersectionManual()));
911 connect(this, SIGNAL(windowsChanged(bool)), actionSnapIntersectionManual, SLOT(setEnabled(bool)));
913 menu->addSeparator();
915 menu->addAction(actionRestrictNothing);
916 actionHandler->setActionRestrictNothing(actionRestrictNothing); // ???WHY???
917 connect(actionRestrictNothing, SIGNAL(activated()), actionHandler, SLOT(slotRestrictNothing()));
918 connect(this, SIGNAL(windowsChanged(bool)), actionRestrictNothing, SLOT(setEnabled(bool)));
919 actionRestrictNothing->setChecked(true);
920 menu->addAction(actionRestrictOrthogonal);
921 actionHandler->setActionRestrictOrthogonal(actionRestrictOrthogonal); // ???WHY???
922 connect(actionRestrictOrthogonal, SIGNAL(activated()), actionHandler, SLOT(slotRestrictOrthogonal()));
923 connect(this, SIGNAL(windowsChanged(bool)), actionRestrictOrthogonal, SLOT(setEnabled(bool)));
924 menu->addAction(actionRestrictHorizontal);
925 actionHandler->setActionRestrictHorizontal(actionRestrictHorizontal); // ???WHY???
926 connect(actionRestrictHorizontal, SIGNAL(activated()), actionHandler, SLOT(slotRestrictHorizontal()));
927 connect(this, SIGNAL(windowsChanged(bool)), actionRestrictHorizontal, SLOT(setEnabled(bool)));
928 menu->addAction(actionRestrictVertical);
929 actionHandler->setActionRestrictVertical(actionRestrictVertical); // ???WHY???
930 connect(actionRestrictVertical, SIGNAL(activated()), actionHandler, SLOT(slotRestrictVertical()));
931 connect(this, SIGNAL(windowsChanged(bool)), actionRestrictVertical, SLOT(setEnabled(bool)));
933 menu->addSeparator();
935 menu->addAction(actionSetRelativeZero);
936 connect(actionSetRelativeZero, SIGNAL(activated()), actionHandler, SLOT(slotSetRelativeZero()));
937 connect(this, SIGNAL(windowsChanged(bool)), actionSetRelativeZero, SLOT(setEnabled(bool)));
938 menu->addAction(actionLockRelativeZero);
939 actionHandler->setActionLockRelativeZero(actionLockRelativeZero);
940 connect(actionLockRelativeZero, SIGNAL(toggled(bool)), actionHandler, SLOT(slotLockRelativeZero(bool))); // ???WHY???
941 connect(this, SIGNAL(windowsChanged(bool)), actionLockRelativeZero, SLOT(setEnabled(bool)));
942 menuBar()->addMenu(menu);
947 menu = new QMenu(tr("&Info"), this);
948 menu->addAction(actionInfoDist);
949 connect(actionInfoDist, SIGNAL(activated()), actionHandler, SLOT(slotInfoDist()));
950 connect(this, SIGNAL(windowsChanged(bool)), actionInfoDist, SLOT(setEnabled(bool)));
951 menu->addAction(actionInfoDist2);
952 connect(actionInfoDist2, SIGNAL(activated()), actionHandler, SLOT(slotInfoDist2()));
953 connect(this, SIGNAL(windowsChanged(bool)), actionInfoDist2, SLOT(setEnabled(bool)));
954 menu->addAction(actionInfoAngle);
955 connect(actionInfoAngle, SIGNAL(activated()), actionHandler, SLOT(slotInfoAngle()));
956 connect(this, SIGNAL(windowsChanged(bool)), actionInfoAngle, SLOT(setEnabled(bool)));
957 menu->addAction(actionInfoTotalLength);
958 connect(actionInfoTotalLength, SIGNAL(activated()), actionHandler, SLOT(slotInfoTotalLength()));
959 connect(this, SIGNAL(windowsChanged(bool)), actionInfoTotalLength, SLOT(setEnabled(bool)));
960 menu->addAction(actionInfoArea);
961 connect(actionInfoArea, SIGNAL(activated()), actionHandler, SLOT(slotInfoArea()));
962 connect(this, SIGNAL(windowsChanged(bool)), actionInfoArea, SLOT(setEnabled(bool)));
963 menuBar()->addMenu(menu);
968 menu = new QMenu(tr("&Layer"), this);
969 menu->addAction(actionLayersDefreezeAll);
970 connect(actionLayersDefreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotLayersDefreezeAll()));
971 connect(this, SIGNAL(windowsChanged(bool)), actionLayersDefreezeAll, SLOT(setEnabled(bool)));
972 menu->addAction(actionLayersFreezeAll);
973 connect(actionLayersFreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotLayersFreezeAll()));
974 connect(this, SIGNAL(windowsChanged(bool)), actionLayersFreezeAll, SLOT(setEnabled(bool)));
975 menu->addAction(actionLayersAdd);
976 connect(actionLayersAdd, SIGNAL(activated()), actionHandler, SLOT(slotLayersAdd()));
977 connect(this, SIGNAL(windowsChanged(bool)), actionLayersAdd, SLOT(setEnabled(bool)));
978 menu->addAction(actionLayersRemove);
979 connect(actionLayersRemove, SIGNAL(activated()), actionHandler, SLOT(slotLayersRemove()));
980 connect(this, SIGNAL(windowsChanged(bool)), actionLayersRemove, SLOT(setEnabled(bool)));
981 menu->addAction(actionLayersEdit);
982 connect(actionLayersEdit, SIGNAL(activated()), actionHandler, SLOT(slotLayersEdit()));
983 connect(this, SIGNAL(windowsChanged(bool)), actionLayersEdit, SLOT(setEnabled(bool)));
984 menu->addAction(actionLayersToggleView);
985 connect(actionLayersToggleView, SIGNAL(activated()), actionHandler, SLOT(slotLayersToggleView()));
986 connect(this, SIGNAL(windowsChanged(bool)), actionLayersToggleView, SLOT(setEnabled(bool)));
987 menuBar()->addMenu(menu);
991 menu = new QMenu(tr("&Block"), this);
992 menu->addAction(actionBlocksDefreezeAll);
993 connect(actionBlocksDefreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotBlocksDefreezeAll()));
994 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksDefreezeAll, SLOT(setEnabled(bool)));
995 menu->addAction(actionBlocksFreezeAll);
996 connect(actionBlocksFreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotBlocksFreezeAll()));
997 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksFreezeAll, SLOT(setEnabled(bool)));
998 menu->addAction(actionBlocksAdd);
999 connect(actionBlocksAdd, SIGNAL(activated()), actionHandler, SLOT(slotBlocksAdd()));
1000 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksAdd, SLOT(setEnabled(bool)));
1001 menu->addAction(actionBlocksRemove);
1002 connect(actionBlocksRemove, SIGNAL(activated()), actionHandler, SLOT(slotBlocksRemove()));
1003 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksRemove, SLOT(setEnabled(bool)));
1004 menu->addAction(actionBlocksAttributes);
1005 connect(actionBlocksAttributes, SIGNAL(activated()), actionHandler, SLOT(slotBlocksAttributes()));
1006 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksAttributes, SLOT(setEnabled(bool)));
1007 menu->addAction(actionBlocksInsert);
1008 connect(actionBlocksInsert, SIGNAL(activated()), actionHandler, SLOT(slotBlocksInsert()));
1009 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksInsert, SLOT(setEnabled(bool)));
1010 menu->addAction(actionBlocksEdit);
1011 connect(actionBlocksEdit, SIGNAL(activated()), actionHandler, SLOT(slotBlocksEdit()));
1012 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksEdit, SLOT(setEnabled(bool)));
1013 menu->addAction(actionBlocksCreate);
1014 connect(actionBlocksCreate, SIGNAL(activated()), actionHandler, SLOT(slotBlocksCreate()));
1015 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksCreate, SLOT(setEnabled(bool)));
1016 menu->addAction(actionBlocksExplode);
1017 connect(actionBlocksExplode, SIGNAL(activated()), actionHandler, SLOT(slotBlocksExplode()));
1018 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksExplode, SLOT(setEnabled(bool)));
1019 menuBar()->addMenu(menu);
1021 //will *this* make a toolbar break for us???
1022 addToolBarBreak(Qt::TopToolBarArea);
1023 // addDockWindow(penToolBar, tr("Pen"), Qt::DockTop);
1024 // addDockWindow(optionWidget, tr("Tool Options"), Qt::DockTop, true);
1025 addToolBar(Qt::TopToolBarArea, (QToolBar *)penToolBar); // hmm.
1026 addToolBar(Qt::TopToolBarArea, optionWidget);
1031 scriptMenu = new QMenu(this);
1032 scriptOpenIDE = actionFactory.createAction(RS2::ActionScriptOpenIDE, this);
1033 scriptOpenIDE->addTo(scriptMenu);
1034 scriptRun = actionFactory.createAction(RS2::ActionScriptRun, this);
1035 scriptRun->addTo(scriptMenu);
1038 scriptOpenIDE = NULL;
1044 menu = new QMenu(tr("&CAM"), this);
1045 action = actionFactory.createAction(RS2::ActionCamExportAuto, actionHandler);
1046 menu->addAction(action);
1047 connect(this, SIGNAL(windowsChanged(bool)), action, SLOT(setEnabled(bool)));
1048 action = actionFactory.createAction(RS2::ActionCamReorder, actionHandler);
1049 menu->addAction(action);
1050 connect(this, SIGNAL(windowsChanged(bool)), action, SLOT(setEnabled(bool)));
1051 menuBar()->addMenu(menu);
1056 helpAboutApp = new QAction(QIcon(QC_APP_ICON16), tr("&About Architektonas"), this);
1057 // helpAboutApp = new QAction(tr("About"), qPixmapFromMimeSource(QC_APP_ICON16), tr("&About %1").arg(QC_APPNAME), 0, this);
1058 helpAboutApp->setStatusTip(tr("About the application"));
1059 //helpAboutApp->setWhatsThis(tr("About\n\nAbout the application"));
1060 connect(helpAboutApp, SIGNAL(activated()), this, SLOT(slotHelpAbout()));
1062 helpManual = new QAction(QIcon(":/res/contents.png"), tr("&Manual"), this);
1063 helpManual->setShortcut(Qt::Key_F1);
1064 // helpManual = new QAction(qPixmapFromMimeSource("contents.png"), tr("&Manual"), Qt::Key_F1, this);
1065 helpManual->setStatusTip(tr("Launch the online manual"));
1066 connect(helpManual, SIGNAL(activated()), this, SLOT(slotHelpManual()));
1068 testDumpEntities = new QAction("Dump &Entities", this);
1069 connect(testDumpEntities, SIGNAL(activated()), this, SLOT(slotTestDumpEntities()));
1070 testDumpUndo = new QAction("Undo Info", this);
1071 connect(testDumpUndo, SIGNAL(activated()), this, SLOT(slotTestDumpUndo()));
1072 testUpdateInserts = new QAction("&Update Inserts", this);
1073 connect(testUpdateInserts, SIGNAL(activated()), this, SLOT(slotTestUpdateInserts()));
1074 testDrawFreehand = new QAction("Draw Freehand", this);
1075 connect(testDrawFreehand, SIGNAL(activated()), this, SLOT(slotTestDrawFreehand()));
1076 testInsertBlock = new QAction("Insert Block", this);
1077 connect(testInsertBlock, SIGNAL(activated()), this, SLOT(slotTestInsertBlock()));
1078 testInsertText = new QAction("Insert Text", this);
1079 connect(testInsertText, SIGNAL(activated()), this, SLOT(slotTestInsertText()));
1080 testInsertImage = new QAction("Insert Image", this);
1081 connect(testInsertImage, SIGNAL(activated()), this, SLOT(slotTestInsertImage()));
1082 testUnicode = new QAction("Unicode", this);
1083 connect(testUnicode, SIGNAL(activated()), this, SLOT(slotTestUnicode()));
1084 testInsertEllipse = new QAction("Insert Ellipse", this);
1085 connect(testInsertEllipse, SIGNAL(activated()), this, SLOT(slotTestInsertEllipse()));
1086 testMath01 = new QAction("Math01", this);
1087 connect(testMath01, SIGNAL(activated()), this, SLOT(slotTestMath01()));
1088 testResize640 = new QAction("Resize 1", this);
1089 connect(testResize640, SIGNAL(activated()), this, SLOT(slotTestResize640()));
1090 testResize800 = new QAction("Resize 2", this);
1091 connect(testResize800, SIGNAL(activated()), this, SLOT(slotTestResize800()));
1092 testResize1024 = new QAction("Resize 3", this);
1093 connect(testResize1024, SIGNAL(activated()), this, SLOT(slotTestResize1024()));
1097 * Initializes the menu bar.
1099 void ApplicationWindow::initMenuBar()
1101 DEBUG->print("ApplicationWindow::initMenuBar()");
1103 // menuBar entry windowsMenu
1104 windowsMenu = new QMenu(tr("&Window"), this);
1105 //according to docs, this is obsolete: windowsMenu->setCheckable(true);
1106 connect(windowsMenu, SIGNAL(aboutToShow()), this, SLOT(slotWindowsMenuAboutToShow()));
1108 // menuBar entry scriptMenu
1109 //scriptMenu = new QPopupMenu(this);
1110 //scriptMenu->setCheckable(true);
1111 //scriptOpenIDE->addTo(scriptMenu);
1112 //scriptRun->addTo(scriptMenu);
1113 //connect(scriptMenu, SIGNAL(aboutToShow()), this, SLOT(slotScriptMenuAboutToShow()));
1115 // menuBar entry helpMenu
1116 helpMenu = new QMenu(tr("&Help"), this);
1117 helpMenu->addAction(helpManual);
1118 helpMenu->addSeparator();
1119 helpMenu->addAction(helpAboutApp);
1121 // menuBar entry test menu
1122 testMenu = new QMenu(tr("De&bugging"), this);
1123 testMenu->addAction(testDumpEntities);
1124 testMenu->addAction(testDumpUndo);
1125 testMenu->addAction(testUpdateInserts);
1126 testMenu->addAction(testDrawFreehand);
1127 testMenu->addAction(testInsertBlock);
1128 testMenu->addAction(testInsertText);
1129 testMenu->addAction(testInsertImage);
1130 testMenu->addAction(testInsertEllipse);
1131 testMenu->addAction(testUnicode);
1132 testMenu->addAction(testMath01);
1133 testMenu->addAction(testResize640);
1134 testMenu->addAction(testResize800);
1135 testMenu->addAction(testResize1024);
1137 // menuBar configuration
1139 menuBar()->addMenu(scriptMenu);
1141 menuBar()->addMenu(windowsMenu);
1143 menuBar()->addMenu(helpMenu);
1146 menuBar()->addMenu(testMenu);
1148 recentFiles = new RecentFiles(this, fileMenu);
1152 * Initializes the tool bars (file tool bar and pen tool bar).
1154 void ApplicationWindow::initToolBar()
1156 DEBUG->print("ApplicationWindow::initToolBar()");
1158 fileToolBar = addToolBar(tr("File Operations"));
1159 fileToolBar->setObjectName("file");
1160 editToolBar = addToolBar(tr("Edit Operations"));
1161 editToolBar->setObjectName("edit");
1162 zoomToolBar = addToolBar(tr("Zoom Operations"));
1163 zoomToolBar->setObjectName("zoom");
1164 penToolBar = new PenToolBar(this, "Pen Selection");
1165 penToolBar->setObjectName("pen");
1167 connect(penToolBar, SIGNAL(penChanged(Pen)), this, SLOT(slotPenChanged(Pen)));
1169 // optionWidget = new Q3ToolBar(this, "Tool Options");
1170 //addToolBarBreak() does nothing...
1171 #warning "!!! add/insertToolBarBreak() does nothing !!!"
1172 // addToolBarBreak(Qt::TopToolBarArea);
1173 optionWidget = addToolBar(tr("Tool Options"));
1174 optionWidget->setObjectName("tooloptions");
1175 optionWidget->setMinimumHeight(26);
1176 optionWidget->setMaximumHeight(26);
1177 #warning "!!! No analogue found for setHorizontallyStretchable yet !!!"
1178 //Maybe sizePolicy or somesuch??
1179 optionWidget->setMinimumWidth(150);
1180 optionWidget->setMaximumWidth(800);
1181 #warning "Following line commented out..."
1182 // optionWidget->setFixedExtentHeight(26);
1183 // optionWidget->setHorizontallyStretchable(true);
1184 // addDockWindow(optionWidget, DockTop, true);
1186 // CAD toolbar left:
1187 // Q3ToolBar * t = new Q3ToolBar(this, "CAD Tools");
1188 QToolBar * t = addToolBar(tr("CAD Tools"));
1189 t->setObjectName("cadtools");
1190 #warning "Following two lines commented out..."
1191 // t->setFixedExtentWidth(59);
1192 t->setMinimumWidth(59);
1193 t->setMaximumWidth(59);
1194 // t->setVerticallyStretchable(true);
1195 // addDockWindow(t, Qt::DockLeft, false);
1196 addToolBar(Qt::LeftToolBarArea, t);
1198 cadToolBar = new CadToolBar(t);//, "CAD Tools");
1199 cadToolBar->createSubToolBars(actionHandler);
1201 connect(cadToolBar, SIGNAL(signalBack()), this, SLOT(slotBack()));
1202 connect(this, SIGNAL(windowsChanged(bool)), cadToolBar, SLOT(setEnabled(bool)));
1204 // QG_CadToolBarMain * cadToolBarMain = new QG_CadToolBarMain(cadToolBar);
1205 //No, no break inserted here either...
1206 // insertToolBarBreak(optionWidget);
1210 * Initializes the status bar at the bottom.
1212 void ApplicationWindow::initStatusBar()
1214 DEBUG->print("ApplicationWindow::initStatusBar()");
1216 statusBar()->setMinimumHeight(32);
1217 coordinateWidget = new CoordinateWidget(statusBar());
1218 statusBar()->addWidget(coordinateWidget);
1219 mouseWidget = new MouseWidget(statusBar());
1220 statusBar()->addWidget(mouseWidget);
1221 selectionWidget = new SelectionWidget(statusBar());
1222 statusBar()->addWidget(selectionWidget);
1226 * Initializes the global application settings from the
1227 * config file (unix, mac) or registry (windows).
1228 * (Actually, this uses the Qt settings subsystem, so we don't have to worry
1231 void ApplicationWindow::initSettings()
1233 DEBUG->print("ApplicationWindow::initSettings()");
1234 settings.beginGroup("RecentFiles");
1236 for(int i=0; i<recentFiles->Maximum(); ++i)
1238 QString filename = settings.value(QString("File") + QString::number(i + 1)).toString();
1240 if (!filename.isEmpty())
1241 recentFiles->add(filename);
1244 settings.endGroup();
1246 if (recentFiles->count() > 0)
1247 recentFiles->UpdateGUI();
1249 settings.beginGroup("Geometry");
1250 QSize windowSize = settings.value("WindowSize", QSize(950, 700)).toSize();
1251 QPoint windowPos = settings.value("WindowPos", QPoint(0, 30)).toPoint();
1252 restoreState(settings.value("DockWindows").toByteArray());
1253 settings.endGroup();
1256 if (windowSize.y() < 30)
1257 windowSize.y() = 30;
1265 * Stores the global application settings to file or registry.
1267 void ApplicationWindow::storeSettings()
1269 DEBUG->print("ApplicationWindow::storeSettings()");
1271 settings.beginGroup("RecentFiles");
1273 for(int i=0; i<recentFiles->count(); ++i)
1274 settings.setValue(QString("File") + QString::number(i + 1), recentFiles->get(i));
1276 settings.endGroup();
1278 settings.beginGroup("Geometry");
1279 settings.setValue("WindowSize", size());
1280 settings.setValue("WindowPos", pos());
1281 settings.setValue("DockWindows", saveState());
1282 settings.endGroup();
1284 DEBUG->print("ApplicationWindow::storeSettings(): OK");
1288 * Initializes the view.
1290 void ApplicationWindow::initView()
1292 DEBUG->print("ApplicationWindow::initView()");
1294 DEBUG->print("init view..");
1298 libraryWidget = NULL;
1299 commandWidget = NULL;
1301 simulationControls = NULL;
1305 DEBUG->print(" simulation widget..");
1306 dw = new QDockWidget(QDockWidget::InDock, this, "Simulation");
1307 simulationControls = new RS_SimulationControls(dw, "Simulation");
1308 simulationControls->setFocusPolicy(Qt::NoFocus);
1309 connect(simulationControls, SIGNAL(escape()), this, SLOT(slotFocus()));
1310 connect(this, SIGNAL(windowsChanged(bool)), simulationControls, SLOT(setEnabled(bool)));
1311 dw->setWidget(simulationControls);
1312 dw->resize(240, 80);
1313 dw->setResizeEnabled(true);
1314 dw->setFixedExtentWidth(120);
1315 dw->setFixedHeight(80);
1316 dw->setCaption(tr("Simulation Controls"));
1317 dw->setCloseMode(Q3DockWindow::Always);
1318 addDockWindow(dw, Qt::DockRight);
1319 simulationDockWindow = dw;
1320 //simulationDockWindow->hide();
1323 DEBUG->print(" layer widget..");
1324 // dw = new QDockWidget(QDockWidget::InDock, this, "Layer");
1325 dw = new QDockWidget(tr("Layer List"), this);
1326 dw->setObjectName("layer");
1327 layerWidget = new LayerWidget(actionHandler, dw, "Layer");
1328 layerWidget->setFocusPolicy(Qt::NoFocus);
1329 connect(layerWidget, SIGNAL(escape()), this, SLOT(slotFocus()));
1330 connect(this, SIGNAL(windowsChanged(bool)), layerWidget, SLOT(setEnabled(bool)));
1331 dw->setWidget(layerWidget);
1332 #warning "following four lines commented out..."
1333 // dw->setFixedExtentWidth(120);
1334 // dw->setResizeEnabled(true);
1335 // dw->setCloseMode(Q3DockWindow::Always);
1336 // dw->setCaption(tr("Layer List"));
1337 addDockWidget(Qt::RightDockWidgetArea, dw);
1338 layerDockWindow = dw;
1340 DEBUG->print(" block widget..");
1341 // dw = new QDockWidget(QDockWidget::InDock, this, "Block");
1342 dw = new QDockWidget(tr("Block List"), this);
1343 dw->setObjectName("block");
1344 blockWidget = new BlockWidget(actionHandler, dw, "Block");
1345 blockWidget->setFocusPolicy(Qt::NoFocus);
1346 connect(blockWidget, SIGNAL(escape()), this, SLOT(slotFocus()));
1347 connect(this, SIGNAL(windowsChanged(bool)), blockWidget, SLOT(setEnabled(bool)));
1348 dw->setWidget(blockWidget);
1349 #warning "following four lines commented out..."
1350 // dw->setFixedExtentWidth(120);
1351 // dw->setResizeEnabled(true);
1352 // dw->setCloseMode(Q3DockWindow::Always);
1353 // dw->setCaption(tr("Block List"));
1354 addDockWidget(Qt::RightDockWidgetArea, dw);
1355 blockDockWindow = dw;
1357 DEBUG->print(" library widget..");
1358 // dw = new QDockWidget(QDockWidget::OutsideDock, this, "Library");
1359 dw = new QDockWidget(tr("Library Browser"), this);
1360 dw->setObjectName("library");
1361 libraryWidget = new LibraryWidget(dw);//WAS:, "Library");
1362 libraryWidget->setActionHandler(actionHandler);
1363 libraryWidget->setFocusPolicy(Qt::NoFocus);
1364 connect(libraryWidget, SIGNAL(escape()), this, SLOT(slotFocus()));
1366 // connect(this, SIGNAL(windowsChanged(bool)), (QObject *)libraryWidget->bInsert, SLOT(setEnabled(bool)));
1367 dw->setWidget(libraryWidget);
1368 dw->resize(240, 400);
1369 #warning "following three lines commented out..."
1370 // dw->setResizeEnabled(true);
1371 // dw->setCloseMode(Q3DockWindow::Always);
1372 // dw->setCaption(tr("Library Browser"));
1373 //not sure how to fix this one
1374 #warning "QMainWindow::addDockWidget: invalid 'area' argument"
1375 // addDockWidget(Qt::NoDockWidgetArea, dw);
1376 //This works, but sux
1377 addDockWidget(Qt::RightDockWidgetArea, dw);
1378 libraryDockWindow = dw;
1379 // libraryDockWindow->hide();
1381 DEBUG->print(" command widget..");
1382 // dw = new QDockWidget(QDockWidget::InDock, this, "Command");
1383 dw = new QDockWidget(tr("Command line"), this);
1384 dw->setObjectName("command");
1385 commandWidget = new CommandWidget(dw);//WAS:, "Command");
1386 commandWidget->setActionHandler(actionHandler);
1387 // commandWidget->redirectStderr();
1388 // std::cerr << "Ready.\n";
1389 // commandWidget->processStderr();
1390 connect(this, SIGNAL(windowsChanged(bool)), commandWidget, SLOT(setEnabled(bool)));
1391 dw->setWidget(commandWidget);
1392 #warning "following four lines commented out..."
1393 // dw->setFixedExtentHeight(45);
1394 // dw->setResizeEnabled(true);
1395 // dw->setCloseMode(QDockWidget::Always);
1396 // dw->setCaption(tr("Command line"));
1397 commandDockWindow = dw;
1398 addDockWidget(Qt::BottomDockWidgetArea, dw);
1400 DEBUG->print(" done");
1404 * Goes back to the previous menu or one step in the current action.
1406 void ApplicationWindow::slotBack()
1408 GraphicView * graphicView = getGraphicView();
1411 graphicView->back();
1415 cadToolBar->showToolBar(RS2::ToolBarMain);
1420 * Goes one step further in the current action.
1422 void ApplicationWindow::slotEnter()
1424 if (!commandWidget || !commandWidget->checkFocus())
1427 cadToolBar->forceNext();
1430 GraphicView * graphicView = getGraphicView();
1433 graphicView->enter();
1439 * Sets the keyboard focus on the command line.
1441 void ApplicationWindow::slotFocusCommandLine()
1443 if (commandWidget->isVisible())
1444 commandWidget->setFocus();
1448 * Shows the given error on the command line.
1450 void ApplicationWindow::slotError(const QString & msg)
1452 commandWidget->appendHistory(msg);
1456 * Hands focus back to the application window. In the rare event of a escape
1457 * press from the layer widget (e.g after switching desktops in XP).
1459 void ApplicationWindow::slotFocus()
1465 * Called when a document window was activated.
1467 //void ApplicationWindow::slotWindowActivated(QMdiSubWindow * /*w*/)
1468 void ApplicationWindow::slotWindowActivated(QMdiSubWindow * sw)
1470 //This passes in a QMdiSubWindow, so why don't we use it???
1472 //#warning "!!! ApplicationWindow::slotWindowActivated() ignores passed in value !!!"
1473 DEBUG->print("ApplicationWindow::slotWindowActivated begin");
1475 //the following does: return (MDIWindow *)workspace->activeSubWindow();
1476 //which means the subwindow is NOT being activated!!!
1477 // MDIWindow * m = getMDIWindow();
1478 MDIWindow * m = (MDIWindow *)sw;
1479 DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::slotWindowActivated m=%08X", m);
1480 DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::slotWindowActivated m->getDoc=%08X",
1481 (m ? m->getDocument() : 0));
1483 if (m && m->getDocument())
1485 //m->setWindowState(WindowMaximized);
1487 DEBUG->print("ApplicationWindow::slotWindowActivated: document: %d", m->getDocument()->getId());
1489 bool showByBlock = m->getDocument()->rtti() == RS2::EntityBlock;
1490 layerWidget->setLayerList(m->getDocument()->getLayerList(), showByBlock);
1491 coordinateWidget->setGraphic(m->GetDrawing());
1494 simulationControls->setGraphicView(m->getGraphicView());
1497 // Only graphics show blocks. (blocks don't)
1498 // if (m->getDocument()->rtti() == RS2::EntityDrawing)
1499 // blockWidget->setBlockList(m->getDocument()->getBlockList());
1501 // blockWidget->setBlockList(NULL);
1502 blockWidget->setBlockList(m->getDocument()->rtti() == RS2::EntityDrawing
1503 ? m->getDocument()->getBlockList() : NULL);
1505 // Update all inserts in this graphic (blocks might have changed):
1506 m->getDocument()->updateInserts();
1507 m->getGraphicView()->redraw();
1509 // set snapmode from snapping menu
1510 actionHandler->updateSnapMode();
1512 // set pen from pen toolbar
1513 slotPenChanged(penToolBar->getPen());
1515 // update toggle button status:
1516 if (m->GetDrawing())
1518 //This is odd... why do this when you can just call the function directly? It's
1519 //IN this class after all...
1520 // emit(gridChanged(m->GetDrawing()->isGridOn()));
1521 // emit(printPreviewChanged(m->getGraphicView()->isPrintPreview()));
1522 actionViewGrid->setChecked(m->GetDrawing()->isGridOn());
1523 actionFilePrintPreview->setChecked(m->getGraphicView()->isPrintPreview());
1527 //This works, but for some reason after this function is over, the subwindow is no
1528 //longer activated. Need to find out why.
1529 //OK, I can see that the workspace isn't getting this window as activated or current.
1530 //Which means that something is definitely wrong here...
1532 //Seems to work now.
1533 //#warning "This is failing... !!! FIX !!!"
1534 printf("slotWindowActivated(QMdiSubWindow *): m=%08X, m->getDocument()=%08X...\n", (uint)m, (uint)(m ? m->getDocument() : 0));
1535 printf("slotWindowActivated(QMdiSubWindow *): activeWindow=%08X...\n", (uint)workspace->activeSubWindow());
1536 printf("slotWindowActivated(QMdiSubWindow *): currentWindow=%08X...\n", (uint)workspace->currentSubWindow());
1537 // slotWindowActivated(QMdiSubWindow * /*w*/): m=00000000, m->getDocument()=00000000...
1539 // Disable/Enable menu and toolbar items
1540 //This is odd... why do this when you can just call the function directly? It's
1541 //IN this class after all...
1542 emit(windowsChanged(m != NULL && m->getDocument() != NULL));
1544 DEBUG->print("ApplicationWindow::slotWindowActivated end");
1548 * Called when the menu 'windows' is about to be shown.
1549 * This is used to update the window list in the menu.
1551 void ApplicationWindow::slotWindowsMenuAboutToShow()
1553 DEBUG->print("ApplicationWindow::slotWindowsMenuAboutToShow");
1555 windowsMenu->clear();
1557 int cascadeId = windowsMenu->insertItem(tr("&Cascade"), workspace, SLOT(cascade()));
1558 int tileId = windowsMenu->insertItem(tr("&Tile"), this, SLOT(slotTileVertical()));
1559 int horTileId = windowsMenu->insertItem(tr("Tile &Horizontally"), this, SLOT(slotTileHorizontal()));
1561 if (workspace->subWindowList().isEmpty())
1563 windowsMenu->setItemEnabled(cascadeId, false);
1564 windowsMenu->setItemEnabled(tileId, false);
1565 windowsMenu->setItemEnabled(horTileId, false);
1568 windowsMenu->insertSeparator();
1570 #warning "!!! Qt4 implementation of insertItem is vastly different from Qt3--FIX !!!"
1572 QList<QMdiSubWindow *> windows = workspace->subWindowList();
1573 //printf("ApplicationWindow::slotWindowsMenuAboutToShow(): workspace->activeSubWindow = %08X\n", workspace->activeSubWindow());
1574 //printf("ApplicationWindow::slotWindowsMenuAboutToShow(): workspace->currentSubWindow = %08X\n", workspace->currentSubWindow());
1576 //#warning "Need to add window numbers underlined so can access windows via keyboard. !!! FIX !!!"
1578 for(int i=0; i<int(windows.count()); i++)
1580 //printf("--> Windows.at(i) = %08X\n", windows.at(i));
1581 // int id = windowsMenu->insertItem(windows.at(i)->caption(), this, SLOT(slotWindowsMenuActivated(int)));
1582 //For some reason the triggered() signal created here is type bool... Dunno why...
1583 //It's signalling using the QAction signal, which is type bool (checked or not).
1585 QString actionName = QString("&%1 %2").arg(i + 1).arg(windows.at(i)->windowTitle());
1586 // QAction * action = new QAction(windows.at(i)->windowTitle(), this);
1587 QAction * action = new QAction(actionName, this);
1588 action->setCheckable(true);
1590 //Neither of these work...
1591 // action->setChecked(workspace->activeSubWindow() == windows.at(i));
1592 action->setChecked(workspace->currentSubWindow() == windows.at(i));
1593 windowsMenu->addAction(action);
1594 connect(windowsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotWindowsMenuActivated(QAction *)));
1595 // connect(blockWidget, SIGNAL(escape()), this, SLOT(slotFocus()));
1597 QAction * id = windowsMenu->addAction(windows.at(i)->windowTitle(), this,
1598 // SLOT(slotWindowsMenuActivated(int)));
1599 SLOT(slotWindowsMenuActivated(QAction *)));
1601 // windowsMenu->setItemParameter(id, i);
1602 // windowsMenu->setItemChecked(id, workspace->activeSubWindow() == windows.at(i));
1604 id->setChecked(workspace->activeSubWindow() == windows.at(i));
1610 * Called when the user selects a document window from the
1613 void ApplicationWindow::slotWindowsMenuActivated(QAction * id)
1615 DEBUG->print("ApplicationWindow::slotWindowsMenuActivated");
1617 // QMdiSubWindow * w = workspace->subWindowList().at(id);
1618 QMdiSubWindow * w = workspace->subWindowList().at(id->data().toInt());
1619 printf("ApplicationWindow::slotWindowsMenuActivated: QMdiSubWindow * w = %08X\n", (uint32_t)w);
1622 workspace->setActiveSubWindow(w);
1623 // w->showMaximized();
1625 printf("--> w is%s activated (activeSW=%08X)\n", (workspace->activeSubWindow() ? "" : " NOT"), (uint32_t)(workspace->activeSubWindow()));
1629 * Tiles MDI windows horizontally.
1631 void ApplicationWindow::slotTileHorizontal()
1633 DEBUG->print("ApplicationWindow::slotTileHorizontal");
1636 // primitive horizontal tiling
1637 QWidgetList windows = workspace->windowList();
1639 if (windows.count() == 0)
1642 int heightForEach = workspace->height() / windows.count();
1645 for(int i=0; i<int(windows.count()); ++i)
1647 QWidget * window = windows.at(i);
1649 #warning "Need to port to Qt4... !!! FIX !!!"
1651 if (window->testWState(WState_Maximized))
1655 window->showNormal();
1659 int preferredHeight = window->minimumHeight() + window->parentWidget()->baseSize().height();
1660 int actHeight = QMAX(heightForEach, preferredHeight);
1662 // window->parentWidget()->resize(workspace->width(), actHeight);
1663 window->parentWidget()->setGeometry(0, y, workspace->width(), actHeight);
1667 workspace->tileSubWindows();
1672 * Tiles MDI windows vertically.
1674 void ApplicationWindow::slotTileVertical()
1680 QWidgetList windows = workspace->windowList();
1681 if (windows.count()==0) {
1685 //int heightForEach = workspace->height() / windows.count();
1687 for (int i=0; i<int(windows.count()); ++i) {
1688 QWidget *window = windows.at(i);
1689 if (window->testWState(WState_Maximized)) {
1692 window->showNormal();
1694 //int preferredHeight = window->minimumHeight()
1695 // + window->parentWidget()->baseSize().height();
1696 //int actHeight = QMAX(heightForEach, preferredHeight);
1698 //window->parentWidget()->setGeometry(0, y,
1699 // workspace->width(), actHeight);
1700 //window->parentWidget()->resize(window->parentWidget()->width(),
1701 // window->parentWidget()->height());
1702 //window->resize(window->width(), window->height());
1707 workspace->tileSubWindows();
1716 void ApplicationWindow::slotCamExportAuto() {
1717 printf("CAM export..\n");
1719 Document* d = getDocument();
1721 Drawing* graphic = (Drawing*)d;
1723 RS_CamDialog dlg(graphic, this);
1731 * Called when something changed in the pen tool bar (e.g. color, width,
1734 void ApplicationWindow::slotPenChanged(Pen pen)
1736 DEBUG->print("ApplicationWindow::slotPenChanged() begin");
1737 DEBUG->print("Setting active pen...");
1738 MDIWindow * m = getMDIWindow();
1741 m->slotPenChanged(pen);
1743 DEBUG->print("ApplicationWindow::slotPenChanged() end");
1747 * Creates a new MDI window with the given document or a new document if 'doc'
1750 MDIWindow * ApplicationWindow::slotFileNew(Document * doc/*= NULL*/)
1752 DEBUG->print("ApplicationWindow::slotFileNew() begin");
1757 statusBar()->showMessage(tr("Creating new file..."));
1759 //#warning "QWidget::setMinimumSize: (/QMdi::ControlLabel) Negative sizes (-1,-1) are not possible"
1760 DEBUG->print(" creating MDI window");
1761 // MDIWindow * w = new MDIWindow(doc, workspace, 0, Qt::WA_DeleteOnClose);
1762 MDIWindow * w = new MDIWindow(doc, workspace, 0, Qt::SubWindow);
1763 w->setAttribute(Qt::WA_DeleteOnClose);
1764 // w->setWindowState(WindowMaximized);
1765 connect(w, SIGNAL(signalClosing()), this, SLOT(slotFileClosing()));
1767 if (w->getDocument()->rtti() == RS2::EntityBlock)
1768 w->setWindowTitle(tr("Block '%1'").arg(((Block *)(w->getDocument()))->getName()));
1770 w->setWindowTitle(tr("Untitled Document %1").arg(id));
1772 w->setWindowIcon(QIcon(":/res/document.png"));
1775 // only graphics offer block lists, blocks don't
1776 DEBUG->print(" adding listeners");
1777 Drawing * graphic = w->getDocument()->getGraphic();
1779 if (graphic != NULL)
1781 // Link the graphic's layer list to the pen tool bar
1782 graphic->addLayerListListener(penToolBar);
1783 // Link the layer list to the layer widget
1784 graphic->addLayerListListener(layerWidget);
1785 // Link the block list to the block widget
1786 graphic->addBlockListListener(blockWidget);
1790 // Link the dialog factory to the mouse widget:
1791 QG_DIALOGFACTORY->setMouseWidget(mouseWidget);
1792 // Link the dialog factory to the coordinate widget:
1793 QG_DIALOGFACTORY->setCoordinateWidget(coordinateWidget);
1794 QG_DIALOGFACTORY->setSelectionWidget(selectionWidget);
1795 // Link the dialog factory to the option widget:
1796 // QG_DIALOGFACTORY->setOptionWidget(optionWidget);
1797 // Link the dialog factory to the cad tool bar:
1798 QG_DIALOGFACTORY->setCadToolBar(cadToolBar);
1799 // Link the dialog factory to the command widget:
1800 QG_DIALOGFACTORY->setCommandWidget(commandWidget);
1801 // Link the dialog factory to the main app window:
1802 QG_DIALOGFACTORY->setMainWindow(this);
1804 #if 1 //bugfix for Qt3->4 conversion
1805 DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::slotFileNew: adding window to workspace...");
1806 // workspace->addWindow(w);
1807 QMdiSubWindow * sw = workspace->addSubWindow(w);
1808 printf("MDIWindow=%08X, QMdiSubWindow=%08X\n", (uint)w, (uint)sw);
1811 DEBUG->print(" showing MDI window");
1814 #warning "w->showMaximized() doesn't seem to do anything here..."
1815 //but then again, the subWindowList isn't going to be empty at this point either...
1816 if (workspace->subWindowList().isEmpty())
1822 #warning "!!! SubWindow is not being activated !!!"
1823 //neither of these is working... Is the event being eaten somewhere???
1824 // workspace->activateNextSubWindow();
1826 //printf("--> ApplicationWindow::slotFileNew(): w %s focus...\n", (w->hasFocus() ? "has" : "DOES NOT HAVE"));
1828 //neither of these work either
1829 //w->activateWindow();
1831 //w->activateWindow();
1834 //not anymore... #warning "!!! Parameter to slotWindowActivated() is ignored !!!"
1835 //Hm, this should be called when the window is actually activated by the QMdiArea...
1836 //Not sure why this isn't happening...
1837 // slotWindowActivated(w);
1838 statusBar()->showMessage(tr("New Drawing created."), 2000);
1840 DEBUG->print("ApplicationWindow::slotFileNew() OK");
1847 * Menu file -> open.
1849 void ApplicationWindow::slotFileOpen()
1851 DEBUG->print("ApplicationWindow::slotFileOpen()");
1853 DEBUG->print("ApplicationWindow::slotFileOpen() 001");
1854 RS2::FormatType type = RS2::FormatUnknown;
1855 DEBUG->print("ApplicationWindow::slotFileOpen() 002");
1856 QString fileName = FileDialog::getOpenFileName(this, &type);
1857 DEBUG->print("ApplicationWindow::slotFileOpen() 003");
1858 slotFileOpen(fileName, type);
1859 DEBUG->print("ApplicationWindow::slotFileOpen(): OK");
1863 * Called when a recently opened file is chosen from the list in the
1866 void ApplicationWindow::slotFileOpenRecent(void)
1869 DEBUG->print("ApplicationWindow::slotFileOpenRecent()");
1871 statusBar()->showMessage(tr("Opening recent file..."));
1872 QString fileName = recentFiles->get(id);
1874 if (fileName.endsWith(" (DXF 1)"))
1875 slotFileOpen(fileName.left(fileName.length() - 8), RS2::FormatDXF1);
1877 slotFileOpen(fileName, RS2::FormatUnknown);
1879 statusBar()->showMessage(tr("Opening recent file..."));
1881 QAction * action = qobject_cast<QAction *>(sender());
1886 QString fileName = action->data().toString();
1888 if (fileName.endsWith(" (DXF 1)"))
1889 slotFileOpen(fileName.left(fileName.length() - 8), RS2::FormatDXF1);
1891 slotFileOpen(fileName, RS2::FormatUnknown);
1896 * Menu file -> open.
1898 void ApplicationWindow::slotFileOpen(const QString & fileName, RS2::FormatType type)
1900 DEBUG->print("ApplicationWindow::slotFileOpen(..)");
1901 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1903 if (!fileName.isEmpty())
1905 DEBUG->print("ApplicationWindow::slotFileOpen: creating new doc window");
1906 // Create new document window:
1907 MDIWindow * w = slotFileNew();
1908 DEBUG->print("ApplicationWindow::slotFileOpen: linking layer list");
1909 // link the layer widget to the new document:
1910 layerWidget->setLayerList(w->getDocument()->getLayerList(), false);
1911 // link the block widget to the new document:
1912 blockWidget->setBlockList(w->getDocument()->getBlockList());
1913 // link coordinate widget to graphic
1914 coordinateWidget->setGraphic(w->GetDrawing());
1916 // link the layer widget to the new document:
1917 simulationControls->setGraphicView(w->getGraphicView());
1919 DEBUG->print("ApplicationWindow::slotFileOpen: open file");
1921 // Open the file in the new view:
1922 if (!w->slotFileOpen(fileName, type))
1925 QApplication::restoreOverrideCursor();
1926 QMessageBox::information(this, QMessageBox::tr("Warning"),
1927 tr("Cannot open the file\n%1\nPlease check the permissions.") .arg(fileName), QMessageBox::Ok);
1928 // w->setForceClosing(true);
1933 DEBUG->print("ApplicationWindow::slotFileOpen: open file: OK");
1934 DEBUG->print("ApplicationWindow::slotFileOpen: update recent file menu: 1");
1936 // update recent files menu:
1937 if (type == RS2::FormatDXF1)
1938 recentFiles->add(fileName + " (DXF 1)");
1940 recentFiles->add(fileName);
1942 DEBUG->print("ApplicationWindow::slotFileOpen: update recent file menu: 2");
1943 recentFiles->UpdateGUI();
1944 DEBUG->print("ApplicationWindow::slotFileOpen: update recent file menu: OK");
1945 DEBUG->print("ApplicationWindow::slotFileOpen: set caption");
1947 w->setWindowTitle(fileName);
1948 DEBUG->print("ApplicationWindow::slotFileOpen: set caption: OK");
1949 DEBUG->print("ApplicationWindow::slotFileOpen: update coordinate widget");
1950 // update coordinate widget format:
1951 DIALOGFACTORY->updateCoordinateWidget(Vector(0.0, 0.0), Vector(0.0, 0.0), true);
1952 DEBUG->print("ApplicationWindow::slotFileOpen: update coordinate widget: OK");
1953 // Update the layer and block widgets (document just loaded may have some)
1954 layerWidget->update();
1955 blockWidget->update();
1956 // show output of filter (if any):
1957 QString message = tr("Loaded document: ") + fileName;
1958 commandWidget->appendHistory(message);
1959 statusBar()->showMessage(message, 2000);
1963 statusBar()->showMessage(tr("Opening aborted"), 2000);
1966 QApplication::restoreOverrideCursor();
1967 DEBUG->print("ApplicationWindow::slotFileOpen(..) OK");
1971 * Menu file -> save.
1973 void ApplicationWindow::slotFileSave()
1975 DEBUG->print("ApplicationWindow::slotFileSave()");
1977 statusBar()->showMessage(tr("Saving drawing..."));
1979 MDIWindow * w = getMDIWindow();
1984 if (w->getDocument()->getFilename().isEmpty())
1990 if (w->slotFileSave(cancelled))
1994 name = w->getDocument()->getFilename();
1995 statusBar()->showMessage(tr("Saved drawing: %1").arg(name), 2000);
2001 QMessageBox::information(this, QMessageBox::tr("Warning"),
2002 tr("Cannot save the file\n%1\nPlease check the permissions.")
2003 .arg(w->getDocument()->getFilename()), QMessageBox::Ok);
2010 * Menu file -> save as.
2012 void ApplicationWindow::slotFileSaveAs()
2014 DEBUG->print("ApplicationWindow::slotFileSaveAs()");
2016 statusBar()->showMessage(tr("Saving drawing under new filename..."));
2018 MDIWindow * w = getMDIWindow();
2025 if (w->slotFileSaveAs(cancelled))
2029 name = w->getDocument()->getFilename();
2030 recentFiles->add(name);
2031 w->setWindowTitle(name);
2037 QMessageBox::information(this, QMessageBox::tr("Warning"),
2038 tr("Cannot save the file\n%1\nPlease check the permissions.")
2039 .arg(w->getDocument()->getFilename()), QMessageBox::Ok);
2043 // updateRecentFilesMenu();
2044 recentFiles->UpdateGUI();
2046 QString message = tr("Saved drawing: %1").arg(name);
2047 statusBar()->showMessage(message, 2000);
2048 commandWidget->appendHistory(message);
2052 * Menu file -> export.
2054 void ApplicationWindow::slotFileExport()
2056 DEBUG->print("ApplicationWindow::slotFileExport()");
2057 statusBar()->showMessage(tr("Exporting drawing..."));
2058 MDIWindow * w = getMDIWindow();
2063 // read default settings:
2064 settings.beginGroup("Paths");
2065 QString defDir = settings.value("ExportImage", SYSTEM->getHomeDir()).toString();
2066 QString defFilter = settings.value("ExportImageFilter", "Portable Network Graphic (*.png)").toString();
2067 settings.endGroup();
2069 bool cancel = false;
2071 // Q3FileDialog fileDlg(NULL, "", true);
2072 QFileDialog fileDlg(NULL, "", "", "");
2074 #warning "Need to port to Qt4... !!! FIX !!!"
2076 Q3StrList f = QImageIO::outputFormats();
2077 QStringList formats = QStringList::fromStrList(f);
2078 QStringList filters;
2081 for (QStringList::Iterator it = formats.begin();
2082 it!=formats.end(); ++it)
2087 st = QString("%1 (*.%2 *.jpg)")
2088 .arg(QG_DialogFactory::extToFormat(*it))
2089 .arg(QString(*it).lower());
2093 st = QString("%1 (*.%2)")
2094 .arg(QG_DialogFactory::extToFormat(*it))
2095 .arg(QString(*it).lower());
2100 //if (!all.isEmpty()) {
2103 //all += QString("*.%1").arg(QString(*it).lower());
2106 QStringList filters;
2109 fileDlg.setFilters(filters);
2110 // fileDlg.setMode(Q3FileDialog::AnyFile);
2111 fileDlg.setFileMode(QFileDialog::AnyFile);
2112 // fileDlg.setCaption(QObject::tr("Export Image"));
2113 fileDlg.setWindowTitle(QObject::tr("Export Image"));
2114 // fileDlg.setDir(defDir);
2115 fileDlg.setDirectory(defDir);
2116 fileDlg.selectNameFilter(defFilter);
2118 if (fileDlg.exec() == QDialog::Accepted)
2120 // fn = fileDlg.selectedFile();
2121 QStringList files = fileDlg.selectedFiles();
2123 if (!files.isEmpty())
2131 // store new default settings:
2134 settings.beginGroup("Paths");
2135 // settings.writeEntry("/ExportImage", QFileInfo(fn).dirPath(true));
2136 settings.setValue("ExportImage", QFileInfo(fn).absolutePath());
2137 settings.setValue("ExportImageFilter", fileDlg.selectedFilter());
2138 settings.endGroup();
2140 // find out extension:
2141 QString filter = fileDlg.selectedFilter();
2142 QString format = "";
2143 // int i = filter.find("(*.");
2144 int i = filter.indexOf("(*.");
2148 // int i2 = filter.find(QRegExp("[) ]"), i);
2149 int i2 = filter.indexOf(QRegExp("[) ]"), i);
2150 format = filter.mid(i + 3, i2 - (i + 3));
2151 format = format.toUpper();
2154 // append extension to file:
2155 if (!QFileInfo(fn).fileName().contains("."))
2156 fn.append("." + format.toLower());
2158 // show options dialog:
2159 ImageOptionsDialog dlg(this);
2160 dlg.setGraphicSize(w->GetDrawing()->getSize());
2164 bool ret = slotFileExport(fn, format, dlg.getSize(), dlg.isBackgroundBlack());
2168 QString message = tr("Exported: %1").arg(fn);
2169 statusBar()->showMessage(message, 2000);
2170 commandWidget->appendHistory(message);
2178 * Exports the drawing as a bitmap.
2180 * @param name File name.
2181 * @param format File format (e.g. "png")
2182 * @param size Size of the bitmap in pixel
2183 * @param black true: Black background, false: white
2184 * @param bw true: black/white export, false: color
2186 bool ApplicationWindow::slotFileExport(const QString & name, const QString & format, QSize size, bool black, bool bw)
2188 MDIWindow * w = getMDIWindow();
2192 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFileExport: no window opened");
2196 Drawing * drawing = w->getDocument()->GetDrawing();
2200 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFileExport: no drawing");
2204 statusBar()->showMessage(tr("Exporting..."));
2205 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
2208 QPixmap * buffer = new QPixmap(size);
2209 // RS_PainterQt * painter = new RS_PainterQt(buffer);
2210 QPainter qpntr(buffer);
2211 PaintInterface * painter = new PaintInterface(&qpntr);
2213 // black background:
2215 // painter->setBackgroundColor(Color(0, 0, 0));
2216 // qpntr.setBackgroundColor(Color(0, 0, 0));
2217 qpntr.setBackground(QBrush(QColor(0, 0, 0)));
2218 // white background:
2220 // painter->setBackgroundColor(Color(255, 255, 255));
2221 // qpntr.setBackgroundColor(Color(255, 255, 255));
2222 qpntr.setBackground(QBrush(QColor(255, 255, 255)));
2226 painter->setDrawingMode(RS2::ModeBW);
2228 // painter->eraseRect(0, 0, size.width(), size.height());
2229 qpntr.eraseRect(0, 0, size.width(), size.height());
2231 StaticGraphicView gv(size.width(), size.height(), painter);
2234 gv.setBackground(Color(0, 0, 0));
2236 gv.setBackground(Color(255, 255, 255));
2238 gv.setContainer(drawing);
2240 gv.drawEntity(drawing, true);
2247 iio.setFileName(name);
2248 iio.setFormat(format);
2255 // QImage image = buffer->toImage();
2256 // QImageWriter writer;
2257 // writer.setFileName(name);
2258 // writer.setFormat(format.toAscii().data());
2259 QImageWriter writer(name, format.toAscii().data());
2261 // if (writer.write(image))
2262 if (writer.write(buffer->toImage()))
2266 QApplication::restoreOverrideCursor();
2272 statusBar()->showMessage(tr("Export complete"), 2000);
2274 statusBar()->showMessage(tr("Export failed!"), 2000);
2280 * Menu file -> close.
2282 void ApplicationWindow::slotFileClose()
2284 DEBUG->print("ApplicationWindow::slotFileClose()");
2286 MDIWindow * m = getMDIWindow();
2295 //m->showMaximized();
2296 m->setWindowState(WindowMaximized);
2302 * Called when a MDI window is actually about to close. Used to
2303 * detach widgets from the document.
2305 void ApplicationWindow::slotFileClosing()
2307 DEBUG->print("ApplicationWindow::slotFileClosing()");
2309 DEBUG->print("detaching lists");
2310 layerWidget->setLayerList(NULL, false);
2311 blockWidget->setBlockList(NULL);
2312 coordinateWidget->setGraphic(NULL);
2314 simulationControls->setGraphicView(NULL);
2319 * Menu file -> print.
2321 void ApplicationWindow::slotFilePrint()
2323 DEBUG->print("ApplicationWindow::slotFilePrint()");
2325 MDIWindow * w = getMDIWindow();
2329 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFilePrint: no window opened");
2333 Drawing * drawing = w->getDocument()->GetDrawing();
2335 if (drawing == NULL)
2337 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFilePrint: no drawing");
2341 statusBar()->showMessage(tr("Printing..."));
2342 QPrinter * printer = new QPrinter(QPrinter::HighResolution);
2343 bool landscape = false;
2344 printer->setPageSize(RS2::rsToQtPaperFormat(drawing->getPaperFormat(&landscape)));
2347 printer->setOrientation(QPrinter::Landscape);
2349 printer->setOrientation(QPrinter::Portrait);
2351 settings.beginGroup("Print");
2352 printer->setOutputFileName(settings.value("FileName", "").toString());
2353 printer->setColorMode((QPrinter::ColorMode)settings.value("/ColorMode", (int)QPrinter::Color).toInt());
2354 #warning "!!! Need to port QPrinter::setOutputToFile() to Qt4 !!!"
2355 // printer->setOutputToFile((bool)RS_SETTINGS->readNumEntry("/PrintToFile", 0));
2356 settings.endGroup();
2359 // if (printer->setup(this))
2360 QPrintDialog dialog(printer, this);
2364 //printer->setOutputToFile(true);
2365 //printer->setOutputFileName(outputFile);
2367 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
2368 printer->setFullPage(true);
2369 //Can call these functions directly from the QPaintDevice...
2370 // Q3PaintDeviceMetrics metr(printer);
2372 // RS_PainterQt * painter = new RS_PainterQt(printer);
2373 QPainter qpntr(printer);
2374 PaintInterface * painter = new PaintInterface(&qpntr);
2375 painter->setDrawingMode(w->getGraphicView()->getDrawingMode());
2377 // StaticGraphicView gv(metr.width(), metr.height(), painter);
2378 StaticGraphicView gv(printer->width(), printer->height(), painter);
2379 gv.setPrinting(true);
2380 gv.setBorders(0, 0, 0, 0);
2382 // double fx = (double)metr.width() / metr.widthMM() * Units::getFactorToMM(graphic->getUnit());
2383 // double fy = (double)metr.height() / metr.heightMM() * Units::getFactorToMM(graphic->getUnit());
2384 double fx = (double)printer->width() / printer->widthMM() * Units::getFactorToMM(drawing->getUnit());
2385 double fy = (double)printer->height() / printer->heightMM() * Units::getFactorToMM(drawing->getUnit());
2386 double f = (fx + fy) / 2;
2387 double scale = drawing->getPaperScale();
2389 gv.setOffset((int)(drawing->getPaperInsertionBase().x * f),
2390 (int)(drawing->getPaperInsertionBase().y * f));
2391 gv.setFactor(f * scale);
2392 gv.setContainer(drawing);
2393 gv.drawEntity(drawing, true);
2397 settings.beginGroup("Print");
2398 #warning "!!! Need to port QPrinter::outputToFile() to Qt4 !!!"
2399 // settings.writeEntry("/PrintToFile", (int)printer->outputToFile());
2400 settings.setValue("ColorMode", (int)printer->colorMode());
2401 settings.setValue("FileName", printer->outputFileName());
2402 settings.endGroup();
2403 QApplication::restoreOverrideCursor();
2408 statusBar()->showMessage(tr("Printing complete"), 2000);
2412 * Menu file -> print preview.
2414 void ApplicationWindow::slotFilePrintPreview(bool on)
2416 DEBUG->print("ApplicationWindow::slotFilePrintPreview()");
2418 DEBUG->print(" creating MDI window");
2419 MDIWindow * parent = getMDIWindow();
2423 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFilePrintPreview: no window opened");
2427 // Close print preview:
2430 DEBUG->print("ApplicationWindow::slotFilePrintPreview(): off");
2432 if (parent->getGraphicView()->isPrintPreview())
2434 DEBUG->print("ApplicationWindow::slotFilePrintPreview(): close");
2438 // Open print preview:
2441 // look for an existing print preview:
2442 MDIWindow * ppv = parent->getPrintPreview();
2446 DEBUG->print("ApplicationWindow::slotFilePrintPreview(): show existing");
2447 slotWindowActivated(ppv);
2452 if (!parent->getGraphicView()->isPrintPreview())
2454 DEBUG->print("ApplicationWindow::slotFilePrintPreview(): create");
2456 MDIWindow * w = new MDIWindow(parent->getDocument(), workspace, 0, Qt::SubWindow);
2457 w->setAttribute(Qt::WA_DeleteOnClose);
2458 parent->addChildWindow(w);
2460 // w->setCaption(tr("Print preview for %1").arg(parent->caption()));
2461 w->setWindowTitle(tr("Print preview for %1").arg(parent->windowTitle()));
2462 // w->setIcon(qPixmapFromMimeSource("document.png"));
2463 // w->setWindowIcon(qPixmapFromMimeSource("document.png"));
2464 w->setWindowIcon(QIcon(":/res/document.png"));
2465 w->getGraphicView()->setPrintPreview(true);
2466 w->getGraphicView()->setBackground(Color(255, 255, 255));
2467 w->getGraphicView()->setDefaultAction(new ActionPrintPreview(*w->getDocument(), *w->getGraphicView()));
2469 // Only drawings offer block lists; blocks themselves don't
2470 // DEBUG->print(" adding listeners");
2471 Drawing * drawing = w->getDocument()->GetDrawing();
2475 // Center by default:
2476 drawing->centerToPage();
2479 // Link the graphic view to the mouse widget:
2480 QG_DIALOGFACTORY->setMouseWidget(mouseWidget);
2481 // Link the graphic view to the coordinate widget:
2482 QG_DIALOGFACTORY->setCoordinateWidget(coordinateWidget);
2483 QG_DIALOGFACTORY->setSelectionWidget(selectionWidget);
2484 // Link the graphic view to the option widget:
2485 //QG_DIALOGFACTORY->setOptionWidget(optionWidget);
2486 // Link the graphic view to the cad tool bar:
2487 QG_DIALOGFACTORY->setCadToolBar(cadToolBar);
2488 // Link the graphic view to the command widget:
2489 QG_DIALOGFACTORY->setCommandWidget(commandWidget);
2491 DEBUG->print(" showing MDI window");
2493 if (workspace->subWindowList().isEmpty())
2498 w->getGraphicView()->zoomPage();
2501 slotWindowActivated(w);
2508 * Menu file -> quit.
2510 void ApplicationWindow::slotFileQuit()
2512 DEBUG->print("ApplicationWindow::slotFileQuit()");
2514 statusBar()->showMessage(tr("Exiting application..."));
2521 * Shows/hides the grid.
2523 * @param toggle true: show, false: hide.
2525 void ApplicationWindow::slotViewGrid(bool toggle)
2527 DEBUG->print("ApplicationWindow::slotViewGrid()");
2529 MDIWindow * m = getMDIWindow();
2533 Drawing * d = m->GetDrawing();
2536 d->setGridOn(toggle);
2542 DEBUG->print("ApplicationWindow::slotViewGrid() OK");
2546 * Enables/disables draft mode.
2548 * @param toggle true: enable, false: disable.
2550 void ApplicationWindow::slotViewDraft(bool toggle)
2552 DEBUG->print("ApplicationWindow::slotViewDraft()");
2554 settings.beginGroup("Appearance");
2555 settings.setValue("DraftMode", toggle);
2556 settings.endGroup();
2562 * Redraws all MDI windows.
2564 void ApplicationWindow::redrawAll()
2566 if (workspace == NULL)
2569 QList<QMdiSubWindow *> windows = workspace->subWindowList();
2571 for(int i=0; i<windows.count(); i++)
2573 QG_GraphicView * gv = ((MDIWindow *)windows.at(i))->getGraphicView();
2581 * Updates all grids of all graphic views.
2583 void ApplicationWindow::updateGrids()
2585 if (workspace == NULL)
2588 QList<QMdiSubWindow *> windows = workspace->subWindowList();
2590 for(int i=0; i<windows.count(); i++)
2592 QG_GraphicView * gv = ((MDIWindow *)windows.at(i))->getGraphicView();
2600 * Shows / hides the status bar.
2602 * @param showSB true: show, false: hide.
2604 void ApplicationWindow::slotViewStatusBar(bool showSB)
2606 DEBUG->print("ApplicationWindow::slotViewStatusBar()");
2609 statusBar()->show();
2611 statusBar()->hide();
2615 * Shows the dialog for general application preferences.
2617 void ApplicationWindow::slotOptionsGeneral()
2619 DIALOGFACTORY->requestOptionsGeneralDialog();
2621 // Update background color of all open drawings:
2622 settings.beginGroup("Appearance");
2623 QColor color(settings.value("BackgroundColor", "#000000").toString());
2624 QColor gridColor(settings.value("GridColor", "Gray").toString());
2625 QColor metaGridColor(settings.value("MetaGridColor", "Darkgray").toString());
2626 QColor selectedColor(settings.value("SelectedColor", "#A54747").toString());
2627 QColor highlightedColor(settings.value("HighlightedColor", "#739373").toString());
2628 settings.endGroup();
2630 QList<QMdiSubWindow *> windows = workspace->subWindowList();
2632 for(int i=0; i<int(windows.count()); i++)
2634 MDIWindow * m = (MDIWindow *)windows.at(i);
2638 QG_GraphicView * gv = m->getGraphicView();
2642 gv->setBackground(color);
2643 gv->setGridColor(gridColor);
2644 gv->setMetaGridColor(metaGridColor);
2645 gv->setSelectedColor(selectedColor);
2646 gv->setHighlightedColor(highlightedColor);
2655 * Menu script -> show ide
2657 void ApplicationWindow::slotScriptOpenIDE()
2660 scripter->openIDE();
2665 * Menu script -> run
2667 void ApplicationWindow::slotScriptRun()
2670 scripter->runScript();
2675 * Menu help -> about.
2677 void ApplicationWindow::slotHelpAbout()
2679 DEBUG->print("ApplicationWindow::slotHelpAbout()");
2681 QStringList modules;
2688 modules += "Scripting";
2691 QString modulesString;
2693 if (!modules.empty())
2694 modulesString = modules.join(", ");
2696 modulesString = tr("None");
2699 QMessageBox box(this);
2700 box.setWindowTitle(tr("About..."));
2701 box.setText(QString("<center>")
2702 + "<h2>Architektonas</h2>"
2703 + tr("Version: %1").arg("1.0.0") + "<br>"
2704 + tr("Date: %1").arg(__DATE__) + "<br>"
2705 + QString("© 2010 Underground Software,<br>James Hammons") + "<br>"
2706 + QString("Portions © 2001-2003 RibbonSoft") + "<br>"
2707 + QString("</center>")
2709 #ifndef QC_ABOUT_HEADER
2710 #warning "Failure..."
2711 // box.setIcon(qPixmapFromMimeSource(QC_APP_ICON));
2712 box.setFixedWidth(340);
2713 box.setFixedHeight(250);
2719 * Menu help -> help.
2721 void ApplicationWindow::slotHelpManual()
2723 #warning "No help system ported to Qt4... !!! FIX !!!"
2725 DEBUG->print("ApplicationWindow::slotHelpManual()");
2727 if (assistant == NULL)
2729 DEBUG->print("ApplicationWindow::slotHelpManual(): appdir: %s", SYSTEM->getAppDir().toLatin1().data());
2730 DEBUG->print("ApplicationWindow::slotHelpManual(): appdir: %s", SYSTEM->getAppDir().toLatin1().data());
2731 assistant = new QAssistantClient(SYSTEM->getAppDir()+"/bin", this);
2732 connect(assistant, SIGNAL(error(const QString&)), this, SLOT(slotError(const QString&)));
2735 args << QDir::convertSeparators(SYSTEM->getDocPath() + "/qcaddoc.adp");
2736 // args << QString("doc") + QDir::separator() + QString("qcaddoc.adp");
2738 #if QT_VERSION>=0x030200
2739 assistant->setArguments(args);
2742 assistant->openAssistant();
2743 //assistant->showPage("index.html");
2750 void ApplicationWindow::slotTestDumpEntities(EntityContainer * d)
2752 DEBUG->print("ApplicationWindow::slotTestDumpEntities()");
2753 static int level = 0;
2754 std::ofstream dumpFile;
2759 dumpFile.open("debug_entities.html");
2764 dumpFile.open("debug_entities.html", std::ios::app);
2772 dumpFile << "<html>\n";
2773 dumpFile << "<body>\n";
2776 for (Entity* e=d->firstEntity();
2781 dumpFile << "<table border=\"1\">\n";
2782 dumpFile << "<tr><td>Entity: " << e->getId()
2786 << "<tr><td><table><tr>"
2787 << "<td>VIS:" << e->isVisible() << "</td>"
2788 << "<td>UND:" << e->isUndone() << "</td>"
2789 << "<td>SEL:" << e->isSelected() << "</td>"
2790 << "<td>TMP:" << e->getFlag(RS2::FlagTemp) << "</td>";
2791 QString lay = "NULL";
2792 if (e->getLayer()!=NULL) {
2793 lay = e->getLayer()->getName();
2796 //fail << "<td>Layer: " << lay << "</td>"
2797 << "<td>Width: " << (int)e->getPen(false).getWidth() << "</td>"
2798 << "<td>Parent: " << e->getParent()->getId() << "</td>"
2806 case RS2::EntityPoint:
2808 Point* p = (Point*)e;
2810 << "<table><tr><td>"
2822 case RS2::EntityLine:
2826 << "<table><tr><td>"
2832 << l->getStartpoint()
2841 case RS2::EntityArc: {
2844 << "<table><tr><td>"
2861 << "<td>Startpoint: "
2862 << a->getStartpoint()
2868 << (int)a->isReversed()
2874 case RS2::EntityCircle: {
2875 Circle* c = (Circle*)e;
2877 << "<table><tr><td>"
2892 case RS2::EntityDimAligned: {
2893 DimAligned* d = (DimAligned*)e;
2895 << "<table><tr><td>"
2896 << "<b>Dimension / Aligned:</b>"
2901 << d->getDefinitionPoint()
2904 << d->getExtensionPoint1()
2907 << d->getExtensionPoint2()
2910 << d->getText().toLatin1().data()
2913 << d->getLabel().toLatin1().data()
2919 case RS2::EntityDimLinear:
2921 DimLinear* d = (DimLinear*)e;
2923 << "<table><tr><td>"
2924 << "<b>Dimension / Linear:</b>"
2929 << d->getDefinitionPoint()
2932 << d->getExtensionPoint1()
2935 << d->getExtensionPoint2()
2938 //fail << d->getText()
2941 //fail << d->getLabel()
2947 case RS2::EntityInsert: {
2948 Insert* i = (Insert*)e;
2950 << "<table><tr><td>"
2955 << "<td>Insertion point:"
2956 << i->getInsertionPoint()
2962 case RS2::EntityText: {
2965 << "<table><tr><td>"
2971 << t->getText().toLatin1().data()
2980 case RS2::EntityHatch: {
2981 Hatch* h = (Hatch*)e;
2983 << "<table><tr><td>"
2989 << h->getPattern().toLatin1().data()
2995 << (int)h->isSolid()
3004 << "<b>Unknown Entity: " << e->rtti() << "</b>"
3009 if (e->isContainer() || e->rtti()==RS2::EntityHatch) {
3010 EntityContainer* ec = (EntityContainer*)e;
3011 dumpFile << "<table><tr><td valign=\"top\"> Contents:</td><td>\n";
3013 slotTestDumpEntities(ec);
3014 dumpFile.open("debug_entities.html", std::ios::app);
3015 dumpFile << "</td></tr></table>\n";
3025 dumpFile << "</body>\n";
3026 dumpFile << "</html>\n";
3036 void ApplicationWindow::slotTestDumpUndo()
3038 DEBUG->print("ApplicationWindow::slotTestDumpUndo()");
3040 Document * d = getDocument();
3044 std::cout << *(Undo*)d;
3045 std::cout << std::endl;
3052 void ApplicationWindow::slotTestUpdateInserts()
3054 DEBUG->print("ApplicationWindow::slotTestUpdateInserts()");
3056 Document * d = getDocument();
3065 void ApplicationWindow::slotTestDrawFreehand()
3067 DEBUG->print("ApplicationWindow::slotTestDrawFreehand()");
3069 //Drawing* g = document->getMarking();
3072 ActionDrawLineFree* action =
3073 new ActionDrawLineFree(*document->getGraphic(),
3076 for (int i=0; i<100; ++i) {
3078 int posx = (random()%600);
3079 int posy = (random()%400);
3081 //RS_MouseEvent rsm1(posx, posy, LEFT);
3082 RS_MouseEvent rsm1(QEvent::MouseButtonPress,
3086 action->mousePressEvent(&rsm1);
3091 for (int k=0; k<100; ++k) {
3092 int accx = (random()%40)-20;
3093 int accy = (random()%40)-20;
3101 //RS_MouseEvent rsm2(posx, posy, LEFT);
3103 RS_MouseEvent rsm2(QEvent::MouseMove,
3107 action->mouseMoveEvent(&rsm2);
3110 action->mouseReleaseEvent(NULL);
3122 void ApplicationWindow::slotTestInsertBlock()
3124 DEBUG->print("ApplicationWindow::slotTestInsertBlock()");
3126 Document * d = getDocument();
3128 if (d != NULL && d->rtti() == RS2::EntityDrawing)
3130 Drawing * graphic = (Drawing *)d;
3132 if (graphic == NULL)
3135 graphic->addLayer(new Layer("default"));
3136 Block * block = new Block(graphic, BlockData("debugblock", Vector(0.0, 0.0), true));
3142 // Add one red line:
3143 line = new Line(block, LineData(Vector(0.0, 0.0), Vector(50.0, 0.0)));
3144 line->setLayerToActive();
3145 line->setPen(Pen(Color(255, 0, 0), RS2::Width01, RS2::SolidLine));
3146 block->addEntity(line);
3148 // Add one line with attributes from block:
3149 line = new Line(block, LineData(Vector(50.0, 0.0), Vector(50.0, 50.0)));
3150 line->setPen(Pen(Color(RS2::FlagByBlock), RS2::WidthByBlock, RS2::LineByBlock));
3151 block->addEntity(line);
3153 // Add one arc with attributes from block:
3154 ArcData d(Vector(50.0, 0.0), 50.0, M_PI / 2.0, M_PI, false);
3155 arc = new Arc(block, d);
3156 arc->setPen(Pen(Color(RS2::FlagByBlock), RS2::WidthByBlock, RS2::LineByBlock));
3157 block->addEntity(arc);
3159 // Add one blue circle:
3160 CircleData circleData(Vector(20.0, 15.0), 12.5);
3161 circle = new Circle(block, circleData);
3162 circle->setLayerToActive();
3163 circle->setPen(Pen(Color(0, 0, 255), RS2::Width01, RS2::SolidLine));
3164 block->addEntity(circle);
3166 graphic->addBlock(block);
3169 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);
3171 // insert one magenta instance of the block (original):
3172 ins = new Insert(graphic, insData);
3173 ins->setLayerToActive();
3174 ins->setPen(Pen(Color(255, 0, 255), RS2::Width02, RS2::SolidLine));
3176 graphic->addEntity(ins);
3178 // insert one green instance of the block (rotate):
3179 insData = 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);
3180 ins = new Insert(graphic, insData);
3181 ins->setLayerToActive();
3182 ins->setPen(Pen(Color(0, 255, 0), RS2::Width02, RS2::SolidLine));
3184 graphic->addEntity(ins);
3186 // insert one cyan instance of the block (move):
3187 insData = InsertData("debugblock", Vector(10.0, 20.0), Vector(1.0, 1.0), 0.0, 1, 1, Vector(0.0, 0.0), NULL, RS2::NoUpdate);
3188 ins = new Insert(graphic, insData);
3189 ins->setLayerToActive();
3190 ins->setPen(Pen(Color(0, 255, 255), RS2::Width02, RS2::SolidLine));
3192 graphic->addEntity(ins);
3194 // insert one blue instance of the block:
3195 for(double a=0.0; a<360.0; a+=45.0)
3197 insData = 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);
3198 ins = new Insert(graphic, insData);
3199 ins->setLayerToActive();
3200 ins->setPen(Pen(Color(0, 0, 255), RS2::Width05, RS2::SolidLine));
3202 graphic->addEntity(ins);
3205 // insert an array of yellow instances of the block:
3206 insData = 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);
3207 ins = new Insert(graphic, insData);
3208 ins->setLayerToActive();
3209 ins->setPen(Pen(Color(255, 255, 0), RS2::Width01, RS2::SolidLine));
3211 graphic->addEntity(ins);
3213 GraphicView * v = getGraphicView();
3223 void ApplicationWindow::slotTestInsertEllipse()
3225 DEBUG->print("ApplicationWindow::slotTestInsertEllipse()");
3227 Document * d = getDocument();
3231 Drawing * graphic = (Drawing *)d;
3233 if (graphic == NULL)
3239 for (double a=0.0; a<2*M_PI; a+=0.1)
3242 v.setPolar(50.0, a);
3243 double xp = 1000.0*a;
3245 EllipseData ellipseData(Vector(xp, 0.0), v, 0.5, 0.0, 2 * M_PI, false);
3246 ellipse = new Ellipse(graphic, ellipseData);
3248 ellipse->setPen(Pen(Color(255, 0, 255), RS2::Width01, RS2::SolidLine));
3250 graphic->addEntity(ellipse);
3251 //graphic->addEntity(new Point(graphic, ellipse->getMax()));
3252 //graphic->addEntity(new Point(graphic, ellipse->getMin()));
3254 line = new Line(graphic, LineData(Vector(xp, 0.0), Vector(xp, 0.0) + v));
3255 line->setPen(Pen(Color(128, 128, 128), RS2::Width01, RS2::SolidLine));
3256 graphic->addEntity(line);
3259 for (double mx=-60.0; mx<60.0; mx+=1.0) {
3260 //for (double mx=0.0; mx<1.0; mx+=2.5) {
3261 VectorSolutions sol = ellipse->mapX(xp + mx);
3262 //graphic->addEntity(new Point(graphic,
3263 // sol.vector2 + Vector(a*500.0, 0.0)));
3264 //graphic->addEntity(new Point(graphic,
3265 // sol.vector3 + Vector(a*500.0, 0.0)));
3266 //graphic->addEntity(new Point(graphic,
3267 // sol.vector4 + Vector(a*500.0, 0.0)));
3269 line = new Line(graphic,
3270 LineData(Vector(xp+mx,-50.0),
3271 Vector(xp+mx,50.0)));
3272 line->setPen(Pen(Color(60, 60, 60),
3275 graphic->addEntity(line);
3277 graphic->addEntity(new Point(graphic,
3283 // different minor/minor relations
3286 for (y=-250.0; y<=250.0; y+=50.0) {
3287 for (x=-250.0; x<=250.0; x+=50.0) {
3290 ellipse = new Ellipse(graphic,
3292 Vector((x/5+50.0)/2.0, 0.0),
3297 ellipse->setPen(Pen(Color(255, 255, 0),
3301 graphic->addEntity(ellipse);
3302 graphic->addEntity(new Point(graphic, ellipse->getMax()));
3303 graphic->addEntity(new Point(graphic, ellipse->getMin()));
3305 ellipse = new Ellipse(graphic,
3306 v + Vector(750.0, 0.0),
3307 Vector((x/5+50.0)/2.0, 0.0),
3312 graphic->addEntity(ellipse);
3313 graphic->addEntity(new Point(graphic, ellipse->getMax()));
3314 graphic->addEntity(new Point(graphic, ellipse->getMin()));
3320 // different rotation angles:
3322 for (rot=0.0; rot<=2*M_PI+0.1; rot+=(M_PI/8)) {
3323 ellipse = new Ellipse(graphic,
3324 Vector(rot*200, 500.0),
3325 Vector(50.0, 0.0).rotate(rot),
3329 graphic->addEntity(ellipse);
3330 graphic->addEntity(new Point(graphic, ellipse->getMax()));
3331 graphic->addEntity(new Point(graphic, ellipse->getMin()));
3335 // different arc angles:
3337 for (rot=0.0; rot<=2*M_PI+0.1; rot+=(M_PI/8)) {
3338 for (a1=0.0; a1<=2*M_PI+0.1; a1+=(M_PI/8)) {
3339 for (a2=a1+M_PI/8; a2<=2*M_PI+a1+0.1; a2+=(M_PI/8)) {
3340 ellipse = new Ellipse(graphic,
3341 Vector(-500.0-a1*200.0-5000.0*rot,
3343 Vector(50.0, 0.0).rotate(rot),
3347 graphic->addEntity(ellipse);
3348 graphic->addEntity(new Point(graphic, ellipse->getMax()));
3349 graphic->addEntity(new Point(graphic, ellipse->getMin()));
3355 GraphicView * v = getGraphicView();
3365 void ApplicationWindow::slotTestInsertText()
3367 DEBUG->print("ApplicationWindow::slotTestInsertText()");
3369 Document * d = getDocument();
3373 Drawing * graphic = (Drawing *)d;
3375 if (graphic == NULL)
3381 textData = TextData(Vector(10.0, 10.0), 10.0, 100.0, RS2::VAlignTop, RS2::HAlignLeft, RS2::LeftToRight, RS2::Exact, 1.0, "Andrew", "normal", 0.0);
3382 text = new Text(graphic, textData);
3383 text->setLayerToActive();
3384 text->setPen(Pen(Color(255, 0, 0), RS2::Width01, RS2::SolidLine));
3385 graphic->addEntity(text);
3389 for (y=-250.0; y<=250.0; y+=50.0) {
3390 for (x=-250.0; x<=250.0; x+=50.0) {
3393 textData = TextData(v,
3404 text = new Text(graphic, textData);
3406 text->setLayerToActive();
3407 text->setPen(Pen(Color(255, 0, 0),
3410 graphic->addEntity(text);
3415 for (x=0.0; x<M_PI*2.0; x+=0.2) {
3416 Vector v(600.0+cos(x)*50.0, 0.0+sin(x)*50.0);
3418 line = new Line(graphic,
3419 LineData(Vector(600.0,0.0),
3421 line->setLayerToActive();
3422 line->setPenToActive();
3423 graphic->addEntity(line);
3425 textData = TextData(v,
3436 text = new Text(graphic, textData);
3438 text->setLayerToActive();
3439 text->setPen(Pen(Color(255, 0, 0),
3442 graphic->addEntity(text);
3445 SolidData solidData = SolidData(Vector(5.0, 10.0),
3447 Vector(15.0, 30.0));
3449 Solid* s = new Solid(graphic, solidData);
3451 s->setLayerToActive();
3452 s->setPen(Pen(Color(255, 255, 0),
3455 graphic->addEntity(s);
3457 GraphicView* v = getGraphicView();
3468 void ApplicationWindow::slotTestInsertImage()
3470 DEBUG->print("ApplicationWindow::slotTestInsertImage()");
3472 Document * d = getDocument();
3477 Drawing * drawing = (Drawing *)d;
3479 if (drawing == NULL)
3483 ImageData imageData;
3485 imageData = 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);
3486 image = new Image(drawing, imageData);
3488 image->setLayerToActive();
3489 image->setPen(Pen(Color(255, 0, 0), RS2::Width01, RS2::SolidLine));
3490 drawing->addEntity(image);
3496 void ApplicationWindow::slotTestUnicode()
3498 DEBUG->print("ApplicationWindow::slotTestUnicode()");
3500 slotFileOpen("./fonts/unicode.cxf", RS2::FormatCXF);
3501 Document* d = getDocument();
3503 Drawing* graphic = (Drawing*)d;
3504 if (graphic==NULL) {
3512 QChar uCode; // e.g. 65 (or 'A')
3513 QString strCode; // unicde as string e.g. '[0041] A'
3515 graphic->setAutoUpdateBorders(false);
3517 for (col=0x0000; col<=0xFFF0; col+=0x10) {
3518 printf("col: %X\n", col);
3519 for (row=0x0; row<=0xF; row++) {
3520 //printf(" row: %X\n", row);
3522 uCode = QChar(col+row);
3523 //printf(" code: %X\n", uCode.unicode());
3525 strCode.setNum(uCode.unicode(), 16);
3526 while (strCode.length()<4) {
3527 strCode="0"+strCode;
3529 strCode = "[" + strCode + "] " + uCode;
3531 if (graphic->findBlock(strCode)!=NULL) {
3532 InsertData d(strCode,
3533 Vector(col/0x10*20.0,row*20.0),
3534 Vector(1.0,1.0), 0.0,
3535 1, 1, Vector(0.0, 0.0),
3536 NULL, RS2::NoUpdate);
3537 ins = new Insert(graphic, d);
3538 ins->setLayerToActive();
3539 ins->setPen(Pen(Color(255, 255, 255),
3543 graphic->addEntity(ins);
3547 graphic->setAutoUpdateBorders(true);
3548 graphic->calculateBorders();
3555 void ApplicationWindow::slotTestMath01()
3557 DEBUG->print("ApplicationWindow::slotTestMath01()");
3559 Document* d = getDocument();
3561 Drawing* graphic = (Drawing*)d;
3562 if (graphic==NULL) {
3567 graphic->addEntity(new Line(graphic,
3568 LineData(Vector(0.0,0.0),
3569 Vector(2*M_PI,0.0))));
3570 graphic->addEntity(new Line(graphic,
3571 LineData(Vector(0.0,-1.0),
3576 double x = 59.0/ARAD;
3577 double x_0 = 60.0/ARAD;
3578 for (a=0.01; a<2*M_PI; a+=0.01) {
3580 Line* line = new Line(graphic,
3581 LineData(Vector(a-0.01, cos(a-0.01)),
3582 Vector(a, cos(a))));
3583 graphic->addEntity(line);
3586 graphic->addEntity(new Line(graphic,
3587 LineData(Vector(a-0.01,cos(x_0)-sin(x_0)*(a-0.01-x_0)),
3588 Vector(a,cos(x_0)-sin(x_0)*(a-x_0)))));
3592 graphic->addEntity(new Line(graphic,
3593 LineData(Vector(x,0.0),
3597 graphic->addEntity(new Line(graphic,
3598 LineData(Vector(x_0,0.0),
3602 //graphic->addEntity(new Line(graphic,
3603 // Vector(0.0,cos(x_0)-sin(x_0)*(0.0-x_0)),
3604 // Vector(6.0,cos(x_0)-sin(x_0)*(6.0-x_0))));
3607 GraphicView* v = getGraphicView();
3617 void ApplicationWindow::slotTestResize640()
3619 DEBUG->print("ApplicationWindow::slotTestResize640()");
3627 void ApplicationWindow::slotTestResize800()
3629 DEBUG->print("ApplicationWindow::slotTestResize800()");
3637 void ApplicationWindow::slotTestResize1024()
3639 DEBUG->print("ApplicationWindow::slotTestResize1024()");
3645 * overloaded for Message box on last window exit.
3647 bool ApplicationWindow::QueryExit(void)
3649 DEBUG->print("ApplicationWindow::queryExit()");
3651 bool success = true;
3652 QList<QMdiSubWindow *> list = workspace->subWindowList();
3654 for(int i=0; i<list.size(); i++)
3656 success = ((MDIWindow *)list[i])->CloseMDI();
3665 DEBUG->print("ApplicationWindow::queryExit(): OK");
3671 * Handle hotkeys. Don't let it to the default handler of Qt.
3672 * it will consume them also if a text field is active
3673 * which means it's impossible to enter a command.
3675 void ApplicationWindow::keyPressEvent(QKeyEvent * e)
3677 #warning "!!! keyPressEvent(): Do we need this anymore? !!!"
3679 static QTime ts = QTime();
3680 static QString firstKey = "";
3682 // single key codes:
3686 case Qt::Key_Control:
3689 case Qt::Key_CapsLock:
3691 QMainWindow::keyPressEvent(e);
3693 // forward to actions:
3694 GraphicView * graphicView = getGraphicView();
3697 graphicView->_keyPressEvent(e);
3703 case Qt::Key_Escape:
3709 case Qt::Key_Return:
3710 if (firstKey.isEmpty())
3718 if (firstKey.isEmpty())
3720 actionHandler->slotZoomIn();
3726 if (firstKey.isEmpty())
3728 actionHandler->slotZoomOut();
3738 if (e->isAccepted())
3741 QTime now = QTime::currentTime();
3744 if (ts.msecsTo(now) < 2000)
3746 QString code = QString("%1%2").arg(firstKey).arg(QChar(e->key())).toLower();
3748 if (actionHandler->keycode(code) == false)
3752 if (QChar(e->key()).isPrint())
3753 firstKey += e->key();
3762 if (QChar(e->key()).isPrint())
3763 firstKey = e->key();
3766 // Q3MainWindow::keyPressEvent(e);
3767 QMainWindow::keyPressEvent(e);
3770 void ApplicationWindow::keyReleaseEvent(QKeyEvent * e)
3775 case Qt::Key_Control:
3778 case Qt::Key_CapsLock:
3780 // Q3MainWindow::keyReleaseEvent(e);
3781 QMainWindow::keyReleaseEvent(e);
3783 // forward to actions:
3784 GraphicView * graphicView = getGraphicView();
3787 graphicView->_keyReleaseEvent(e);
3794 // THIS LOOKS LIKE A BUG TO ME...
3795 #warning "!!! keyPressEvent called in keyReleaseEvent !!!"
3796 // Q3MainWindow::keyPressEvent(e);
3797 QMainWindow::keyPressEvent(e);
3801 * @return Pointer to application window.
3803 /*static*/ ApplicationWindow * ApplicationWindow::getAppWindow()
3809 * @return Pointer to workspace.
3811 QMdiArea * ApplicationWindow::getWorkspace()
3817 * @return Pointer to the currently active MDI Window or NULL if no MDI Window
3820 MDIWindow * ApplicationWindow::getMDIWindow()
3822 DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::getMDIWindow: workspace=%08X", workspace);
3824 // Here is the problem: Window isn't active...
3827 printf("ApplicationWindow::getMDIWindow: activeSubWindow =%08X\n", (uint)workspace->activeSubWindow());
3828 printf("ApplicationWindow::getMDIWindow: currentSubWindow=%08X\n", (uint)workspace->currentSubWindow());
3829 DEBUG->print("ApplicationWindow::getMDIWindow: activeSubWindow=%08X", workspace->activeSubWindow());
3830 return (MDIWindow *)workspace->activeSubWindow();
3833 DEBUG->print("ApplicationWindow::getMDIWindow: activeSubWindow=??? (workspace == NULL)");
3838 * Implementation from MainWindowInterface (and QS_ScripterHostInterface).
3840 * @return Pointer to the graphic view of the currently active document
3841 * window or NULL if no window is available.
3843 /*virtual*/ GraphicView * ApplicationWindow::getGraphicView()
3845 MDIWindow * m = getMDIWindow();
3847 return (m ? m->getGraphicView() : NULL);
3851 * Implementation from MainWindowInterface (and QS_ScripterHostInterface).
3853 * @return Pointer to the graphic document of the currently active document
3854 * window or NULL if no window is available.
3856 /*virtual*/ Document * ApplicationWindow::getDocument()
3858 MDIWindow * m = getMDIWindow();
3860 return (m ? m->getDocument() : NULL);
3864 * Creates a new document. Implementation from MainWindowInterface.
3866 /*virtual*/ void ApplicationWindow::createNewDocument(const QString & fileName/*= QString::null*/,
3867 Document * doc/*= NULL*/)
3871 if (fileName != QString::null && getDocument())
3872 getDocument()->setFilename(fileName);
3877 * Implementation from QG_MainWindowInterface.
3879 * @return Pointer to this.
3881 /*virtual*/ QMainWindow * ApplicationWindow::GetMainWindow()
3887 * @return Pointer to action handler. Implementation from QG_MainWindowInterface.
3889 /*virtual*/ ActionHandler * ApplicationWindow::getActionHandler()
3891 return actionHandler;
3896 * Implementation from QG_MainWindowInterface.
3898 /*virtual*/ void ApplicationWindow::showSimulationControls()
3901 simulationDockWindow->show();
3907 * @return Pointer to the qsa object.
3909 QSProject * ApplicationWindow::getQSAProject()
3911 if (scripter != NULL)
3912 return scripter->getQSAProject();
3919 * Implementation from QG_MainWindowInterface.
3921 /*virtual*/ void ApplicationWindow::setFocus2()