-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathTrackedComponentView.cpp
More file actions
846 lines (761 loc) · 28.8 KB
/
Copy pathTrackedComponentView.cpp
File metadata and controls
846 lines (761 loc) · 28.8 KB
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
#include "TrackedComponentView.h"
#include <assert.h>
#include "QBrush"
#include "QPainter"
#include <QGraphicsSceneHoverEvent>
#include "QGraphicsScene"
#include "QGraphicsEllipseItem"
#include "ComponentShape.h"
#include "Model/CoreParameter.h"
#include "Controller/ControllerTrackedComponentCore.h"
#include "Interfaces/IModel/IModelTrackedTrajectory.h"
#include "QDebug"
#include "QMenu"
#include "qlabel.h"
#include "QWidgetAction"
#include "QAction"
#include "qcolordialog.h"
class QGraphicsSceneHoverEvent;
TrackedComponentView::TrackedComponentView(QGraphicsItem* parent,
IController* controller,
IModel* model)
: IViewTrackedComponent(parent, controller, model)
{
m_boundingRect = QRectF(0, 0, 4080, 4080);
m_currentFrameNumber = 0;
setAcceptHoverEvents(true);
setAcceptDrops(true);
_watchingDrag = 0;
m_permissions.insert(std::pair<ENUMS::COREPERMISSIONS, bool>(
ENUMS::COREPERMISSIONS::COMPONENTVIEW,
true));
m_permissions.insert(std::pair<ENUMS::COREPERMISSIONS, bool>(
ENUMS::COREPERMISSIONS::COMPONENTADD,
true));
m_permissions.insert(std::pair<ENUMS::COREPERMISSIONS, bool>(
ENUMS::COREPERMISSIONS::COMPONENTMOVE,
true));
m_permissions.insert(std::pair<ENUMS::COREPERMISSIONS, bool>(
ENUMS::COREPERMISSIONS::COMPONENTREMOVE,
true));
m_permissions.insert(std::pair<ENUMS::COREPERMISSIONS, bool>(
ENUMS::COREPERMISSIONS::COMPONENTSWAP,
true));
m_permissions.insert(std::pair<ENUMS::COREPERMISSIONS, bool>(
ENUMS::COREPERMISSIONS::COMPONENTROTATE,
true));
}
void TrackedComponentView::rcvDimensionUpdate(int x, int y)
{
m_boundingRect = QRectF(0, 0, x, y);
update();
}
QRectF TrackedComponentView::boundingRect() const
{
return m_boundingRect;
}
void TrackedComponentView::paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget)
{
IModelTrackedTrajectory* all = dynamic_cast<IModelTrackedTrajectory*>(
getModel());
// check if model exists
if (!all) {
return;
}
}
void TrackedComponentView::getNotified()
{
updateShapes(m_currentFrameNumber);
update();
}
bool TrackedComponentView::sceneEventFilter(QGraphicsItem* watched,
QEvent* event)
{
return true;
}
bool TrackedComponentView::eventFilter(QObject* target, QEvent* event)
{
return false;
}
void TrackedComponentView::hoverEnterEvent(QGraphicsSceneHoverEvent* event)
{
}
void TrackedComponentView::hoverLeaveEvent(QGraphicsSceneHoverEvent* event)
{
}
QVariant TrackedComponentView::itemChange(GraphicsItemChange change,
const QVariant& value)
{
if (change == ItemSceneHasChanged && this->scene()) {
createChildShapesAtStart();
}
return QGraphicsItem::itemChange(change, value);
}
void TrackedComponentView::mousePressEvent(QGraphicsSceneMouseEvent* event)
{
// right clicking the view unselects all selected items so do this to avoid
// this behavior
if (event->button() != Qt::LeftButton) {
event->accept();
return;
}
QGraphicsItem::mousePressEvent(event);
}
/// opens a context menu when right clicked
void TrackedComponentView::contextMenuEvent(
QGraphicsSceneContextMenuEvent* event)
{
lastClickedPos = event->pos().toPoint();
QMenu menu;
// create the info box
QWidgetAction* infoBox = new QWidgetAction(this);
QString info = QString("Position (x,y) : ");
info.append(QString("(" + QString::number(lastClickedPos.x()) + ", " +
QString::number(lastClickedPos.y()) + ")"));
QLabel* infoLabel = new QLabel(info);
infoLabel->setWordWrap(true);
infoLabel->setStyleSheet("QLabel {font-weight: bold; text-align: center}");
infoLabel->setAlignment(Qt::AlignCenter);
infoBox->setDefaultWidget(infoLabel);
menu.addAction(infoBox);
menu.addSeparator();
QAction* addComponentAction = menu.addAction(
"Add trajectory here",
dynamic_cast<TrackedComponentView*>(this),
SLOT(addTrajectory()));
QAction* swapIdsAction = menu.addAction(
"Swap ID's",
dynamic_cast<TrackedComponentView*>(this),
SLOT(swapIds()));
QAction* unmarkAllAction = menu.addAction(
"Unmark all...",
dynamic_cast<TrackedComponentView*>(this),
SLOT(unmarkAll()));
QAction* removeSelectedAction = menu.addAction(
"Remove selected trajectories",
dynamic_cast<TrackedComponentView*>(this),
SLOT(removeTrajectories()));
// manage permissions
addComponentAction->setEnabled(
m_permissions[ENUMS::COREPERMISSIONS::COMPONENTADD]);
swapIdsAction->setEnabled(
m_permissions[ENUMS::COREPERMISSIONS::COMPONENTSWAP]);
removeSelectedAction->setEnabled(
m_permissions[ENUMS::COREPERMISSIONS::COMPONENTREMOVE]);
// manage swapping
swapIdsAction->setEnabled(false);
QList<QGraphicsItem*> allSelectedItems = this->scene()->selectedItems();
// check if two shapes are selected
if (allSelectedItems.size() == 2 &&
dynamic_cast<ComponentShape*>(allSelectedItems[0]) &&
dynamic_cast<ComponentShape*>(allSelectedItems[1])) {
ComponentShape* selectedItem0 = dynamic_cast<ComponentShape*>(
allSelectedItems[0]);
ComponentShape* selectedItem1 = dynamic_cast<ComponentShape*>(
allSelectedItems[1]);
// check if both shapes are swappable (check permission for each shape)
// and general permission
if (selectedItem0->isSwappable() && selectedItem1->isSwappable() &&
m_permissions[ENUMS::COREPERMISSIONS::COMPONENTSWAP]) {
swapIdsAction->setEnabled(true);
}
}
// execute menu
QAction* selectedAction = menu.exec(event->screenPos());
lastClickedPos = QPoint(0, 0);
}
/// set permissions for this and all component shapes, which were send by the
/// plugin
void TrackedComponentView::setPermission(
std::pair<ENUMS::COREPERMISSIONS, bool> permission)
{
m_permissions[permission.first] = permission.second;
qDebug() << permission.first << " set to" << permission.second;
// first check if permission is for view, if not pass permission to shapes
// -> view has all permissions, shapes only certain ones
if (permission.first == ENUMS::COREPERMISSIONS::COMPONENTVIEW) {
this->setVisible(permission.second);
return;
}
// does not need to be propagated to shapes; only handled by view
if (permission.first == ENUMS::COREPERMISSIONS::COMPONENTADD) {
return;
}
QGraphicsItem* child;
foreach (child, this->childItems()) {
ComponentShape* shape = dynamic_cast<ComponentShape*>(child);
if (shape) {
shape->setPermission(permission);
}
}
}
/// at plugin load, draw each element of initial main trajectory
void TrackedComponentView::createChildShapesAtStart()
{
// flush all old children (e.g. from previous trackers)
foreach (QGraphicsItem* child, this->childItems()) {
child->hide();
delete child;
}
// check if scene is set
assert(this->scene());
// create a shape for each model-component upon plugin-init
IModelTrackedTrajectory* all = dynamic_cast<IModelTrackedTrajectory*>(
getModel());
if (all) {
for (int i = 0; i < all->size(); i++) {
IModelTrackedTrajectory* trajectory =
dynamic_cast<IModelTrackedTrajectory*>(all->getChild(i));
if (trajectory) {
// create componentshape for trajectory
ComponentShape* newShape =
new ComponentShape(this, trajectory, trajectory->getId());
connectShape(newShape);
}
IModelTrackedPoint* rect = dynamic_cast<IModelTrackedPoint*>(
all->getChild(i));
if (rect) {
int x = rect->getX();
int y = rect->getY();
int w = 20;
int h = 20;
QGraphicsRectItem* rect =
new QGraphicsRectItem(x - w / 2, y - h / 2, w, h, this);
rect->setPen(QPen(Qt::blue));
rect->setBrush(QBrush(Qt::blue));
rect->setFlag(ItemIsMovable);
rect->setFlag(ItemIsSelectable);
rect->setFlag(ItemSendsGeometryChanges);
rect->setData(0, i);
}
}
}
}
/// connect a newly created component shape to all slots it needs and set
/// permissions
void TrackedComponentView::connectShape(ComponentShape* shape)
{
CoreParameter* coreParams = dynamic_cast<CoreParameter*>(
dynamic_cast<ControllerTrackedComponentCore*>(getController())
->getCoreParameter());
// set type
IModelTrackedTrajectory* trajectory = shape->getTrajectory();
IModelTrackedPoint* point = dynamic_cast<IModelTrackedPoint*>(
trajectory->getChild(m_currentFrameNumber));
if (point) {
shape->setData(1, "point");
}
IModelTrackedEllipse* ellipse = dynamic_cast<IModelTrackedEllipse*>(
trajectory->getChild(m_currentFrameNumber));
if (ellipse) {
shape->setData(1, "ellipse");
}
IModelTrackedRectangle* rectangle = dynamic_cast<IModelTrackedRectangle*>(
trajectory->getChild(m_currentFrameNumber));
if (rectangle) {
shape->setData(1, "rectangle");
}
IModelTrackedPolygon* polygon = dynamic_cast<IModelTrackedPolygon*>(
trajectory->getChild(m_currentFrameNumber));
if (polygon) {
shape->setData(1, "polygon");
}
// connect slots/signals
QObject::connect(
shape,
SIGNAL(emitRemoveTrajectory(IModelTrackedTrajectory*)),
dynamic_cast<ControllerTrackedComponentCore*>(this->getController()),
SIGNAL(emitRemoveTrajectory(IModelTrackedTrajectory*)),
Qt::DirectConnection);
QObject::connect(
shape,
SIGNAL(emitRemoveTrackEntity(IModelTrackedTrajectory*, uint)),
dynamic_cast<ControllerTrackedComponentCore*>(this->getController()),
SIGNAL(emitRemoveTrackEntity(IModelTrackedTrajectory*, uint)),
Qt::DirectConnection);
QObject::connect(
shape,
SIGNAL(emitMoveElement(IModelTrackedTrajectory*,
QPoint,
QPoint,
uint,
int)),
dynamic_cast<ControllerTrackedComponentCore*>(this->getController()),
SIGNAL(emitMoveElement(IModelTrackedTrajectory*,
QPoint,
QPoint,
uint,
int)),
Qt::DirectConnection);
QObject::connect(
shape,
SIGNAL(emitToggleFixTrack(IModelTrackedTrajectory*, bool)),
dynamic_cast<ControllerTrackedComponentCore*>(this->getController()),
SIGNAL(emitToggleFixTrack(IModelTrackedTrajectory*, bool)),
Qt::DirectConnection);
QObject::connect(
shape,
SIGNAL(emitEntityRotation(IModelTrackedTrajectory*,
double,
double,
uint)),
dynamic_cast<ControllerTrackedComponentCore*>(this->getController()),
SIGNAL(emitEntityRotation(IModelTrackedTrajectory*,
double,
double,
uint)),
Qt::DirectConnection);
QObject::connect(
shape,
&ComponentShape::emitGoToFrame,
dynamic_cast<ControllerTrackedComponentCore*>(this->getController()),
&ControllerTrackedComponentCore::emitGoToFrame,
Qt::DirectConnection);
QObject::connect(shape,
SIGNAL(broadcastMove()),
this,
SLOT(receiveBroadcastMove()),
Qt::DirectConnection);
// set the shapes members
shape->m_currentFramenumber = m_currentFrameNumber;
shape->setMembers(coreParams);
// set permissions
shape->setPermission(std::pair<ENUMS::COREPERMISSIONS, bool>(
ENUMS::COREPERMISSIONS::COMPONENTMOVE,
m_permissions[ENUMS::COREPERMISSIONS::COMPONENTMOVE]));
shape->setPermission(std::pair<ENUMS::COREPERMISSIONS, bool>(
ENUMS::COREPERMISSIONS::COMPONENTREMOVE,
m_permissions[ENUMS::COREPERMISSIONS::COMPONENTREMOVE]));
shape->setPermission(std::pair<ENUMS::COREPERMISSIONS, bool>(
ENUMS::COREPERMISSIONS::COMPONENTSWAP,
m_permissions[ENUMS::COREPERMISSIONS::COMPONENTSWAP]));
shape->setPermission(std::pair<ENUMS::COREPERMISSIONS, bool>(
ENUMS::COREPERMISSIONS::COMPONENTROTATE,
m_permissions[ENUMS::COREPERMISSIONS::COMPONENTROTATE]));
// update the shape
shape->updateAttributes(m_currentFrameNumber);
}
/*********************************************************************/ /**
*******************************SLOTS*************************************
*************************************************************************/
/**
* updates componentshapes, deletes all if tracking data empty and creates new
* if new trajectories were added componentshapes are children of this view
* (see qt's parent-child-system)
*/
void TrackedComponentView::updateShapes(uint framenumber)
{
m_currentFrameNumber = framenumber;
IModelTrackedTrajectory* all = dynamic_cast<IModelTrackedTrajectory*>(
getModel());
if (!all || all->size() == 0) {
// if root is nullptr, delete all children
foreach (auto child, this->childItems()) {
delete child;
}
return;
}
// update each shape; shape hides itself if trajectory is empty or not
// existant or currentchild
foreach (auto child, this->childItems()) {
ComponentShape* shape = dynamic_cast<ComponentShape*>(child);
if (shape) {
shape->updateAttributes(m_currentFrameNumber);
}
}
// check for new trajectories; for each create a new shape
if (this->childItems().size() < all->size()) {
// iterate over trajectories from back to increase performance
for (int i = all->size() - 1;
i >= 0 && this->childItems().size() <= all->size();
i--) {
IModelTrackedTrajectory* trajectory =
dynamic_cast<IModelTrackedTrajectory*>(all->getChild(i));
// check if trajectory already has shape object
if (trajectory && !checkTrajectory(trajectory)) {
ComponentShape* newShape =
new ComponentShape(this, trajectory, trajectory->getId());
connectShape(newShape);
} else {
// already there or nullptr
}
// all trajectories already have shapes
if (all->size() == this->childItems().size()) {
break;
}
}
}
}
/**
* gets triggered when one or more shape is moved; emits move signal to tracker
* for all selected shapes if not broadcasted, only the position of actually
* moved componentshape is saved in tracking data the rest would be reset after
* update
*/
void TrackedComponentView::receiveBroadcastMove()
{
QList<QGraphicsItem*> allSelectedItems = this->scene()->selectedItems();
QList<ComponentShape*> allSelectedEntitiesList;
QGraphicsItem* item;
foreach (item, allSelectedItems) {
ComponentShape* shape = dynamic_cast<ComponentShape*>(item);
if (shape) {
if (shape->isSelected()) {
allSelectedEntitiesList.append(shape);
}
}
}
int numberSelectedEntitiesToMove = allSelectedEntitiesList.size();
ComponentShape* entity;
foreach (entity, allSelectedEntitiesList) {
ComponentShape* shape = dynamic_cast<ComponentShape*>(entity);
if (shape) {
if (shape->isSelected()) {
IModelTrackedTrajectory* shapeTrajectory =
shape->getTrajectory();
// calculate the current pos and emit it to the commands
// component
shape->emitMoveElement(
shapeTrajectory,
shape->getOldPos() +
QPoint(shape->m_w / 2, shape->m_h / 2),
shape->pos().toPoint() +
QPoint(shape->m_w / 2, shape->m_h / 2),
m_currentFrameNumber,
numberSelectedEntitiesToMove);
numberSelectedEntitiesToMove--;
}
}
}
}
void TrackedComponentView::receiveViewSwitch(bool lever)
{
this->setVisible(lever);
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->m_tracingLayer->setVisible(lever);
}
}
}
void TrackedComponentView::receiveTrackDimensionsAll(int width, int height)
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->receiveDimensions(width, height);
}
}
}
void TrackedComponentView::receiveTrackDimensionsSelected(int width,
int height)
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape && childShape->isSelected()) {
childShape->receiveDimensions(width, height);
}
}
}
void TrackedComponentView::receiveTrackOrientationLine(bool toggle)
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->receiveToggleOrientationLine(toggle);
}
}
}
void TrackedComponentView::receiveTrackShowId(bool toggle)
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->receiveShowId(toggle);
}
}
}
void TrackedComponentView::receiveTrackDimensionsSetDefault()
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->setDimensionsToDefault();
}
}
}
void TrackedComponentView::receiveTracingSteps(int steps)
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->receiveTracingSteps(steps);
}
}
}
void TrackedComponentView::receiveTracingStyle(QString style)
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->receiveTracingStyle(style);
}
}
}
void TrackedComponentView::receiveTracingHistoryLength(int history)
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->receiveTracingLength(history);
}
}
}
void TrackedComponentView::receiveTracingTimeDegradation(QString degradation)
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->receiveTracingTimeDegradation(degradation);
}
}
}
void TrackedComponentView::receiveColorChangeBrushAll()
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
const QColorDialog::ColorDialogOptions options = QFlag(
QColorDialog::ShowAlphaChannel || QColorDialog::DontUseNativeDialog);
QColor color = QColorDialog::getColor(Qt::white,
nullptr,
QString("Choose fill color"),
options);
// QColorDialog* cDialog = new QColorDialog(Qt::white);
// cDialog->show();
// cDialog->activateWindow();
// cDialog->raise();
// cDialog->setFocus();
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->changeBrushColor(color);
}
}
}
void TrackedComponentView::receiveColorChangeBorderAll()
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
QColor color = QColorDialog::getColor(Qt::white,
nullptr,
QString("Choose border color"),
QColorDialog::ShowAlphaChannel);
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->changePenColor(color);
}
}
}
void TrackedComponentView::receiveColorChangeBorderSelected()
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
QColor color = QColorDialog::getColor(Qt::white,
nullptr,
QString("Choose border color"),
QColorDialog::ShowAlphaChannel);
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape && childShape->isSelected()) {
childShape->changePenColor(color);
}
}
}
void TrackedComponentView::receiveColorChangeBrushSelected()
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
QColor color = QColorDialog::getColor(Qt::white,
nullptr,
QString("Choose fill color"),
QColorDialog::ShowAlphaChannel);
;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape && childShape->isSelected()) {
childShape->changeBrushColor(color);
}
}
}
void TrackedComponentView::receiveSelectAll()
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
if (dynamic_cast<ComponentShape*>(childItem)) {
childItem->setSelected(true);
}
}
}
///////////////////////context menu action slots///////////////
void TrackedComponentView::addTrajectory()
{
IModelTrackedTrajectory* all = dynamic_cast<IModelTrackedTrajectory*>(
getModel());
int id = -1;
if (all) {
id = all->size() + 1;
}
if (id <= 0) {
qWarning() << "ID cannot be smaller than or equal 0";
}
if (!lastClickedPos.isNull()) {
// qDebug() << "TCV: new track at position " << lastClickedPos;
emitAddTrajectory(lastClickedPos, id);
lastClickedPos = QPoint(0, 0);
} else {
// qDebug() << "TCV: new track at center of top left quarter of video";
QPoint topLeftQuarterCenter = QPoint(this->boundingRect().width() / 8,
this->boundingRect().height() /
8);
emitAddTrajectory(topLeftQuarterCenter, id);
}
}
void TrackedComponentView::swapIds()
{
QList<QGraphicsItem*> allSelectedItems = this->scene()->selectedItems();
if (allSelectedItems.size() != 2) {
qWarning()
<< "There need to be exactly two tracks selected to swap ID's!";
return;
}
ComponentShape* shape0 = dynamic_cast<ComponentShape*>(
allSelectedItems[0]);
ComponentShape* shape1 = dynamic_cast<ComponentShape*>(
allSelectedItems[1]);
if (shape0 && shape1 && shape0->isSwappable() && shape1->isSwappable()) {
IModelTrackedTrajectory* trajectory0 =
dynamic_cast<IModelTrackedTrajectory*>(shape0->getTrajectory());
IModelTrackedTrajectory* trajectory1 =
dynamic_cast<IModelTrackedTrajectory*>(shape1->getTrajectory());
emitSwapIds(trajectory0, trajectory1);
} else {
qWarning() << "Selected objects are not swappable";
}
}
void TrackedComponentView::removeTrajectories()
{
QList<QGraphicsItem*> allSelectedItems = this->scene()->selectedItems();
QGraphicsItem* item;
foreach (item, allSelectedItems) {
ComponentShape* shape = dynamic_cast<ComponentShape*>(item);
if (shape) {
shape->removeTrack();
}
}
}
void TrackedComponentView::unmarkAll()
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->unmarkShape();
}
}
}
///////////////////////////////////////////////////////
bool TrackedComponentView::checkTrajectory(IModelTrackedTrajectory* trajectory)
{
bool isVisualized = false;
for (int i = 0; i < this->childItems().size(); i++) {
ComponentShape* shape = dynamic_cast<ComponentShape*>(
this->childItems()[i]);
if (shape) {
if (shape->getTrajectory() == trajectory) {
isVisualized = true;
break;
}
}
}
return isVisualized;
}
void TrackedComponentView::receiveTracerProportions(float proportion)
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->receiveTracerProportions(proportion);
}
}
}
void TrackedComponentView::receiveTracerOrientationLine(bool toggle)
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->receiveTracerOrientationLine(toggle);
}
}
}
void TrackedComponentView::receiveTracerFrameNumber(bool toggle)
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->receiveTracerFrameNumber(toggle);
}
}
}
void TrackedComponentView::receiveToggleAntialiasingEntities(bool toggle)
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->receiveAntialiasing(toggle);
}
}
}
void TrackedComponentView::receiveIgnoreZoom(bool toggle)
{
QList<QGraphicsItem*> childrenItems = this->childItems();
QGraphicsItem* childItem;
foreach (childItem, childrenItems) {
ComponentShape* childShape = dynamic_cast<ComponentShape*>(childItem);
if (childShape) {
childShape->receiveIgnoreZoom(toggle);
}
}
}