-
Notifications
You must be signed in to change notification settings - Fork 17
/
ActivityServiceWindow.cpp
126 lines (110 loc) · 4.4 KB
/
ActivityServiceWindow.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
/* 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 "ActivityServiceWindow.h"
#include "ActivityServiceProperties.h"
#include "Game.h"
#include "Activity.h"
#include "Route.h"
#include "Service.h"
#include "ActLib.h"
#include "EditFileNameDialog.h"
ActivityServiceWindow::ActivityServiceWindow(QWidget* parent) : QWidget(parent) {
setWindowFlags(Qt::WindowType::Tool);
setWindowTitle(tr("Services"));
serviceProperties = new ActivityServiceProperties(this);
QVBoxLayout *actionListLayout = new QVBoxLayout;
actionListLayout->setContentsMargins(0,0,0,0);
actionListLayout->setSpacing(0);
QPushButton *bNewActionEvent = new QPushButton("New Service");
QObject::connect(bNewActionEvent, SIGNAL(released()),
this, SLOT(bNewServiceSelected()));
QPushButton *bDeleteActionEvent = new QPushButton("Delete");
QObject::connect(bDeleteActionEvent, SIGNAL(released()),
this, SLOT(bDeleteServiceSelected()));
actionListLayout->addWidget(&serviceList);
actionListLayout->addWidget(bNewActionEvent);
actionListLayout->addWidget(bDeleteActionEvent);
QStringList list;
list.append("Name:");
list.append("This:");
list.append("Any:");
serviceList.setFixedWidth(250);
serviceList.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
serviceList.setColumnCount(3);
serviceList.setHeaderLabels(list);
serviceList.setRootIsDecorated(false);
serviceList.header()->resizeSection(0,170);
serviceList.header()->resizeSection(1,30);
serviceList.header()->resizeSection(2,30);
QHBoxLayout *v = new QHBoxLayout;
v->setSpacing(2);
v->setContentsMargins(1,1,1,1);
v->addItem(actionListLayout);
v->addWidget(serviceProperties);
this->setLayout(v);
QObject::connect(&serviceList, SIGNAL(itemClicked(QTreeWidgetItem*, int)),
this, SLOT(serviceListSelected(QTreeWidgetItem*, int)));
}
ActivityServiceWindow::~ActivityServiceWindow() {
}
void ActivityServiceWindow::showServices(Route* r){
if(this->isHidden())
return;
route = r;
serviceProperties->setPaths(route->path);
activity = route->getCurrentActivity();
serviceList.clear();
QList<QTreeWidgetItem *> items;
QStringList list;
for(int i = 0; i < ActLib::jestservice; i++ ){
if(ActLib::Services[i] == NULL)
continue;
//new QListWidgetItem ( route->service[i]->displayName, &serviceList, i );
list.clear();
list.append(ActLib::Services[i]->displayName);
list.append("");
list.append("");
QTreeWidgetItem *item = new QTreeWidgetItem((QTreeWidget*)0, list, i );
item->setCheckState(0, Qt::Unchecked);
item->setCheckState(1, Qt::Unchecked);
if(activity != NULL){
if(activity->isPlayerServiceInUse(ActLib::Services[i]->nameId))
item->setCheckState(0, Qt::Checked);
if(activity->isServiceInUse(ActLib::Services[i]->nameId))
item->setCheckState(1, Qt::Checked);
}
if(ActLib::IsServiceInUse(ActLib::Services[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);
}
serviceList.insertTopLevelItems(0, items);
}
void ActivityServiceWindow::serviceListSelected(QTreeWidgetItem * item, int column){
if(route == NULL)
return;
serviceProperties->showService(ActLib::Services[item->type()]);
}
void ActivityServiceWindow::serviceNameChanged(int id){
}
void ActivityServiceWindow::bNewServiceSelected(){
EditFileNameDialog eWindow;
eWindow.exec();
if(eWindow.isOk && eWindow.name.text().length() > 0){
ActLib::AddService(Game::root + "/routes/" + Game::route + "/services/", eWindow.name.text()+".srv", true);
}
showServices(route);
reloadServicesList();
}
void ActivityServiceWindow::bDeleteServiceSelected(){
}