KIO

kfilecustomdialog.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
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(mFileWidget->okButton(), &QPushButton::clicked, q, [this]() {
39  mFileWidget->slotOk();
40  });
41  mFileWidget->cancelButton()->show();
42  q->connect(mFileWidget->cancelButton(), &QPushButton::clicked, q, [this]() {
43  mFileWidget->slotCancel();
44  q->reject();
45  });
46  q->connect(mFileWidget, &KFileWidget::accepted, q, [this] {
47  q->accept();
48  });
49 }
50 
52  : QDialog(parent)
53  , d(new KFileCustomDialogPrivate(this))
54 {
55  d->init(QUrl());
56 }
57 
59  : QDialog(parent)
60  , d(new KFileCustomDialogPrivate(this))
61 {
62  d->init(startDir);
63 }
64 
65 KFileCustomDialog::~KFileCustomDialog() = default;
66 
68 {
69  d->mFileWidget->setUrl(url);
70 }
71 
73 {
74  d->mFileWidget->setCustomWidget(QString(), widget);
75 }
76 
78 {
79  return d->mFileWidget;
80 }
81 
83 {
84  d->mFileWidget->setOperationMode(op);
85 }
86 
87 void KFileCustomDialog::accept()
88 {
89  d->mFileWidget->accept();
91 }
QCA_EXPORT void init()
void clicked(bool checked)
KFileCustomDialog(QWidget *parent=nullptr)
Constructs a custom file dialog.
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
KFileWidget * fileWidget() const
fileWidget
void setOperationMode(KFileWidget::OperationMode op)
Sets the operational mode of the filedialog to Saving, Opening or Other.
This class implement a custom file dialog.
virtual void accept()
void accepted()
Emitted by slotOk() (directly or asynchronously) once everything has been done.
void setUrl(const QUrl &url)
Sets the directory to view.
void setCustomWidget(QWidget *widget)
Set a custom widget that should be added to the file dialog.
void setObjectName(const QString &name)
OperationMode
Defines some default behavior of the filedialog.
Definition: kfilewidget.h:101
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 6 2023 04:00:01 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.