Merge remote-tracking branch 'origin/stable' into 5.3
Change-Id: Icd073d40ce10ab4733b997036815795dd3fbaac1
This commit is contained in:
commit
5721c0811a
@ -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
|
** Contact: http://www.qt-project.org/legal
|
||||||
**
|
**
|
||||||
** This file is part of the documentation of the Qt Toolkit.
|
** This file is part of the documentation of the Qt Toolkit.
|
||||||
@ -112,15 +112,19 @@
|
|||||||
{ImageViewer}'s appearance.
|
{ImageViewer}'s appearance.
|
||||||
|
|
||||||
\snippet widgets/imageviewer/imageviewer.cpp 1
|
\snippet widgets/imageviewer/imageviewer.cpp 1
|
||||||
|
|
||||||
|
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
|
\snippet widgets/imageviewer/imageviewer.cpp 2
|
||||||
|
|
||||||
In the \c open() slot, we show a file dialog to the user. The
|
In the \c loadFile() function, we check if the file's
|
||||||
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.
|
|
||||||
|
|
||||||
Unless the file name is a empty string, we check if the file's
|
|
||||||
format is an image format by constructing a QImage which tries to
|
format is an image format by constructing a QImage which tries to
|
||||||
load the image from the file. If the constructor returns a null
|
load the image from the file. If the constructor returns a null
|
||||||
image, we use a QMessageBox to alert the user.
|
image, we use a QMessageBox to alert the user.
|
||||||
@ -135,7 +139,6 @@
|
|||||||
information message with an \uicontrol OK button (the default) is
|
information message with an \uicontrol OK button (the default) is
|
||||||
sufficient, since the message is part of a normal operation.
|
sufficient, since the message is part of a normal operation.
|
||||||
|
|
||||||
\snippet widgets/imageviewer/imageviewer.cpp 3
|
|
||||||
\snippet widgets/imageviewer/imageviewer.cpp 4
|
\snippet widgets/imageviewer/imageviewer.cpp 4
|
||||||
|
|
||||||
If the format is supported, we display the image in \c imageLabel
|
If the format is supported, we display the image in \c imageLabel
|
||||||
|
@ -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
|
** Contact: http://www.qt-project.org/legal
|
||||||
**
|
**
|
||||||
** This file is part of the examples of the Qt Toolkit.
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
@ -61,23 +61,22 @@ ImageViewer::ImageViewer()
|
|||||||
createActions();
|
createActions();
|
||||||
createMenus();
|
createMenus();
|
||||||
|
|
||||||
setWindowTitle(tr("Image Viewer"));
|
resize(QGuiApplication::primaryScreen()->availableSize() * 3 / 5);
|
||||||
resize(500, 400);
|
|
||||||
}
|
}
|
||||||
//! [0]
|
|
||||||
|
|
||||||
//! [1]
|
//! [0]
|
||||||
void ImageViewer::open()
|
//! [2]
|
||||||
//! [1] //! [2]
|
|
||||||
|
bool ImageViewer::loadFile(const QString &fileName)
|
||||||
{
|
{
|
||||||
QString fileName = QFileDialog::getOpenFileName(this,
|
|
||||||
tr("Open File"), QDir::currentPath());
|
|
||||||
if (!fileName.isEmpty()) {
|
|
||||||
QImage image(fileName);
|
QImage image(fileName);
|
||||||
if (image.isNull()) {
|
if (image.isNull()) {
|
||||||
QMessageBox::information(this, tr("Image Viewer"),
|
QMessageBox::information(this, QGuiApplication::applicationDisplayName(),
|
||||||
tr("Cannot load %1.").arg(fileName));
|
tr("Cannot load %1.").arg(QDir::toNativeSeparators(fileName)));
|
||||||
return;
|
setWindowFilePath(QString());
|
||||||
|
imageLabel->setPixmap(QPixmap());
|
||||||
|
imageLabel->adjustSize();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
//! [2] //! [3]
|
//! [2] //! [3]
|
||||||
imageLabel->setPixmap(QPixmap::fromImage(image));
|
imageLabel->setPixmap(QPixmap::fromImage(image));
|
||||||
@ -90,10 +89,33 @@ void ImageViewer::open()
|
|||||||
|
|
||||||
if (!fitToWindowAct->isChecked())
|
if (!fitToWindowAct->isChecked())
|
||||||
imageLabel->adjustSize();
|
imageLabel->adjustSize();
|
||||||
|
|
||||||
|
setWindowFilePath(fileName);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//! [4]
|
//! [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]
|
//! [5]
|
||||||
void ImageViewer::print()
|
void ImageViewer::print()
|
||||||
//! [5] //! [6]
|
//! [5] //! [6]
|
||||||
|
@ -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
|
** Contact: http://www.qt-project.org/legal
|
||||||
**
|
**
|
||||||
** This file is part of the examples of the Qt Toolkit.
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
@ -61,6 +61,7 @@ class ImageViewer : public QMainWindow
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
ImageViewer();
|
ImageViewer();
|
||||||
|
bool loadFile(const QString &);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void open();
|
void open();
|
||||||
|
@ -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
|
** Contact: http://www.qt-project.org/legal
|
||||||
**
|
**
|
||||||
** This file is part of the examples of the Qt Toolkit.
|
** This file is part of the examples of the Qt Toolkit.
|
||||||
@ -39,13 +39,23 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QCommandLineParser>
|
||||||
|
|
||||||
#include "imageviewer.h"
|
#include "imageviewer.h"
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication app(argc, 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;
|
ImageViewer imageViewer;
|
||||||
|
if (!commandLineParser.positionalArguments().isEmpty()
|
||||||
|
&& !imageViewer.loadFile(commandLineParser.positionalArguments().front())) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
imageViewer.show();
|
imageViewer.show();
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
@ -75,10 +75,17 @@ void QCollator::setCaseSensitivity(Qt::CaseSensitivity cs)
|
|||||||
{
|
{
|
||||||
detach();
|
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;
|
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))
|
if (U_FAILURE(status))
|
||||||
qWarning("ucol_setAttribute: Case First failed: %d", status);
|
qWarning("ucol_setAttribute: Case First failed: %d", status);
|
||||||
}
|
}
|
||||||
|
@ -128,12 +128,15 @@ bool QCollator::ignorePunctuation() const
|
|||||||
int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) const
|
int QCollator::compare(const QChar *s1, int len1, const QChar *s2, int len2) const
|
||||||
{
|
{
|
||||||
SInt32 result;
|
SInt32 result;
|
||||||
return UCCompareText(d->collator.collator,
|
Boolean equivalent;
|
||||||
|
UCCompareText(d->collator.collator,
|
||||||
reinterpret_cast<const UniChar *>(s1), len1,
|
reinterpret_cast<const UniChar *>(s1), len1,
|
||||||
reinterpret_cast<const UniChar *>(s2), len2,
|
reinterpret_cast<const UniChar *>(s2), len2,
|
||||||
NULL,
|
&equivalent,
|
||||||
&result);
|
&result);
|
||||||
return result;
|
if (equivalent)
|
||||||
|
return 0;
|
||||||
|
return result < 0 ? -1 : 1;
|
||||||
}
|
}
|
||||||
int QCollator::compare(const QString &str1, const QString &str2) const
|
int QCollator::compare(const QString &str1, const QString &str2) const
|
||||||
{
|
{
|
||||||
|
@ -74,6 +74,7 @@ bool QAndroidPlatformOpenGLContext::needsFBOReadBackWorkaroud()
|
|||||||
needsWorkaround =
|
needsWorkaround =
|
||||||
qstrcmp(rendererString, "Mali-400 MP") == 0
|
qstrcmp(rendererString, "Mali-400 MP") == 0
|
||||||
|| qstrcmp(rendererString, "Adreno (TM) 200") == 0
|
|| qstrcmp(rendererString, "Adreno (TM) 200") == 0
|
||||||
|
|| qstrcmp(rendererString, "Adreno (TM) 205") == 0
|
||||||
|| qstrcmp(rendererString, "GC1000 core") == 0;
|
|| qstrcmp(rendererString, "GC1000 core") == 0;
|
||||||
set = true;
|
set = true;
|
||||||
}
|
}
|
||||||
|
@ -1936,7 +1936,10 @@ void QWindowsWindow::getSizeHints(MINMAXINFO *mmi) const
|
|||||||
&& (m_data.flags & Qt::FramelessWindowHint)) {
|
&& (m_data.flags & Qt::FramelessWindowHint)) {
|
||||||
// This block fixes QTBUG-8361: Frameless windows shouldn't cover the
|
// This block fixes QTBUG-8361: Frameless windows shouldn't cover the
|
||||||
// taskbar when maximized
|
// 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();
|
mmi->ptMaxSize.y = screen->availableGeometry().height();
|
||||||
|
|
||||||
// Width, because you can have the taskbar on the sides too.
|
// 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):
|
// 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.x = screen->availableGeometry().x();
|
||||||
mmi->ptMaxPosition.y = screen->availableGeometry().y();
|
mmi->ptMaxPosition.y = screen->availableGeometry().y();
|
||||||
} else {
|
} else if (!screen){
|
||||||
qWarning() << "Invalid screen";
|
qWarning() << "effectiveScreen() returned a null screen";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +52,9 @@ class tst_QCollator : public QObject
|
|||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void moveSemantics();
|
void moveSemantics();
|
||||||
|
|
||||||
|
void compare_data();
|
||||||
|
void compare();
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef Q_COMPILER_RVALUE_REFS
|
#ifdef Q_COMPILER_RVALUE_REFS
|
||||||
@ -87,6 +90,93 @@ void tst_QCollator::moveSemantics()
|
|||||||
#endif
|
#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)
|
QTEST_APPLESS_MAIN(tst_QCollator)
|
||||||
|
|
||||||
#include "tst_qcollator.moc"
|
#include "tst_qcollator.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user