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
shun_iwasawa 754d45
FileField::FileField(QWidget *parent, QString path, bool readOnly,
shun-iwasawa 42cc64
                     bool doNotBrowseInitialPath, bool codePath)
Shinya Kitaoka 120a6e
    : QWidget(parent)
Shinya Kitaoka 120a6e
    , m_filters(QStringList())
Shinya Kitaoka 120a6e
    , m_fileMode(QFileDialog::DirectoryOnly)
shun-iwasawa 42cc64
    , m_lastSelectedPath(path)
shun-iwasawa 42cc64
    , m_codePath(codePath) {
Shinya Kitaoka 120a6e
  setMaximumHeight(WidgetHeight);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_field            = new LineEdit(path);
Shinya Kitaoka 120a6e
  m_fileBrowseButton = new QPushButton(tr("..."));
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_field->setReadOnly(readOnly);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  m_fileBrowseButton->setMinimumSize(20, WidgetHeight);
Shinya Kitaoka 120a6e
  m_fileBrowseButton->setObjectName("PushButton_NoPadding");
Shinya Kitaoka 120a6e
shun_iwasawa 754d45
  // if the initial text is not path, set the string here and prevent browsing
shun_iwasawa 754d45
  if (doNotBrowseInitialPath) m_descriptionText = path;
shun_iwasawa 754d45
Shinya Kitaoka 120a6e
  QHBoxLayout *mainLayout = new QHBoxLayout();
Shinya Kitaoka 120a6e
  mainLayout->setMargin(0);
Shinya Kitaoka 120a6e
  mainLayout->setSpacing(1);
Shinya Kitaoka 120a6e
  {
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_field, 5);
Shinya Kitaoka 120a6e
    mainLayout->addWidget(m_fileBrowseButton, 1);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  setLayout(mainLayout);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //--- signal-slot connections
Shinya Kitaoka 120a6e
  if (!readOnly)
Shinya Kitaoka 120a6e
    connect(m_field, SIGNAL(editingFinished()), SIGNAL(pathChanged()));
Shinya Kitaoka 120a6e
  connect(m_fileBrowseButton, SIGNAL(pressed()), this, SLOT(browseDirectory()));
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileField::setFileMode(const QFileDialog::FileMode &fileMode) {
Shinya Kitaoka 120a6e
  m_fileMode = fileMode;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileField::setFilters(const QStringList &filters) { m_filters = filters; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
QString FileField::getPath() { return m_field->text(); }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileField::setPath(const QString &path) {
Shinya Kitaoka 120a6e
  m_field->setText(path);
Shinya Kitaoka 120a6e
  m_lastSelectedPath = path;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileField::setBrowserPopupController(BrowserPopupController *controller) {
Shinya Kitaoka 120a6e
  m_browserPopupController = controller;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
FileField::BrowserPopupController *FileField::getBrowserPopupController() {
Shinya Kitaoka 120a6e
  return m_browserPopupController;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void FileField::browseDirectory() {
Shinya Kitaoka 120a6e
  if (!m_fileBrowseButton->hasFocus()) return;
Shinya Kitaoka 120a6e
  QString directory = QString();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!m_browserPopupController) return;
Shinya Kitaoka 120a6e
  m_browserPopupController->openPopup(
Shinya Kitaoka 120a6e
      m_filters, (m_fileMode == QFileDialog::DirectoryOnly),
shun_iwasawa 135173
      (m_lastSelectedPath == m_descriptionText) ? "" : m_lastSelectedPath,
shun_iwasawa 135173
      this);
Shinya Kitaoka 120a6e
  if (m_browserPopupController->isExecute())
shun-iwasawa 42cc64
    directory = m_browserPopupController->getPath(m_codePath);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (!directory.isEmpty()) {
Shinya Kitaoka 120a6e
    setPath(directory);
Shinya Kitaoka 120a6e
    m_lastSelectedPath = directory;
Shinya Kitaoka 120a6e
    emit pathChanged();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}