summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-03-28 09:23:03 +0200
committerLiang Qi <liang.qi@qt.io>2017-03-28 09:28:31 +0200
commitb48a13fd6843e12b5725aa3ff0d010007e7c43b4 (patch)
tree316cfe36fc67906efcd92ff806c7c0da56ed4f8e /tests/auto/widgets
parent3398d9d40cb0dae2dc2a1a4f7dc3b4b9cceae903 (diff)
parent15fe60cfdada84ea519f08e905d59cc3fb6d20cd (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts: examples/examples.pro tests/auto/corelib/tools/qchar/tst_qchar.cpp tests/auto/other/qaccessibility/accessiblewidgets.h Change-Id: I426696c40ab57d14dc295b8103152cede79f244c
Diffstat (limited to 'tests/auto/widgets')
-rw-r--r--tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp53
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp28
-rw-r--r--tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp3
-rw-r--r--tests/auto/widgets/widgets/qtextedit/tst_qtextedit.cpp236
4 files changed, 319 insertions, 1 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/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index cd1df49f8c..5fe0232d90 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -277,6 +277,7 @@ private slots:
#endif
void setLocale();
+ void propagateLocale();
void deleteStyle();
void multipleToplevelFocusCheck();
void setFocus();
@@ -1205,6 +1206,33 @@ void tst_QWidget::setLocale()
QCOMPARE(child2.locale(), QLocale(QLocale::French));
}
+void tst_QWidget::propagateLocale()
+{
+ QWidget parent;
+ parent.setLocale(QLocale::French);
+ // Non-window widget; propagates locale:
+ QWidget *child = new QWidget(&parent);
+ QVERIFY(!child->isWindow());
+ QVERIFY(!child->testAttribute(Qt::WA_WindowPropagation));
+ QCOMPARE(child->locale(), QLocale(QLocale::French));
+ parent.setLocale(QLocale::Italian);
+ QCOMPARE(child->locale(), QLocale(QLocale::Italian));
+ delete child;
+ // Window: doesn't propagate locale:
+ child = new QWidget(&parent, Qt::Window);
+ QVERIFY(child->isWindow());
+ QVERIFY(!child->testAttribute(Qt::WA_WindowPropagation));
+ QCOMPARE(child->locale(), QLocale());
+ parent.setLocale(QLocale::French);
+ QCOMPARE(child->locale(), QLocale());
+ // ... unless we tell it to:
+ child->setAttribute(Qt::WA_WindowPropagation, true);
+ QVERIFY(child->testAttribute(Qt::WA_WindowPropagation));
+ QCOMPARE(child->locale(), QLocale(QLocale::French));
+ parent.setLocale(QLocale::Italian);
+ QCOMPARE(child->locale(), QLocale(QLocale::Italian));
+}
+
void tst_QWidget::visible_setWindowOpacity()
{
QScopedPointer<QWidget> testWidget(new QWidget);
diff --git a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp
index 52d7a39406..ceef88338a 100644
--- a/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp
+++ b/tests/auto/widgets/widgets/qmdiarea/tst_qmdiarea.cpp
@@ -106,7 +106,8 @@ static bool tabBetweenSubWindowsIn(QMdiArea *mdiArea, int tabCount = -1, bool re
}
QMdiSubWindow *subWindow = subWindows.at(reverse ? subWindows.size() -1 - i : i);
if (rubberBand->geometry() != subWindow->geometry()) {
- qWarning("Rubber band has different geometry");
+ qWarning().nospace() << "Rubber band of tab " << i << " has different geometry: "
+ << rubberBand->geometry() << " (sub window: " << subWindow->geometry() << ").";
return false;
}
}
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"