tahoma2d/toonz/sources/toonzqt/lineedit.cpp

58 lines
1.7 KiB
C++
Raw Normal View History

2016-03-19 06:57:51 +13:00
#include "toonzqt/lineedit.h"
#include "toonzqt/dvdialog.h"
#include <QKeyEvent>
using namespace DVGui;
//=============================================================================
// LineEdit
//-----------------------------------------------------------------------------
LineEdit::LineEdit(QWidget *parent, bool forbiddenSpecialChars)
: QLineEdit(parent), m_forbiddenSpecialChars(forbiddenSpecialChars)
{
}
//-----------------------------------------------------------------------------
LineEdit::LineEdit(const QString &contents, QWidget *parent, bool forbiddenSpecialChars)
: QLineEdit(contents, parent), m_isReturnPressed(false), m_forbiddenSpecialChars(forbiddenSpecialChars)
{
}
//-----------------------------------------------------------------------------
void LineEdit::focusInEvent(QFocusEvent *event)
{
m_isReturnPressed = false;
QLineEdit::focusInEvent(event);
emit focusIn();
}
//-----------------------------------------------------------------------------
void LineEdit::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) {
m_isReturnPressed = true;
clearFocus();
return;
} else {
m_isReturnPressed = false;
if (m_forbiddenSpecialChars) {
switch (event->key()) {
CASE Qt::Key_Backslash : __OR Qt::Key_Slash : __OR Qt::Key_Colon : __OR Qt::Key_Asterisk : __OR Qt::Key_Question : __OR Qt::Key_QuoteDbl : __OR Qt::Key_Greater : __OR Qt::Key_Less : __OR Qt::Key_Bar : __OR Qt::Key_Period:
{
2016-04-19 20:43:43 +12:00
DVGui::info(tr("A file name cannot contains any of the following chracters: /\\:*?\"<>|."));
2016-03-19 06:57:51 +13:00
return;
}
default:
QLineEdit::keyPressEvent(event);
}
} else
QLineEdit::keyPressEvent(event);
}
}