-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuttonmecs.cpp
More file actions
137 lines (120 loc) · 4.16 KB
/
buttonmecs.cpp
File metadata and controls
137 lines (120 loc) · 4.16 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
#include "buttonmecs.h"
#include <QLabel>
#include "project.h"
ButtonMECS::ButtonMECS(int x, int y, bool enableAction):
CommonItemMECS(x, y),
addOnClickAction(enableAction)
{
this->color = QColor(255, 0, 0);
m_onClickAction = new ItemAction();
}
void ButtonMECS::Copy(CommonItemMECS *from)
{
ButtonMECS *temp = (ButtonMECS *)from;
m_downImage = temp->m_downImage;
m_heldImage = temp->m_heldImage;
*m_onClickAction = *(temp->m_onClickAction);
CommonItemMECS::Copy(from);
}
QString ButtonMECS::GetName()
{
return "Button";
}
QString ButtonMECS::GetTextName()
{
return "Caption";
}
QGridLayout *ButtonMECS::GetPropertiesWidgets()
{
QLabel *lblLabelUpImage = new QLabel("Up Image:");
lblLabelUpImage->setFixedWidth(120);
m_cmbUpImage = new QComboBox;
m_cmbUpImage->addItem("");
m_cmbUpImage->addItems(Project::GetImages());
if (!getBackgroundImage().isEmpty())
{
QStringList list = getBackgroundImage().split('/');
if (list.count() > 1)
m_cmbUpImage->setCurrentIndex(m_cmbUpImage->findText(list[1]));
else
m_cmbUpImage->setCurrentIndex(m_cmbUpImage->findText(getBackgroundImage()));
}
QLabel *lblLabelDownImage = new QLabel("Down Image:");
m_cmbDownImage = new QComboBox;
m_cmbDownImage->addItem("");
m_cmbDownImage->addItems(Project::GetImages());
if (!m_downImage.isEmpty())
{
QStringList list = m_downImage.split('/');
if (list.count() > 1)
m_cmbDownImage->setCurrentIndex(m_cmbDownImage->findText(list[1]));
else
m_cmbDownImage->setCurrentIndex(m_cmbDownImage->findText(m_downImage));
}
QLabel *lblLabelHeldImage = new QLabel("Held Image:");
m_cmbHeldImage = new QComboBox;
m_cmbHeldImage->addItem("");
m_cmbHeldImage->addItems(Project::GetImages());
if (!m_heldImage.isEmpty())
{
QStringList list = m_heldImage.split('/');
m_cmbHeldImage->setCurrentIndex(m_cmbHeldImage->findText(list[1]));
if (list.count() > 1)
m_cmbHeldImage->setCurrentIndex(m_cmbHeldImage->findText(list[1]));
else
m_cmbHeldImage->setCurrentIndex(m_cmbHeldImage->findText(m_heldImage));
}
QLabel *lblCurrentAction = new QLabel(m_onClickActionString);
QGridLayout *layout = new QGridLayout();
layout->addWidget(lblLabelUpImage, 0, 0);
layout->addWidget(m_cmbUpImage, 0, 1);
layout->addWidget(lblLabelDownImage, 1, 0);
layout->addWidget(m_cmbDownImage, 1, 1);
layout->addWidget(lblLabelHeldImage, 2, 0);
layout->addWidget(m_cmbHeldImage, 2, 1);
layout->addWidget(lblCurrentAction, 3, 0, 1, 2);
if (addOnClickAction)
{
layout->addLayout(m_onClickAction->GetLayout(), 4, 0, 1, 2);
}
// QObject::connect(m_onClickAction, SIGNAL(OnChangeCommand(QString)), SLOT(onChangeCommand(QString)));
return layout;
}
void ButtonMECS::AcceptWidgetsProperties()
{
setBackgroundImage(Project::ImagesDirectory
+ QString("/") + m_cmbUpImage->currentText());
m_downImage = Project::ImagesDirectory
+ QString("/") +m_cmbDownImage->currentText();
m_heldImage = Project::ImagesDirectory
+ QString("/") +m_cmbHeldImage->currentText();
if (addOnClickAction)
m_onClickActionString = m_onClickAction->ToString();
}
void ButtonMECS::SetDownImage(QString image)
{
m_downImage = image;
}
void ButtonMECS::SetHeldImage(QString image)
{
m_heldImage = image;
}
void ButtonMECS::SetOnClickAction(QString commandType, QString target, QString command)
{
m_onClickAction->Init(commandType, target, command);
m_onClickActionString = " " + commandType + " " + target + " " + command;
}
QString ButtonMECS::Save()
{
QString onClickAction = QString("OnClick = %0")
.arg(m_onClickActionString.trimmed());
return QString (
"[%0]\n"\
"Caption = %1\n").arg(GetName()).arg(getText()) + CommonItemMECS::Save() +
QString ("UpImage = %0\n" \
"DownImage = %1\n" \
"HeldImage = %2\n").arg(getBackgroundImage())
.arg(m_downImage).arg(m_heldImage) +
((addOnClickAction)?onClickAction:"")
+ "\n\n";
}