-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdirectorytab.cpp
More file actions
168 lines (145 loc) · 4.95 KB
/
directorytab.cpp
File metadata and controls
168 lines (145 loc) · 4.95 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
/*
*
Copyright (C) 2016 Gabriele Salvato
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <QFileDialog>
#include <QLabel>
#include <QGridLayout>
#include <QStandardPaths>
#include "directorytab.h"
#include <utility>
/*!
* \brief DirectoryTab::DirectoryTab
* \param parent
*/
DirectoryTab::DirectoryTab(QWidget *parent)
: QWidget(parent)
{
slidesDirEdit.setText(QString(""));
spotsDirEdit.setText(QString(""));
slidesDirEdit.setStyleSheet("background:red;color:white;");
spotsDirEdit.setStyleSheet("background:red;color:white;");
buttonSelectSlidesDir.setText("...");
buttonSelectSpotsDir.setText("...");
connect(&buttonSelectSlidesDir, SIGNAL(clicked()),
this, SLOT(onSelectSlideDir()));
connect(&buttonSelectSpotsDir, SIGNAL(clicked()),
this, SLOT(onSelectSpotDir()));
slidesDirEdit.setReadOnly(true);
spotsDirEdit.setReadOnly(true);
QLabel *slidesPathLabel = new QLabel(tr("Slides folder:"));
QLabel *spotsPathLabel = new QLabel(tr("Spots folder:"));
auto *mainLayout = new QGridLayout;
mainLayout->addWidget(slidesPathLabel, 0, 0, 1, 1);
mainLayout->addWidget(&slidesDirEdit, 0, 1, 1, 3);
mainLayout->addWidget(&buttonSelectSlidesDir, 0, 4, 1, 1);
mainLayout->addWidget(spotsPathLabel, 1, 0, 1, 1);
mainLayout->addWidget(&spotsDirEdit, 1, 1, 1, 3);
mainLayout->addWidget(&buttonSelectSpotsDir, 1, 4, 1, 1);
setLayout(mainLayout);
}
void
DirectoryTab::setSlideDir(const QString& sDir) {
slidesDirEdit.setText(sDir);
QDir slideDir(sDir);
if(slideDir.exists()) {
slidesDirEdit.setStyleSheet(styleSheet());
}
else {
slidesDirEdit.setStyleSheet("background:red;color:white;");
}
}
void
DirectoryTab::setSpotDir(const QString& sDir){
spotsDirEdit.setText(sDir);
QDir spotDir(sDir);
if(spotDir.exists()) {
spotsDirEdit.setStyleSheet(styleSheet());
}
else {
spotsDirEdit.setStyleSheet("background:red;color:white;");
}
}
QString
DirectoryTab::getSlideDir() {
return slidesDirEdit.text();
}
QString
DirectoryTab::getSpotDir(){
return spotsDirEdit.text();
}
void
DirectoryTab::onSelectSlideDir() {
QString sSlideDir = slidesDirEdit.text();
QFileDialog* pGetDirDlg;
QDir slideDir = QDir(sSlideDir);
if(slideDir.exists()) {
pGetDirDlg = new QFileDialog(this, tr("Slide Dir"),
sSlideDir);
}
else {
pGetDirDlg = new QFileDialog(this, tr("Slide Dir"),
QStandardPaths::displayName(QStandardPaths::GenericDataLocation));
}
pGetDirDlg->setOptions(QFileDialog::ShowDirsOnly);
pGetDirDlg->setFileMode(QFileDialog::Directory);
pGetDirDlg->setViewMode(QFileDialog::List);
#ifdef Q_OS_ANDROID
pGetDirDlg->setWindowFlags(Qt::Window);
#endif
if(pGetDirDlg->exec() == QDialog::Accepted)
sSlideDir = pGetDirDlg->directory().absolutePath();
pGetDirDlg->deleteLater();
if(!sSlideDir.endsWith(QString("/"))) sSlideDir+= QString("/");
slidesDirEdit.setText(sSlideDir);
slideDir.setPath(sSlideDir);
if(slideDir.exists()) {
slidesDirEdit.setStyleSheet(styleSheet());
}
else {
slidesDirEdit.setStyleSheet("background:red;color:white;");
}
}
void
DirectoryTab::onSelectSpotDir() {
QString sSpotDir = spotsDirEdit.text();
QFileDialog* pGetDirDlg;
QDir spotDir = QDir(sSpotDir);
if(spotDir.exists()) {
pGetDirDlg = new QFileDialog(this, tr("Spot Dir"),
sSpotDir);
}
else {
pGetDirDlg = new QFileDialog(this, tr("Spot Dir"),
QStandardPaths::displayName(QStandardPaths::GenericDataLocation));
}
pGetDirDlg->setOptions(QFileDialog::ShowDirsOnly);
pGetDirDlg->setFileMode(QFileDialog::Directory);
pGetDirDlg->setViewMode(QFileDialog::List);
#ifdef Q_OS_ANDROID
pGetDirDlg->setWindowFlags(Qt::Window);
#endif
if(pGetDirDlg->exec() == QDialog::Accepted)
sSpotDir = pGetDirDlg->directory().absolutePath();
pGetDirDlg->deleteLater();
if(!sSpotDir.endsWith(QString("/"))) sSpotDir+= QString("/");
spotsDirEdit.setText(sSpotDir);
spotDir.setPath(sSpotDir);
if(spotDir.exists()) {
spotsDirEdit.setStyleSheet(styleSheet());
}
else {
spotsDirEdit.setStyleSheet("background:red;color:white;");
}
}