-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChooseDirWindow.cpp
More file actions
104 lines (83 loc) · 2.48 KB
/
ChooseDirWindow.cpp
File metadata and controls
104 lines (83 loc) · 2.48 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
#include "ChooseDirWindow.h"
ChooseDirWindow::ChooseDirWindow(QWidget *parent) : FileManager(parent)
{
ui->mainSplitter->widget(2)->deleteLater();
delete previewWidget;
previewWidget = nullptr;
ui->mainSplitter->setSizes({300, 7000});
delete ui->copyButton;
ui->copyButton = nullptr;
delete ui->moveButton;
ui->moveButton = nullptr;
delete ui->deleteButton;
ui->deleteButton = nullptr;
delete ui->horizontalLayout;
ui->horizontalLayout = nullptr;
window()->setWindowFlags(Qt::Dialog);
actionsWidget = new QWidget();
actionsLayout = new QHBoxLayout(actionsWidget);
folderNameEdit = new QLineEdit(this);
openBtn = new QPushButton(this);
openBtn->setText("Выбрать");
actionsLayout->addWidget(folderNameEdit);
actionsLayout->addWidget(openBtn);
ui->contentLayout->addWidget(actionsWidget);
connect(ui->listView, &QListView::clicked, this, [=](const QModelIndex &index)
{
QString fullPath = index.data(Qt::UserRole + 2).toString();
QFileInfo fileInfo(fullPath);
if (fileInfo.isDir())
{
folderNameEdit->setText(fileInfo.fileName());
} });
connect(openBtn, &QPushButton::clicked, this, [this]()
{
selectedPath = fileModel->currentPath() + "/" + folderNameEdit->text();
accept(); });
connect(fileModel, &FileModel::pathChanged, this, &ChooseDirWindow::pathChanged);
}
ChooseDirWindow::~ChooseDirWindow()
{
}
int ChooseDirWindow::exec()
{
setWindowModality(Qt::ApplicationModal);
show();
QEventLoop loop;
connect(this, &ChooseDirWindow::accepted, &loop, &QEventLoop::quit);
connect(this, &ChooseDirWindow::rejected, &loop, &QEventLoop::quit);
loop.exec();
return dialogResult; // 1 - accepted, 0 - rejected
}
void ChooseDirWindow::closeEvent(QCloseEvent *event)
{
emit rejected();
QMainWindow::closeEvent(event);
}
void ChooseDirWindow::accept()
{
dialogResult = 1;
emit accepted();
close();
}
void ChooseDirWindow::reject()
{
dialogResult = 0;
emit rejected();
close();
}
QString ChooseDirWindow::chooseDirPath(QWidget *parent, QString dir, QString title)
{
ChooseDirWindow window(parent);
window.fileModel->setPath(dir);
window.window()->setWindowTitle(title);
if (window.exec() == 1)
{
return window.selectedPath;
}
return QString();
}
void ChooseDirWindow::pathChanged(const QString &newPath)
{
folderNameEdit->setText("");
}