qtutilities/widgets/pathselection.h

81 lines
1.8 KiB
C
Raw Normal View History

2016-04-09 02:32:07 +02:00
#ifndef WIDGETS_PATHSELECTION_H
#define WIDGETS_PATHSELECTION_H
#include "../global.h"
2016-04-09 02:32:07 +02:00
#include <QFileDialog>
QT_FORWARD_DECLARE_CLASS(QPushButton)
QT_FORWARD_DECLARE_CLASS(QCompleter)
namespace QtUtilities {
2016-04-09 02:32:07 +02:00
class ClearLineEdit;
2017-05-01 03:16:25 +02:00
class QT_UTILITIES_EXPORT PathSelection : public QWidget {
2016-04-09 02:32:07 +02:00
Q_OBJECT
2016-04-09 02:32:07 +02:00
public:
explicit PathSelection(QWidget *parent = nullptr);
ClearLineEdit *lineEdit();
const ClearLineEdit *lineEdit() const;
void provideCustomFileMode(QFileDialog::FileMode customFileMode);
void provideCustomFileDialog(QFileDialog *customFileDialog);
protected:
bool event(QEvent *event) override;
2018-10-10 21:12:58 +02:00
bool eventFilter(QObject *obj, QEvent *event) override;
2016-04-09 02:32:07 +02:00
2020-03-08 13:07:31 +01:00
private Q_SLOTS:
2016-04-09 02:32:07 +02:00
void showFileDialog();
void setTexts();
2016-04-09 02:32:07 +02:00
private:
ClearLineEdit *m_lineEdit;
QPushButton *m_button;
QFileDialog *m_customDialog;
QFileDialog::FileMode m_customMode;
static QCompleter *s_completer;
2016-04-09 02:32:07 +02:00
};
/*!
* \brief Returns the line edit with the selected path.
*/
inline ClearLineEdit *PathSelection::lineEdit()
{
return m_lineEdit;
}
/*!
* \brief Returns the line edit with the selected path.
*/
inline const ClearLineEdit *PathSelection::lineEdit() const
{
return m_lineEdit;
}
/*!
* \brief Can be used to provide a custom file mode.
*
* The default file mode is QFileDialog::Directory.
*/
inline void PathSelection::provideCustomFileMode(QFileDialog::FileMode customFileMode)
{
m_customMode = customFileMode;
}
/*!
* \brief Can be used to provide a custom file dialog.
*
2017-05-04 22:46:37 +02:00
* The default file mode is ignored when a custom file dialog has been
* specified.
2016-04-09 02:32:07 +02:00
*/
inline void PathSelection::provideCustomFileDialog(QFileDialog *customFileDialog)
{
m_customDialog = customFileDialog;
}
} // namespace QtUtilities
2016-04-09 02:32:07 +02:00
#endif // WIDGETS_PATHSELECTION_H