1 #include "gui/maxlengthtextedit.h"
6 MaxLengthTextEdit::MaxLengthTextEdit(QWidget *parent)
7 : QTextEdit(parent), m_maxLength(-1) {
8 connect(
this, SIGNAL(textChanged()),
this, SLOT(checkLength()));
11 MaxLengthTextEdit::~MaxLengthTextEdit(){
14 int MaxLengthTextEdit::maxLength()
const {
18 void MaxLengthTextEdit::setMaxLength(
int max_length) {
19 m_maxLength = max_length;
22 void MaxLengthTextEdit::checkLength() {
23 QTimer::singleShot(0,
this, SLOT(reallyCheckLength()));
26 void MaxLengthTextEdit::reallyCheckLength() {
27 while (m_maxLength >= 0 && toPlainText().size() > m_maxLength) {
28 textCursor().deletePreviousChar();