GetFileDialog.cpp
1.45 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
#include <QLabel>
#include <QPushButton>
#include <QDialogButtonBox>
#include <QGridLayout>
#include <QFileDialog>
#include "GetFileDialog.h"
GetFileDialog::GetFileDialog(const QString &openFileMsg, const QString &fileType, QWidget *parent)
: QDialog(parent),
m_fName(QString()),
m_openFileMsg(openFileMsg),
m_fileType(fileType)
{
QLabel *fNameLabel = new QLabel(openFileMsg + " *");
m_fNameLE = new QLineEdit;
m_fNameLE->setEnabled(false);
QPushButton *browseButton = new QPushButton("...");
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
| QDialogButtonBox::Cancel);
QGridLayout *layout = new QGridLayout;
layout->addWidget(fNameLabel, 0, 0);
layout->addWidget(m_fNameLE, 0, 1);
layout->addWidget(browseButton, 0, 2);
layout->addWidget(buttonBox, 1, 0, 1, 3);
setLayout(layout);
connect(browseButton, SIGNAL(clicked()), this, SLOT(setFName()));
connect(buttonBox, SIGNAL(accepted()), this, SLOT(checkForm()));
connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
}
///////////////
// accessors //
///////////////
QString GetFileDialog::getFName() const
{
return m_fName;
}
///////////
// slots //
///////////
void GetFileDialog::setFName()
{
m_fName = QFileDialog::getOpenFileName(this, "Open " + m_openFileMsg, QString(), m_fileType);
m_fNameLE->setText(m_fName);
}
void GetFileDialog::checkForm()
{
m_fName = m_fNameLE->text();
if (!m_fName.isEmpty())
accept();
}