summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/corelib/threads/mandelbrot/main.cpp34
-rw-r--r--examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp16
-rw-r--r--examples/corelib/threads/mandelbrot/mandelbrotwidget.h4
-rw-r--r--examples/corelib/threads/mandelbrot/renderthread.cpp28
-rw-r--r--examples/corelib/threads/mandelbrot/renderthread.h7
-rw-r--r--examples/embedded/flickable/main.cpp2
-rw-r--r--examples/network/fortuneserver/server.cpp2
-rw-r--r--examples/network/threadedfortuneserver/fortuneserver.cpp2
-rw-r--r--examples/network/torrent/torrentclient.cpp16
-rw-r--r--examples/widgets/dialogs/standarddialogs/dialog.cpp8
-rw-r--r--examples/widgets/doc/src/addressbook-tutorial.qdoc6
-rw-r--r--examples/widgets/doc/src/fetchmore.qdoc17
-rw-r--r--examples/widgets/itemviews/editabletreemodel/mainwindow.cpp2
-rw-r--r--examples/widgets/itemviews/editabletreemodel/treemodel.cpp3
-rw-r--r--examples/widgets/itemviews/fetchmore/filelistmodel.cpp53
-rw-r--r--examples/widgets/itemviews/fetchmore/filelistmodel.h13
-rw-r--r--examples/widgets/itemviews/fetchmore/window.cpp48
-rw-r--r--examples/widgets/itemviews/fetchmore/window.h13
-rw-r--r--examples/widgets/mainwindows/mainwindow/toolbar.cpp2
-rw-r--r--examples/widgets/painting/gradients/gradients.cpp2
-rw-r--r--examples/widgets/painting/pathstroke/pathstroke.cpp24
-rw-r--r--examples/widgets/painting/shared/hoverpoints.cpp24
-rw-r--r--examples/widgets/richtext/textedit/.prev_CMakeLists.txt2
-rw-r--r--examples/widgets/richtext/textedit/CMakeLists.txt2
-rw-r--r--examples/widgets/richtext/textedit/images/mac/textundercolor.pngbin0 -> 6916 bytes
-rw-r--r--examples/widgets/richtext/textedit/images/win/textundercolor.pngbin0 -> 6916 bytes
-rw-r--r--examples/widgets/richtext/textedit/textedit.cpp17
-rw-r--r--examples/widgets/richtext/textedit/textedit.h2
-rw-r--r--examples/widgets/richtext/textedit/textedit.qrc2
-rw-r--r--examples/widgets/tools/CMakeLists.txt6
-rw-r--r--examples/widgets/tools/plugandpaint/CMakeLists.txt16
-rw-r--r--examples/widgets/tools/plugandpaint/app/CMakeLists.txt56
-rw-r--r--examples/widgets/tools/plugandpaint/app/app.pro6
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/basictools/CMakeLists.txt26
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/extrafilters/CMakeLists.txt27
-rw-r--r--examples/widgets/tools/settingseditor/settingstree.cpp2
-rw-r--r--examples/widgets/touch/fingerpaint/scribblearea.cpp6
-rw-r--r--examples/widgets/touch/knobs/knob.cpp8
-rw-r--r--examples/widgets/touch/pinchzoom/graphicsview.cpp8
-rw-r--r--examples/widgets/widgets/calendarwidget/window.cpp17
-rw-r--r--examples/widgets/widgets/imageviewer/imageviewer.cpp9
-rw-r--r--examples/widgets/widgets/stylesheet/mainwindow.cpp6
-rw-r--r--examples/widgets/widgets/validators/localeselector.cpp10
43 files changed, 310 insertions, 244 deletions
diff --git a/examples/corelib/threads/mandelbrot/main.cpp b/examples/corelib/threads/mandelbrot/main.cpp
index 9832d55514..19ea8cf417 100644
--- a/examples/corelib/threads/mandelbrot/main.cpp
+++ b/examples/corelib/threads/mandelbrot/main.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -52,11 +52,43 @@
#include <QApplication>
+#include <QScreen>
+
+#include <QCommandLineParser>
+#include <QCommandLineOption>
+#include <QDebug>
+#include <QRect>
+
//! [0]
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
+
+ QCommandLineParser parser;
+ parser.setApplicationDescription("Qt Mandelbrot Example");
+ parser.addHelpOption();
+ parser.addVersionOption();
+ QCommandLineOption passesOption("passes", "Number of passes (1-8)", "passes");
+ parser.addOption(passesOption);
+ parser.process(app);
+
+ if (parser.isSet(passesOption)) {
+ const auto passesStr = parser.value(passesOption);
+ bool ok;
+ const int passes = passesStr.toInt(&ok);
+ if (!ok || passes < 1 || passes > 8) {
+ qWarning() << "Invalid value:" << passesStr;
+ return -1;
+ }
+ RenderThread::setNumPasses(passes);
+ }
+
MandelbrotWidget widget;
+ const auto geometry = widget.screen()->availableGeometry();
+ widget.resize((2 * geometry.size()) / 3);
+ const auto pos = (geometry.size() - widget.size()) / 2;
+ widget.move(geometry.topLeft() + QPoint(pos.width(), pos.height()));
+
widget.show();
return app.exec();
}
diff --git a/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp b/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp
index b0c3733b22..bb1f83482b 100644
--- a/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp
+++ b/examples/corelib/threads/mandelbrot/mandelbrotwidget.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -73,6 +73,8 @@ MandelbrotWidget::MandelbrotWidget(QWidget *parent) :
pixmapScale(DefaultScale),
curScale(DefaultScale)
{
+ help = tr("Use mouse wheel or the '+' and '-' keys to zoom. "
+ "Press and hold left mouse button to scroll.");
connect(&thread, &RenderThread::renderedImage,
this, &MandelbrotWidget::updatePixmap);
@@ -80,8 +82,6 @@ MandelbrotWidget::MandelbrotWidget(QWidget *parent) :
#if QT_CONFIG(cursor)
setCursor(Qt::CrossCursor);
#endif
- resize(550, 400);
-
}
//! [1]
@@ -127,8 +127,9 @@ void MandelbrotWidget::paintEvent(QPaintEvent * /* event */)
}
//! [8] //! [9]
- QString text = tr("Use mouse wheel or the '+' and '-' keys to zoom. "
- "Press and hold left mouse button to scroll.");
+ QString text = help;
+ if (!info.isEmpty())
+ text += ' ' + info;
QFontMetrics metrics = painter.fontMetrics();
int textWidth = metrics.horizontalAdvance(text);
@@ -169,6 +170,9 @@ void MandelbrotWidget::keyPressEvent(QKeyEvent *event)
case Qt::Key_Up:
scroll(0, +ScrollStep);
break;
+ case Qt::Key_Q:
+ close();
+ break;
default:
QWidget::keyPressEvent(event);
}
@@ -226,6 +230,8 @@ void MandelbrotWidget::updatePixmap(const QImage &image, double scaleFactor)
if (!lastDragPos.isNull())
return;
+ info = image.text(RenderThread::infoKey());
+
pixmap = QPixmap::fromImage(image);
pixmapOffset = QPoint();
lastDragPos = QPoint();
diff --git a/examples/corelib/threads/mandelbrot/mandelbrotwidget.h b/examples/corelib/threads/mandelbrot/mandelbrotwidget.h
index cb40962535..956ffc10a8 100644
--- a/examples/corelib/threads/mandelbrot/mandelbrotwidget.h
+++ b/examples/corelib/threads/mandelbrot/mandelbrotwidget.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -86,6 +86,8 @@ private:
QPixmap pixmap;
QPoint pixmapOffset;
QPoint lastDragPos;
+ QString help;
+ QString info;
double centerX;
double centerY;
double pixmapScale;
diff --git a/examples/corelib/threads/mandelbrot/renderthread.cpp b/examples/corelib/threads/mandelbrot/renderthread.cpp
index 4d2009471c..1f2af3b999 100644
--- a/examples/corelib/threads/mandelbrot/renderthread.cpp
+++ b/examples/corelib/threads/mandelbrot/renderthread.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -51,8 +51,14 @@
#include "renderthread.h"
#include <QImage>
+
+#include <QElapsedTimer>
+#include <QTextStream>
+
#include <cmath>
+int RenderThread::numPasses = 8;
+
//! [0]
RenderThread::RenderThread(QObject *parent)
: QThread(parent)
@@ -98,6 +104,7 @@ void RenderThread::render(double centerX, double centerY, double scaleFactor,
//! [3]
void RenderThread::run()
{
+ QElapsedTimer timer;
forever {
mutex.lock();
const double devicePixelRatio = this->devicePixelRatio;
@@ -116,13 +123,14 @@ void RenderThread::run()
QImage image(resultSize, QImage::Format_RGB32);
image.setDevicePixelRatio(devicePixelRatio);
- const int NumPasses = 8;
int pass = 0;
- while (pass < NumPasses) {
+ while (pass < numPasses) {
const int MaxIterations = (1 << (2 * pass + 6)) + 32;
const int Limit = 4;
bool allBlack = true;
+ timer.restart();
+
for (int y = -halfHeight; y < halfHeight; ++y) {
if (restart)
break;
@@ -165,8 +173,20 @@ void RenderThread::run()
if (allBlack && pass == 0) {
pass = 4;
} else {
- if (!restart)
+ if (!restart) {
+ QString message;
+ QTextStream str(&message);
+ str << " Pass " << (pass + 1) << '/' << numPasses
+ << ", max iterations: " << MaxIterations << ", time: ";
+ const auto elapsed = timer.elapsed();
+ if (elapsed > 2000)
+ str << (elapsed / 1000) << 's';
+ else
+ str << elapsed << "ms";
+ image.setText(infoKey(), message);
+
emit renderedImage(image, requestedScaleFactor);
+ }
//! [5] //! [6]
++pass;
}
diff --git a/examples/corelib/threads/mandelbrot/renderthread.h b/examples/corelib/threads/mandelbrot/renderthread.h
index 6174e0ed3d..7bbd9ae056 100644
--- a/examples/corelib/threads/mandelbrot/renderthread.h
+++ b/examples/corelib/threads/mandelbrot/renderthread.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -72,6 +72,10 @@ public:
void render(double centerX, double centerY, double scaleFactor, QSize resultSize,
double devicePixelRatio);
+ static void setNumPasses(int n) { numPasses = n; }
+
+ static QString infoKey() { return QStringLiteral("info"); }
+
signals:
void renderedImage(const QImage &image, double scaleFactor);
@@ -88,6 +92,7 @@ private:
double scaleFactor;
double devicePixelRatio;
QSize resultSize;
+ static int numPasses;
bool restart = false;
bool abort = false;
diff --git a/examples/embedded/flickable/main.cpp b/examples/embedded/flickable/main.cpp
index fd30d15e49..139baa6ba7 100644
--- a/examples/embedded/flickable/main.cpp
+++ b/examples/embedded/flickable/main.cpp
@@ -72,7 +72,7 @@ static QStringList colorPairs(int max)
// randomize it
colors.clear();
while (combinedColors.count()) {
- int i = QRandomGenerator::global()->bounded(int(combinedColors.count()));
+ int i = QRandomGenerator::global()->bounded(combinedColors.count());
colors << combinedColors[i];
combinedColors.removeAt(i);
if (colors.count() == max)
diff --git a/examples/network/fortuneserver/server.cpp b/examples/network/fortuneserver/server.cpp
index 95aadb60c9..c91b6a5c0c 100644
--- a/examples/network/fortuneserver/server.cpp
+++ b/examples/network/fortuneserver/server.cpp
@@ -145,7 +145,7 @@ void Server::sendFortune()
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_10);
- out << fortunes[QRandomGenerator::global()->bounded(int(fortunes.size()))];
+ out << fortunes[QRandomGenerator::global()->bounded(fortunes.size())];
//! [4] //! [7]
QTcpSocket *clientConnection = tcpServer->nextPendingConnection();
diff --git a/examples/network/threadedfortuneserver/fortuneserver.cpp b/examples/network/threadedfortuneserver/fortuneserver.cpp
index a93bbc7058..73d7e22531 100644
--- a/examples/network/threadedfortuneserver/fortuneserver.cpp
+++ b/examples/network/threadedfortuneserver/fortuneserver.cpp
@@ -72,7 +72,7 @@ FortuneServer::FortuneServer(QObject *parent)
//! [1]
void FortuneServer::incomingConnection(qintptr socketDescriptor)
{
- QString fortune = fortunes.at(QRandomGenerator::global()->bounded(int(fortunes.size())));
+ QString fortune = fortunes.at(QRandomGenerator::global()->bounded(fortunes.size()));
FortuneThread *thread = new FortuneThread(socketDescriptor, fortune, this);
connect(thread, &FortuneThread::finished, thread, &FortuneThread::deleteLater);
thread->start();
diff --git a/examples/network/torrent/torrentclient.cpp b/examples/network/torrent/torrentclient.cpp
index a63e927e09..7571d77b41 100644
--- a/examples/network/torrent/torrentclient.cpp
+++ b/examples/network/torrent/torrentclient.cpp
@@ -700,7 +700,7 @@ void TorrentClient::connectToPeers()
d->connections << client;
// Pick a random peer from the list of weighed peers.
- TorrentPeer *peer = weighedPeers.takeAt(QRandomGenerator::global()->bounded(int(weighedPeers.size())));
+ TorrentPeer *peer = weighedPeers.takeAt(QRandomGenerator::global()->bounded(weighedPeers.size()));
weighedPeers.removeAll(peer);
peer->connectStart = QDateTime::currentSecsSinceEpoch();
peer->lastVisited = peer->connectStart;
@@ -1130,7 +1130,7 @@ void TorrentClient::scheduleUploads()
// random peer to allow it to compete for a position among the
// downloaders. (This is known as an "optimistic unchoke".)
if (!allClients.isEmpty()) {
- PeerWireClient *client = allClients[QRandomGenerator::global()->bounded(int(allClients.size()))];
+ PeerWireClient *client = allClients[QRandomGenerator::global()->bounded(allClients.size())];
if (client->peerWireState() & PeerWireClient::ChokingPeer)
client->unchokePeer();
}
@@ -1191,7 +1191,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
piece = d->payloads.value(client);
if (!piece) {
QList<TorrentPiece *> values = d->pendingPieces.values();
- piece = values.value(QRandomGenerator::global()->bounded(int(values.size())));
+ piece = values.value(QRandomGenerator::global()->bounded(values.size()));
piece->inProgress = true;
d->payloads.insert(client, piece);
}
@@ -1248,7 +1248,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
++it;
}
if (!partialPieces.isEmpty())
- piece = partialPieces.value(QRandomGenerator::global()->bounded(int(partialPieces.size())));
+ piece = partialPieces.value(QRandomGenerator::global()->bounded(partialPieces.size()));
if (!piece) {
// Pick a random piece 3 out of 4 times; otherwise, pick either
@@ -1295,7 +1295,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
}
// Select one piece randomly
- pieceIndex = piecesReadyForDownload.at(QRandomGenerator::global()->bounded(int(piecesReadyForDownload.size())));
+ pieceIndex = piecesReadyForDownload.at(QRandomGenerator::global()->bounded(piecesReadyForDownload.size()));
delete [] occurrences;
} else {
// Make up a list of available piece indices, and pick
@@ -1306,7 +1306,7 @@ void TorrentClient::schedulePieceForClient(PeerWireClient *client)
if (incompletePiecesAvailableToClient.testBit(i))
values << i;
}
- pieceIndex = values.at(QRandomGenerator::global()->bounded(int(values.size())));
+ pieceIndex = values.at(QRandomGenerator::global()->bounded(values.size()));
}
// Create a new TorrentPiece and fill in all initial
@@ -1398,8 +1398,8 @@ int TorrentClient::requestBlocks(PeerWireClient *client, TorrentPiece *piece, in
// speedup comes from an increased chance of receiving
// different blocks from the different peers.
for (int i = 0; i < bits.size(); ++i) {
- int a = QRandomGenerator::global()->bounded(int(bits.size()));
- int b = QRandomGenerator::global()->bounded(int(bits.size()));
+ int a = QRandomGenerator::global()->bounded(bits.size());
+ int b = QRandomGenerator::global()->bounded(bits.size());
int tmp = bits[a];
bits[a] = bits[b];
bits[b] = tmp;
diff --git a/examples/widgets/dialogs/standarddialogs/dialog.cpp b/examples/widgets/dialogs/standarddialogs/dialog.cpp
index cd7e8085a2..7df24e06f6 100644
--- a/examples/widgets/dialogs/standarddialogs/dialog.cpp
+++ b/examples/widgets/dialogs/standarddialogs/dialog.cpp
@@ -388,8 +388,14 @@ void Dialog::setColor()
void Dialog::setFont()
{
const QFontDialog::FontDialogOptions options = QFlag(fontDialogOptionsWidget->value());
+
+ const QString &description = fontLabel->text();
+ QFont defaultFont;
+ if (!description.isEmpty())
+ defaultFont.fromString(description);
+
bool ok;
- QFont font = QFontDialog::getFont(&ok, QFont(fontLabel->text()), this, "Select Font", options);
+ QFont font = QFontDialog::getFont(&ok, defaultFont, this, "Select Font", options);
if (ok) {
fontLabel->setText(font.key());
fontLabel->setFont(font);
diff --git a/examples/widgets/doc/src/addressbook-tutorial.qdoc b/examples/widgets/doc/src/addressbook-tutorial.qdoc
index 563b6a2be9..53acb82b1a 100644
--- a/examples/widgets/doc/src/addressbook-tutorial.qdoc
+++ b/examples/widgets/doc/src/addressbook-tutorial.qdoc
@@ -842,7 +842,7 @@
If \c fileName is not empty, we create a QFile object, \c file, with
\c fileName. QFile works with QDataStream as QFile is a QIODevice.
- Next, we attempt to open the file in \l{QIODevice::}{WriteOnly} mode.
+ Next, we attempt to open the file in \l{QIODeviceBase::}{WriteOnly} mode.
If this is unsuccessful, we display a QMessageBox to inform the user.
\snippet tutorials/addressbook/part6/addressbook.cpp saveToFile() function part2
@@ -869,7 +869,7 @@
\image addressbook-tutorial-part6-load.png
If \c fileName is not empty, again, we use a QFile object, \c file, and
- attempt to open it in \l{QIODevice::}{ReadOnly} mode. Similar to our
+ attempt to open it in \l{QIODeviceBase::}{ReadOnly} mode. Similar to our
implementation of \c saveToFile(), if this attempt is unsuccessful, we
display a QMessageBox to inform the user.
@@ -939,7 +939,7 @@
choose a location for the file. Using the file name chosen, we create an
instance of QFile to write to.
- We attempt to open the file in \l{QIODevice::}{WriteOnly} mode. If this
+ We attempt to open the file in \l{QIODeviceBase::}{WriteOnly} mode. If this
process fails, we display a QMessageBox to inform the user about the
problem and return. Otherwise, we pass the file as a parameter to a
QTextStream object, \c out. Like QDataStream, the QTextStream class
diff --git a/examples/widgets/doc/src/fetchmore.qdoc b/examples/widgets/doc/src/fetchmore.qdoc
index a27efaf071..940a252319 100644
--- a/examples/widgets/doc/src/fetchmore.qdoc
+++ b/examples/widgets/doc/src/fetchmore.qdoc
@@ -34,15 +34,9 @@
\image fetchmore-example.png
-
- This example consists of a dialog where you can enter a directory
- name in the \uicontrol Directory edit field. The application loads and
- visualizes all files it finds as you are typing. It is not required
- to press [Enter] to launch the search.
-
When you have large - or perhaps even infinite - data sets, you
will need to add items to the model in batches, and preferably only
- when the items are needed by the view (i.e., when they are visible
+ when the items are needed by the view (i.e., when they become visible
in the view).
In this example, we implement \c FileListModel - an item view
@@ -50,6 +44,15 @@
Window, which sets up the GUI and feeds the model with
directories.
+ The UI consists of a dialog with a list showing the contents
+ of the root directory. Directories can be navigated by double-clicking.
+
+ At the bottom, there is a log window displaying messages when the view
+ asks the model for more data.
+
+ To exercise it, navigate to a large directory (say \c /bin), and scroll
+ to the bottom. Log messages appear showing the data being retrieved.
+
Let's take a tour of \c {FileListModel}'s code.
\section1 FileListModel Class Definition
diff --git a/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp b/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp
index 7faa325469..47fc232751 100644
--- a/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp
+++ b/examples/widgets/itemviews/editabletreemodel/mainwindow.cpp
@@ -62,7 +62,7 @@ MainWindow::MainWindow(QWidget *parent)
QFile file(":/default.txt");
file.open(QIODevice::ReadOnly);
- TreeModel *model = new TreeModel(headers, file.readAll());
+ TreeModel *model = new TreeModel(headers, file.readAll(), this);
file.close();
view->setModel(model);
diff --git a/examples/widgets/itemviews/editabletreemodel/treemodel.cpp b/examples/widgets/itemviews/editabletreemodel/treemodel.cpp
index 1161a8b5d2..e8ca2afffd 100644
--- a/examples/widgets/itemviews/editabletreemodel/treemodel.cpp
+++ b/examples/widgets/itemviews/editabletreemodel/treemodel.cpp
@@ -212,6 +212,9 @@ bool TreeModel::removeRows(int position, int rows, const QModelIndex &parent)
//! [8]
int TreeModel::rowCount(const QModelIndex &parent) const
{
+ if (parent.isValid() && parent.column() > 0)
+ return 0;
+
const TreeItem *parentItem = getItem(parent);
return parentItem ? parentItem->childCount() : 0;
diff --git a/examples/widgets/itemviews/fetchmore/filelistmodel.cpp b/examples/widgets/itemviews/fetchmore/filelistmodel.cpp
index 3ee80617c0..5c93aba6f4 100644
--- a/examples/widgets/itemviews/fetchmore/filelistmodel.cpp
+++ b/examples/widgets/itemviews/fetchmore/filelistmodel.cpp
@@ -54,8 +54,10 @@
#include <QDir>
#include <QPalette>
+static const int batchSize = 100;
+
FileListModel::FileListModel(QObject *parent)
- : QAbstractListModel(parent), fileCount(0)
+ : QAbstractListModel(parent)
{}
//![4]
@@ -67,24 +69,33 @@ int FileListModel::rowCount(const QModelIndex &parent) const
QVariant FileListModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
- return QVariant();
-
- if (index.row() >= fileList.size() || index.row() < 0)
- return QVariant();
-
- if (role == Qt::DisplayRole) {
- return fileList.at(index.row());
- } else if (role == Qt::BackgroundRole) {
- int batch = (index.row() / 100) % 2;
- if (batch == 0)
- return qApp->palette().base();
- else
- return qApp->palette().alternateBase();
+ return {};
+
+ const int row = index.row();
+ if (row >= fileList.size() || row < 0)
+ return {};
+
+ switch (role) {
+ case Qt::DisplayRole:
+ return fileList.at(row).fileName();
+ case Qt::BackgroundRole: {
+ const int batch = row / batchSize;
+ const QPalette &palette = QGuiApplication::palette();
+ return (batch % 2) != 0 ? palette.alternateBase() : palette.base();
+ }
+ case Qt::DecorationRole:
+ return iconProvider.icon(fileList.at(row));
}
- return QVariant();
+ return {};
}
+
//![4]
+QFileInfo FileListModel::fileInfoAt(const QModelIndex &index) const
+{
+ return fileList.at(index.row());
+}
+
//![1]
bool FileListModel::canFetchMore(const QModelIndex &parent) const
{
@@ -99,19 +110,20 @@ void FileListModel::fetchMore(const QModelIndex &parent)
{
if (parent.isValid())
return;
- int remainder = fileList.size() - fileCount;
- int itemsToFetch = qMin(100, remainder);
+ const int start = fileCount;
+ const int remainder = int(fileList.size()) - start;
+ const int itemsToFetch = qMin(batchSize, remainder);
if (itemsToFetch <= 0)
return;
- beginInsertRows(QModelIndex(), fileCount, fileCount + itemsToFetch - 1);
+ beginInsertRows(QModelIndex(), start, start + itemsToFetch - 1);
fileCount += itemsToFetch;
endInsertRows();
- emit numberPopulated(itemsToFetch);
+ emit numberPopulated(path, start, itemsToFetch, int(fileList.size()));
}
//![2]
@@ -121,7 +133,8 @@ void FileListModel::setDirPath(const QString &path)
QDir dir(path);
beginResetModel();
- fileList = dir.entryList();
+ this->path = path;
+ fileList = dir.entryInfoList(QDir::NoDot | QDir::AllEntries, QDir::Name);
fileCount = 0;
endResetModel();
}
diff --git a/examples/widgets/itemviews/fetchmore/filelistmodel.h b/examples/widgets/itemviews/fetchmore/filelistmodel.h
index 35cf6f7b46..1cd61f8c8e 100644
--- a/examples/widgets/itemviews/fetchmore/filelistmodel.h
+++ b/examples/widgets/itemviews/fetchmore/filelistmodel.h
@@ -52,7 +52,8 @@
#define FILELISTMODEL_H
#include <QAbstractListModel>
-#include <QStringList>
+#include <QFileInfoList>
+#include <QFileIconProvider>
//![0]
class FileListModel : public QAbstractListModel
@@ -65,8 +66,10 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
+ QFileInfo fileInfoAt(const QModelIndex &) const;
+
signals:
- void numberPopulated(int number);
+ void numberPopulated(const QString &path, int start, int number, int total);
public slots:
void setDirPath(const QString &path);
@@ -76,8 +79,10 @@ protected:
void fetchMore(const QModelIndex &parent) override;
private:
- QStringList fileList;
- int fileCount;
+ QFileInfoList fileList;
+ QString path;
+ QFileIconProvider iconProvider;
+ int fileCount = 0;
};
//![0]
diff --git a/examples/widgets/itemviews/fetchmore/window.cpp b/examples/widgets/itemviews/fetchmore/window.cpp
index fa23bddc73..64746c18f8 100644
--- a/examples/widgets/itemviews/fetchmore/window.cpp
+++ b/examples/widgets/itemviews/fetchmore/window.cpp
@@ -56,37 +56,43 @@
Window::Window(QWidget *parent)
: QWidget(parent)
{
- FileListModel *model = new FileListModel(this);
- model->setDirPath(QLibraryInfo::path(QLibraryInfo::PrefixPath));
+ model = new FileListModel(this);
+ model->setDirPath(QDir::rootPath());
- QLabel *label = new QLabel(tr("&Directory:"));
- QLineEdit *lineEdit = new QLineEdit;
- label->setBuddy(lineEdit);
-
- QListView *view = new QListView;
+ view = new QListView;
view->setModel(model);
- logViewer = new QTextBrowser(this);
- logViewer->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
+ logViewer = new QPlainTextEdit(this);
+ logViewer->setReadOnly(true);
+ logViewer->setSizePolicy(QSizePolicy(QSizePolicy::Preferred,
+ QSizePolicy::Preferred));
- connect(lineEdit, &QLineEdit::textChanged,
- model, &FileListModel::setDirPath);
- connect(lineEdit, &QLineEdit::textChanged,
- logViewer, &QTextEdit::clear);
connect(model, &FileListModel::numberPopulated,
this, &Window::updateLog);
+ connect(view, &QAbstractItemView::activated,
+ this, &Window::activated);
- QGridLayout *layout = new QGridLayout;
- layout->addWidget(label, 0, 0);
- layout->addWidget(lineEdit, 0, 1);
- layout->addWidget(view, 1, 0, 1, 2);
- layout->addWidget(logViewer, 2, 0, 1, 2);
+ auto *layout = new QVBoxLayout(this);
+ layout->addWidget(view);
+ layout->addWidget(logViewer);
- setLayout(layout);
setWindowTitle(tr("Fetch More Example"));
}
-void Window::updateLog(int number)
+void Window::updateLog(const QString &path, int start, int number, int total)
+{
+ const int last = start + number - 1;
+ const QString nativePath = QDir::toNativeSeparators(path);
+ const QString message = tr("%1..%2/%3 items from \"%4\" added.")
+ .arg(start).arg(last).arg(total).arg(nativePath);
+ logViewer->appendPlainText(message);
+}
+
+void Window::activated(const QModelIndex &index)
{
- logViewer->append(tr("%1 items added.").arg(number));
+ const QFileInfo fi = model->fileInfoAt(index);
+ if (fi.isDir()) {
+ logViewer->clear();
+ model->setDirPath(fi.absoluteFilePath());
+ }
}
diff --git a/examples/widgets/itemviews/fetchmore/window.h b/examples/widgets/itemviews/fetchmore/window.h
index 61bcb94bde..1f7c2a8728 100644
--- a/examples/widgets/itemviews/fetchmore/window.h
+++ b/examples/widgets/itemviews/fetchmore/window.h
@@ -54,9 +54,13 @@
#include <QWidget>
QT_BEGIN_NAMESPACE
-class QTextBrowser;
+class QModelIndex;
+class QListView;
+class QPlainTextEdit;
QT_END_NAMESPACE
+class FileListModel;
+
class Window : public QWidget
{
Q_OBJECT
@@ -65,10 +69,13 @@ public:
Window(QWidget *parent = nullptr);
public slots:
- void updateLog(int number);
+ void updateLog(const QString &path, int start, int number, int total);
+ void activated(const QModelIndex &);
private:
- QTextBrowser *logViewer;
+ QPlainTextEdit *logViewer;
+ FileListModel *model;
+ QListView *view;
};
#endif // WINDOW_H
diff --git a/examples/widgets/mainwindows/mainwindow/toolbar.cpp b/examples/widgets/mainwindows/mainwindow/toolbar.cpp
index 2c663a1618..431a804298 100644
--- a/examples/widgets/mainwindows/mainwindow/toolbar.cpp
+++ b/examples/widgets/mainwindows/mainwindow/toolbar.cpp
@@ -264,7 +264,7 @@ void ToolBar::randomize()
QList<QAction *> randomized;
QList<QAction *> actions = this->actions();
while (!actions.isEmpty()) {
- QAction *action = actions.takeAt(QRandomGenerator::global()->bounded(int(actions.size())));
+ QAction *action = actions.takeAt(QRandomGenerator::global()->bounded(actions.size()));
randomized.append(action);
}
clear();
diff --git a/examples/widgets/painting/gradients/gradients.cpp b/examples/widgets/painting/gradients/gradients.cpp
index 76d5818d32..045da2b0c0 100644
--- a/examples/widgets/painting/gradients/gradients.cpp
+++ b/examples/widgets/painting/gradients/gradients.cpp
@@ -105,6 +105,8 @@ uint ShadeWidget::colorAt(int x)
for (int i = 1; i < pts.size(); ++i) {
if (pts.at(i - 1).x() <= x && pts.at(i).x() >= x) {
QLineF l(pts.at(i - 1), pts.at(i));
+ if (qIsNull(l.dx()))
+ continue;
l.setLength(l.length() * ((x - l.x1()) / l.dx()));
return m_shade.pixel(qRound(qMin(l.x2(), (qreal(m_shade.width() - 1)))),
qRound(qMin(l.y2(), qreal(m_shade.height() - 1))));
diff --git a/examples/widgets/painting/pathstroke/pathstroke.cpp b/examples/widgets/painting/pathstroke/pathstroke.cpp
index 412c2da6a4..bfa588f201 100644
--- a/examples/widgets/painting/pathstroke/pathstroke.cpp
+++ b/examples/widgets/painting/pathstroke/pathstroke.cpp
@@ -622,11 +622,11 @@ bool PathStrokeRenderer::event(QEvent *e)
case QEvent::TouchUpdate:
{
const QTouchEvent *const event = static_cast<const QTouchEvent*>(e);
- const QList<QTouchEvent::TouchPoint> points = event->touchPoints();
- for (const QTouchEvent::TouchPoint &touchPoint : points) {
- const int id = touchPoint.id();
- switch (touchPoint.state()) {
- case Qt::TouchPointPressed:
+ const auto points = event->points();
+ for (const auto &point : points) {
+ const int id = point.id();
+ switch (point.state()) {
+ case QEventPoint::Pressed:
{
// find the point, move it
const auto mappedPoints = m_fingerPointMapping.values();
@@ -638,32 +638,32 @@ bool PathStrokeRenderer::event(QEvent *e)
if (activePoints.contains(i))
continue;
- qreal d = QLineF(touchPoint.position(), m_points.at(i)).length();
+ qreal d = QLineF(point.position(), m_points.at(i)).length();
if ((distance < 0 && d < 12 * m_pointSize) || d < distance) {
distance = d;
activePoint = i;
}
}
if (activePoint != -1) {
- m_fingerPointMapping.insert(touchPoint.id(), activePoint);
- m_points[activePoint] = touchPoint.position();
+ m_fingerPointMapping.insert(point.id(), activePoint);
+ m_points[activePoint] = point.position();
}
break;
}
- case Qt::TouchPointReleased:
+ case QEventPoint::Released:
{
// move the point and release
QHash<int,int>::iterator it = m_fingerPointMapping.find(id);
- m_points[it.value()] = touchPoint.position();
+ m_points[it.value()] = point.position();
m_fingerPointMapping.erase(it);
break;
}
- case Qt::TouchPointMoved:
+ case QEventPoint::Updated:
{
// move the point
const int pointIdx = m_fingerPointMapping.value(id, -1);
if (pointIdx >= 0)
- m_points[pointIdx] = touchPoint.position();
+ m_points[pointIdx] = point.position();
break;
}
default:
diff --git a/examples/widgets/painting/shared/hoverpoints.cpp b/examples/widgets/painting/shared/hoverpoints.cpp
index 9fe947cedc..417d593d04 100644
--- a/examples/widgets/painting/shared/hoverpoints.cpp
+++ b/examples/widgets/painting/shared/hoverpoints.cpp
@@ -176,12 +176,12 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
case QEvent::TouchUpdate:
{
const QTouchEvent *const touchEvent = static_cast<const QTouchEvent*>(event);
- const QList<QTouchEvent::TouchPoint> points = touchEvent->touchPoints();
+ const auto points = touchEvent->points();
const qreal pointSize = qMax(m_pointSize.width(), m_pointSize.height());
- for (const QTouchEvent::TouchPoint &touchPoint : points) {
- const int id = touchPoint.id();
- switch (touchPoint.state()) {
- case Qt::TouchPointPressed:
+ for (const auto &point : points) {
+ const int id = point.id();
+ switch (point.state()) {
+ case QEventPoint::Pressed:
{
// find the point, move it
const auto mappedPoints = m_fingerPointMapping.values();
@@ -197,7 +197,7 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
if (activePoints.contains(i))
continue;
- qreal d = QLineF(touchPoint.position(), m_points.at(i)).length();
+ qreal d = QLineF(point.position(), m_points.at(i)).length();
if ((distance < 0 && d < 12 * pointSize) || d < distance) {
distance = d;
activePoint = i;
@@ -206,25 +206,25 @@ bool HoverPoints::eventFilter(QObject *object, QEvent *event)
}
}
if (activePoint != -1) {
- m_fingerPointMapping.insert(touchPoint.id(), activePoint);
- movePoint(activePoint, touchPoint.position());
+ m_fingerPointMapping.insert(point.id(), activePoint);
+ movePoint(activePoint, point.position());
}
}
break;
- case Qt::TouchPointReleased:
+ case QEventPoint::Released:
{
// move the point and release
QHash<int,int>::iterator it = m_fingerPointMapping.find(id);
- movePoint(it.value(), touchPoint.position());
+ movePoint(it.value(), point.position());
m_fingerPointMapping.erase(it);
}
break;
- case Qt::TouchPointMoved:
+ case QEventPoint::Updated:
{
// move the point
const int pointIdx = m_fingerPointMapping.value(id, -1);
if (pointIdx >= 0) // do we track this point?
- movePoint(pointIdx, touchPoint.position());
+ movePoint(pointIdx, point.position());
}
break;
default:
diff --git a/examples/widgets/richtext/textedit/.prev_CMakeLists.txt b/examples/widgets/richtext/textedit/.prev_CMakeLists.txt
index 97fde062dd..c32496a98b 100644
--- a/examples/widgets/richtext/textedit/.prev_CMakeLists.txt
+++ b/examples/widgets/richtext/textedit/.prev_CMakeLists.txt
@@ -59,6 +59,7 @@ set(textedit_resource_files
"images/mac/textleft.png"
"images/mac/textright.png"
"images/mac/textunder.png"
+ "images/mac/textundercolor.png"
"images/mac/zoomin.png"
"images/mac/zoomout.png"
"images/win/checkbox-checked.png"
@@ -82,6 +83,7 @@ set(textedit_resource_files
"images/win/textleft.png"
"images/win/textright.png"
"images/win/textunder.png"
+ "images/win/textundercolor.png"
"images/win/zoomin.png"
"images/win/zoomout.png"
)
diff --git a/examples/widgets/richtext/textedit/CMakeLists.txt b/examples/widgets/richtext/textedit/CMakeLists.txt
index a376f9f747..8940fd5abf 100644
--- a/examples/widgets/richtext/textedit/CMakeLists.txt
+++ b/examples/widgets/richtext/textedit/CMakeLists.txt
@@ -65,6 +65,7 @@ set(textedit_resource_files
"images/mac/textleft.png"
"images/mac/textright.png"
"images/mac/textunder.png"
+ "images/mac/textundercolor.png"
"images/mac/zoomin.png"
"images/mac/zoomout.png"
"images/win/checkbox-checked.png"
@@ -88,6 +89,7 @@ set(textedit_resource_files
"images/win/textleft.png"
"images/win/textright.png"
"images/win/textunder.png"
+ "images/win/textundercolor.png"
"images/win/zoomin.png"
"images/win/zoomout.png"
)
diff --git a/examples/widgets/richtext/textedit/images/mac/textundercolor.png b/examples/widgets/richtext/textedit/images/mac/textundercolor.png
new file mode 100644
index 0000000000..30e24e61c3
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/mac/textundercolor.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/images/win/textundercolor.png b/examples/widgets/richtext/textedit/images/win/textundercolor.png
new file mode 100644
index 0000000000..30e24e61c3
--- /dev/null
+++ b/examples/widgets/richtext/textedit/images/win/textundercolor.png
Binary files differ
diff --git a/examples/widgets/richtext/textedit/textedit.cpp b/examples/widgets/richtext/textedit/textedit.cpp
index 194e1e3d92..ed91f6e250 100644
--- a/examples/widgets/richtext/textedit/textedit.cpp
+++ b/examples/widgets/richtext/textedit/textedit.cpp
@@ -354,6 +354,10 @@ void TextEdit::setupTextActions()
actionTextColor = menu->addAction(pix, tr("&Color..."), this, &TextEdit::textColor);
tb->addAction(actionTextColor);
+ const QIcon underlineColorIcon(rsrcPath + "/textundercolor.png");
+ actionUnderlineColor = menu->addAction(underlineColorIcon, tr("Underline color..."), this, &TextEdit::underlineColor);
+ tb->addAction(actionUnderlineColor);
+
menu->addSeparator();
const QIcon checkboxIcon = QIcon::fromTheme("status-checkbox-checked", QIcon(rsrcPath + "/checkbox-checked.png"));
@@ -620,7 +624,7 @@ void TextEdit::textItalic()
void TextEdit::textFamily(const QString &f)
{
QTextCharFormat fmt;
- fmt.setFontFamily(f);
+ fmt.setFontFamilies({f});
mergeFormatOnWordOrSelection(fmt);
}
@@ -729,6 +733,17 @@ void TextEdit::textColor()
colorChanged(col);
}
+void TextEdit::underlineColor()
+{
+ QColor col = QColorDialog::getColor(Qt::black, this);
+ if (!col.isValid())
+ return;
+ QTextCharFormat fmt;
+ fmt.setUnderlineColor(col);
+ mergeFormatOnWordOrSelection(fmt);
+ colorChanged(col);
+}
+
void TextEdit::textAlign(QAction *a)
{
if (a == actionAlignLeft)
diff --git a/examples/widgets/richtext/textedit/textedit.h b/examples/widgets/richtext/textedit/textedit.h
index 07a307f83d..debc401150 100644
--- a/examples/widgets/richtext/textedit/textedit.h
+++ b/examples/widgets/richtext/textedit/textedit.h
@@ -95,6 +95,7 @@ private slots:
void textSize(const QString &p);
void textStyle(int styleIndex);
void textColor();
+ void underlineColor();
void textAlign(QAction *a);
void setChecked(bool checked);
void indent();
@@ -125,6 +126,7 @@ private:
QAction *actionTextUnderline;
QAction *actionTextItalic;
QAction *actionTextColor;
+ QAction *actionUnderlineColor;
QAction *actionAlignLeft;
QAction *actionAlignCenter;
QAction *actionAlignRight;
diff --git a/examples/widgets/richtext/textedit/textedit.qrc b/examples/widgets/richtext/textedit/textedit.qrc
index 1641acc207..a30d50fdbf 100644
--- a/examples/widgets/richtext/textedit/textedit.qrc
+++ b/examples/widgets/richtext/textedit/textedit.qrc
@@ -22,6 +22,7 @@
<file>images/mac/textleft.png</file>
<file>images/mac/textright.png</file>
<file>images/mac/textunder.png</file>
+ <file>images/mac/textundercolor.png</file>
<file>images/mac/zoomin.png</file>
<file>images/mac/zoomout.png</file>
<file>images/win/checkbox.png</file>
@@ -45,6 +46,7 @@
<file>images/win/textleft.png</file>
<file>images/win/textright.png</file>
<file>images/win/textunder.png</file>
+ <file>images/win/textundercolor.png</file>
<file>images/win/zoomin.png</file>
<file>images/win/zoomout.png</file>
<file>example.html</file>
diff --git a/examples/widgets/tools/CMakeLists.txt b/examples/widgets/tools/CMakeLists.txt
index 022f4a2b8f..72bc4cc44b 100644
--- a/examples/widgets/tools/CMakeLists.txt
+++ b/examples/widgets/tools/CMakeLists.txt
@@ -14,5 +14,9 @@ add_subdirectory(undoframework)
if(QT_FEATURE_library) # special case
add_subdirectory(echoplugin)
- add_subdirectory(plugandpaint) # special case
+ # special case begin
+ if(QT_FEATURE_inputdialog)
+ add_subdirectory(plugandpaint)
+ endif()
+ # special case end
endif()
diff --git a/examples/widgets/tools/plugandpaint/CMakeLists.txt b/examples/widgets/tools/plugandpaint/CMakeLists.txt
index 4e35d0d0c3..3c997faf21 100644
--- a/examples/widgets/tools/plugandpaint/CMakeLists.txt
+++ b/examples/widgets/tools/plugandpaint/CMakeLists.txt
@@ -1,7 +1,19 @@
# Generated from plugandpaint.pro.
+# special case skip regeneration
+cmake_minimum_required(VERSION 3.14)
+project(plugandpaint LANGUAGES CXX)
-if(NOT QT_FEATURE_inputdialog)
- return()
+find_package(Qt6 COMPONENTS Core Gui Widgets)
+
+set(CMAKE_AUTOMOC ON)
+set(CMAKE_AUTORCC ON)
+set(CMAKE_AUTOUIC ON)
+
+if(NOT DEFINED INSTALL_EXAMPLESDIR)
+ set(INSTALL_EXAMPLESDIR "examples")
endif()
+
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/plugandpaint")
+
add_subdirectory(plugins)
add_subdirectory(app)
diff --git a/examples/widgets/tools/plugandpaint/app/CMakeLists.txt b/examples/widgets/tools/plugandpaint/app/CMakeLists.txt
index bdf934fa2c..14cdaeb822 100644
--- a/examples/widgets/tools/plugandpaint/app/CMakeLists.txt
+++ b/examples/widgets/tools/plugandpaint/app/CMakeLists.txt
@@ -1,23 +1,5 @@
# Generated from app.pro.
-
-cmake_minimum_required(VERSION 3.14)
-project(plugandpaint LANGUAGES CXX)
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-set(CMAKE_AUTOUIC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/plugandpaint")
-
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Widgets)
+# special case skip regeneration
qt_add_executable(plugandpaint
interfaces.h
@@ -31,43 +13,9 @@ set_target_properties(plugandpaint PROPERTIES
MACOSX_BUNDLE TRUE
)
target_link_libraries(plugandpaint PUBLIC
- # Remove: L../plugins
- Qt::Core
- Qt::Gui
Qt::Widgets
- pnp_basictools # special case
+ pnp_basictools
)
-target_link_libraries(plugandpaint PUBLIC pnp_basictools) # special case
-
-if(macx-xcode)
- target_link_libraries(plugandpaint PUBLIC
- (
- )
- pnp_basictools$
- )
-endif()
-
-if(NOT macx-xcode)
- target_link_libraries(plugandpaint PUBLIC
- pnp_basictools
- )
-endif()
-
-if(((NOT (macx-xcode)) AND (( NOT debug_and_release OR build_pass ) AND CONFIG(debug,debug OR release))) AND (APPLE))
- target_link_libraries(plugandpaint PUBLIC
- (LIBS, 0)
- (LIBS, 1)
- _debug
- )
-endif()
-
-if(((NOT (macx-xcode)) AND (( NOT debug_and_release OR build_pass ) AND CONFIG(debug,debug OR release))) AND (WIN32))
- target_link_libraries(plugandpaint PUBLIC
- (LIBS, 0)
- (LIBS, 1)
- d
- )
-endif()
install(TARGETS plugandpaint
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
diff --git a/examples/widgets/tools/plugandpaint/app/app.pro b/examples/widgets/tools/plugandpaint/app/app.pro
index 558d359e7d..e5ff02ecf2 100644
--- a/examples/widgets/tools/plugandpaint/app/app.pro
+++ b/examples/widgets/tools/plugandpaint/app/app.pro
@@ -18,7 +18,11 @@ LIBS = -L../plugins
macx-xcode {
LIBS += -lpnp_basictools$($${QMAKE_XCODE_LIBRARY_SUFFIX_SETTING})
} else {
- LIBS += -lpnp_basictools
+ android {
+ LIBS += -lpnp_basictools_$${QT_ARCH}
+ } else {
+ LIBS += -lpnp_basictools
+ }
if(!debug_and_release|build_pass):CONFIG(debug, debug|release) {
mac:LIBS = $$member(LIBS, 0) $$member(LIBS, 1)_debug
win32:LIBS = $$member(LIBS, 0) $$member(LIBS, 1)d
diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/CMakeLists.txt b/examples/widgets/tools/plugandpaint/plugins/basictools/CMakeLists.txt
index 97e4021d61..c66f83ce62 100644
--- a/examples/widgets/tools/plugandpaint/plugins/basictools/CMakeLists.txt
+++ b/examples/widgets/tools/plugandpaint/plugins/basictools/CMakeLists.txt
@@ -1,23 +1,5 @@
# Generated from basictools.pro.
-
-cmake_minimum_required(VERSION 3.14)
-project(pnp_basictools LANGUAGES CXX)
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-set(CMAKE_AUTOUIC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/plugandpaint/plugins")
-
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Widgets)
+# special case skip regeneration
qt_add_plugin(pnp_basictools STATIC)
target_sources(pnp_basictools PRIVATE
@@ -36,9 +18,3 @@ target_link_libraries(pnp_basictools PUBLIC
Qt::Gui
Qt::Widgets
)
-
-install(TARGETS pnp_basictools
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/widgets/tools/plugandpaint/plugins/extrafilters/CMakeLists.txt b/examples/widgets/tools/plugandpaint/plugins/extrafilters/CMakeLists.txt
index bb6948e610..9227dd0537 100644
--- a/examples/widgets/tools/plugandpaint/plugins/extrafilters/CMakeLists.txt
+++ b/examples/widgets/tools/plugandpaint/plugins/extrafilters/CMakeLists.txt
@@ -1,31 +1,13 @@
# Generated from extrafilters.pro.
-
-cmake_minimum_required(VERSION 3.14)
-project(pnp_extrafilters LANGUAGES CXX)
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-set(CMAKE_AUTOMOC ON)
-set(CMAKE_AUTORCC ON)
-set(CMAKE_AUTOUIC ON)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/widgets/tools/plugandpaint/plugins")
-
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Widgets)
+# special case skip regeneration
qt_add_plugin(pnp_extrafilters)
target_sources(pnp_extrafilters PRIVATE
extrafiltersplugin.cpp extrafiltersplugin.h
)
set_target_properties(pnp_extrafilters PROPERTIES
- WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
+ LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/app"
)
target_include_directories(pnp_extrafilters PUBLIC
../../app
@@ -38,7 +20,6 @@ target_link_libraries(pnp_extrafilters PUBLIC
)
install(TARGETS pnp_extrafilters
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}/plugins"
+ LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}/plugins"
)
diff --git a/examples/widgets/tools/settingseditor/settingstree.cpp b/examples/widgets/tools/settingseditor/settingstree.cpp
index 04af8ce3b9..bcbf3744a5 100644
--- a/examples/widgets/tools/settingseditor/settingstree.cpp
+++ b/examples/widgets/tools/settingseditor/settingstree.cpp
@@ -214,7 +214,7 @@ void SettingsTree::updateChildItems(QTreeWidgetItem *parent)
if (value.userType() == QMetaType::UnknownType) {
child->setText(1, "Invalid");
} else {
- if (value.type() == QVariant::String) {
+ if (value.typeId() == QMetaType::QString) {
const QString stringValue = value.toString();
if (m_typeChecker->boolExp.match(stringValue).hasMatch()) {
value.setValue(stringValue.compare("true", Qt::CaseInsensitive) == 0);
diff --git a/examples/widgets/touch/fingerpaint/scribblearea.cpp b/examples/widgets/touch/fingerpaint/scribblearea.cpp
index 7af565ff30..2e6e532afb 100644
--- a/examples/widgets/touch/fingerpaint/scribblearea.cpp
+++ b/examples/widgets/touch/fingerpaint/scribblearea.cpp
@@ -196,11 +196,11 @@ bool ScribbleArea::event(QEvent *event)
case QEvent::TouchEnd:
{
const QTouchEvent *touch = static_cast<QTouchEvent *>(event);
- const QList<QTouchEvent::TouchPoint> touchPoints = static_cast<QTouchEvent *>(event)->touchPoints();
+ const auto touchPoints = static_cast<QTouchEvent *>(event)->points();
for (const QTouchEvent::TouchPoint &touchPoint : touchPoints) {
switch (touchPoint.state()) {
- case Qt::TouchPointStationary:
- case Qt::TouchPointReleased:
+ case QEventPoint::Stationary:
+ case QEventPoint::Released:
// don't do anything if this touch point hasn't moved or has been released
continue;
default:
diff --git a/examples/widgets/touch/knobs/knob.cpp b/examples/widgets/touch/knobs/knob.cpp
index 659ba82f45..eb64b56ceb 100644
--- a/examples/widgets/touch/knobs/knob.cpp
+++ b/examples/widgets/touch/knobs/knob.cpp
@@ -77,11 +77,11 @@ bool Knob::sceneEvent(QEvent *event)
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
- if (touchEvent->touchPoints().count() == 2) {
- const QTouchEvent::TouchPoint &touchPoint1 = touchEvent->touchPoints().first();
- const QTouchEvent::TouchPoint &touchPoint2 = touchEvent->touchPoints().last();
+ if (touchEvent->points().count() == 2) {
+ const QEventPoint &touchPoint1 = touchEvent->points().first();
+ const QEventPoint &touchPoint2 = touchEvent->points().last();
- QLineF line1(touchPoint1.lastScenePos(), touchPoint2.lastScenePos());
+ QLineF line1(touchPoint1.sceneLastPosition(), touchPoint2.sceneLastPosition());
QLineF line2(touchPoint1.scenePosition(), touchPoint2.scenePosition());
setTransform(QTransform().rotate(line2.angleTo(line1)), true);
diff --git a/examples/widgets/touch/pinchzoom/graphicsview.cpp b/examples/widgets/touch/pinchzoom/graphicsview.cpp
index e1ce42f93f..5ad3f9152b 100644
--- a/examples/widgets/touch/pinchzoom/graphicsview.cpp
+++ b/examples/widgets/touch/pinchzoom/graphicsview.cpp
@@ -68,15 +68,15 @@ bool GraphicsView::viewportEvent(QEvent *event)
case QEvent::TouchEnd:
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
- QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
+ const auto touchPoints = touchEvent->points();
if (touchPoints.count() == 2) {
// determine scale factor
- const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
- const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
+ const QEventPoint &touchPoint0 = touchPoints.first();
+ const QEventPoint &touchPoint1 = touchPoints.last();
qreal currentScaleFactor =
QLineF(touchPoint0.position(), touchPoint1.position()).length()
/ QLineF(touchPoint0.pressPosition(), touchPoint1.pressPosition()).length();
- if (touchEvent->touchPointStates() & Qt::TouchPointReleased) {
+ if (touchEvent->touchPointStates() & QEventPoint::Released) {
// if one of the fingers is released, remember the current scale
// factor so that adding another finger later will continue zooming
// by adding new scale factor to the existing remembered value.
diff --git a/examples/widgets/widgets/calendarwidget/window.cpp b/examples/widgets/widgets/calendarwidget/window.cpp
index 23010a6e1a..38e9798d83 100644
--- a/examples/widgets/widgets/calendarwidget/window.cpp
+++ b/examples/widgets/widgets/calendarwidget/window.cpp
@@ -237,6 +237,9 @@ void Window::createPreviewGroupBox()
}
//! [9]
+// TODO: use loc.name() as label (but has underscore in place of slash)
+// TODO: use locale() == loc instead of only comparing language and territory
+// Needs someone familiar with this example to work out ramifications
//! [10]
void Window::createGeneralOptionsGroupBox()
{
@@ -247,16 +250,16 @@ void Window::createGeneralOptionsGroupBox()
int index = 0;
for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) {
QLocale::Language lang = static_cast<QLocale::Language>(_lang);
- QList<QLocale::Country> countries = QLocale::countriesForLanguage(lang);
- for (int i = 0; i < countries.count(); ++i) {
- QLocale::Country country = countries.at(i);
+ const auto locales =
+ QLocale::matchingLocales(lang, QLocale::AnyScript, QLocale::AnyTerritory);
+ for (auto loc : locales) {
QString label = QLocale::languageToString(lang);
+ auto territory = loc.territory();
label += QLatin1Char('/');
- label += QLocale::countryToString(country);
- QLocale locale(lang, country);
- if (this->locale().language() == lang && this->locale().country() == country)
+ label += QLocale::territoryToString(territory);
+ if (locale().language() == lang && locale().territory() == territory)
curLocaleIndex = index;
- localeCombo->addItem(label, locale);
+ localeCombo->addItem(label, loc);
++index;
}
}
diff --git a/examples/widgets/widgets/imageviewer/imageviewer.cpp b/examples/widgets/widgets/imageviewer/imageviewer.cpp
index bce74a2434..6a1072afef 100644
--- a/examples/widgets/widgets/imageviewer/imageviewer.cpp
+++ b/examples/widgets/widgets/imageviewer/imageviewer.cpp
@@ -115,8 +115,11 @@ bool ImageViewer::loadFile(const QString &fileName)
setWindowFilePath(fileName);
- const QString message = tr("Opened \"%1\", %2x%3, Depth: %4")
- .arg(QDir::toNativeSeparators(fileName)).arg(image.width()).arg(image.height()).arg(image.depth());
+ const QString description = image.colorSpace().isValid()
+ ? image.colorSpace().description() : tr("unknown");
+ const QString message = tr("Opened \"%1\", %2x%3, Depth: %4 (%5)")
+ .arg(QDir::toNativeSeparators(fileName)).arg(image.width()).arg(image.height())
+ .arg(image.depth()).arg(description);
statusBar()->showMessage(message);
return true;
}
@@ -148,7 +151,7 @@ bool ImageViewer::saveFile(const QString &fileName)
if (!writer.write(image)) {
QMessageBox::information(this, QGuiApplication::applicationDisplayName(),
tr("Cannot write %1: %2")
- .arg(QDir::toNativeSeparators(fileName)), writer.errorString());
+ .arg(QDir::toNativeSeparators(fileName), writer.errorString()));
return false;
}
const QString message = tr("Wrote \"%1\"").arg(QDir::toNativeSeparators(fileName));
diff --git a/examples/widgets/widgets/stylesheet/mainwindow.cpp b/examples/widgets/widgets/stylesheet/mainwindow.cpp
index a8bd20e964..6e7bb295e1 100644
--- a/examples/widgets/widgets/stylesheet/mainwindow.cpp
+++ b/examples/widgets/widgets/stylesheet/mainwindow.cpp
@@ -76,10 +76,12 @@ void MainWindow::on_editStyleAction_triggered()
void MainWindow::on_aboutAction_triggered()
{
+ const QString url = QStringLiteral("http://doc.qt.io/qt-%1/stylesheet.html")
+ .arg(QT_VERSION_MAJOR);
QMessageBox::about(this, tr("About Style sheet"),
tr("The <b>Style Sheet</b> example shows how widgets can be styled "
- "using <a href=\"http://doc.qt.io/qt-5/stylesheet.html\">Qt "
+ "using <a href=\"%1\">Qt "
"Style Sheets</a>. Click <b>File|Edit Style Sheet</b> to pop up the "
"style editor, and either choose an existing style sheet or design "
- "your own."));
+ "your own.").arg(url));
}
diff --git a/examples/widgets/widgets/validators/localeselector.cpp b/examples/widgets/widgets/validators/localeselector.cpp
index 3dcd04d9ff..3fdf5c6b3b 100644
--- a/examples/widgets/widgets/validators/localeselector.cpp
+++ b/examples/widgets/widgets/validators/localeselector.cpp
@@ -60,18 +60,18 @@ LocaleSelector::LocaleSelector(QWidget *parent)
for (int _lang = QLocale::C; _lang <= QLocale::LastLanguage; ++_lang) {
QLocale::Language lang = static_cast<QLocale::Language>(_lang);
const QList<QLocale> locales =
- QLocale::matchingLocales(lang, QLocale::AnyScript, QLocale::AnyCountry);
+ QLocale::matchingLocales(lang, QLocale::AnyScript, QLocale::AnyTerritory);
for (const QLocale &l : locales) {
QString label = QLocale::languageToString(l.language());
label += QLatin1Char('/');
- label += QLocale::countryToString(l.country());
- // distinguish locales by script, if there are more than one script for a language/country pair
- if (QLocale::matchingLocales(l.language(), QLocale::AnyScript, l.country()).size() > 1)
+ label += QLocale::territoryToString(l.territory());
+ // distinguish locales by script, if there are more than one script for a language/territory pair
+ if (QLocale::matchingLocales(l.language(), QLocale::AnyScript, l.territory()).size() > 1)
label += QLatin1String(" (") + QLocale::scriptToString(l.script()) + QLatin1Char(')');
addItem(label, QVariant::fromValue(l));
- if (l.language() == locale().language() && l.country() == locale().country()
+ if (l.language() == locale().language() && l.territory() == locale().territory()
&& (locale().script() == QLocale::AnyScript || l.script() == locale().script())) {
curIndex = index;
}