File indexing completed on 2024-05-19 04:29:25

0001 /*
0002  *  SPDX-FileCopyrightText: 2015 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef KIS_FILE_NAME_REQUESTER_H
0008 #define KIS_FILE_NAME_REQUESTER_H
0009 
0010 #include "kritawidgets_export.h"
0011 
0012 #include <QWidget>
0013 #include <QString>
0014 #include <QUrl>
0015 #include <KoFileDialog.h>
0016 #include <QValidator>
0017 
0018 
0019 namespace Ui {
0020     class WdgFileNameRequester;
0021 }
0022 
0023 /**
0024  * This represents an editable file name.
0025  * Visual it presents a QLineEdit + a button that pops up
0026  * a file chooser.
0027  *
0028  * Signals are fired when the user changes the text
0029  * or selects a new file via the button/file chooser.
0030  */
0031 class KRITAWIDGETS_EXPORT KisFileNameRequester : public QWidget
0032 {
0033     Q_OBJECT
0034 
0035 public:
0036     explicit KisFileNameRequester(QWidget *parent = 0);
0037     ~KisFileNameRequester() override;
0038 
0039     void setStartDir(const QString &path);
0040     /// Set the name used to store the last-used directory in the settings
0041     void setConfigurationName(const QString &name);
0042 
0043     QString fileName() const;
0044 
0045     void setMode(KoFileDialog::DialogType mode);
0046     KoFileDialog::DialogType mode() const;
0047     void setReadOnlyText(bool readonly);
0048 
0049     /**
0050      * Sets the mime type filters to use, same format as KoFileDialog::setMimeTypeFilters.
0051      * If this is not called, the default list is used, which simply selects all the image
0052      * file formats Krita can load.
0053      */
0054     void setMimeTypeFilters(const QStringList &filterList, QString defaultFilter = QString());
0055 
0056     void setValidator(QValidator *validator);
0057 
0058 public Q_SLOTS:
0059     void slotSelectFile();
0060     void setFileName(const QString &path);
0061 
0062 Q_SIGNALS:
0063     void textChanged(const QString &fileName);
0064     void fileSelected(const QString &fileName);
0065 
0066 private:
0067     QScopedPointer<Ui::WdgFileNameRequester> m_ui;
0068     QString m_basePath;
0069     KoFileDialog::DialogType m_mode;
0070     QStringList m_mime_filter_list;
0071     QString m_mime_default_filter;
0072     QString m_name;
0073 };
0074 
0075 #endif // KIS_FILE_NAME_REQUESTER_H