forked from GokuMK/TSRE5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEngListWidget.cpp
183 lines (158 loc) · 5.84 KB
/
EngListWidget.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
/* This file is part of TSRE5.
*
* TSRE5 - train sim game engine and MSTS/OR Editors.
* Copyright (C) 2016 Piotr Gadecki <[email protected]>
*
* Licensed under GNU General Public License 3.0 or later.
*
* See LICENSE.md or https://www.gnu.org/licenses/gpl.html
*/
#include "EngListWidget.h"
#include "EngLib.h"
#include "Eng.h"
#include "Game.h"
EngListWidget::EngListWidget() : QWidget(){
addBegButton.setText("Add Beg");
addCurButton.setText("Add Cur");
addEndButton.setText("Add End");
addRandButton.setText("Add Rand");
addNum.setText("1");
engType.addItem("ALL");
engType.addItem("electric");
engType.addItem("diesel");
engType.addItem("steam");
engType.addItem("carriage");
engType.addItem("freight");
engType.addItem("tender");
couplingType.addItem("ALL");
couplingType.addItem("Chain");
couplingType.addItem("Automatic");
couplingType.addItem("Bar");
QVBoxLayout *vbox = new QVBoxLayout;
vbox->setSpacing(2);
vbox->setContentsMargins(0,1,1,1);
QFormLayout *vlist = new QFormLayout;
vlist->setSpacing(2);
vlist->setContentsMargins(3,0,3,0);
vlist->addRow("Total:", &totalVal);
vlist->addRow("Type:", &engType);
vlist->addRow("Coupling:", &couplingType);
vlist->addRow("Search", &searchBox);
vlist->addRow("Num to add", &addNum);
vbox->addItem(vlist);
QHBoxLayout *addbuttons = new QHBoxLayout;
addbuttons->addWidget(&addBegButton);
addbuttons->addWidget(&addCurButton);
addbuttons->addWidget(&addEndButton);
addbuttons->addWidget(&addRandButton);
//vbox->addWidget();
vbox->addItem(addbuttons);
vbox->addWidget(&items);
//vbox->addStretch(1);
this->setLayout(vbox);
engType.setStyleSheet("combobox-popup: 0;");
this->setMinimumWidth(250);
couplingType.setStyleSheet("combobox-popup: 0;");
QObject::connect(&engType, SIGNAL(activated(QString)),
this, SLOT(fs(QString)));
QObject::connect(&couplingType, SIGNAL(activated(QString)),
this, SLOT(fs(QString)));
QObject::connect(&searchBox, SIGNAL(textEdited(QString)),
this, SLOT(fs(QString)));
QObject::connect(&items, SIGNAL(itemSelectionChanged()),
this, SLOT(itemsSelected()));
QObject::connect(&addBegButton, SIGNAL(released()),
this, SLOT(addBegButtonSelected()));
QObject::connect(&addCurButton, SIGNAL(released()),
this, SLOT(addCurButtonSelected()));
QObject::connect(&addEndButton, SIGNAL(released()),
this, SLOT(addEndButtonSelected()));
QObject::connect(&addRandButton, SIGNAL(released()),
this, SLOT(addRndButtonSelected()));
items.viewport()->installEventFilter(this);
items.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
totalVal.setEnabled(false);
}
EngListWidget::~EngListWidget() {
}
void EngListWidget::fs(QString n){
QString ef = engType.currentText();
if(engType.currentIndex() == 0)
ef = "";
QString cf = couplingType.currentText();
if(couplingType.currentIndex() == 0)
cf = "";
QString sf = searchBox.text();
qDebug() << ef <<" "<< cf <<" "<< sf;
fillEngList(ef, cf, sf);
}
void EngListWidget::fillEngList(){
fillEngList("","","");
}
void EngListWidget::fillEngList(QString engFilter, QString couplingFilter, QString searchFilter){
items.clear();
Eng * e;
totalVal.setText(QString::number(Game::currentEngLib->jesteng));
for (int i = 0; i < Game::currentEngLib->jesteng; i++){
e = Game::currentEngLib->eng[i];
if(e == NULL) continue;
if(e->loaded !=1) continue;
if(!e->engFilter(engFilter)) continue;
if(!e->couplingFilter(couplingFilter)) continue;
if(!e->searchFilter(searchFilter)) continue;
new QListWidgetItem ( e->displayName, &items, i);
}
items.sortItems(Qt::AscendingOrder);
}
void EngListWidget::itemsSelected(){
QListWidgetItem * item = items.currentItem();
//qDebug() << item->type() << " " << item->text();
emit engListSelected(item->type());
}
void EngListWidget::addBegButtonSelected(){
bool ok = false;
int count = addNum.text().toInt(&ok);
if(!ok) count = 1;
addBegButtonSelected(count);
}
void EngListWidget::addBegButtonSelected(int count){
QListWidgetItem * item = items.currentItem();
if(item == NULL) return;
emit addToConSelected(item->type(), 0, count);
}
void EngListWidget::addCurButtonSelected(){
bool ok = false;
int count = addNum.text().toInt(&ok);
if(!ok) count = 1;
addCurButtonSelected(count);
}
void EngListWidget::addCurButtonSelected(int count){
QListWidgetItem * item = items.currentItem();
if(item == NULL) return;
emit addToConSelected(item->type(), 1, count);
}
void EngListWidget::addEndButtonSelected(){
bool ok = false;
int count = addNum.text().toInt(&ok);
if(!ok) count = 1;
addEndButtonSelected(count);
}
void EngListWidget::addEndButtonSelected(int count){
QListWidgetItem * item = items.currentItem();
if(item == NULL) return;
emit addToConSelected(item->type(), 2, count);
}
void EngListWidget::addRndButtonSelected(){
QListWidgetItem * item = items.currentItem();
if(item == NULL) return;
emit addToRandomConsist(item->type());
}
bool EngListWidget::eventFilter(QObject *obj, QEvent *event) {
if (event->type() == QEvent::MouseButtonDblClick) {
QMouseEvent * mouseEvent = static_cast <QMouseEvent *> (event);
if (mouseEvent->button() == Qt::LeftButton) {
addEndButtonSelected(1);
}
}
return QWidget::eventFilter(obj, event);
}