Files
86Box/src/qt/qt_filefield.cpp

65 lines
1.6 KiB
C++
Raw Normal View History

2022-02-07 15:00:02 +06:00
/*
2023-01-06 15:36:05 -05:00
* 86Box A hypervisor and IBM PC system emulator that specializes in
* running old operating systems and software designed for IBM
* PC systems and compatibles from 1981 through fairly recent
* system designs based on the PCI bus.
2022-02-07 15:00:02 +06:00
*
2023-01-06 15:36:05 -05:00
* This file is part of the 86Box distribution.
2022-02-07 15:00:02 +06:00
*
2023-01-06 15:36:05 -05:00
* File field widget.
2022-02-07 15:00:02 +06:00
*
*
*
2023-01-06 15:36:05 -05:00
* Authors: Joakim L. Gilje <jgilje@jgilje.net>
2022-02-07 15:00:02 +06:00
* Cacodemon345
*
2023-01-06 15:36:05 -05:00
* Copyright 2021 Joakim L. Gilje
* Copyright 2022 Cacodemon345
2022-02-07 15:00:02 +06:00
*/
2021-11-25 10:20:56 +01:00
#include "qt_filefield.hpp"
#include "ui_qt_filefield.h"
#include <QFileDialog>
2022-11-19 08:49:04 -05:00
FileField::FileField(QWidget *parent)
: QWidget(parent)
, ui(new Ui::FileField)
2021-11-25 10:20:56 +01:00
{
ui->setupUi(this);
2022-11-19 08:49:04 -05:00
connect(ui->label, &QLineEdit::editingFinished, this, [this]() {
fileName_ = ui->label->text();
emit fileSelected(ui->label->text());
});
2022-02-10 01:38:00 +06:00
this->setFixedWidth(this->sizeHint().width() + ui->pushButton->sizeHint().width());
2021-11-25 10:20:56 +01:00
}
FileField::~FileField()
{
delete ui;
}
2022-11-19 08:49:04 -05:00
void
FileField::setFileName(const QString &fileName)
{
2021-11-25 10:20:56 +01:00
fileName_ = fileName;
ui->label->setText(fileName);
}
2022-11-19 08:49:04 -05:00
void
FileField::on_pushButton_clicked()
{
2021-11-25 10:20:56 +01:00
QString fileName;
if (createFile_) {
fileName = QFileDialog::getSaveFileName(this, QString(), QString(), filter_, &selectedFilter_);
2021-11-25 10:20:56 +01:00
} else {
fileName = QFileDialog::getOpenFileName(this, QString(), QString(), filter_, &selectedFilter_);
2021-11-25 10:20:56 +01:00
}
if (!fileName.isNull()) {
fileName_ = fileName;
ui->label->setText(fileName);
emit fileSelected(fileName);
}
2021-11-25 10:20:56 +01:00
}