summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-03-21 19:07:53 +0100
committerLiang Qi <liang.qi@qt.io>2017-03-21 19:07:53 +0100
commit65faf4565595d91996ddec4af25af5e97c7f0317 (patch)
treea7415e90db3fa1e46f638e1c31d2f2b9a5d0ec4a /tests/auto/widgets
parenta9383ef99a29c333a1edd32695ddc29ea0ba805d (diff)
parent26bc4ac5cb56ce8f2d3d10125fa9c6a72140573a (diff)
Merge remote-tracking branch 'origin/5.8' into 5.9
Conflicts: src/plugins/platforms/eglfs/eglfs-plugin.pro Change-Id: Id76cdbb41b7758572a3b8ea4dcb40d49bac968db
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp53
-rw-r--r--tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp236
2 files changed, 289 insertions, 0 deletions
diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
index d241296a6b..f2cf78e8ac 100644
--- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
+++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp
@@ -45,6 +45,7 @@
#include <qpushbutton.h>
#include <qscrollbar.h>
#include <qboxlayout.h>
+#include <qitemdelegate.h>
#include <qlineedit.h>
#include <qscreen.h>
#include <qscopedpointer.h>
@@ -151,6 +152,7 @@ private slots:
void testSelectionModelInSyncWithView();
void testClickToSelect();
void testDialogAsEditor();
+ void QTBUG46785_mouseout_hover_state();
};
class MyAbstractItemDelegate : public QAbstractItemDelegate
@@ -2213,5 +2215,56 @@ void tst_QAbstractItemView::testDialogAsEditor()
QCOMPARE(delegate.result, QDialog::Accepted);
}
+class HoverItemDelegate : public QItemDelegate
+{
+public:
+ HoverItemDelegate()
+ : QItemDelegate()
+ , m_paintedWithoutHover(false)
+ { }
+
+ void paint(QPainter *painter, const QStyleOptionViewItem &opt, const QModelIndex &index) const override
+ {
+ Q_UNUSED(painter);
+
+ if (!(opt.state & QStyle::State_MouseOver)) {
+
+ // We don't want to set m_paintedWithoutHover for any item so check for the item at 0,0
+ if (index.row() == 0 && index.column() == 0) {
+ m_paintedWithoutHover = true;
+ }
+ }
+ }
+
+ mutable bool m_paintedWithoutHover;
+};
+
+void tst_QAbstractItemView::QTBUG46785_mouseout_hover_state()
+{
+ HoverItemDelegate delegate;
+
+ QTableWidget table(5, 5);
+ table.verticalHeader()->hide();
+ table.horizontalHeader()->hide();
+ table.setMouseTracking(true);
+ table.setItemDelegate(&delegate);
+ centerOnScreen(&table);
+ table.show();
+ QVERIFY(QTest::qWaitForWindowActive(&table));
+
+ QModelIndex item = table.model()->index(0, 0);
+ QRect itemRect = table.visualRect(item);
+
+ // Move the mouse into the center of the item at 0,0 to cause a paint event to occur
+ QTest::mouseMove(table.viewport(), itemRect.center());
+ QTest::mouseClick(table.viewport(), Qt::LeftButton, 0, itemRect.center());
+
+ delegate.m_paintedWithoutHover = false;
+
+ QTest::mouseMove(table.viewport(), QPoint(-50, 0));
+
+ QTRY_VERIFY(delegate.m_paintedWithoutHover);
+}
+
QTEST_MAIN(tst_QAbstractItemView)
#include "tst_qabstractitemview.moc"
diff --git a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp
index b9ea310d80..bc94e2a05b 100644
--- a/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp
+++ b/tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp
@@ -46,6 +46,7 @@
#include <qcommonstyle.h>
#include <qlayout.h>
#include <qdir.h>
+#include <qpaintengine.h>
#include <qabstracttextdocumentlayout.h>
#include <qtextdocumentfragment.h>
@@ -60,6 +61,8 @@ typedef QPair<Qt::Key, Qt::KeyboardModifier> keyPairType;
typedef QList<keyPairType> pairListType;
Q_DECLARE_METATYPE(keyPairType);
+Q_DECLARE_METATYPE(QList<QInputMethodEvent::Attribute>);
+
QT_FORWARD_DECLARE_CLASS(QTextEdit)
class tst_QTextEdit : public QObject
@@ -200,6 +203,9 @@ private slots:
void wheelEvent();
#endif
+ void preeditCharFormat_data();
+ void preeditCharFormat();
+
private:
void createSelection();
int blockCount() const;
@@ -2594,5 +2600,235 @@ void tst_QTextEdit::wheelEvent()
#endif
+namespace {
+ class MyPaintEngine : public QPaintEngine
+ {
+ public:
+ bool begin(QPaintDevice *)
+ {
+ return true;
+ }
+
+ bool end()
+ {
+ return true;
+ }
+
+ void updateState(const QPaintEngineState &)
+ {
+ }
+
+ void drawPixmap(const QRectF &, const QPixmap &, const QRectF &)
+ {
+ }
+
+ void drawTextItem(const QPointF &, const QTextItem &textItem) Q_DECL_OVERRIDE
+ {
+ itemFonts.append(qMakePair(textItem.text(), textItem.font()));
+ }
+
+ Type type() const { return User; }
+
+
+ QList<QPair<QString, QFont> > itemFonts;
+ };
+
+ class MyPaintDevice : public QPaintDevice
+ {
+ public:
+ MyPaintDevice() : m_paintEngine(new MyPaintEngine)
+ {
+ }
+
+
+ QPaintEngine *paintEngine () const
+ {
+ return m_paintEngine;
+ }
+
+ int metric (QPaintDevice::PaintDeviceMetric metric) const {
+ switch (metric) {
+ case QPaintDevice::PdmWidth:
+ case QPaintDevice::PdmHeight:
+ case QPaintDevice::PdmWidthMM:
+ case QPaintDevice::PdmHeightMM:
+ case QPaintDevice::PdmNumColors:
+ return INT_MAX;
+ case QPaintDevice::PdmDepth:
+ return 32;
+ case QPaintDevice::PdmDpiX:
+ case QPaintDevice::PdmDpiY:
+ case QPaintDevice::PdmPhysicalDpiX:
+ case QPaintDevice::PdmPhysicalDpiY:
+ return 72;
+ case QPaintDevice::PdmDevicePixelRatio:
+ case QPaintDevice::PdmDevicePixelRatioScaled:
+ ; // fall through
+ }
+ return 0;
+ }
+
+ MyPaintEngine *m_paintEngine;
+ };
+}
+
+void tst_QTextEdit::preeditCharFormat_data()
+{
+ QTest::addColumn<QList<QInputMethodEvent::Attribute> >("imeAttributes");
+ QTest::addColumn<QStringList>("substrings");
+ QTest::addColumn<QList<bool> >("boldnessList");
+ QTest::addColumn<QList<bool> >("italicnessList");
+ QTest::addColumn<QList<int> >("pointSizeList");
+
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ {
+ QTextCharFormat tcf;
+ tcf.setFontPointSize(13);
+ tcf.setFontItalic(true);
+ attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, 1, 1, tcf));
+ }
+
+ {
+ QTextCharFormat tcf;
+ tcf.setFontPointSize(8);
+ tcf.setFontWeight(QFont::Normal);
+ attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, 4, 2, tcf));
+ }
+
+ QTest::newRow("Two formats, middle, in order")
+ << attributes
+ << (QStringList() << "P" << "r" << "eE" << "di" << "tText")
+ << (QList<bool>() << true << true << true << false << true)
+ << (QList<bool>() << false << true << false << false << false)
+ << (QList<int>() << 20 << 13 << 20 << 8 << 20);
+ }
+
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ {
+ QTextCharFormat tcf;
+ tcf.setFontPointSize(8);
+ tcf.setFontWeight(QFont::Normal);
+ attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, 4, 2, tcf));
+ }
+
+ {
+ QTextCharFormat tcf;
+ tcf.setFontPointSize(13);
+ tcf.setFontItalic(true);
+ attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, 1, 1, tcf));
+ }
+
+ QTest::newRow("Two formats, middle, out of order")
+ << attributes
+ << (QStringList() << "P" << "r" << "eE" << "di" << "tText")
+ << (QList<bool>() << true << true << true << false << true)
+ << (QList<bool>() << false << true << false << false << false)
+ << (QList<int>() << 20 << 13 << 20 << 8 << 20);
+ }
+
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ {
+ QTextCharFormat tcf;
+ tcf.setFontPointSize(13);
+ tcf.setFontItalic(true);
+ attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, 0, 1, tcf));
+ }
+
+ {
+ QTextCharFormat tcf;
+ tcf.setFontPointSize(8);
+ tcf.setFontWeight(QFont::Normal);
+ attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, 4, 2, tcf));
+ }
+
+ QTest::newRow("Two formats, front, in order")
+ << attributes
+ << (QStringList() << "P" << "reE" << "di" << "tText")
+ << (QList<bool>() << true << true << false << true)
+ << (QList<bool>() << true << false << false << false)
+ << (QList<int>() << 13 << 20 << 8 << 20);
+ }
+
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ {
+ QTextCharFormat tcf;
+ tcf.setFontPointSize(8);
+ tcf.setFontWeight(QFont::Normal);
+ attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, 4, 2, tcf));
+ }
+
+ {
+ QTextCharFormat tcf;
+ tcf.setFontPointSize(13);
+ tcf.setFontItalic(true);
+ attributes.append(QInputMethodEvent::Attribute(QInputMethodEvent::TextFormat, 0, 1, tcf));
+ }
+
+ QTest::newRow("Two formats, front, out of order")
+ << attributes
+ << (QStringList() << "P" << "reE" << "di" << "tText")
+ << (QList<bool>() << true << true << false << true)
+ << (QList<bool>() << true << false << false << false)
+ << (QList<int>() << 13 << 20 << 8 << 20);
+ }
+}
+
+void tst_QTextEdit::preeditCharFormat()
+{
+ QFETCH(QList<QInputMethodEvent::Attribute>, imeAttributes);
+ QFETCH(QStringList, substrings);
+ QFETCH(QList<bool>, boldnessList);
+ QFETCH(QList<bool>, italicnessList);
+ QFETCH(QList<int>, pointSizeList);
+
+ QTextEdit *w = new QTextEdit;
+ w->show();
+ QVERIFY(QTest::qWaitForWindowExposed(w));
+
+ // Set main char format
+ {
+ QTextCharFormat tcf;
+ tcf.setFontPointSize(20);
+ tcf.setFontWeight(QFont::Bold);
+ w->mergeCurrentCharFormat(tcf);
+ }
+
+ QList<QInputMethodEvent::Attribute> attributes;
+ attributes.prepend(QInputMethodEvent::Attribute(QInputMethodEvent::Cursor,
+ w->textCursor().position(),
+ 0,
+ QVariant()));
+
+ attributes += imeAttributes;
+
+ QInputMethodEvent event("PreEditText", attributes);
+ QApplication::sendEvent(w, &event);
+
+ MyPaintDevice device;
+ {
+ QPainter p(&device);
+ w->document()->drawContents(&p);
+ }
+
+ QCOMPARE(device.m_paintEngine->itemFonts.size(), substrings.size());
+ for (int i = 0; i < substrings.size(); ++i)
+ QCOMPARE(device.m_paintEngine->itemFonts.at(i).first, substrings.at(i));
+
+ for (int i = 0; i < substrings.size(); ++i)
+ QCOMPARE(device.m_paintEngine->itemFonts.at(i).second.bold(), boldnessList.at(i));
+
+ for (int i = 0; i < substrings.size(); ++i)
+ QCOMPARE(device.m_paintEngine->itemFonts.at(i).second.italic(), italicnessList.at(i));
+
+ for (int i = 0; i < substrings.size(); ++i)
+ QCOMPARE(device.m_paintEngine->itemFonts.at(i).second.pointSize(), pointSizeList.at(i));
+
+ delete w;
+}
+
QTEST_MAIN(tst_QTextEdit)
#include "tst_qtextedit.moc"