diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-05-28 16:41:49 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-06-03 15:14:42 +0200 |
commit | e4079eca49adce16e31dac2a18d49d7a55817891 (patch) | |
tree | 1dfb960ec1115b1f552afe8a013058542389505e /examples | |
parent | f32a6cfb6b6236533508901f114ab57396da8ff3 (diff) | |
parent | ec6dc5f78453048c4f0604655a34c6c20c79d819 (diff) | |
download | qtbase-e4079eca49adce16e31dac2a18d49d7a55817891.tar.gz |
Merge remote-tracking branch 'origin/dev' into wip/cmake
Take 5.
Change-Id: Ifb2d20e95ba824e45e667fba6c2ba45389991cc3
Diffstat (limited to 'examples')
40 files changed, 645 insertions, 155 deletions
diff --git a/examples/corelib/serialization/convert/cborconverter.cpp b/examples/corelib/serialization/convert/cborconverter.cpp index ad69983eb1..f907bb0af6 100644 --- a/examples/corelib/serialization/convert/cborconverter.cpp +++ b/examples/corelib/serialization/convert/cborconverter.cpp @@ -226,7 +226,7 @@ void CborDiagnosticDumper::saveFile(QIODevice *f, const QVariant &contents, cons QTextStream out(f); out << convertFromVariant(contents, Double).toDiagnosticNotation(opts) - << endl; + << Qt::endl; } CborConverter::CborConverter() diff --git a/examples/corelib/serialization/convert/textconverter.cpp b/examples/corelib/serialization/convert/textconverter.cpp index e80e69a0b5..7aed08f96c 100644 --- a/examples/corelib/serialization/convert/textconverter.cpp +++ b/examples/corelib/serialization/convert/textconverter.cpp @@ -66,7 +66,7 @@ static void dumpVariant(QTextStream &out, const QVariant &v) case QVariant::String: { const QStringList list = v.toStringList(); for (const QString &s : list) - out << s << endl; + out << s << Qt::endl; break; } @@ -80,11 +80,11 @@ static void dumpVariant(QTextStream &out, const QVariant &v) } case QMetaType::Nullptr: - out << "(null)" << endl; + out << "(null)" << Qt::endl; break; default: - out << v.toString() << endl; + out << v.toString() << Qt::endl; break; } } diff --git a/examples/embedded/raycasting/raycasting.cpp b/examples/embedded/raycasting/raycasting.cpp index d37b9f5d2e..7213811213 100644 --- a/examples/embedded/raycasting/raycasting.cpp +++ b/examples/embedded/raycasting/raycasting.cpp @@ -255,11 +255,7 @@ public: protected: void resizeEvent(QResizeEvent*) { -#if defined(Q_OS_WINCE_WM) - touchDevice = true; -#else touchDevice = false; -#endif if (touchDevice) { if (width() < height()) { trackPad = QRect(0, height() / 2, width(), height() / 2); diff --git a/examples/network/bearermonitor/bearermonitor.pro b/examples/network/bearermonitor/bearermonitor.pro index 7d90b408e0..16ac41298a 100644 --- a/examples/network/bearermonitor/bearermonitor.pro +++ b/examples/network/bearermonitor/bearermonitor.pro @@ -13,7 +13,7 @@ FORMS = bearermonitor_240_320.ui \ bearermonitor_640_480.ui \ sessionwidget.ui -win32:LIBS += -lws2_32 +win32: QMAKE_USE += ws2_32 CONFIG += console diff --git a/examples/network/torrent/ratecontroller.cpp b/examples/network/torrent/ratecontroller.cpp index 47b49dba30..87c65096b6 100644 --- a/examples/network/torrent/ratecontroller.cpp +++ b/examples/network/torrent/ratecontroller.cpp @@ -123,11 +123,11 @@ void RateController::transfer() qint64 writeChunk = qMax<qint64>(1, bytesToWrite / pendingSockets.size()); qint64 readChunk = qMax<qint64>(1, bytesToRead / pendingSockets.size()); - QSetIterator<PeerWireClient *> it(pendingSockets); - while (it.hasNext() && (bytesToWrite > 0 || bytesToRead > 0)) { - PeerWireClient *socket = it.next(); + for (auto it = pendingSockets.begin(), end = pendingSockets.end(); it != end && (bytesToWrite > 0 || bytesToRead > 0); /*erasing*/) { + auto current = it++; + PeerWireClient *socket = *current; if (socket->state() != QAbstractSocket::ConnectedState) { - pendingSockets.remove(socket); + pendingSockets.erase(current); continue; } @@ -156,7 +156,7 @@ void RateController::transfer() if (dataTransferred && socket->canTransferMore()) canTransferMore = true; else - pendingSockets.remove(socket); + pendingSockets.erase(current); } } while (canTransferMore && (bytesToWrite > 0 || bytesToRead > 0) && !pendingSockets.isEmpty()); diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp index d01a5f3d9e..b4cbbb7a45 100644 --- a/examples/network/torrent/torrentclient.cpp +++ b/examples/network/torrent/torrentclient.cpp @@ -720,9 +720,9 @@ QList<TorrentPeer *> TorrentClient::weighedFreePeers() const qint64 now = QDateTime::currentSecsSinceEpoch(); QList<TorrentPeer *> freePeers; QMap<QString, int> connectionsPerPeer; - for (TorrentPeer *peer : d->peers) { + for (TorrentPeer *peer : qAsConst(d->peers)) { bool busy = false; - for (PeerWireClient *client : d->connections) { + for (PeerWireClient *client : qAsConst(d->connections)) { if (client->state() == PeerWireClient::ConnectedState && client->peerAddress() == peer->address && client->peerPort() == peer->port) { @@ -1084,25 +1084,25 @@ void TorrentClient::scheduleUploads() // seeding, we sort by upload speed. Seeds are left out; there's // no use in unchoking them. QList<PeerWireClient *> allClients = d->connections; - QMultiMap<int, PeerWireClient *> transferSpeeds; + QVector<QPair<qint64, PeerWireClient *>> transferSpeeds; for (PeerWireClient *client : qAsConst(allClients)) { if (client->state() == QAbstractSocket::ConnectedState && client->availablePieces().count(true) != d->pieceCount) { if (d->state == Seeding) { - transferSpeeds.insert(client->uploadSpeed(), client); + transferSpeeds.push_back({client->uploadSpeed(), client}); } else { - transferSpeeds.insert(client->downloadSpeed(), client); + transferSpeeds.push_back({client->downloadSpeed(), client}); } } } + std::sort(transferSpeeds.begin(), transferSpeeds.end()); + // Unchoke the top 'MaxUploads' downloaders (peers that we are // uploading to) and choke all others. int maxUploaders = MaxUploads; - QMapIterator<int, PeerWireClient *> it(transferSpeeds); - it.toBack(); - while (it.hasPrevious()) { - PeerWireClient *client = it.previous().value(); + for (auto rit = transferSpeeds.crbegin(), rend = transferSpeeds.crend(); rit != rend; ++rit) { + PeerWireClient *client = rit->second; bool interested = (client->peerWireState() & PeerWireClient::PeerIsInterested); if (maxUploaders) { @@ -1484,30 +1484,26 @@ void TorrentClient::addToPeerList(const QList<TorrentPeer> &peerList) // of the peers that have no (or low) activity. int maxPeers = ConnectionManager::instance()->maxConnections() * 3; if (d->peers.size() > maxPeers) { + auto tooMany = d->peers.size() - maxPeers; + // Find what peers are currently connected & active - QSet<TorrentPeer *> activePeers; - for (TorrentPeer *peer : qAsConst(d->peers)) { + const auto firstNInactivePeers = [&tooMany, this] (TorrentPeer *peer) { + if (!tooMany) + return false; for (const PeerWireClient *client : qAsConst(d->connections)) { if (client->peer() == peer && (client->downloadSpeed() + client->uploadSpeed()) > 1024) - activePeers << peer; + return false; } - } - + --tooMany; + return true; + }; // Remove inactive peers from the peer list until we're below // the max connections count. - QList<int> toRemove; - for (int i = 0; i < d->peers.size() && (d->peers.size() - toRemove.size()) > maxPeers; ++i) { - if (!activePeers.contains(d->peers.at(i))) - toRemove << i; - } - QListIterator<int> toRemoveIterator(toRemove); - toRemoveIterator.toBack(); - while (toRemoveIterator.hasPrevious()) - d->peers.removeAt(toRemoveIterator.previous()); - + d->peers.erase(std::remove_if(d->peers.begin(), d->peers.end(), + firstNInactivePeers), + d->peers.end()); // If we still have too many peers, remove the oldest ones. - while (d->peers.size() > maxPeers) - d->peers.takeFirst(); + d->peers.erase(d->peers.begin(), d->peers.begin() + tooMany); } if (d->state != Paused && d->state != Stopping && d->state != Idle) { diff --git a/examples/opengl/contextinfo/widget.cpp b/examples/opengl/contextinfo/widget.cpp index b1b7076503..0762c91662 100644 --- a/examples/opengl/contextinfo/widget.cpp +++ b/examples/opengl/contextinfo/widget.cpp @@ -384,7 +384,7 @@ void Widget::renderWindowReady() m_output->append(tr("Qt OpenGL library handle: %1") .arg(QString::number(qintptr(QOpenGLContext::openGLModuleHandle()), 16))); - QList<QByteArray> extensionList = context->extensions().toList(); + QList<QByteArray> extensionList = context->extensions().values(); std::sort(extensionList.begin(), extensionList.end()); m_extensions->append(tr("Found %1 extensions:").arg(extensionList.count())); for (const QByteArray &ext : qAsConst(extensionList)) diff --git a/examples/opengl/hellogles3/main.cpp b/examples/opengl/hellogles3/main.cpp index 29b3b9617a..9451b2882f 100644 --- a/examples/opengl/hellogles3/main.cpp +++ b/examples/opengl/hellogles3/main.cpp @@ -69,11 +69,11 @@ int main(int argc, char *argv[]) QSurfaceFormat fmt; fmt.setDepthBufferSize(24); - // Request OpenGL 3.3 compatibility or OpenGL ES 3.0. + // Request OpenGL 3.3 core or OpenGL ES 3.0. if (QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL) { - qDebug("Requesting 3.3 compatibility context"); + qDebug("Requesting 3.3 core context"); fmt.setVersion(3, 3); - fmt.setProfile(QSurfaceFormat::CompatibilityProfile); + fmt.setProfile(QSurfaceFormat::CoreProfile); } else { qDebug("Requesting 3.0 context"); fmt.setVersion(3, 0); diff --git a/examples/opengl/legacy/overpainting/glwidget.cpp b/examples/opengl/legacy/overpainting/glwidget.cpp index f98d043c5c..0094f8ead7 100644 --- a/examples/opengl/legacy/overpainting/glwidget.cpp +++ b/examples/opengl/legacy/overpainting/glwidget.cpp @@ -247,12 +247,8 @@ void GLWidget::createBubbles(int number) //! [13] void GLWidget::animate() { - QMutableListIterator<Bubble*> iter(bubbles); - - while (iter.hasNext()) { - Bubble *bubble = iter.next(); + for (Bubble *bubble : qAsConst(bubbles)) bubble->move(rect()); - } update(); } //! [13] diff --git a/examples/opengl/qopenglwidget/glwidget.cpp b/examples/opengl/qopenglwidget/glwidget.cpp index 946b2bec67..5057291f12 100644 --- a/examples/opengl/qopenglwidget/glwidget.cpp +++ b/examples/opengl/qopenglwidget/glwidget.cpp @@ -399,12 +399,9 @@ void GLWidget::paintGL() painter.end(); - QMutableListIterator<Bubble*> iter(m_bubbles); - - while (iter.hasNext()) { - Bubble *bubble = iter.next(); + for (Bubble *bubble : qAsConst(m_bubbles)) bubble->move(rect()); - } + if (!(m_frames % 100)) { m_time.start(); m_frames = 0; diff --git a/examples/qtconcurrent/wordcount/main.cpp b/examples/qtconcurrent/wordcount/main.cpp index ff7ea24ee7..32cb4d0e08 100644 --- a/examples/qtconcurrent/wordcount/main.cpp +++ b/examples/qtconcurrent/wordcount/main.cpp @@ -126,11 +126,8 @@ WordCount countWords(const QString &file) // at a time. void reduce(WordCount &result, const WordCount &w) { - QMapIterator<QString, int> i(w); - while (i.hasNext()) { - i.next(); + for (auto i = w.begin(), end = w.end(); i != end; ++i) result[i.key()] += i.value(); - } } int main(int argc, char** argv) diff --git a/examples/widgets/dialogs/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp index 1830b21e8f..c91a594490 100644 --- a/examples/widgets/dialogs/standarddialogs/dialog.cpp +++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp @@ -287,7 +287,6 @@ Dialog::Dialog(QWidget *parent) fileDialogOptionsWidget->addCheckBox(tr("Show directories only"), QFileDialog::ShowDirsOnly); fileDialogOptionsWidget->addCheckBox(tr("Do not resolve symlinks"), QFileDialog::DontResolveSymlinks); fileDialogOptionsWidget->addCheckBox(tr("Do not confirm overwrite"), QFileDialog::DontConfirmOverwrite); - fileDialogOptionsWidget->addCheckBox(tr("Do not use sheet"), QFileDialog::DontUseSheet); fileDialogOptionsWidget->addCheckBox(tr("Readonly"), QFileDialog::ReadOnly); fileDialogOptionsWidget->addCheckBox(tr("Hide name filter details"), QFileDialog::HideNameFilterDetails); fileDialogOptionsWidget->addCheckBox(tr("Do not use custom directory icons (Windows)"), QFileDialog::DontUseCustomDirectoryIcons); diff --git a/examples/widgets/doc/src/icons.qdoc b/examples/widgets/doc/src/icons.qdoc index 60cb9062c2..7aae0491d6 100644 --- a/examples/widgets/doc/src/icons.qdoc +++ b/examples/widgets/doc/src/icons.qdoc @@ -262,12 +262,7 @@ provides arrays allowing to map from enumeration value to row/column (by using QVector::indexOf()) and back by using the array index and lists of the matching strings. Qt's containers can be easily populated by - using C++ 11 initializer lists. If the compiler does not provide that feature, - a pattern like - - \snippet widgets/icons/iconpreviewarea.cpp 43 - - can be used. + using C++ 11 initializer lists. We need two public functions to set the current icon and the icon's size. In addition the class has three private functions: We diff --git a/examples/widgets/graphicsview/diagramscene/arrow.cpp b/examples/widgets/graphicsview/diagramscene/arrow.cpp index 88160d9399..525e0b3fbb 100644 --- a/examples/widgets/graphicsview/diagramscene/arrow.cpp +++ b/examples/widgets/graphicsview/diagramscene/arrow.cpp @@ -113,15 +113,13 @@ void Arrow::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QLineF centerLine(myStartItem->pos(), myEndItem->pos()); QPolygonF endPolygon = myEndItem->polygon(); QPointF p1 = endPolygon.first() + myEndItem->pos(); - QPointF p2; QPointF intersectPoint; - QLineF polyLine; for (int i = 1; i < endPolygon.count(); ++i) { - p2 = endPolygon.at(i) + myEndItem->pos(); - polyLine = QLineF(p1, p2); - QLineF::IntersectType intersectType = - polyLine.intersect(centerLine, &intersectPoint); - if (intersectType == QLineF::BoundedIntersection) + QPointF p2 = endPolygon.at(i) + myEndItem->pos(); + QLineF polyLine = QLineF(p1, p2); + QLineF::IntersectionType intersectionType = + polyLine.intersects(centerLine, &intersectPoint); + if (intersectionType == QLineF::BoundedIntersection) break; p1 = p2; } diff --git a/examples/widgets/painting/composition/main.cpp b/examples/widgets/painting/composition/main.cpp index 2eaeaba2c5..1ffa29dddc 100644 --- a/examples/widgets/painting/composition/main.cpp +++ b/examples/widgets/painting/composition/main.cpp @@ -56,13 +56,13 @@ int main(int argc, char *argv[]) { QApplication app(argc, argv); + QScopedPointer<QStyle> arthurStyle(new ArthurStyle()); CompositionWidget compWidget(nullptr); - QStyle *arthurStyle = new ArthurStyle(); - compWidget.setStyle(arthurStyle); + compWidget.setStyle(arthurStyle.data()); const QList<QWidget *> widgets = compWidget.findChildren<QWidget *>(); for (QWidget *w : widgets) - w->setStyle(arthurStyle); + w->setStyle(arthurStyle.data()); compWidget.show(); return app.exec(); diff --git a/examples/widgets/painting/gradients/gradients.cpp b/examples/widgets/painting/gradients/gradients.cpp index 8df45be8d9..a4528ce06f 100644 --- a/examples/widgets/painting/gradients/gradients.cpp +++ b/examples/widgets/painting/gradients/gradients.cpp @@ -72,7 +72,7 @@ ShadeWidget::ShadeWidget(ShadeType type, QWidget *parent) setPalette(pal); } else { - setAttribute(Qt::WA_NoBackground); + setAttribute(Qt::WA_OpaquePaintEvent); } QPolygonF points; diff --git a/examples/widgets/painting/pathstroke/pathstroke.cpp b/examples/widgets/painting/pathstroke/pathstroke.cpp index 03e55bb2a2..e4009f0b1a 100644 --- a/examples/widgets/painting/pathstroke/pathstroke.cpp +++ b/examples/widgets/painting/pathstroke/pathstroke.cpp @@ -611,7 +611,8 @@ bool PathStrokeRenderer::event(QEvent *e) case Qt::TouchPointPressed: { // find the point, move it - QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values()); + const auto mappedPoints = m_fingerPointMapping.values(); + QSet<int> activePoints = QSet<int>(mappedPoints.begin(), mappedPoints.end()); int activePoint = -1; qreal distance = -1; const int pointsCount = m_points.size(); diff --git a/examples/widgets/painting/shared/hoverpoints.cpp b/examples/widgets/painting/shared/hoverpoints.cpp index 74c78088ad..2032fb5a2c 100644 --- a/examples/widgets/painting/shared/hoverpoints.cpp +++ b/examples/widgets/painting/shared/hoverpoints.cpp @@ -180,7 +180,8 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event) case Qt::TouchPointPressed: { // find the point, move it - QSet<int> activePoints = QSet<int>::fromList(m_fingerPointMapping.values()); + const auto mappedPoints = m_fingerPointMapping.values(); + QSet<int> activePoints = QSet<int>(mappedPoints.begin(), mappedPoints.end()); int activePoint = -1; qreal distance = -1; const int pointsCount = m_points.size(); diff --git a/examples/widgets/qnx/foreignwindows/collector.cpp b/examples/widgets/qnx/foreignwindows/collector.cpp new file mode 100644 index 0000000000..4b9e774945 --- /dev/null +++ b/examples/widgets/qnx/foreignwindows/collector.cpp @@ -0,0 +1,176 @@ +/*************************************************************************** +** +** Copyright (C) 2018 QNX Software Systems. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> +#include <QDebug> +#include <QHBoxLayout> +#include <QWindow> + +#include <algorithm> +#include <screen/screen.h> + +#include "collector.h" + +constexpr int MANAGER_EVENT_NAME_SUGGESTION = 9999; + +Collector::Collector(QWidget *parent) + : QWidget(parent) +{ + QApplication::instance()->installNativeEventFilter(this); + + QLayout *layout = new QHBoxLayout(this); + setLayout(layout); +} + +Collector::~Collector() +{ + QApplication::instance()->removeNativeEventFilter(this); +} + +bool Collector::nativeEventFilter(const QByteArray &eventType, void *message, long *result) +{ + Q_UNUSED(result); + + if (eventType == QByteArrayLiteral("screen_event_t")) + return filterQnxScreenEvent(static_cast<screen_event_t>(message)); + + return false; +} + +bool Collector::filterQnxScreenEvent(screen_event_t event) +{ + int objectType = SCREEN_OBJECT_TYPE_CONTEXT; + screen_get_event_property_iv(event, SCREEN_PROPERTY_OBJECT_TYPE, &objectType); + + if (objectType == SCREEN_OBJECT_TYPE_WINDOW) + return filterQnxScreenWindowEvent(event); + + return false; +} + +bool Collector::filterQnxScreenWindowEvent(screen_event_t event) +{ + int eventType = SCREEN_EVENT_NONE; + screen_get_event_property_iv(event, SCREEN_PROPERTY_TYPE, &eventType); + screen_window_t window = nullptr; + screen_get_event_property_pv(event, + SCREEN_PROPERTY_WINDOW, + reinterpret_cast<void **>(&window)); + + if (eventType == SCREEN_EVENT_CREATE) + return filterQnxScreenWindowCreateEvent(window, event); + else if (eventType == SCREEN_EVENT_CLOSE) + return filterQnxScreenWindowCloseEvent(window, event); + else if (eventType == SCREEN_EVENT_MANAGER) + return filterQnxScreenWindowManagerEvent(window, event); + + return false; +} + +bool Collector::filterQnxScreenWindowCreateEvent(screen_window_t window, screen_event_t event) +{ + Q_UNUSED(event); + WId winId = reinterpret_cast<WId>(window); + + QByteArray parentGroup(256, 0); + screen_get_window_property_cv(window, + SCREEN_PROPERTY_PARENT, + parentGroup.length(), + parentGroup.data()); + parentGroup.resize(strlen(parentGroup.constData())); + + QByteArray group(256, 0); + screen_get_window_property_cv(reinterpret_cast<screen_window_t>(windowHandle()->winId()), + SCREEN_PROPERTY_GROUP, + group.length(), + group.data()); + group.resize(strlen(group.constData())); + + if (parentGroup != group) + return false; + + Collectible collectible; + collectible.window = QWindow::fromWinId(winId); + collectible.widget = QWidget::createWindowContainer(collectible.window, this); + layout()->addWidget(collectible.widget); + m_collectibles.append(collectible); + + return false; +} + +bool Collector::filterQnxScreenWindowCloseEvent(screen_window_t window, screen_event_t event) +{ + Q_UNUSED(event); + WId winId = reinterpret_cast<WId>(window); + auto it = std::find_if(m_collectibles.begin(), m_collectibles.end(), + [winId] (const Collectible &collectible) { + return collectible.window->winId() == winId; + }); + if (it != m_collectibles.end()) { + delete it->widget; + // it->window is deleted by it->widget. + m_collectibles.erase(it); + } + + return false; +} + +bool Collector::filterQnxScreenWindowManagerEvent(screen_window_t window, screen_event_t event) +{ + int managerEventType = 0; + screen_get_event_property_iv(event, SCREEN_PROPERTY_SUBTYPE, &managerEventType); + + if (managerEventType == MANAGER_EVENT_NAME_SUGGESTION) + return filterQnxScreenWindowManagerNameEvent(window, event); + + return false; +} + +bool Collector::filterQnxScreenWindowManagerNameEvent(screen_window_t window, screen_event_t event) +{ + Q_UNUSED(window); + int dataSize = 0; + screen_get_event_property_iv(event, SCREEN_PROPERTY_SIZE, &dataSize); + if (dataSize > 0) { + QByteArray data(dataSize, 0); + screen_get_event_property_cv(event, SCREEN_PROPERTY_USER_DATA, data.size(), data.data()); + } + + return false; +} diff --git a/examples/widgets/qnx/foreignwindows/collector.h b/examples/widgets/qnx/foreignwindows/collector.h new file mode 100644 index 0000000000..2b1ed499ff --- /dev/null +++ b/examples/widgets/qnx/foreignwindows/collector.h @@ -0,0 +1,75 @@ +/*************************************************************************** +** +** Copyright (C) 2018 QNX Software Systems. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef COLLECTOR_H_ +#define COLLECTOR_H_ + +#include <QAbstractNativeEventFilter> +#include <QWidget> +#include <QVector> + +#include <screen/screen.h> + +class Collector : public QWidget, public QAbstractNativeEventFilter +{ +public: + explicit Collector(QWidget *parent = nullptr); + ~Collector() override; + + bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override; + +private: + struct Collectible + { + QWindow *window; + QWidget *widget; + }; + QVector<Collectible> m_collectibles; + + bool filterQnxScreenEvent(screen_event_t event); + bool filterQnxScreenWindowEvent(screen_event_t event); + bool filterQnxScreenWindowCreateEvent(screen_window_t window, screen_event_t event); + bool filterQnxScreenWindowCloseEvent(screen_window_t window, screen_event_t event); + bool filterQnxScreenWindowManagerEvent(screen_window_t window, screen_event_t event); + bool filterQnxScreenWindowManagerNameEvent(screen_window_t window, + screen_event_t event); +}; + + +#endif /* COLLECTOR_H_ */ diff --git a/examples/widgets/qnx/foreignwindows/foreignwindows.pro b/examples/widgets/qnx/foreignwindows/foreignwindows.pro new file mode 100644 index 0000000000..09ff8633eb --- /dev/null +++ b/examples/widgets/qnx/foreignwindows/foreignwindows.pro @@ -0,0 +1,11 @@ +TEMPLATE = app + +HEADERS += collector.h +SOURCES += main.cpp collector.cpp +LIBS += -lscreen + +QT += widgets + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/widgets/qnx/foreignwindows +INSTALLS += target diff --git a/examples/widgets/qnx/foreignwindows/main.cpp b/examples/widgets/qnx/foreignwindows/main.cpp new file mode 100644 index 0000000000..128e93cf88 --- /dev/null +++ b/examples/widgets/qnx/foreignwindows/main.cpp @@ -0,0 +1,53 @@ +/*************************************************************************** +** +** Copyright (C) 2018 QNX Software Systems. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** 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 https://www.qt.io/terms-conditions. For further +** information use the contact form at https://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 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include "collector.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + Collector collector; + collector.resize(640, 480); + collector.show(); + + return app.exec(); +} diff --git a/examples/widgets/richtext/textedit/CMakeLists.txt b/examples/widgets/richtext/textedit/CMakeLists.txt index 9166f6748a..487f708b34 100644 --- a/examples/widgets/richtext/textedit/CMakeLists.txt +++ b/examples/widgets/richtext/textedit/CMakeLists.txt @@ -11,7 +11,7 @@ add_qt_executable(textedit SOURCES main.cpp textedit.cpp textedit.h - LIBRARIES + PUBLIC_LIBRARIES Qt::Widgets ) @@ -19,6 +19,8 @@ add_qt_executable(textedit add_qt_resource(textedit "textedit" PREFIX "/" FILES example.html images/logo32.png + images/mac/checkbox-checked.png + images/mac/checkbox.png images/mac/editcopy.png images/mac/editcut.png images/mac/editpaste.png @@ -29,6 +31,8 @@ add_qt_resource(textedit "textedit" PREFIX "/" FILES images/mac/fileopen.png images/mac/fileprint.png images/mac/filesave.png + images/mac/format-indent-less.png + images/mac/format-indent-more.png images/mac/textbold.png images/mac/textcenter.png images/mac/textitalic.png @@ -38,6 +42,8 @@ add_qt_resource(textedit "textedit" PREFIX "/" FILES images/mac/textunder.png images/mac/zoomin.png images/mac/zoomout.png + images/win/checkbox-checked.png + images/win/checkbox.png images/win/editcopy.png images/win/editcut.png images/win/editpaste.png @@ -48,6 +54,8 @@ add_qt_resource(textedit "textedit" PREFIX "/" FILES images/win/fileopen.png images/win/fileprint.png images/win/filesave.png + images/win/format-indent-less.png + images/win/format-indent-more.png images/win/textbold.png images/win/textcenter.png images/win/textitalic.png @@ -59,7 +67,7 @@ add_qt_resource(textedit "textedit" PREFIX "/" FILES images/win/zoomout.png) -#### Keys ignored in scope 1:.:textedit.pro:<NONE>: +#### Keys ignored in scope 1:.:.:textedit.pro:<TRUE>: # EXAMPLE_FILES = "textedit.qdoc" # TEMPLATE = "app" @@ -67,9 +75,9 @@ add_qt_resource(textedit "textedit" PREFIX "/" FILES ##################################################################### extend_target(textedit CONDITION TARGET Qt::PrintSupport - LIBRARIES + PUBLIC_LIBRARIES Qt::PrintSupport ) -#### Keys ignored in scope 3:.:textedit.pro:build_all AND NOT build_pass: +#### Keys ignored in scope 3:.:.:textedit.pro:build_all AND NOT build_pass: # CONFIG = "-build_all" "release" diff --git a/examples/widgets/richtext/textedit/example.md b/examples/widgets/richtext/textedit/example.md new file mode 100644 index 0000000000..a16a9197b4 --- /dev/null +++ b/examples/widgets/richtext/textedit/example.md @@ -0,0 +1,102 @@ +# QTextEdit + +The QTextEdit widget is an advanced editor that supports formatted rich text. +It can be used to display HTML and other rich document formats. Internally, +QTextEdit uses the QTextDocument class to describe both the high-level +structure of each document and the low-level formatting of paragraphs. + +If you are viewing this document in the textedit example, you can edit this +document to explore Qt's rich text editing features. We have included some +comments in each of the following sections to encourage you to experiment. + +## Font and Paragraph Styles + +QTextEdit supports **bold**, *italic*, & ~~strikethrough~~ font styles, and +can display <span style="font-size:10pt; font-weight:600; +color:#00007f;">multicolored</span> text. Font families such as <span +style="font-family:Times New Roman">Times New Roman</span> and `Courier` +can also be used directly. *If you place the cursor in a region of styled text, +the controls in the tool bars will change to reflect the current style.* + +Paragraphs can be formatted so that the text is left-aligned, right-aligned, +centered, or fully justified. + +*Try changing the alignment of some text and resize the editor to see how the +text layout changes.* + +## Lists + +Different kinds of lists can be included in rich text documents. Standard +bullet lists can be nested, using different symbols for each level of the list: + +- Disc symbols are typically used for top-level list items. + * Circle symbols can be used to distinguish between items in lower-level + lists. + + Square symbols provide a reasonable alternative to discs and circles. + +Ordered lists can be created that can be used for tables of contents. Different +characters can be used to enumerate items, and we can use both Roman and Arabic +numerals in the same list structure: + +1. Introduction +2. Qt Tools + 1) Qt Assistant + 2) Qt Designer + 1. Form Editor + 2. Component Architecture + 3) Qt Linguist + +The list will automatically be renumbered if you add or remove items. *Try +adding new sections to the above list or removing existing item to see the +numbers change.* + +Task lists can be used to track progress on projects: + +- [ ] This is not yet done +- This is just a bullet point +- [x] This is done + +## Images + +Inline images are treated like ordinary ranges of characters in the text +editor, so they flow with the surrounding text. Images can also be selected in +the same way as text, making it easy to cut, copy, and paste them. + +![logo](images/logo32.png "logo") *Try to select this image by clicking and +dragging over it with the mouse, or use the text cursor to select it by holding +down Shift and using the arrow keys. You can then cut or copy it, and paste it +into different parts of this document.* + +## Tables + +QTextEdit can arrange and format tables, supporting features such as row and +column spans, text formatting within cells, and size constraints for columns. + +| | Development Tools | Programming Techniques | Graphical User Interfaces | +| ------------: | ----------------- | ---------------------- | ------------------------- | +| 9:00 - 11:00 | Introduction to Qt ||| +| 11:00 - 13:00 | Using qmake | Object-oriented Programming | Layouts in Qt | +| 13:00 - 15:00 | Qt Designer Tutorial | Extreme Programming | Writing Custom Styles | +| 15:00 - 17:00 | Qt Linguist and Internationalization | | | + +*Try adding text to the cells in the table and experiment with the alignment of +the paragraphs.* + +## Hyperlinks + +QTextEdit is designed to support hyperlinks between documents, and this feature +is used extensively in +[Qt Assistant](http://doc.qt.io/qt-5/qtassistant-index.html). Hyperlinks are +automatically created when an HTML file is imported into an editor. Since the +rich text framework supports hyperlinks natively, they can also be created +programatically. + +## Undo and Redo + +Full support for undo and redo operations is built into QTextEdit and the +underlying rich text framework. Operations on a document can be packaged +together to make editing a more comfortable experience for the user. + +*Try making changes to this document and press `Ctrl+Z` to undo them. You can +always recover the original contents of the document.* + diff --git a/examples/widgets/richtext/textedit/images/mac/checkbox-checked.png b/examples/widgets/richtext/textedit/images/mac/checkbox-checked.png Binary files differnew file mode 100644 index 0000000000..a072d7fb5c --- /dev/null +++ b/examples/widgets/richtext/textedit/images/mac/checkbox-checked.png diff --git a/examples/widgets/richtext/textedit/images/mac/checkbox.png b/examples/widgets/richtext/textedit/images/mac/checkbox.png Binary files differnew file mode 100644 index 0000000000..4064909712 --- /dev/null +++ b/examples/widgets/richtext/textedit/images/mac/checkbox.png diff --git a/examples/widgets/richtext/textedit/images/mac/format-indent-less.png b/examples/widgets/richtext/textedit/images/mac/format-indent-less.png Binary files differnew file mode 100644 index 0000000000..e38074e78b --- /dev/null +++ b/examples/widgets/richtext/textedit/images/mac/format-indent-less.png diff --git a/examples/widgets/richtext/textedit/images/mac/format-indent-more.png b/examples/widgets/richtext/textedit/images/mac/format-indent-more.png Binary files differnew file mode 100644 index 0000000000..1bdeabd354 --- /dev/null +++ b/examples/widgets/richtext/textedit/images/mac/format-indent-more.png diff --git a/examples/widgets/richtext/textedit/images/win/checkbox-checked.png b/examples/widgets/richtext/textedit/images/win/checkbox-checked.png Binary files differnew file mode 100644 index 0000000000..a072d7fb5c --- /dev/null +++ b/examples/widgets/richtext/textedit/images/win/checkbox-checked.png diff --git a/examples/widgets/richtext/textedit/images/win/checkbox.png b/examples/widgets/richtext/textedit/images/win/checkbox.png Binary files differnew file mode 100644 index 0000000000..4064909712 --- /dev/null +++ b/examples/widgets/richtext/textedit/images/win/checkbox.png diff --git a/examples/widgets/richtext/textedit/images/win/format-indent-less.png b/examples/widgets/richtext/textedit/images/win/format-indent-less.png Binary files differnew file mode 100644 index 0000000000..e38074e78b --- /dev/null +++ b/examples/widgets/richtext/textedit/images/win/format-indent-less.png diff --git a/examples/widgets/richtext/textedit/images/win/format-indent-more.png b/examples/widgets/richtext/textedit/images/win/format-indent-more.png Binary files differnew file mode 100644 index 0000000000..1bdeabd354 --- /dev/null +++ b/examples/widgets/richtext/textedit/images/win/format-indent-more.png diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp index 3ad9f48b67..996bb8e0a4 100644 --- a/examples/widgets/richtext/textedit/textedit.cpp +++ b/examples/widgets/richtext/textedit/textedit.cpp @@ -71,6 +71,7 @@ #include <QCloseEvent> #include <QMessageBox> #include <QMimeData> +#include <QMimeDatabase> #if defined(QT_PRINTSUPPORT_LIB) #include <QtPrintSupport/qtprintsupportglobal.h> #if QT_CONFIG(printer) @@ -316,6 +317,14 @@ void TextEdit::setupTextActions() actionAlignJustify->setShortcut(Qt::CTRL + Qt::Key_J); actionAlignJustify->setCheckable(true); actionAlignJustify->setPriority(QAction::LowPriority); + const QIcon indentMoreIcon = QIcon::fromTheme("format-indent-more", QIcon(rsrcPath + "/format-indent-more.png")); + actionIndentMore = menu->addAction(indentMoreIcon, tr("&Indent"), this, &TextEdit::indent); + actionIndentMore->setShortcut(Qt::CTRL + Qt::Key_BracketRight); + actionIndentMore->setPriority(QAction::LowPriority); + const QIcon indentLessIcon = QIcon::fromTheme("format-indent-less", QIcon(rsrcPath + "/format-indent-less.png")); + actionIndentLess = menu->addAction(indentLessIcon, tr("&Unindent"), this, &TextEdit::unindent); + actionIndentLess->setShortcut(Qt::CTRL + Qt::Key_BracketLeft); + actionIndentLess->setPriority(QAction::LowPriority); // Make sure the alignLeft is always left of the alignRight QActionGroup *alignGroup = new QActionGroup(this); @@ -334,6 +343,10 @@ void TextEdit::setupTextActions() tb->addActions(alignGroup->actions()); menu->addActions(alignGroup->actions()); + tb->addAction(actionIndentMore); + tb->addAction(actionIndentLess); + menu->addAction(actionIndentMore); + menu->addAction(actionIndentLess); menu->addSeparator(); @@ -342,6 +355,15 @@ void TextEdit::setupTextActions() actionTextColor = menu->addAction(pix, tr("&Color..."), this, &TextEdit::textColor); tb->addAction(actionTextColor); + menu->addSeparator(); + + const QIcon checkboxIcon = QIcon::fromTheme("status-checkbox-checked", QIcon(rsrcPath + "/checkbox-checked.png")); + actionToggleCheckState = menu->addAction(checkboxIcon, tr("Chec&ked"), this, &TextEdit::setChecked); + actionToggleCheckState->setShortcut(Qt::CTRL + Qt::Key_K); + actionToggleCheckState->setCheckable(true); + actionToggleCheckState->setPriority(QAction::LowPriority); + tb->addAction(actionToggleCheckState); + tb = addToolBar(tr("Format Actions")); tb->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea); addToolBarBreak(Qt::TopToolBarArea); @@ -353,6 +375,8 @@ void TextEdit::setupTextActions() comboStyle->addItem("Bullet List (Disc)"); comboStyle->addItem("Bullet List (Circle)"); comboStyle->addItem("Bullet List (Square)"); + comboStyle->addItem("Task List (Unchecked)"); + comboStyle->addItem("Task List (Checked)"); comboStyle->addItem("Ordered List (Decimal)"); comboStyle->addItem("Ordered List (Alpha lower)"); comboStyle->addItem("Ordered List (Alpha upper)"); @@ -395,11 +419,18 @@ bool TextEdit::load(const QString &f) QByteArray data = file.readAll(); QTextCodec *codec = Qt::codecForHtml(data); QString str = codec->toUnicode(data); + QUrl baseUrl = (f.front() == QLatin1Char(':') ? QUrl(f) : QUrl::fromLocalFile(f)).adjusted(QUrl::RemoveFilename); + textEdit->document()->setBaseUrl(baseUrl); if (Qt::mightBeRichText(str)) { textEdit->setHtml(str); } else { - str = QString::fromLocal8Bit(data); - textEdit->setPlainText(str); +#if QT_CONFIG(textmarkdownreader) + QMimeDatabase db; + if (db.mimeTypeForFileNameAndData(f, data).name() == QLatin1String("text/markdown")) + textEdit->setMarkdown(str); + else +#endif + textEdit->setPlainText(QString::fromLocal8Bit(data)); } setCurrentFileName(f); @@ -451,7 +482,15 @@ void TextEdit::fileOpen() QFileDialog fileDialog(this, tr("Open File...")); fileDialog.setAcceptMode(QFileDialog::AcceptOpen); fileDialog.setFileMode(QFileDialog::ExistingFile); - fileDialog.setMimeTypeFilters(QStringList() << "text/html" << "text/plain"); + fileDialog.setMimeTypeFilters(QStringList() +#if QT_CONFIG(texthtmlparser) + << "text/html" +#endif +#if QT_CONFIG(textmarkdownreader) + + << "text/markdown" +#endif + << "text/plain"); if (fileDialog.exec() != QDialog::Accepted) return; const QString fn = fileDialog.selectedFiles().first(); @@ -485,9 +524,18 @@ bool TextEdit::fileSaveAs() QFileDialog fileDialog(this, tr("Save as...")); fileDialog.setAcceptMode(QFileDialog::AcceptSave); QStringList mimeTypes; - mimeTypes << "application/vnd.oasis.opendocument.text" << "text/html" << "text/plain"; + mimeTypes << "text/plain" +#if QT_CONFIG(textodfwriter) + << "application/vnd.oasis.opendocument.text" +#endif +#if QT_CONFIG(textmarkdownwriter) + << "text/markdown" +#endif + << "text/html"; fileDialog.setMimeTypeFilters(mimeTypes); +#if QT_CONFIG(textodfwriter) fileDialog.setDefaultSuffix("odt"); +#endif if (fileDialog.exec() != QDialog::Accepted) return false; const QString fn = fileDialog.selectedFiles().first(); @@ -592,6 +640,7 @@ void TextEdit::textStyle(int styleIndex) { QTextCursor cursor = textEdit->textCursor(); QTextListFormat::Style style = QTextListFormat::ListStyleUndefined; + QTextBlockFormat::MarkerType marker = QTextBlockFormat::NoMarker; switch (styleIndex) { case 1: @@ -604,18 +653,32 @@ void TextEdit::textStyle(int styleIndex) style = QTextListFormat::ListSquare; break; case 4: - style = QTextListFormat::ListDecimal; + if (cursor.currentList()) + style = cursor.currentList()->format().style(); + else + style = QTextListFormat::ListDisc; + marker = QTextBlockFormat::Unchecked; break; case 5: - style = QTextListFormat::ListLowerAlpha; + if (cursor.currentList()) + style = cursor.currentList()->format().style(); + else + style = QTextListFormat::ListDisc; + marker = QTextBlockFormat::Checked; break; case 6: - style = QTextListFormat::ListUpperAlpha; + style = QTextListFormat::ListDecimal; break; case 7: - style = QTextListFormat::ListLowerRoman; + style = QTextListFormat::ListLowerAlpha; break; case 8: + style = QTextListFormat::ListUpperAlpha; + break; + case 9: + style = QTextListFormat::ListLowerRoman; + break; + case 10: style = QTextListFormat::ListUpperRoman; break; default: @@ -628,7 +691,7 @@ void TextEdit::textStyle(int styleIndex) if (style == QTextListFormat::ListStyleUndefined) { blockFmt.setObjectIndex(-1); - int headingLevel = styleIndex >= 9 ? styleIndex - 9 + 1 : 0; // H1 to H6, or Standard + int headingLevel = styleIndex >= 11 ? styleIndex - 11 + 1 : 0; // H1 to H6, or Standard blockFmt.setHeadingLevel(headingLevel); cursor.setBlockFormat(blockFmt); @@ -640,6 +703,8 @@ void TextEdit::textStyle(int styleIndex) cursor.mergeCharFormat(fmt); textEdit->mergeCurrentCharFormat(fmt); } else { + blockFmt.setMarker(marker); + cursor.setBlockFormat(blockFmt); QTextListFormat listFmt; if (cursor.currentList()) { listFmt = cursor.currentList()->format(); @@ -678,6 +743,45 @@ void TextEdit::textAlign(QAction *a) textEdit->setAlignment(Qt::AlignJustify); } +void TextEdit::setChecked(bool checked) +{ + textStyle(checked ? 5 : 4); +} + +void TextEdit::indent() +{ + modifyIndentation(1); +} + +void TextEdit::unindent() +{ + modifyIndentation(-1); +} + +void TextEdit::modifyIndentation(int amount) +{ + QTextCursor cursor = textEdit->textCursor(); + cursor.beginEditBlock(); + if (cursor.currentList()) { + QTextListFormat listFmt = cursor.currentList()->format(); + // See whether the line above is the list we want to move this item into, + // or whether we need a new list. + QTextCursor above(cursor); + above.movePosition(QTextCursor::Up); + if (above.currentList() && listFmt.indent() + amount == above.currentList()->format().indent()) { + above.currentList()->add(cursor.block()); + } else { + listFmt.setIndent(listFmt.indent() + amount); + cursor.createList(listFmt); + } + } else { + QTextBlockFormat blockFmt = cursor.blockFormat(); + blockFmt.setIndent(blockFmt.indent() + amount); + cursor.setBlockFormat(blockFmt); + } + cursor.endEditBlock(); +} + void TextEdit::currentCharFormatChanged(const QTextCharFormat &format) { fontChanged(format.font()); @@ -700,27 +804,40 @@ void TextEdit::cursorPositionChanged() comboStyle->setCurrentIndex(3); break; case QTextListFormat::ListDecimal: - comboStyle->setCurrentIndex(4); + comboStyle->setCurrentIndex(6); break; case QTextListFormat::ListLowerAlpha: - comboStyle->setCurrentIndex(5); + comboStyle->setCurrentIndex(7); break; case QTextListFormat::ListUpperAlpha: - comboStyle->setCurrentIndex(6); + comboStyle->setCurrentIndex(8); break; case QTextListFormat::ListLowerRoman: - comboStyle->setCurrentIndex(7); + comboStyle->setCurrentIndex(9); break; case QTextListFormat::ListUpperRoman: - comboStyle->setCurrentIndex(8); + comboStyle->setCurrentIndex(10); break; default: comboStyle->setCurrentIndex(-1); break; } + switch (textEdit->textCursor().block().blockFormat().marker()) { + case QTextBlockFormat::NoMarker: + actionToggleCheckState->setChecked(false); + break; + case QTextBlockFormat::Unchecked: + comboStyle->setCurrentIndex(4); + actionToggleCheckState->setChecked(false); + break; + case QTextBlockFormat::Checked: + comboStyle->setCurrentIndex(5); + actionToggleCheckState->setChecked(true); + break; + } } else { int headingLevel = textEdit->textCursor().blockFormat().headingLevel(); - comboStyle->setCurrentIndex(headingLevel ? headingLevel + 8 : 0); + comboStyle->setCurrentIndex(headingLevel ? headingLevel + 10 : 0); } } diff --git a/examples/widgets/richtext/textedit/textedit.h b/examples/widgets/richtext/textedit/textedit.h index ae0b13a4cc..9e50166c6f 100644 --- a/examples/widgets/richtext/textedit/textedit.h +++ b/examples/widgets/richtext/textedit/textedit.h @@ -96,6 +96,9 @@ private slots: void textStyle(int styleIndex); void textColor(); void textAlign(QAction *a); + void setChecked(bool checked); + void indent(); + void unindent(); void currentCharFormatChanged(const QTextCharFormat &format); void cursorPositionChanged(); @@ -110,6 +113,7 @@ private: void setupTextActions(); bool maybeSave(); void setCurrentFileName(const QString &fileName); + void modifyIndentation(int amount); void mergeFormatOnWordOrSelection(const QTextCharFormat &format); void fontChanged(const QFont &f); @@ -125,6 +129,9 @@ private: QAction *actionAlignCenter; QAction *actionAlignRight; QAction *actionAlignJustify; + QAction *actionIndentLess; + QAction *actionIndentMore; + QAction *actionToggleCheckState; QAction *actionUndo; QAction *actionRedo; #ifndef QT_NO_CLIPBOARD diff --git a/examples/widgets/richtext/textedit/textedit.qrc b/examples/widgets/richtext/textedit/textedit.qrc index 7d6efd7d67..1641acc207 100644 --- a/examples/widgets/richtext/textedit/textedit.qrc +++ b/examples/widgets/richtext/textedit/textedit.qrc @@ -1,6 +1,8 @@ <!DOCTYPE RCC><RCC version="1.0"> <qresource prefix="/"> <file>images/logo32.png</file> + <file>images/mac/checkbox.png</file> + <file>images/mac/checkbox-checked.png</file> <file>images/mac/editcopy.png</file> <file>images/mac/editcut.png</file> <file>images/mac/editpaste.png</file> @@ -11,6 +13,8 @@ <file>images/mac/fileopen.png</file> <file>images/mac/fileprint.png</file> <file>images/mac/filesave.png</file> + <file>images/mac/format-indent-less.png</file> + <file>images/mac/format-indent-more.png</file> <file>images/mac/textbold.png</file> <file>images/mac/textcenter.png</file> <file>images/mac/textitalic.png</file> @@ -20,6 +24,8 @@ <file>images/mac/textunder.png</file> <file>images/mac/zoomin.png</file> <file>images/mac/zoomout.png</file> + <file>images/win/checkbox.png</file> + <file>images/win/checkbox-checked.png</file> <file>images/win/editcopy.png</file> <file>images/win/editcut.png</file> <file>images/win/editpaste.png</file> @@ -30,6 +36,8 @@ <file>images/win/fileopen.png</file> <file>images/win/fileprint.png</file> <file>images/win/filesave.png</file> + <file>images/win/format-indent-less.png</file> + <file>images/win/format-indent-more.png</file> <file>images/win/textbold.png</file> <file>images/win/textcenter.png</file> <file>images/win/textitalic.png</file> diff --git a/examples/widgets/tools/i18n/languagechooser.cpp b/examples/widgets/tools/i18n/languagechooser.cpp index f07d0ddee3..963165ff81 100644 --- a/examples/widgets/tools/i18n/languagechooser.cpp +++ b/examples/widgets/tools/i18n/languagechooser.cpp @@ -163,11 +163,8 @@ QStringList LanguageChooser::findQmFiles() QDir dir(":/translations"); QStringList fileNames = dir.entryList(QStringList("*.qm"), QDir::Files, QDir::Name); - QMutableStringListIterator i(fileNames); - while (i.hasNext()) { - i.next(); - i.setValue(dir.filePath(i.value())); - } + for (QString &fileName : fileNames) + fileName = dir.filePath(fileName); return fileNames; } diff --git a/examples/widgets/tools/plugandpaint/app/interfaces.h b/examples/widgets/tools/plugandpaint/app/interfaces.h index a1e91e13ff..705e578809 100644 --- a/examples/widgets/tools/plugandpaint/app/interfaces.h +++ b/examples/widgets/tools/plugandpaint/app/interfaces.h @@ -68,7 +68,7 @@ QT_END_NAMESPACE class BrushInterface { public: - virtual ~BrushInterface() {} + virtual ~BrushInterface() = default; virtual QStringList brushes() const = 0; virtual QRect mousePress(const QString &brush, QPainter &painter, @@ -84,7 +84,7 @@ public: class ShapeInterface { public: - virtual ~ShapeInterface() {} + virtual ~ShapeInterface() = default; virtual QStringList shapes() const = 0; virtual QPainterPath generateShape(const QString &shape, @@ -96,7 +96,7 @@ public: class FilterInterface { public: - virtual ~FilterInterface() {} + virtual ~FilterInterface() = default; virtual QStringList filters() const = 0; virtual QImage filterImage(const QString &filter, const QImage &image, diff --git a/examples/widgets/tools/plugandpaint/app/paintarea.cpp b/examples/widgets/tools/plugandpaint/app/paintarea.cpp index 4295e04cc0..e225d78398 100644 --- a/examples/widgets/tools/plugandpaint/app/paintarea.cpp +++ b/examples/widgets/tools/plugandpaint/app/paintarea.cpp @@ -59,7 +59,7 @@ PaintArea::PaintArea(QWidget *parent) : QWidget(parent) { setAttribute(Qt::WA_StaticContents); - setAttribute(Qt::WA_NoBackground); + setAttribute(Qt::WA_OpaquePaintEvent); theImage.fill(qRgb(255, 255, 255)); } diff --git a/examples/widgets/widgets/icons/iconpreviewarea.cpp b/examples/widgets/widgets/icons/iconpreviewarea.cpp index 1a2f514ba8..7a73a137cd 100644 --- a/examples/widgets/widgets/icons/iconpreviewarea.cpp +++ b/examples/widgets/widgets/icons/iconpreviewarea.cpp @@ -79,8 +79,6 @@ IconPreviewArea::IconPreviewArea(QWidget *parent) } //! [0] -#ifdef Q_COMPILER_INITIALIZER_LISTS - //! [42] QVector<QIcon::Mode> IconPreviewArea::iconModes() { @@ -107,44 +105,6 @@ QStringList IconPreviewArea::iconStateNames() } //! [42] -#else // Q_COMPILER_INITIALIZER_LISTS - -//! [43] -QVector<QIcon::Mode> IconPreviewArea::iconModes() -{ - static QVector<QIcon::Mode> result; - if (result.isEmpty()) - result << QIcon::Normal << QIcon::Active << QIcon::Disabled << QIcon::Selected; - return result; -} -//! [43] - -QVector<QIcon::State> IconPreviewArea::iconStates() -{ - static QVector<QIcon::State> result; - if (result.isEmpty()) - result << QIcon::Off << QIcon::On; - return result; -} - -QStringList IconPreviewArea::iconModeNames() -{ - static QStringList result; - if (result.isEmpty()) - result << tr("Normal") << tr("Active") << tr("Disabled") << tr("Selected"); - return result; -} - -QStringList IconPreviewArea::iconStateNames() -{ - static QStringList result; - if (result.isEmpty()) - result << tr("Off") << tr("On"); - return result; -} - -#endif // !Q_COMPILER_INITIALIZER_LISTS - //! [1] void IconPreviewArea::setIcon(const QIcon &icon) { diff --git a/examples/xml/htmlinfo/main.cpp b/examples/xml/htmlinfo/main.cpp index 22bf36f33c..bc19ae4a82 100644 --- a/examples/xml/htmlinfo/main.cpp +++ b/examples/xml/htmlinfo/main.cpp @@ -54,10 +54,10 @@ void parseHtmlFile(QTextStream &out, const QString &fileName) { QFile file(fileName); - out << "Analysis of HTML file: " << fileName << endl; + out << "Analysis of HTML file: " << fileName << Qt::endl; if (!file.open(QIODevice::ReadOnly)) { - out << " Couldn't open the file." << endl << endl << endl; + out << " Couldn't open the file." << Qt::endl << Qt::endl << Qt::endl; return; } @@ -85,22 +85,22 @@ void parseHtmlFile(QTextStream &out, const QString &fileName) //! [2] if (reader.hasError()) { out << " The HTML file isn't well-formed: " << reader.errorString() - << endl << endl << endl; + << Qt::endl << Qt::endl << Qt::endl; return; } //! [2] - out << " Title: \"" << title << '"' << endl - << " Number of paragraphs: " << paragraphCount << endl - << " Number of links: " << links.size() << endl - << " Showing first few links:" << endl; + out << " Title: \"" << title << '"' << Qt::endl + << " Number of paragraphs: " << paragraphCount << Qt::endl + << " Number of links: " << links.size() << Qt::endl + << " Showing first few links:" << Qt::endl; while (links.size() > 5) links.removeLast(); for (const QString &link : qAsConst(links)) - out << " " << link << endl; - out << endl << endl; + out << " " << link << Qt::endl; + out << Qt::endl << Qt::endl; } int main(int argc, char **argv) |