diff options
Diffstat (limited to 'tests')
42 files changed, 430 insertions, 25 deletions
diff --git a/tests/auto/corelib/json/invalidBinaryData/10.bjson b/tests/auto/corelib/json/invalidBinaryData/10.bjson Binary files differnew file mode 100644 index 0000000000..12b29b7aa5 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/10.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/11.bjson b/tests/auto/corelib/json/invalidBinaryData/11.bjson Binary files differnew file mode 100644 index 0000000000..cf2b612111 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/11.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/12.bjson b/tests/auto/corelib/json/invalidBinaryData/12.bjson Binary files differnew file mode 100644 index 0000000000..9c2403350e --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/12.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/13.bjson b/tests/auto/corelib/json/invalidBinaryData/13.bjson Binary files differnew file mode 100644 index 0000000000..db6308b1fd --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/13.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/14.bjson b/tests/auto/corelib/json/invalidBinaryData/14.bjson Binary files differnew file mode 100644 index 0000000000..347da4572c --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/14.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/15.bjson b/tests/auto/corelib/json/invalidBinaryData/15.bjson Binary files differnew file mode 100644 index 0000000000..c6c5558934 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/15.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/16.bjson b/tests/auto/corelib/json/invalidBinaryData/16.bjson Binary files differnew file mode 100644 index 0000000000..ae8b57446d --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/16.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/17.bjson b/tests/auto/corelib/json/invalidBinaryData/17.bjson Binary files differnew file mode 100644 index 0000000000..32f0cc0e23 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/17.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/18.bjson b/tests/auto/corelib/json/invalidBinaryData/18.bjson Binary files differnew file mode 100644 index 0000000000..50c89169eb --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/18.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/19.bjson b/tests/auto/corelib/json/invalidBinaryData/19.bjson Binary files differnew file mode 100644 index 0000000000..b922212f45 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/19.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/20.bjson b/tests/auto/corelib/json/invalidBinaryData/20.bjson Binary files differnew file mode 100644 index 0000000000..c965a0d294 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/20.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/21.bjson b/tests/auto/corelib/json/invalidBinaryData/21.bjson Binary files differnew file mode 100644 index 0000000000..98165ee40c --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/21.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/22.bjson b/tests/auto/corelib/json/invalidBinaryData/22.bjson Binary files differnew file mode 100644 index 0000000000..151f773a81 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/22.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/23.bjson b/tests/auto/corelib/json/invalidBinaryData/23.bjson Binary files differnew file mode 100644 index 0000000000..6eb5269470 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/23.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/24.bjson b/tests/auto/corelib/json/invalidBinaryData/24.bjson Binary files differnew file mode 100644 index 0000000000..c55a2a3e3b --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/24.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/25.bjson b/tests/auto/corelib/json/invalidBinaryData/25.bjson Binary files differnew file mode 100644 index 0000000000..6c619f2ae1 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/25.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/26.bjson b/tests/auto/corelib/json/invalidBinaryData/26.bjson Binary files differnew file mode 100644 index 0000000000..3bf303215a --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/26.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/27.bjson b/tests/auto/corelib/json/invalidBinaryData/27.bjson Binary files differnew file mode 100644 index 0000000000..d2656c2287 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/27.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/28.bjson b/tests/auto/corelib/json/invalidBinaryData/28.bjson Binary files differnew file mode 100644 index 0000000000..6797cf8c40 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/28.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/29.bjson b/tests/auto/corelib/json/invalidBinaryData/29.bjson Binary files differnew file mode 100644 index 0000000000..0645dfc3b2 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/29.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/30.bjson b/tests/auto/corelib/json/invalidBinaryData/30.bjson Binary files differnew file mode 100644 index 0000000000..f77fe1efd0 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/30.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/31.bjson b/tests/auto/corelib/json/invalidBinaryData/31.bjson Binary files differnew file mode 100644 index 0000000000..d9840b6582 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/31.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/32.bjson b/tests/auto/corelib/json/invalidBinaryData/32.bjson Binary files differnew file mode 100644 index 0000000000..1de4cb829f --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/32.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/33.bjson b/tests/auto/corelib/json/invalidBinaryData/33.bjson Binary files differnew file mode 100644 index 0000000000..532a31dc08 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/33.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/34.bjson b/tests/auto/corelib/json/invalidBinaryData/34.bjson Binary files differnew file mode 100644 index 0000000000..f498558eff --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/34.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/35.bjson b/tests/auto/corelib/json/invalidBinaryData/35.bjson Binary files differnew file mode 100644 index 0000000000..8701210755 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/35.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/36.bjson b/tests/auto/corelib/json/invalidBinaryData/36.bjson Binary files differnew file mode 100644 index 0000000000..ef5864e911 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/36.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/37.bjson b/tests/auto/corelib/json/invalidBinaryData/37.bjson Binary files differnew file mode 100644 index 0000000000..f4dd4ae12f --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/37.bjson diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index 5878d56a47..02f3a1901e 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -93,6 +93,7 @@ private Q_SLOTS: void fromBinary(); void toAndFromBinary_data(); void toAndFromBinary(); + void invalidBinaryData(); void parseNumbers(); void parseStrings(); void parseDuplicateKeys(); @@ -1764,6 +1765,21 @@ void tst_QtJson::toAndFromBinary() QCOMPARE(doc, outdoc); } +void tst_QtJson::invalidBinaryData() +{ + QDir dir(testDataDir + "/invalidBinaryData"); + QFileInfoList files = dir.entryInfoList(); + for (int i = 0; i < files.size(); ++i) { + if (!files.at(i).isFile()) + continue; + QFile file(files.at(i).filePath()); + file.open(QIODevice::ReadOnly); + QByteArray bytes = file.readAll(); + QJsonDocument document = QJsonDocument::fromRawData(bytes.constData(), bytes.size()); + QVERIFY(document.isNull()); + } +} + void tst_QtJson::parseNumbers() { { diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index 8dc6f901e6..8df8c2d3b6 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -162,6 +162,7 @@ private: const QString m_prefix; const QString m_convertFromImage; const QString m_loadFromData; + const QTemporaryDir m_tempDir; }; static bool lenientCompare(const QPixmap &actual, const QPixmap &expected) @@ -209,11 +210,11 @@ void tst_QPixmap::initTestCase() QVERIFY(!m_prefix.isEmpty()); QVERIFY(!m_convertFromImage.isEmpty()); QVERIFY(!m_loadFromData.isEmpty()); + QVERIFY2(m_tempDir.isValid(), qPrintable(m_tempDir.errorString())); } void tst_QPixmap::cleanupTestCase() { - QFile::remove(QLatin1String("temp_image.png")); } void tst_QPixmap::swap() @@ -1455,18 +1456,18 @@ void tst_QPixmap::preserveDepth() void tst_QPixmap::loadAsBitmapOrPixmap() { QImage tmp(10, 10, QImage::Format_RGB32); - tmp.save("temp_image.png"); + tmp.save(m_tempDir.path() + "/temp_image.png"); bool ok; // Check that we can load the pixmap as a pixmap and that it then turns into a pixmap - QPixmap pixmap("temp_image.png"); + QPixmap pixmap(m_tempDir.path() + "/temp_image.png"); QVERIFY(!pixmap.isNull()); QVERIFY(pixmap.depth() > 1); QVERIFY(!pixmap.isQBitmap()); pixmap = QPixmap(); - ok = pixmap.load("temp_image.png"); + ok = pixmap.load(m_tempDir.path() + "/temp_image.png"); QVERIFY(ok); QVERIFY(!pixmap.isNull()); QVERIFY(pixmap.depth() > 1); @@ -1474,20 +1475,20 @@ void tst_QPixmap::loadAsBitmapOrPixmap() //now we can try to load it without an extension pixmap = QPixmap(); - ok = pixmap.load("temp_image"); + ok = pixmap.load(m_tempDir.path() + "/temp_image"); QVERIFY(ok); QVERIFY(!pixmap.isNull()); QVERIFY(pixmap.depth() > 1); QVERIFY(!pixmap.isQBitmap()); // The do the same check for bitmaps.. - QBitmap bitmap("temp_image.png"); + QBitmap bitmap(m_tempDir.path() + "/temp_image.png"); QVERIFY(!bitmap.isNull()); QCOMPARE(bitmap.depth(), 1); QVERIFY(bitmap.isQBitmap()); bitmap = QBitmap(); - ok = bitmap.load("temp_image.png"); + ok = bitmap.load(m_tempDir.path() + "/temp_image.png"); QVERIFY(ok); QVERIFY(!bitmap.isNull()); QCOMPARE(bitmap.depth(), 1); diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index 0d1d0f1ae1..b8af5271ea 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -134,6 +134,7 @@ private slots: void xToCursorForLigatures(); void cursorInNonStopChars(); void nbsp(); + void nbspWithFormat(); void noModificationOfInputString(); void superscriptCrash_qtbug53911(); @@ -2254,5 +2255,41 @@ void tst_QTextLayout::superscriptCrash_qtbug53911() qDeleteAll(textLayouts); } +void tst_QTextLayout::nbspWithFormat() +{ + QString s1 = QLatin1String("ABCDEF "); + QString s2 = QLatin1String("GHI"); + QChar nbsp(QChar::Nbsp); + QString s3 = QLatin1String("JKLMNOPQRSTUVWXYZ"); + + QTextLayout layout; + layout.setText(s1 + s2 + nbsp + s3); + + QTextLayout::FormatRange formatRange; + formatRange.start = s1.length() + s2.length(); + formatRange.length = 1; + formatRange.format.setFontUnderline(true); + + QList<QTextLayout::FormatRange> overrides; + overrides.append(formatRange); + + layout.setAdditionalFormats(overrides); + + layout.beginLayout(); + forever { + QTextLine line = layout.createLine(); + if (!line.isValid()) + break; + line.setLineWidth(1); + } + layout.endLayout(); + + QCOMPARE(layout.lineCount(), 2); + QCOMPARE(layout.lineAt(0).textStart(), 0); + QCOMPARE(layout.lineAt(0).textLength(), s1.length()); + QCOMPARE(layout.lineAt(1).textStart(), s1.length()); + QCOMPARE(layout.lineAt(1).textLength(), s2.length() + 1 + s3.length()); +} + QTEST_MAIN(tst_QTextLayout) #include "tst_qtextlayout.moc" diff --git a/tests/auto/tools/qmakelib/evaltest.cpp b/tests/auto/tools/qmakelib/evaltest.cpp index 4cd335d732..df8736a1b1 100644 --- a/tests/auto/tools/qmakelib/evaltest.cpp +++ b/tests/auto/tools/qmakelib/evaltest.cpp @@ -1120,8 +1120,8 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir) QTest::newRow("$$section(): bad number of arguments") << "VAR = $$section(1, 2) \\\n$$section(1, 2, 3, 4, 5)" << "VAR =" - << "##:1: section(var) section(var, sep, begin, end) requires three or four arguments.\n" - "##:2: section(var) section(var, sep, begin, end) requires three or four arguments." + << "##:1: section(var, sep, begin, end) requires three or four arguments.\n" + "##:2: section(var, sep, begin, end) requires three or four arguments." << true; QTest::newRow("$$find()") diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp index ad7600c784..1acf885285 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -1093,6 +1093,10 @@ static QSet<QString> fileListUnderIndex(const QFileSystemModel *model, const QMo void tst_QFileSystemModel::specialFiles() { +#ifndef Q_OS_UNIX + QSKIP("Not implemented"); +#endif + QFileSystemModel model; model.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); @@ -1101,23 +1105,8 @@ void tst_QFileSystemModel::specialFiles() // as it will always return a valid index for existing files, // even if the file is not visible with the given filter. -#if defined(Q_OS_UNIX) const QModelIndex rootIndex = model.setRootPath(QStringLiteral("/dev/")); const QString testFileName = QStringLiteral("null"); -#elif defined(Q_OS_WIN) - const QModelIndex rootIndex = model.setRootPath(flatDirTestPath); - - const QString testFileName = QStringLiteral("linkSource.lnk"); - - QFile file(flatDirTestPath + QLatin1String("/linkTarget.txt")); - QVERIFY(file.open(QIODevice::WriteOnly)); - file.close(); - QVERIFY(file.link(flatDirTestPath + '/' + testFileName)); -#else - QSKIP("Not implemented"); - QModelIndex rootIndex; - QString testFileName; -#endif QTRY_VERIFY(fileListUnderIndex(&model, rootIndex).contains(testFileName)); diff --git a/tests/auto/widgets/widgets/qlabel/red@2x.png b/tests/auto/widgets/widgets/qlabel/red@2x.png Binary files differnew file mode 100644 index 0000000000..4a843e744f --- /dev/null +++ b/tests/auto/widgets/widgets/qlabel/red@2x.png diff --git a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp index ad971c6b5f..6363d0c673 100644 --- a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp +++ b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp @@ -96,6 +96,9 @@ private Q_SLOTS: void taskQTBUG_7902_contextMenuCrash(); #endif + void taskQTBUG_48157_dprPixmap(); + void taskQTBUG_48157_dprMovie(); + private: QLabel *testWidget; QPointer<Widget> test_box; @@ -541,5 +544,26 @@ void tst_QLabel::taskQTBUG_7902_contextMenuCrash() } #endif +void tst_QLabel::taskQTBUG_48157_dprPixmap() +{ + QLabel label; + QPixmap pixmap; + pixmap.load(QFINDTESTDATA(QStringLiteral("red@2x.png"))); + QCOMPARE(pixmap.devicePixelRatio(), 2.0); + label.setPixmap(pixmap); + QCOMPARE(label.sizeHint(), pixmap.rect().size() / pixmap.devicePixelRatio()); +} + +void tst_QLabel::taskQTBUG_48157_dprMovie() +{ + QLabel label; + QMovie movie; + movie.setFileName(QFINDTESTDATA(QStringLiteral("red@2x.png"))); + movie.start(); + QCOMPARE(movie.currentPixmap().devicePixelRatio(), 2.0); + label.setMovie(&movie); + QCOMPARE(label.sizeHint(), movie.currentPixmap().size() / movie.currentPixmap().devicePixelRatio()); +} + QTEST_MAIN(tst_QLabel) #include "tst_qlabel.moc" diff --git a/tests/manual/qcursor/childwidget/childwidget.pro b/tests/manual/qcursor/childwidget/childwidget.pro new file mode 100644 index 0000000000..9ca41c5b4f --- /dev/null +++ b/tests/manual/qcursor/childwidget/childwidget.pro @@ -0,0 +1,6 @@ +TEMPLATE = app +TARGET = childwidget +INCLUDEPATH += . +QT += widgets + +SOURCES += main.cpp diff --git a/tests/manual/qcursor/childwidget/main.cpp b/tests/manual/qcursor/childwidget/main.cpp new file mode 100644 index 0000000000..4447c87210 --- /dev/null +++ b/tests/manual/qcursor/childwidget/main.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtWidgets> + +class CursorWidget : public QWidget +{ +public: + CursorWidget(QCursor cursor, QColor color) + :m_cursor(cursor) + ,m_color(color) + { + if (cursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(cursor); + } + + void paintEvent(QPaintEvent *e) + { + QPainter p(this); + p.fillRect(e->rect(), m_color); + } + + void mousePressEvent(QMouseEvent *) + { + // Toggle cursor + QCursor newCursor = (cursor().shape() == m_cursor.shape()) ? QCursor() : m_cursor; + if (newCursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(newCursor); + } + +private: + QCursor m_cursor; + QColor m_color; +}; + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + // Test child widgets (one of which is native) with set cursors. + // Click window to toggle cursor. + + CursorWidget w1((QCursor(Qt::SizeVerCursor)), QColor(Qt::blue).darker()); + w1.resize(200, 200); + w1.show(); + + CursorWidget w2((QCursor(Qt::OpenHandCursor)), QColor(Qt::red).darker()); + w2.setParent(&w1); + w2.setGeometry(0, 0, 100, 100); + w2.show(); + + CursorWidget w3((QCursor(Qt::IBeamCursor)), QColor(Qt::green).darker()); + w3.winId(); + w3.setParent(&w1); + w3.setGeometry(100, 100, 100, 100); + w3.show(); + + return app.exec(); +} diff --git a/tests/manual/qcursor/childwindow/childwindow.pro b/tests/manual/qcursor/childwindow/childwindow.pro new file mode 100644 index 0000000000..194536a91a --- /dev/null +++ b/tests/manual/qcursor/childwindow/childwindow.pro @@ -0,0 +1,5 @@ +TEMPLATE = app +TARGET = childwindow +INCLUDEPATH += . + +SOURCES += main.cpp diff --git a/tests/manual/qcursor/childwindow/main.cpp b/tests/manual/qcursor/childwindow/main.cpp new file mode 100644 index 0000000000..5fc293dfcf --- /dev/null +++ b/tests/manual/qcursor/childwindow/main.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtGui> + +class CursorWindow : public QRasterWindow +{ +public: + CursorWindow(QCursor cursor, QColor color) + :m_cursor(cursor) + ,m_color(color) + { + if (cursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(cursor); + } + + void paintEvent(QPaintEvent *e) + { + QPainter p(this); + p.fillRect(e->rect(), m_color); + } + + void mousePressEvent(QMouseEvent *) + { + // Toggle cursor + QCursor newCursor = (cursor().shape() == m_cursor.shape()) ? QCursor() : m_cursor; + if (newCursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(newCursor); + } + +private: + QCursor m_cursor; + QColor m_color; +}; + +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + + // Test child windows with set cursors. Create parent window and + // two child windows. Click window to toggle cursor. + + CursorWindow w1((QCursor(Qt::SizeVerCursor)), QColor(Qt::blue).darker()); + w1.resize(200, 200); + w1.show(); + + CursorWindow w2((QCursor(Qt::OpenHandCursor)), QColor(Qt::red).darker()); + w2.setParent(&w1); + w2.setGeometry(0, 0, 100, 100); + w2.show(); + + CursorWindow w3((QCursor(Qt::IBeamCursor)), QColor(Qt::green).darker()); + w3.setParent(&w1); + w3.setGeometry(100, 100, 100, 100); + w3.show(); + + return app.exec(); +} diff --git a/tests/manual/qcursor/childwindowcontainer/childwindowcontainer.pro b/tests/manual/qcursor/childwindowcontainer/childwindowcontainer.pro new file mode 100644 index 0000000000..2233ce4a63 --- /dev/null +++ b/tests/manual/qcursor/childwindowcontainer/childwindowcontainer.pro @@ -0,0 +1,6 @@ +TEMPLATE = app +TARGET = childwindowcontainer +INCLUDEPATH += . +QT += widgets + +SOURCES += main.cpp diff --git a/tests/manual/qcursor/childwindowcontainer/main.cpp b/tests/manual/qcursor/childwindowcontainer/main.cpp new file mode 100644 index 0000000000..d440133a42 --- /dev/null +++ b/tests/manual/qcursor/childwindowcontainer/main.cpp @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtWidgets> + +class CursorWindow : public QRasterWindow +{ +public: + CursorWindow(QCursor cursor, QColor color) + :m_cursor(cursor) + ,m_color(color) + { + if (cursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(cursor); + } + + void paintEvent(QPaintEvent *e) + { + QPainter p(this); + p.fillRect(e->rect(), m_color); + } + + void mousePressEvent(QMouseEvent *) + { + // Toggle cursor + QCursor newCursor = (cursor().shape() == m_cursor.shape()) ? QCursor() : m_cursor; + if (newCursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(newCursor); + } + +private: + QCursor m_cursor; + QColor m_color; +}; + +class CursorWidget : public QWidget +{ +public: + CursorWidget(QCursor cursor, QColor color) + :m_cursor(cursor) + ,m_color(color) + { + if (cursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(cursor); + } + + void paintEvent(QPaintEvent *e) + { + QPainter p(this); + p.fillRect(e->rect(), m_color); + } + + void mousePressEvent(QMouseEvent *) + { + // Toggle cursor + QCursor newCursor = (cursor().shape() == m_cursor.shape()) ? QCursor() : m_cursor; + if (newCursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(newCursor); + } + +private: + QCursor m_cursor; + QColor m_color; +}; + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + { + // Create top-level windowContainer with window. Setting the cursor + // for the container should set the cursor for the window as well. + // Setting the cursor for the window overrides the cursor for the + // container. The example starts out with a window cursor; click + // to fall back to the container cursor. + CursorWindow *w1 = new CursorWindow(QCursor(Qt::OpenHandCursor), QColor(Qt::red).darker()); + QWidget* container = QWidget::createWindowContainer(w1); + container->resize(200, 200); + container->setCursor(Qt::PointingHandCursor); + container->show(); + } + + { + // Similar to above, but with a top-level QWiget + CursorWidget *w1 = new CursorWidget(QCursor(Qt::IBeamCursor), QColor(Qt::green).darker()); + w1->resize(200, 200); + + CursorWindow *w2 = new CursorWindow(QCursor(Qt::OpenHandCursor), QColor(Qt::red).darker()); + QWidget* container = QWidget::createWindowContainer(w2); + container->winId(); // must make the container native, otherwise setCursor + // sets the cursor on a QWindowContainerClassWindow which + // is outside the QWindow hierarchy (macOS). + container->setParent(w1); + container->setCursor(Qt::PointingHandCursor); + container->setGeometry(0, 0, 100, 100); + + w1->show(); + } + + return app.exec(); +} diff --git a/tests/manual/qcursor/qcursor.pro b/tests/manual/qcursor/qcursor.pro index 0b5c2b1945..c6617b8e89 100644 --- a/tests/manual/qcursor/qcursor.pro +++ b/tests/manual/qcursor/qcursor.pro @@ -1,3 +1,3 @@ TEMPLATE = subdirs -SUBDIRS = allcursors grab_override qcursorhighdpi +SUBDIRS = allcursors childwidget childwindow childwindowcontainer grab_override qcursorhighdpi |