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
Change-Id: If41adf34f38bfa101f2c5433082828c1a10668b1
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 30e6d822327d8105d209af10d077512f21ecc12c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Doris Verria 2023-12-20 14:28:28 +01:00 committed by Qt Cherry-pick Bot
parent 2b18f6c7b8
commit e4c533c336
5 changed files with 15 additions and 5 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 KiB

View File

@ -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

View File

@ -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;

View File

@ -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: