aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicktextedit
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@theqtcompany.com>2015-02-04 18:00:53 +0100
committerJ-P Nurmi <jpnurmi@theqtcompany.com>2015-03-05 22:45:19 +0000
commite157fcba9e515e63410d6b96b35c589182a4d5fa (patch)
treec78c668ed33afbf20829cb0132ca9e3df77b85f6 /tests/auto/quick/qquicktextedit
parentb419ca92bef624893fa46559186b207905bc45e0 (diff)
TextEdit: add support for padding
This makes it possible for TextArea to inherit TextEdit, reserve space for the decoration, and set the desired property defaults without having to create dozens of property aliases. [ChangeLog][QtQuick][TextEdit] Added padding, leftPadding, topPadding, rightPadding and bottomPadding properties. Task-number: QTBUG-41559 Change-Id: I4fa22f86e6151524a63b2b862f17bc9d6a713142 Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'tests/auto/quick/qquicktextedit')
-rw-r--r--tests/auto/quick/qquicktextedit/data/padding.qml12
-rw-r--r--tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp80
2 files changed, 92 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicktextedit/data/padding.qml b/tests/auto/quick/qquicktextedit/data/padding.qml
new file mode 100644
index 0000000000..f4852bec8b
--- /dev/null
+++ b/tests/auto/quick/qquicktextedit/data/padding.qml
@@ -0,0 +1,12 @@
+import QtQuick 2.6
+
+TextEdit {
+ width: 200; height: 200
+ text: "Hello Qt"
+
+ padding: 10
+ topPadding: 20
+ leftPadding: 30
+ rightPadding: 40
+ bottomPadding: 50
+}
diff --git a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
index 86f25ace48..256e5b4bd5 100644
--- a/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
+++ b/tests/auto/quick/qquicktextedit/tst_qquicktextedit.cpp
@@ -205,6 +205,8 @@ private slots:
void cursorRectangle_QTBUG_38947();
void textCached_QTBUG_41583();
+ void padding();
+
private:
void simulateKeys(QWindow *window, const QList<Key> &keys);
void simulateKeys(QWindow *window, const QKeySequence &sequence);
@@ -5363,6 +5365,84 @@ void tst_qquicktextedit::textCached_QTBUG_41583()
QVERIFY(!textedit->property("empty").toBool());
}
+void tst_qquicktextedit::padding()
+{
+ QScopedPointer<QQuickView> window(new QQuickView);
+ window->setSource(testFileUrl("padding.qml"));
+ QTRY_COMPARE(window->status(), QQuickView::Ready);
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+ QQuickItem *root = window->rootObject();
+ QVERIFY(root);
+ QQuickTextEdit *obj = qobject_cast<QQuickTextEdit*>(root);
+ QVERIFY(obj != 0);
+
+ qreal cw = obj->contentWidth();
+ qreal ch = obj->contentHeight();
+
+ QVERIFY(cw > 0);
+ QVERIFY(ch > 0);
+
+ QCOMPARE(obj->topPadding(), 20.0);
+ QCOMPARE(obj->leftPadding(), 30.0);
+ QCOMPARE(obj->rightPadding(), 40.0);
+ QCOMPARE(obj->bottomPadding(), 50.0);
+
+ QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding());
+ QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding());
+
+ obj->setTopPadding(2.25);
+ QCOMPARE(obj->topPadding(), 2.25);
+ QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding());
+
+ obj->setLeftPadding(3.75);
+ QCOMPARE(obj->leftPadding(), 3.75);
+ QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding());
+
+ obj->setRightPadding(4.4);
+ QCOMPARE(obj->rightPadding(), 4.4);
+ QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding());
+
+ obj->setBottomPadding(1.11);
+ QCOMPARE(obj->bottomPadding(), 1.11);
+ QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding());
+
+ obj->setText("Qt");
+ QVERIFY(obj->contentWidth() < cw);
+ QCOMPARE(obj->contentHeight(), ch);
+ cw = obj->contentWidth();
+
+ QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding());
+ QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding());
+
+ obj->setFont(QFont("Courier", 96));
+ QVERIFY(obj->contentWidth() > cw);
+ QVERIFY(obj->contentHeight() > ch);
+ cw = obj->contentWidth();
+ ch = obj->contentHeight();
+
+ QCOMPARE(obj->implicitWidth(), cw + obj->leftPadding() + obj->rightPadding());
+ QCOMPARE(obj->implicitHeight(), ch + obj->topPadding() + obj->bottomPadding());
+
+ obj->resetTopPadding();
+ QCOMPARE(obj->topPadding(), 10.0);
+ obj->resetLeftPadding();
+ QCOMPARE(obj->leftPadding(), 10.0);
+ obj->resetRightPadding();
+ QCOMPARE(obj->rightPadding(), 10.0);
+ obj->resetBottomPadding();
+ QCOMPARE(obj->bottomPadding(), 10.0);
+
+ obj->resetPadding();
+ QCOMPARE(obj->padding(), 0.0);
+ QCOMPARE(obj->topPadding(), 0.0);
+ QCOMPARE(obj->leftPadding(), 0.0);
+ QCOMPARE(obj->rightPadding(), 0.0);
+ QCOMPARE(obj->bottomPadding(), 0.0);
+
+ delete root;
+}
+
QTEST_MAIN(tst_qquicktextedit)
#include "tst_qquicktextedit.moc"