2022-02-07 15:00:02 +06: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.
|
|
|
|
|
*
|
|
|
|
|
* This file is part of the 86Box distribution.
|
|
|
|
|
*
|
|
|
|
|
* File field widget.
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* Authors: Joakim L. Gilje <jgilje@jgilje.net>
|
|
|
|
|
* Cacodemon345
|
|
|
|
|
*
|
|
|
|
|
* Copyright 2021 Joakim L. Gilje
|
|
|
|
|
* Copyright 2022 Cacodemon345
|
|
|
|
|
*/
|
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-02-03 23:00:39 +06:00
|
|
|
|
2022-11-19 08:49:04 -05:00
|
|
|
connect(ui->label, &QLineEdit::editingFinished, this, [this]() {
|
2022-02-06 00:37:24 +06:00
|
|
|
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_) {
|
2022-01-07 01:58:18 +06:00
|
|
|
fileName = QFileDialog::getSaveFileName(this, QString(), QString(), filter_, &selectedFilter_);
|
2021-11-25 10:20:56 +01:00
|
|
|
} else {
|
2022-01-07 01:58:18 +06:00
|
|
|
fileName = QFileDialog::getOpenFileName(this, QString(), QString(), filter_, &selectedFilter_);
|
2021-11-25 10:20:56 +01:00
|
|
|
}
|
|
|
|
|
|
2022-02-05 01:35:26 +06:00
|
|
|
if (!fileName.isNull()) {
|
|
|
|
|
fileName_ = fileName;
|
|
|
|
|
ui->label->setText(fileName);
|
|
|
|
|
emit fileSelected(fileName);
|
|
|
|
|
}
|
2021-11-25 10:20:56 +01:00
|
|
|
}
|