-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMainWindow.cpp
2075 lines (1697 loc) · 78.8 KB
/
MainWindow.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
////////////////////////////////////////////////////////////////////////
// Copyright 2009-2018 NTESS. Under the terms
// of Contract DE-NA0003525 with NTESS, the U.S.
// Government retains certain rights in this software.
//
// Copyright (c) 2009-2018, NTESS
// All rights reserved.
//
// Portions are copyright of other developers:
// See the file CONTRIBUTORS.TXT in the top level directory
// the distribution for more information.
//
// This file is part of the SST software package. For license
// information, see the LICENSE file in the top level directory of the
// distribution.
////////////////////////////////////////////////////////////////////////
#include "MainWindow.h"
#include <QtPrintSupport>
////////////////////////////////////////////////////////////
MainWindow::MainWindow(QWidget* parent /*=0*/)
: QMainWindow(parent)
{
// Create the Undo Stack
m_UndoStack = new QUndoStack(this);
// Create the User Actions
CreateActions();
// Create the Menus and Toolbars that use the User Actions
CreateMenus();
CreateToolbars();
CreateStatusbar();
// Create the Undo Window (Useful for debugging the Undo Stack
// m_UndoViewWindow = new QUndoView(m_UndoStack);
// m_UndoViewWindow->setWindowTitle(tr("Command List"));
// m_UndoViewWindow->show();
// m_UndoViewWindow->setAttribute(Qt::WA_QuitOnClose, false);
// Set the Applications default font that Text uses in the scene
m_DefaultFont = QGuiApplication::font();
SetFontControls(m_DefaultFont);
// Build the Wiring Scene and set its initial size (of the scene window, not the viewport)
m_WiringScene = new WiringScene(m_GenericItemMenu, m_UndoStack, this);
m_WiringScene->setSceneRect(QRectF(0, 0, 5000, 5000));
// Build the view object for the wiring scene
m_WiringView = new QGraphicsView(m_WiringScene);
// Create the Tabbed Widget Window that will house multiple QGraphics View windows
m_TabWiringWindow = new QTabWidget(this);
m_TabWiringWindow->addTab(m_WiringView, "RENAME_ME");
SetMainTabTitle(UNTITLED);
// Connect Scene Event Signals to Main Window Handlers
connect(m_WiringScene, SIGNAL(SceneEventComponentAdded(GraphicItemComponent*)), this, SLOT(HandleSceneEventComponentAdded(GraphicItemComponent*)));
connect(m_WiringScene, SIGNAL(SceneEventTextAdded(GraphicItemText*)), this, SLOT(HandleSceneEventTextAdded(GraphicItemText*)));
connect(m_WiringScene, SIGNAL(SceneEventWireAddedInitialPlacement(GraphicItemWire*)), this, SLOT(HandleSceneEventWireAddedInitialPlacement(GraphicItemWire*)));
connect(m_WiringScene, SIGNAL(SceneEventWireAddedFinalPlacement(GraphicItemWire*)), this, SLOT(HandleSceneEventWireAddedFinalPlacement(GraphicItemWire*)));
connect(m_WiringScene, SIGNAL(selectionChanged()), this, SLOT(HandleSceneEventSelectionChanged()));
connect(m_WiringScene, SIGNAL(SceneEventGraphicItemSelected(QGraphicsItem*)), this, SLOT(HandleSceneEventGraphicItemSelected(QGraphicsItem*)));
connect(m_WiringScene, SIGNAL(SceneEventGraphicItemSelectedProperties(ItemProperties*)), this, SLOT(HandleSceneEventGraphicItemSelectedProperties(ItemProperties*)));
connect(m_WiringScene, SIGNAL(SceneEventSetProjectDirty()), this, SLOT(HandleSceneEventSetProjectDirty()));
connect(m_WiringScene, SIGNAL(SceneEventRefreshPropertiesWindowProperty(QString, QString)), this, SLOT(HandleSceneEventRefreshPropertiesWindowProperty(QString, QString)));
connect(m_WiringScene, SIGNAL(SceneEventRefreshPropertiesWindow(ItemProperties*)), this, SLOT(HandleSceneEventRefreshPropertiesWindow(ItemProperties*)));
connect(m_WiringScene, SIGNAL(SceneEventDragAndDropFinished()), this, SLOT(HandleSceneEventDragAndDropFinished()));
connect(m_UndoStack, SIGNAL(cleanChanged(bool)), this, SLOT(HandleUndoStackCleanChanged(bool)));
// Create the Components Right Side Window
m_CompToolBox = new WindowComponentToolBox(this);
// Create the Properties Left Side Window
m_PropWin = new WindowItemProperties(this);
// Layout the 3 Main Windows (Components, Scene, Properties) from left to right
m_MainSplitterWidget = new QSplitter;
m_MainSplitterWidget->addWidget(m_CompToolBox);
m_MainSplitterWidget->addWidget(m_TabWiringWindow);
m_MainSplitterWidget->addWidget(m_PropWin);
// Set the Main widget as the Main window.
setCentralWidget(m_MainSplitterWidget);
// Set the window title
setWindowTitle(tr("SST Workbench"));
// Initialize Application Persistant Data
m_PersistentSettings = new QSettings(QDir::homePath() + PERSISTFILENAME, QSettings::IniFormat);
RestorePersistentStorage();
// Init variables
m_LoadedProjectDataFilePathName = "";
m_ProjectIsDirty = false;
m_SelectedComponent = NULL;
m_ComponentMovingPorts = NULL;
m_SelectedText = NULL;
m_PasteOffset = DEFAULT_PASTE_OFFSET;
// Start the Focus on the main Wiring Window
m_WiringView->setFocus();
UserActionHandlerNewProject();
}
MainWindow::~MainWindow()
{
if (m_PersistentSettings != NULL) {
delete m_PersistentSettings;
}
}
void MainWindow::SetMainTabTitle(QString Title)
{
// Set the Tab of thw Wiring Window
QString NewTitle = QString(MAINSCREENTITLE) + Title;
m_TabWiringWindow->setTabText(0, NewTitle);
}
void MainWindow::SetMainTabTitle(QFileInfo FileInfo)
{
SetMainTabTitle(FileInfo.baseName());
}
bool MainWindow::IsSceneEmpty()
{
return m_WiringScene->items().isEmpty();
}
bool MainWindow::AreSceneComponentsSelected()
{
// Check to see if the scene is empty
if (IsSceneEmpty() == true) {
return false;
}
// The scene is not empty, so see if there are any selected items
QGraphicsItem* selectedItem = m_WiringScene->selectedItems().first();
return (selectedItem != NULL);
}
void MainWindow::SetFontControls(const QFont& font)
{
m_FontSelectCombo->setCurrentFont(font);
m_FontSizeCombo->setEditText(QString().setNum(font.pointSize()));
m_BoldAction->setChecked(font.weight() == QFont::Bold);
m_ItalicAction->setChecked(font.italic());
m_UnderlineAction->setChecked(font.underline());
}
void MainWindow::SetSceneScaleByPercent(double ScalePercent)
{
double NewScale;
double NewScalePercent = ScalePercent;
// Limit how much we can zoom in
if (NewScalePercent > ZOOM_IN_LIMIT) {
NewScalePercent = ZOOM_IN_LIMIT;
}
// Limit how much we can zoom out
if (NewScalePercent < ZOOM_OUT_LIMIT) {
NewScalePercent = ZOOM_OUT_LIMIT;
}
// Round it to the closest step
NewScalePercent = RoundTo(NewScalePercent, (double) ZOOM_STEP_SIZE);
// Change the Percent into a double
NewScale = NewScalePercent / 100;
// Get the old matrix and then scale it to the new size
QMatrix oldMatrix = m_WiringView->matrix();
m_WiringView->resetMatrix();
m_WiringView->translate(oldMatrix.dx(), oldMatrix.dy());
m_WiringView->scale(NewScale, NewScale);
// Update the Display
UpdateSceneScaleDisplay();
}
void MainWindow::UpdateSceneScaleDisplay()
{
qreal NewScaleValueF;
int NewScaleValue;
QString NewScaleText;
QString CurrentText;
int MatchIndex;
int SizeCount;
// Figure out the current scaling and make it a percentage
NewScaleValueF = m_WiringView->transform().m11() * 100;
// Round the number to an integer
NewScaleValue = round(NewScaleValueF);
// Convert it to a percent string
NewScaleText = QString("%1%").arg(NewScaleValue);
// Set the control
m_SceneScaleCombo->setCurrentText(NewScaleText);
// This is to get around an QT Issue, when the user enters text into the
// Combobox, it is added to the list of options, We want to keep our
// List of options fixed (not increasing), but sill allow the user to enter their own data
// Therefore we remove the entry from the list (it is always added at the end by default).
CurrentText = QString("%1").arg(NewScaleValue); // FIRST TIME WITHOUT A %
MatchIndex = m_SceneScaleCombo->findText(CurrentText);
SizeCount = m_SceneScaleCombo->count();
if (MatchIndex == SizeCount - 1) {
if (CurrentText != m_LastScaleString) {
m_SceneScaleCombo->removeItem(MatchIndex);
m_SceneScaleCombo->setCurrentIndex(-1);
m_SceneScaleCombo->setEditText(CurrentText);
}
}
CurrentText = QString("%1%").arg(NewScaleValue); // SECOND TIME WITH A %
MatchIndex = m_SceneScaleCombo->findText(CurrentText);
SizeCount = m_SceneScaleCombo->count();
if (MatchIndex == SizeCount - 1) {
if (CurrentText != m_LastScaleString) {
m_SceneScaleCombo->removeItem(MatchIndex);
m_SceneScaleCombo->setCurrentIndex(-1);
m_SceneScaleCombo->setEditText(CurrentText);
}
}
}
void MainWindow::SavePersistentStorage()
{
// Save the Persistent Data (Between runs of this app)
QSettings* settings = MainWindow::GetPersistentSettings();
// Main Window Settings
settings->beginGroup(PERSISTGROUP_MAINWINDOW);
settings->setValue(PERSISTVALUE_SIZE, size());
settings->setValue(PERSISTVALUE_POSIITON, pos());
settings->setValue(PERSISTVALUE_MAINWINSTATE, saveState());
settings->setValue(PERSISTVALUE_SPLITTERSTATE, m_MainSplitterWidget->saveState());
settings->endGroup();
// General Settings
settings->beginGroup(PERSISTGROUP_GENERAL);
settings->setValue(PERSISTVALUE_SSTINFOXMLFILEPATHNAME, m_SSTInfoXMLDataFilePathName);
settings->setValue(PERSISTVALUE_PROJECTFILEPATHNAME, m_LastSavedProjectDataFilePathName);
settings->setValue(PERSISTVALUE_PYTHONEXPORTFILEPATHNAME, m_LastExportedPythonFilePathName);
settings->endGroup();
settings->beginGroup(PERSISTGROUP_PREFERENCES);
settings->setValue(PERSISTVALUE_PREF_RETURNTOSELAFTERWIRE, m_ReturnToSelectToolAfterPlacingWire);
settings->setValue(PERSISTVALUE_PREF_RETURNTOSELAFTERTEXT, m_ReturnToSelectToolAfterPlacingText);
settings->endGroup();
}
void MainWindow::RestorePersistentStorage()
{
// Restore the Persistent Data (Between runs of this app)
QSettings* settings = MainWindow::GetPersistentSettings();
// Main Window Settings
settings->beginGroup(PERSISTGROUP_MAINWINDOW);
resize(settings->value(PERSISTVALUE_SIZE, QSize(1200, 800)).toSize());
move(settings->value(PERSISTVALUE_POSIITON, QPoint(200, 200)).toPoint());
restoreState(settings->value(PERSISTVALUE_MAINWINSTATE).toByteArray());
m_MainSplitterWidget->restoreState(settings->value(PERSISTVALUE_SPLITTERSTATE).toByteArray());
settings->endGroup();
// General Settings
settings->beginGroup(PERSISTGROUP_GENERAL);
m_SSTInfoXMLDataFilePathName = settings->value(PERSISTVALUE_SSTINFOXMLFILEPATHNAME, QDir::homePath()).toString();
m_LastSavedProjectDataFilePathName = settings->value(PERSISTVALUE_PROJECTFILEPATHNAME, QDir::homePath()).toString();
m_LastExportedPythonFilePathName = settings->value(PERSISTVALUE_PYTHONEXPORTFILEPATHNAME, QDir::homePath()).toString();
settings->endGroup();
settings->beginGroup(PERSISTGROUP_PREFERENCES);
m_ReturnToSelectToolAfterPlacingWire = settings->value(PERSISTVALUE_PREF_RETURNTOSELAFTERWIRE, true).toBool();
m_ReturnToSelectToolAfterPlacingText = settings->value(PERSISTVALUE_PREF_RETURNTOSELAFTERTEXT, true).toBool();
settings->endGroup();
}
bool MainWindow::SaveProjectData(QString ProjectFilePathName)
{
QByteArray SaveBuffer;
QByteArray ComputedHash;
// Create a Data Stream and Connect it to the Buffer
QDataStream DataStreamOut(&SaveBuffer, QIODevice::WriteOnly);
// Save Version Informatgion
DataStreamOut << (quint32)SSTWORKBENCHPROJECTFILEMAGICNUMBER; // SSTWorkbench Magic Number
DataStreamOut << (qint32)SSTWORKBENCHPROJECTFILEFORMATVERSION; // SSTWorkbench File Format Version
DataStreamOut.setVersion(QDataStream::Qt_5_2); // QT's Serialization Version (for complex Types)
// Start Streaming the data structures to the file
if (m_CompToolBox->GetSSTInfoData() != NULL) {
m_CompToolBox->GetSSTInfoData()->SaveData(DataStreamOut);
m_WiringScene->SaveData(DataStreamOut);
}
// Compute the Checksum of the Save Buffer
QCryptographicHash Checksum(QCryptographicHash::Md5);
Checksum.addData(SaveBuffer);
ComputedHash = Checksum.result();
// Add the Checksum Computed Hash to the front of the buffer
SaveBuffer.prepend(ComputedHash);
// Open the file and save the buffer
QFile SaveFile(ProjectFilePathName);
SaveFile.open(QIODevice::WriteOnly);
SaveFile.write(SaveBuffer);
SaveFile.close();
// Set the Main Screen Tab Title
SetMainTabTitle(QFileInfo(ProjectFilePathName));
SetProjectDirty(false);
return true;
}
bool MainWindow::LoadProjectData(QString ProjectFilePathName)
{
QByteArray LoadBuffer;
QByteArray LoadHash;
QByteArray ComputeHash;
// Open the file & Read its contents
QFile LoadFile(ProjectFilePathName);
LoadFile.open(QIODevice::ReadOnly);
LoadBuffer = LoadFile.readAll();
LoadFile.close();
// Get and then remove the 16 bytes from the front of the file.
// This should be the MD5 Hash
LoadHash = LoadBuffer.left(16);
LoadBuffer.remove(0, 16);
// Compute the Checksum of the Remaining Load Buffer
QCryptographicHash Checksum(QCryptographicHash::Md5);
Checksum.addData(LoadBuffer);
ComputeHash = Checksum.result();
// Check to see that the Loaded Hash and the Computed Hash match
if (ComputeHash != LoadHash) {
QMessageBox::critical(NULL, "Failed to Load Project File", QString("ERROR: Cannot Load Project File = %1; File Corrupted; Checksum is incorrect.").arg(ProjectFilePathName));
return false;
}
// Create a Data Stream and Connect it to the Buffer
QDataStream DataStreamIn(&LoadBuffer, QIODevice::ReadOnly);
// Read the Magic Number and Validate it to ensure that this is an SSTWorkbench file
quint32 MagicNumber;
DataStreamIn >> MagicNumber;
if (MagicNumber != SSTWORKBENCHPROJECTFILEMAGICNUMBER) {
QMessageBox::critical(NULL, "Failed to Load Project File", QString("ERROR: Cannot Load Project File = %1; File is not a SSTWorkbench file").arg(ProjectFilePathName));
return false;
}
// Read The Version to ensure that we are correct
qint32 FileVersion;
DataStreamIn >> FileVersion;
if (FileVersion < SSTWORKBENCHPROJECTFILEFORMATVERSION) {
QMessageBox::critical(NULL, "Failed to Load Project File", QString("ERROR: Cannot Load Project File = %1; File is too OLD; Version is %2 and Expected Version is %3").arg(ProjectFilePathName).arg(FileVersion).arg(SSTWORKBENCHPROJECTFILEFORMATVERSION));
return false;
}
if (FileVersion > SSTWORKBENCHPROJECTFILEFORMATVERSION) {
QMessageBox::critical(NULL, "Failed to Load Project File", QString("ERROR: Cannot Load Project File = %1; File is too NEW; Version is %2 and Expected Version is %3").arg(ProjectFilePathName).arg(FileVersion).arg(SSTWORKBENCHPROJECTFILEFORMATVERSION));
return false;
}
// Set the Streaming Version based upon our SSTWORKBENCHFILEFORMATVERSION
DataStreamIn.setVersion(QDataStream::Qt_5_2);
// Create a new SSTInfoData Structure & Load the data from the file
SSTInfoData* NewSSTInfoData = new SSTInfoData(DataStreamIn);
// Add the new SSTInfoData to the Component Toolbax
m_CompToolBox->LoadSSTInfo(NewSSTInfoData, false);
// Build the Wiring Scene
m_WiringScene->LoadData(DataStreamIn);
// Set nothing selected
m_WiringScene->SetNothingSelected();
// Set the Main Screen Tab Title
SetMainTabTitle(QFileInfo(ProjectFilePathName));
// Display all GraphicItems
UserActionSceneScaleZoomAll();
SetProjectDirty(false);
return true;
}
bool MainWindow::IsSSTInfoDataLoaded()
{
return (m_CompToolBox->GetSSTInfoData() != NULL);
}
void MainWindow::CreateActions()
{
////////////////////////////////////////////////////////
// CREATE THE LIST OF ACTIONS THAT THE USER CAN TAKE
////////////////////////////////////////////////////////
///
m_BringToFrontAction = new QAction(QIcon(":/images/ItemBringToFront.png"), tr("Bring to &Front"), this);
m_BringToFrontAction->setShortcuts(QKeySequence::Forward);
m_BringToFrontAction->setStatusTip(tr("Bring Item To Front"));
connect(m_BringToFrontAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerBringToFront()));
m_SendToBackAction = new QAction(QIcon(":/images/ItemSendToBack.png"), tr("Send to &Back"), this);
m_SendToBackAction->setShortcuts(QKeySequence::Back);
m_SendToBackAction->setStatusTip(tr("Send Item To Back"));
connect(m_SendToBackAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerSendToBack()));
m_DeleteAction = new QAction(QIcon(":/images/ItemDelete.png"), tr("&Delete"), this);
m_DeleteAction->setShortcuts(QKeySequence::Delete);
m_DeleteAction->setStatusTip(tr("Delete Item"));
m_DeleteAction->setEnabled(false);
connect(m_DeleteAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerDeleteItem()));
///
m_UndoAction = m_UndoStack->createUndoAction(this, tr("&Undo"));
m_UndoAction->setIcon(QIcon(":/images/Undo.png"));
m_UndoAction->setShortcuts(QKeySequence::Undo);
m_RedoAction = m_UndoStack->createRedoAction(this, tr("&Redo"));
m_RedoAction->setIcon(QIcon(":/images/Redo.png"));
m_RedoAction->setShortcuts(QKeySequence::Redo);
m_SelectAllAction = new QAction(tr("Select &All"), this);
m_SelectAllAction->setShortcuts(QKeySequence::SelectAll);
m_SelectAllAction->setStatusTip(tr("Select All Items"));
connect(m_SelectAllAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerSelectAll()));
///
m_CutAction = new QAction(tr("Cut"), this);
m_CutAction->setShortcuts(QKeySequence::Cut);
m_CutAction->setStatusTip(tr("Cut All Selected Items"));
connect(m_CutAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerCut()));
m_CopyAction = new QAction(tr("Copy"), this);
m_CopyAction->setShortcuts(QKeySequence::Copy);
m_CopyAction->setStatusTip(tr("Copy All Selected Items"));
connect(m_CopyAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerCopy()));
m_PasteAction = new QAction(tr("Paste"), this);
m_PasteAction->setShortcuts(QKeySequence::Paste);
m_PasteAction->setStatusTip(tr("Paste Items"));
connect(m_PasteAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerPaste()));
///
m_WorkBenchNewProjectAction = new QAction(QIcon(":/images/ProjectNew.png"), tr("&New Project..."), this);
m_WorkBenchNewProjectAction->setShortcuts(QKeySequence::New);
m_WorkBenchNewProjectAction->setStatusTip(tr("New SST Workbench Project"));
connect(m_WorkBenchNewProjectAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerNewProject()));
m_WorkBenchLoadDesignAction = new QAction(QIcon(":/images/ProjectOpen.png"), tr("&Open Project..."), this);
m_WorkBenchLoadDesignAction->setShortcuts(QKeySequence::Open);
m_WorkBenchLoadDesignAction->setStatusTip(tr("Load SST Workbench Project"));
connect(m_WorkBenchLoadDesignAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerLoadDesign()));
m_WorkBenchSaveDesignAction = new QAction(QIcon(":/images/ProjectSave.png"), tr("&Save Project"), this);
m_WorkBenchSaveDesignAction->setShortcuts(QKeySequence::Save);
m_WorkBenchSaveDesignAction->setStatusTip(tr("Save SST Workbench Project"));
m_WorkBenchSaveDesignAction->setEnabled(false);
connect(m_WorkBenchSaveDesignAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerSaveDesign()));
m_WorkBenchSaveAsAction = new QAction(QIcon(":/images/ProjectSave.png"), tr("Save Project As..."), this);
m_WorkBenchSaveAsAction->setShortcuts(QKeySequence::SaveAs);
m_WorkBenchSaveAsAction->setStatusTip(tr("Save SST Workbench Project As"));
m_WorkBenchSaveAsAction->setEnabled(false);
connect(m_WorkBenchSaveAsAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerSaveAs()));
m_ImportSSTInfoAction = new QAction(QIcon(":/images/ImportXML.png"), tr("Im&port SSTInfo Data..."), this);
m_ImportSSTInfoAction->setShortcut(tr("Ctrl+F"));
m_ImportSSTInfoAction->setStatusTip(tr("Import SSTInfo Data File"));
connect(m_ImportSSTInfoAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerImportSSTInfo()));
m_ExportSSTInputDeckAction = new QAction(QIcon(":/images/SST_Single_S_Logo.png"), tr("E&xport SST Input Deck..."), this);
m_ExportSSTInputDeckAction->setShortcut(tr("Ctrl+E"));
m_ExportSSTInputDeckAction->setStatusTip(tr("Export Project To An SST Python Input Deck"));
m_ExportSSTInputDeckAction->setEnabled(false);
connect(m_ExportSSTInputDeckAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerExportSSTInputDeck()));
m_ExitAction = new QAction(tr("E&xit"), this);
m_ExitAction->setShortcuts(QKeySequence::Quit);
m_ExitAction->setStatusTip(tr("Quit SST Workbench"));
connect(m_ExitAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerExit()));
m_PreferencesAction = new QAction(tr("P&references"), this);
m_PreferencesAction->setShortcuts(QKeySequence::Preferences);
m_PreferencesAction->setStatusTip(tr("Preferences"));
connect(m_PreferencesAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerPreferences()));
m_AboutAction = new QAction(tr("A&bout SST Workbench"), this);
m_AboutAction->setStatusTip(tr("About SST Workbench"));
connect(m_AboutAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerAbout()));
m_PrintAction = new QAction(tr("&Print..."), this);
m_PrintAction->setShortcuts(QKeySequence::Print);
m_PrintAction->setStatusTip(tr("Print Current View"));
connect(m_PrintAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerPrint()));
///
m_BoldAction = new QAction(tr("Bold"), this);
m_BoldAction->setCheckable(true);
QPixmap pixmap(":/images/TextBold.png");
m_BoldAction->setIcon(QIcon(pixmap));
m_BoldAction->setShortcuts(QKeySequence::Bold);
m_BoldAction->setStatusTip(tr("Bold"));
connect(m_BoldAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerFontChange()));
m_ItalicAction = new QAction(QIcon(":/images/TextItalic.png"), tr("Italic"), this);
m_ItalicAction->setCheckable(true);
m_ItalicAction->setShortcuts(QKeySequence::Italic);
m_ItalicAction->setStatusTip(tr("Italic"));
connect(m_ItalicAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerFontChange()));
m_UnderlineAction = new QAction(QIcon(":/images/TextUnderline.png"), tr("Underline"), this);
m_UnderlineAction->setCheckable(true);
m_UnderlineAction->setShortcuts(QKeySequence::Underline);
m_UnderlineAction->setStatusTip(tr("Underline"));
connect(m_UnderlineAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerFontChange()));
///
// Build the Component Menu Actions
m_MovePortsAction = new QAction("&Move Port Positions", this);
m_MovePortsAction->setStatusTip(tr("Move Component Ports"));
connect(m_MovePortsAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerMovePorts()));
m_SetDynamicPortsAction = new QAction("Set Dynamic Por&ts...", this);
m_SetDynamicPortsAction->setStatusTip(tr("Set Component Dynamic Ports"));
m_SetDynamicPortsAction->setVisible(false);
connect(m_SetDynamicPortsAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerSetDynamicPorts()));
m_ManageModulesAction = new QAction("Mana&ge Component Modules...", this);
m_ManageModulesAction->setStatusTip(tr("Manage the Components Modules"));
m_ManageModulesAction->setVisible(false);
connect(m_ManageModulesAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerManageModules()));
///
// Actions for displaying the Toolbars
m_ShowToolsToolbarAction = new QAction("Tools", this);
m_ShowToolsToolbarAction->setStatusTip(tr("Enable/Disable Tools Toolbar"));
m_ShowToolsToolbarAction->setCheckable(true);
m_ShowToolsToolbarAction->setChecked(true);
connect(m_ShowToolsToolbarAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerShowToolbars()));
m_ShowItemToolbarAction = new QAction("Item Control", this);
m_ShowItemToolbarAction->setStatusTip(tr("Enable/Disable Item Control Toolbar"));
m_ShowItemToolbarAction->setCheckable(true);
m_ShowItemToolbarAction->setChecked(true);
connect(m_ShowItemToolbarAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerShowToolbars()));
m_ShowFontControlToolbarAction = new QAction("Font Control", this);
m_ShowFontControlToolbarAction->setStatusTip(tr("Enable/Disable Font Control Toolbar"));
m_ShowFontControlToolbarAction->setCheckable(true);
m_ShowFontControlToolbarAction->setChecked(true);
connect(m_ShowFontControlToolbarAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerShowToolbars()));
m_ShowViewControlToolbarAction = new QAction("View Control", this);
m_ShowViewControlToolbarAction->setStatusTip(tr("Enable/Disable View Control Toolbar"));
m_ShowViewControlToolbarAction->setCheckable(true);
m_ShowViewControlToolbarAction->setChecked(true);
connect(m_ShowViewControlToolbarAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerShowToolbars()));
m_ShowFileActionsToolbarAction = new QAction("File Actions", this);
m_ShowFileActionsToolbarAction->setStatusTip(tr("Enable/Disable File Actions Toolbar"));
m_ShowFileActionsToolbarAction->setCheckable(true);
m_ShowFileActionsToolbarAction->setChecked(true);
connect(m_ShowFileActionsToolbarAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerShowToolbars()));
m_ShowEditToolbarAction = new QAction("Edit", this);
m_ShowEditToolbarAction->setStatusTip(tr("Enable/Disable Edit Toolbar"));
m_ShowEditToolbarAction->setCheckable(true);
m_ShowEditToolbarAction->setChecked(true);
connect(m_ShowEditToolbarAction, SIGNAL(triggered()), this, SLOT(UserActionHandlerShowToolbars()));
///
// Zoom In
m_SceneScaleZoomInAction = new QAction(QIcon(":/images/ZoomIn.png"), tr("Zoom In"), this);
m_SceneScaleZoomInAction->setShortcuts(QKeySequence::ZoomIn);
m_SceneScaleZoomInAction->setToolTip(tr("Zoom In"));
m_SceneScaleZoomInAction->setStatusTip(tr("Zoom In"));
connect(m_SceneScaleZoomInAction, SIGNAL(triggered()), this, SLOT(UserActionSceneScaleZoomIn()));
// Zoom Out
m_SceneScaleZoomOutAction = new QAction(QIcon(":/images/ZoomOut.png"), tr("Zoom Out"), this);
m_SceneScaleZoomOutAction->setShortcuts(QKeySequence::ZoomOut);
m_SceneScaleZoomOutAction->setToolTip(tr("Zoom Out"));
m_SceneScaleZoomOutAction->setStatusTip(tr("Zoom Out"));
connect(m_SceneScaleZoomOutAction, SIGNAL(triggered()), this, SLOT(UserActionSceneScaleZoomOut()));
// Zoom All
m_SceneScaleZoomAllAction = new QAction(QIcon(":/images/ZoomAll.png"), tr("Zoom Al&l"), this);
m_SceneScaleZoomAllAction->setShortcut(tr("Ctrl+L"));
m_SceneScaleZoomAllAction->setToolTip(tr("Zoom All"));
m_SceneScaleZoomAllAction->setStatusTip(tr("Zoom All"));
connect(m_SceneScaleZoomAllAction, SIGNAL(triggered()), this, SLOT(UserActionSceneScaleZoomAll()));
}
void MainWindow::CreateMenus()
{
//////////////////////////////////////////
// BUILD THE MENU AND TIE TO THE ACTIONS
//////////////////////////////////////////
// File Menu
m_FileMenu = menuBar()->addMenu(tr("&File"));
m_FileMenu->addAction(m_WorkBenchNewProjectAction);
m_FileMenu->addSeparator();
m_FileMenu->addAction(m_WorkBenchLoadDesignAction);
m_FileMenu->addAction(m_WorkBenchSaveDesignAction);
m_FileMenu->addSeparator();
m_FileMenu->addAction(m_WorkBenchSaveAsAction);
m_FileMenu->addSeparator();
m_FileMenu->addAction(m_ImportSSTInfoAction);
m_FileMenu->addSeparator();
m_FileMenu->addAction(m_ExportSSTInputDeckAction);
m_FileMenu->addSeparator();
m_FileMenu->addAction(m_PrintAction);
m_FileMenu->addSeparator();
m_FileMenu->addAction(m_PreferencesAction);
m_FileMenu->addSeparator();
m_FileMenu->addAction(m_ExitAction);
// Edit Menu
m_EditMenu = menuBar()->addMenu(tr("&Edit"));
m_EditMenu->addAction(m_UndoAction);
m_EditMenu->addAction(m_RedoAction);
m_EditMenu->addSeparator();
m_EditMenu->addAction(m_SelectAllAction);
m_EditMenu->addSeparator();
m_EditMenu->addAction(m_CutAction);
m_EditMenu->addAction(m_CopyAction);
m_EditMenu->addAction(m_PasteAction);
// Item Menu
m_GenericItemMenu = menuBar()->addMenu(tr("&Item"));
m_GenericItemMenu->addAction(m_DeleteAction);
m_GenericItemMenu->addSeparator();
m_GenericItemMenu->addAction(m_BringToFrontAction);
m_GenericItemMenu->addAction(m_SendToBackAction);
m_GenericItemMenu->addSeparator();
m_GenericItemMenu->addAction(m_MovePortsAction);
m_GenericItemMenu->addSeparator();
m_GenericItemMenu->addAction(m_SetDynamicPortsAction);
m_GenericItemMenu->addSeparator();
m_GenericItemMenu->addAction(m_ManageModulesAction);
// View Menu
m_ViewMenu = menuBar()->addMenu(tr("&View"));
m_ViewMenu->addAction(m_SceneScaleZoomAllAction);
m_ViewMenu->addSeparator();
m_ViewMenu->addAction(m_SceneScaleZoomInAction);
m_ViewMenu->addAction(m_SceneScaleZoomOutAction);
// Toolbar Menu
m_ToolbarMenu = menuBar()->addMenu(tr("&Toolbars"));
m_ToolbarMenu->addAction(m_ShowFileActionsToolbarAction);
m_ToolbarMenu->addAction(m_ShowEditToolbarAction);
m_ToolbarMenu->addAction(m_ShowToolsToolbarAction);
m_ToolbarMenu->addAction(m_ShowItemToolbarAction);
m_ToolbarMenu->addAction(m_ShowFontControlToolbarAction);
m_ToolbarMenu->addAction(m_ShowViewControlToolbarAction);
// Help Menu
m_AboutMenu = menuBar()->addMenu(tr("&Help"));
m_AboutMenu->addAction(m_AboutAction);
}
void MainWindow::CreateToolbars()
{
//////////////////////////////////////////
// BUILD THE CONTROLS USED BY THE TOOLBARS
// AND TIE THE BUTTONS TO THE ACTIONS
//////////////////////////////////////////
// Build the Font Selector Control
m_FontSelectCombo = new QFontComboBox();
m_FontSelectCombo->setToolTip(tr("Select Text Font"));
m_FontSelectCombo->setStatusTip(tr("Select Text Font"));
connect(m_FontSelectCombo, SIGNAL(activated(QString)), this, SLOT(UserActionFontSelectChanged(QString)));
// Build the Font Size Control
m_FontSizeCombo = new QComboBox;
m_FontSizeCombo->setEditable(true);
m_FontSizeCombo->setToolTip(tr("Set Text Size"));
m_FontSizeCombo->setStatusTip(tr("Set Text Size"));
for (int i = 4; i <= 32; i = i + 2) {
m_FontSizeCombo->addItem(QString().setNum(i));
}
m_LastFontSizeString = m_FontSizeCombo->itemText(m_FontSizeCombo->count() - 1);
QIntValidator* FontValidator = new QIntValidator(2, 64, this); // Allow user to enter different number not on the select list
m_FontSizeCombo->setValidator(FontValidator);
m_FontSizeCombo->setInsertPolicy(QComboBox::InsertAtBottom);
connect(m_FontSizeCombo, SIGNAL(activated(QString)), this, SLOT(UserActionFontSizeChanged(QString)));
// Font Color Button
m_FontColorToolButton = new QToolButton;
m_FontColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
m_FontColorToolButton->setMenu(CreateColorMenu(SLOT(UserActionTextColorChanged()), Qt::black));
m_FontColorToolButton->setToolTip(tr("Set Text Color"));
m_FontColorToolButton->setStatusTip(tr("Set Text Color"));
m_TextColorAction = m_FontColorToolButton->menu()->defaultAction();
m_FontColorToolButton->setIcon(CreateColorToolButtonIcon(":/images/PointerText.png", Qt::black));
// m_FontColorToolButton->setAutoFillBackground(true);
connect(m_FontColorToolButton, SIGNAL(clicked()), this, SLOT(UserActionTextColorButtonTriggered()));
// ComponentFill Color Button
m_ComponentFillColorToolButton = new QToolButton;
m_ComponentFillColorToolButton->setPopupMode(QToolButton::MenuButtonPopup);
m_ComponentFillColorToolButton->setMenu(CreateColorMenu(SLOT(UserActionComponentFillColorChanged()), Qt::white, true));
m_ComponentFillColorToolButton->setToolTip(tr("Set Component Color"));
m_ComponentFillColorToolButton->setStatusTip(tr("Set Component Color"));
m_ComponentFillColorAction = m_ComponentFillColorToolButton->menu()->defaultAction();
m_ComponentFillColorToolButton->setIcon(CreateColorToolButtonIcon(":/images/ItemFloodfill.png", Qt::white));
connect(m_ComponentFillColorToolButton, SIGNAL(clicked()), this, SLOT(UserActionComponentFillColorButtonTriggered()));
// Pointer SelectMove Button
QToolButton* PointerSelectMoveButton = new QToolButton;
PointerSelectMoveButton->setToolTip(tr("Select / Move Item"));
PointerSelectMoveButton->setStatusTip(tr("Select / Move Item"));
PointerSelectMoveButton->setCheckable(true);
PointerSelectMoveButton->setChecked(true);
PointerSelectMoveButton->setIcon(QIcon(":/images/PointerSelectMove.png"));
// Pointer Add a Wire Button
QToolButton* PointerAddWireButton = new QToolButton;
PointerAddWireButton->setToolTip(tr("Add A Wire"));
PointerAddWireButton->setStatusTip(tr("Add A Wire"));
PointerAddWireButton->setCheckable(true);
PointerAddWireButton->setIcon(QIcon(":/images/PointerLine.png"));
// Pointer Add Text Button
QToolButton* PointerAddTextButton = new QToolButton;
PointerAddTextButton->setToolTip(tr("Add Text"));
PointerAddTextButton->setStatusTip(tr("Add Text"));
PointerAddTextButton->setCheckable(true);
PointerAddTextButton->setIcon(QIcon(":/images/PointerText.png"));
// Create a group for the pointer and line buttons (makes them mutually exclusive)
m_PointerTypeGroup = new QButtonGroup(this);
m_PointerTypeGroup->setExclusive(false); // Allow buttons to not be mutually exclusive, mut. exclusion Done in handlers
m_PointerTypeGroup->addButton(PointerSelectMoveButton, int(WiringScene::MODE_SELECTMOVEITEM));
m_PointerTypeGroup->addButton(PointerAddWireButton, int(WiringScene::MODE_ADDWIRE));
m_PointerTypeGroup->addButton(PointerAddTextButton, int(WiringScene::MODE_ADDTEXT));
// If a buton of this group is clicked, then call the function
connect(m_PointerTypeGroup, SIGNAL(buttonClicked(int)), this, SLOT(UserActionPointerGroupClicked(int)));
// The Scaling combo box for the Scene scale
m_SceneScaleCombo = new QComboBox;
QStringList scales;
scales << tr("25%") << tr("50%") << tr("75%") << tr("100%") << tr("125%") << tr("150%") << tr("200%");
m_SceneScaleCombo->addItems(scales);
m_LastScaleString = m_SceneScaleCombo->itemText(m_SceneScaleCombo->count() - 1);
m_SceneScaleCombo->setEditable(true);
m_SceneScaleCombo->setCurrentIndex(3);
m_SceneScaleCombo->setToolTip(tr("Set Scale"));
m_SceneScaleCombo->setStatusTip(tr("Set Scale"));
// Setup a validator to allow user to enter different number not on the select list
QRegExp re("[1-5]{1,1}[0-9]{0,2}%{0,1}"); // First digit must be 1-5 and is required, followed by 0 or more digits of 0-9 followed by an optional %
QRegExpValidator* ScaleValidator = new QRegExpValidator(re, this); // Allow user to enter different number not on the select list
m_SceneScaleCombo->setValidator(ScaleValidator);
m_SceneScaleCombo->setInsertPolicy(QComboBox::InsertAtBottom);
connect(m_SceneScaleCombo, SIGNAL(activated(QString)), this, SLOT(UserActionSceneScaleChanged(QString)));
/////////////////////////
// BUILD THE TOOLBARS
/////////////////////////
// File Actions
m_FileActionsToolbar = addToolBar(tr("File Actions"));
m_FileActionsToolbar->setObjectName("File Actions");
m_FileActionsToolbar->addAction(m_WorkBenchLoadDesignAction);
m_FileActionsToolbar->addAction(m_WorkBenchSaveDesignAction);
m_FileActionsToolbar->addAction(m_ImportSSTInfoAction);
m_FileActionsToolbar->addAction(m_ExportSSTInputDeckAction);
// Edit Toolbar
m_EditToolbar = addToolBar(tr("Edit"));
m_EditToolbar->setObjectName("Edit");
m_EditToolbar->addAction(m_UndoAction);
m_EditToolbar->addAction(m_RedoAction);
// Tools Toolbar
m_ToolsToolbar = addToolBar(tr("Tools"));
m_ToolsToolbar->setObjectName("Tools");
m_ToolsToolbar->addWidget(PointerSelectMoveButton);
m_ToolsToolbar->addWidget(PointerAddWireButton);
m_ToolsToolbar->addWidget(PointerAddTextButton);
// Edit Toolbar
m_ItemToolBar = addToolBar(tr("Item"));
m_ItemToolBar->setObjectName("Item");
m_ItemToolBar->addAction(m_DeleteAction);
m_ItemToolBar->addAction(m_BringToFrontAction);
m_ItemToolBar->addAction(m_SendToBackAction);
m_ItemToolBar->addWidget(m_ComponentFillColorToolButton);
// Text ToolBar
m_FontControlToolBar = addToolBar(tr("Font Control"));
m_FontControlToolBar->setObjectName("Font Control");
m_FontControlToolBar->addWidget(m_FontSelectCombo);
m_FontControlToolBar->addWidget(m_FontSizeCombo);
m_FontControlToolBar->addAction(m_BoldAction);
m_FontControlToolBar->addAction(m_ItalicAction);
m_FontControlToolBar->addAction(m_UnderlineAction);
m_FontControlToolBar->addWidget(m_FontColorToolButton);
// View Control Toolbar
m_ViewControlToolbar = addToolBar(tr("View Control"));
m_ViewControlToolbar->setObjectName("View Control");
m_ViewControlToolbar->addWidget(m_SceneScaleCombo);
m_ViewControlToolbar->addAction(m_SceneScaleZoomAllAction);
m_FileActionsToolbar->addSeparator();
m_ViewControlToolbar->addAction(m_SceneScaleZoomInAction);
m_ViewControlToolbar->addAction(m_SceneScaleZoomOutAction);
// Turn off the right click on the toolbar area to prevent the toolbar menu from popping up
setContextMenuPolicy(Qt::NoContextMenu);
}
void MainWindow::CreateStatusbar()
{
// Create/Display the Status Bar
statusBar()->showMessage(tr(""));
}
QIcon MainWindow::CreateColorIcon(QColor color)
{
// Create the Pixmap for the icon
QPixmap pixmap(20, 20);
// Create a painter for the Pixmap
QPainter painter(&pixmap);
// Draw an outside box
painter.setPen(QPen());
painter.drawRect(0, 0, 20, 20);
// Now Fill it
painter.setPen(Qt::NoPen);
painter.fillRect(QRect(1, 1, 18, 18), color);
// Return the icon
return QIcon(pixmap);
}
QMenu* MainWindow::CreateColorMenu(const char* slot, QColor defaultColor, bool ComponentColors /*=false*/)
{
// Build list of Colors and a list of their names
QList<QColor> colors;
QStringList colorNames;
if (ComponentColors == true) {
// Colors for Components
colors << Qt::green << Qt::red << Qt::cyan << Qt::yellow << Qt::gray << Qt::white;
colorNames << tr("green") << tr("red") << tr("cyan") << tr("yellow") << tr("gray") << tr("white");
} else {
// Colors for Text
colors << Qt::black << Qt::green << Qt::red << Qt::blue;
colorNames << tr("black") << tr("green") << tr("red") << tr("blue");
}
// Now Build the Color Menu
QMenu* colorMenu = new QMenu(this);
// For each color set it up
for (int i = 0; i < colors.count(); ++i) {
QAction* action = new QAction(colorNames.at(i), this);
action->setData(colors.at(i));
action->setIcon(CreateColorIcon(colors.at(i)));
connect(action, SIGNAL(triggered()), this, slot);
colorMenu->addAction(action);
// If this color is the default color, make it the default action
if (colors.at(i) == defaultColor) {
colorMenu->setDefaultAction(action);
}
}
return colorMenu;
}
QIcon MainWindow::CreateColorToolButtonIcon(const QString& imageFile, QColor color)
{
// This builds the small color icon under the color picker toolbar buttons
QPixmap pixmap(50, 80);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
QPixmap image(imageFile);
// Draw icon centred horizontally on button.
QRect target(4, 0, 42, 43);
QRect source(0, 0, 42, 43);
painter.fillRect(QRect(0, 60, 50, 80), color);
painter.drawPixmap(target, image, source);
return QIcon(pixmap);
}
void MainWindow::EnableMovingPorts(bool Enable)
{
if (Enable == true) {
// Make sure a Component has been selected
// Then enable the Component to move ports
if (m_SelectedComponent != NULL) {
if (m_ComponentMovingPorts == NULL) {
m_ComponentMovingPorts = m_SelectedComponent;
m_ComponentMovingPorts->SetMovingPortsMode(true);
}
}
} else {
if (m_ComponentMovingPorts != NULL) {
m_ComponentMovingPorts->SetMovingPortsMode(false);
m_ComponentMovingPorts = NULL;
}
}
}
void MainWindow::UserActionComponentToolboxButtonPressed(SSTInfoDataComponent* ptrComponent)
{
// THIS HANDLER IS CALLED WHEN A BUTTON IN THE COMPONENT TOOLBOX (LEFT WINDOW) IS PRESSED DOWN
// Disable Moving Ports
EnableMovingPorts(false);
if (ptrComponent != NULL) {
// Set the WiringScene Operation Mode to Add Components
m_WiringScene->SetOperationMode(WiringScene::OperationMode(WiringScene::MODE_ADDCOMPONENT));
// Now Set the component from SSTInfo into the Scene to use when the user places it
m_WiringScene->SetUserChosenSSTInfoDataComponent(ptrComponent);
// Since we are in MODE_ADDCOMPONENT, turn off the ANY of the other Pointer
// Toolbar Buttons (MODE_ADDWIRE, MODE_ADDTEXT, or MODE_SELECTMOVEITEM)
QList<QAbstractButton*> PointerToolbarButtons = m_PointerTypeGroup->buttons();
// Turn off the checked setting for all other buttons
foreach (QAbstractButton* button, PointerToolbarButtons) {
button->setChecked(false);
}
} else {
// The ComponentToolbox is changed and we need to do nothing if the scene is clicked
m_WiringScene->SetOperationMode(WiringScene::OperationMode(WiringScene::MODE_DONOTHING));
}
}
void MainWindow::UserActionPointerGroupClicked(int id)
{
// THIS HANDLER IS CALLED WHEN ONE OF THE 3 BUTTONS OF THE
// ACTION POINTER GROUP (TOOBAR) IS CLICKED
// Disable Moving Ports
EnableMovingPorts(false);
// Turn off any checked ToolBox component
m_CompToolBox->UncheckAllCurrentGroupButtons();
// Get the id of the button we press (this will be one of the WiringScene Modes)
// MODE_ADDWIRE, MODE_ADDTEXT, or MODE_SELECTMOVEITEM
int NewMode = id;
// Set the WiringScene Operation Mode to the new mode
m_WiringScene->SetOperationMode(WiringScene::OperationMode(NewMode));
// Get a pointer to the list of the toolbar buttons
QList<QAbstractButton*> PointerToolbarButtons = m_PointerTypeGroup->buttons();
// Make sure the buttons are Mutually exclusive
// Turn off the checked setting for all other buttons, but make sure the selected button is checked
foreach (QAbstractButton* button, PointerToolbarButtons) {
if (m_PointerTypeGroup->button(id) != button) {
button->setChecked(false);
} else {
button->setChecked(true);
}
}
}
void MainWindow::HandleSceneEventComponentAdded(GraphicItemComponent* Item)
{
// Handler called when a Component Item is added to the scene
Q_UNUSED(Item)
// Disable Moving Ports
EnableMovingPorts(false);
}
void MainWindow::HandleSceneEventTextAdded(GraphicItemText* Item)
{
// Handler called when a Text Item is added to the scene