2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2016 Eugene Shalygin
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
33 #include "base/path.h"
39 class IFileEditorWithCompletion
;
44 * Widget for editing strings which are paths in filesystem
46 class FileSystemPathEdit
: public QWidget
49 Q_DISABLE_COPY_MOVE(FileSystemPathEdit
)
51 Q_PROPERTY(Mode mode READ mode WRITE setMode
)
52 Q_PROPERTY(Path selectedPath READ selectedPath WRITE setSelectedPath NOTIFY selectedPathChanged
)
53 Q_PROPERTY(QString fileNameFilter READ fileNameFilter WRITE setFileNameFilter
)
54 Q_PROPERTY(QString dialogCaption READ dialogCaption WRITE setDialogCaption
)
56 class FileSystemPathEditPrivate
;
59 ~FileSystemPathEdit() override
;
63 FileOpen
, //!< opening files, shows open file dialog
64 FileSave
, //!< saving files, shows save file dialog
65 DirectoryOpen
, //!< selecting existing directories
66 DirectorySave
, //!< selecting directories for saving
67 ReadOnly
//!< no browse button and no dialog, only validate path and check read permission
72 void setMode(Mode mode
);
74 Path
selectedPath() const;
75 void setSelectedPath(const Path
&val
);
77 QString
fileNameFilter() const;
78 void setFileNameFilter(const QString
&val
);
80 Path
placeholder() const;
81 void setPlaceholder(const Path
&val
);
83 /// The browse button caption is "..." if true, and "Browse" otherwise
84 bool briefBrowseButtonCaption() const;
85 void setBriefBrowseButtonCaption(bool brief
);
87 QString
dialogCaption() const;
88 void setDialogCaption(const QString
&caption
);
90 virtual void clear() = 0;
93 void selectedPathChanged(const Path
&path
);
96 explicit FileSystemPathEdit(Private::IFileEditorWithCompletion
*editor
, QWidget
*parent
);
98 template <class Widget
>
99 Widget
*editWidget() const
101 return static_cast<Widget
*>(editWidgetImpl());
108 Q_DECLARE_PRIVATE(FileSystemPathEdit
)
110 virtual QString
editWidgetText() const = 0;
111 virtual void setEditWidgetText(const QString
&text
) = 0;
113 QWidget
*editWidgetImpl() const;
115 FileSystemPathEditPrivate
*d_ptr
= nullptr;
118 /// Widget which uses QLineEdit for path editing
119 class FileSystemPathLineEdit final
: public FileSystemPathEdit
121 using base
= FileSystemPathEdit
;
122 using WidgetType
= Private::FileLineEdit
;
125 explicit FileSystemPathLineEdit(QWidget
*parent
= nullptr);
127 void clear() override
;
130 QString
editWidgetText() const override
;
131 void setEditWidgetText(const QString
&text
) override
;
134 /// Widget which uses QComboBox for path editing
135 class FileSystemPathComboEdit final
: public FileSystemPathEdit
137 using base
= FileSystemPathEdit
;
138 using WidgetType
= Private::FileComboEdit
;
141 explicit FileSystemPathComboEdit(QWidget
*parent
= nullptr);
143 void clear() override
;
146 Path
item(int index
) const;
147 void addItem(const Path
&path
);
148 void insertItem(int index
, const Path
&path
);
150 int currentIndex() const;
151 void setCurrentIndex(int index
);
153 int maxVisibleItems() const;
154 void setMaxVisibleItems(int maxItems
);
157 QString
editWidgetText() const override
;
158 void setEditWidgetText(const QString
&text
) override
;