File: pathselection.h

package info (click to toggle)
martchus-qtutilities 6.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 780 kB
  • sloc: cpp: 5,908; xml: 37; sh: 25; ansic: 12; makefile: 12
file content (80 lines) | stat: -rw-r--r-- 1,814 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#ifndef WIDGETS_PATHSELECTION_H
#define WIDGETS_PATHSELECTION_H

#include "../global.h"

#include <QFileDialog>

QT_FORWARD_DECLARE_CLASS(QPushButton)
QT_FORWARD_DECLARE_CLASS(QCompleter)

namespace QtUtilities {

class ClearLineEdit;

class QT_UTILITIES_EXPORT PathSelection : public QWidget {
    Q_OBJECT

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;
    bool eventFilter(QObject *obj, QEvent *event) override;

private Q_SLOTS:
    void showFileDialog();
    void setTexts();

private:
    ClearLineEdit *m_lineEdit;
    QPushButton *m_button;
    QFileDialog *m_customDialog;
    QFileDialog::FileMode m_customMode;
    static QCompleter *s_completer;
};

/*!
 * \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.
 *
 * The default file mode is ignored when a custom file dialog has been
 * specified.
 */
inline void PathSelection::provideCustomFileDialog(QFileDialog *customFileDialog)
{
    m_customDialog = customFileDialog;
}
} // namespace QtUtilities

#endif // WIDGETS_PATHSELECTION_H