2016-05-17 03:04:11 +12:00
|
|
|
#pragma once
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
#ifndef FILEFIELD_H
|
|
|
|
#define FILEFIELD_H
|
|
|
|
|
|
|
|
#include "tcommon.h"
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include "tfilepath.h"
|
|
|
|
#include "toonzqt/lineedit.h"
|
|
|
|
|
|
|
|
#undef DVAPI
|
|
|
|
#undef DVVAR
|
|
|
|
#ifdef TOONZQT_EXPORTS
|
|
|
|
#define DVAPI DV_EXPORT_API
|
|
|
|
#define DVVAR DV_EXPORT_VAR
|
|
|
|
#else
|
|
|
|
#define DVAPI DV_IMPORT_API
|
|
|
|
#define DVVAR DV_IMPORT_VAR
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// forward declaration
|
|
|
|
class QPushButton;
|
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
namespace DVGui {
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
//=============================================================================
|
|
|
|
/*! \class DVGui::FileField
|
2016-06-15 18:43:10 +12:00
|
|
|
\brief The FileField class provides an object to manage file
|
|
|
|
browser.
|
|
|
|
|
|
|
|
Inherits \b QWidget.
|
|
|
|
|
|
|
|
The object FileField is composed of two part, a field \b
|
|
|
|
LineEdit and a
|
|
|
|
button \b QPushButton. Click button to open a directory browser
|
|
|
|
popup
|
|
|
|
that is used to choose a directory.
|
|
|
|
You can set in constructor default path.
|
|
|
|
Maximum height object is fixed to \b DVGui::WidgetHeight.
|
|
|
|
By default dialog permit user to select only folder, but using
|
|
|
|
setFileMode()
|
|
|
|
you can indicate what the user may select in the file dialog,
|
|
|
|
folder or file;
|
|
|
|
you can also set file type using setFilters().
|
2016-03-19 06:57:51 +13:00
|
|
|
*/
|
2016-06-15 18:43:10 +12:00
|
|
|
class DVAPI FileField : public QWidget {
|
|
|
|
Q_OBJECT
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
LineEdit *m_field;
|
|
|
|
QStringList m_filters;
|
|
|
|
QFileDialog::FileMode m_fileMode;
|
|
|
|
QString m_windowTitle;
|
2016-10-29 00:05:27 +13:00
|
|
|
QString m_descriptionText; // if the initial text is not path, set the string
|
|
|
|
// here and prevent browsing
|
2018-06-08 17:53:28 +12:00
|
|
|
bool m_codePath;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
protected: // used in the child class for CleanupSettings
|
|
|
|
QPushButton *m_fileBrowseButton;
|
|
|
|
QString m_lastSelectedPath;
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
public:
|
2016-06-15 18:43:10 +12:00
|
|
|
/* N.B. Vedi il commento della classe BrowserPopupController in
|
|
|
|
* filebrowserpopup.cpp*/
|
|
|
|
class BrowserPopupController {
|
|
|
|
public:
|
|
|
|
BrowserPopupController() {}
|
|
|
|
virtual ~BrowserPopupController() {}
|
|
|
|
virtual bool isExecute() { return true; };
|
2018-06-08 17:53:28 +12:00
|
|
|
virtual QString getPath(bool codePath = true) { return QString(); };
|
2017-07-03 18:46:30 +12:00
|
|
|
virtual void openPopup(QStringList, bool, QString,
|
|
|
|
const QWidget * = NULL){};
|
2016-06-15 18:43:10 +12:00
|
|
|
};
|
|
|
|
|
|
|
|
static BrowserPopupController *m_browserPopupController;
|
|
|
|
|
|
|
|
FileField(QWidget *parent = 0, QString path = QString(),
|
2018-06-08 17:53:28 +12:00
|
|
|
bool readOnly = false, bool doNotBrowseInitialPath = false,
|
|
|
|
bool codePath = true);
|
2016-06-15 18:43:10 +12:00
|
|
|
~FileField() {}
|
|
|
|
|
|
|
|
/*! Set what the user may select in the file dialog:
|
|
|
|
\li QFileDialog::DirectoryOnly show only directory.
|
|
|
|
\li QFileDialog::AnyFile, QFileDialog::ExistingFile,
|
|
|
|
QFileDialog::Directory, QFileDialog::ExistingFiles
|
|
|
|
show directory and file. */
|
|
|
|
void setFileMode(const QFileDialog::FileMode &fileMode);
|
|
|
|
/*! Set file type in dialog popup. */
|
|
|
|
void setFilters(const QStringList &filters);
|
|
|
|
void setValidator(const QValidator *v) { m_field->setValidator(v); }
|
|
|
|
QString getPath();
|
|
|
|
void setPath(const QString &path);
|
2020-06-09 16:42:51 +12:00
|
|
|
LineEdit *getField() { return m_field; }
|
2016-06-15 18:43:10 +12:00
|
|
|
|
|
|
|
static void setBrowserPopupController(BrowserPopupController *controller);
|
|
|
|
static BrowserPopupController *getBrowserPopupController();
|
2020-11-09 19:55:47 +13:00
|
|
|
void forceOpenBrowser();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
protected slots:
|
2016-06-15 18:43:10 +12:00
|
|
|
/*! Open a static file dialog popup to browse and choose directories. If a
|
|
|
|
directory is seleceted and choose, set field to this
|
|
|
|
directory. */
|
|
|
|
// reimplemented in the "save in" filefield in CleanupSettings
|
|
|
|
virtual void browseDirectory();
|
2016-03-19 06:57:51 +13:00
|
|
|
|
|
|
|
signals:
|
2016-06-15 18:43:10 +12:00
|
|
|
/*! This signal is emitted when path in field change, or by field edit or by
|
|
|
|
browse popup. */
|
|
|
|
void pathChanged();
|
2016-03-19 06:57:51 +13:00
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2016-06-15 18:43:10 +12:00
|
|
|
} // namespace DVGui
|
2016-03-19 06:57:51 +13:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-06-15 18:43:10 +12:00
|
|
|
#endif // FILEFIELD_H
|