forked from deltaxrobot/Delta-X-Software
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectManager.cpp
148 lines (119 loc) · 3.74 KB
/
ProjectManager.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
#include "ProjectManager.h"
ProjectManager::ProjectManager(QWidget* parent) : QWidget(parent)
{
this->setStyleSheet("QPushButton{min-width:60px;min-height:20px;}");
SubProject = new QStackedWidget();
}
void ProjectManager::InitTabManager(QTabWidget *tabWidget)
{
twProjectManager = tabWidget;
connect(twProjectManager, SIGNAL(tabBarClicked(int)), this, SLOT(ChangeProjectTab(int)));
connect(twProjectManager, SIGNAL(tabBarDoubleClicked(int)), this, SLOT(ChangeProjectName(int)));
connect(twProjectManager, SIGNAL(tabCloseRequested(int)), this, SLOT(CloseProject(int)));
}
void ProjectManager::InitAddNewTab(QWidget *addNewTab)
{
tabAddNewButton = addNewTab;
if (twProjectManager != NULL)
{
int index = twProjectManager->indexOf(addNewTab);
QTabBar* tb = twProjectManager->tabBar();
tb->tabButton(index, QTabBar::RightSide)->deleteLater();
tb->setTabButton(index, QTabBar::RightSide, 0);
}
}
void ProjectManager::AddNewTab(QWidget* newTab, QStackedWidget* stack)
{
if (newTab == NULL)
{
newTab = new QWidget();
}
int tabID = twProjectManager->count() - 1;
if (stack != NULL)
{
twProjectManager->insertTab(tabID, stack, QString("project " + QString::number(tabID)));
twProjectManager->setCurrentWidget(stack);
stack->addWidget(newTab);
}
else
{
twProjectManager->insertTab(tabID, newTab, QString("project " + QString::number(tabID)));
}
}
void ProjectManager::AddNewTab(QStackedWidget *stack, int id, QString name = "")
{
if (name == "")
{
name = QString("project " + QString::number(id));
}
twProjectManager->insertTab(id, stack, name);
twProjectManager->setCurrentWidget(stack);
}
void ProjectManager::RemoveTab(int tabIndex)
{
}
QString ProjectManager::GetProjectName(int index)
{
return twProjectManager->tabText(index);
}
QString ProjectManager::GetProjectName(QWidget *widget)
{
return GetProjectName(twProjectManager->indexOf(widget));
}
RobotWindow *ProjectManager::GetProject(QString name)
{
foreach(RobotWindow* robot, RobotWindows)
{
if (robot->ProjectName == name)
return robot;
}
return NULL;
}
void ProjectManager::ChangeProjectTab(int index)
{
if (twProjectManager->widget(index) == tabAddNewButton)
{
if (IsNewTabSlotOutside == false)
{
AddNewTab();
}
NewTab_Signal(index);
}
else
{
CurrentRobotWindow = RobotWindows.at(index);
}
}
void ProjectManager::ChangeProjectName(int tabIndex)
{
QString oldTabName = twProjectManager->tabText(tabIndex);
bool ok;
QString newTabName = QInputDialog::getText(this, tr("Change project name"), tr("New name:"), QLineEdit::Normal, oldTabName, &ok);
if (ok && !newTabName.isEmpty())
{
twProjectManager->setTabText(tabIndex, newTabName);
// RobotManagers[tabIndex]->Name = newTabName;
}
}
void ProjectManager::CloseProject(int tabIndex)
{
QString projectName = twProjectManager->tabText(tabIndex);
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, projectName, "Do you want to close this project?",
QMessageBox::Yes|QMessageBox::No);
if (reply == QMessageBox::Yes)
{
twProjectManager->removeTab(tabIndex);
VariableManager::instance().removeVar(QString("project") + QString::number(tabIndex));
delete SoftwareManager::GetInstance()->SoftwareProjectManager->RobotWindows.at(tabIndex);
SoftwareManager::GetInstance()->SoftwareProjectManager->RobotWindows.removeAt(tabIndex);
}
else
{
return;
}
if (tabIndex > 0)
{
twProjectManager->setCurrentIndex(tabIndex - 1);
}
}