forked from Shazib/CometFTP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
215 lines (166 loc) · 6.62 KB
/
MainWindow.cpp
File metadata and controls
215 lines (166 loc) · 6.62 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
* This is the main class for the application
* It contains all other widgets and manages them
*/
#include "MainWindow.h"
MainWindow::MainWindow(QFrame *parent)
: QFrame(parent)
{
// Initial Setup
max = false;
switched = false;
this->resize(900,500);
move(QApplication::desktop()->availableGeometry(this).center() - rect().center());
int _min=500;
int _max=1500;
animTime=(_min+_max)>>1;
// Load GUI
createGuiComponents();
createMainLayout();
// Load Slots
QObject::connect(btnQuit, SIGNAL(clicked()), this, SLOT(close()));
QObject::connect(btnMax, SIGNAL(clicked()), this, SLOT(maxSize()));
QObject::connect(btnMin, SIGNAL(clicked()), this, SLOT(showMinimized()));
QObject::connect(btnMenu, SIGNAL(clicked()), this, SLOT(aboutClick()));
}
// Setup main GUI components
void MainWindow::createGuiComponents()
{
// Taskbar Buttons
btnQuit = new QPushButton("",this);
btnMin = new QPushButton("", this);
btnMax = new QPushButton("",this);
btnMenu = new QPushButton("", this);
btnMenu->setContentsMargins(QMargins(10,0,0,0));
// Button Naming
btnQuit->setObjectName("btnQuit");
btnMin->setObjectName("btnMin");
btnMax->setObjectName("btnMax");
btnMenu->setObjectName("btnMenu");
// Button Sizes
btnQuit->setMaximumSize(30,26);
btnMax->setMinimumSize(30,26);
btnMin->setMaximumSize(30,26);
btnMenu->setMaximumSize(103,27);
}
// Create the main layout
void MainWindow::createMainLayout()
{
// Setup Layouts
mainLayout = new QVBoxLayout();
topLayout = new QHBoxLayout();
topLeftLayout = new QHBoxLayout();
topMiddleLayout = new QHBoxLayout();
topRightLayout = new QHBoxLayout();
// Create Top Layout
// Adding Buttons to Layout
topRightLayout->addWidget(btnMin);
topRightLayout->addWidget(btnMax);
topRightLayout->addWidget(btnQuit);
topLeftLayout->addWidget(btnMenu);
// Layout spacing
topRightLayout->setContentsMargins(QMargins(0,0,0,0));
topRightLayout->setSpacing(0);
topRightLayout->setAlignment(Qt::AlignRight|Qt::AlignTop);
topLeftLayout->setContentsMargins(QMargins(10,0,0,0));
topLeftLayout->setSpacing(0);
topLeftLayout->setAlignment(Qt::AlignTop);
topLayout->setSpacing(0);
topLayout->setAlignment(Qt::AlignTop);
topLayout->setContentsMargins(QMargins(-1,-1,-1,0));
// Setup Status Area
statusArea = new StatusArea(this);
topMiddleLayout->addWidget(statusArea);
topMiddleLayout->setContentsMargins(4,4,4,0);
topLayout->addLayout(topLeftLayout);
topLayout->addLayout(topMiddleLayout);
topLayout->addLayout(topRightLayout);
topLayout->setMargin(0);
// Create Bottom Layout
// Layouts
bottomLeftLayout = new QHBoxLayout();
bottomRightLayout = new QHBoxLayout();
bottomLayout = new QHBoxLayout();
// Setup Required Widgets
localExplorer = new LocalExplorer();
serverExplorer = new ServerExplorer();
QObject::connect(serverExplorer,SIGNAL(sendCredentials(std::string,std::string,std::string,std::string)),this,SLOT(recieveCredentials(std::string,std::string,std::string,std::string)));
QObject::connect(serverExplorer,SIGNAL(sendDropData(QString,QString,QString,QString)),SLOT(recieveDropData(QString,QString,QString,QString)));
QObject::connect(localExplorer,SIGNAL(sendDropData(QString,QString,QString,QString)),SLOT(recieveDropData(QString,QString,QString,QString)));
bottomLeftLayout->addWidget(localExplorer);
bottomRightLayout->addWidget(serverExplorer);
// Proxy Widgets for Slider
QWidget* localExplorerWidget = new QWidget();
QWidget* serverExplorerWidget = new QWidget();
localExplorerWidget->setLayout(bottomLeftLayout);
serverExplorerWidget->setLayout(bottomRightLayout);
// Main Slider Widget 1
bottomLayout->addWidget(localExplorerWidget);
bottomLayout->addWidget(serverExplorerWidget);
bottomLayout->setContentsMargins(4,0,4,4);
QWidget* explorerSlider = new QWidget();
explorerSlider->setLayout(bottomLayout);
// Empty Frame to Test
//QWidget* temp = new QWidget();
downloadManager = new DownloadManager(this);
QObject::connect(this,SIGNAL(sendCredentials(std::string,std::string,std::string,std::string)),downloadManager,SLOT(receiveCredentials(std::string,std::string,std::string,std::string)));
// Create Bottom Stacked Slider Widget
mainContent = new SlidingStackedWidget(this);
mainContent->addWidget(explorerSlider);
mainContent->addWidget(downloadManager);
mainContent->setSpeed(animTime);
mainContent->setVerticalMode(true);
mainContent->setAnimation(QEasingCurve::OutQuart);
mainLayout->setContentsMargins(0,0,0,0);
mainLayout->addLayout(topLayout,0);
mainLayout->addWidget(mainContent,0,0);
this->setLayout(mainLayout);
QObject::connect(downloadManager, SIGNAL(setProgress(int)), statusArea,SLOT(setProgress(int)));
QObject::connect(downloadManager, SIGNAL(setFileName(QString)),statusArea,SLOT(setFileName(QString)));
QObject::connect(downloadManager, SIGNAL(setNumFiles(int)),statusArea,SLOT(setNumFiles(int)));
QObject::connect(statusArea->cancel,SIGNAL(clicked()),downloadManager,SLOT(receiveCancelClick()));
QObject::connect(statusArea->pause, SIGNAL(clicked()),downloadManager,SLOT(receivePauseClick()));
QObject::connect(downloadManager,SIGNAL(setSpeed(QString)),statusArea,SLOT(setSpeed(QString)));
}
void MainWindow::maxSize()
{
if(!max) {
int a = QApplication::desktop()->screenNumber(this);
resize(QApplication::desktop()->availableGeometry(a).size());
move(QApplication::desktop()->availableGeometry(a).topLeft());
max = true;
} else if (max){
resize(900,500);
move(QApplication::desktop()->availableGeometry(this).center() - rect().center());
max = false;
}
}
// Slots for status area
void MainWindow::switchSlides()
{
if( switched == false){
mainContent->slideInIdx(1,SlidingStackedWidget::BOTTOM2TOP);
switched = true;
} else if (switched == true) {
mainContent->slideInIdx(0,SlidingStackedWidget::BOTTOM2TOP);
switched = false;
}
}
void MainWindow::recieveCredentials(std::string host, std::string user, std::string password, std::string port)
{
qDebug() << "Credentials Recieved";
emit sendCredentials(host,user, password,port);
}
void MainWindow::recieveDropData(QString type, QString source, QString destination, QString sftpType)
{
// Send to downloader
downloadManager->addData(type,source,destination,sftpType);
}
void MainWindow::aboutClick()
{
About* about = new About();
about->show();
}
MainWindow::~MainWindow()
{
}