-
-
Notifications
You must be signed in to change notification settings - Fork 972
/
qc_applicationwindow.cpp
4858 lines (4072 loc) · 162 KB
/
qc_applicationwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
**
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file gpl-2.0.txt included in the
** packaging of this file.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
**
** This copyright notice MUST APPEAR in all copies of the script!
**
**********************************************************************/
#include <QStatusBar>
#include <QMenuBar>
#include <QDockWidget>
#if QT_VERSION < 0x040400
#include <QtAssistant/QAssistantClient>
#include <QTime>
#include "emu_qt44.h"
#else
#include <QtHelp>
#include "helpbrowser.h"
#endif // QT_VERSION 0x040400
#include <QSplitter>
#include <QMdiArea>
#include "qc_applicationwindow.h"
// RVT_PORT added
#include <QImageWriter>
#if QT_VERSION >= 0x040300
#include <QtSvg>
#endif
#include <fstream>
#if QT_VERSION >= 0x050000
# include <QtPrintSupport/QPrinter>
# include <QtPrintSupport/QPrintDialog>
#else
# include <QPrinter>
# include <QPrintDialog>
#endif
#include <QFileDialog>
#include <QMessageBox>
#include <QTimer>
//Plugin support
#include <QPluginLoader>
#include "rs_actionprintpreview.h"
#include "rs_dimaligned.h"
#include "rs_dimlinear.h"
#include "rs_hatch.h"
#include "rs_image.h"
#include "rs_insert.h"
#include "rs_mtext.h"
#include "rs_text.h"
#include "rs_settings.h"
#include "rs_staticgraphicview.h"
#include "rs_system.h"
#include "rs_actionlibraryinsert.h"
#include "rs_painterqt.h"
#include "rs_selection.h"
#include "qg_cadtoolbar.h"
#include "qg_snaptoolbar.h"
#include "qg_actionfactory.h"
#include "qg_blockwidget.h"
#include "qg_layerwidget.h"
#include "qg_librarywidget.h"
#include "qg_commandwidget.h"
#include "qg_coordinatewidget.h"
#include "qg_dlgimageoptions.h"
#include "qg_filedialog.h"
#include "qg_selectionwidget.h"
#include "qg_activelayername.h"
#include "qg_mousewidget.h"
#include "rs_dialogfactory.h"
#include "qc_dialogfactory.h"
#include "main.h"
#include "doc_plugin_interface.h"
#include "qc_plugininterface.h"
#include "rs_commands.h"
QC_ApplicationWindow* QC_ApplicationWindow::appWindow = NULL;
#ifndef QC_APP_ICON
# define QC_APP_ICON ":/main/librecad.png"
#endif
#ifndef QC_ABOUT_ICON
# define QC_ABOUT_ICON ":/main/intro_librecad.png"
#endif
#ifndef QC_APP_ICON16
# define QC_APP_ICON16 ":/main/librecad16.png"
#endif
#include <QSplashScreen>
extern QSplashScreen *splash;
/* - Window Title Bar Extra (character) Size.
* - Notes: Extra characters appearing in the windows title bar
* are " - [", ... "]" (5), and sometimes "Print preview of " (17).
* */
#define WTB_EXTRA_SIZE (5 + 17)
/* Window Title Bar Maximum Size.
* Notes: On Windows XP, this is 79.
* */
#define WTB_MAX_SIZE 79
QAction* QC_ApplicationWindow::previousZoom=NULL;
QAction* QC_ApplicationWindow::undoButton=NULL;
QAction* QC_ApplicationWindow::redoButton=NULL;
/**
* Constructor. Initializes the app.
*/
QC_ApplicationWindow::QC_ApplicationWindow()
: QMainWindow(0),
QG_MainWindowInterface()
,m_qDraftModeTitle(" ["+tr("Draft Mode")+"]")
{
RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow");
setAttribute(Qt::WA_DeleteOnClose);
appWindow = this;
#if QT_VERSION < 0x040400
assistant = NULL;
#else
helpEngine = NULL;
helpWindow = NULL;
#endif // QT_VERSION 0x040400
mdiAreaCAD = NULL;
RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow: setting icon");
setWindowIcon(QIcon(QC_APP_ICON));
RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow: creating action handler");
actionHandler = new QG_ActionHandler(this);
RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow: creating action handler: OK");
#ifdef RS_SCRIPTING
RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow: creating scripter");
scripter = new QS_Scripter(this, this);
RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow: creating scripter: OK");
#endif
RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow: init view");
initView();
RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow: init toolbar");
initToolBar();
RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow: init actions");
initActions();
RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow: init menu bar");
initMenuBar();
RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow: init status bar");
initStatusBar();
RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow: creating dialogFactory");
dialogFactory = new QC_DialogFactory(this, optionWidget);
RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow: creating dialogFactory: OK");
RS_DEBUG->print("setting dialog factory object");
if (RS_DialogFactory::instance()==NULL) {
RS_DEBUG->print("no RS_DialogFactory instance");
}
else {
RS_DEBUG->print("got RS_DialogFactory instance");
}
RS_DialogFactory::instance()->setFactoryObject(dialogFactory);
RS_DEBUG->print("setting dialog factory object: OK");
RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow: init settings");
initSettings();
RS_DEBUG->print("QC_ApplicationWindow::QC_ApplicationWindow: init MDI");
initMDI();
// Activate autosave timer
autosaveTimer = new QTimer(this);
autosaveTimer->setObjectName("autosave");
connect(autosaveTimer, SIGNAL(timeout()), this, SLOT(slotFileAutoSave()));
RS_SETTINGS->beginGroup("/Defaults");
autosaveTimer->start(RS_SETTINGS->readNumEntry("/AutoSaveTime", 5)*60*1000);
RS_SETTINGS->endGroup();
// Disable menu and toolbar items
emit windowsChanged(false);
RS_COMMANDS->updateAlias();
//plugin load
loadPlugins();
QMenu *importMenu = findMenu("/File/Import", menuBar()->children(), "");
if (importMenu && importMenu->isEmpty())
importMenu->setDisabled(true);
statusBar()->showMessage(XSTR(QC_APPNAME) " Ready", 2000);
//setFocusPolicy(WheelFocus);
previousZoomEnable=false;
undoEnable=false;
redoEnable=false;
}
/**
* Find a menu entry in the current menu list. This function will try to recursivly find the menu
* searchMenu for example foo/bar
* thisMenuList list of Widgets
* currentEntry only used internally dueing recursion
* returns 0 when no menu was found
*/
QMenu *QC_ApplicationWindow::findMenu(const QString &searchMenu, const QObjectList thisMenuList, const QString& currentEntry) {
if (searchMenu==currentEntry)
return ( QMenu *)thisMenuList.at(0)->parent();
QList<QObject*>::const_iterator i=thisMenuList.begin();
while (i != thisMenuList.end()) {
if ((*i)->inherits ("QMenu")) {
QMenu *ii=(QMenu*)*i;
if (QMenu *foundMenu=findMenu(searchMenu, ii->children(), currentEntry+"/"+ii->objectName().replace("&", ""))) {
return foundMenu;
}
}
i++;
}
return 0;
}
/**
* Loads the found plugins.
*/
void QC_ApplicationWindow::loadPlugins() {
loadedPlugins.clear();
QStringList lst = RS_SYSTEM->getDirectoryList("plugins");
for (int i = 0; i < lst.size(); ++i) {
QDir pluginsDir(lst.at(i));
foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
QObject *plugin = pluginLoader.instance();
if (plugin) {
QC_PluginInterface *pluginInterface = qobject_cast<QC_PluginInterface *>(plugin);
if (pluginInterface) {
loadedPlugins.append(pluginInterface);
PluginCapabilities pluginCapabilities=pluginInterface->getCapabilities();
foreach (PluginMenuLocation loc, pluginCapabilities.menuEntryPoints) {
QAction *actpl = new QAction(loc.menuEntryActionName, plugin);
actpl->setData(loc.menuEntryActionName);
connect(actpl, SIGNAL(triggered()), this, SLOT(execPlug()));
connect(this, SIGNAL(windowsChanged(bool)), actpl, SLOT(setEnabled(bool)));
QMenu *atMenu = findMenu("/"+loc.menuEntryPoint, menuBar()->children(), "");
if (atMenu) {
atMenu->addAction(actpl);
} else {
QStringList treemenu = loc.menuEntryPoint.split('/', QString::SkipEmptyParts);
QString currentLevel="";
QMenu *parentMenu=0;
do {
QString menuName=treemenu.at(0); treemenu.removeFirst();
currentLevel=currentLevel+"/"+menuName;
atMenu = findMenu(currentLevel, menuBar()->children(), "");
if (atMenu==0) {
if (parentMenu==0) {
parentMenu=menuBar()->addMenu(menuName);
} else {
parentMenu=parentMenu->addMenu(menuName);
}
parentMenu->setObjectName(menuName);
}
} while(treemenu.size()>0);
parentMenu->addAction(actpl);
}
}
}
} else {
QMessageBox::information(this, "Info", pluginLoader.errorString());
RS_DEBUG->print("QC_ApplicationWindow::loadPlugin: %s", pluginLoader.errorString().toLatin1().data());
}
}
}
}
/**
* Execute the plugin.
*/
void QC_ApplicationWindow::execPlug() {
QAction *action = qobject_cast<QAction *>(sender());
QC_PluginInterface *plugin = qobject_cast<QC_PluginInterface *>(action->parent());
//get actual drawing
QC_MDIWindow* w = getMDIWindow();
RS_Document* currdoc = w->getDocument();
//create document interface instance
Doc_plugin_interface pligundoc(currdoc, w->getGraphicView(), this);
//execute plugin
plugin->execComm(&pligundoc, this, action->data().toString());
//TODO call update view
w->getGraphicView()->redraw();
}
/**
* Destructor.
*/
QC_ApplicationWindow::~QC_ApplicationWindow() {
RS_DEBUG->print("QC_ApplicationWindow::~QC_ApplicationWindow");
#ifdef RS_SCRIPTING
RS_DEBUG->print("QC_ApplicationWindow::~QC_ApplicationWindow: "
"deleting scripter");
delete scripter;
RS_DEBUG->print("QC_ApplicationWindow::~QC_ApplicationWindow: "
"deleting scripter: OK");
#endif
RS_DEBUG->print("QC_ApplicationWindow::~QC_ApplicationWindow: "
"deleting action handler");
delete actionHandler;
RS_DEBUG->print("QC_ApplicationWindow::~QC_ApplicationWindow: "
"deleting action handler: OK");
RS_DEBUG->print("QC_ApplicationWindow::~QC_ApplicationWindow: "
"deleting dialog factory");
delete dialogFactory;
RS_DEBUG->print("QC_ApplicationWindow::~QC_ApplicationWindow: "
"deleting dialog factory: OK");
RS_DEBUG->print("QC_ApplicationWindow::~QC_ApplicationWindow: "
"deleting assistant..");
#if QT_VERSION < 0x040400
if (assistant != NULL) {
delete assistant;
}
#else
if (helpEngine!=NULL) {
delete helpEngine;
}
if (helpWindow!=NULL) {
delete helpWindow;
}
#endif // QT_VERSION 0x040400
RS_DEBUG->print("QC_ApplicationWindow::~QC_ApplicationWindow: "
"deleting assistant: OK");
RS_DEBUG->print("QC_ApplicationWindow::~QC_ApplicationWindow: OK");
}
/**
* Runs the start script if scripting is available.
*/
void QC_ApplicationWindow::slotRunStartScript() {
slotRunScript("autostart.qs");
restoreDocks();
}
/**
* Runs a script. The action that triggers this slot has to carry the
* name of the script file.
*/
void QC_ApplicationWindow::slotRunScript() {
RS_DEBUG->print("QC_ApplicationWindow::slotRunScript");
const QObject* s = sender();
if (s!=NULL) {
QString script = ((QAction*)s)->text();
RS_DEBUG->print("QC_ApplicationWindow::slotRunScript: %s",
script.toLatin1().data());
slotRunScript(script);
}
}
/**
* Runs the script with the given name.
*/
void QC_ApplicationWindow::slotRunScript(const QString& name) {
Q_UNUSED(name);
#ifdef RS_SCRIPTING
RS_DEBUG->print("QC_ApplicationWindow::slotRunScript");
if (scripter==NULL) {
RS_DEBUG->print(RS_Debug::D_WARNING,
"QC_ApplicationWindow::slotRunScript: "
"scripter not initialized");
return;
}
statusBar()->showMessage(tr("Running script '%1'").arg(name), 2000);
QStringList scriptList = RS_SYSTEM->getScriptList();
scriptList.append(RS_SYSTEM->getHomeDir() + "/." XSTR(QC_APPKEY) "/" + name);
for (QStringList::Iterator it = scriptList.begin(); it!=scriptList.end(); ++it) {
RS_DEBUG->print("QC_ApplicationWindow::slotRunScript: "
"checking script '%s'", (*it).latin1());
QFileInfo fi(*it);
if (fi.exists() && fi.fileName()==name) {
RS_DEBUG->print("QC_ApplicationWindow::slotRunScript: running '%s'",
(*it).latin1());
scripter->runScript(*it, "main");
}
}
#endif
}
/**
* Called from toolbar buttons that were added by scripts to
* insert blocks.
*/
void QC_ApplicationWindow::slotInsertBlock() {
const QObject* s = sender();
if (s!=NULL) {
QString block = ((QAction*)s)->text();
RS_DEBUG->print("QC_ApplicationWindow::slotInsertBlock: %s",
block.toLatin1().data());
slotInsertBlock(block);
}
}
/**
* Called to insert blocks.
*/
void QC_ApplicationWindow::slotInsertBlock(const QString& name) {
RS_DEBUG->print("QC_ApplicationWindow::slotInsertBlock: '%s'", name.toLatin1().data());
statusBar()->showMessage(tr("Inserting block '%1'").arg(name), 2000);
RS_GraphicView* graphicView = getGraphicView();
RS_Document* document = getDocument();
if (graphicView!=NULL && document!=NULL) {
RS_ActionLibraryInsert* action =
new RS_ActionLibraryInsert(*document, *graphicView);
action->setFile(name);
graphicView->setCurrentAction(action);
}
}
/**
* Shows the main application window and a splash screen.
*/
void QC_ApplicationWindow::show() {
#ifdef QSPLASHSCREEN_H
if (splash) {
splash->raise();
}
#endif
QMainWindow::show();
#ifdef QSPLASHSCREEN_H
if (splash) {
splash->raise();
qApp->processEvents();
splash->clearMessage();
# ifdef QC_DELAYED_SPLASH_SCREEN
QTimer::singleShot(1000*2, this, SLOT(finishSplashScreen()));
# else
finishSplashScreen();
# endif
}
#endif
}
/**
* Called when the splash screen has to terminate.
*/
void QC_ApplicationWindow::finishSplashScreen() {
#ifdef QSPLASHSCREEN_H
if (splash) {
splash->finish(this);
delete splash;
splash = 0;
}
#endif
}
/**
* Close Event. Called when the user tries to close the app.
*/
void QC_ApplicationWindow::closeEvent(QCloseEvent* ce) {
RS_DEBUG->print("QC_ApplicationWindow::closeEvent()");
if (!queryExit(false)) {
ce->ignore();
}
else
{
if(mdiAreaCAD==NULL){
ce->accept();
return;
}
mdiAreaCAD->closeAllSubWindows();
if (mdiAreaCAD->currentSubWindow()) {
ce->ignore();
} else {
ce->accept();
}
}
//we shouldn't need this; saving should be done within ~QG_SnapToolBar()
//snapToolBar->saveSnapMode();
RS_DEBUG->print("QC_ApplicationWindow::closeEvent(): OK");
}
/**
* Handles right-clicks for moving back to the last cad tool bar.
*/
void QC_ApplicationWindow::mouseReleaseEvent(QMouseEvent* e) {
if (e->button()==Qt::RightButton && cadToolBar!=NULL) {
cadToolBar->showToolBarMain();
}
e->accept();
}
/**
* Initializes the MDI mdiAreaCAD.
*/
void QC_ApplicationWindow::initMDI() {
RS_DEBUG->print("QC_ApplicationWindow::initMDI() begin");
QFrame *vb = new QFrame(this);
vb->setSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum);
QVBoxLayout *layout = new QVBoxLayout;
vb->setFrameStyle(QFrame::StyledPanel | QFrame::Sunken);
layout->setContentsMargins ( 0, 0, 0, 0 );
mdiAreaCAD = new QMdiArea(this);
activedMdiSubWindow=NULL;
mdiAreaTab = false;
layout->addWidget(mdiAreaCAD);
// mdiAreaCAD->setScrollBarsEnabled(false);
mdiAreaCAD->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
mdiAreaCAD->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
mdiAreaCAD->setFocusPolicy(Qt::ClickFocus);
mdiAreaCAD->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
#if QT_VERSION >= 0x040800
mdiAreaCAD->setTabsClosable(true);
#endif
vb->setLayout(layout);
setCentralWidget(vb);
connect(mdiAreaCAD, SIGNAL(subWindowActivated(QMdiSubWindow*)),
this, SLOT(slotWindowActivated(QMdiSubWindow*)));
//send key events for mdiAreaCAD to command widget by default
mdiAreaCAD->installEventFilter(commandWidget);
RS_DEBUG->print("QC_ApplicationWindow::initMDI() end");
}
/**
* @return Pointer to the currently active MDI Window or NULL if no
* MDI Window is active.
*/
QC_MDIWindow* QC_ApplicationWindow::getMDIWindow() {
if (mdiAreaCAD!=NULL) {
QMdiSubWindow* w=mdiAreaCAD->currentSubWindow();
if(w!=NULL) {
return qobject_cast<QC_MDIWindow*>(w->widget());
}
}
return NULL;
}
/* *
* Description: Initializes all QActions of the application.
* Author(s): ..., Claude Sylvain
* Created:
* Last modified: 16 July 2011
* Parameters: void
* Returns: void
* */
void QC_ApplicationWindow::initActions(void)
{
RS_DEBUG->print("QC_ApplicationWindow::initActions()");
QG_ActionFactory actionFactory(actionHandler, this);
QAction* action;
QMenu* menu;
QMenu* subMenu;
// File actions:
//
menu = menuBar()->addMenu(tr("&File"));
menu->setObjectName("File");
fileToolBar->setWindowTitle(tr("File"));
actionFactory.addGUI(menu, fileToolBar, this, {RS2::ActionFileNew
,RS2::ActionFileNewTemplate
,RS2::ActionFileOpen
,RS2::ActionFileSave
,RS2::ActionFileSaveAs
,RS2::ActionFileExport});
subMenu = menu->addMenu(tr("Import"));
subMenu->setObjectName("Import");
//insert images
// Image:
actionFactory.addGUI(subMenu, actionHandler, RS2::ActionDrawImage);
// Import Block:
actionFactory.addGUI(subMenu, this, RS2::ActionBlocksImport);
menu->addSeparator();
actionFactory.addGUI(menu, this, {RS2::ActionFileClose
,RS2::ActionFilePrint
,RS2::ActionFilePrintPDF});
action= actionFactory.addGUI(menu, this, RS2::ActionFilePrintPreview);
connect(this, SIGNAL(printPreviewChanged(bool)), action, SLOT(setChecked(bool)));
menu->addSeparator();
actionFactory.addGUI(menu, this, RS2::ActionFileQuit);
menu->addSeparator();
addToolBar(Qt::TopToolBarArea, fileToolBar); //tr("File");
fileMenu = menu;
// Editing actions:
//
menu = menuBar()->addMenu(tr("&Edit"));
menu->setObjectName("Edit");
editToolBar->setWindowTitle(tr("Edit"));
actionFactory.addGUI(menu, editToolBar, actionHandler, RS2::ActionEditKillAllActions);
editToolBar->addSeparator();
menu->addSeparator();
undoButton = actionFactory.addGUI(menu, editToolBar, actionHandler, RS2::ActionEditUndo);
redoButton = actionFactory.addGUI(menu, editToolBar, actionHandler, RS2::ActionEditRedo);
editToolBar->addSeparator();
menu->addSeparator();
actionFactory.addGUI(menu, editToolBar, actionHandler, {RS2::ActionEditCut
,RS2::ActionEditCopy
,RS2::ActionEditPaste});
menu->addSeparator();
// Draw order:
subMenu= menu->addMenu(tr("Draw &Order"));
subMenu->setObjectName("Order");
actionFactory.addGUI(subMenu, actionHandler, {RS2::ActionOrderBottom
,RS2::ActionOrderLower
,RS2::ActionOrderRaise
,RS2::ActionOrderTop});
actionFactory.addGUI(menu, this, RS2::ActionOptionsGeneral);
actionFactory.addGUI(menu, actionHandler, RS2::ActionOptionsDrawing);
//addToolBar(tb, tr("Edit"));
addToolBar(Qt::TopToolBarArea, editToolBar); //tr("Edit");
// Options menu:
//
//menu = new QPopupMenu(this);
//menuBar()->insertItem(tr("&Options"), menu);
// Viewing / Zooming actions:
//
menu = menuBar()->addMenu(tr("&View"));
menu->setObjectName("View");
zoomToolBar->setWindowTitle(tr("View"));
action=actionFactory.addGUI(menu, zoomToolBar, this, RS2::ActionViewGrid);
action->setChecked(true);
connect(this, SIGNAL(gridChanged(bool)), action, SLOT(setChecked(bool)));
RS_SETTINGS->beginGroup("/Appearance");
bool draftMode = (bool)RS_SETTINGS->readNumEntry("/DraftMode", 0);
RS_SETTINGS->endGroup();
action=actionFactory.addGUI(menu, zoomToolBar, this, RS2::ActionViewDraft);
action->setChecked(draftMode);
connect(this, SIGNAL(draftChanged(bool)), action, SLOT(setChecked(bool)));
/*
action = new QAction(tr("Back"),
tr("&Back"), Key_Escape, this);
connect(action, SIGNAL(activated()),
this, SLOT(slotBack()));
action->addTo(menu);
*/
menu->addSeparator();
zoomToolBar->addSeparator();
actionFactory.addGUI(menu, zoomToolBar, actionHandler, {RS2::ActionZoomRedraw
,RS2::ActionZoomIn
,RS2::ActionZoomOut
,RS2::ActionZoomAuto});
previousZoom =actionFactory.addGUI(menu, zoomToolBar, actionHandler, RS2::ActionZoomPrevious);
previousZoom->setEnabled(false);
actionFactory.addGUI(menu, zoomToolBar, actionHandler, {RS2::ActionZoomWindow
, RS2::ActionZoomPan});
menu->addSeparator();
actionFactory.addGUI(menu, this, RS2::ActionViewStatusBar);
subMenu= menu->addMenu(tr("&Toolbars"));
subMenu->setObjectName("Toolbars");
actionFactory.addGUI(subMenu, this, layerWidget->parentWidget(), RS2::ActionViewLayerList);
actionFactory.addGUI(subMenu, this, blockWidget->parentWidget(), RS2::ActionViewBlockList);
actionFactory.addGUI(subMenu, this, libraryWidget->parentWidget(), RS2::ActionViewLibrary);
actionFactory.addGUI(subMenu, this, commandWidget->parentWidget(), RS2::ActionViewCommandLine);
subMenu->addSeparator();
actionFactory.addGUI(subMenu, this, penToolBar, RS2::ActionViewPenToolbar);
actionFactory.addGUI(subMenu, this, optionWidget, RS2::ActionViewOptionToolbar);
actionFactory.addGUI(subMenu, this, fileToolBar, RS2::ActionViewFileToolbar);
actionFactory.addGUI(subMenu, this, editToolBar, RS2::ActionViewEditToolbar);
actionFactory.addGUI(subMenu, this, snapToolBar, RS2::ActionViewSnapToolbar);
// RVT_PORT menu->insertItem(tr("Vie&ws"), createDockWindowMenu(NoToolBars));
// RVT_PORT menu->insertItem(tr("Tool&bars"), createDockWindowMenu(OnlyToolBars));
// tr("Focus on Command Line")
action = new QAction(tr("Focus on &Command Line"), this);
action->setIcon(QIcon(":/main/editclear.png"));
{//added commandline shortcuts, feature request# 3437106
QList<QKeySequence> commandLineShortcuts;
commandLineShortcuts<<QKeySequence(Qt::CTRL + Qt::Key_M)<<QKeySequence( Qt::Key_Colon)<<QKeySequence(Qt::Key_Space);
action->setShortcuts(commandLineShortcuts);
}
//action->zetStatusTip(tr("Focus on Command Line"));
connect(action, SIGNAL(triggered()),
this, SLOT(slotFocusCommandLine()));
menu->addAction(action);
//addToolBar(tb, tr("View"));
addToolBar(Qt::TopToolBarArea, zoomToolBar); //tr("View");
// Selecting actions:
//
menu = menuBar()->addMenu(tr("&Select"));
menu->setObjectName("Select");
actionFactory.addGUI(menu, actionHandler, {RS2::ActionDeselectAll
,RS2::ActionSelectAll
,RS2::ActionSelectSingle
,RS2::ActionSelectContour
,RS2::ActionSelectWindow
,RS2::ActionDeselectWindow
,RS2::ActionSelectIntersected
,RS2::ActionDeselectIntersected
,RS2::ActionSelectLayer
,RS2::ActionSelectInvert
});
// Drawing actions:
//
menu = menuBar()->addMenu(tr("&Draw"));
menu->setObjectName("Draw");
// Points:
// subMenu= menu->addMenu(tr("&Point"));
// subMenu->setObjectName("Point");
actionFactory.addGUI(menu, actionHandler, RS2::ActionDrawPoint);
// Lines:
subMenu= menu->addMenu(tr("&Line"));
subMenu->setObjectName("Line");
actionFactory.addGUI(subMenu, actionHandler, {RS2::ActionDrawLine
,RS2::ActionDrawLineAngle
,RS2::ActionDrawLineHorizontal
,RS2::ActionDrawLineVertical
,RS2::ActionDrawLineRectangle
,RS2::ActionDrawLineParallel
,RS2::ActionDrawLineParallelThrough
,RS2::ActionDrawLineBisector
,RS2::ActionDrawLineTangent1
,RS2::ActionDrawLineTangent2
,RS2::ActionDrawLineOrthTan
,RS2::ActionDrawLineOrthogonal
,RS2::ActionDrawLineRelAngle
,RS2::ActionDrawLinePolygonCenCor
,RS2::ActionDrawLinePolygonCorCor
,RS2::ActionDrawLineFree
,RS2::ActionDrawPolyline});
// Arcs:
subMenu= menu->addMenu(tr("&Arc"));
subMenu->setObjectName("Arc");
actionFactory.addGUI(subMenu, actionHandler, {RS2::ActionDrawArc
,RS2::ActionDrawArc3P
,RS2::ActionDrawArcParallel
,RS2::ActionDrawArcTangential});
// Circles:
subMenu= menu->addMenu(tr("&Circle"));
subMenu->setObjectName("Circle");
actionFactory.addGUI(subMenu, actionHandler, {RS2::ActionDrawCircle
,RS2::ActionDrawCircleCR
,RS2::ActionDrawCircle2P
,RS2::ActionDrawCircle2PR
,RS2::ActionDrawCircle3P
,RS2::ActionDrawCircleParallel
,RS2::ActionDrawCircleInscribe
,RS2::ActionDrawCircleTan1_2P
,RS2::ActionDrawCircleTan2
,RS2::ActionDrawCircleTan2_1P
,RS2::ActionDrawCircleTan3});
// Ellipses:
subMenu= menu->addMenu(tr("&Ellipse"));
subMenu->setObjectName("Ellipse");
actionFactory.addGUI(subMenu, actionHandler, {RS2::ActionDrawEllipseAxis
,RS2::ActionDrawEllipseArcAxis
,RS2::ActionDrawEllipseFociPoint
,RS2::ActionDrawEllipse4Points
,RS2::ActionDrawEllipseCenter3Points
,RS2::ActionDrawEllipseInscribe});
// Splines:
subMenu= menu->addMenu(tr("&Spline"));
subMenu->setObjectName("Spline");
actionFactory.addGUI(subMenu, actionHandler, {RS2::ActionDrawSpline
, RS2::ActionDrawSplinePoints});
// Polylines:
subMenu= menu->addMenu(tr("&Polyline"));
subMenu->setObjectName("Polyline");
actionFactory.addGUI(subMenu, actionHandler, {RS2::ActionDrawPolyline
,RS2::ActionPolylineAdd
,RS2::ActionPolylineAppend
,RS2::ActionPolylineDel
,RS2::ActionPolylineDelBetween
,RS2::ActionPolylineTrim
,RS2::ActionPolylineEquidistant
,RS2::ActionPolylineSegment});
// Text:
subMenu= menu->addMenu(tr("&Text"));
subMenu->setObjectName("Text");
actionFactory.addGUI(subMenu, actionHandler, {RS2::ActionDrawMText
, RS2::ActionDrawText});
// Hatch:
actionFactory.addGUI(menu, actionHandler, {RS2::ActionDrawHatch
// Image:
, RS2::ActionDrawImage});
// Dimensioning actions:
//
#ifdef __APPLE1__
QMenu* m = menu;
menu= m->addMenu(tr("&Dimension"));
#else
menu = menuBar()->addMenu(tr("&Dimension"));
#endif
menu->setObjectName("Dimension");
actionFactory.addGUI(menu, actionHandler, {RS2::ActionDimAligned
,RS2::ActionDimLinear
,RS2::ActionDimLinearHor
,RS2::ActionDimLinearVer
,RS2::ActionDimRadial
,RS2::ActionDimDiametric
,RS2::ActionDimAngular
,RS2::ActionDimLeader});
// Modifying actions:
//
menu = menuBar()->addMenu(tr("&Modify"));
menu->setObjectName("Modify");
actionFactory.addGUI(menu, actionHandler, {RS2::ActionModifyMove
,RS2::ActionModifyRotate
,RS2::ActionModifyScale
,RS2::ActionModifyMirror
,RS2::ActionModifyMoveRotate
,RS2::ActionModifyRotate2
,RS2::ActionModifyRevertDirection
,RS2::ActionModifyTrim
,RS2::ActionModifyTrim2
,RS2::ActionModifyTrimAmount
,RS2::ActionModifyOffset
,RS2::ActionModifyBevel
,RS2::ActionModifyRound
,RS2::ActionModifyCut
,RS2::ActionModifyStretch
,RS2::ActionModifyEntity
,RS2::ActionModifyAttributes
,RS2::ActionModifyDelete
,RS2::ActionModifyDeleteQuick
,RS2::ActionModifyExplodeText
,RS2::ActionBlocksExplode});
// Snapping actions:
//
menu = menuBar()->addMenu(tr("&Snap"));
menu->setObjectName("Snap");
if(snapToolBar!=NULL) {
auto&& actions = snapToolBar->getActions();
foreach(QAction* a, actions){
menu->addAction(a);
// connect(this, SIGNAL(windowsChanged(bool)), a, SLOT(setEnabled(bool)));
}
}
// Info actions:
//
menu = menuBar()->addMenu(tr("&Info"));
menu->setObjectName("Info");
actionFactory.addGUI(menu, actionHandler, {RS2::ActionInfoDist
,RS2::ActionInfoDist2
,RS2::ActionInfoAngle
,RS2::ActionInfoTotalLength
,RS2::ActionInfoArea});
//action = actionFactory.createAction(RS2::ActionInfoInside,
// actionHandler);
//action->addTo(menu);
// Layer actions:
//
menu = menuBar()->addMenu(tr("&Layer"));
menu->setObjectName("Layer");
actionFactory.addGUI(menu, actionHandler, {RS2::ActionLayersDefreezeAll
,RS2::ActionLayersFreezeAll
,RS2::ActionLayersAdd
,RS2::ActionLayersRemove
,RS2::ActionLayersEdit
,RS2::ActionLayersToggleLock
,RS2::ActionLayersToggleView});
// Block actions:
//
menu = menuBar()->addMenu(tr("&Block"));
menu->setObjectName("Block");
actionFactory.addGUI(menu, actionHandler, {RS2::ActionBlocksDefreezeAll
,RS2::ActionBlocksFreezeAll
,RS2::ActionBlocksToggleView
,RS2::ActionBlocksAdd
,RS2::ActionBlocksRemove
,RS2::ActionBlocksAttributes
,RS2::ActionBlocksInsert
,RS2::ActionBlocksEdit
,RS2::ActionBlocksSave
,RS2::ActionBlocksCreate
,RS2::ActionBlocksExplode});
QMainWindow::addToolBarBreak(Qt::TopToolBarArea);
addToolBar(Qt::TopToolBarArea, penToolBar);
addToolBar(Qt::TopToolBarArea, optionWidget);
#ifdef RS_SCRIPTING
// Scripts menu:
//
scriptMenu = new QMenu(tr("&Scripts"));
scriptMenu->setObjectName("Scripts");
scriptOpenIDE = actionFactory.createAction(RS2::ActionScriptOpenIDE, this);
scriptOpenIDE->addTo(scriptMenu);