-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_finder.cpp
executable file
·44 lines (36 loc) · 1.33 KB
/
file_finder.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
#include "file_finder.hpp"
FileFinder::FileFinder(std::string label): QWidget(nullptr) {
browseButton = new QPushButton("Browse");
QObject::connect(browseButton, &QPushButton::clicked, this, &FileFinder::browse);
fileBox = new FileCombobox();
fileBox->setEditable(true);
fileBox->setFrame(true);
//fileBox->setSizeAdjustPolicy(FileCombobox::AdjustToContents);
fileBox->setMinimumWidth(150);
QObject::connect(fileBox, &FileCombobox::enterPressed, this, &FileFinder::checkEmpty);
QHBoxLayout *layout = new QHBoxLayout();
layout->addWidget(new QLabel(QString::fromStdString(label + ":")));
layout->addWidget(fileBox, Qt::AlignLeft);
layout->addWidget(browseButton);
setLayout(layout);
}
QString FileFinder::currentText() {
return fileBox->currentText();
}
void FileFinder::browse() {
QString fileName = QFileDialog::getOpenFileName(nullptr, "Open File", QDir::homePath());
if (!fileName.isEmpty()) {
if (fileBox->findText(fileName) == -1)
fileBox->addItem(fileName);
fileBox->setCurrentIndex(fileBox->findText(fileName));
emit contentChanged();
}
}
void FileFinder::checkEmpty() {
if(fileBox->currentText().isEmpty())
return;
emit contentChanged();
}
void FileFinder::setText(QString text) {
fileBox->setEditText(text);
}