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
71 void setMode(Mode mode
);
73 Path
selectedPath() const;
74 void setSelectedPath(const Path
&val
);
76 QString
fileNameFilter() const;
77 void setFileNameFilter(const QString
&val
);
79 Path
placeholder() const;
80 void setPlaceholder(const Path
&val
);
82 /// The browse button caption is "..." if true, and "Browse" otherwise
83 bool briefBrowseButtonCaption() const;
84 void setBriefBrowseButtonCaption(bool brief
);
86 QString
dialogCaption() const;
87 void setDialogCaption(const QString
&caption
);
89 virtual void clear() = 0;
92 void selectedPathChanged(const Path
&path
);
95 explicit FileSystemPathEdit(Private::IFileEditorWithCompletion
*editor
, QWidget
*parent
);
97 template <class Widget
>
98 Widget
*editWidget() const
100 return static_cast<Widget
*>(editWidgetImpl());
107 Q_DECLARE_PRIVATE(FileSystemPathEdit
)
109 virtual QString
editWidgetText() const = 0;
110 virtual void setEditWidgetText(const QString
&text
) = 0;
112 QWidget
*editWidgetImpl() const;
114 FileSystemPathEditPrivate
*d_ptr
= nullptr;
117 /// Widget which uses QLineEdit for path editing
118 class FileSystemPathLineEdit final
: public FileSystemPathEdit
120 using base
= FileSystemPathEdit
;
121 using WidgetType
= Private::FileLineEdit
;
124 explicit FileSystemPathLineEdit(QWidget
*parent
= nullptr);
126 void clear() override
;
129 QString
editWidgetText() const override
;
130 void setEditWidgetText(const QString
&text
) override
;
133 /// Widget which uses QComboBox for path editing
134 class FileSystemPathComboEdit final
: public FileSystemPathEdit
136 using base
= FileSystemPathEdit
;
137 using WidgetType
= Private::FileComboEdit
;
140 explicit FileSystemPathComboEdit(QWidget
*parent
= nullptr);
142 void clear() override
;
145 Path
item(int index
) const;
146 void addItem(const Path
&path
);
147 void insertItem(int index
, const Path
&path
);
149 int currentIndex() const;
150 void setCurrentIndex(int index
);
152 int maxVisibleItems() const;
153 void setMaxVisibleItems(int maxItems
);
156 QString
editWidgetText() const override
;
157 void setEditWidgetText(const QString
&text
) override
;