textedit maxlength, fix charlist status height

This commit is contained in:
Henrique Santiago 2012-04-08 19:10:07 -03:00
parent 9ca09d9849
commit 2f3c83e858
3 changed files with 12 additions and 0 deletions

View File

@ -41,6 +41,7 @@ MainWindow
anchors.right: parent.right anchors.right: parent.right
anchors.bottom: separator.top anchors.bottom: separator.top
margin-bottom: 5 margin-bottom: 5
text-auto-resize: true
HorizontalSeparator HorizontalSeparator
id: separator id: separator

View File

@ -37,6 +37,7 @@ UITextEdit::UITextEdit()
m_alwaysActive = false; m_alwaysActive = false;
m_shiftNavigation = false; m_shiftNavigation = false;
m_multiline = false; m_multiline = false;
m_maxLength = 0;
blinkCursor(); blinkCursor();
} }
@ -281,6 +282,9 @@ void UITextEdit::appendText(std::string text)
boost::replace_all(text, "\r", " "); boost::replace_all(text, "\r", " ");
if(text.length() > 0) { if(text.length() > 0) {
// only add text if textedit can add it
if(m_maxLength > 0 && m_text.length() + text.length() > m_maxLength)
return;
// only ignore text append if it contains invalid characters // only ignore text append if it contains invalid characters
if(m_validCharacters.size() > 0) { if(m_validCharacters.size() > 0) {
@ -306,6 +310,9 @@ void UITextEdit::appendCharacter(char c)
return; return;
if(m_cursorPos >= 0) { if(m_cursorPos >= 0) {
if(m_maxLength > 0 && m_text.length() + 1 > m_maxLength)
return;
if(m_validCharacters.size() > 0 && m_validCharacters.find(c) == std::string::npos) if(m_validCharacters.size() > 0 && m_validCharacters.find(c) == std::string::npos)
return; return;
@ -416,6 +423,8 @@ void UITextEdit::onStyleApply(const std::string& styleName, const OTMLNodePtr& s
setShiftNavigation(node->value<bool>()); setShiftNavigation(node->value<bool>());
else if(node->tag() == "multiline") else if(node->tag() == "multiline")
setMultiline(node->value<bool>()); setMultiline(node->value<bool>());
else if(node->tag() == "max-length")
setMaxLength(node->value<int>());
} }
} }

View File

@ -44,6 +44,7 @@ public:
void setValidCharacters(const std::string validCharacters) { m_validCharacters = validCharacters; } void setValidCharacters(const std::string validCharacters) { m_validCharacters = validCharacters; }
void setShiftNavigation(bool enable) { m_shiftNavigation = enable; } void setShiftNavigation(bool enable) { m_shiftNavigation = enable; }
void setMultiline(bool enable) { m_multiline = enable; } void setMultiline(bool enable) { m_multiline = enable; }
void setMaxLength(uint maxLength) { m_maxLength = maxLength; }
void moveCursor(bool right); void moveCursor(bool right);
void appendText(std::string text); void appendText(std::string text);
@ -84,6 +85,7 @@ private:
bool m_shiftNavigation; bool m_shiftNavigation;
bool m_multiline; bool m_multiline;
std::string m_validCharacters; std::string m_validCharacters;
uint m_maxLength;
std::vector<Rect> m_glyphsCoords; std::vector<Rect> m_glyphsCoords;
std::vector<Rect> m_glyphsTexCoords; std::vector<Rect> m_glyphsTexCoords;