summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>2016-08-22 11:30:00 +0200
committerOswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>2016-08-22 11:30:01 +0200
commitd314819fc02139e05e16c56657898c704f7fb48f (patch)
treea61ba968233634948401c8339f9613844de1c2b5 /examples
parent9f888d2fde9c5413e5519e0914e9b13638760985 (diff)
parente0e9e196a72ffe5457034894eaaadc90ed0d34ef (diff)
Merge dev into 5.8
Diffstat (limited to 'examples')
-rw-r--r--examples/corelib/threads/doc/src/semaphores.qdoc2
-rw-r--r--examples/dbus/dbus.pro5
-rw-r--r--examples/examples.pro2
-rw-r--r--examples/gui/gui.pro2
-rw-r--r--examples/gui/rasterwindow/rasterwindow.cpp2
-rw-r--r--examples/network/network.pro8
-rw-r--r--examples/opengl/legacy/framebufferobject2/framebufferobject2.pro2
-rw-r--r--examples/opengl/legacy/grabber/grabber.pro2
-rw-r--r--examples/opengl/legacy/hellogl/hellogl.pro2
-rw-r--r--examples/opengl/legacy/legacy.pro2
-rw-r--r--examples/opengl/legacy/overpainting/overpainting.pro2
-rw-r--r--examples/opengl/legacy/pbuffers/pbuffers.pro2
-rw-r--r--examples/opengl/legacy/pbuffers2/pbuffers2.pro2
-rw-r--r--examples/opengl/legacy/samplebuffers/samplebuffers.pro2
-rw-r--r--examples/widgets/desktop/systray/doc/src/systray.qdoc4
-rw-r--r--examples/widgets/dialogs/findfiles/window.cpp139
-rw-r--r--examples/widgets/dialogs/findfiles/window.h6
-rw-r--r--examples/widgets/doc/dropsite.qdoc2
-rw-r--r--examples/widgets/doc/src/application.qdoc6
-rw-r--r--examples/widgets/doc/src/classwizard.qdoc4
-rw-r--r--examples/widgets/doc/src/findfiles.qdoc38
-rw-r--r--examples/widgets/doc/src/licensewizard.qdoc4
-rw-r--r--examples/widgets/doc/src/plugandpaint.qdoc2
-rw-r--r--examples/widgets/draganddrop/draggabletext/dragwidget.cpp4
-rw-r--r--examples/widgets/graphicsview/boxes/boxes.pro2
-rw-r--r--examples/widgets/graphicsview/graphicsview.pro2
-rw-r--r--examples/widgets/painting/composition/composition.pro2
-rw-r--r--examples/widgets/painting/shared/shared.pri2
-rw-r--r--examples/widgets/tools/codecs/mainwindow.cpp137
-rw-r--r--examples/widgets/tools/codecs/mainwindow.h16
-rw-r--r--examples/widgets/tools/codecs/previewform.cpp176
-rw-r--r--examples/widgets/tools/codecs/previewform.h16
-rw-r--r--examples/widgets/tools/plugandpaint/app/app.pro13
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/basictools/basictools.pro1
-rw-r--r--examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafilters.pro1
-rw-r--r--examples/widgets/widgets.pro4
-rw-r--r--examples/widgets/widgets/charactermap/characterwidget.cpp17
-rw-r--r--examples/widgets/widgets/charactermap/characterwidget.h2
-rw-r--r--examples/widgets/widgets/charactermap/mainwindow.cpp121
-rw-r--r--examples/widgets/widgets/charactermap/mainwindow.h6
-rw-r--r--examples/widgets/widgets/icons/images/designer.pngbin4205 -> 3604 bytes
-rw-r--r--examples/widgets/widgets/icons/images/qt_extended_16x16.pngbin524 -> 1263 bytes
-rw-r--r--examples/widgets/widgets/icons/images/qt_extended_32x32.pngbin892 -> 15518 bytes
-rw-r--r--examples/widgets/widgets/icons/images/qt_extended_48x48.pngbin1294 -> 789 bytes
44 files changed, 529 insertions, 235 deletions
diff --git a/examples/corelib/threads/doc/src/semaphores.qdoc b/examples/corelib/threads/doc/src/semaphores.qdoc
index b1a1fc1ed2..ccbfcdb6e2 100644
--- a/examples/corelib/threads/doc/src/semaphores.qdoc
+++ b/examples/corelib/threads/doc/src/semaphores.qdoc
@@ -129,7 +129,7 @@
\c{freeBytes.available()} is \c BufferSize - 1 and
\c{usedBytes.available()} is 1. At that point, two things can
happen: Either the consumer thread takes over and reads that
- byte, or the consumer gets to produce a second byte.
+ byte, or the producer thread gets to produce a second byte.
The producer-consumer model presented in this example makes it
possible to write highly concurrent multithreaded applications.
diff --git a/examples/dbus/dbus.pro b/examples/dbus/dbus.pro
index 083e442dfb..afeb1de0d5 100644
--- a/examples/dbus/dbus.pro
+++ b/examples/dbus/dbus.pro
@@ -2,8 +2,9 @@ requires(qtHaveModule(dbus))
TEMPLATE = subdirs
SUBDIRS = listnames \
- pingpong \
- complexpingpong
+ pingpong
+
+!uikit: SUBDIRS += complexpingpong
qtHaveModule(widgets) {
SUBDIRS += chat \
diff --git a/examples/examples.pro b/examples/examples.pro
index bcc13704dc..b57d281384 100644
--- a/examples/examples.pro
+++ b/examples/examples.pro
@@ -15,7 +15,7 @@ SUBDIRS = \
widgets \
xml
-contains(QT_CONFIG, opengl): SUBDIRS += opengl
+qtConfig(opengl): SUBDIRS += opengl
aggregate.files = aggregate/examples.pro
aggregate.path = $$[QT_INSTALL_EXAMPLES]
diff --git a/examples/gui/gui.pro b/examples/gui/gui.pro
index 3a63ffb5eb..e4fec201d7 100644
--- a/examples/gui/gui.pro
+++ b/examples/gui/gui.pro
@@ -5,6 +5,6 @@ CONFIG += no_docs_target
SUBDIRS += analogclock
SUBDIRS += rasterwindow
-contains(QT_CONFIG, opengl(es2)?) {
+qtConfig(opengl(es2)?) {
SUBDIRS += openglwindow
}
diff --git a/examples/gui/rasterwindow/rasterwindow.cpp b/examples/gui/rasterwindow/rasterwindow.cpp
index c44222b13d..eb34bec252 100644
--- a/examples/gui/rasterwindow/rasterwindow.cpp
+++ b/examples/gui/rasterwindow/rasterwindow.cpp
@@ -55,8 +55,8 @@ RasterWindow::RasterWindow(QWindow *parent)
: QWindow(parent)
, m_update_pending(false)
{
- m_backingStore = new QBackingStore(this);
create();
+ m_backingStore = new QBackingStore(this);
setGeometry(100, 100, 300, 200);
diff --git a/examples/network/network.pro b/examples/network/network.pro
index 6a09acaae8..a6a6f3ef52 100644
--- a/examples/network/network.pro
+++ b/examples/network/network.pro
@@ -21,7 +21,7 @@ qtHaveModule(widgets) {
load(qfeatures)
!contains(QT_DISABLED_FEATURES, bearermanagement) {
# no QProcess
- !vxworks:!qnx:!winrt:!integrity: SUBDIRS += network-chat
+ !vxworks:!qnx:!winrt:!integrity:!uikit: SUBDIRS += network-chat
SUBDIRS += \
bearermonitor \
@@ -30,9 +30,9 @@ qtHaveModule(widgets) {
}
- contains(QT_CONFIG, openssl):SUBDIRS += securesocketclient
- contains(QT_CONFIG, openssl-linked):SUBDIRS += securesocketclient
- contains(QT_CONFIG, sctp):SUBDIRS += multistreamserver multistreamclient
+ qtConfig(openssl): SUBDIRS += securesocketclient
+ qtConfig(openssl-linked): SUBDIRS += securesocketclient
+ qtConfig(sctp): SUBDIRS += multistreamserver multistreamclient
}
EXAMPLE_FILES = shared
diff --git a/examples/opengl/legacy/framebufferobject2/framebufferobject2.pro b/examples/opengl/legacy/framebufferobject2/framebufferobject2.pro
index 78fc6b1a63..3f2578bc1f 100644
--- a/examples/opengl/legacy/framebufferobject2/framebufferobject2.pro
+++ b/examples/opengl/legacy/framebufferobject2/framebufferobject2.pro
@@ -8,4 +8,4 @@ QT += opengl widgets
target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/framebufferobject2
INSTALLS += target
-contains(QT_CONFIG, opengles.|angle|dynamicgl):error("This example requires Qt to be configured with -opengl desktop")
+qtConfig(opengles.|angle|dynamicgl): error("This example requires Qt to be configured with -opengl desktop")
diff --git a/examples/opengl/legacy/grabber/grabber.pro b/examples/opengl/legacy/grabber/grabber.pro
index 1db0e23156..88c03f1c5e 100644
--- a/examples/opengl/legacy/grabber/grabber.pro
+++ b/examples/opengl/legacy/grabber/grabber.pro
@@ -9,4 +9,4 @@ QT += opengl widgets
target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/grabber
INSTALLS += target
-contains(QT_CONFIG, opengles.|angle|dynamicgl):error("This example requires Qt to be configured with -opengl desktop")
+qtConfig(opengles.|angle|dynamicgl): error("This example requires Qt to be configured with -opengl desktop")
diff --git a/examples/opengl/legacy/hellogl/hellogl.pro b/examples/opengl/legacy/hellogl/hellogl.pro
index c211242fd2..c6e926c245 100644
--- a/examples/opengl/legacy/hellogl/hellogl.pro
+++ b/examples/opengl/legacy/hellogl/hellogl.pro
@@ -14,4 +14,4 @@ QT += opengl widgets
target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/hellogl
INSTALLS += target
-contains(QT_CONFIG, opengles.|angle):error("This example requires Qt to be configured with -opengl desktop")
+qtConfig(opengles.|angle): error("This example requires Qt to be configured with -opengl desktop")
diff --git a/examples/opengl/legacy/legacy.pro b/examples/opengl/legacy/legacy.pro
index 0a74d50f7f..1398332c11 100644
--- a/examples/opengl/legacy/legacy.pro
+++ b/examples/opengl/legacy/legacy.pro
@@ -2,7 +2,7 @@ requires(qtHaveModule(opengl))
TEMPLATE = subdirs
-!contains(QT_CONFIG, dynamicgl): !contains(QT_CONFIG, opengles2) {
+!qtConfig(dynamicgl):!qtConfig(opengles2) {
# legacy desktop-only examples, no dynamic GL support
SUBDIRS = \
grabber \
diff --git a/examples/opengl/legacy/overpainting/overpainting.pro b/examples/opengl/legacy/overpainting/overpainting.pro
index cc46f18889..17213a6079 100644
--- a/examples/opengl/legacy/overpainting/overpainting.pro
+++ b/examples/opengl/legacy/overpainting/overpainting.pro
@@ -16,4 +16,4 @@ SOURCES = bubble.cpp \
target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/overpainting
INSTALLS += target
-contains(QT_CONFIG, opengles.|angle):error("This example requires Qt to be configured with -opengl desktop")
+qtConfig(opengles.|angle): error("This example requires Qt to be configured with -opengl desktop")
diff --git a/examples/opengl/legacy/pbuffers/pbuffers.pro b/examples/opengl/legacy/pbuffers/pbuffers.pro
index d779a2a2dc..7572ba3583 100644
--- a/examples/opengl/legacy/pbuffers/pbuffers.pro
+++ b/examples/opengl/legacy/pbuffers/pbuffers.pro
@@ -10,4 +10,4 @@ QT += opengl widgets
target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/pbuffers
INSTALLS += target
-contains(QT_CONFIG, opengles.|angle|dynamicgl):error("This example requires Qt to be configured with -opengl desktop")
+qtConfig(opengles.|angle|dynamicgl): error("This example requires Qt to be configured with -opengl desktop")
diff --git a/examples/opengl/legacy/pbuffers2/pbuffers2.pro b/examples/opengl/legacy/pbuffers2/pbuffers2.pro
index 2ba40a6f74..f1baae3931 100644
--- a/examples/opengl/legacy/pbuffers2/pbuffers2.pro
+++ b/examples/opengl/legacy/pbuffers2/pbuffers2.pro
@@ -8,4 +8,4 @@ RESOURCES += pbuffers2.qrc
target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/pbuffers2
INSTALLS += target
-contains(QT_CONFIG, opengles.|angle|dynamicgl):error("This example requires Qt to be configured with -opengl desktop")
+qtConfig(opengles.|angle|dynamicgl): error("This example requires Qt to be configured with -opengl desktop")
diff --git a/examples/opengl/legacy/samplebuffers/samplebuffers.pro b/examples/opengl/legacy/samplebuffers/samplebuffers.pro
index 3719f5039d..aca56f8df8 100644
--- a/examples/opengl/legacy/samplebuffers/samplebuffers.pro
+++ b/examples/opengl/legacy/samplebuffers/samplebuffers.pro
@@ -7,4 +7,4 @@ QT += opengl widgets
target.path = $$[QT_INSTALL_EXAMPLES]/opengl/legacy/samplebuffers
INSTALLS += target
-contains(QT_CONFIG, opengles.|angle|dynamicgl):error("This example requires Qt to be configured with -opengl desktop")
+qtConfig(opengles.|angle|dynamicgl): error("This example requires Qt to be configured with -opengl desktop")
diff --git a/examples/widgets/desktop/systray/doc/src/systray.qdoc b/examples/widgets/desktop/systray/doc/src/systray.qdoc
index aa70561638..b89fed72e0 100644
--- a/examples/widgets/desktop/systray/doc/src/systray.qdoc
+++ b/examples/widgets/desktop/systray/doc/src/systray.qdoc
@@ -137,7 +137,7 @@
to show the message with the title, body, and icon for the time
specified in milliseconds.
- OS X users note: The Growl notification system must be
+ \macos users note: The Growl notification system must be
installed for QSystemTrayIcon::showMessage() to display messages.
QSystemTrayIcon also has the corresponding, \l {QSystemTrayIcon::}
@@ -172,7 +172,7 @@
We have reimplemented the QWidget::closeEvent() event handler to
receive widget close events, showing the above message to the
- users when they are closing the editor window. On OS X we need to
+ users when they are closing the editor window. On \macos we need to
avoid showing the message and accepting the close event when the
user really intends to quit the application, that is, when the
user has triggered "Quit" in the menu bar or pressed the Command+Q
diff --git a/examples/widgets/dialogs/findfiles/window.cpp b/examples/widgets/dialogs/findfiles/window.cpp
index 2f9b187bf0..05e160ed87 100644
--- a/examples/widgets/dialogs/findfiles/window.cpp
+++ b/examples/widgets/dialogs/findfiles/window.cpp
@@ -52,51 +52,72 @@
#include "window.h"
+//! [17]
+enum { absoluteFileNameRole = Qt::UserRole + 1 };
+//! [17]
+
+//! [18]
+static inline QString fileNameOfItem(const QTableWidgetItem *item)
+{
+ return item->data(absoluteFileNameRole).toString();
+}
+//! [18]
+
+//! [14]
+static inline void openFile(const QString &fileName)
+{
+ QDesktopServices::openUrl(QUrl::fromLocalFile(fileName));
+}
+//! [14]
+
//! [0]
Window::Window(QWidget *parent)
: QWidget(parent)
{
- browseButton = new QPushButton(tr("&Browse..."), this);
+ QPushButton *browseButton = new QPushButton(tr("&Browse..."), this);
connect(browseButton, &QAbstractButton::clicked, this, &Window::browse);
findButton = new QPushButton(tr("&Find"), this);
connect(findButton, &QAbstractButton::clicked, this, &Window::find);
fileComboBox = createComboBox(tr("*"));
+ connect(fileComboBox->lineEdit(), &QLineEdit::returnPressed,
+ this, &Window::animateFindClick);
textComboBox = createComboBox();
- directoryComboBox = createComboBox(QDir::currentPath());
+ connect(textComboBox->lineEdit(), &QLineEdit::returnPressed,
+ this, &Window::animateFindClick);
+ directoryComboBox = createComboBox(QDir::toNativeSeparators(QDir::currentPath()));
+ connect(directoryComboBox->lineEdit(), &QLineEdit::returnPressed,
+ this, &Window::animateFindClick);
- fileLabel = new QLabel(tr("Named:"));
- textLabel = new QLabel(tr("Containing text:"));
- directoryLabel = new QLabel(tr("In directory:"));
filesFoundLabel = new QLabel;
createFilesTable();
//! [0]
//! [1]
- QGridLayout *mainLayout = new QGridLayout;
- mainLayout->addWidget(fileLabel, 0, 0);
+ QGridLayout *mainLayout = new QGridLayout(this);
+ mainLayout->addWidget(new QLabel(tr("Named:")), 0, 0);
mainLayout->addWidget(fileComboBox, 0, 1, 1, 2);
- mainLayout->addWidget(textLabel, 1, 0);
+ mainLayout->addWidget(new QLabel(tr("Containing text:")), 1, 0);
mainLayout->addWidget(textComboBox, 1, 1, 1, 2);
- mainLayout->addWidget(directoryLabel, 2, 0);
+ mainLayout->addWidget(new QLabel(tr("In directory:")), 2, 0);
mainLayout->addWidget(directoryComboBox, 2, 1);
mainLayout->addWidget(browseButton, 2, 2);
mainLayout->addWidget(filesTable, 3, 0, 1, 3);
mainLayout->addWidget(filesFoundLabel, 4, 0, 1, 2);
mainLayout->addWidget(findButton, 4, 2);
- setLayout(mainLayout);
setWindowTitle(tr("Find Files"));
- resize(700, 300);
+ const QRect screenGeometry = QApplication::desktop()->screenGeometry(this);
+ resize(screenGeometry.width() / 2, screenGeometry.height() / 3);
}
//! [1]
//! [2]
void Window::browse()
{
- QString directory = QFileDialog::getExistingDirectory(this,
- tr("Find Files"), QDir::currentPath());
+ QString directory =
+ QDir::toNativeSeparators(QFileDialog::getExistingDirectory(this, tr("Find Files"), QDir::currentPath()));
if (!directory.isEmpty()) {
if (directoryComboBox->findText(directory) == -1)
@@ -112,14 +133,28 @@ static void updateComboBox(QComboBox *comboBox)
comboBox->addItem(comboBox->currentText());
}
+//! [13]
+
+static void findRecursion(const QString &path, const QString &pattern, QStringList *result)
+{
+ QDir currentDir(path);
+ const QString prefix = path + QLatin1Char('/');
+ foreach (const QString &match, currentDir.entryList(QStringList(pattern), QDir::Files | QDir::NoSymLinks))
+ result->append(prefix + match);
+ foreach (const QString &dir, currentDir.entryList(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot))
+ findRecursion(prefix + dir, pattern, result);
+}
+
+//! [13]
//! [3]
+
void Window::find()
{
filesTable->setRowCount(0);
QString fileName = fileComboBox->currentText();
QString text = textComboBox->currentText();
- QString path = directoryComboBox->currentText();
+ QString path = QDir::cleanPath(directoryComboBox->currentText());
//! [3]
updateComboBox(fileComboBox);
@@ -127,19 +162,21 @@ void Window::find()
updateComboBox(directoryComboBox);
//! [4]
+
currentDir = QDir(path);
QStringList files;
- if (fileName.isEmpty())
- fileName = "*";
- files = currentDir.entryList(QStringList(fileName),
- QDir::Files | QDir::NoSymLinks);
-
+ findRecursion(path, fileName.isEmpty() ? QStringLiteral("*") : fileName, &files);
if (!text.isEmpty())
files = findFiles(files, text);
showFiles(files);
}
//! [4]
+void Window::animateFindClick()
+{
+ findButton->animateClick();
+}
+
//! [5]
QStringList Window::findFiles(const QStringList &files, const QString &text)
{
@@ -149,21 +186,26 @@ QStringList Window::findFiles(const QStringList &files, const QString &text)
progressDialog.setWindowTitle(tr("Find Files"));
//! [5] //! [6]
+ QMimeDatabase mimeDatabase;
QStringList foundFiles;
for (int i = 0; i < files.size(); ++i) {
progressDialog.setValue(i);
- progressDialog.setLabelText(tr("Searching file number %1 of %2...")
- .arg(i).arg(files.size()));
- qApp->processEvents();
+ progressDialog.setLabelText(tr("Searching file number %1 of %n...", 0, files.size()).arg(i));
+ QCoreApplication::processEvents();
//! [6]
if (progressDialog.wasCanceled())
break;
//! [7]
- QFile file(currentDir.absoluteFilePath(files[i]));
-
+ const QString fileName = files.at(i);
+ const QMimeType mimeType = mimeDatabase.mimeTypeForFile(fileName);
+ if (mimeType.isValid() && !mimeType.inherits(QStringLiteral("text/plain"))) {
+ qWarning() << "Not searching binary file " << QDir::toNativeSeparators(fileName);
+ continue;
+ }
+ QFile file(fileName);
if (file.open(QIODevice::ReadOnly)) {
QString line;
QTextStream in(&file);
@@ -171,7 +213,7 @@ QStringList Window::findFiles(const QStringList &files, const QString &text)
if (progressDialog.wasCanceled())
break;
line = in.readLine();
- if (line.contains(text)) {
+ if (line.contains(text, Qt::CaseInsensitive)) {
foundFiles << files[i];
break;
}
@@ -186,13 +228,18 @@ QStringList Window::findFiles(const QStringList &files, const QString &text)
void Window::showFiles(const QStringList &files)
{
for (int i = 0; i < files.size(); ++i) {
- QFile file(currentDir.absoluteFilePath(files[i]));
- qint64 size = QFileInfo(file).size();
-
- QTableWidgetItem *fileNameItem = new QTableWidgetItem(files[i]);
+ const QString &fileName = files.at(i);
+ const QString toolTip = QDir::toNativeSeparators(fileName);
+ const QString relativePath = QDir::toNativeSeparators(currentDir.relativeFilePath(fileName));
+ const qint64 size = QFileInfo(fileName).size();
+ QTableWidgetItem *fileNameItem = new QTableWidgetItem(relativePath);
+ fileNameItem->setData(absoluteFileNameRole, QVariant(fileName));
+ fileNameItem->setToolTip(toolTip);
fileNameItem->setFlags(fileNameItem->flags() ^ Qt::ItemIsEditable);
QTableWidgetItem *sizeItem = new QTableWidgetItem(tr("%1 KB")
.arg(int((size + 1023) / 1024)));
+ sizeItem->setData(absoluteFileNameRole, QVariant(fileName));
+ sizeItem->setToolTip(toolTip);
sizeItem->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
sizeItem->setFlags(sizeItem->flags() ^ Qt::ItemIsEditable);
@@ -201,8 +248,7 @@ void Window::showFiles(const QStringList &files)
filesTable->setItem(row, 0, fileNameItem);
filesTable->setItem(row, 1, sizeItem);
}
- filesFoundLabel->setText(tr("%1 file(s) found").arg(files.size()) +
- (" (Double click on a file to open it)"));
+ filesFoundLabel->setText(tr("%n file(s) found (Double click on a file to open it)", 0, files.size()));
filesFoundLabel->setWordWrap(true);
}
//! [8]
@@ -230,20 +276,43 @@ void Window::createFilesTable()
filesTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
filesTable->verticalHeader()->hide();
filesTable->setShowGrid(false);
-
+//! [15]
+ filesTable->setContextMenuPolicy(Qt::CustomContextMenu);
+ connect(filesTable, &QTableWidget::customContextMenuRequested,
+ this, &Window::contextMenu);
connect(filesTable, &QTableWidget::cellActivated,
this, &Window::openFileOfItem);
+//! [15]
}
//! [11]
+
//! [12]
void Window::openFileOfItem(int row, int /* column */)
{
- QTableWidgetItem *item = filesTable->item(row, 0);
-
- QDesktopServices::openUrl(QUrl::fromLocalFile(currentDir.absoluteFilePath(item->text())));
+ const QTableWidgetItem *item = filesTable->item(row, 0);
+ openFile(fileNameOfItem(item));
}
//! [12]
+//! [16]
+void Window::contextMenu(const QPoint &pos)
+{
+ const QTableWidgetItem *item = filesTable->itemAt(pos);
+ if (!item)
+ return;
+ QMenu menu;
+ QAction *copyAction = menu.addAction("Copy Name");
+ QAction *openAction = menu.addAction("Open");
+ QAction *action = menu.exec(filesTable->mapToGlobal(pos));
+ if (!action)
+ return;
+ const QString fileName = fileNameOfItem(item);
+ if (action == copyAction)
+ QGuiApplication::clipboard()->setText(QDir::toNativeSeparators(fileName));
+ else if (action == openAction)
+ openFile(fileName);
+}
+//! [16]
diff --git a/examples/widgets/dialogs/findfiles/window.h b/examples/widgets/dialogs/findfiles/window.h
index ae4f49b726..fe217381e2 100644
--- a/examples/widgets/dialogs/findfiles/window.h
+++ b/examples/widgets/dialogs/findfiles/window.h
@@ -73,7 +73,9 @@ public:
private slots:
void browse();
void find();
+ void animateFindClick();
void openFileOfItem(int row, int column);
+ void contextMenu(const QPoint &pos);
private:
QStringList findFiles(const QStringList &files, const QString &text);
@@ -84,11 +86,7 @@ private:
QComboBox *fileComboBox;
QComboBox *textComboBox;
QComboBox *directoryComboBox;
- QLabel *fileLabel;
- QLabel *textLabel;
- QLabel *directoryLabel;
QLabel *filesFoundLabel;
- QPushButton *browseButton;
QPushButton *findButton;
QTableWidget *filesTable;
diff --git a/examples/widgets/doc/dropsite.qdoc b/examples/widgets/doc/dropsite.qdoc
index ee350717e2..32bcfe8916 100644
--- a/examples/widgets/doc/dropsite.qdoc
+++ b/examples/widgets/doc/dropsite.qdoc
@@ -222,7 +222,7 @@
and Qt::AlignLeft.
A QString object, \c text, is customized to display data according to the
- contents of \c format. We invoke {QString}'s \l{QString::simplified()}
+ contents of \c format. We invoke \l{QString}'s \l{QString::simplified()}
{simplified()} function on \c text, to obtain a string that has no
additional space before, after or in between words.
diff --git a/examples/widgets/doc/src/application.qdoc b/examples/widgets/doc/src/application.qdoc
index ba45ec4e16..040aa171b7 100644
--- a/examples/widgets/doc/src/application.qdoc
+++ b/examples/widgets/doc/src/application.qdoc
@@ -234,7 +234,7 @@
Just before we create the \uicontrol{Help} menu, we call
QMenuBar::addSeparator(). This has no effect for most widget
- styles (e.g., Windows and OS X styles), but for some
+ styles (e.g., Windows and \macos styles), but for some
styles this makes sure that \uicontrol{Help} is pushed to the right
side of the menu bar.
@@ -253,7 +253,7 @@
load the user's preferences and other application settings. The
QSettings class provides a high-level interface for storing
settings permanently on disk. On Windows, it uses the (in)famous
- Windows registry; on OS X, it uses the native XML-based
+ Windows registry; on \macos, it uses the native XML-based
CFPreferences API; on Unix/X11, it uses text files.
The QSettings constructor takes arguments that identify your
@@ -305,7 +305,7 @@
We start by opening the file in read-only mode. The QFile::Text
flag indicates that the file is a text file, not a binary file.
- On Unix and OS X, this makes no difference, but on Windows,
+ On Unix and \macos, this makes no difference, but on Windows,
it ensures that the "\\r\\n" end-of-line sequence is converted to
"\\n" when reading.
diff --git a/examples/widgets/doc/src/classwizard.qdoc b/examples/widgets/doc/src/classwizard.qdoc
index 9391e0e133..6977cf5efa 100644
--- a/examples/widgets/doc/src/classwizard.qdoc
+++ b/examples/widgets/doc/src/classwizard.qdoc
@@ -76,7 +76,7 @@
\endlist
Although the program is just an example, if you press \uicontrol Finish
- (\uicontrol Done on OS X), actual C++ source files will actually be
+ (\uicontrol Done on \macos), actual C++ source files will actually be
generated.
\section1 The ClassWizard Class
@@ -158,7 +158,7 @@
layouts. The \c className field is created with an asterisk (\c
*) next to its name. This makes it a \l{mandatory fields}{mandatory field}, that
is, a field that must be filled before the user can press the
- \uicontrol Next button (\uicontrol Continue on OS X). The fields' values
+ \uicontrol Next button (\uicontrol Continue on \macos). The fields' values
can be accessed from any other page using QWizardPage::field(),
or from the wizard code using QWizard::field().
diff --git a/examples/widgets/doc/src/findfiles.qdoc b/examples/widgets/doc/src/findfiles.qdoc
index 700105e100..b8363dc698 100644
--- a/examples/widgets/doc/src/findfiles.qdoc
+++ b/examples/widgets/doc/src/findfiles.qdoc
@@ -120,10 +120,12 @@
\snippet dialogs/findfiles/window.cpp 4
We use the directory's path to create a QDir; the QDir class
- provides access to directory structures and their contents. We
- create a list of the files (contained in the newly created QDir)
- that match the specified file name. If the file name is empty
- the list will contain all the files in the directory.
+ provides access to directory structures and their contents.
+
+ \snippet dialogs/findfiles/window.cpp 13
+
+ We recursively create a list of the files (contained in the newl
+ created QDir) that match the specified file name.
Then we search through all the files in the list, using the private
\c findFiles() function, eliminating the ones that don't contain
@@ -173,9 +175,7 @@
\snippet dialogs/findfiles/window.cpp 7
- After updating the QProgressDialog, we create a QFile using the
- QDir::absoluteFilePath() function which returns the absolute path
- name of a file in the directory. We open the file in read-only
+ After updating the QProgressDialog, we open the file in read-only
mode, and read one line at a time using QTextStream.
The QTextStream class provides a convenient interface for reading
@@ -194,9 +194,18 @@
Both the \c findFiles() and \c showFiles() functions are called from
the \c find() slot. In the \c showFiles() function we run through
- the provided list of file names, adding each file name to the
+ the provided list of file names, adding each relative file name to the
first column in the table widget and retrieving the file's size using
- QFile and QFileInfo for the second column.
+ QFileInfo for the second column. For later use, we set
+ the absolute path as a data on the QTableWidget using the
+ the role absoluteFileNameRole defined to be Qt::UserRole + 1.
+
+ \snippet dialogs/findfiles/window.cpp 17
+
+ This allows for retrieving the name of an item using a
+ convenience function:
+
+ \snippet dialogs/findfiles/window.cpp 18
We also update the total number of files found.
@@ -236,8 +245,19 @@
\snippet dialogs/findfiles/window.cpp 12
+ \snippet dialogs/findfiles/window.cpp 14
+
The \c openFileOfItem() slot is invoked when the user double
clicks on a cell in the table. The QDesktopServices::openUrl()
knows how to open a file given the file name.
+
+ \snippet dialogs/findfiles/window.cpp 15
+ \snippet dialogs/findfiles/window.cpp 16
+
+ We set the context menu policy to of the table view to Qt::CustomContextMenu
+ and connect a slot contextMenu() to its signal
+ customContextMenuRequested(). We retrieve the absolute file name
+ from the data of the QTableWidgetItem and populate the context menu
+ with actions offering to copy the file name and to open the file.
*/
diff --git a/examples/widgets/doc/src/licensewizard.qdoc b/examples/widgets/doc/src/licensewizard.qdoc
index 6f89be5698..30f1a876d2 100644
--- a/examples/widgets/doc/src/licensewizard.qdoc
+++ b/examples/widgets/doc/src/licensewizard.qdoc
@@ -94,7 +94,7 @@
\snippet dialogs/licensewizard/licensewizard.cpp 4
We set the style to \l{QWizard::}{ModernStyle} on all platforms
- except OS X,
+ except \macos,
\snippet dialogs/licensewizard/licensewizard.cpp 5
\snippet dialogs/licensewizard/licensewizard.cpp 6
@@ -160,7 +160,7 @@
layouts. The fields are created with an asterisk (\c
*) next to their name. This makes them \l{mandatory fields}, that
is, fields that must be filled before the user can press the
- \uicontrol Next button (\uicontrol Continue on OS X). The fields' values
+ \uicontrol Next button (\uicontrol Continue on \macos). The fields' values
can be accessed from any other page using QWizardPage::field().
Resetting the page amounts to clearing the two text fields.
diff --git a/examples/widgets/doc/src/plugandpaint.qdoc b/examples/widgets/doc/src/plugandpaint.qdoc
index 5495ae8097..d3044860ab 100644
--- a/examples/widgets/doc/src/plugandpaint.qdoc
+++ b/examples/widgets/doc/src/plugandpaint.qdoc
@@ -162,7 +162,7 @@
subdirectory of the Plug & Paint example. On Unix, this is just a
matter of initializing the QDir variable with
QApplication::applicationDirPath(), the path of the executable
- file, and to do a \l{QDir::cd()}{cd()}. On Windows and OS X,
+ file, and to do a \l{QDir::cd()}{cd()}. On Windows and \macos,
this file is usually located in a subdirectory, so we need to
take this into account.
diff --git a/examples/widgets/draganddrop/draggabletext/dragwidget.cpp b/examples/widgets/draganddrop/draggabletext/dragwidget.cpp
index b184fcf060..fb169b953b 100644
--- a/examples/widgets/draganddrop/draggabletext/dragwidget.cpp
+++ b/examples/widgets/draganddrop/draggabletext/dragwidget.cpp
@@ -160,7 +160,9 @@ void DragWidget::mousePressEvent(QMouseEvent *event)
mimeData->setData(hotSpotMimeDataKey(),
QByteArray::number(hotSpot.x()) + ' ' + QByteArray::number(hotSpot.y()));
- QPixmap pixmap(child->size());
+ qreal dpr = window()->windowHandle()->devicePixelRatio();
+ QPixmap pixmap(child->size() * dpr);
+ pixmap.setDevicePixelRatio(dpr);
child->render(&pixmap);
QDrag *drag = new QDrag(this);
diff --git a/examples/widgets/graphicsview/boxes/boxes.pro b/examples/widgets/graphicsview/boxes/boxes.pro
index 14d22537e8..afdca816b1 100644
--- a/examples/widgets/graphicsview/boxes/boxes.pro
+++ b/examples/widgets/graphicsview/boxes/boxes.pro
@@ -1,6 +1,6 @@
QT += opengl widgets
-contains(QT_CONFIG, opengles.|angle|dynamicgl):error("This example requires Qt to be configured with -opengl desktop")
+qtConfig(opengles.|angle|dynamicgl): error("This example requires Qt to be configured with -opengl desktop")
HEADERS += 3rdparty/fbm.h \
glbuffers.h \
diff --git a/examples/widgets/graphicsview/graphicsview.pro b/examples/widgets/graphicsview/graphicsview.pro
index 06a7ce8071..5a054fe6b2 100644
--- a/examples/widgets/graphicsview/graphicsview.pro
+++ b/examples/widgets/graphicsview/graphicsview.pro
@@ -15,6 +15,6 @@ SUBDIRS = \
contains(DEFINES, QT_NO_CURSOR)|contains(DEFINES, QT_NO_DRAGANDDROP): SUBDIRS -= dragdroprobot
-qtHaveModule(opengl):!contains(QT_CONFIG, opengles.):!contains(QT_CONFIG,dynamicgl) {
+qtHaveModule(opengl):!qtConfig(opengles.):!qtConfig(dynamicgl) {
SUBDIRS += boxes
}
diff --git a/examples/widgets/painting/composition/composition.pro b/examples/widgets/painting/composition/composition.pro
index 7d174ca2bc..5fdbe4a5a2 100644
--- a/examples/widgets/painting/composition/composition.pro
+++ b/examples/widgets/painting/composition/composition.pro
@@ -6,7 +6,7 @@ SHARED_FOLDER = ../shared
include($$SHARED_FOLDER/shared.pri)
RESOURCES += composition.qrc
-qtHaveModule(opengl): !contains(QT_CONFIG,dynamicgl) {
+qtHaveModule(opengl):!qtConfig(dynamicgl) {
DEFINES += USE_OPENGL
QT += opengl
}
diff --git a/examples/widgets/painting/shared/shared.pri b/examples/widgets/painting/shared/shared.pri
index c8d119f4e5..362cc6819c 100644
--- a/examples/widgets/painting/shared/shared.pri
+++ b/examples/widgets/painting/shared/shared.pri
@@ -1,6 +1,6 @@
INCLUDEPATH += $$PWD
-qtHaveModule(opengl)|contains(QT_CONFIG, opengles2) {
+qtHaveModule(opengl)|qtConfig(opengles2) {
DEFINES += QT_OPENGL_SUPPORT
QT += opengl widgets
}
diff --git a/examples/widgets/tools/codecs/mainwindow.cpp b/examples/widgets/tools/codecs/mainwindow.cpp
index fe29eeffa3..5e4810dd4d 100644
--- a/examples/widgets/tools/codecs/mainwindow.cpp
+++ b/examples/widgets/tools/codecs/mainwindow.cpp
@@ -55,8 +55,8 @@
MainWindow::MainWindow()
{
- textEdit = new QTextEdit;
- textEdit->setLineWrapMode(QTextEdit::NoWrap);
+ textEdit = new QPlainTextEdit;
+ textEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
setCentralWidget(textEdit);
findCodecs();
@@ -64,54 +64,57 @@ MainWindow::MainWindow()
previewForm = new PreviewForm(this);
previewForm->setCodecList(codecs);
- createActions();
createMenus();
setWindowTitle(tr("Codecs"));
- resize(500, 400);
+
+ const QRect screenGeometry = QApplication::desktop()->screenGeometry(this);
+ resize(screenGeometry.width() / 2, screenGeometry.height() * 2 / 3);
}
void MainWindow::open()
{
- QString fileName = QFileDialog::getOpenFileName(this);
- if (!fileName.isEmpty()) {
- QFile file(fileName);
- if (!file.open(QFile::ReadOnly)) {
- QMessageBox::warning(this, tr("Codecs"),
- tr("Cannot read file %1:\n%2")
- .arg(fileName)
- .arg(file.errorString()));
- return;
- }
+ const QString fileName = QFileDialog::getOpenFileName(this);
+ if (fileName.isEmpty())
+ return;
+ QFile file(fileName);
+ if (!file.open(QFile::ReadOnly)) {
+ QMessageBox::warning(this, tr("Codecs"),
+ tr("Cannot read file %1:\n%2")
+ .arg(QDir::toNativeSeparators(fileName),
+ file.errorString()));
+ return;
+ }
- QByteArray data = file.readAll();
+ const QByteArray data = file.readAll();
- previewForm->setEncodedData(data);
- if (previewForm->exec())
- textEdit->setPlainText(previewForm->decodedString());
- }
+ previewForm->setWindowTitle(tr("Choose Encoding for %1").arg(QFileInfo(fileName).fileName()));
+ previewForm->setEncodedData(data);
+ if (previewForm->exec())
+ textEdit->setPlainText(previewForm->decodedString());
}
void MainWindow::save()
{
- QString fileName = QFileDialog::getSaveFileName(this);
- if (!fileName.isEmpty()) {
- QFile file(fileName);
- if (!file.open(QFile::WriteOnly | QFile::Text)) {
- QMessageBox::warning(this, tr("Codecs"),
- tr("Cannot write file %1:\n%2")
- .arg(fileName)
- .arg(file.errorString()));
- return;
- }
-
- QAction *action = qobject_cast<QAction *>(sender());
- QByteArray codecName = action->data().toByteArray();
-
- QTextStream out(&file);
- out.setCodec(codecName.constData());
- out << textEdit->toPlainText();
+ const QAction *action = qobject_cast<const QAction *>(sender());
+ const QByteArray codecName = action->data().toByteArray();
+ const QString title = tr("Save As (%1)").arg(QLatin1String(codecName));
+
+ QString fileName = QFileDialog::getSaveFileName(this, title);
+ if (fileName.isEmpty())
+ return;
+ QFile file(fileName);
+ if (!file.open(QFile::WriteOnly | QFile::Text)) {
+ QMessageBox::warning(this, tr("Codecs"),
+ tr("Cannot write file %1:\n%2")
+ .arg(QDir::toNativeSeparators(fileName),
+ file.errorString()));
+ return;
}
+
+ QTextStream out(&file);
+ out.setCodec(codecName.constData());
+ out << textEdit->toPlainText();
}
void MainWindow::about()
@@ -143,9 +146,9 @@ void MainWindow::findCodecs()
QString sortKey = codec->name().toUpper();
int rank;
- if (sortKey.startsWith("UTF-8")) {
+ if (sortKey.startsWith(QLatin1String("UTF-8"))) {
rank = 1;
- } else if (sortKey.startsWith("UTF-16")) {
+ } else if (sortKey.startsWith(QLatin1String("UTF-16"))) {
rank = 2;
} else if (iso8859RegExp.exactMatch(sortKey)) {
if (iso8859RegExp.cap(1).size() == 1)
@@ -155,58 +158,38 @@ void MainWindow::findCodecs()
} else {
rank = 5;
}
- sortKey.prepend(QChar('0' + rank));
+ sortKey.prepend(QLatin1Char('0' + rank));
codecMap.insert(sortKey, codec);
}
codecs = codecMap.values();
}
-void MainWindow::createActions()
+void MainWindow::createMenus()
{
- openAct = new QAction(tr("&Open..."), this);
+ QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
+ QAction *openAct =
+ fileMenu->addAction(tr("&Open..."), this, &MainWindow::open);
openAct->setShortcuts(QKeySequence::Open);
- connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
-
- foreach (QTextCodec *codec, codecs) {
- QString text = tr("%1...").arg(QString(codec->name()));
- QAction *action = new QAction(text, this);
- action->setData(codec->name());
- connect(action, SIGNAL(triggered()), this, SLOT(save()));
+ QMenu *saveAsMenu = fileMenu->addMenu(tr("&Save As"));
+ connect(saveAsMenu, &QMenu::aboutToShow,
+ this, &MainWindow::aboutToShowSaveAsMenu);
+ foreach (const QTextCodec *codec, codecs) {
+ const QByteArray name = codec->name();
+ QAction *action = saveAsMenu->addAction(tr("%1...").arg(QLatin1String(name)));
+ action->setData(QVariant(name));
+ connect(action, &QAction::triggered, this, &MainWindow::save);
saveAsActs.append(action);
}
- exitAct = new QAction(tr("E&xit"), this);
- exitAct->setShortcuts(QKeySequence::Quit);
- connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
-
- aboutAct = new QAction(tr("&About"), this);
- connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
-
- aboutQtAct = new QAction(tr("About &Qt"), this);
- connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
-}
-
-void MainWindow::createMenus()
-{
- saveAsMenu = new QMenu(tr("&Save As"), this);
- foreach (QAction *action, saveAsActs)
- saveAsMenu->addAction(action);
- connect(saveAsMenu, SIGNAL(aboutToShow()),
- this, SLOT(aboutToShowSaveAsMenu()));
-
- fileMenu = new QMenu(tr("&File"), this);
- fileMenu->addAction(openAct);
- fileMenu->addMenu(saveAsMenu);
fileMenu->addSeparator();
- fileMenu->addAction(exitAct);
-
- helpMenu = new QMenu(tr("&Help"), this);
- helpMenu->addAction(aboutAct);
- helpMenu->addAction(aboutQtAct);
+ QAction *exitAct = fileMenu->addAction(tr("E&xit"), this, &QWidget::close);
+ exitAct->setShortcuts(QKeySequence::Quit);
- menuBar()->addMenu(fileMenu);
menuBar()->addSeparator();
- menuBar()->addMenu(helpMenu);
+
+ QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(tr("&About"), this, &MainWindow::about);
+ helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
}
diff --git a/examples/widgets/tools/codecs/mainwindow.h b/examples/widgets/tools/codecs/mainwindow.h
index 1e8b440a02..7121c0b122 100644
--- a/examples/widgets/tools/codecs/mainwindow.h
+++ b/examples/widgets/tools/codecs/mainwindow.h
@@ -56,9 +56,8 @@
QT_BEGIN_NAMESPACE
class QAction;
-class QMenu;
class QTextCodec;
-class QTextEdit;
+class QPlainTextEdit;
QT_END_NAMESPACE
class PreviewForm;
@@ -77,21 +76,12 @@ private slots:
private:
void findCodecs();
- void createActions();
void createMenus();
- QTextEdit *textEdit;
+ QList<QAction *> saveAsActs;
+ QPlainTextEdit *textEdit;
PreviewForm *previewForm;
QList<QTextCodec *> codecs;
-
- QMenu *fileMenu;
- QMenu *helpMenu;
- QMenu *saveAsMenu;
- QAction *openAct;
- QList<QAction *> saveAsActs;
- QAction *exitAct;
- QAction *aboutAct;
- QAction *aboutQtAct;
};
#endif
diff --git a/examples/widgets/tools/codecs/previewform.cpp b/examples/widgets/tools/codecs/previewform.cpp
index 82203175ca..e5ca13f011 100644
--- a/examples/widgets/tools/codecs/previewform.cpp
+++ b/examples/widgets/tools/codecs/previewform.cpp
@@ -52,47 +52,159 @@
#include "previewform.h"
+// Helpers for creating hex dumps
+static void indent(QTextStream &str, int indent)
+{
+ for (int i = 0; i < indent; ++i)
+ str << ' ';
+}
+
+static void formatHex(QTextStream &str, const QByteArray &data)
+{
+ const int fieldWidth = str.fieldWidth();
+ const QTextStream::FieldAlignment alignment = str.fieldAlignment();
+ const int base = str.integerBase();
+ const QChar padChar = str.padChar();
+ str.setIntegerBase(16);
+ str.setPadChar(QLatin1Char('0'));
+ str.setFieldAlignment(QTextStream::AlignRight);
+
+ const unsigned char *p = reinterpret_cast<const unsigned char *>(data.constBegin());
+ for (const unsigned char *end = p + data.size(); p < end; ++p) {
+ str << ' ';
+ str.setFieldWidth(2);
+ str << unsigned(*p);
+ str.setFieldWidth(fieldWidth);
+ }
+ str.setFieldAlignment(alignment);
+ str.setPadChar(padChar);
+ str.setIntegerBase(base);
+}
+
+static void formatPrintableCharacters(QTextStream &str, const QByteArray &data)
+{
+ for (int i = 0, size = data.size(); i < size; ++i) {
+ const char c = data.at(i);
+ switch (c) {
+ case '\0':
+ str << "\\0";
+ break;
+ case '\t':
+ str << "\\t";
+ break;
+ case '\r':
+ str << "\\r";
+ break;
+ case '\n':
+ str << "\\n";
+ break;
+ default:
+ if (c >= 32 && uchar(c) < 127)
+ str << ' ' << c;
+ else
+ str << "..";
+ break;
+ }
+ }
+}
+
+static QString formatHexDump(const QByteArray &data)
+{
+ enum { lineWidth = 16 };
+ QString result;
+ QTextStream str(&result);
+ str.setIntegerBase(16);
+ str.setPadChar(QLatin1Char('0'));
+ const int fieldWidth = str.fieldWidth();
+ const QTextStream::FieldAlignment alignment = str.fieldAlignment();
+ for (int a = 0, size = data.size(); a < size; a += lineWidth) {
+ str.setFieldAlignment(QTextStream::AlignRight);
+ str.setFieldWidth(8);
+ str << a;
+ str.setFieldWidth(fieldWidth);
+ str.setFieldAlignment(alignment);
+
+ const int end = qMin(a + lineWidth, size);
+ const QByteArray line = data.mid(a, end - a);
+
+ formatHex(str, line);
+ indent(str, 3 * (lineWidth - line.size()));
+
+ str << ' ';
+ formatPrintableCharacters(str, line);
+ indent(str, 2 * (lineWidth - line.size()));
+ str << '\n';
+ }
+ return result;
+}
+
PreviewForm::PreviewForm(QWidget *parent)
: QDialog(parent)
{
+ setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
encodingComboBox = new QComboBox;
- encodingLabel = new QLabel(tr("&Encoding:"));
+ QLabel *encodingLabel = new QLabel(tr("&Encoding:"));
encodingLabel->setBuddy(encodingComboBox);
- textEdit = new QTextEdit;
- textEdit->setLineWrapMode(QTextEdit::NoWrap);
+ textEdit = new QPlainTextEdit;
+ textEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
textEdit->setReadOnly(true);
+ hexDumpEdit = new QPlainTextEdit;
+ hexDumpEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
+ hexDumpEdit->setReadOnly(true);
+ hexDumpEdit->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
- buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok
- | QDialogButtonBox::Cancel);
+ QDialogButtonBox *buttonBox =
+ new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
+ okButton = buttonBox->button(QDialogButtonBox::Ok);
- connect(encodingComboBox, SIGNAL(activated(int)),
- this, SLOT(updateTextEdit()));
- connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
- connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
+ typedef void(QComboBox::*ComboBoxIntSignal)(int);
+ connect(encodingComboBox, static_cast<ComboBoxIntSignal>(&QComboBox::activated),
+ this, &PreviewForm::updateTextEdit);
+ connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
+ connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
- QGridLayout *mainLayout = new QGridLayout;
+ QGridLayout *mainLayout = new QGridLayout(this);
mainLayout->addWidget(encodingLabel, 0, 0);
mainLayout->addWidget(encodingComboBox, 0, 1);
- mainLayout->addWidget(textEdit, 1, 0, 1, 2);
- mainLayout->addWidget(buttonBox, 2, 0, 1, 2);
- setLayout(mainLayout);
+ tabWidget = new QTabWidget;
+ tabWidget->addTab(textEdit, tr("Preview"));
+ tabWidget->addTab(hexDumpEdit, tr("Hex Dump"));
+ mainLayout->addWidget(tabWidget, 1, 0, 1, 2);
+ statusLabel = new QLabel;
+ mainLayout->addWidget(statusLabel, 2, 0, 1, 2);
+ mainLayout->addWidget(buttonBox, 3, 0, 1, 2);
- setWindowTitle(tr("Choose Encoding"));
- resize(400, 300);
+ const QRect screenGeometry = QApplication::desktop()->screenGeometry(this);
+ resize(screenGeometry.width() * 2 / 5, screenGeometry.height() / 2);
}
void PreviewForm::setCodecList(const QList<QTextCodec *> &list)
{
encodingComboBox->clear();
- foreach (QTextCodec *codec, list)
- encodingComboBox->addItem(codec->name(), codec->mibEnum());
+ foreach (const QTextCodec *codec, list) {
+ encodingComboBox->addItem(QLatin1String(codec->name()),
+ QVariant(codec->mibEnum()));
+ }
+}
+
+void PreviewForm::reset()
+{
+ decodedStr.clear();
+ textEdit->clear();
+ hexDumpEdit->clear();
+ statusLabel->clear();
+ statusLabel->setStyleSheet(QString());
+ okButton->setEnabled(false);
+ tabWidget->setCurrentIndex(0);
}
void PreviewForm::setEncodedData(const QByteArray &data)
{
+ reset();
encodedData = data;
+ hexDumpEdit->setPlainText(formatHexDump(data));
updateTextEdit();
}
@@ -100,12 +212,30 @@ void PreviewForm::updateTextEdit()
{
int mib = encodingComboBox->itemData(
encodingComboBox->currentIndex()).toInt();
- QTextCodec *codec = QTextCodec::codecForMib(mib);
+ const QTextCodec *codec = QTextCodec::codecForMib(mib);
+ const QString name = QLatin1String(codec->name());
- QTextStream in(&encodedData);
- in.setAutoDetectUnicode(false);
- in.setCodec(codec);
- decodedStr = in.readAll();
+ QTextCodec::ConverterState state;
+ decodedStr = codec->toUnicode(encodedData.constData(), encodedData.size(), &state);
- textEdit->setPlainText(decodedStr);
+ bool success = true;
+ if (state.remainingChars) {
+ success = false;
+ const QString message =
+ tr("%1: conversion error at character %2")
+ .arg(name).arg(encodedData.size() - state.remainingChars + 1);
+ statusLabel->setText(message);
+ statusLabel->setStyleSheet(QStringLiteral("background-color: \"red\";"));
+ } else if (state.invalidChars) {
+ statusLabel->setText(tr("%1: %n invalid characters", 0, state.invalidChars).arg(name));
+ statusLabel->setStyleSheet(QStringLiteral("background-color: \"yellow\";"));
+ } else {
+ statusLabel->setText(tr("%1: %n bytes converted", 0, encodedData.size()).arg(name));
+ statusLabel->setStyleSheet(QString());
+ }
+ if (success)
+ textEdit->setPlainText(decodedStr);
+ else
+ textEdit->clear();
+ okButton->setEnabled(success);
}
diff --git a/examples/widgets/tools/codecs/previewform.h b/examples/widgets/tools/codecs/previewform.h
index f3e13233b4..1846b976de 100644
--- a/examples/widgets/tools/codecs/previewform.h
+++ b/examples/widgets/tools/codecs/previewform.h
@@ -58,8 +58,10 @@ QT_BEGIN_NAMESPACE
class QComboBox;
class QDialogButtonBox;
class QLabel;
+class QPlainTextEdit;
+class QPushButton;
+class QTabWidget;
class QTextCodec;
-class QTextEdit;
QT_END_NAMESPACE
class PreviewForm : public QDialog
@@ -67,7 +69,7 @@ class PreviewForm : public QDialog
Q_OBJECT
public:
- PreviewForm(QWidget *parent = 0);
+ explicit PreviewForm(QWidget *parent = Q_NULLPTR);
void setCodecList(const QList<QTextCodec *> &list);
void setEncodedData(const QByteArray &data);
@@ -77,13 +79,17 @@ private slots:
void updateTextEdit();
private:
+ void reset();
+
QByteArray encodedData;
QString decodedStr;
+ QPushButton *okButton;
+ QTabWidget *tabWidget;
QComboBox *encodingComboBox;
- QLabel *encodingLabel;
- QTextEdit *textEdit;
- QDialogButtonBox *buttonBox;
+ QPlainTextEdit *textEdit;
+ QPlainTextEdit *hexDumpEdit;
+ QLabel *statusLabel;
};
#endif
diff --git a/examples/widgets/tools/plugandpaint/app/app.pro b/examples/widgets/tools/plugandpaint/app/app.pro
index 8139cd53ad..e35203edf2 100644
--- a/examples/widgets/tools/plugandpaint/app/app.pro
+++ b/examples/widgets/tools/plugandpaint/app/app.pro
@@ -13,11 +13,16 @@ SOURCES = main.cpp \
paintarea.cpp \
plugindialog.cpp
-LIBS = -L../plugins -lpnp_basictools
+LIBS = -L../plugins
-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
+macx-xcode:qtConfig(simulator_and_device) {
+ LIBS += -lpnp_basictools$($${QMAKE_XCODE_LIBRARY_PLATFORM_SUFFIX_SETTING})$($${QMAKE_XCODE_LIBRARY_SUFFIX_SETTING})
+} 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
+ }
}
#! [0]
diff --git a/examples/widgets/tools/plugandpaint/plugins/basictools/basictools.pro b/examples/widgets/tools/plugandpaint/plugins/basictools/basictools.pro
index f28be96b03..8317019c10 100644
--- a/examples/widgets/tools/plugandpaint/plugins/basictools/basictools.pro
+++ b/examples/widgets/tools/plugandpaint/plugins/basictools/basictools.pro
@@ -14,3 +14,4 @@ target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tools/plugandpaint/plugins
INSTALLS += target
CONFIG += install_ok # Do not cargo-cult this!
+uikit: CONFIG += debug_and_release simulator_and_device
diff --git a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafilters.pro b/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafilters.pro
index deb3c5e70e..4716665d34 100644
--- a/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafilters.pro
+++ b/examples/widgets/tools/plugandpaint/plugins/extrafilters/extrafilters.pro
@@ -14,3 +14,4 @@ target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tools/plugandpaint/plugins
INSTALLS += target
CONFIG += install_ok # Do not cargo-cult this!
+uikit: CONFIG += debug_and_release simulator_and_device
diff --git a/examples/widgets/widgets.pro b/examples/widgets/widgets.pro
index cc489b5c16..65a96dd718 100644
--- a/examples/widgets/widgets.pro
+++ b/examples/widgets/widgets.pro
@@ -22,11 +22,11 @@ SUBDIRS = \
tutorials \
widgets
-contains(QT_CONFIG, opengl(es2)?) {
+qtConfig(opengl(es2)?) {
SUBDIRS += windowcontainer
}
-!contains(QT_CONFIG, opengl(es2)?): SUBDIRS -= windowcontainer
+!qtConfig(opengl(es2)?): SUBDIRS -= windowcontainer
contains(DEFINES, QT_NO_CURSOR): SUBDIRS -= mainwindows
contains(DEFINES, QT_NO_DRAGANDDROP): SUBDIRS -= draganddrop
mac:SUBDIRS += mac
diff --git a/examples/widgets/widgets/charactermap/characterwidget.cpp b/examples/widgets/widgets/charactermap/characterwidget.cpp
index 07912da6ff..55d45501f1 100644
--- a/examples/widgets/widgets/charactermap/characterwidget.cpp
+++ b/examples/widgets/widgets/charactermap/characterwidget.cpp
@@ -54,11 +54,9 @@
//! [0]
CharacterWidget::CharacterWidget(QWidget *parent)
- : QWidget(parent)
+ : QWidget(parent), columns(16), lastKey(-1)
{
- squareSize = 24;
- columns = 16;
- lastKey = -1;
+ calculateSquareSize();
setMouseTracking(true);
}
//! [0]
@@ -67,7 +65,7 @@ CharacterWidget::CharacterWidget(QWidget *parent)
void CharacterWidget::updateFont(const QFont &font)
{
displayFont.setFamily(font.family());
- squareSize = qMax(24, QFontMetrics(displayFont).xHeight() * 3);
+ calculateSquareSize();
adjustSize();
update();
}
@@ -77,7 +75,7 @@ void CharacterWidget::updateFont(const QFont &font)
void CharacterWidget::updateSize(const QString &fontSize)
{
displayFont.setPointSize(fontSize.toInt());
- squareSize = qMax(24, QFontMetrics(displayFont).xHeight() * 3);
+ calculateSquareSize();
adjustSize();
update();
}
@@ -89,7 +87,7 @@ void CharacterWidget::updateStyle(const QString &fontStyle)
const QFont::StyleStrategy oldStrategy = displayFont.styleStrategy();
displayFont = fontDatabase.font(displayFont.family(), fontStyle, displayFont.pointSize());
displayFont.setStyleStrategy(oldStrategy);
- squareSize = qMax(24, QFontMetrics(displayFont).xHeight() * 3);
+ calculateSquareSize();
adjustSize();
update();
}
@@ -104,6 +102,11 @@ void CharacterWidget::updateFontMerging(bool enable)
update();
}
+void CharacterWidget::calculateSquareSize()
+{
+ squareSize = qMax(16, 4 + QFontMetrics(displayFont, this).height());
+}
+
//! [3]
QSize CharacterWidget::sizeHint() const
{
diff --git a/examples/widgets/widgets/charactermap/characterwidget.h b/examples/widgets/widgets/charactermap/characterwidget.h
index 8a33d69628..53add51e6f 100644
--- a/examples/widgets/widgets/charactermap/characterwidget.h
+++ b/examples/widgets/widgets/charactermap/characterwidget.h
@@ -86,6 +86,8 @@ protected:
void paintEvent(QPaintEvent *event) override;
private:
+ void calculateSquareSize();
+
QFont displayFont;
int columns;
int lastKey;
diff --git a/examples/widgets/widgets/charactermap/mainwindow.cpp b/examples/widgets/widgets/charactermap/mainwindow.cpp
index 2141850f16..8b406ba1ca 100644
--- a/examples/widgets/widgets/charactermap/mainwindow.cpp
+++ b/examples/widgets/widgets/charactermap/mainwindow.cpp
@@ -54,10 +54,30 @@
#include "mainwindow.h"
//! [0]
+
+Q_DECLARE_METATYPE(QFontComboBox::FontFilter)
+
MainWindow::MainWindow()
{
+ QMenu *fileMenu = menuBar()->addMenu(tr("File"));
+ fileMenu->addAction(tr("Quit"), this, &QWidget::close);
+ QMenu *helpMenu = menuBar()->addMenu(tr("&Help"));
+ helpMenu->addAction(tr("Show Font Info"), this, &MainWindow::showInfo);
+ helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
+
QWidget *centralWidget = new QWidget;
+ QLabel *filterLabel = new QLabel(tr("Filter:"));
+ filterCombo = new QComboBox;
+ filterCombo->addItem(tr("All"), QVariant::fromValue(QFontComboBox::AllFonts));
+ filterCombo->addItem(tr("Scalable"), QVariant::fromValue(QFontComboBox::ScalableFonts));
+ filterCombo->addItem(tr("Monospaced"), QVariant::fromValue(QFontComboBox::MonospacedFonts));
+ filterCombo->addItem(tr("Proportional"), QVariant::fromValue(QFontComboBox::ProportionalFonts));
+ filterCombo->setCurrentIndex(0);
+ typedef void (QComboBox::*QComboBoxIntSignal)(int);
+ connect(filterCombo, static_cast<QComboBoxIntSignal>(&QComboBox::currentIndexChanged),
+ this, &MainWindow::filterChanged);
+
QLabel *fontLabel = new QLabel(tr("Font:"));
fontCombo = new QFontComboBox;
QLabel *sizeLabel = new QLabel(tr("Size:"));
@@ -80,38 +100,39 @@ MainWindow::MainWindow()
//! [2]
lineEdit = new QLineEdit;
+ lineEdit->setClearButtonEnabled(true);
#ifndef QT_NO_CLIPBOARD
QPushButton *clipboardButton = new QPushButton(tr("&To clipboard"));
//! [2]
-//! [3]
- clipboard = QApplication::clipboard();
-//! [3]
#endif
//! [4]
- connect(fontCombo, SIGNAL(currentFontChanged(QFont)),
- this, SLOT(findStyles(QFont)));
- connect(fontCombo, SIGNAL(currentFontChanged(QFont)),
- this, SLOT(findSizes(QFont)));
- connect(fontCombo, SIGNAL(currentFontChanged(QFont)),
- characterWidget, SLOT(updateFont(QFont)));
- connect(sizeCombo, SIGNAL(currentIndexChanged(QString)),
- characterWidget, SLOT(updateSize(QString)));
- connect(styleCombo, SIGNAL(currentIndexChanged(QString)),
- characterWidget, SLOT(updateStyle(QString)));
+ connect(fontCombo, &QFontComboBox::currentFontChanged,
+ this, &MainWindow::findStyles);
+ connect(fontCombo, &QFontComboBox::currentFontChanged,
+ this, &MainWindow::findSizes);
+ connect(fontCombo, &QFontComboBox::currentFontChanged,
+ characterWidget, &CharacterWidget::updateFont);
+ typedef void (QComboBox::*QComboBoxStringSignal)(const QString &);
+ connect(sizeCombo, static_cast<QComboBoxStringSignal>(&QComboBox::currentIndexChanged),
+ characterWidget, &CharacterWidget::updateSize);
+ connect(styleCombo, static_cast<QComboBoxStringSignal>(&QComboBox::currentIndexChanged),
+ characterWidget, &CharacterWidget::updateStyle);
//! [4] //! [5]
- connect(characterWidget, SIGNAL(characterSelected(QString)),
- this, SLOT(insertCharacter(QString)));
+ connect(characterWidget, &CharacterWidget::characterSelected,
+ this, &MainWindow::insertCharacter);
#ifndef QT_NO_CLIPBOARD
- connect(clipboardButton, SIGNAL(clicked()), this, SLOT(updateClipboard()));
+ connect(clipboardButton, &QAbstractButton::clicked, this, &MainWindow::updateClipboard);
#endif
//! [5]
- connect(fontMerging, SIGNAL(toggled(bool)), characterWidget, SLOT(updateFontMerging(bool)));
+ connect(fontMerging, &QAbstractButton::toggled, characterWidget, &CharacterWidget::updateFontMerging);
//! [6]
QHBoxLayout *controlsLayout = new QHBoxLayout;
+ controlsLayout->addWidget(filterLabel);
+ controlsLayout->addWidget(filterCombo, 1);
controlsLayout->addWidget(fontLabel);
controlsLayout->addWidget(fontCombo, 1);
controlsLayout->addWidget(sizeLabel);
@@ -163,6 +184,14 @@ void MainWindow::findStyles(const QFont &font)
}
//! [8]
+void MainWindow::filterChanged(int f)
+{
+ const QFontComboBox::FontFilter filter =
+ filterCombo->itemData(f).value<QFontComboBox::FontFilter>();
+ fontCombo->setFontFilters(filter);
+ statusBar()->showMessage(tr("%n font(s) found", 0, fontCombo->count()));
+}
+
void MainWindow::findSizes(const QFont &font)
{
QFontDatabase fontDatabase;
@@ -208,9 +237,63 @@ void MainWindow::insertCharacter(const QString &character)
void MainWindow::updateClipboard()
{
//! [11]
- clipboard->setText(lineEdit->text(), QClipboard::Clipboard);
+ QGuiApplication::clipboard()->setText(lineEdit->text(), QClipboard::Clipboard);
//! [11]
- clipboard->setText(lineEdit->text(), QClipboard::Selection);
+ QGuiApplication::clipboard()->setText(lineEdit->text(), QClipboard::Selection);
}
#endif
+
+class FontInfoDialog : public QDialog
+{
+public:
+ explicit FontInfoDialog(QWidget *parent = Q_NULLPTR);
+
+private:
+ QString text() const;
+};
+
+FontInfoDialog::FontInfoDialog(QWidget *parent) : QDialog(parent)
+{
+ setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
+ QVBoxLayout *mainLayout = new QVBoxLayout(this);
+ QPlainTextEdit *textEdit = new QPlainTextEdit(text(), this);
+ textEdit->setReadOnly(true);
+ textEdit->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont));
+ mainLayout->addWidget(textEdit);
+ QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close, this);
+ connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
+ mainLayout->addWidget(buttonBox);
+}
+
+QString FontInfoDialog::text() const
+{
+ QString text;
+ QTextStream str(&text);
+ const QFont defaultFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
+ const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
+ const QFont titleFont = QFontDatabase::systemFont(QFontDatabase::TitleFont);
+ const QFont smallestReadableFont = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont);
+
+ str << "Qt " << QT_VERSION_STR << " on " << QGuiApplication::platformName()
+ << ", " << logicalDpiX() << "DPI";
+ if (!qFuzzyCompare(devicePixelRatioF(), qreal(1)))
+ str << ", device pixel ratio: " << devicePixelRatioF();
+ str << "\n\nDefault font : " << defaultFont.family() << ", " << defaultFont.pointSizeF() << "pt\n"
+ << "Fixed font : " << fixedFont.family() << ", " << fixedFont.pointSizeF() << "pt\n"
+ << "Title font : " << titleFont.family() << ", " << titleFont.pointSizeF() << "pt\n"
+ << "Smallest font: " << smallestReadableFont.family() << ", " << smallestReadableFont.pointSizeF() << "pt\n";
+
+ return text;
+}
+
+void MainWindow::showInfo()
+{
+ const QRect screenGeometry = QApplication::desktop()->screenGeometry(this);
+ FontInfoDialog *dialog = new FontInfoDialog(this);
+ dialog->setWindowTitle(tr("Fonts"));
+ dialog->setAttribute(Qt::WA_DeleteOnClose);
+ dialog->resize(screenGeometry.width() / 4, screenGeometry.height() / 4);
+ dialog->show();
+}
+
//! [10]
diff --git a/examples/widgets/widgets/charactermap/mainwindow.h b/examples/widgets/widgets/charactermap/mainwindow.h
index 2865eacc00..eac16b35fa 100644
--- a/examples/widgets/widgets/charactermap/mainwindow.h
+++ b/examples/widgets/widgets/charactermap/mainwindow.h
@@ -73,18 +73,18 @@ public:
MainWindow();
public slots:
+ void filterChanged(int);
void findStyles(const QFont &font);
void findSizes(const QFont &font);
void insertCharacter(const QString &character);
#ifndef QT_NO_CLIPBOARD
void updateClipboard();
#endif
+ void showInfo();
private:
CharacterWidget *characterWidget;
-#ifndef QT_NO_CLIPBOARD
- QClipboard *clipboard;
-#endif
+ QComboBox *filterCombo;
QComboBox *styleCombo;
QComboBox *sizeCombo;
QFontComboBox *fontCombo;
diff --git a/examples/widgets/widgets/icons/images/designer.png b/examples/widgets/widgets/icons/images/designer.png
index 0988fcee3f..9f8578b49e 100644
--- a/examples/widgets/widgets/icons/images/designer.png
+++ b/examples/widgets/widgets/icons/images/designer.png
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/qt_extended_16x16.png b/examples/widgets/widgets/icons/images/qt_extended_16x16.png
index bee4e7d6cd..30bcb45ed2 100644
--- a/examples/widgets/widgets/icons/images/qt_extended_16x16.png
+++ b/examples/widgets/widgets/icons/images/qt_extended_16x16.png
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/qt_extended_32x32.png b/examples/widgets/widgets/icons/images/qt_extended_32x32.png
index 6e7d000c04..d609c1e1e5 100644
--- a/examples/widgets/widgets/icons/images/qt_extended_32x32.png
+++ b/examples/widgets/widgets/icons/images/qt_extended_32x32.png
Binary files differ
diff --git a/examples/widgets/widgets/icons/images/qt_extended_48x48.png b/examples/widgets/widgets/icons/images/qt_extended_48x48.png
index 7a93d88900..0e524fed5f 100644
--- a/examples/widgets/widgets/icons/images/qt_extended_48x48.png
+++ b/examples/widgets/widgets/icons/images/qt_extended_48x48.png
Binary files differ