aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViacheslav Sobolev <ext-viacheslav.sobolev@nokia.com>2010-08-17 13:06:48 +0300
committerPekka Vuorela <pekka.ta.vuorela@nokia.com>2010-08-23 15:33:26 +0300
commit79ad6d612d1129324c5b16a8c6ee51f194d10409 (patch)
tree4d1167fbda1536b45d2e5ee688600f41f66781aa
parent4372746f10ae8bef687c469646f3feaa9595dfd0 (diff)
Fixes: NB#177305 Left over characters are not right shifting on erasing the characters of input text field
RevBy: Pekka Vuorela Details: also includes unit test
-rw-r--r--src/views/mtexteditview.cpp19
-rw-r--r--tests/ut_mtexteditview/ut_mtexteditview.cpp30
2 files changed, 46 insertions, 3 deletions
diff --git a/src/views/mtexteditview.cpp b/src/views/mtexteditview.cpp
index 7e95cfce..0e2f3b12 100644
--- a/src/views/mtexteditview.cpp
+++ b/src/views/mtexteditview.cpp
@@ -279,14 +279,29 @@ void MTextEditViewPrivate::checkScroll()
} else if (activeDocument()->textWidth() != -1) {
// checking scrolling with respect to size only if the size is set
- if (currentX > (activeDocument()->textWidth() - 2 * activeDocument()->documentMargin()
- + hscroll)) {
+ qreal rightBorder = activeDocument()->textWidth() - 2 * activeDocument()->documentMargin()
+ + hscroll;
+
+ if (currentX > rightBorder) {
// check cursor being after the widget (if the widget size is set)
// FIXME: margins seem to be a bit funny. this avoids having cursor outside
// visible area.
hscroll = currentX - activeDocument()->textWidth()
+ 2 * activeDocument()->documentMargin();
scrolled = true;
+ } else if (hscroll > 0) {
+ // scroll text to the right if
+ // 1) there is text before widget and
+ // 2) there is free space between end of text and right widget's border
+ qreal endX = activeDocument()->idealWidth();
+
+ if (endX < rightBorder) {
+ hscroll -= rightBorder - endX;
+ if (hscroll < 0) {
+ hscroll = 0;
+ }
+ scrolled = true;
+ }
}
}
diff --git a/tests/ut_mtexteditview/ut_mtexteditview.cpp b/tests/ut_mtexteditview/ut_mtexteditview.cpp
index e7c13bec..8cb43ec0 100644
--- a/tests/ut_mtexteditview/ut_mtexteditview.cpp
+++ b/tests/ut_mtexteditview/ut_mtexteditview.cpp
@@ -189,6 +189,9 @@ void Ut_MTextEditView::testMaskedCharacters()
/*
* Bug #150452, The position of text cursor is wrong after
* deleting text with backspace key in the MTextEdit
+ *
+ * Bug #177305, Left over characters are not right shifting
+ * on erasing the characters of input text filed
*/
void Ut_MTextEditView::testUpdateScrollWhenTextChanged()
{
@@ -197,11 +200,14 @@ void Ut_MTextEditView::testUpdateScrollWhenTextChanged()
m_subject = new MTextEditView(m_controller);
m_controller->setView(m_subject);
+ m_controller->resize(200, 80); // set some fixed text size
+
int count = 256;
qreal hscroll = 0;
QKeyEvent bsEvent(QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier, "\b");
QKeyEvent event(QEvent::KeyPress, Qt::Key_X, Qt::NoModifier, "x");
+ // test for bug #150452
QCOMPARE(m_subject->d_ptr->hscroll, qreal(0));
for (int n = 0; n < count; ++n) {
m_controller->keyPressEvent(&event);
@@ -213,12 +219,34 @@ void Ut_MTextEditView::testUpdateScrollWhenTextChanged()
m_controller->keyPressEvent(&bsEvent);
}
QVERIFY(hscroll > m_subject->d_ptr->hscroll);
- QVERIFY(m_subject->d_ptr->hscroll > qreal(1.0));
+ QCOMPARE(m_subject->d_ptr->hscroll, qreal(0));
while (!m_controller->text().isEmpty()) {
m_controller->keyPressEvent(&bsEvent);
}
QCOMPARE(m_subject->d_ptr->hscroll, qreal(0));
+
+ // test for bug #177305
+ for (int n = 0; n < count; ++n) {
+ m_controller->keyPressEvent(&event);
+ }
+ m_controller->setCursorPosition(count - 2);
+ hscroll = m_subject->d_ptr->hscroll;
+ QVERIFY(hscroll > 0);
+
+ for (int n = 0; n < (count / 2); ++n) {
+ m_controller->keyPressEvent(&bsEvent);
+ }
+ QVERIFY(hscroll > m_subject->d_ptr->hscroll);
+ QVERIFY(m_subject->d_ptr->hscroll > qreal(1.0));
+
+ for (int n = 0;
+ (n < count) && (m_subject->d_ptr->hscroll > 0)
+ && !m_controller->text().isEmpty();
+ ++n) {
+ m_controller->keyPressEvent(&bsEvent);
+ }
+ QVERIFY(m_controller->cursorPosition() > 0);
}
void Ut_MTextEditView::testSizeHint()