forked from GokuMK/TSRE5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActivityTrafficWindow.cpp
118 lines (108 loc) · 4.11 KB
/
ActivityTrafficWindow.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
/* 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 "ActivityTrafficWindow.h"
#include "ActivityTrafficProperties.h"
#include "Route.h"
#include "Traffic.h"
#include "Activity.h"
#include "ActLib.h"
#include "Game.h"
#include "EditFileNameDialog.h"
ActivityTrafficWindow::ActivityTrafficWindow(QWidget* parent) : QWidget(parent) {
setWindowFlags(Qt::WindowType::Tool);
setWindowTitle(tr("Traffic"));
trafficProperties = new ActivityTrafficProperties(this);
QVBoxLayout *actionListLayout = new QVBoxLayout;
actionListLayout->setContentsMargins(0,0,0,0);
actionListLayout->setSpacing(0);
QPushButton *bNew = new QPushButton("New Traffic");
QObject::connect(bNew, SIGNAL(released()),
this, SLOT(bNewTrafficSelected()));
QPushButton *bDelete = new QPushButton("Delete");
//QObject::connect(bDelete, SIGNAL(released()),
// this, SLOT(bDeleteTrafficSelected()));
QStringList list;
list.append("Name:");
list.append("This:");
list.append("Any:");
lTraffic.setFixedWidth(250);
lTraffic.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
lTraffic.setColumnCount(3);
lTraffic.setHeaderLabels(list);
lTraffic.setRootIsDecorated(false);
lTraffic.header()->resizeSection(0,170);
lTraffic.header()->resizeSection(1,30);
lTraffic.header()->resizeSection(2,30);
actionListLayout->addWidget(&lTraffic);
actionListLayout->addWidget(bNew);
actionListLayout->addWidget(bDelete);
QHBoxLayout *v = new QHBoxLayout;
v->setSpacing(2);
v->setContentsMargins(1,1,1,1);
v->addItem(actionListLayout);
v->addWidget(trafficProperties);
this->setLayout(v);
QObject::connect(&lTraffic, SIGNAL(itemClicked(QTreeWidgetItem*, int)),
this, SLOT(lTrafficSelected(QTreeWidgetItem*, int)));
}
ActivityTrafficWindow::~ActivityTrafficWindow() {
}
void ActivityTrafficWindow::showTraffic(Route* r){
if(this->isHidden())
return;
route = r;
Activity *activity = route->getCurrentActivity();
//serviceProperties->setPaths(route->path);
//activity = r->s
lTraffic.clear();
QList<QTreeWidgetItem *> items;
QStringList list;
for(int i = 0; i < ActLib::jesttraffic; i++ ){
if(ActLib::Traffics[i] == NULL)
continue;
//new QListWidgetItem ( route->service[i]->displayName, &serviceList, i );
list.clear();
list.append(ActLib::Traffics[i]->nameId);
list.append("");
list.append("");
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0, list, i );
//if(i == 0){
// item->setCheckState(1, Qt::Checked);
//}else{
item->setCheckState(1, Qt::Unchecked);
if(activity != NULL){
if(activity->isTrafficInUse(ActLib::Traffics[i]->nameId))
item->setCheckState(1, Qt::Checked);
}
if(ActLib::IsTrafficInUse(ActLib::Traffics[i]->nameId))
item->setCheckState(2, Qt::Checked);
else
item->setCheckState(2, Qt::Unchecked);
//}
item->setCheckState(2, Qt::Checked);
item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
items.append(item);
}
lTraffic.insertTopLevelItems(0, items);
}
void ActivityTrafficWindow::lTrafficSelected(QTreeWidgetItem *item, int column){
if(route == NULL)
return;
trafficProperties->showTraffic(ActLib::Traffics[item->type()]);
}
void ActivityTrafficWindow::bNewTrafficSelected(){
EditFileNameDialog eWindow;
eWindow.exec();
if(eWindow.isOk && eWindow.name.text().length() > 0){
ActLib::AddTraffic(Game::root + "/routes/" + Game::route + "/traffic/", eWindow.name.text()+".trf", true);
}
showTraffic(route);
reloadTrafficsList();
}