Changeset View
Changeset View
Standalone View
Standalone View
src/dialogs/choosefiledialog.cpp
Show All 20 Lines | |||||
21 | #include <QListWidget> | 21 | #include <QListWidget> | ||
22 | #include <QVBoxLayout> | 22 | #include <QVBoxLayout> | ||
23 | #include "choosefiledialog.h" | 23 | #include "choosefiledialog.h" | ||
24 | 24 | | |||
25 | ChooseFileDialog::ChooseFileDialog(QWidget *parent, QList<QUrl> files) : | 25 | ChooseFileDialog::ChooseFileDialog(QWidget *parent, QList<QUrl> files) : | ||
26 | QDialog(parent) | 26 | QDialog(parent) | ||
27 | { | 27 | { | ||
28 | const int padding = 30; | 28 | const int padding = 30; | ||
29 | auto listWigdet = new QListWidget(); | 29 | auto listWidget = new QListWidget(this); | ||
30 | listWigdet->setMinimumWidth(fontMetrics().height() / 2 * padding); | 30 | listWidget->setMinimumWidth(fontMetrics().height() / 2 * padding); | ||
31 | 31 | | |||
32 | foreach (const auto &url, files) { | 32 | foreach (const auto &url, files) { | ||
33 | listWigdet->addItem(url.toLocalFile()); | 33 | listWidget->addItem(url.toLocalFile()); | ||
34 | } | 34 | } | ||
35 | connect(listWigdet, &QListWidget::currentRowChanged, this, [this, &files](const int t) { | 35 | listWidget->setCurrentRow(0); | ||
36 | connect(listWidget, &QListWidget::currentRowChanged, this, [this, &files](const int t) { | ||||
36 | m_choosen_file = files.at(t); | 37 | m_choosen_file = files.at(t); | ||
37 | }); | 38 | }); | ||
38 | 39 | | |||
39 | auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); | 40 | auto buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this); | ||
40 | connect(buttonBox, &QDialogButtonBox::accepted, this, &ChooseFileDialog::accept); | 41 | connect(buttonBox, &QDialogButtonBox::accepted, this, &ChooseFileDialog::accept); | ||
41 | connect(buttonBox, &QDialogButtonBox::rejected, this, &ChooseFileDialog::reject); | 42 | connect(buttonBox, &QDialogButtonBox::rejected, this, &ChooseFileDialog::reject); | ||
42 | 43 | | |||
43 | auto layout = new QVBoxLayout; | 44 | auto layout = new QVBoxLayout; | ||
44 | auto label = new QLabel(i18n("Choose a file to print:")); | 45 | auto label = new QLabel(i18n("Choose a file to print:"), this); | ||
45 | layout->addWidget(label); | 46 | layout->addWidget(label); | ||
46 | layout->addWidget(listWigdet); | 47 | layout->addWidget(listWidget); | ||
47 | layout->addWidget(buttonBox); | 48 | layout->addWidget(buttonBox); | ||
48 | setLayout(layout); | 49 | setLayout(layout); | ||
49 | } | 50 | } | ||
50 | 51 | | |||
51 | const QUrl ChooseFileDialog::choosenFile() | 52 | const QUrl ChooseFileDialog::choosenFile() | ||
52 | { | 53 | { | ||
53 | return m_choosen_file; | 54 | return m_choosen_file; | ||
54 | } | 55 | } |