diff options
-rw-r--r-- | examples/widgets/doc/src/imageviewer.qdoc | 21 | ||||
-rw-r--r-- | examples/widgets/widgets/imageviewer/imageviewer.cpp | 68 | ||||
-rw-r--r-- | examples/widgets/widgets/imageviewer/imageviewer.h | 3 | ||||
-rw-r--r-- | examples/widgets/widgets/imageviewer/main.cpp | 12 | ||||
-rw-r--r-- | src/corelib/tools/qcollator_icu.cpp | 11 | ||||
-rw-r--r-- | src/corelib/tools/qcollator_macx.cpp | 9 | ||||
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformopenglcontext.cpp | 1 | ||||
-rw-r--r-- | src/plugins/platforms/windows/qwindowswindow.cpp | 9 | ||||
-rw-r--r-- | tests/auto/corelib/tools/qcollator/tst_qcollator.cpp | 90 |
9 files changed, 182 insertions, 42 deletions
diff --git a/examples/widgets/doc/src/imageviewer.qdoc b/examples/widgets/doc/src/imageviewer.qdoc index 96013e844a..6361e3f35b 100644 --- a/examples/widgets/doc/src/imageviewer.qdoc +++ b/examples/widgets/doc/src/imageviewer.qdoc @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the documentation of the Qt Toolkit. @@ -112,15 +112,19 @@ {ImageViewer}'s appearance. \snippet widgets/imageviewer/imageviewer.cpp 1 - \snippet widgets/imageviewer/imageviewer.cpp 2 - In the \c open() slot, we show a file dialog to the user. The - easiest way to create a QFileDialog is to use the static - convenience functions. QFileDialog::getOpenFileName() returns an - existing file selected by the user. If the user presses \uicontrol - Cancel, QFileDialog returns an empty string. + In the \c open() slot, we show a file dialog to the user. We compile + a list of mime types for use as a filter by querying QImageReader + for the available mime type names. + + We show the file dialog until a valid file name is entered or + the user cancels. + + The function \c loadFile() is used to load the image. + + \snippet widgets/imageviewer/imageviewer.cpp 2 - Unless the file name is a empty string, we check if the file's + In the \c loadFile() function, we check if the file's format is an image format by constructing a QImage which tries to load the image from the file. If the constructor returns a null image, we use a QMessageBox to alert the user. @@ -135,7 +139,6 @@ information message with an \uicontrol OK button (the default) is sufficient, since the message is part of a normal operation. - \snippet widgets/imageviewer/imageviewer.cpp 3 \snippet widgets/imageviewer/imageviewer.cpp 4 If the format is supported, we display the image in \c imageLabel diff --git a/examples/widgets/widgets/imageviewer/imageviewer.cpp b/examples/widgets/widgets/imageviewer/imageviewer.cpp index 77ec92d57a..eae94a2499 100644 --- a/examples/widgets/widgets/imageviewer/imageviewer.cpp +++ b/examples/widgets/widgets/imageviewer/imageviewer.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the examples of the Qt Toolkit. @@ -61,39 +61,61 @@ ImageViewer::ImageViewer() createActions(); createMenus(); - setWindowTitle(tr("Image Viewer")); - resize(500, 400); + resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5); } + //! [0] +//! [2] -//! [1] -void ImageViewer::open() -//! [1] //! [2] +bool ImageViewer::loadFile(const QString &fileName) { - QString fileName = QFileDialog::getOpenFileName(this, - tr("Open File"), QDir::currentPath()); - if (!fileName.isEmpty()) { - QImage image(fileName); - if (image.isNull()) { - QMessageBox::information(this, tr("Image Viewer"), - tr("Cannot load %1.").arg(fileName)); - return; - } + QImage image(fileName); + if (image.isNull()) { + QMessageBox::information(this, QGuiApplication::applicationDisplayName(), + tr("Cannot load %1.").arg(QDir::toNativeSeparators(fileName))); + setWindowFilePath(QString()); + imageLabel->setPixmap(QPixmap()); + imageLabel->adjustSize(); + return false; + } //! [2] //! [3] - imageLabel->setPixmap(QPixmap::fromImage(image)); + imageLabel->setPixmap(QPixmap::fromImage(image)); //! [3] //! [4] - scaleFactor = 1.0; + scaleFactor = 1.0; + + printAct->setEnabled(true); + fitToWindowAct->setEnabled(true); + updateActions(); - printAct->setEnabled(true); - fitToWindowAct->setEnabled(true); - updateActions(); + if (!fitToWindowAct->isChecked()) + imageLabel->adjustSize(); - if (!fitToWindowAct->isChecked()) - imageLabel->adjustSize(); - } + setWindowFilePath(fileName); + return true; } + //! [4] +//! [2] + +//! [1] +void ImageViewer::open() +{ + QStringList mimeTypeFilters; + foreach (const QByteArray &mimeTypeName, QImageReader::supportedMimeTypes()) + mimeTypeFilters.append(mimeTypeName); + mimeTypeFilters.sort(); + const QStringList picturesLocations = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation); + QFileDialog dialog(this, tr("Open File"), + picturesLocations.isEmpty() ? QDir::currentPath() : picturesLocations.first()); + dialog.setAcceptMode(QFileDialog::AcceptOpen); + dialog.setMimeTypeFilters(mimeTypeFilters); + dialog.selectMimeTypeFilter("image/jpeg"); + + while (dialog.exec() == QDialog::Accepted && !loadFile(dialog.selectedFiles().first())) {} +} +//! [1] + //! [5] void ImageViewer::print() //! [5] //! [6] diff --git a/examples/widgets/widgets/imageviewer/imageviewer.h b/examples/widgets/widgets/imageviewer/imageviewer.h index 7a0f0eb845..a4fd82a696 100644 --- a/examples/widgets/widgets/imageviewer/imageviewer.h +++ b/examples/widgets/widgets/imageviewer/imageviewer.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the examples of the Qt Toolkit. @@ -61,6 +61,7 @@ class ImageViewer : public QMainWindow public: ImageViewer(); + bool loadFile(const QString &); private slots: void open(); diff --git a/examples/widgets/widgets/imageviewer/main.cpp b/examples/widgets/widgets/imageviewer/main.cpp index f1697f9e3f..ee66b29591 100644 --- a/examples/widgets/widgets/imageviewer/main.cpp +++ b/examples/widgets/widgets/imageviewer/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the examples of the Qt Toolkit. @@ -39,13 +39,23 @@ ****************************************************************************/ #include <QApplication> +#include <QCommandLineParser> #include "imageviewer.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); + QGuiApplication::setApplicationDisplayName(ImageViewer::tr("Image Viewer")); + QCommandLineParser commandLineParser; + commandLineParser.addHelpOption(); + commandLineParser.addPositionalArgument(ImageViewer::tr("[file]"), ImageViewer::tr("Image file to open.")); + commandLineParser.process(QCoreApplication::arguments()); ImageViewer imageViewer; + if (!commandLineParser.positionalArguments().isEmpty() + && !imageViewer.loadFile(commandLineParser.positionalArguments().front())) { + return -1; + } imageViewer.show(); return app.exec(); } diff --git a/src/corelib/tools/qcollator_icu.cpp b/src/corelib/tools/qcollator_icu.cpp index 407a493d25..23e88b5015 100644 --- a/src/corelib/tools/qcollator_icu.cpp +++ b/src/corelib/tools/qcollator_icu.cpp @@ -75,10 +75,17 @@ void QCollator::setCaseSensitivity(Qt::CaseSensitivity cs) { detach(); - UColAttributeValue val = (cs == Qt::CaseSensitive) ? UCOL_UPPER_FIRST : UCOL_OFF; + // The strength attribute in ICU is rather badly documented. Basically UCOL_PRIMARY + // ignores differences between base characters and accented characters as well as case. + // So A and A-umlaut would compare equal. + // UCOL_SECONDARY ignores case differences. UCOL_TERTIARY is the default in most languages + // and does case sensitive comparison. + // UCOL_QUATERNARY is used as default in a few languages such as Japanese to take care of some + // additional differences in those languages. + UColAttributeValue val = (cs == Qt::CaseSensitive) ? UCOL_DEFAULT_STRENGTH : UCOL_SECONDARY; UErrorCode status = U_ZERO_ERROR; - ucol_setAttribute(d->collator, UCOL_CASE_FIRST, val, &status); + ucol_setAttribute(d->collator, UCOL_STRENGTH, val, &status); if (U_FAILURE(status)) qWarning("ucol_setAttribute: Case First failed: %d", status); } diff --git a/src/corelib/tools/qcollator_macx.cpp b/src/corelib/tools/qcollator_macx.cpp index 8985cd4eba..877510489a 100644 --- a/src/corelib/tools/qcollator_macx.cpp +++ b/src/corelib/tools/qcollator_macx.cpp @@ -128,12 +128,15 @@ bool QCollator::ignorePunctuation() const int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) const { SInt32 result; - return UCCompareText(d->collator.collator, + Boolean equivalent; + UCCompareText(d->collator.collator, reinterpret_cast<const UniChar *>(s1), len1, reinterpret_cast<const UniChar *>(s2), len2, - NULL, + &equivalent, &result); - return result; + if (equivalent) + return 0; + return result < 0 ? -1 : 1; } int QCollator::compare(const QString &str1, const QString &str2) const { diff --git a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp index 53047585cf..3a3ea71562 100644 --- a/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp +++ b/src/plugins/platforms/android/qandroidplatformopenglcontext.cpp @@ -74,6 +74,7 @@ bool QAndroidPlatformOpenGLContext::needsFBOReadBackWorkaroud() needsWorkaround = qstrcmp(rendererString, "Mali-400 MP") == 0 || qstrcmp(rendererString, "Adreno (TM) 200") == 0 + || qstrcmp(rendererString, "Adreno (TM) 205") == 0 || qstrcmp(rendererString, "GC1000 core") == 0; set = true; } diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index c8eaded38d..cdc0b24464 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -1936,7 +1936,10 @@ void QWindowsWindow::getSizeHints(MINMAXINFO *mmi) const && (m_data.flags & Qt::FramelessWindowHint)) { // This block fixes QTBUG-8361: Frameless windows shouldn't cover the // taskbar when maximized - if (const QScreen *screen = effectiveScreen(window())) { + const QScreen *screen = effectiveScreen(window()); + + // Documentation of MINMAXINFO states that it will only work for the primary screen + if (screen && screen == QGuiApplication::primaryScreen()) { mmi->ptMaxSize.y = screen->availableGeometry().height(); // Width, because you can have the taskbar on the sides too. @@ -1945,8 +1948,8 @@ void QWindowsWindow::getSizeHints(MINMAXINFO *mmi) const // If you have the taskbar on top, or on the left you don't want it at (0,0): mmi->ptMaxPosition.x = screen->availableGeometry().x(); mmi->ptMaxPosition.y = screen->availableGeometry().y(); - } else { - qWarning() << "Invalid screen"; + } else if (!screen){ + qWarning() << "effectiveScreen() returned a null screen"; } } diff --git a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp index 3df8422a34..9ed27a8742 100644 --- a/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp +++ b/tests/auto/corelib/tools/qcollator/tst_qcollator.cpp @@ -52,6 +52,9 @@ class tst_QCollator : public QObject private Q_SLOTS: void moveSemantics(); + + void compare_data(); + void compare(); }; #ifdef Q_COMPILER_RVALUE_REFS @@ -87,6 +90,93 @@ void tst_QCollator::moveSemantics() #endif } + +void tst_QCollator::compare_data() +{ + QTest::addColumn<QString>("locale"); + QTest::addColumn<QString>("s1"); + QTest::addColumn<QString>("s2"); + QTest::addColumn<int>("result"); + QTest::addColumn<int>("caseInsensitiveResult"); + + /* + A few tests below are commented out on the mac. It's unclear why they fail, + as it looks like the collator for the locale is created correctly. + */ + + /* + It's hard to test English, because it's treated differently + on different platforms. For example, on Linux, it uses the + iso14651_t1 template file, which happens to provide good + defaults for Swedish. Mac OS X seems to do a pure bytewise + comparison of Latin-1 values, although I'm not sure. So I + just test digits to make sure that it's not totally broken. + */ + QTest::newRow("english1") << QString("en_US") << QString("5") << QString("4") << 1 << 1; + QTest::newRow("english2") << QString("en_US") << QString("4") << QString("6") << -1 << -1; + QTest::newRow("english3") << QString("en_US") << QString("5") << QString("6") << -1 << -1; + QTest::newRow("english4") << QString("en_US") << QString("a") << QString("b") << -1 << -1; + /* + In Swedish, a with ring above (E5) comes before a with + diaresis (E4), which comes before o diaresis (F6), which + all come after z. + */ + QTest::newRow("swedish1") << QString("sv_SE") << QString::fromLatin1("\xe5") << QString::fromLatin1("\xe4") << -1 << -1; + QTest::newRow("swedish2") << QString("sv_SE") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1 << -1; + QTest::newRow("swedish3") << QString("sv_SE") << QString::fromLatin1("\xe5") << QString::fromLatin1("\xf6") << -1 << -1; +#ifndef Q_OS_MAC + QTest::newRow("swedish4") << QString("sv_SE") << QString::fromLatin1("z") << QString::fromLatin1("\xe5") << -1 << -1; +#endif + + /* + In Norwegian, ae (E6) comes before o with stroke (D8), which + comes before a with ring above (E5). + */ + QTest::newRow("norwegian1") << QString("no_NO") << QString::fromLatin1("\xe6") << QString::fromLatin1("\xd8") << -1 << -1; +#ifndef Q_OS_MAC + QTest::newRow("norwegian2") << QString("no_NO") << QString::fromLatin1("\xd8") << QString::fromLatin1("\xe5") << -1 << -1; +#endif + QTest::newRow("norwegian3") << QString("no_NO") << QString::fromLatin1("\xe6") << QString::fromLatin1("\xe5") << -1 << -1; + + /* + In German, z comes *after* a with diaresis (E4), + which comes before o diaresis (F6). + */ + QTest::newRow("german1") << QString("de_DE") << QString::fromLatin1("a") << QString::fromLatin1("\xe4") << -1 << -1; + QTest::newRow("german2") << QString("de_DE") << QString::fromLatin1("b") << QString::fromLatin1("\xe4") << 1 << 1; + QTest::newRow("german3") << QString("de_DE") << QString::fromLatin1("z") << QString::fromLatin1("\xe4") << 1 << 1; + QTest::newRow("german4") << QString("de_DE") << QString::fromLatin1("\xe4") << QString::fromLatin1("\xf6") << -1 << -1; + QTest::newRow("german5") << QString("de_DE") << QString::fromLatin1("z") << QString::fromLatin1("\xf6") << 1 << 1; + QTest::newRow("german6") << QString("de_DE") << QString::fromLatin1("\xc0") << QString::fromLatin1("\xe0") << 1 << 0; + QTest::newRow("german7") << QString("de_DE") << QString::fromLatin1("\xd6") << QString::fromLatin1("\xf6") << 1 << 0; + QTest::newRow("german8") << QString("de_DE") << QString::fromLatin1("oe") << QString::fromLatin1("\xf6") << 1 << 1; + QTest::newRow("german9") << QString("de_DE") << QString("A") << QString("a") << 1 << 0; + + /* + French sorting of e and e with accent + */ + QTest::newRow("french1") << QString("fr_FR") << QString::fromLatin1("\xe9") << QString::fromLatin1("e") << 1 << 1; + QTest::newRow("french2") << QString("fr_FR") << QString::fromLatin1("\xe9t") << QString::fromLatin1("et") << 1 << 1; + QTest::newRow("french3") << QString("fr_FR") << QString::fromLatin1("\xe9") << QString::fromLatin1("d") << 1 << 1; + QTest::newRow("french4") << QString("fr_FR") << QString::fromLatin1("\xe9") << QString::fromLatin1("f") << -1 << -1; + +} + + +void tst_QCollator::compare() +{ + QFETCH(QString, locale); + QFETCH(QString, s1); + QFETCH(QString, s2); + QFETCH(int, result); + QFETCH(int, caseInsensitiveResult); + + QCollator collator(locale); + QCOMPARE(collator.compare(s1, s2), result); + collator.setCaseSensitivity(Qt::CaseInsensitive); + QCOMPARE(collator.compare(s1, s2), caseInsensitiveResult); +} + QTEST_APPLESS_MAIN(tst_QCollator) #include "tst_qcollator.moc" |