1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com> |
4 | Work sponsored by the LiMux project of the city of Munich |
5 | |
6 | SPDX-License-Identifier: LGPL-2.0-only |
7 | */ |
8 | |
9 | #include "kfilecustomdialog.h" |
10 | |
11 | #include <QPushButton> |
12 | #include <QUrl> |
13 | #include <QVBoxLayout> |
14 | |
15 | class KFileCustomDialogPrivate |
16 | { |
17 | public: |
18 | explicit KFileCustomDialogPrivate(KFileCustomDialog *qq) |
19 | : q(qq) |
20 | { |
21 | } |
22 | void init(const QUrl &startDir); |
23 | |
24 | KFileWidget *mFileWidget = nullptr; |
25 | KFileCustomDialog *const q; |
26 | }; |
27 | |
28 | void KFileCustomDialogPrivate::init(const QUrl &startDir) |
29 | { |
30 | QVBoxLayout *mainLayout = new QVBoxLayout(q); |
31 | mainLayout->setObjectName(QStringLiteral("mainlayout" )); |
32 | |
33 | mFileWidget = new KFileWidget(startDir, q); |
34 | mFileWidget->setObjectName(QStringLiteral("filewidget" )); |
35 | mainLayout->addWidget(mFileWidget); |
36 | |
37 | mFileWidget->okButton()->show(); |
38 | q->connect(sender: mFileWidget->okButton(), signal: &QPushButton::clicked, context: q, slot: [this]() { |
39 | mFileWidget->slotOk(); |
40 | }); |
41 | mFileWidget->cancelButton()->show(); |
42 | q->connect(sender: mFileWidget->cancelButton(), signal: &QPushButton::clicked, context: q, slot: [this]() { |
43 | mFileWidget->slotCancel(); |
44 | q->reject(); |
45 | }); |
46 | q->connect(sender: mFileWidget, signal: &KFileWidget::accepted, context: q, slot: [this] { |
47 | q->accept(); |
48 | }); |
49 | } |
50 | |
51 | KFileCustomDialog::KFileCustomDialog(QWidget *parent) |
52 | : QDialog(parent) |
53 | , d(new KFileCustomDialogPrivate(this)) |
54 | { |
55 | d->init(startDir: QUrl()); |
56 | } |
57 | |
58 | KFileCustomDialog::KFileCustomDialog(const QUrl &startDir, QWidget *parent) |
59 | : QDialog(parent) |
60 | , d(new KFileCustomDialogPrivate(this)) |
61 | { |
62 | d->init(startDir); |
63 | } |
64 | |
65 | KFileCustomDialog::~KFileCustomDialog() = default; |
66 | |
67 | void KFileCustomDialog::setUrl(const QUrl &url) |
68 | { |
69 | d->mFileWidget->setUrl(url); |
70 | } |
71 | |
72 | void KFileCustomDialog::setCustomWidget(QWidget *widget) |
73 | { |
74 | d->mFileWidget->setCustomWidget(text: QString(), widget); |
75 | } |
76 | |
77 | KFileWidget *KFileCustomDialog::fileWidget() const |
78 | { |
79 | return d->mFileWidget; |
80 | } |
81 | |
82 | void KFileCustomDialog::setOperationMode(KFileWidget::OperationMode op) |
83 | { |
84 | d->mFileWidget->setOperationMode(op); |
85 | } |
86 | |
87 | void KFileCustomDialog::accept() |
88 | { |
89 | d->mFileWidget->accept(); |
90 | QDialog::accept(); |
91 | } |
92 | |
93 | #include "moc_kfilecustomdialog.cpp" |
94 | |