-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomDropContainerWidget.cpp
More file actions
51 lines (48 loc) · 2.1 KB
/
CustomDropContainerWidget.cpp
File metadata and controls
51 lines (48 loc) · 2.1 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
/**
* Authors: Alysha Aul, Nandhitha Krishnan, Paul Rodgers, Nouran Sakr, Chun Yang
* Date: November 28, 2023
* Purpose: To act as a Container that accept drag and drop the start point and end point.
*/
#include "CustomDropContainerWidget.h"
/**
* Class constructor for make drop and drag possible for the node
* It will accept dropped image
*/
CustomDropContainerWidget::CustomDropContainerWidget(Board* board)
{
boardInstance_= board;
acceptDrops("WImage");
setInline(false);
}
/**
* Drop event Method: when we actually drop the item we need to check if we can drop or not.
* @param event: the drop event which contains the information about dropped item.
*/
void CustomDropContainerWidget::dropEvent(WDropEvent event)
{
if(event.mimeType() == "WImage"){
WImage *child = static_cast<WImage*>(event.source());
WContainerWidget *parent = static_cast<WContainerWidget*>(child->parent());
WTableCell *parentCell = static_cast<WTableCell*>(this->parent());
int row = parentCell->row();
int column = parentCell->column();
int type = boardInstance_->getMap()->getNode(row, column)->getType();
// if it is not a wall block, then we can drop
if(type != 5) {
parent->removeChild(child);
if(child->alternateText() == "Start-Icon"){
WImage *temp = addWidget(std::make_unique<Wt::WImage>(Wt::WLink("images/triangletwo-right.svg")));
temp->setDraggable("WImage");
temp->setAlternateText("Start-Icon");
// modify start point of map in board class
boardInstance_->getMap()->setStartPoint(row, column);
}else if(child->alternateText() == "End-Icon") {
WImage *temp = addWidget(std::make_unique<Wt::WImage>(Wt::WLink("images/circle.svg")));
temp->setDraggable("WImage");
temp->setAlternateText("End-Icon");
// modify end point of map in board class
boardInstance_->getMap()->setTargetPoint(row, column);
}
}
}
}