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 <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
15class KFileCustomDialogPrivate
16{
17public:
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
28void 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
53 , d(new KFileCustomDialogPrivate(this))
54{
55 d->init(QUrl());
56}
57
60 , d(new KFileCustomDialogPrivate(this))
61{
62 d->init(startDir);
63}
64
65KFileCustomDialog::~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
86
87void KFileCustomDialog::accept()
88{
89 d->mFileWidget->accept();
91}
92
93#include "moc_kfilecustomdialog.cpp"
void setUrl(const QUrl &url)
Sets the directory to view.
KFileCustomDialog(QWidget *parent=nullptr)
Constructs a custom file dialog.
KFileWidget * fileWidget() const
fileWidget
void setOperationMode(KFileWidget::OperationMode op)
Sets the operational mode of the filedialog to Saving, Opening or Other.
void setCustomWidget(QWidget *widget)
Set a custom widget that should be added to the file dialog.
File selector widget.
Definition kfilewidget.h:49
void accepted()
Emitted by slotOk() (directly or asynchronously) once everything has been done.
void setOperationMode(OperationMode)
Sets the operational mode of the filedialog to Saving, Opening or Other.
OperationMode
Defines some default behavior of the filedialog.
void clicked(bool checked)
void addWidget(QWidget *widget, int stretch, Qt::Alignment alignment)
QDialog(QWidget *parent, Qt::WindowFlags f)
virtual void accept()
QObject * parent() const const
void setObjectName(QAnyStringView name)
QWidget(QWidget *parent, Qt::WindowFlags f)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:49:37 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.