forked from GokuMK/TSRE5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConUnitsWidget.cpp
106 lines (95 loc) · 3.17 KB
/
ConUnitsWidget.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
/* This file is part of TSRE5.
*
* TSRE5 - train sim game engine and MSTS/OR Editors.
* Copyright (C) 2016 Piotr Gadecki <pgadecki@gmail.com>
*
* Licensed under GNU General Public License 3.0 or later.
*
* See LICENSE.md or https://www.gnu.org/licenses/gpl.html
*/
#include "ConUnitsWidget.h"
#include "Consist.h"
#include "Eng.h"
#include "EngLib.h"
#include "Game.h"
ConUnitsWidget::ConUnitsWidget() {
QPushButton *bUp = new QPushButton("Up");
QPushButton *bDown = new QPushButton("Down");
QPushButton *bDel = new QPushButton("Delete");
QPushButton *bFlip = new QPushButton("Flip");
QHBoxLayout *bbox = new QHBoxLayout;
bbox->addWidget(bUp);
bbox->addWidget(bDown);
bbox->addWidget(bDel);
bbox->addWidget(bFlip);
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("Units:",&count);
vbox->addItem(bbox);
vbox->addItem(vlist);
vbox->addWidget(&items);
//vbox->addStretch(1);
this->setLayout(vbox);
this->setMinimumWidth(250);
QObject::connect(&items, SIGNAL(itemClicked(QListWidgetItem*)),
this, SLOT(itemsSelected(QListWidgetItem*)));
QObject::connect(bDel, SIGNAL(released()),
this, SLOT(bDelReleased()));
QObject::connect(bUp, SIGNAL(released()),
this, SLOT(bUpReleased()));
QObject::connect(bDown, SIGNAL(released()),
this, SLOT(bDownReleased()));
QObject::connect(bFlip, SIGNAL(released()),
this, SLOT(bFlipReleased()));
items.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
ConUnitsWidget::~ConUnitsWidget() {
}
void ConUnitsWidget::setCon(Consist* c){
con = c;
if(con == NULL) return;
items.clear();
count.setText(QString::number(con->engItems.size()));
Eng * e;
QString prefix;
for (int i = 0; i < con->engItems.size(); i++){
e = Game::currentEngLib->eng[con->engItems[i].eng];
if(e == NULL) continue;
prefix = "";
if(e->loaded !=1) {
prefix += "[BROKEN]";
if(con->engItems[i].flip) prefix+="[F]";
new QListWidgetItem ( prefix+" "+con->engItems[i].ename, &items, i);
} else {
if(con->engItems[i].flip) prefix+="[F]";
new QListWidgetItem ( prefix+" "+e->engName, &items, i);
}
}
}
void ConUnitsWidget::itemsSelected(QListWidgetItem * item){
emit selected(item->type());
}
void ConUnitsWidget::bDelReleased(){
//Game::currentEngLib = englib;
con->deteleSelected();
emit refreshItem();
}
void ConUnitsWidget::bUpReleased(){
//Game::currentEngLib = englib;
con->moveLeftSelected();
emit refreshItem();
}
void ConUnitsWidget::bDownReleased(){
//Game::currentEngLib = englib;
con->moveRightSelected();
emit refreshItem();
}
void ConUnitsWidget::bFlipReleased(){
//Game::currentEngLib = englib;
con->flipSelected();
emit refreshItem();
}