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;
69 extern QSplashScreen * splash;
72 * Constructor. Initializes the app.
74 ApplicationWindow::ApplicationWindow():
75 QMainWindow((QWidget *)NULL/*,this is not a Qt::WindowFlags --> Qt::WA_DeleteOnClose*/), QG_MainWindowInterface()
77 DEBUG->print("ApplicationWindow::ApplicationWindow");
82 #warning "!!! Need to create new application icon !!!"
83 DEBUG->print("ApplicationWindow::ApplicationWindow: setting icon");
84 setWindowIcon(QIcon(":/res/qcad.png"));
85 CreateQtActions(this);
87 DEBUG->print("ApplicationWindow::ApplicationWindow: creating action handler");
88 actionHandler = new ActionHandler(this);
89 DEBUG->print("ApplicationWindow::ApplicationWindow: creating action handler: OK");
92 DEBUG->print("ApplicationWindow::ApplicationWindow: creating scripter");
93 scripter = new QS_Scripter(this, this);
94 DEBUG->print("ApplicationWindow::ApplicationWindow: creating scripter: OK");
97 DEBUG->print("ApplicationWindow::ApplicationWindow: init view");
99 DEBUG->print("ApplicationWindow::ApplicationWindow: init toolbar");
101 DEBUG->print("ApplicationWindow::ApplicationWindow: init actions");
103 DEBUG->print("ApplicationWindow::ApplicationWindow: init menu bar");
105 DEBUG->print("ApplicationWindow::ApplicationWindow: init status bar");
108 DEBUG->print("ApplicationWindow::ApplicationWindow: creating dialogFactory");
109 dialogFactory = new QC_DialogFactory(this, optionWidget);
110 DEBUG->print("ApplicationWindow::ApplicationWindow: creating dialogFactory: OK");
111 DEBUG->print("setting dialog factory object");
112 DEBUG->print("%s DialogFactory instance", (DialogFactory::instance() ? "got" : "no"));
113 DialogFactory::instance()->setFactoryObject(dialogFactory);
114 DEBUG->print("setting dialog factory object: OK");
116 DEBUG->print("ApplicationWindow::ApplicationWindow: init settings");
118 DEBUG->print("ApplicationWindow::ApplicationWindow: init MDI");
121 // Disable menu and toolbar items
122 emit windowsChanged(false);
124 statusBar()->showMessage("Architektonas Ready", 2000);
125 //setFocusPolicy(WheelFocus);
131 ApplicationWindow::~ApplicationWindow()
133 DEBUG->print("ApplicationWindow::~ApplicationWindow");
135 DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting scripter");
137 DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting scripter: OK");
140 DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting action handler");
141 delete actionHandler;
142 DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting action handler: OK");
144 DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting dialog factory");
145 delete dialogFactory;
146 DEBUG->print("ApplicationWindow::~ApplicationWindow: deleting dialog factory: OK");
148 DEBUG->print("ApplicationWindow::~ApplicationWindow: OK");
152 * Runs the start script if scripting is available.
154 void ApplicationWindow::slotRunStartScript()
156 slotRunScript("autostart.qs");
160 * Runs a script. The action that triggers this slot has to carry the
161 * name of the script file.
163 void ApplicationWindow::slotRunScript()
165 DEBUG->print("ApplicationWindow::slotRunScript");
167 const QObject * s = sender();
171 QString script = ((QAction *)s)->text();
172 DEBUG->print("ApplicationWindow::slotRunScript: %s", script.toLatin1().data());
173 slotRunScript(script);
178 * Runs the script with the given name.
180 void ApplicationWindow::slotRunScript(const QString & name)
183 DEBUG->print("ApplicationWindow::slotRunScript");
185 if (scripter == NULL)
187 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotRunScript: scripter not initialized");
191 statusBar()->showMessage(tr("Running script '%1'").arg(name), 2000);
193 QStringList scriptList = SYSTEM->getScriptList();
194 scriptList.append(SYSTEM->getHomeDir() + "/.architektonas/" + name);
196 for (QStringList::Iterator it = scriptList.begin(); it!=scriptList.end(); ++it)
198 DEBUG->print("ApplicationWindow::slotRunScript: checking script '%s'", (*it).toLatin1().data();
201 if (fi.exists() && fi.fileName() == name)
203 DEBUG->print("ApplicationWindow::slotRunScript: running '%s'", (*it).toLatin1().data());
204 scripter->runScript(*it, "main");
211 * Called from toolbar buttons that were added by scripts to
214 void ApplicationWindow::slotInsertBlock()
216 const QObject * s = sender();
220 QString block = ((QAction *)s)->text();
221 DEBUG->print("ApplicationWindow::slotInsertBlock: %s", block.toLatin1().data());
222 slotInsertBlock(block);
227 * Called to insert blocks.
229 void ApplicationWindow::slotInsertBlock(const QString & name)
231 DEBUG->print("ApplicationWindow::slotInsertBlock: '%s'", name.toLatin1().data());
233 statusBar()->showMessage(tr("Inserting block '%1'").arg(name), 2000);
235 GraphicView * graphicView = getGraphicView();
236 Document * document = getDocument();
238 if (graphicView && document)
240 ActionLibraryInsert * action = new ActionLibraryInsert(*document, *graphicView);
241 action->setFile(name);
242 graphicView->setCurrentAction(action);
247 * Shows the main application window and a splash screen.
249 void ApplicationWindow::show()
251 #ifdef QSPLASHSCREEN_H
258 #ifdef QSPLASHSCREEN_H
262 qApp->processEvents();
263 splash->clearMessage();
264 # ifdef QC_DELAYED_SPLASH_SCREEN
265 QTimer::singleShot(1000 * 2, this, SLOT(finishSplashScreen()));
267 finishSplashScreen();
274 * Called when the splash screen has to terminate.
276 void ApplicationWindow::finishSplashScreen()
278 #ifdef QSPLASHSCREEN_H
281 splash->finish(this);
289 * Close Event. Called when the user tries to close the app.
291 void ApplicationWindow::closeEvent(QCloseEvent * /*ce*/)
293 DEBUG->print("ApplicationWindow::closeEvent()");
295 DEBUG->print("ApplicationWindow::closeEvent(): OK");
299 * Handles right-clicks for moving back to the last cad tool bar.
301 void ApplicationWindow::mouseReleaseEvent(QMouseEvent * e)
303 if (e->button() == Qt::RightButton && cadToolBar != NULL)
304 cadToolBar->showToolBarMain();
310 * Initializes the MDI workspace.
312 void ApplicationWindow::initMDI()
314 DEBUG->print("ApplicationWindow::initMDI() begin");
316 /* Could use QVBoxLayout instead of Q3VBox, but do we even need to? */
317 // Q3VBox * vb = new Q3VBox(this);
318 // vb->setFrameStyle(Q3Frame::StyledPanel | Q3Frame::Sunken);
319 // workspace = new QMdiArea(vb);
320 workspace = new QMdiArea(this);
321 // workspace->setScrollBarsEnabled(true);
322 // setCentralWidget(vb);
323 setCentralWidget(workspace);//JLH:hmm. (Yes, it works! \o/)
324 DEBUG->print("ApplicationWindow::initMDI(): workspace=%08X", workspace);
326 //#warning "Object::connect: No such signal QMdiArea::windowActivated(QWidget *)"
327 // connect(workspace, SIGNAL(windowActivated(QWidget *)), this, SLOT(slotWindowActivated(QWidget *)));
328 connect(workspace, SIGNAL(subWindowActivated(QMdiSubWindow *)), this,
329 SLOT(slotWindowActivated(QMdiSubWindow *)));
331 DEBUG->print("ApplicationWindow::initMDI() end");
335 * Initializes all QActions of the application.
336 * (Actually, it creates all application menus & toolbars. All actions are
337 * created in CreateQtActions() and simply referenced here.)
339 void ApplicationWindow::initActions()
341 DEBUG->print("ApplicationWindow::initActions()");
346 QMenu * menu = new QMenu(tr("&File"), this);
347 QToolBar * tb = fileToolBar;
348 tb->setWindowTitle("File");
349 // tb->setCloseMode(Q3DockWindow::Undocked);
351 menu->addAction(actionFileNew);
352 tb->addAction(actionFileNew);
353 connect(actionFileNew, SIGNAL(activated()), this, SLOT(slotFileNew()));
354 menu->addAction(actionFileOpen);
355 tb->addAction(actionFileOpen);
356 connect(actionFileOpen, SIGNAL(activated()), this, SLOT(slotFileOpen()));
357 menu->addAction(actionFileSave);
358 tb->addAction(actionFileSave);
359 connect(actionFileSave, SIGNAL(activated()), this, SLOT(slotFileSave()));
360 connect(this, SIGNAL(windowsChanged(bool)), actionFileSave, SLOT(setEnabled(bool)));
361 menu->addAction(actionFileSaveAs);
362 connect(actionFileSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs()));
363 connect(this, SIGNAL(windowsChanged(bool)), actionFileSaveAs, SLOT(setEnabled(bool)));
364 menu->addAction(actionFileExport);
365 connect(actionFileExport, SIGNAL(activated()), this, SLOT(slotFileExport()));
366 connect(this, SIGNAL(windowsChanged(bool)), actionFileExport, SLOT(setEnabled(bool)));
368 menu->addSeparator();
370 menu->addAction(actionFileClose);
371 connect(actionFileClose, SIGNAL(activated()), this, SLOT(slotFileClose()));
372 connect(this, SIGNAL(windowsChanged(bool)), actionFileClose, SLOT(setEnabled(bool)));
374 menu->addSeparator();
376 menu->addAction(actionFilePrint);
377 tb->addAction(actionFilePrint);
378 connect(actionFilePrint, SIGNAL(activated()), this, SLOT(slotFilePrint()));
379 connect(this, SIGNAL(windowsChanged(bool)), actionFilePrint, SLOT(setEnabled(bool)));
380 menu->addAction(actionFilePrintPreview);
381 tb->addAction(actionFilePrintPreview);
382 connect(actionFilePrintPreview, SIGNAL(toggled(bool)), this, SLOT(slotFilePrintPreview(bool)));
383 //??? connect(this, SIGNAL(printPreviewChanged(bool)), actionFilePrintPreview, SLOT(setOn(bool)));
384 connect(this, SIGNAL(windowsChanged(bool)), actionFilePrintPreview, SLOT(setEnabled(bool)));
386 menu->addSeparator();
388 menu->addAction(actionFileQuit);
389 connect(actionFileQuit, SIGNAL(activated()), this, SLOT(slotFileQuit()));
391 menu->addSeparator();
393 menuBar()->addMenu(menu);
394 addToolBar(Qt::TopToolBarArea, tb);
400 menu = new QMenu(tr("&Edit"), this);
402 tb->setWindowTitle("Edit");
403 // tb->setCloseMode(Q3DockWindow::Undocked);
405 // action = actionFactory.createAction(RS2::ActionEditUndo, actionHandler);
406 menu->addAction(actionEditUndo);
407 tb->addAction(actionEditUndo);
408 connect(actionEditUndo, SIGNAL(activated()), actionHandler, SLOT(slotEditUndo()));
409 connect(this, SIGNAL(windowsChanged(bool)), actionEditUndo, SLOT(setEnabled(bool)));
410 // action = actionFactory.createAction(RS2::ActionEditRedo, actionHandler);
411 menu->addAction(actionEditRedo);
412 tb->addAction(actionEditRedo);
413 connect(actionEditRedo, SIGNAL(activated()), actionHandler, SLOT(slotEditRedo()));
414 connect(this, SIGNAL(windowsChanged(bool)), actionEditRedo, SLOT(setEnabled(bool)));
417 menu->addSeparator();
419 // action = actionFactory.createAction(RS2::ActionEditCut, actionHandler);
420 menu->addAction(actionEditCut);
421 tb->addAction(actionEditCut);
422 connect(actionEditCut, SIGNAL(activated()), actionHandler, SLOT(slotEditCut()));
423 connect(this, SIGNAL(windowsChanged(bool)), actionEditCut, SLOT(setEnabled(bool)));
424 // action = actionFactory.createAction(RS2::ActionEditCopy, actionHandler);
425 menu->addAction(actionEditCopy);
426 tb->addAction(actionEditCopy);
427 connect(actionEditCopy, SIGNAL(activated()), actionHandler, SLOT(slotEditCopy()));
428 connect(this, SIGNAL(windowsChanged(bool)), actionEditCopy, SLOT(setEnabled(bool)));
429 // action = actionFactory.createAction(RS2::ActionEditPaste, actionHandler);
430 menu->addAction(actionEditPaste);
431 tb->addAction(actionEditPaste);
432 connect(actionEditPaste, SIGNAL(activated()), actionHandler, SLOT(slotEditPaste()));
433 connect(this, SIGNAL(windowsChanged(bool)), actionEditPaste, SLOT(setEnabled(bool)));
435 menu->addSeparator();
437 menu->addAction(actionOptionsGeneral);
438 connect(actionOptionsGeneral, SIGNAL(activated()), this, SLOT(slotOptionsGeneral()));
439 menu->addAction(actionOptionsDrawing);
440 connect(actionOptionsDrawing, SIGNAL(activated()), actionHandler, SLOT(slotOptionsDrawing()));
441 connect(this, SIGNAL(windowsChanged(bool)), actionOptionsDrawing, SLOT(setEnabled(bool)));
443 menuBar()->addMenu(menu);
444 addToolBar(Qt::TopToolBarArea, tb);
448 //menu = new QPopupMenu(this);
449 //menuBar()->insertItem(tr("&Options"), menu);
451 // Viewing / Zooming actions:
453 // menu = new Q3PopupMenu(this);
454 menu = new QMenu(tr("&View"), this);
455 //obsolete: menu->setCheckable(true);
457 tb->setWindowTitle("View");
458 // tb->setCloseMode(Q3DockWindow::Undocked);
460 // action = actionFactory.createAction(RS2::ActionViewGrid, this);
461 menu->addAction(actionViewGrid);
462 tb->addAction(actionViewGrid);
463 actionViewGrid->setChecked(true);
464 connect(actionViewGrid, SIGNAL(toggled(bool)), this, SLOT(slotViewGrid(bool)));
465 //??? connect(this, SIGNAL(gridChanged(bool)), actionViewGrid, SLOT(setOn(bool)));
466 connect(this, SIGNAL(windowsChanged(bool)), actionViewGrid, SLOT(setEnabled(bool)));
468 settings.beginGroup("Appearance");
469 bool draftMode = settings.value("DraftMode", false).toBool();
472 // action = actionFactory.createAction(RS2::ActionViewDraft, this);
473 menu->addAction(actionViewDraft);
474 tb->addAction(actionViewDraft);
475 actionViewDraft->setChecked(draftMode);
476 connect(actionViewDraft, SIGNAL(toggled(bool)), this, SLOT(slotViewDraft(bool)));
477 //??? connect(this, SIGNAL(draftChanged(bool)), actionViewDraft, SLOT(setOn(bool)));
478 connect(this, SIGNAL(windowsChanged(bool)), actionViewDraft, SLOT(setEnabled(bool)));
480 // action = actionFactory.createAction(RS2::ActionZoomRedraw, actionHandler);
481 menu->addAction(actionZoomRedraw);
482 tb->addAction(actionZoomRedraw);
483 connect(actionZoomRedraw, SIGNAL(activated()), actionHandler, SLOT(slotZoomRedraw()));
484 connect(this, SIGNAL(windowsChanged(bool)), actionZoomRedraw, SLOT(setEnabled(bool)));
485 // action = actionFactory.createAction(RS2::ActionZoomIn, actionHandler);
486 menu->addAction(actionZoomIn);
487 tb->addAction(actionZoomIn);
488 connect(actionZoomIn, SIGNAL(activated()), actionHandler, SLOT(slotZoomIn()));
489 connect(this, SIGNAL(windowsChanged(bool)), actionZoomIn, SLOT(setEnabled(bool)));
490 // action = actionFactory.createAction(RS2::ActionZoomOut, actionHandler);
491 menu->addAction(actionZoomOut);
492 tb->addAction(actionZoomOut);
493 connect(actionZoomOut, SIGNAL(activated()), actionHandler, SLOT(slotZoomOut()));
494 connect(this, SIGNAL(windowsChanged(bool)), actionZoomOut, SLOT(setEnabled(bool)));
495 // action = actionFactory.createAction(RS2::ActionZoomAuto, actionHandler);
496 menu->addAction(actionZoomAuto);
497 tb->addAction(actionZoomAuto);
498 connect(actionZoomAuto, SIGNAL(activated()), actionHandler, SLOT(slotZoomAuto()));
499 connect(this, SIGNAL(windowsChanged(bool)), actionZoomAuto, SLOT(setEnabled(bool)));
500 // action = actionFactory.createAction(RS2::ActionZoomPrevious, actionHandler);
501 menu->addAction(actionZoomPrevious);
502 tb->addAction(actionZoomPrevious);
503 connect(actionZoomPrevious, SIGNAL(activated()), actionHandler, SLOT(slotZoomPrevious()));
504 connect(this, SIGNAL(windowsChanged(bool)), actionZoomPrevious, SLOT(setEnabled(bool)));
505 // action = actionFactory.createAction(RS2::ActionZoomWindow, actionHandler);
506 menu->addAction(actionZoomWindow);
507 tb->addAction(actionZoomWindow);
508 connect(actionZoomWindow, SIGNAL(activated()), actionHandler, SLOT(slotZoomWindow()));
509 connect(this, SIGNAL(windowsChanged(bool)), actionZoomWindow, SLOT(setEnabled(bool)));
510 // action = actionFactory.createAction(RS2::ActionZoomPan, actionHandler);
511 menu->addAction(actionZoomPan);
512 tb->addAction(actionZoomPan);
513 connect(actionZoomPan, SIGNAL(activated()), actionHandler, SLOT(slotZoomPan()));
514 connect(this, SIGNAL(windowsChanged(bool)), actionZoomPan, SLOT(setEnabled(bool)));
516 menu->addSeparator();
518 // action = actionFactory.createAction(RS2::ActionViewStatusBar, this);
519 menu->addAction(actionViewStatusbar);
520 actionViewStatusbar->setChecked(true);
521 connect(actionViewStatusbar, SIGNAL(toggled(bool)), this, SLOT(slotViewStatusBar(bool)));
524 menu->insertItem(tr("Vie&ws"), createDockWindowMenu(NoToolBars));
525 menu->insertItem(tr("Tool&bars"), createDockWindowMenu(OnlyToolBars));
527 //Actually, this isn't really needed... This crap is maintained by Qt...
528 //#warning "!!! More stuff to port to Qt4 !!!"
531 menu->addAction(actionFocusCommandLine);
532 connect(actionFocusCommandLine, SIGNAL(activated()), this, SLOT(slotFocusCommandLine()));
533 connect(this, SIGNAL(windowsChanged(bool)), actionFocusCommandLine, SLOT(setEnabled(bool)));
534 menuBar()->addMenu(menu);
535 //addToolBar(tb, tr("View"));
536 // addDockWindow(tb, tr("View"), Qt::DockTop);
537 addToolBar(Qt::TopToolBarArea, tb);
539 // Selecting actions:
541 menu = new QMenu(tr("&Select"), this);
542 // action = actionFactory.createAction(RS2::ActionDeselectAll, actionHandler);
543 menu->addAction(actionDeselectAll);
544 connect(actionDeselectAll, SIGNAL(activated()), actionHandler, SLOT(slotDeselectAll()));
545 connect(this, SIGNAL(windowsChanged(bool)), actionDeselectAll, SLOT(setEnabled(bool)));
546 // action = actionFactory.createAction(RS2::ActionSelectAll, actionHandler);
547 menu->addAction(actionSelectAll);
548 connect(actionSelectAll, SIGNAL(activated()), actionHandler, SLOT(slotSelectAll()));
549 connect(this, SIGNAL(windowsChanged(bool)), actionSelectAll, SLOT(setEnabled(bool)));
550 // action = actionFactory.createAction(RS2::ActionSelectSingle, actionHandler);
551 menu->addAction(actionSelectSingle);
552 connect(actionSelectSingle, SIGNAL(activated()), actionHandler, SLOT(slotSelectSingle()));
553 connect(this, SIGNAL(windowsChanged(bool)), actionSelectSingle, SLOT(setEnabled(bool)));
554 // action = actionFactory.createAction(RS2::ActionSelectContour, actionHandler);
555 menu->addAction(actionSelectContour);
556 connect(actionSelectContour, SIGNAL(activated()), actionHandler, SLOT(slotSelectContour()));
557 connect(this, SIGNAL(windowsChanged(bool)), actionSelectContour, SLOT(setEnabled(bool)));
558 // action = actionFactory.createAction(RS2::ActionDeselectWindow, actionHandler);
559 menu->addAction(actionDeselectWindow);
560 connect(actionDeselectWindow, SIGNAL(activated()), actionHandler, SLOT(slotDeselectWindow()));
561 connect(this, SIGNAL(windowsChanged(bool)), actionDeselectWindow, SLOT(setEnabled(bool)));
562 // action = actionFactory.createAction(RS2::ActionSelectWindow, actionHandler);
563 menu->addAction(actionSelectWindow);
564 connect(actionSelectWindow, SIGNAL(activated()), actionHandler, SLOT(slotSelectWindow()));
565 connect(this, SIGNAL(windowsChanged(bool)), actionSelectWindow, SLOT(setEnabled(bool)));
566 // action = actionFactory.createAction(RS2::ActionSelectInvert, actionHandler);
567 menu->addAction(actionSelectInvert);
568 connect(actionSelectInvert, SIGNAL(activated()), actionHandler, SLOT(slotSelectInvert()));
569 connect(this, SIGNAL(windowsChanged(bool)), actionSelectInvert, SLOT(setEnabled(bool)));
570 // action = actionFactory.createAction(RS2::ActionSelectIntersected, actionHandler);
571 menu->addAction(actionSelectIntersected);
572 connect(actionSelectIntersected, SIGNAL(activated()), actionHandler, SLOT(slotSelectIntersected()));
573 connect(this, SIGNAL(windowsChanged(bool)), actionSelectIntersected, SLOT(setEnabled(bool)));
574 // action = actionFactory.createAction(RS2::ActionDeselectIntersected, actionHandler);
575 menu->addAction(actionDeselectIntersected);
576 connect(actionDeselectIntersected, SIGNAL(activated()), actionHandler, SLOT(slotDeselectIntersected()));
577 connect(this, SIGNAL(windowsChanged(bool)), actionDeselectIntersected, SLOT(setEnabled(bool)));
578 // action = actionFactory.createAction(RS2::ActionSelectLayer, actionHandler);
579 menu->addAction(actionSelectLayer);
580 connect(actionSelectLayer, SIGNAL(activated()), actionHandler, SLOT(slotSelectLayer()));
581 connect(this, SIGNAL(windowsChanged(bool)), actionSelectLayer, SLOT(setEnabled(bool)));
582 menuBar()->addMenu(menu);
586 menu = new QMenu(tr("&Draw"), this);
589 QMenu * subMenu = new QMenu(tr("&Point"), this);
590 // action = actionFactory.createAction(RS2::ActionDrawPoint, actionHandler);
591 subMenu->addAction(actionDrawPoint);
592 connect(actionDrawPoint, SIGNAL(activated()), actionHandler, SLOT(slotDrawPoint()));
593 connect(this, SIGNAL(windowsChanged(bool)), actionDrawPoint, SLOT(setEnabled(bool)));
594 menu->addMenu(subMenu);
597 subMenu = new QMenu(tr("&Line"), this);
598 // action = actionFactory.createAction(RS2::ActionDrawLine, actionHandler);
599 subMenu->addAction(actionDrawLine);
600 connect(actionDrawLine, SIGNAL(activated()), actionHandler, SLOT(slotDrawLine()));
601 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLine, SLOT(setEnabled(bool)));
602 // action = actionFactory.createAction(RS2::ActionDrawLineAngle, actionHandler);
603 subMenu->addAction(actionDrawLineAngle);
604 connect(actionDrawLineAngle, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineAngle()));
605 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineAngle, SLOT(setEnabled(bool)));
606 // action = actionFactory.createAction(RS2::ActionDrawLineHorizontal, actionHandler);
607 subMenu->addAction(actionDrawLineHorizontal);
608 connect(actionDrawLineHorizontal, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineHorizontal()));
609 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineHorizontal, SLOT(setEnabled(bool)));
610 // action = actionFactory.createAction(RS2::ActionDrawLineVertical, actionHandler);
611 subMenu->addAction(actionDrawLineVertical);
612 connect(actionDrawLineVertical, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineVertical()));
613 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineVertical, SLOT(setEnabled(bool)));
614 // action = actionFactory.createAction(RS2::ActionDrawLineRectangle, actionHandler);
615 subMenu->addAction(actionDrawLineRectangle);
616 connect(actionDrawLineRectangle, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineRectangle()));
617 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineRectangle, SLOT(setEnabled(bool)));
618 // action = actionFactory.createAction(RS2::ActionDrawLineParallel, actionHandler);
619 subMenu->addAction(actionDrawLineParallel);
620 connect(actionDrawLineParallel, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineParallel()));
621 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineParallel, SLOT(setEnabled(bool)));
622 // action = actionFactory.createAction(RS2::ActionDrawLineParallelThrough, actionHandler);
623 subMenu->addAction(actionDrawLineParallelThrough);
624 connect(actionDrawLineParallelThrough, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineParallelThrough()));
625 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineParallelThrough, SLOT(setEnabled(bool)));
626 // action = actionFactory.createAction(RS2::ActionDrawLineBisector, actionHandler);
627 subMenu->addAction(actionDrawLineBisector);
628 connect(actionDrawLineBisector, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineBisector()));
629 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineBisector, SLOT(setEnabled(bool)));
630 // action = actionFactory.createAction(RS2::ActionDrawLineTangent1, actionHandler);
631 subMenu->addAction(actionDrawLineTangent1);
632 connect(actionDrawLineTangent1, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineTangent1()));
633 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineTangent1, SLOT(setEnabled(bool)));
634 // action = actionFactory.createAction(RS2::ActionDrawLineTangent2, actionHandler);
635 subMenu->addAction(actionDrawLineTangent2);
636 connect(actionDrawLineTangent2, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineTangent2()));
637 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineTangent2, SLOT(setEnabled(bool)));
638 // action = actionFactory.createAction(RS2::ActionDrawLineOrthogonal, actionHandler);
639 subMenu->addAction(actionDrawLineOrthogonal);
640 connect(actionDrawLineOrthogonal, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineOrthogonal()));
641 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineOrthogonal, SLOT(setEnabled(bool)));
642 // action = actionFactory.createAction(RS2::ActionDrawLineRelAngle, actionHandler);
643 subMenu->addAction(actionDrawLineRelAngle);
644 connect(actionDrawLineRelAngle, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineRelAngle()));
645 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineRelAngle, SLOT(setEnabled(bool)));
646 // action = actionFactory.createAction(RS2::ActionDrawLinePolygon, actionHandler);
647 subMenu->addAction(actionDrawLinePolygon);
648 connect(actionDrawLinePolygon, SIGNAL(activated()), actionHandler, SLOT(slotDrawLinePolygon()));
649 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLinePolygon, SLOT(setEnabled(bool)));
650 // action = actionFactory.createAction(RS2::ActionDrawLinePolygon2, actionHandler);
651 subMenu->addAction(actionDrawLinePolygon2);
652 connect(actionDrawLinePolygon2, SIGNAL(activated()), actionHandler, SLOT(slotDrawLinePolygon2()));
653 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLinePolygon2, SLOT(setEnabled(bool)));
654 // action = actionFactory.createAction(RS2::ActionDrawLineFree, actionHandler);
655 subMenu->addAction(actionDrawLineFree);
656 connect(actionDrawLineFree, SIGNAL(activated()), actionHandler, SLOT(slotDrawLineFree()));
657 connect(this, SIGNAL(windowsChanged(bool)), actionDrawLineFree, SLOT(setEnabled(bool)));
658 menu->addMenu(subMenu);
661 subMenu = new QMenu(tr("&Arc"), this);
662 subMenu->addAction(actionDrawArc);
663 connect(actionDrawArc, SIGNAL(activated()), actionHandler, SLOT(slotDrawArc()));
664 connect(this, SIGNAL(windowsChanged(bool)), actionDrawArc, SLOT(setEnabled(bool)));
665 subMenu->addAction(actionDrawArc3P);
666 connect(actionDrawArc3P, SIGNAL(activated()), actionHandler, SLOT(slotDrawArc3P()));
667 connect(this, SIGNAL(windowsChanged(bool)), actionDrawArc3P, SLOT(setEnabled(bool)));
668 subMenu->addAction(actionDrawArcParallel);
669 connect(actionDrawArcParallel, SIGNAL(activated()), actionHandler, SLOT(slotDrawArcParallel()));
670 connect(this, SIGNAL(windowsChanged(bool)), actionDrawArcParallel, SLOT(setEnabled(bool)));
671 subMenu->addAction(actionDrawArcTangential);
672 connect(actionDrawArcTangential, SIGNAL(activated()), actionHandler, SLOT(slotDrawArcTangential()));
673 connect(this, SIGNAL(windowsChanged(bool)), actionDrawArcTangential, SLOT(setEnabled(bool)));
674 menu->addMenu(subMenu);
677 subMenu = new QMenu(tr("&Circle"), this);
678 // action = actionFactory.createAction(RS2::ActionDrawCircle, actionHandler);
679 subMenu->addAction(actionDrawCircle);
680 connect(actionDrawCircle, SIGNAL(activated()), actionHandler, SLOT(slotDrawCircle()));
681 connect(this, SIGNAL(windowsChanged(bool)), actionDrawCircle, SLOT(setEnabled(bool)));
682 // action = actionFactory.createAction(RS2::ActionDrawCircleCR, actionHandler);
683 subMenu->addAction(actionDrawCircleCR);
684 connect(actionDrawCircleCR, SIGNAL(activated()), actionHandler, SLOT(slotDrawCircleCR()));
685 connect(this, SIGNAL(windowsChanged(bool)), actionDrawCircleCR, SLOT(setEnabled(bool)));
686 // action = actionFactory.createAction(RS2::ActionDrawCircle2P, actionHandler);
687 subMenu->addAction(actionDrawCircle2P);
688 connect(actionDrawCircle2P, SIGNAL(activated()), actionHandler, SLOT(slotDrawCircle2P()));
689 connect(this, SIGNAL(windowsChanged(bool)), actionDrawCircle2P, SLOT(setEnabled(bool)));
690 // action = actionFactory.createAction(RS2::ActionDrawCircle3P, actionHandler);
691 subMenu->addAction(actionDrawCircle3P);
692 connect(actionDrawCircle3P, SIGNAL(activated()), actionHandler, SLOT(slotDrawCircle3P()));
693 connect(this, SIGNAL(windowsChanged(bool)), actionDrawCircle3P, SLOT(setEnabled(bool)));
694 // action = actionFactory.createAction(RS2::ActionDrawCircleParallel, actionHandler);
695 subMenu->addAction(actionDrawCircleParallel);
696 connect(actionDrawCircleParallel, SIGNAL(activated()), actionHandler, SLOT(slotDrawCircleParallel()));
697 connect(this, SIGNAL(windowsChanged(bool)), actionDrawCircleParallel, SLOT(setEnabled(bool)));
698 menu->addMenu(subMenu);
701 subMenu = new QMenu(tr("&Ellipse"), this);
702 // action = actionFactory.createAction(RS2::ActionDrawEllipseAxis, actionHandler);
703 subMenu->addAction(actionDrawEllipseAxis);
704 connect(actionDrawEllipseAxis, SIGNAL(activated()), actionHandler, SLOT(slotDrawEllipseAxis()));
705 connect(this, SIGNAL(windowsChanged(bool)), actionDrawEllipseAxis, SLOT(setEnabled(bool)));
706 // action = actionFactory.createAction(RS2::ActionDrawEllipseArcAxis, actionHandler);
707 subMenu->addAction(actionDrawEllipseArcAxis);
708 connect(actionDrawEllipseArcAxis, SIGNAL(activated()), actionHandler, SLOT(slotDrawEllipseArcAxis()));
709 connect(this, SIGNAL(windowsChanged(bool)), actionDrawEllipseArcAxis, SLOT(setEnabled(bool)));
710 menu->addMenu(subMenu);
713 subMenu = new QMenu(tr("&Spline"), this);
714 // action = actionFactory.createAction(RS2::ActionDrawSpline, actionHandler);
715 subMenu->addAction(actionDrawSpline);
716 connect(actionDrawSpline, SIGNAL(activated()), actionHandler, SLOT(slotDrawSpline()));
717 connect(this, SIGNAL(windowsChanged(bool)), actionDrawSpline, SLOT(setEnabled(bool)));
718 menu->addMenu(subMenu);
721 subMenu = new QMenu(tr("&Polyline"), this);
722 // action = actionFactory.createAction(RS2::ActionDrawPolyline, actionHandler);
723 subMenu->addAction(actionDrawPolyline);
724 connect(actionDrawPolyline, SIGNAL(activated()), actionHandler, SLOT(slotDrawPolyline()));
725 connect(this, SIGNAL(windowsChanged(bool)), actionDrawPolyline, SLOT(setEnabled(bool)));
726 // action = actionFactory.createAction(RS2::ActionPolylineAdd, actionHandler);
727 subMenu->addAction(actionPolylineAdd);
728 connect(actionPolylineAdd, SIGNAL(activated()), actionHandler, SLOT(slotPolylineAdd()));
729 connect(this, SIGNAL(windowsChanged(bool)), actionPolylineAdd, SLOT(setEnabled(bool)));
730 subMenu->addAction(actionPolylineAppend);
731 connect(actionPolylineAppend, SIGNAL(activated()), actionHandler, SLOT(slotPolylineAppend()));
732 connect(this, SIGNAL(windowsChanged(bool)), actionPolylineAppend, SLOT(setEnabled(bool)));
733 // action = actionFactory.createAction(RS2::ActionPolylineDel, actionHandler);
734 subMenu->addAction(actionPolylineDel);
735 connect(actionPolylineDel, SIGNAL(activated()), actionHandler, SLOT(slotPolylineDel()));
736 connect(this, SIGNAL(windowsChanged(bool)), actionPolylineDel, SLOT(setEnabled(bool)));
737 // action = actionFactory.createAction(RS2::ActionPolylineDelBetween, actionHandler);
738 subMenu->addAction(actionPolylineDelBetween);
739 connect(actionPolylineDelBetween, SIGNAL(activated()), actionHandler, SLOT(slotPolylineDelBetween()));
740 connect(this, SIGNAL(windowsChanged(bool)), actionPolylineDelBetween, SLOT(setEnabled(bool)));
741 // action = actionFactory.createAction(RS2::ActionPolylineTrim, actionHandler);
742 subMenu->addAction(actionPolylineTrim);
743 connect(actionPolylineTrim, SIGNAL(activated()), actionHandler, SLOT(slotPolylineTrim()));
744 connect(this, SIGNAL(windowsChanged(bool)), actionPolylineTrim, SLOT(setEnabled(bool)));
745 menu->addMenu(subMenu);
748 // action = actionFactory.createAction(RS2::ActionDrawText, actionHandler);
749 menu->addAction(actionDrawText);
750 connect(actionDrawText, SIGNAL(activated()), actionHandler, SLOT(slotDrawText()));
751 connect(this, SIGNAL(windowsChanged(bool)), actionDrawText, SLOT(setEnabled(bool)));
753 // action = actionFactory.createAction(RS2::ActionDrawHatch, actionHandler);
754 menu->addAction(actionDrawHatch);
755 connect(actionDrawHatch, SIGNAL(activated()), actionHandler, SLOT(slotDrawHatch()));
756 connect(this, SIGNAL(windowsChanged(bool)), actionDrawHatch, SLOT(setEnabled(bool)));
758 // action = actionFactory.createAction(RS2::ActionDrawImage, actionHandler);
759 menu->addAction(actionDrawImage);
760 connect(actionDrawImage, SIGNAL(activated()), actionHandler, SLOT(slotDrawImage()));
761 connect(this, SIGNAL(windowsChanged(bool)), actionDrawImage, SLOT(setEnabled(bool)));
762 // menuBar()->insertItem(tr("&Draw"), menu);
763 menuBar()->addMenu(menu);
765 // Dimensioning actions:
771 menu = new QMenu(tr("&Dimension"), this);
772 menu->addAction(actionDimAligned);
773 connect(actionDimAligned, SIGNAL(activated()), actionHandler, SLOT(slotDimAligned()));
774 connect(this, SIGNAL(windowsChanged(bool)), actionDimAligned, SLOT(setEnabled(bool)));
775 menu->addAction(actionDimLinear);
776 connect(actionDimLinear, SIGNAL(activated()), actionHandler, SLOT(slotDimLinear()));
777 connect(this, SIGNAL(windowsChanged(bool)), actionDimLinear, SLOT(setEnabled(bool)));
778 menu->addAction(actionDimLinearHor);
779 connect(actionDimLinearHor, SIGNAL(activated()), actionHandler, SLOT(slotDimLinearHor()));
780 connect(this, SIGNAL(windowsChanged(bool)), actionDimLinearHor, SLOT(setEnabled(bool)));
781 menu->addAction(actionDimLinearVer);
782 connect(actionDimLinearVer, SIGNAL(activated()), actionHandler, SLOT(slotDimLinearVer()));
783 connect(this, SIGNAL(windowsChanged(bool)), actionDimLinearVer, SLOT(setEnabled(bool)));
784 menu->addAction(actionDimRadial);
785 connect(actionDimRadial, SIGNAL(activated()), actionHandler, SLOT(slotDimRadial()));
786 connect(this, SIGNAL(windowsChanged(bool)), actionDimRadial, SLOT(setEnabled(bool)));
787 menu->addAction(actionDimDiametric);
788 connect(actionDimDiametric, SIGNAL(activated()), actionHandler, SLOT(slotDimDiametric()));
789 connect(this, SIGNAL(windowsChanged(bool)), actionDimDiametric, SLOT(setEnabled(bool)));
790 menu->addAction(actionDimAngular);
791 connect(actionDimAngular, SIGNAL(activated()), actionHandler, SLOT(slotDimAngular()));
792 connect(this, SIGNAL(windowsChanged(bool)), actionDimAngular, SLOT(setEnabled(bool)));
793 menu->addAction(actionDimLeader);
794 connect(actionDimLeader, SIGNAL(activated()), actionHandler, SLOT(slotDimLeader()));
795 connect(this, SIGNAL(windowsChanged(bool)), actionDimLeader, SLOT(setEnabled(bool)));
797 m->insertItem(tr("&Dimension"), menu);
799 menuBar()->addMenu(menu);
802 // Modifying actions:
804 menu = new QMenu(tr("&Modify"), this);
805 menu->addAction(actionModifyMove);
806 connect(actionModifyMove, SIGNAL(activated()), actionHandler, SLOT(slotModifyMove()));
807 connect(this, SIGNAL(windowsChanged(bool)), actionModifyMove, SLOT(setEnabled(bool)));
808 menu->addAction(actionModifyRotate);
809 connect(actionModifyRotate, SIGNAL(activated()), actionHandler, SLOT(slotModifyRotate()));
810 connect(this, SIGNAL(windowsChanged(bool)), actionModifyRotate, SLOT(setEnabled(bool)));
811 menu->addAction(actionModifyScale);
812 connect(actionModifyScale, SIGNAL(activated()), actionHandler, SLOT(slotModifyScale()));
813 connect(this, SIGNAL(windowsChanged(bool)), actionModifyScale, SLOT(setEnabled(bool)));
814 menu->addAction(actionModifyMirror);
815 connect(actionModifyMirror, SIGNAL(activated()), actionHandler, SLOT(slotModifyMirror()));
816 connect(this, SIGNAL(windowsChanged(bool)), actionModifyMirror, SLOT(setEnabled(bool)));
817 menu->addAction(actionModifyMoveRotate);
818 connect(actionModifyMoveRotate, SIGNAL(activated()), actionHandler, SLOT(slotModifyMoveRotate()));
819 connect(this, SIGNAL(windowsChanged(bool)), actionModifyMoveRotate, SLOT(setEnabled(bool)));
820 menu->addAction(actionModifyRotate2);
821 connect(actionModifyRotate2, SIGNAL(activated()), actionHandler, SLOT(slotModifyRotate2()));
822 connect(this, SIGNAL(windowsChanged(bool)), actionModifyRotate2, SLOT(setEnabled(bool)));
823 menu->addAction(actionModifyTrim);
824 connect(actionModifyTrim, SIGNAL(activated()), actionHandler, SLOT(slotModifyTrim()));
825 connect(this, SIGNAL(windowsChanged(bool)), actionModifyTrim, SLOT(setEnabled(bool)));
826 menu->addAction(actionModifyTrim2);
827 connect(actionModifyTrim2, SIGNAL(activated()), actionHandler, SLOT(slotModifyTrim2()));
828 connect(this, SIGNAL(windowsChanged(bool)), actionModifyTrim2, SLOT(setEnabled(bool)));
829 menu->addAction(actionModifyTrimAmount);
830 connect(actionModifyTrimAmount, SIGNAL(activated()), actionHandler, SLOT(slotModifyTrimAmount()));
831 connect(this, SIGNAL(windowsChanged(bool)), actionModifyTrimAmount, SLOT(setEnabled(bool)));
832 menu->addAction(actionModifyBevel);
833 connect(actionModifyBevel, SIGNAL(activated()), actionHandler, SLOT(slotModifyBevel()));
834 connect(this, SIGNAL(windowsChanged(bool)), actionModifyBevel, SLOT(setEnabled(bool)));
835 menu->addAction(actionModifyRound);
836 connect(actionModifyRound, SIGNAL(activated()), actionHandler, SLOT(slotModifyRound()));
837 connect(this, SIGNAL(windowsChanged(bool)), actionModifyRound, SLOT(setEnabled(bool)));
838 menu->addAction(actionModifyCut);
839 connect(actionModifyCut, SIGNAL(activated()), actionHandler, SLOT(slotModifyCut()));
840 connect(this, SIGNAL(windowsChanged(bool)), actionModifyCut, SLOT(setEnabled(bool)));
841 menu->addAction(actionModifyStretch);
842 connect(actionModifyStretch, SIGNAL(activated()), actionHandler, SLOT(slotModifyStretch()));
843 connect(this, SIGNAL(windowsChanged(bool)), actionModifyStretch, SLOT(setEnabled(bool)));
844 menu->addAction(actionModifyEntity);
845 connect(actionModifyEntity, SIGNAL(activated()), actionHandler, SLOT(slotModifyEntity()));
846 connect(this, SIGNAL(windowsChanged(bool)), actionModifyEntity, SLOT(setEnabled(bool)));
847 menu->addAction(actionModifyAttributes);
848 connect(actionModifyAttributes, SIGNAL(activated()), actionHandler, SLOT(slotModifyAttributes()));
849 connect(this, SIGNAL(windowsChanged(bool)), actionModifyAttributes, SLOT(setEnabled(bool)));
850 menu->addAction(actionModifyDelete);
851 connect(actionModifyDelete, SIGNAL(activated()), actionHandler, SLOT(slotModifyDelete()));
852 connect(this, SIGNAL(windowsChanged(bool)), actionModifyDelete, SLOT(setEnabled(bool)));
853 menu->addAction(actionModifyDeleteQuick);
854 connect(actionModifyDeleteQuick, SIGNAL(activated()), actionHandler, SLOT(slotModifyDeleteQuick()));
855 connect(this, SIGNAL(windowsChanged(bool)), actionModifyDeleteQuick, SLOT(setEnabled(bool)));
856 menu->addAction(actionModifyExplodeText);
857 connect(actionModifyExplodeText, SIGNAL(activated()), actionHandler, SLOT(slotModifyExplodeText()));
858 connect(this, SIGNAL(windowsChanged(bool)), actionModifyExplodeText, SLOT(setEnabled(bool)));
859 menu->addAction(actionBlocksExplode);
860 connect(actionBlocksExplode, SIGNAL(activated()), actionHandler, SLOT(slotBlocksExplode()));
861 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksExplode, SLOT(setEnabled(bool)));
862 menuBar()->addMenu(menu);
866 menu = new QMenu(tr("&Snap"), this);
867 menu->addAction(actionSnapFree);
868 actionHandler->setActionSnapFree(actionSnapFree); // ???Why???
869 connect(actionSnapFree, SIGNAL(activated()), actionHandler, SLOT(slotSnapFree()));
870 connect(this, SIGNAL(windowsChanged(bool)), actionSnapFree, SLOT(setEnabled(bool)));
871 actionSnapFree->setChecked(true);
872 menu->addAction(actionSnapGrid);
873 actionHandler->setActionSnapGrid(actionSnapGrid); // ???Why???
874 connect(actionSnapGrid, SIGNAL(activated()), actionHandler, SLOT(slotSnapGrid()));
875 connect(this, SIGNAL(windowsChanged(bool)), actionSnapGrid, SLOT(setEnabled(bool)));
876 menu->addAction(actionSnapEndpoint);
877 actionHandler->setActionSnapEndpoint(actionSnapEndpoint); // ???Why???
878 connect(actionSnapEndpoint, SIGNAL(activated()), actionHandler, SLOT(slotSnapEndpoint()));
879 connect(this, SIGNAL(windowsChanged(bool)), actionSnapEndpoint, SLOT(setEnabled(bool)));
880 menu->addAction(actionSnapOnEntity);
881 actionHandler->setActionSnapOnEntity(actionSnapOnEntity); // ???Why???
882 connect(actionSnapOnEntity, SIGNAL(activated()), actionHandler, SLOT(slotSnapOnEntity()));
883 connect(this, SIGNAL(windowsChanged(bool)), actionSnapOnEntity, SLOT(setEnabled(bool)));
884 menu->addAction(actionSnapCenter);
885 actionHandler->setActionSnapCenter(actionSnapCenter); // ???Why???
886 connect(actionSnapCenter, SIGNAL(activated()), actionHandler, SLOT(slotSnapCenter()));
887 connect(this, SIGNAL(windowsChanged(bool)), actionSnapCenter, SLOT(setEnabled(bool)));
888 menu->addAction(actionSnapMiddle);
889 actionHandler->setActionSnapMiddle(actionSnapMiddle); // ???Why???
890 connect(actionSnapMiddle, SIGNAL(activated()), actionHandler, SLOT(slotSnapMiddle()));
891 connect(this, SIGNAL(windowsChanged(bool)), actionSnapMiddle, SLOT(setEnabled(bool)));
892 menu->addAction(actionSnapDist);
893 actionHandler->setActionSnapDist(actionSnapDist); // ???Why???
894 connect(actionSnapDist, SIGNAL(activated()), actionHandler, SLOT(slotSnapDist()));
895 connect(this, SIGNAL(windowsChanged(bool)), actionSnapDist, SLOT(setEnabled(bool)));
896 menu->addAction(actionSnapIntersection);
897 actionHandler->setActionSnapIntersection(actionSnapIntersection); // ???Why???
898 connect(actionSnapIntersection, SIGNAL(activated()), actionHandler, SLOT(slotSnapIntersection()));
899 connect(this, SIGNAL(windowsChanged(bool)), actionSnapIntersection, SLOT(setEnabled(bool)));
900 menu->addAction(actionSnapIntersectionManual);
901 actionHandler->setActionSnapIntersectionManual(actionSnapIntersectionManual); // ???Why???
902 connect(actionSnapIntersectionManual, SIGNAL(activated()), actionHandler, SLOT(slotSnapIntersectionManual()));
903 connect(this, SIGNAL(windowsChanged(bool)), actionSnapIntersectionManual, SLOT(setEnabled(bool)));
905 menu->addSeparator();
907 menu->addAction(actionRestrictNothing);
908 actionHandler->setActionRestrictNothing(actionRestrictNothing); // ???WHY???
909 connect(actionRestrictNothing, SIGNAL(activated()), actionHandler, SLOT(slotRestrictNothing()));
910 connect(this, SIGNAL(windowsChanged(bool)), actionRestrictNothing, SLOT(setEnabled(bool)));
911 actionRestrictNothing->setChecked(true);
912 menu->addAction(actionRestrictOrthogonal);
913 actionHandler->setActionRestrictOrthogonal(actionRestrictOrthogonal); // ???WHY???
914 connect(actionRestrictOrthogonal, SIGNAL(activated()), actionHandler, SLOT(slotRestrictOrthogonal()));
915 connect(this, SIGNAL(windowsChanged(bool)), actionRestrictOrthogonal, SLOT(setEnabled(bool)));
916 menu->addAction(actionRestrictHorizontal);
917 actionHandler->setActionRestrictHorizontal(actionRestrictHorizontal); // ???WHY???
918 connect(actionRestrictHorizontal, SIGNAL(activated()), actionHandler, SLOT(slotRestrictHorizontal()));
919 connect(this, SIGNAL(windowsChanged(bool)), actionRestrictHorizontal, SLOT(setEnabled(bool)));
920 menu->addAction(actionRestrictVertical);
921 actionHandler->setActionRestrictVertical(actionRestrictVertical); // ???WHY???
922 connect(actionRestrictVertical, SIGNAL(activated()), actionHandler, SLOT(slotRestrictVertical()));
923 connect(this, SIGNAL(windowsChanged(bool)), actionRestrictVertical, SLOT(setEnabled(bool)));
925 menu->addSeparator();
927 menu->addAction(actionSetRelativeZero);
928 connect(actionSetRelativeZero, SIGNAL(activated()), actionHandler, SLOT(slotSetRelativeZero()));
929 connect(this, SIGNAL(windowsChanged(bool)), actionSetRelativeZero, SLOT(setEnabled(bool)));
930 menu->addAction(actionLockRelativeZero);
931 actionHandler->setActionLockRelativeZero(actionLockRelativeZero);
932 connect(actionLockRelativeZero, SIGNAL(toggled(bool)), actionHandler, SLOT(slotLockRelativeZero(bool))); // ???WHY???
933 connect(this, SIGNAL(windowsChanged(bool)), actionLockRelativeZero, SLOT(setEnabled(bool)));
934 menuBar()->addMenu(menu);
939 menu = new QMenu(tr("&Info"), this);
940 menu->addAction(actionInfoDist);
941 connect(actionInfoDist, SIGNAL(activated()), actionHandler, SLOT(slotInfoDist()));
942 connect(this, SIGNAL(windowsChanged(bool)), actionInfoDist, SLOT(setEnabled(bool)));
943 menu->addAction(actionInfoDist2);
944 connect(actionInfoDist2, SIGNAL(activated()), actionHandler, SLOT(slotInfoDist2()));
945 connect(this, SIGNAL(windowsChanged(bool)), actionInfoDist2, SLOT(setEnabled(bool)));
946 menu->addAction(actionInfoAngle);
947 connect(actionInfoAngle, SIGNAL(activated()), actionHandler, SLOT(slotInfoAngle()));
948 connect(this, SIGNAL(windowsChanged(bool)), actionInfoAngle, SLOT(setEnabled(bool)));
949 menu->addAction(actionInfoTotalLength);
950 connect(actionInfoTotalLength, SIGNAL(activated()), actionHandler, SLOT(slotInfoTotalLength()));
951 connect(this, SIGNAL(windowsChanged(bool)), actionInfoTotalLength, SLOT(setEnabled(bool)));
952 menu->addAction(actionInfoArea);
953 connect(actionInfoArea, SIGNAL(activated()), actionHandler, SLOT(slotInfoArea()));
954 connect(this, SIGNAL(windowsChanged(bool)), actionInfoArea, SLOT(setEnabled(bool)));
955 menuBar()->addMenu(menu);
960 menu = new QMenu(tr("&Layer"), this);
961 menu->addAction(actionLayersDefreezeAll);
962 connect(actionLayersDefreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotLayersDefreezeAll()));
963 connect(this, SIGNAL(windowsChanged(bool)), actionLayersDefreezeAll, SLOT(setEnabled(bool)));
964 menu->addAction(actionLayersFreezeAll);
965 connect(actionLayersFreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotLayersFreezeAll()));
966 connect(this, SIGNAL(windowsChanged(bool)), actionLayersFreezeAll, SLOT(setEnabled(bool)));
967 menu->addAction(actionLayersAdd);
968 connect(actionLayersAdd, SIGNAL(activated()), actionHandler, SLOT(slotLayersAdd()));
969 connect(this, SIGNAL(windowsChanged(bool)), actionLayersAdd, SLOT(setEnabled(bool)));
970 menu->addAction(actionLayersRemove);
971 connect(actionLayersRemove, SIGNAL(activated()), actionHandler, SLOT(slotLayersRemove()));
972 connect(this, SIGNAL(windowsChanged(bool)), actionLayersRemove, SLOT(setEnabled(bool)));
973 menu->addAction(actionLayersEdit);
974 connect(actionLayersEdit, SIGNAL(activated()), actionHandler, SLOT(slotLayersEdit()));
975 connect(this, SIGNAL(windowsChanged(bool)), actionLayersEdit, SLOT(setEnabled(bool)));
976 menu->addAction(actionLayersToggleView);
977 connect(actionLayersToggleView, SIGNAL(activated()), actionHandler, SLOT(slotLayersToggleView()));
978 connect(this, SIGNAL(windowsChanged(bool)), actionLayersToggleView, SLOT(setEnabled(bool)));
979 menuBar()->addMenu(menu);
983 menu = new QMenu(tr("&Block"), this);
984 menu->addAction(actionBlocksDefreezeAll);
985 connect(actionBlocksDefreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotBlocksDefreezeAll()));
986 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksDefreezeAll, SLOT(setEnabled(bool)));
987 menu->addAction(actionBlocksFreezeAll);
988 connect(actionBlocksFreezeAll, SIGNAL(activated()), actionHandler, SLOT(slotBlocksFreezeAll()));
989 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksFreezeAll, SLOT(setEnabled(bool)));
990 menu->addAction(actionBlocksAdd);
991 connect(actionBlocksAdd, SIGNAL(activated()), actionHandler, SLOT(slotBlocksAdd()));
992 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksAdd, SLOT(setEnabled(bool)));
993 menu->addAction(actionBlocksRemove);
994 connect(actionBlocksRemove, SIGNAL(activated()), actionHandler, SLOT(slotBlocksRemove()));
995 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksRemove, SLOT(setEnabled(bool)));
996 menu->addAction(actionBlocksAttributes);
997 connect(actionBlocksAttributes, SIGNAL(activated()), actionHandler, SLOT(slotBlocksAttributes()));
998 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksAttributes, SLOT(setEnabled(bool)));
999 menu->addAction(actionBlocksInsert);
1000 connect(actionBlocksInsert, SIGNAL(activated()), actionHandler, SLOT(slotBlocksInsert()));
1001 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksInsert, SLOT(setEnabled(bool)));
1002 menu->addAction(actionBlocksEdit);
1003 connect(actionBlocksEdit, SIGNAL(activated()), actionHandler, SLOT(slotBlocksEdit()));
1004 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksEdit, SLOT(setEnabled(bool)));
1005 menu->addAction(actionBlocksCreate);
1006 connect(actionBlocksCreate, SIGNAL(activated()), actionHandler, SLOT(slotBlocksCreate()));
1007 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksCreate, SLOT(setEnabled(bool)));
1008 menu->addAction(actionBlocksExplode);
1009 connect(actionBlocksExplode, SIGNAL(activated()), actionHandler, SLOT(slotBlocksExplode()));
1010 connect(this, SIGNAL(windowsChanged(bool)), actionBlocksExplode, SLOT(setEnabled(bool)));
1011 menuBar()->addMenu(menu);
1013 //will *this* make a toolbar break for us???
1014 addToolBarBreak(Qt::TopToolBarArea);
1015 // addDockWindow(penToolBar, tr("Pen"), Qt::DockTop);
1016 // addDockWindow(optionWidget, tr("Tool Options"), Qt::DockTop, true);
1017 addToolBar(Qt::TopToolBarArea, (QToolBar *)penToolBar); // hmm.
1018 addToolBar(Qt::TopToolBarArea, optionWidget);
1023 scriptMenu = new QMenu(this);
1024 scriptOpenIDE = actionFactory.createAction(RS2::ActionScriptOpenIDE, this);
1025 scriptOpenIDE->addTo(scriptMenu);
1026 scriptRun = actionFactory.createAction(RS2::ActionScriptRun, this);
1027 scriptRun->addTo(scriptMenu);
1030 scriptOpenIDE = NULL;
1036 menu = new QMenu(tr("&CAM"), this);
1037 action = actionFactory.createAction(RS2::ActionCamExportAuto, actionHandler);
1038 menu->addAction(action);
1039 connect(this, SIGNAL(windowsChanged(bool)), action, SLOT(setEnabled(bool)));
1040 action = actionFactory.createAction(RS2::ActionCamReorder, actionHandler);
1041 menu->addAction(action);
1042 connect(this, SIGNAL(windowsChanged(bool)), action, SLOT(setEnabled(bool)));
1043 menuBar()->addMenu(menu);
1048 helpAboutApp = new QAction(QIcon("qcad16.png"), tr("&About Architektonas"), this);
1049 // helpAboutApp = new QAction(tr("About"), qPixmapFromMimeSource(QC_APP_ICON16), tr("&About %1").arg(QC_APPNAME), 0, this);
1050 helpAboutApp->setStatusTip(tr("About the application"));
1051 //helpAboutApp->setWhatsThis(tr("About\n\nAbout the application"));
1052 connect(helpAboutApp, SIGNAL(activated()), this, SLOT(slotHelpAbout()));
1054 helpManual = new QAction(QIcon(":/res/contents.png"), tr("&Manual"), this);
1055 helpManual->setShortcut(Qt::Key_F1);
1056 // helpManual = new QAction(qPixmapFromMimeSource("contents.png"), tr("&Manual"), Qt::Key_F1, this);
1057 helpManual->setStatusTip(tr("Launch the online manual"));
1058 connect(helpManual, SIGNAL(activated()), this, SLOT(slotHelpManual()));
1060 testDumpEntities = new QAction("Dump &Entities", this);
1061 connect(testDumpEntities, SIGNAL(activated()), this, SLOT(slotTestDumpEntities()));
1062 testDumpUndo = new QAction("Undo Info", this);
1063 connect(testDumpUndo, SIGNAL(activated()), this, SLOT(slotTestDumpUndo()));
1064 testUpdateInserts = new QAction("&Update Inserts", this);
1065 connect(testUpdateInserts, SIGNAL(activated()), this, SLOT(slotTestUpdateInserts()));
1066 testDrawFreehand = new QAction("Draw Freehand", this);
1067 connect(testDrawFreehand, SIGNAL(activated()), this, SLOT(slotTestDrawFreehand()));
1068 testInsertBlock = new QAction("Insert Block", this);
1069 connect(testInsertBlock, SIGNAL(activated()), this, SLOT(slotTestInsertBlock()));
1070 testInsertText = new QAction("Insert Text", this);
1071 connect(testInsertText, SIGNAL(activated()), this, SLOT(slotTestInsertText()));
1072 testInsertImage = new QAction("Insert Image", this);
1073 connect(testInsertImage, SIGNAL(activated()), this, SLOT(slotTestInsertImage()));
1074 testUnicode = new QAction("Unicode", this);
1075 connect(testUnicode, SIGNAL(activated()), this, SLOT(slotTestUnicode()));
1076 testInsertEllipse = new QAction("Insert Ellipse", this);
1077 connect(testInsertEllipse, SIGNAL(activated()), this, SLOT(slotTestInsertEllipse()));
1078 testMath01 = new QAction("Math01", this);
1079 connect(testMath01, SIGNAL(activated()), this, SLOT(slotTestMath01()));
1080 testResize640 = new QAction("Resize 1", this);
1081 connect(testResize640, SIGNAL(activated()), this, SLOT(slotTestResize640()));
1082 testResize800 = new QAction("Resize 2", this);
1083 connect(testResize800, SIGNAL(activated()), this, SLOT(slotTestResize800()));
1084 testResize1024 = new QAction("Resize 3", this);
1085 connect(testResize1024, SIGNAL(activated()), this, SLOT(slotTestResize1024()));
1089 * Initializes the menu bar.
1091 void ApplicationWindow::initMenuBar()
1093 DEBUG->print("ApplicationWindow::initMenuBar()");
1095 // menuBar entry windowsMenu
1096 windowsMenu = new QMenu(tr("&Window"), this);
1097 //according to docs, this is obsolete: windowsMenu->setCheckable(true);
1098 connect(windowsMenu, SIGNAL(aboutToShow()), this, SLOT(slotWindowsMenuAboutToShow()));
1100 // menuBar entry scriptMenu
1101 //scriptMenu = new QPopupMenu(this);
1102 //scriptMenu->setCheckable(true);
1103 //scriptOpenIDE->addTo(scriptMenu);
1104 //scriptRun->addTo(scriptMenu);
1105 //connect(scriptMenu, SIGNAL(aboutToShow()), this, SLOT(slotScriptMenuAboutToShow()));
1107 // menuBar entry helpMenu
1108 helpMenu = new QMenu(tr("&Help"), this);
1109 helpMenu->addAction(helpManual);
1110 helpMenu->addSeparator();
1111 helpMenu->addAction(helpAboutApp);
1113 // menuBar entry test menu
1114 testMenu = new QMenu(tr("De&bugging"), this);
1115 testMenu->addAction(testDumpEntities);
1116 testMenu->addAction(testDumpUndo);
1117 testMenu->addAction(testUpdateInserts);
1118 testMenu->addAction(testDrawFreehand);
1119 testMenu->addAction(testInsertBlock);
1120 testMenu->addAction(testInsertText);
1121 testMenu->addAction(testInsertImage);
1122 testMenu->addAction(testInsertEllipse);
1123 testMenu->addAction(testUnicode);
1124 testMenu->addAction(testMath01);
1125 testMenu->addAction(testResize640);
1126 testMenu->addAction(testResize800);
1127 testMenu->addAction(testResize1024);
1129 // menuBar configuration
1131 menuBar()->addMenu(scriptMenu);
1133 menuBar()->addMenu(windowsMenu);
1135 menuBar()->addMenu(helpMenu);
1138 menuBar()->addMenu(testMenu);
1140 recentFiles = new RecentFiles(this, fileMenu);
1144 * Initializes the tool bars (file tool bar and pen tool bar).
1146 void ApplicationWindow::initToolBar()
1148 DEBUG->print("ApplicationWindow::initToolBar()");
1150 fileToolBar = addToolBar(tr("File Operations"));
1151 fileToolBar->setObjectName("file");
1152 editToolBar = addToolBar(tr("Edit Operations"));
1153 editToolBar->setObjectName("edit");
1154 zoomToolBar = addToolBar(tr("Zoom Operations"));
1155 zoomToolBar->setObjectName("zoom");
1156 penToolBar = new PenToolBar(this, "Pen Selection");
1157 penToolBar->setObjectName("pen");
1159 connect(penToolBar, SIGNAL(penChanged(Pen)), this, SLOT(slotPenChanged(Pen)));
1161 // optionWidget = new Q3ToolBar(this, "Tool Options");
1162 //addToolBarBreak() does nothing...
1163 #warning "!!! add/insertToolBarBreak() does nothing !!!"
1164 // addToolBarBreak(Qt::TopToolBarArea);
1165 optionWidget = addToolBar(tr("Tool Options"));
1166 optionWidget->setObjectName("tooloptions");
1167 optionWidget->setMinimumHeight(26);
1168 optionWidget->setMaximumHeight(26);
1169 #warning "!!! No analogue found for setHorizontallyStretchable yet !!!"
1170 //Maybe sizePolicy or somesuch??
1171 optionWidget->setMinimumWidth(150);
1172 optionWidget->setMaximumWidth(800);
1173 #warning "Following line commented out..."
1174 // optionWidget->setFixedExtentHeight(26);
1175 // optionWidget->setHorizontallyStretchable(true);
1176 // addDockWindow(optionWidget, DockTop, true);
1178 // CAD toolbar left:
1179 // Q3ToolBar * t = new Q3ToolBar(this, "CAD Tools");
1180 QToolBar * t = addToolBar(tr("CAD Tools"));
1181 t->setObjectName("cadtools");
1182 #warning "Following two lines commented out..."
1183 // t->setFixedExtentWidth(59);
1184 t->setMinimumWidth(59);
1185 t->setMaximumWidth(59);
1186 // t->setVerticallyStretchable(true);
1187 // addDockWindow(t, Qt::DockLeft, false);
1188 addToolBar(Qt::LeftToolBarArea, t);
1190 cadToolBar = new CadToolBar(t);//, "CAD Tools");
1191 cadToolBar->createSubToolBars(actionHandler);
1193 connect(cadToolBar, SIGNAL(signalBack()), this, SLOT(slotBack()));
1194 connect(this, SIGNAL(windowsChanged(bool)), cadToolBar, SLOT(setEnabled(bool)));
1196 // QG_CadToolBarMain * cadToolBarMain = new QG_CadToolBarMain(cadToolBar);
1197 //No, no break inserted here either...
1198 // insertToolBarBreak(optionWidget);
1202 * Initializes the status bar at the bottom.
1204 void ApplicationWindow::initStatusBar()
1206 DEBUG->print("ApplicationWindow::initStatusBar()");
1208 statusBar()->setMinimumHeight(32);
1209 coordinateWidget = new CoordinateWidget(statusBar());
1210 statusBar()->addWidget(coordinateWidget);
1211 mouseWidget = new MouseWidget(statusBar());
1212 statusBar()->addWidget(mouseWidget);
1213 selectionWidget = new SelectionWidget(statusBar());
1214 statusBar()->addWidget(selectionWidget);
1218 * Initializes the global application settings from the
1219 * config file (unix, mac) or registry (windows).
1220 * (Actually, this uses the Qt settings subsystem, so we don't have to worry
1223 void ApplicationWindow::initSettings()
1225 DEBUG->print("ApplicationWindow::initSettings()");
1226 settings.beginGroup("RecentFiles");
1228 for(int i=0; i<recentFiles->Maximum(); ++i)
1230 QString filename = settings.value(QString("File") + QString::number(i + 1)).toString();
1232 if (!filename.isEmpty())
1233 recentFiles->add(filename);
1236 settings.endGroup();
1238 if (recentFiles->count() > 0)
1239 recentFiles->UpdateGUI();
1241 settings.beginGroup("Geometry");
1242 QSize windowSize = settings.value("WindowSize", QSize(950, 700)).toSize();
1243 QPoint windowPos = settings.value("WindowPos", QPoint(0, 30)).toPoint();
1244 restoreState(settings.value("DockWindows").toByteArray());
1245 settings.endGroup();
1248 if (windowSize.y() < 30)
1249 windowSize.y() = 30;
1257 * Stores the global application settings to file or registry.
1259 void ApplicationWindow::storeSettings()
1261 DEBUG->print("ApplicationWindow::storeSettings()");
1263 settings.beginGroup("RecentFiles");
1265 for(int i=0; i<recentFiles->count(); ++i)
1266 settings.setValue(QString("File") + QString::number(i + 1), recentFiles->get(i));
1268 settings.endGroup();
1270 settings.beginGroup("Geometry");
1271 settings.setValue("WindowSize", size());
1272 settings.setValue("WindowPos", pos());
1273 settings.setValue("DockWindows", saveState());
1274 settings.endGroup();
1276 DEBUG->print("ApplicationWindow::storeSettings(): OK");
1280 * Initializes the view.
1282 void ApplicationWindow::initView()
1284 DEBUG->print("ApplicationWindow::initView()");
1286 DEBUG->print("init view..");
1290 libraryWidget = NULL;
1291 commandWidget = NULL;
1293 simulationControls = NULL;
1297 DEBUG->print(" simulation widget..");
1298 dw = new QDockWidget(QDockWidget::InDock, this, "Simulation");
1299 simulationControls = new RS_SimulationControls(dw, "Simulation");
1300 simulationControls->setFocusPolicy(Qt::NoFocus);
1301 connect(simulationControls, SIGNAL(escape()), this, SLOT(slotFocus()));
1302 connect(this, SIGNAL(windowsChanged(bool)), simulationControls, SLOT(setEnabled(bool)));
1303 dw->setWidget(simulationControls);
1304 dw->resize(240, 80);
1305 dw->setResizeEnabled(true);
1306 dw->setFixedExtentWidth(120);
1307 dw->setFixedHeight(80);
1308 dw->setCaption(tr("Simulation Controls"));
1309 dw->setCloseMode(Q3DockWindow::Always);
1310 addDockWindow(dw, Qt::DockRight);
1311 simulationDockWindow = dw;
1312 //simulationDockWindow->hide();
1315 DEBUG->print(" layer widget..");
1316 // dw = new QDockWidget(QDockWidget::InDock, this, "Layer");
1317 dw = new QDockWidget(tr("Layer List"), this);
1318 dw->setObjectName("layer");
1319 layerWidget = new LayerWidget(actionHandler, dw, "Layer");
1320 layerWidget->setFocusPolicy(Qt::NoFocus);
1321 connect(layerWidget, SIGNAL(escape()), this, SLOT(slotFocus()));
1322 connect(this, SIGNAL(windowsChanged(bool)), layerWidget, SLOT(setEnabled(bool)));
1323 dw->setWidget(layerWidget);
1324 #warning "following four lines commented out..."
1325 // dw->setFixedExtentWidth(120);
1326 // dw->setResizeEnabled(true);
1327 // dw->setCloseMode(Q3DockWindow::Always);
1328 // dw->setCaption(tr("Layer List"));
1329 addDockWidget(Qt::RightDockWidgetArea, dw);
1330 layerDockWindow = dw;
1332 DEBUG->print(" block widget..");
1333 // dw = new QDockWidget(QDockWidget::InDock, this, "Block");
1334 dw = new QDockWidget(tr("Block List"), this);
1335 dw->setObjectName("block");
1336 blockWidget = new BlockWidget(actionHandler, dw, "Block");
1337 blockWidget->setFocusPolicy(Qt::NoFocus);
1338 connect(blockWidget, SIGNAL(escape()), this, SLOT(slotFocus()));
1339 connect(this, SIGNAL(windowsChanged(bool)), blockWidget, SLOT(setEnabled(bool)));
1340 dw->setWidget(blockWidget);
1341 #warning "following four lines commented out..."
1342 // dw->setFixedExtentWidth(120);
1343 // dw->setResizeEnabled(true);
1344 // dw->setCloseMode(Q3DockWindow::Always);
1345 // dw->setCaption(tr("Block List"));
1346 addDockWidget(Qt::RightDockWidgetArea, dw);
1347 blockDockWindow = dw;
1349 DEBUG->print(" library widget..");
1350 // dw = new QDockWidget(QDockWidget::OutsideDock, this, "Library");
1351 dw = new QDockWidget(tr("Library Browser"), this);
1352 dw->setObjectName("library");
1353 libraryWidget = new LibraryWidget(dw);//WAS:, "Library");
1354 libraryWidget->setActionHandler(actionHandler);
1355 libraryWidget->setFocusPolicy(Qt::NoFocus);
1356 connect(libraryWidget, SIGNAL(escape()), this, SLOT(slotFocus()));
1358 // connect(this, SIGNAL(windowsChanged(bool)), (QObject *)libraryWidget->bInsert, SLOT(setEnabled(bool)));
1359 dw->setWidget(libraryWidget);
1360 dw->resize(240, 400);
1361 #warning "following three lines commented out..."
1362 // dw->setResizeEnabled(true);
1363 // dw->setCloseMode(Q3DockWindow::Always);
1364 // dw->setCaption(tr("Library Browser"));
1365 //not sure how to fix this one
1366 #warning "QMainWindow::addDockWidget: invalid 'area' argument"
1367 // addDockWidget(Qt::NoDockWidgetArea, dw);
1368 //This works, but sux
1369 addDockWidget(Qt::RightDockWidgetArea, dw);
1370 libraryDockWindow = dw;
1371 // libraryDockWindow->hide();
1373 DEBUG->print(" command widget..");
1374 // dw = new QDockWidget(QDockWidget::InDock, this, "Command");
1375 dw = new QDockWidget(tr("Command line"), this);
1376 dw->setObjectName("command");
1377 commandWidget = new CommandWidget(dw);//WAS:, "Command");
1378 commandWidget->setActionHandler(actionHandler);
1379 // commandWidget->redirectStderr();
1380 // std::cerr << "Ready.\n";
1381 // commandWidget->processStderr();
1382 connect(this, SIGNAL(windowsChanged(bool)), commandWidget, SLOT(setEnabled(bool)));
1383 dw->setWidget(commandWidget);
1384 #warning "following four lines commented out..."
1385 // dw->setFixedExtentHeight(45);
1386 // dw->setResizeEnabled(true);
1387 // dw->setCloseMode(QDockWidget::Always);
1388 // dw->setCaption(tr("Command line"));
1389 commandDockWindow = dw;
1390 addDockWidget(Qt::BottomDockWidgetArea, dw);
1392 DEBUG->print(" done");
1396 * Goes back to the previous menu or one step in the current action.
1398 void ApplicationWindow::slotBack()
1400 GraphicView * graphicView = getGraphicView();
1403 graphicView->back();
1407 cadToolBar->showToolBar(RS2::ToolBarMain);
1412 * Goes one step further in the current action.
1414 void ApplicationWindow::slotEnter()
1416 if (!commandWidget || !commandWidget->checkFocus())
1419 cadToolBar->forceNext();
1422 GraphicView * graphicView = getGraphicView();
1425 graphicView->enter();
1431 * Sets the keyboard focus on the command line.
1433 void ApplicationWindow::slotFocusCommandLine()
1435 if (commandWidget->isVisible())
1436 commandWidget->setFocus();
1440 * Shows the given error on the command line.
1442 void ApplicationWindow::slotError(const QString & msg)
1444 commandWidget->appendHistory(msg);
1448 * Hands focus back to the application window. In the rare event of a escape
1449 * press from the layer widget (e.g after switching desktops in XP).
1451 void ApplicationWindow::slotFocus()
1457 * Called when a document window was activated.
1459 //void ApplicationWindow::slotWindowActivated(QMdiSubWindow * /*w*/)
1460 void ApplicationWindow::slotWindowActivated(QMdiSubWindow * sw)
1462 //This passes in a QMdiSubWindow, so why don't we use it???
1464 //#warning "!!! ApplicationWindow::slotWindowActivated() ignores passed in value !!!"
1465 DEBUG->print("ApplicationWindow::slotWindowActivated begin");
1467 //the following does: return (MDIWindow *)workspace->activeSubWindow();
1468 //which means the subwindow is NOT being activated!!!
1469 // MDIWindow * m = getMDIWindow();
1470 MDIWindow * m = (MDIWindow *)sw;
1471 // MDIWindow * m = (MDIWindow *)(sw->widget());
1472 DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::slotWindowActivated m=%08X", m);
1473 DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::slotWindowActivated m->getDoc=%08X",
1474 (m ? m->getDocument() : 0));
1476 if (m && m->getDocument())
1478 //m->setWindowState(WindowMaximized);
1480 DEBUG->print("ApplicationWindow::slotWindowActivated: document: %d", m->getDocument()->getId());
1482 bool showByBlock = m->getDocument()->rtti() == RS2::EntityBlock;
1483 layerWidget->setLayerList(m->getDocument()->getLayerList(), showByBlock);
1484 coordinateWidget->setGraphic(m->GetDrawing());
1487 simulationControls->setGraphicView(m->getGraphicView());
1490 // Only graphics show blocks. (blocks don't)
1491 // if (m->getDocument()->rtti() == RS2::EntityDrawing)
1492 // blockWidget->setBlockList(m->getDocument()->getBlockList());
1494 // blockWidget->setBlockList(NULL);
1495 blockWidget->setBlockList(m->getDocument()->rtti() == RS2::EntityDrawing
1496 ? m->getDocument()->getBlockList() : NULL);
1498 // Update all inserts in this graphic (blocks might have changed):
1499 m->getDocument()->updateInserts();
1500 m->getGraphicView()->redraw();
1502 // set snapmode from snapping menu
1503 actionHandler->updateSnapMode();
1505 // set pen from pen toolbar
1506 slotPenChanged(penToolBar->getPen());
1508 // update toggle button status:
1509 if (m->GetDrawing())
1511 //This is odd... why do this when you can just call the function directly? It's
1512 //IN this class after all...
1513 // emit(gridChanged(m->GetDrawing()->isGridOn()));
1514 // emit(printPreviewChanged(m->getGraphicView()->isPrintPreview()));
1515 actionViewGrid->setChecked(m->GetDrawing()->isGridOn());
1516 actionFilePrintPreview->setChecked(m->getGraphicView()->isPrintPreview());
1520 //This works, but for some reason after this function is over, the subwindow is no
1521 //longer activated. Need to find out why.
1522 //OK, I can see that the workspace isn't getting this window as activated or current.
1523 //Which means that something is definitely wrong here...
1525 //Seems to work now.
1526 //#warning "This is failing... !!! FIX !!!"
1527 printf("slotWindowActivated(QMdiSubWindow *): m=%08X, m->getDocument()=%08X...\n", (uint)m, (uint)(m ? m->getDocument() : 0));
1528 printf("slotWindowActivated(QMdiSubWindow *): activeWindow=%08X...\n", (uint)workspace->activeSubWindow());
1529 printf("slotWindowActivated(QMdiSubWindow *): currentWindow=%08X...\n", (uint)workspace->currentSubWindow());
1530 // slotWindowActivated(QMdiSubWindow * /*w*/): m=00000000, m->getDocument()=00000000...
1532 // Disable/Enable menu and toolbar items
1533 //This is odd... why do this when you can just call the function directly? It's
1534 //IN this class after all...
1535 //In this case it makes a little sense, as the signal is connected to all the actions'
1536 //setEnabled() function calls.
1537 emit(windowsChanged(m != NULL && m->getDocument() != NULL));
1539 DEBUG->print("ApplicationWindow::slotWindowActivated end");
1543 * Called when the menu 'windows' is about to be shown.
1544 * This is used to update the window list in the menu.
1546 void ApplicationWindow::slotWindowsMenuAboutToShow()
1548 DEBUG->print("ApplicationWindow::slotWindowsMenuAboutToShow");
1550 windowsMenu->clear();
1552 int cascadeId = windowsMenu->insertItem(tr("&Cascade"), workspace, SLOT(cascade()));
1553 int tileId = windowsMenu->insertItem(tr("&Tile"), this, SLOT(slotTileVertical()));
1554 int horTileId = windowsMenu->insertItem(tr("Tile &Horizontally"), this, SLOT(slotTileHorizontal()));
1556 if (workspace->subWindowList().isEmpty())
1558 windowsMenu->setItemEnabled(cascadeId, false);
1559 windowsMenu->setItemEnabled(tileId, false);
1560 windowsMenu->setItemEnabled(horTileId, false);
1563 windowsMenu->insertSeparator();
1565 #warning "!!! Qt4 implementation of insertItem is vastly different from Qt3--FIX !!!"
1567 QList<QMdiSubWindow *> windows = workspace->subWindowList();
1568 //printf("ApplicationWindow::slotWindowsMenuAboutToShow(): workspace->activeSubWindow = %08X\n", workspace->activeSubWindow());
1569 //printf("ApplicationWindow::slotWindowsMenuAboutToShow(): workspace->currentSubWindow = %08X\n", workspace->currentSubWindow());
1571 //#warning "Need to add window numbers underlined so can access windows via keyboard. !!! FIX !!!"
1573 for(int i=0; i<int(windows.count()); i++)
1575 //printf("--> Windows.at(i) = %08X\n", windows.at(i));
1576 // int id = windowsMenu->insertItem(windows.at(i)->caption(), this, SLOT(slotWindowsMenuActivated(int)));
1577 //For some reason the triggered() signal created here is type bool... Dunno why...
1578 //It's signalling using the QAction signal, which is type bool (checked or not).
1580 QString actionName = QString("&%1 %2").arg(i + 1).arg(windows.at(i)->windowTitle());
1581 // QAction * action = new QAction(windows.at(i)->windowTitle(), this);
1582 QAction * action = new QAction(actionName, this);
1583 action->setCheckable(true);
1585 //Neither of these work...
1586 // action->setChecked(workspace->activeSubWindow() == windows.at(i));
1587 action->setChecked(workspace->currentSubWindow() == windows.at(i));
1588 windowsMenu->addAction(action);
1589 connect(windowsMenu, SIGNAL(triggered(QAction *)), this, SLOT(slotWindowsMenuActivated(QAction *)));
1590 // connect(blockWidget, SIGNAL(escape()), this, SLOT(slotFocus()));
1592 QAction * id = windowsMenu->addAction(windows.at(i)->windowTitle(), this,
1593 // SLOT(slotWindowsMenuActivated(int)));
1594 SLOT(slotWindowsMenuActivated(QAction *)));
1596 // windowsMenu->setItemParameter(id, i);
1597 // windowsMenu->setItemChecked(id, workspace->activeSubWindow() == windows.at(i));
1599 id->setChecked(workspace->activeSubWindow() == windows.at(i));
1605 * Called when the user selects a document window from the
1608 void ApplicationWindow::slotWindowsMenuActivated(QAction * id)
1610 DEBUG->print("ApplicationWindow::slotWindowsMenuActivated");
1612 // QMdiSubWindow * w = workspace->subWindowList().at(id);
1613 QMdiSubWindow * w = workspace->subWindowList().at(id->data().toInt());
1614 printf("ApplicationWindow::slotWindowsMenuActivated: QMdiSubWindow * w = %08X\n", (uint32_t)w);
1617 workspace->setActiveSubWindow(w);
1618 // w->showMaximized();
1620 printf("--> w is%s activated (activeSW=%08X)\n", (workspace->activeSubWindow() ? "" : " NOT"), (uint32_t)(workspace->activeSubWindow()));
1624 * Tiles MDI windows horizontally.
1626 void ApplicationWindow::slotTileHorizontal()
1628 DEBUG->print("ApplicationWindow::slotTileHorizontal");
1631 // primitive horizontal tiling
1632 QWidgetList windows = workspace->windowList();
1634 if (windows.count() == 0)
1637 int heightForEach = workspace->height() / windows.count();
1640 for(int i=0; i<int(windows.count()); ++i)
1642 QWidget * window = windows.at(i);
1644 #warning "Need to port to Qt4... !!! FIX !!!"
1646 if (window->testWState(WState_Maximized))
1650 window->showNormal();
1654 int preferredHeight = window->minimumHeight() + window->parentWidget()->baseSize().height();
1655 int actHeight = QMAX(heightForEach, preferredHeight);
1657 // window->parentWidget()->resize(workspace->width(), actHeight);
1658 window->parentWidget()->setGeometry(0, y, workspace->width(), actHeight);
1662 workspace->tileSubWindows();
1667 * Tiles MDI windows vertically.
1669 void ApplicationWindow::slotTileVertical()
1675 QWidgetList windows = workspace->windowList();
1676 if (windows.count()==0) {
1680 //int heightForEach = workspace->height() / windows.count();
1682 for (int i=0; i<int(windows.count()); ++i) {
1683 QWidget *window = windows.at(i);
1684 if (window->testWState(WState_Maximized)) {
1687 window->showNormal();
1689 //int preferredHeight = window->minimumHeight()
1690 // + window->parentWidget()->baseSize().height();
1691 //int actHeight = QMAX(heightForEach, preferredHeight);
1693 //window->parentWidget()->setGeometry(0, y,
1694 // workspace->width(), actHeight);
1695 //window->parentWidget()->resize(window->parentWidget()->width(),
1696 // window->parentWidget()->height());
1697 //window->resize(window->width(), window->height());
1702 workspace->tileSubWindows();
1711 void ApplicationWindow::slotCamExportAuto() {
1712 printf("CAM export..\n");
1714 Document* d = getDocument();
1716 Drawing* graphic = (Drawing*)d;
1718 RS_CamDialog dlg(graphic, this);
1726 * Called when something changed in the pen tool bar (e.g. color, width,
1729 void ApplicationWindow::slotPenChanged(Pen pen)
1731 DEBUG->print("ApplicationWindow::slotPenChanged() begin");
1732 DEBUG->print("Setting active pen...");
1733 MDIWindow * m = getMDIWindow();
1736 m->slotPenChanged(pen);
1738 DEBUG->print("ApplicationWindow::slotPenChanged() end");
1742 * Creates a new MDI window with the given document or a new document if 'doc'
1745 MDIWindow * ApplicationWindow::slotFileNew(Document * doc/*= NULL*/)
1747 DEBUG->print("ApplicationWindow::slotFileNew() begin");
1752 statusBar()->showMessage(tr("Creating new file..."));
1754 //#warning "QWidget::setMinimumSize: (/QMdi::ControlLabel) Negative sizes (-1,-1) are not possible"
1755 DEBUG->print(" creating MDI window");
1756 // MDIWindow * w = new MDIWindow(doc, workspace, 0, Qt::WA_DeleteOnClose);
1757 MDIWindow * w = new MDIWindow(doc, workspace, 0, Qt::SubWindow);
1758 w->setAttribute(Qt::WA_DeleteOnClose);
1759 // w->setWindowState(WindowMaximized);
1760 connect(w, SIGNAL(signalClosing()), this, SLOT(slotFileClosing()));
1762 if (w->getDocument()->rtti() == RS2::EntityBlock)
1763 w->setWindowTitle(tr("Block '%1'").arg(((Block *)(w->getDocument()))->getName()));
1765 w->setWindowTitle(tr("Untitled Document %1").arg(id));
1767 w->setWindowIcon(QIcon(":/res/document.png"));
1770 // only graphics offer block lists, blocks don't
1771 DEBUG->print(" adding listeners");
1772 Drawing * graphic = w->getDocument()->getGraphic();
1774 if (graphic != NULL)
1776 // Link the graphic's layer list to the pen tool bar
1777 graphic->addLayerListListener(penToolBar);
1778 // Link the layer list to the layer widget
1779 graphic->addLayerListListener(layerWidget);
1780 // Link the block list to the block widget
1781 graphic->addBlockListListener(blockWidget);
1785 // Link the dialog factory to the mouse widget:
1786 QG_DIALOGFACTORY->setMouseWidget(mouseWidget);
1787 // Link the dialog factory to the coordinate widget:
1788 QG_DIALOGFACTORY->setCoordinateWidget(coordinateWidget);
1789 QG_DIALOGFACTORY->setSelectionWidget(selectionWidget);
1790 // Link the dialog factory to the option widget:
1791 // QG_DIALOGFACTORY->setOptionWidget(optionWidget);
1792 // Link the dialog factory to the cad tool bar:
1793 QG_DIALOGFACTORY->setCadToolBar(cadToolBar);
1794 // Link the dialog factory to the command widget:
1795 QG_DIALOGFACTORY->setCommandWidget(commandWidget);
1796 // Link the dialog factory to the main app window:
1797 QG_DIALOGFACTORY->setMainWindow(this);
1799 #if 1 //bugfix for Qt3->4 conversion
1800 DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::slotFileNew: adding window to workspace...");
1801 // workspace->addWindow(w);
1802 QMdiSubWindow * sw = workspace->addSubWindow(w);
1803 printf("MDIWindow=%08X, QMdiSubWindow=%08X\n", (uint)w, (uint)sw);
1806 DEBUG->print(" showing MDI window");
1809 #warning "w->showMaximized() doesn't seem to do anything here..."
1810 //but then again, the subWindowList isn't going to be empty at this point either...
1811 if (workspace->subWindowList().isEmpty())
1817 #warning "!!! SubWindow is not being activated !!!"
1818 //neither of these is working... Is the event being eaten somewhere???
1819 // workspace->activateNextSubWindow();
1821 //printf("--> ApplicationWindow::slotFileNew(): w %s focus...\n", (w->hasFocus() ? "has" : "DOES NOT HAVE"));
1823 //neither of these work either
1824 //w->activateWindow();
1826 //w->activateWindow();
1829 /*printf("FileNew: Setting active subwindow... (w=%08X)\n", (uint)w);
1830 workspace->setActiveSubWindow(w);
1831 printf("FileNew: Workspace active window = %08X\n", (uint)(workspace->activeSubWindow()));
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 //#warning "ApplicationWindow::slotFileExport(): Need to port to Qt4... !!! FIX !!!"
2256 // QImage image = buffer->toImage();
2257 // QImageWriter writer;
2258 // writer.setFileName(name);
2259 // writer.setFormat(format.toAscii().data());
2260 QImageWriter writer(name, format.toAscii().data());
2262 // if (writer.write(image))
2263 if (writer.write(buffer->toImage()))
2267 QApplication::restoreOverrideCursor();
2273 statusBar()->showMessage(tr("Export complete"), 2000);
2275 statusBar()->showMessage(tr("Export failed!"), 2000);
2281 * Menu file -> close.
2283 void ApplicationWindow::slotFileClose()
2285 DEBUG->print("ApplicationWindow::slotFileClose()");
2287 MDIWindow * m = getMDIWindow();
2296 //m->showMaximized();
2297 m->setWindowState(WindowMaximized);
2303 * Called when a MDI window is actually about to close. Used to
2304 * detach widgets from the document.
2306 void ApplicationWindow::slotFileClosing()
2308 DEBUG->print("ApplicationWindow::slotFileClosing()");
2310 DEBUG->print("detaching lists");
2311 layerWidget->setLayerList(NULL, false);
2312 blockWidget->setBlockList(NULL);
2313 coordinateWidget->setGraphic(NULL);
2315 simulationControls->setGraphicView(NULL);
2320 * Menu file -> print.
2322 void ApplicationWindow::slotFilePrint()
2324 DEBUG->print("ApplicationWindow::slotFilePrint()");
2326 MDIWindow * w = getMDIWindow();
2330 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFilePrint: no window opened");
2334 Drawing * drawing = w->getDocument()->GetDrawing();
2336 if (drawing == NULL)
2338 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFilePrint: no drawing");
2342 statusBar()->showMessage(tr("Printing..."));
2343 QPrinter * printer = new QPrinter(QPrinter::HighResolution);
2344 bool landscape = false;
2345 printer->setPageSize(RS2::rsToQtPaperFormat(drawing->getPaperFormat(&landscape)));
2348 printer->setOrientation(QPrinter::Landscape);
2350 printer->setOrientation(QPrinter::Portrait);
2352 settings.beginGroup("Print");
2353 printer->setOutputFileName(settings.value("FileName", "").toString());
2354 printer->setColorMode((QPrinter::ColorMode)settings.value("/ColorMode", (int)QPrinter::Color).toInt());
2355 #warning "!!! Need to port QPrinter::setOutputToFile() to Qt4 !!!"
2356 // printer->setOutputToFile((bool)RS_SETTINGS->readNumEntry("/PrintToFile", 0));
2357 settings.endGroup();
2360 // if (printer->setup(this))
2361 QPrintDialog dialog(printer, this);
2365 //printer->setOutputToFile(true);
2366 //printer->setOutputFileName(outputFile);
2368 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
2369 printer->setFullPage(true);
2370 //Can call these functions directly from the QPaintDevice...
2371 // Q3PaintDeviceMetrics metr(printer);
2373 // RS_PainterQt * painter = new RS_PainterQt(printer);
2374 QPainter qpntr(printer);
2375 PaintInterface * painter = new PaintInterface(&qpntr);
2376 painter->setDrawingMode(w->getGraphicView()->getDrawingMode());
2378 // StaticGraphicView gv(metr.width(), metr.height(), painter);
2379 StaticGraphicView gv(printer->width(), printer->height(), painter);
2380 gv.setPrinting(true);
2381 gv.setBorders(0, 0, 0, 0);
2383 // double fx = (double)metr.width() / metr.widthMM() * Units::getFactorToMM(graphic->getUnit());
2384 // double fy = (double)metr.height() / metr.heightMM() * Units::getFactorToMM(graphic->getUnit());
2385 double fx = (double)printer->width() / printer->widthMM() * Units::getFactorToMM(drawing->getUnit());
2386 double fy = (double)printer->height() / printer->heightMM() * Units::getFactorToMM(drawing->getUnit());
2387 double f = (fx + fy) / 2;
2388 double scale = drawing->getPaperScale();
2390 gv.setOffset((int)(drawing->getPaperInsertionBase().x * f),
2391 (int)(drawing->getPaperInsertionBase().y * f));
2392 gv.setFactor(f * scale);
2393 gv.setContainer(drawing);
2394 gv.drawEntity(drawing, true);
2398 settings.beginGroup("Print");
2399 #warning "!!! Need to port QPrinter::outputToFile() to Qt4 !!!"
2400 // settings.writeEntry("/PrintToFile", (int)printer->outputToFile());
2401 settings.setValue("ColorMode", (int)printer->colorMode());
2402 settings.setValue("FileName", printer->outputFileName());
2403 settings.endGroup();
2404 QApplication::restoreOverrideCursor();
2409 statusBar()->showMessage(tr("Printing complete"), 2000);
2413 * Menu file -> print preview.
2415 void ApplicationWindow::slotFilePrintPreview(bool on)
2417 DEBUG->print("ApplicationWindow::slotFilePrintPreview()");
2419 DEBUG->print(" creating MDI window");
2420 MDIWindow * parent = getMDIWindow();
2424 DEBUG->print(Debug::D_WARNING, "ApplicationWindow::slotFilePrintPreview: no window opened");
2428 // Close print preview:
2431 DEBUG->print("ApplicationWindow::slotFilePrintPreview(): off");
2433 if (parent->getGraphicView()->isPrintPreview())
2435 DEBUG->print("ApplicationWindow::slotFilePrintPreview(): close");
2439 // Open print preview:
2442 // look for an existing print preview:
2443 MDIWindow * ppv = parent->getPrintPreview();
2447 DEBUG->print("ApplicationWindow::slotFilePrintPreview(): show existing");
2448 slotWindowActivated(ppv);
2453 if (!parent->getGraphicView()->isPrintPreview())
2455 DEBUG->print("ApplicationWindow::slotFilePrintPreview(): create");
2457 MDIWindow * w = new MDIWindow(parent->getDocument(), workspace, 0, Qt::SubWindow);
2458 w->setAttribute(Qt::WA_DeleteOnClose);
2459 parent->addChildWindow(w);
2461 // w->setCaption(tr("Print preview for %1").arg(parent->caption()));
2462 w->setWindowTitle(tr("Print preview for %1").arg(parent->windowTitle()));
2463 // w->setIcon(qPixmapFromMimeSource("document.png"));
2464 // w->setWindowIcon(qPixmapFromMimeSource("document.png"));
2465 w->setWindowIcon(QIcon(":/res/document.png"));
2466 w->getGraphicView()->setPrintPreview(true);
2467 w->getGraphicView()->setBackground(Color(255, 255, 255));
2468 w->getGraphicView()->setDefaultAction(new ActionPrintPreview(*w->getDocument(), *w->getGraphicView()));
2470 // Only drawings offer block lists; blocks themselves don't
2471 // DEBUG->print(" adding listeners");
2472 Drawing * drawing = w->getDocument()->GetDrawing();
2476 // Center by default:
2477 drawing->centerToPage();
2480 // Link the graphic view to the mouse widget:
2481 QG_DIALOGFACTORY->setMouseWidget(mouseWidget);
2482 // Link the graphic view to the coordinate widget:
2483 QG_DIALOGFACTORY->setCoordinateWidget(coordinateWidget);
2484 QG_DIALOGFACTORY->setSelectionWidget(selectionWidget);
2485 // Link the graphic view to the option widget:
2486 //QG_DIALOGFACTORY->setOptionWidget(optionWidget);
2487 // Link the graphic view to the cad tool bar:
2488 QG_DIALOGFACTORY->setCadToolBar(cadToolBar);
2489 // Link the graphic view to the command widget:
2490 QG_DIALOGFACTORY->setCommandWidget(commandWidget);
2492 DEBUG->print(" showing MDI window");
2494 if (workspace->subWindowList().isEmpty())
2499 w->getGraphicView()->zoomPage();
2502 slotWindowActivated(w);
2509 * Menu file -> quit.
2511 void ApplicationWindow::slotFileQuit()
2513 DEBUG->print("ApplicationWindow::slotFileQuit()");
2515 statusBar()->showMessage(tr("Exiting application..."));
2522 * Shows/hides the grid.
2524 * @param toggle true: show, false: hide.
2526 void ApplicationWindow::slotViewGrid(bool toggle)
2528 DEBUG->print("ApplicationWindow::slotViewGrid()");
2530 MDIWindow * m = getMDIWindow();
2534 Drawing * d = m->GetDrawing();
2537 d->setGridOn(toggle);
2543 DEBUG->print("ApplicationWindow::slotViewGrid() OK");
2547 * Enables/disables draft mode.
2549 * @param toggle true: enable, false: disable.
2551 void ApplicationWindow::slotViewDraft(bool toggle)
2553 DEBUG->print("ApplicationWindow::slotViewDraft()");
2555 settings.beginGroup("Appearance");
2556 settings.setValue("DraftMode", toggle);
2557 settings.endGroup();
2563 * Redraws all MDI windows.
2565 void ApplicationWindow::redrawAll()
2567 if (workspace == NULL)
2570 QList<QMdiSubWindow *> windows = workspace->subWindowList();
2572 for(int i=0; i<windows.count(); i++)
2574 QG_GraphicView * gv = ((MDIWindow *)windows.at(i))->getGraphicView();
2582 * Updates all grids of all graphic views.
2584 void ApplicationWindow::updateGrids()
2586 if (workspace == NULL)
2589 QList<QMdiSubWindow *> windows = workspace->subWindowList();
2591 for(int i=0; i<windows.count(); i++)
2593 QG_GraphicView * gv = ((MDIWindow *)windows.at(i))->getGraphicView();
2601 * Shows / hides the status bar.
2603 * @param showSB true: show, false: hide.
2605 void ApplicationWindow::slotViewStatusBar(bool showSB)
2607 DEBUG->print("ApplicationWindow::slotViewStatusBar()");
2610 statusBar()->show();
2612 statusBar()->hide();
2616 * Shows the dialog for general application preferences.
2618 void ApplicationWindow::slotOptionsGeneral()
2620 DIALOGFACTORY->requestOptionsGeneralDialog();
2622 // Update background color of all open drawings:
2623 settings.beginGroup("Appearance");
2624 QColor color(settings.value("BackgroundColor", "#000000").toString());
2625 QColor gridColor(settings.value("GridColor", "Gray").toString());
2626 QColor metaGridColor(settings.value("MetaGridColor", "Darkgray").toString());
2627 QColor selectedColor(settings.value("SelectedColor", "#A54747").toString());
2628 QColor highlightedColor(settings.value("HighlightedColor", "#739373").toString());
2629 settings.endGroup();
2631 QList<QMdiSubWindow *> windows = workspace->subWindowList();
2633 for(int i=0; i<int(windows.count()); i++)
2635 MDIWindow * m = (MDIWindow *)windows.at(i);
2639 QG_GraphicView * gv = m->getGraphicView();
2643 gv->setBackground(color);
2644 gv->setGridColor(gridColor);
2645 gv->setMetaGridColor(metaGridColor);
2646 gv->setSelectedColor(selectedColor);
2647 gv->setHighlightedColor(highlightedColor);
2656 * Menu script -> show ide
2658 void ApplicationWindow::slotScriptOpenIDE()
2661 scripter->openIDE();
2666 * Menu script -> run
2668 void ApplicationWindow::slotScriptRun()
2671 scripter->runScript();
2676 * Menu help -> about.
2678 void ApplicationWindow::slotHelpAbout()
2680 DEBUG->print("ApplicationWindow::slotHelpAbout()");
2682 QStringList modules;
2689 modules += "Scripting";
2692 QString modulesString;
2694 if (!modules.empty())
2695 modulesString = modules.join(", ");
2697 modulesString = tr("None");
2700 QMessageBox box(this);
2701 box.setWindowTitle(tr("About..."));
2702 box.setText(QString("<center>")
2703 + "<h2>Architektonas</h2>"
2704 + tr("Version: %1").arg("1.0.0") + "<br>"
2705 + tr("Date: %1").arg(__DATE__) + "<br>"
2706 + QString("© 2010 Underground Software,<br>James Hammons") + "<br>"
2707 + QString("Portions © 2001-2003 RibbonSoft") + "<br>"
2708 + QString("</center>")
2710 #ifndef QC_ABOUT_HEADER
2711 #warning "Failure..."
2712 // box.setIcon(qPixmapFromMimeSource(QC_APP_ICON));
2713 box.setFixedWidth(340);
2714 box.setFixedHeight(250);
2720 * Menu help -> help.
2722 void ApplicationWindow::slotHelpManual()
2724 #warning "No help system ported to Qt4... !!! FIX !!!"
2726 DEBUG->print("ApplicationWindow::slotHelpManual()");
2728 if (assistant == NULL)
2730 DEBUG->print("ApplicationWindow::slotHelpManual(): appdir: %s", SYSTEM->getAppDir().toLatin1().data());
2731 DEBUG->print("ApplicationWindow::slotHelpManual(): appdir: %s", SYSTEM->getAppDir().toLatin1().data());
2732 assistant = new QAssistantClient(SYSTEM->getAppDir()+"/bin", this);
2733 connect(assistant, SIGNAL(error(const QString&)), this, SLOT(slotError(const QString&)));
2736 args << QDir::convertSeparators(SYSTEM->getDocPath() + "/qcaddoc.adp");
2737 // args << QString("doc") + QDir::separator() + QString("qcaddoc.adp");
2739 #if QT_VERSION>=0x030200
2740 assistant->setArguments(args);
2743 assistant->openAssistant();
2744 //assistant->showPage("index.html");
2751 void ApplicationWindow::slotTestDumpEntities(EntityContainer * d)
2753 DEBUG->print("ApplicationWindow::slotTestDumpEntities()");
2754 static int level = 0;
2755 std::ofstream dumpFile;
2760 dumpFile.open("debug_entities.html");
2765 dumpFile.open("debug_entities.html", std::ios::app);
2773 dumpFile << "<html>\n";
2774 dumpFile << "<body>\n";
2777 for (Entity* e=d->firstEntity();
2782 dumpFile << "<table border=\"1\">\n";
2783 dumpFile << "<tr><td>Entity: " << e->getId()
2787 << "<tr><td><table><tr>"
2788 << "<td>VIS:" << e->isVisible() << "</td>"
2789 << "<td>UND:" << e->isUndone() << "</td>"
2790 << "<td>SEL:" << e->isSelected() << "</td>"
2791 << "<td>TMP:" << e->getFlag(RS2::FlagTemp) << "</td>";
2792 QString lay = "NULL";
2793 if (e->getLayer()!=NULL) {
2794 lay = e->getLayer()->getName();
2797 //fail << "<td>Layer: " << lay << "</td>"
2798 << "<td>Width: " << (int)e->getPen(false).getWidth() << "</td>"
2799 << "<td>Parent: " << e->getParent()->getId() << "</td>"
2807 case RS2::EntityPoint:
2809 Point* p = (Point*)e;
2811 << "<table><tr><td>"
2823 case RS2::EntityLine:
2827 << "<table><tr><td>"
2833 << l->getStartpoint()
2842 case RS2::EntityArc: {
2845 << "<table><tr><td>"
2862 << "<td>Startpoint: "
2863 << a->getStartpoint()
2869 << (int)a->isReversed()
2875 case RS2::EntityCircle: {
2876 Circle* c = (Circle*)e;
2878 << "<table><tr><td>"
2893 case RS2::EntityDimAligned: {
2894 DimAligned* d = (DimAligned*)e;
2896 << "<table><tr><td>"
2897 << "<b>Dimension / Aligned:</b>"
2902 << d->getDefinitionPoint()
2905 << d->getExtensionPoint1()
2908 << d->getExtensionPoint2()
2911 << d->getText().toLatin1().data()
2914 << d->getLabel().toLatin1().data()
2920 case RS2::EntityDimLinear:
2922 DimLinear* d = (DimLinear*)e;
2924 << "<table><tr><td>"
2925 << "<b>Dimension / Linear:</b>"
2930 << d->getDefinitionPoint()
2933 << d->getExtensionPoint1()
2936 << d->getExtensionPoint2()
2939 //fail << d->getText()
2942 //fail << d->getLabel()
2948 case RS2::EntityInsert: {
2949 Insert* i = (Insert*)e;
2951 << "<table><tr><td>"
2956 << "<td>Insertion point:"
2957 << i->getInsertionPoint()
2963 case RS2::EntityText: {
2966 << "<table><tr><td>"
2972 << t->getText().toLatin1().data()
2981 case RS2::EntityHatch: {
2982 Hatch* h = (Hatch*)e;
2984 << "<table><tr><td>"
2990 << h->getPattern().toLatin1().data()
2996 << (int)h->isSolid()
3005 << "<b>Unknown Entity: " << e->rtti() << "</b>"
3010 if (e->isContainer() || e->rtti()==RS2::EntityHatch) {
3011 EntityContainer* ec = (EntityContainer*)e;
3012 dumpFile << "<table><tr><td valign=\"top\"> Contents:</td><td>\n";
3014 slotTestDumpEntities(ec);
3015 dumpFile.open("debug_entities.html", std::ios::app);
3016 dumpFile << "</td></tr></table>\n";
3026 dumpFile << "</body>\n";
3027 dumpFile << "</html>\n";
3037 void ApplicationWindow::slotTestDumpUndo()
3039 DEBUG->print("ApplicationWindow::slotTestDumpUndo()");
3041 Document * d = getDocument();
3045 std::cout << *(Undo*)d;
3046 std::cout << std::endl;
3053 void ApplicationWindow::slotTestUpdateInserts()
3055 DEBUG->print("ApplicationWindow::slotTestUpdateInserts()");
3057 Document * d = getDocument();
3066 void ApplicationWindow::slotTestDrawFreehand()
3068 DEBUG->print("ApplicationWindow::slotTestDrawFreehand()");
3070 //Drawing* g = document->getMarking();
3073 ActionDrawLineFree* action =
3074 new ActionDrawLineFree(*document->getGraphic(),
3077 for (int i=0; i<100; ++i) {
3079 int posx = (random()%600);
3080 int posy = (random()%400);
3082 //RS_MouseEvent rsm1(posx, posy, LEFT);
3083 RS_MouseEvent rsm1(QEvent::MouseButtonPress,
3087 action->mousePressEvent(&rsm1);
3092 for (int k=0; k<100; ++k) {
3093 int accx = (random()%40)-20;
3094 int accy = (random()%40)-20;
3102 //RS_MouseEvent rsm2(posx, posy, LEFT);
3104 RS_MouseEvent rsm2(QEvent::MouseMove,
3108 action->mouseMoveEvent(&rsm2);
3111 action->mouseReleaseEvent(NULL);
3123 void ApplicationWindow::slotTestInsertBlock()
3125 DEBUG->print("ApplicationWindow::slotTestInsertBlock()");
3127 Document * d = getDocument();
3129 if (d != NULL && d->rtti() == RS2::EntityDrawing)
3131 Drawing * graphic = (Drawing *)d;
3133 if (graphic == NULL)
3136 graphic->addLayer(new Layer("default"));
3137 Block * block = new Block(graphic, BlockData("debugblock", Vector(0.0, 0.0), true));
3143 // Add one red line:
3144 line = new Line(block, LineData(Vector(0.0, 0.0), Vector(50.0, 0.0)));
3145 line->setLayerToActive();
3146 line->setPen(Pen(Color(255, 0, 0), RS2::Width01, RS2::SolidLine));
3147 block->addEntity(line);
3149 // Add one line with attributes from block:
3150 line = new Line(block, LineData(Vector(50.0, 0.0), Vector(50.0, 50.0)));
3151 line->setPen(Pen(Color(RS2::FlagByBlock), RS2::WidthByBlock, RS2::LineByBlock));
3152 block->addEntity(line);
3154 // Add one arc with attributes from block:
3155 ArcData d(Vector(50.0, 0.0), 50.0, M_PI / 2.0, M_PI, false);
3156 arc = new Arc(block, d);
3157 arc->setPen(Pen(Color(RS2::FlagByBlock), RS2::WidthByBlock, RS2::LineByBlock));
3158 block->addEntity(arc);
3160 // Add one blue circle:
3161 CircleData circleData(Vector(20.0, 15.0), 12.5);
3162 circle = new Circle(block, circleData);
3163 circle->setLayerToActive();
3164 circle->setPen(Pen(Color(0, 0, 255), RS2::Width01, RS2::SolidLine));
3165 block->addEntity(circle);
3167 graphic->addBlock(block);
3170 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);
3172 // insert one magenta instance of the block (original):
3173 ins = new Insert(graphic, insData);
3174 ins->setLayerToActive();
3175 ins->setPen(Pen(Color(255, 0, 255), RS2::Width02, RS2::SolidLine));
3177 graphic->addEntity(ins);
3179 // insert one green instance of the block (rotate):
3180 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);
3181 ins = new Insert(graphic, insData);
3182 ins->setLayerToActive();
3183 ins->setPen(Pen(Color(0, 255, 0), RS2::Width02, RS2::SolidLine));
3185 graphic->addEntity(ins);
3187 // insert one cyan instance of the block (move):
3188 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);
3189 ins = new Insert(graphic, insData);
3190 ins->setLayerToActive();
3191 ins->setPen(Pen(Color(0, 255, 255), RS2::Width02, RS2::SolidLine));
3193 graphic->addEntity(ins);
3195 // insert one blue instance of the block:
3196 for(double a=0.0; a<360.0; a+=45.0)
3198 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);
3199 ins = new Insert(graphic, insData);
3200 ins->setLayerToActive();
3201 ins->setPen(Pen(Color(0, 0, 255), RS2::Width05, RS2::SolidLine));
3203 graphic->addEntity(ins);
3206 // insert an array of yellow instances of the block:
3207 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);
3208 ins = new Insert(graphic, insData);
3209 ins->setLayerToActive();
3210 ins->setPen(Pen(Color(255, 255, 0), RS2::Width01, RS2::SolidLine));
3212 graphic->addEntity(ins);
3214 GraphicView * v = getGraphicView();
3224 void ApplicationWindow::slotTestInsertEllipse()
3226 DEBUG->print("ApplicationWindow::slotTestInsertEllipse()");
3228 Document * d = getDocument();
3232 Drawing * graphic = (Drawing *)d;
3234 if (graphic == NULL)
3240 for (double a=0.0; a<2*M_PI; a+=0.1)
3243 v.setPolar(50.0, a);
3244 double xp = 1000.0*a;
3246 EllipseData ellipseData(Vector(xp, 0.0), v, 0.5, 0.0, 2 * M_PI, false);
3247 ellipse = new Ellipse(graphic, ellipseData);
3249 ellipse->setPen(Pen(Color(255, 0, 255), RS2::Width01, RS2::SolidLine));
3251 graphic->addEntity(ellipse);
3252 //graphic->addEntity(new Point(graphic, ellipse->getMax()));
3253 //graphic->addEntity(new Point(graphic, ellipse->getMin()));
3255 line = new Line(graphic, LineData(Vector(xp, 0.0), Vector(xp, 0.0) + v));
3256 line->setPen(Pen(Color(128, 128, 128), RS2::Width01, RS2::SolidLine));
3257 graphic->addEntity(line);
3260 for (double mx=-60.0; mx<60.0; mx+=1.0) {
3261 //for (double mx=0.0; mx<1.0; mx+=2.5) {
3262 VectorSolutions sol = ellipse->mapX(xp + mx);
3263 //graphic->addEntity(new Point(graphic,
3264 // sol.vector2 + Vector(a*500.0, 0.0)));
3265 //graphic->addEntity(new Point(graphic,
3266 // sol.vector3 + Vector(a*500.0, 0.0)));
3267 //graphic->addEntity(new Point(graphic,
3268 // sol.vector4 + Vector(a*500.0, 0.0)));
3270 line = new Line(graphic,
3271 LineData(Vector(xp+mx,-50.0),
3272 Vector(xp+mx,50.0)));
3273 line->setPen(Pen(Color(60, 60, 60),
3276 graphic->addEntity(line);
3278 graphic->addEntity(new Point(graphic,
3284 // different minor/minor relations
3287 for (y=-250.0; y<=250.0; y+=50.0) {
3288 for (x=-250.0; x<=250.0; x+=50.0) {
3291 ellipse = new Ellipse(graphic,
3293 Vector((x/5+50.0)/2.0, 0.0),
3298 ellipse->setPen(Pen(Color(255, 255, 0),
3302 graphic->addEntity(ellipse);
3303 graphic->addEntity(new Point(graphic, ellipse->getMax()));
3304 graphic->addEntity(new Point(graphic, ellipse->getMin()));
3306 ellipse = new Ellipse(graphic,
3307 v + Vector(750.0, 0.0),
3308 Vector((x/5+50.0)/2.0, 0.0),
3313 graphic->addEntity(ellipse);
3314 graphic->addEntity(new Point(graphic, ellipse->getMax()));
3315 graphic->addEntity(new Point(graphic, ellipse->getMin()));
3321 // different rotation angles:
3323 for (rot=0.0; rot<=2*M_PI+0.1; rot+=(M_PI/8)) {
3324 ellipse = new Ellipse(graphic,
3325 Vector(rot*200, 500.0),
3326 Vector(50.0, 0.0).rotate(rot),
3330 graphic->addEntity(ellipse);
3331 graphic->addEntity(new Point(graphic, ellipse->getMax()));
3332 graphic->addEntity(new Point(graphic, ellipse->getMin()));
3336 // different arc angles:
3338 for (rot=0.0; rot<=2*M_PI+0.1; rot+=(M_PI/8)) {
3339 for (a1=0.0; a1<=2*M_PI+0.1; a1+=(M_PI/8)) {
3340 for (a2=a1+M_PI/8; a2<=2*M_PI+a1+0.1; a2+=(M_PI/8)) {
3341 ellipse = new Ellipse(graphic,
3342 Vector(-500.0-a1*200.0-5000.0*rot,
3344 Vector(50.0, 0.0).rotate(rot),
3348 graphic->addEntity(ellipse);
3349 graphic->addEntity(new Point(graphic, ellipse->getMax()));
3350 graphic->addEntity(new Point(graphic, ellipse->getMin()));
3356 GraphicView * v = getGraphicView();
3366 void ApplicationWindow::slotTestInsertText()
3368 DEBUG->print("ApplicationWindow::slotTestInsertText()");
3370 Document * d = getDocument();
3374 Drawing * graphic = (Drawing *)d;
3376 if (graphic == NULL)
3382 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);
3383 text = new Text(graphic, textData);
3384 text->setLayerToActive();
3385 text->setPen(Pen(Color(255, 0, 0), RS2::Width01, RS2::SolidLine));
3386 graphic->addEntity(text);
3390 for (y=-250.0; y<=250.0; y+=50.0) {
3391 for (x=-250.0; x<=250.0; x+=50.0) {
3394 textData = TextData(v,
3405 text = new Text(graphic, textData);
3407 text->setLayerToActive();
3408 text->setPen(Pen(Color(255, 0, 0),
3411 graphic->addEntity(text);
3416 for (x=0.0; x<M_PI*2.0; x+=0.2) {
3417 Vector v(600.0+cos(x)*50.0, 0.0+sin(x)*50.0);
3419 line = new Line(graphic,
3420 LineData(Vector(600.0,0.0),
3422 line->setLayerToActive();
3423 line->setPenToActive();
3424 graphic->addEntity(line);
3426 textData = TextData(v,
3437 text = new Text(graphic, textData);
3439 text->setLayerToActive();
3440 text->setPen(Pen(Color(255, 0, 0),
3443 graphic->addEntity(text);
3446 SolidData solidData = SolidData(Vector(5.0, 10.0),
3448 Vector(15.0, 30.0));
3450 Solid* s = new Solid(graphic, solidData);
3452 s->setLayerToActive();
3453 s->setPen(Pen(Color(255, 255, 0),
3456 graphic->addEntity(s);
3458 GraphicView* v = getGraphicView();
3469 void ApplicationWindow::slotTestInsertImage()
3471 DEBUG->print("ApplicationWindow::slotTestInsertImage()");
3473 Document * d = getDocument();
3478 Drawing * drawing = (Drawing *)d;
3480 if (drawing == NULL)
3484 ImageData imageData;
3486 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);
3487 image = new Image(drawing, imageData);
3489 image->setLayerToActive();
3490 image->setPen(Pen(Color(255, 0, 0), RS2::Width01, RS2::SolidLine));
3491 drawing->addEntity(image);
3497 void ApplicationWindow::slotTestUnicode()
3499 DEBUG->print("ApplicationWindow::slotTestUnicode()");
3501 slotFileOpen("./fonts/unicode.cxf", RS2::FormatCXF);
3502 Document* d = getDocument();
3504 Drawing* graphic = (Drawing*)d;
3505 if (graphic==NULL) {
3513 QChar uCode; // e.g. 65 (or 'A')
3514 QString strCode; // unicde as string e.g. '[0041] A'
3516 graphic->setAutoUpdateBorders(false);
3518 for (col=0x0000; col<=0xFFF0; col+=0x10) {
3519 printf("col: %X\n", col);
3520 for (row=0x0; row<=0xF; row++) {
3521 //printf(" row: %X\n", row);
3523 uCode = QChar(col+row);
3524 //printf(" code: %X\n", uCode.unicode());
3526 strCode.setNum(uCode.unicode(), 16);
3527 while (strCode.length()<4) {
3528 strCode="0"+strCode;
3530 strCode = "[" + strCode + "] " + uCode;
3532 if (graphic->findBlock(strCode)!=NULL) {
3533 InsertData d(strCode,
3534 Vector(col/0x10*20.0,row*20.0),
3535 Vector(1.0,1.0), 0.0,
3536 1, 1, Vector(0.0, 0.0),
3537 NULL, RS2::NoUpdate);
3538 ins = new Insert(graphic, d);
3539 ins->setLayerToActive();
3540 ins->setPen(Pen(Color(255, 255, 255),
3544 graphic->addEntity(ins);
3548 graphic->setAutoUpdateBorders(true);
3549 graphic->calculateBorders();
3556 void ApplicationWindow::slotTestMath01()
3558 DEBUG->print("ApplicationWindow::slotTestMath01()");
3560 Document* d = getDocument();
3562 Drawing* graphic = (Drawing*)d;
3563 if (graphic==NULL) {
3568 graphic->addEntity(new Line(graphic,
3569 LineData(Vector(0.0,0.0),
3570 Vector(2*M_PI,0.0))));
3571 graphic->addEntity(new Line(graphic,
3572 LineData(Vector(0.0,-1.0),
3577 double x = 59.0/ARAD;
3578 double x_0 = 60.0/ARAD;
3579 for (a=0.01; a<2*M_PI; a+=0.01) {
3581 Line* line = new Line(graphic,
3582 LineData(Vector(a-0.01, cos(a-0.01)),
3583 Vector(a, cos(a))));
3584 graphic->addEntity(line);
3587 graphic->addEntity(new Line(graphic,
3588 LineData(Vector(a-0.01,cos(x_0)-sin(x_0)*(a-0.01-x_0)),
3589 Vector(a,cos(x_0)-sin(x_0)*(a-x_0)))));
3593 graphic->addEntity(new Line(graphic,
3594 LineData(Vector(x,0.0),
3598 graphic->addEntity(new Line(graphic,
3599 LineData(Vector(x_0,0.0),
3603 //graphic->addEntity(new Line(graphic,
3604 // Vector(0.0,cos(x_0)-sin(x_0)*(0.0-x_0)),
3605 // Vector(6.0,cos(x_0)-sin(x_0)*(6.0-x_0))));
3608 GraphicView* v = getGraphicView();
3618 void ApplicationWindow::slotTestResize640()
3620 DEBUG->print("ApplicationWindow::slotTestResize640()");
3628 void ApplicationWindow::slotTestResize800()
3630 DEBUG->print("ApplicationWindow::slotTestResize800()");
3638 void ApplicationWindow::slotTestResize1024()
3640 DEBUG->print("ApplicationWindow::slotTestResize1024()");
3646 * overloaded for Message box on last window exit.
3648 bool ApplicationWindow::QueryExit(void)
3650 DEBUG->print("ApplicationWindow::queryExit()");
3652 bool success = true;
3653 QList<QMdiSubWindow *> list = workspace->subWindowList();
3655 for(int i=0; i<list.size(); i++)
3657 success = ((MDIWindow *)list[i])->CloseMDI();
3666 DEBUG->print("ApplicationWindow::queryExit(): OK");
3672 * Handle hotkeys. Don't let it to the default handler of Qt.
3673 * it will consume them also if a text field is active
3674 * which means it's impossible to enter a command.
3676 void ApplicationWindow::keyPressEvent(QKeyEvent * e)
3678 #warning "!!! keyPressEvent(): Do we need this anymore? !!!"
3680 static QTime ts = QTime();
3681 static QString firstKey = "";
3683 // single key codes:
3687 case Qt::Key_Control:
3690 case Qt::Key_CapsLock:
3692 QMainWindow::keyPressEvent(e);
3694 // forward to actions:
3695 GraphicView * graphicView = getGraphicView();
3698 graphicView->_keyPressEvent(e);
3704 case Qt::Key_Escape:
3710 case Qt::Key_Return:
3711 if (firstKey.isEmpty())
3719 if (firstKey.isEmpty())
3721 actionHandler->slotZoomIn();
3727 if (firstKey.isEmpty())
3729 actionHandler->slotZoomOut();
3739 if (e->isAccepted())
3742 QTime now = QTime::currentTime();
3745 if (ts.msecsTo(now) < 2000)
3747 QString code = QString("%1%2").arg(firstKey).arg(QChar(e->key())).toLower();
3749 if (actionHandler->keycode(code) == false)
3753 if (QChar(e->key()).isPrint())
3754 firstKey += e->key();
3763 if (QChar(e->key()).isPrint())
3764 firstKey = e->key();
3767 // Q3MainWindow::keyPressEvent(e);
3768 QMainWindow::keyPressEvent(e);
3771 void ApplicationWindow::keyReleaseEvent(QKeyEvent * e)
3776 case Qt::Key_Control:
3779 case Qt::Key_CapsLock:
3781 // Q3MainWindow::keyReleaseEvent(e);
3782 QMainWindow::keyReleaseEvent(e);
3784 // forward to actions:
3785 GraphicView * graphicView = getGraphicView();
3788 graphicView->_keyReleaseEvent(e);
3795 // THIS LOOKS LIKE A BUG TO ME...
3796 #warning "!!! keyPressEvent called in keyReleaseEvent !!!"
3797 // Q3MainWindow::keyPressEvent(e);
3798 QMainWindow::keyPressEvent(e);
3802 * @return Pointer to application window.
3804 /*static*/ ApplicationWindow * ApplicationWindow::getAppWindow()
3810 * @return Pointer to workspace.
3812 QMdiArea * ApplicationWindow::getWorkspace()
3818 * @return Pointer to the currently active MDI Window or NULL if no MDI Window
3821 MDIWindow * ApplicationWindow::getMDIWindow()
3823 DEBUG->print(/*Debug::D_CRITICAL,*/ "ApplicationWindow::getMDIWindow: workspace=%08X", workspace);
3825 // Here is the problem: Window isn't active...
3828 printf("ApplicationWindow::getMDIWindow: activeSubWindow =%08X\n", (uint)workspace->activeSubWindow());
3829 printf("ApplicationWindow::getMDIWindow: currentSubWindow=%08X\n", (uint)workspace->currentSubWindow());
3830 DEBUG->print("ApplicationWindow::getMDIWindow: activeSubWindow=%08X", workspace->activeSubWindow());
3831 return (MDIWindow *)workspace->activeSubWindow();
3834 DEBUG->print("ApplicationWindow::getMDIWindow: activeSubWindow=??? (workspace == NULL)");
3839 * Implementation from MainWindowInterface (and QS_ScripterHostInterface).
3841 * @return Pointer to the graphic view of the currently active document
3842 * window or NULL if no window is available.
3844 /*virtual*/ GraphicView * ApplicationWindow::getGraphicView()
3846 MDIWindow * m = getMDIWindow();
3848 return (m ? m->getGraphicView() : NULL);
3852 * Implementation from MainWindowInterface (and QS_ScripterHostInterface).
3854 * @return Pointer to the graphic document of the currently active document
3855 * window or NULL if no window is available.
3857 /*virtual*/ Document * ApplicationWindow::getDocument()
3859 MDIWindow * m = getMDIWindow();
3861 return (m ? m->getDocument() : NULL);
3865 * Creates a new document. Implementation from MainWindowInterface.
3867 /*virtual*/ void ApplicationWindow::createNewDocument(const QString & fileName/*= QString::null*/,
3868 Document * doc/*= NULL*/)
3872 if (fileName != QString::null && getDocument())
3873 getDocument()->setFilename(fileName);
3878 * Implementation from QG_MainWindowInterface.
3880 * @return Pointer to this.
3882 /*virtual*/ QMainWindow * ApplicationWindow::GetMainWindow()
3888 * @return Pointer to action handler. Implementation from QG_MainWindowInterface.
3890 /*virtual*/ ActionHandler * ApplicationWindow::getActionHandler()
3892 return actionHandler;
3897 * Implementation from QG_MainWindowInterface.
3899 /*virtual*/ void ApplicationWindow::showSimulationControls()
3902 simulationDockWindow->show();
3908 * @return Pointer to the qsa object.
3910 QSProject * ApplicationWindow::getQSAProject()
3912 if (scripter != NULL)
3913 return scripter->getQSAProject();
3920 * Implementation from QG_MainWindowInterface.
3922 /*virtual*/ void ApplicationWindow::setFocus2()