Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/filefield.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/dvdialog.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/gutil.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/lineedit.h"
Toshihiro Shimizu 890ddd
#include "tfilepath.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <qhboxlayout></qhboxlayout>
Toshihiro Shimizu 890ddd
#include <qpushbutton></qpushbutton>
Toshihiro Shimizu 890ddd
#include <qfiledialog></qfiledialog>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FileField::BrowserPopupController *FileField::m_browserPopupController = 0;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// FileField
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FileField::FileField(QWidget *parent, QString path, bool readOnly)
Toshihiro Shimizu 890ddd
	: QWidget(parent), m_filters(QStringList()), m_fileMode(QFileDialog::DirectoryOnly), m_lastSelectedPath(path)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	setMaximumHeight(WidgetHeight);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_field = new LineEdit(path);
Toshihiro Shimizu 890ddd
	m_fileBrowseButton = new QPushButton(tr("..."));
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_field->setReadOnly(readOnly);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	m_fileBrowseButton->setMinimumSize(20, WidgetHeight);
Toshihiro Shimizu 890ddd
	m_fileBrowseButton->setObjectName("PushButton_NoPadding");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	QHBoxLayout *mainLayout = new QHBoxLayout();
Toshihiro Shimizu 890ddd
	mainLayout->setMargin(0);
Toshihiro Shimizu 890ddd
	mainLayout->setSpacing(1);
Toshihiro Shimizu 890ddd
	{
Toshihiro Shimizu 890ddd
		mainLayout->addWidget(m_field, 5);
Toshihiro Shimizu 890ddd
		mainLayout->addWidget(m_fileBrowseButton, 1);
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
	setLayout(mainLayout);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	//--- signal-slot connections
Toshihiro Shimizu 890ddd
	if (!readOnly)
Toshihiro Shimizu 890ddd
		connect(m_field, SIGNAL(editingFinished()), SIGNAL(pathChanged()));
Toshihiro Shimizu 890ddd
	connect(m_fileBrowseButton, SIGNAL(pressed()), this, SLOT(browseDirectory()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FileField::setFileMode(const QFileDialog::FileMode &fileMode)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_fileMode = fileMode;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FileField::setFilters(const QStringList &filters)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_filters = filters;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
QString FileField::getPath()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_field->text();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FileField::setPath(const QString &path)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_field->setText(path);
Toshihiro Shimizu 890ddd
	m_lastSelectedPath = path;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FileField::setBrowserPopupController(BrowserPopupController *controller)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	m_browserPopupController = controller;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FileField::BrowserPopupController *FileField::getBrowserPopupController()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	return m_browserPopupController;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void FileField::browseDirectory()
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
	if (!m_fileBrowseButton->hasFocus())
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	QString directory = QString();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!m_browserPopupController)
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	m_browserPopupController->openPopup(m_filters, (m_fileMode == QFileDialog::DirectoryOnly), m_lastSelectedPath);
Toshihiro Shimizu 890ddd
	if (m_browserPopupController->isExecute())
Toshihiro Shimizu 890ddd
		directory = m_browserPopupController->getPath();
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	if (!directory.isEmpty()) {
Toshihiro Shimizu 890ddd
		setPath(directory);
Toshihiro Shimizu 890ddd
		m_lastSelectedPath = directory;
Toshihiro Shimizu 890ddd
		emit pathChanged();
Toshihiro Shimizu 890ddd
		return;
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
}