File indexing completed on 2024-05-19 05:51:01
0001 /* Atelier KDE Printer Host for 3D Printing 0002 Copyright (C) <2017> 0003 Author: Lays Rodrigues - lays.rodrigues@kde.org 0004 Chris Rizzitello - rizzitello@kde.org 0005 This program is free software: you can redistribute it and/or modify 0006 it under the terms of the GNU General Public License as published by 0007 the Free Software Foundation, either version 3 of the License, or 0008 (at your option) any later version. 0009 0010 This program is distributed in the hope that it will be useful, 0011 but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 GNU General Public License for more details. 0014 0015 You should have received a copy of the GNU General Public License 0016 along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 #include "choosefiledialog.h" 0019 #include <KLocalizedString> 0020 #include <QDialogButtonBox> 0021 #include <QLabel> 0022 #include <QListWidget> 0023 #include <QVBoxLayout> 0024 0025 ChooseFileDialog::ChooseFileDialog(QWidget *parent, QList<QUrl> files) 0026 : QDialog(parent) 0027 { 0028 const int padding = 30; 0029 auto listWidget = new QListWidget(this); 0030 listWidget->setMinimumWidth(fontMetrics().height() / 2 * padding); 0031 0032 foreach (const auto &url, files) { 0033 listWidget->addItem(url.toLocalFile()); 0034 } 0035 listWidget->setCurrentRow(0); 0036 connect(listWidget, &QListWidget::currentRowChanged, this, [this, &files](const int t) { m_choosen_file = files.at(t); }); 0037 0038 auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); 0039 connect(buttonBox, &QDialogButtonBox::accepted, this, &ChooseFileDialog::accept); 0040 connect(buttonBox, &QDialogButtonBox::rejected, this, &ChooseFileDialog::reject); 0041 0042 auto layout = new QVBoxLayout; 0043 auto label = new QLabel(i18n("Choose a file to print:"), this); 0044 layout->addWidget(label); 0045 layout->addWidget(listWidget); 0046 layout->addWidget(buttonBox); 0047 setLayout(layout); 0048 } 0049 0050 const QUrl ChooseFileDialog::choosenFile() 0051 { 0052 return m_choosen_file; 0053 }