Seamly2D
Code documentation
vfilepropertyeditor.h
Go to the documentation of this file.
1 /************************************************************************
2  **
3  ** @file vfilepropertyeditor.h
4  ** @author hedgeware <internal(at)hedgeware.net>
5  ** @date
6  **
7  ** @brief
8  ** @copyright
9  ** All rights reserved. This program and the accompanying materials
10  ** are made available under the terms of the GNU Lesser General Public License
11  ** (LGPL) version 2.1 which accompanies this distribution, and is available at
12  ** http://www.gnu.org/licenses/lgpl-2.1.html
13  **
14  ** This library is distributed in the hope that it will be useful,
15  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  ** Lesser General Public License for more details.
18  **
19  *************************************************************************/
20 
21 #ifndef VFILEPROPERTYEDITOR_H
22 #define VFILEPROPERTYEDITOR_H
23 
24 #include <qcompilerdetection.h>
25 #include <QLineEdit>
26 #include <QMetaObject>
27 #include <QMimeData>
28 #include <QObject>
29 #include <QString>
30 #include <QStringList>
31 #include <QToolButton>
32 #include <QWidget>
33 #include <QtGlobal>
34 
35 namespace VPE
36 {
37 
38 
39 class VFileEditWidget : public QWidget
40 {
41  Q_OBJECT
42 
43 public:
44  explicit VFileEditWidget(QWidget* parent, bool is_directory = false);
45  virtual ~VFileEditWidget() Q_DECL_OVERRIDE;
46 
47 
48  //! This function returns the file currently set to this editor
49  QString getFile() const;
50 
51  //! Needed for proper event handling
52  virtual bool eventFilter(QObject* obj, QEvent* ev) Q_DECL_OVERRIDE;
53 
54  //! Returns the directory/file setting
55  //! \return True, if a directory dialog is being shown, false if a file dialog
56  bool isDirectory();
57 
58 signals:
59  //! This signal is emitted when the user changed the curret file.
60  //! Actions triggering this signal are either using the file dialog
61  //! to select a new file or changing the file path in the line edit.
62  void dataChangedByUser(const QString &getFile, VFileEditWidget* editor);
63 
64  //! This signal is emitted whenever dataChangedByUser() gets emmitted
65  //! and is connected to the delegate's commitData() signal
66  void commitData(QWidget* editor);
67 
68 
69 public slots:
70  //! Sets the current file, does not check if it is valid
71  //! \param value The new filepath the widget should show
72  //! \param emit_signal If true, this will emit the dataChangedByUser()-signal (if file differs from the current
73  //! file)
74  void setFile(const QString &value, bool emit_signal = false);
75 
76  //! Sets a filter for the file field
77  //! \param dialog_filter The filter used for the File Dialog
78  //! \param filter_list The list of file endings. The filters are being checked using regular expressions
79  void setFilter(const QString& dialog_filter = QString(), const QStringList& filter_list = QStringList());
80 
81  //! Sets whether the property stores a directory or a file
82  void setDirectory(bool dir);
83 
84 private slots:
85  //! This slot gets activated, when the "..." button gets clicked
86  void onToolButtonClicked();
87 
88 protected:
89  virtual void dragEnterEvent(QDragEnterEvent* event) Q_DECL_OVERRIDE;
90  virtual void dragMoveEvent(QDragMoveEvent* event) Q_DECL_OVERRIDE;
91  virtual void dragLeaveEvent(QDragLeaveEvent* event) Q_DECL_OVERRIDE;
92  virtual void dropEvent(QDropEvent* event) Q_DECL_OVERRIDE;
93 
94  //! This function checks the mime data, if it is compatible with the filters
95  virtual bool checkMimeData(const QMimeData* data, QString& file) const;
96 
97  //! This checks, if a file is compatible with the filters
98  virtual bool checkFileFilter(const QString& file) const;
99 
100 
102  QToolButton* ToolButton;
103  QLineEdit* FileLineEdit;
105  QStringList FilterList;
106 
107  //! Specifies whether it is being looked for a directory (true) or a file (false, default)
108  bool Directory;
109 
110 private:
111  Q_DISABLE_COPY(VFileEditWidget)
112 };
113 
114 }
115 
116 #endif // VFILEPROPERTYEDITOR_H
virtual void dragLeaveEvent(QDragLeaveEvent *event) Q_DECL_OVERRIDE
void commitData(QWidget *editor)
This signal is emitted whenever dataChangedByUser() gets emmitted and is connected to the delegate's ...
virtual void dragEnterEvent(QDragEnterEvent *event) Q_DECL_OVERRIDE
void onToolButtonClicked()
This slot gets activated, when the "..." button gets clicked.
virtual ~VFileEditWidget() Q_DECL_OVERRIDE
void setDirectory(bool dir)
Sets whether the property stores a directory or a file.
virtual void dragMoveEvent(QDragMoveEvent *event) Q_DECL_OVERRIDE
VFileEditWidget(QWidget *parent, bool is_directory=false)
virtual bool eventFilter(QObject *obj, QEvent *ev) Q_DECL_OVERRIDE
Needed for proper event handling.
virtual void dropEvent(QDropEvent *event) Q_DECL_OVERRIDE
bool Directory
Specifies whether it is being looked for a directory (true) or a file (false, default)
void setFile(const QString &value, bool emit_signal=false)
Sets the current file, does not check if it is valid.
QString getFile() const
This function returns the file currently set to this editor.
void dataChangedByUser(const QString &getFile, VFileEditWidget *editor)
This signal is emitted when the user changed the curret file. Actions triggering this signal are eith...
virtual bool checkMimeData(const QMimeData *data, QString &file) const
This function checks the mime data, if it is compatible with the filters.
virtual bool checkFileFilter(const QString &file) const
This checks, if a file is compatible with the filters.
void setFilter(const QString &dialog_filter=QString(), const QStringList &filter_list=QStringList())
Sets a filter for the file field.
bool isDirectory()
Returns the directory/file setting.