Merge branch 'master' of https://vcs.maemo.org/git/situare
[situare] / src / ui / updatelocation / updatelocationdialog.cpp
index b047149..20e78ad 100644 (file)
    USA.\r
 */\r
 \r
+#include <QApplication>\r
 #include <QCheckBox>\r
 #include <QDebug>\r
 #include <QDialogButtonBox>\r
 #include <QGridLayout>\r
+#include <QKeyEvent>\r
 #include <QLabel>\r
 #include <QPushButton>\r
 #include <QScrollArea>\r
@@ -157,24 +159,14 @@ void UpdateLocationDialog::textChanged()
 {\r
     qDebug() << __PRETTY_FUNCTION__;\r
 \r
-    QString msgText = m_textEdit->toPlainText();\r
+    QString msgText = m_textEdit->toPlainText().toUtf8();\r
 \r
-    if (msgText.length() > MESSAGE_MAX_LENGTH)\r
-    {\r
-        int cursorPos = m_textEdit->textCursor().position();\r
-\r
-        QTextCursor textCursor = m_textEdit->textCursor();\r
-        int removedChars = msgText.length() - MESSAGE_MAX_LENGTH;\r
-        m_textEdit->blockSignals(true);\r
-\r
-        m_textEdit->setText( msgText.left(cursorPos - removedChars) + msgText.mid(cursorPos));\r
-        m_textEdit->blockSignals(false);\r
-\r
-        textCursor.setPosition(cursorPos - removedChars);\r
-        m_textEdit->setTextCursor(textCursor);\r
+    if (msgText.length() > MESSAGE_MAX_LENGTH) {\r
+        QKeyEvent event = QKeyEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier);\r
+        QApplication::sendEvent(m_textEdit, &event);\r
     }\r
 \r
-    m_charCountLabel->setNum(MESSAGE_MAX_LENGTH - m_textEdit->toPlainText().length());\r
+    m_charCountLabel->setNum(MESSAGE_MAX_LENGTH - m_textEdit->toPlainText().toUtf8().length());\r
 }\r
 \r
 void UpdateLocationDialog::textSelectionChanged()\r
@@ -187,4 +179,3 @@ void UpdateLocationDialog::textSelectionChanged()
     }\r
     disconnect(m_textEdit, SIGNAL(selectionChanged()), this, SLOT(textSelectionChanged()));\r
 }\r
-\r