Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "toonzqt/lineedit.h"
Toshihiro Shimizu 890ddd
#include "toonzqt/dvdialog.h"
Toshihiro Shimizu 890ddd
#include <qkeyevent></qkeyevent>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace DVGui;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//=============================================================================
Toshihiro Shimizu 890ddd
// LineEdit
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
LineEdit::LineEdit(QWidget *parent, bool forbiddenSpecialChars)
Shinya Kitaoka 120a6e
    : QLineEdit(parent), m_forbiddenSpecialChars(forbiddenSpecialChars) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
LineEdit::LineEdit(const QString &contents, QWidget *parent,
Shinya Kitaoka 120a6e
                   bool forbiddenSpecialChars)
Shinya Kitaoka 120a6e
    : QLineEdit(contents, parent)
Shinya Kitaoka 120a6e
    , m_isReturnPressed(false)
Shinya Kitaoka 120a6e
    , m_forbiddenSpecialChars(forbiddenSpecialChars) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LineEdit::focusInEvent(QFocusEvent *event) {
Shinya Kitaoka 120a6e
  m_isReturnPressed = false;
Shinya Kitaoka 120a6e
  QLineEdit::focusInEvent(event);
Shinya Kitaoka 120a6e
  emit focusIn();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void LineEdit::keyPressEvent(QKeyEvent *event) {
Shinya Kitaoka 120a6e
  if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
Shinya Kitaoka 120a6e
    m_isReturnPressed = true;
Jeremy Bullock f3ea7c
    emit returnPressedNow();
Shinya Kitaoka 120a6e
    clearFocus();
Shinya Kitaoka 120a6e
    return;
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    m_isReturnPressed = false;
Shinya Kitaoka 120a6e
    if (m_forbiddenSpecialChars) {
Shinya Kitaoka 120a6e
      switch (event->key()) {
Shinya Kitaoka 120a6e
      case Qt::Key_Backslash:
Shinya Kitaoka 120a6e
      case Qt::Key_Slash:
Shinya Kitaoka 120a6e
      case Qt::Key_Colon:
Shinya Kitaoka 120a6e
      case Qt::Key_Asterisk:
Shinya Kitaoka 120a6e
      case Qt::Key_Question:
Shinya Kitaoka 120a6e
      case Qt::Key_QuoteDbl:
Shinya Kitaoka 120a6e
      case Qt::Key_Greater:
Shinya Kitaoka 120a6e
      case Qt::Key_Less:
Shinya Kitaoka 120a6e
      case Qt::Key_Bar:
Shinya Kitaoka 120a6e
      case Qt::Key_Period:
Shinya Kitaoka 120a6e
        DVGui::info(
Shinya Kitaoka 120a6e
            tr("A file name cannot contains any of the following chracters: "
Shinya Kitaoka 120a6e
               "/\\:*?\"<>|."));
Shinya Kitaoka 120a6e
        return;
Shinya Kitaoka 120a6e
      default:
Shinya Kitaoka 120a6e
        QLineEdit::keyPressEvent(event);
Shinya Kitaoka 120a6e
        break;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      QLineEdit::keyPressEvent(event);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}