File indexing completed on 2024-12-15 03:44:59

0001 /*
0002     SPDX-FileCopyrightText: 2017 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: MIT
0005 */
0006 
0007 #include "chartexportdialog.h"
0008 #include "ui_chartexportdialog.h"
0009 
0010 #include <QFileDialog>
0011 
0012 using namespace KUserFeedback::Console;
0013 
0014 ChartExportDialog::ChartExportDialog(QWidget *parent)
0015     : QDialog(parent)
0016     , ui(new Ui::ChartExportDialog)
0017 {
0018     ui->setupUi(this);
0019 
0020     connect(ui->fileEdit, &QLineEdit::textChanged, this, &ChartExportDialog::validate);
0021     connect(ui->fileButton, &QPushButton::clicked, this, &ChartExportDialog::fileButtonClicked);
0022     validate();
0023 }
0024 
0025 ChartExportDialog::~ChartExportDialog() = default;
0026 
0027 ChartExportDialog::Type ChartExportDialog::type() const
0028 {
0029     if (ui->imageButton->isChecked())
0030         return Image;
0031     if (ui->svgButton->isChecked())
0032         return SVG;
0033     if (ui->pdfButton->isChecked())
0034         return PDF;
0035     Q_UNREACHABLE();
0036 }
0037 
0038 QString ChartExportDialog::filename() const
0039 {
0040     return ui->fileEdit->text();
0041 }
0042 
0043 QSize ChartExportDialog::size() const
0044 {
0045     return QSize(ui->width->value(), ui->height->value());
0046 }
0047 
0048 void ChartExportDialog::fileButtonClicked()
0049 {
0050     const auto fn = QFileDialog::getSaveFileName(this, tr("Export Chart"));
0051     if (!fn.isEmpty())
0052         ui->fileEdit->setText(fn);
0053 }
0054 
0055 void ChartExportDialog::validate()
0056 {
0057     ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(!ui->fileEdit->text().isEmpty());
0058 }
0059 
0060 #include "moc_chartexportdialog.cpp"