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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
/*
* The information in this file is
* Copyright(c) 2007 Ball Aerospace & Technologies Corporation
* and is subject to the terms and conditions of the
* GNU Lesser General Public License Version 2.1
* The license text is available from
* http://www.gnu.org/licenses/lgpl.html
*/
#ifndef FILEBROWSER_H
#define FILEBROWSER_H
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>
class Filename;
/**
* A widget to allow the user to browse for files.
*
* The FileBrowser extends the QWidget class to provide a single QWidget
* capable of performing typical file-browsing tasks. This class associates an
* editable text-entry field with a button which brings up a file selection
* dialog by calling either the QFileDialog::getOpenFileName() method or the
* QFileDialog::getSaveFileName() method. Selecting a file through the file
* selection dialog will populate the text field.
*/
class FileBrowser : public QWidget
{
Q_OBJECT
public:
enum BrowseType
{
File,
Directory
};
/**
* Creates a FileBrowser with no file selected.
*
* @param pParent
* The parent widget.
*/
FileBrowser(QWidget* pParent = NULL);
/**
* Destroys the widget and all child widget items.
*/
~FileBrowser();
/**
* Sets the name of the file.
*
* This method sets the name of the file to be displayed in the FileBrowser.
*
* @param filename
* The name of the file.
*/
void setFilename(const QString& filename);
/**
* Sets the name of the file.
*
* This method sets the name of the file to be displayed in the FileBrowser.
*
* @param filename
* The name of the file.
*/
void setFilename(const Filename& filename);
/**
* Gets the name of the file.
*
* This method gets the name of the file displayed in the FileBrowser.
*
* @return The name of the file.
*/
QString getFilename() const;
/**
* Sets the browse caption.
*
* This method sets the browse caption of the FileBrowser. For more information on browse captions,
* please refer to the QFileDialog::getOpenFileName documentation.
*
* @param caption
* The browse caption.
*/
void setBrowseCaption(const QString& caption);
/**
* Gets the browse caption.
*
* This method gets the browse caption of the FileBrowser. For more information on browse captions,
* please refer to the QFileDialog::getOpenFileName documentation.
*
* @return The browse caption.
*
*/
QString getBrowseCaption() const;
/**
* Sets the browse directory.
*
* This method sets the browse directory of the FileBrowser. For more information on browse directories,
* please refer to the QFileDialog::getOpenFileName documentation.
*
* @param directory
* The browse directory.
*/
void setBrowseDirectory(const QString& directory);
/**
* Gets the browse directory.
*
* This method gets the browse directory of the FileBrowser. For more information on browse directories,
* please refer to the QFileDialog::getOpenFileName documentation.
*
* @return The browse directory.
*/
QString getBrowseDirectory() const;
/**
* Sets the browse file filters.
*
* This method sets the browse file filters of the FileBrowser. For more information on browse file filters,
* please refer to the QFileDialog::getOpenFileName documentation.
*
* @param filters
* The browse file filters.
*/
void setBrowseFileFilters(const QString& filters);
/**
* Gets the browse file filters.
*
* This method gets the browse file filters of the FileBrowser. For more information on browse file filters,
* please refer to the QFileDialog::getOpenFileName documentation.
*
* @return The browse file filters.
*/
QString getBrowseFileFilters() const;
/**
* Sets the file selection dialog to only browse for existing files.
*
* By default if this method is not called, isBrowseExistingFile() returns
* \c true.
*
* @param bExistingFile
* Set this value to \c true to browse only for existing files.
* Set the value to \c false to allow non-existent files to be
* selected.
*
* @see QFileDialog::getOpenFileName(), QFileDialog::getSaveFileName()
*/
void setBrowseExistingFile(bool bExistingFile);
/**
* Queries whether the file selection dialog only browses for existing
* files.
*
* @return Returns \c true if the file selection dialog only browses for
* existing files. Returns \c false if non-existent files can be
* selected. Returns \c true by default if setBrowseExistingFile()
* has not been called on this instance of the file browser.
*
* @see QFileDialog::getOpenFileName(), QFileDialog::getSaveFileName()
*/
bool isBrowseExistingFile() const;
void setBrowseType(BrowseType browseType);
BrowseType getBrowseType() const;
signals:
/**
* This signal is emitted when the filename is changed.
*/
void filenameChanged(const QString& filename);
protected:
/**
* Sends a focus out event if needed based on the current editing status.
*
* @param pObject
* The object prompting the event.
* @param pEvent
* The event invoked by the object.
*
* @return Returns the value returned by the default QWidget
* implementation.
*/
bool eventFilter(QObject* pObject, QEvent* pEvent);
protected slots:
/**
* Calls QFileDialog::getOpenFileName to allow the user to specify a file.
* If no browse directory has been set, then the current file's directory will be used as the initial directory.
*/
void browse();
private:
QLineEdit* mpFileEdit;
QPushButton* mpBrowseButton;
QString mBrowseCaption;
QString mBrowseDirectory;
QString mBrowseFilters;
bool mExistingFile;
BrowseType mBrowseType;
};
#endif
|