diff options
author | Doris Verria <doris.verria@qt.io> | 2023-12-20 14:28:28 +0100 |
---|---|---|
committer | Doris Verria <doris.verria@qt.io> | 2023-12-21 14:58:54 +0100 |
commit | 30e6d822327d8105d209af10d077512f21ecc12c (patch) | |
tree | 8c506f8a93faef753b403ddbbdfebbd466c367b9 /examples/widgets/gestures | |
parent | 5f7b4c045f4347b9e47849d15d5932df45626c51 (diff) |
Update ImageGestures example
- Update screenshot
- Provide some information text on the screen when no images are found
- Add all supported image formats to the file filters
- Minor fixes according to our coding conventions: eg. don't shadow
variables
Fixes: QTBUG-119979
Pick-to: 6.7
Change-Id: If41adf34f38bfa101f2c5433082828c1a10668b1
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'examples/widgets/gestures')
3 files changed, 15 insertions, 5 deletions
diff --git a/examples/widgets/gestures/imagegestures/doc/src/imagegestures.qdoc b/examples/widgets/gestures/imagegestures/doc/src/imagegestures.qdoc index 878da3f8aa..46053566ab 100644 --- a/examples/widgets/gestures/imagegestures/doc/src/imagegestures.qdoc +++ b/examples/widgets/gestures/imagegestures/doc/src/imagegestures.qdoc @@ -10,7 +10,7 @@ This example shows how to enable gestures for a widget and use gesture input to perform actions. - \image imagegestures-example.jpg + \image imagegestures-example.png We use two classes to create the user interface for the application: \c MainWidget and \c ImageWidget. The \c MainWidget class is simply used as a container for the diff --git a/examples/widgets/gestures/imagegestures/imagewidget.cpp b/examples/widgets/gestures/imagegestures/imagewidget.cpp index 3ee72392fd..189281cc11 100644 --- a/examples/widgets/gestures/imagegestures/imagewidget.cpp +++ b/examples/widgets/gestures/imagegestures/imagewidget.cpp @@ -41,6 +41,12 @@ void ImageWidget::paintEvent(QPaintEvent*) { QPainter p(this); + if (files.isEmpty() && !path.isEmpty()) { + p.drawText(rect(), Qt::AlignCenter|Qt::TextWordWrap, + tr("No supported image formats found")); + return; + } + const qreal iw = currentImage.width(); const qreal ih = currentImage.height(); const qreal wh = height(); @@ -144,11 +150,15 @@ void ImageWidget::resizeEvent(QResizeEvent*) update(); } -void ImageWidget::openDirectory(const QString &path) +void ImageWidget::openDirectory(const QString &url) { - this->path = path; + path = url; QDir dir(path); - const QStringList nameFilters{"*.jpg", "*.png"}; + + QStringList nameFilters; + const QList<QByteArray> supportedFormats = QImageReader::supportedImageFormats(); + for (const QByteArray &format : supportedFormats) + nameFilters.append(QLatin1String("*.") + QString::fromLatin1(format)); files = dir.entryInfoList(nameFilters, QDir::Files|QDir::Readable, QDir::Name); position = 0; diff --git a/examples/widgets/gestures/imagegestures/imagewidget.h b/examples/widgets/gestures/imagegestures/imagewidget.h index b5bbc9ef0f..1f4010baac 100644 --- a/examples/widgets/gestures/imagegestures/imagewidget.h +++ b/examples/widgets/gestures/imagegestures/imagewidget.h @@ -25,7 +25,7 @@ class ImageWidget : public QWidget public: ImageWidget(QWidget *parent = nullptr); - void openDirectory(const QString &path); + void openDirectory(const QString &url); void grabGestures(const QList<Qt::GestureType> &gestures); protected: |