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