6.5.3 clean

This commit is contained in:
kleuter
2023-11-01 18:02:52 +01:00
parent bbe896803b
commit 7018d9e6c8
2170 changed files with 57471 additions and 43550 deletions

View File

@ -4,6 +4,7 @@
/*!
\example gestures/imagegestures
\title Image Gestures Example
\examplecategory {User Interface Components}
\brief Demonstrates the use of simple gestures in a widget.
This example shows how to enable gestures for a widget and use gesture input

View File

@ -149,15 +149,23 @@ void ImageWidget::openDirectory(const QString &path)
this->path = path;
QDir dir(path);
const QStringList nameFilters{"*.jpg", "*.png"};
files = dir.entryList(nameFilters, QDir::Files|QDir::Readable, QDir::Name);
files = dir.entryInfoList(nameFilters, QDir::Files|QDir::Readable, QDir::Name);
position = 0;
goToImage(0);
update();
}
QImage ImageWidget::loadImage(const QString &fileName) const
/*
With Android's content scheme paths, it might not be possible to simply
append a file name to the chosen directory path to be able to open the image,
because usually paths are returned by an Android file provider and handling those
paths manually is not guaranteed to work. For that reason, it's better to keep
around QFileInfo objects and use absoluteFilePath().
*/
QImage ImageWidget::loadImage(const QFileInfo &fileInfo) const
{
const QString fileName = fileInfo.absoluteFilePath();
QImageReader reader(fileName);
reader.setAutoTransform(true);
qCDebug(lcExample) << "loading" << QDir::toNativeSeparators(fileName) << position << '/' << files.size();
@ -187,7 +195,7 @@ void ImageWidget::goNextImage()
prevImage = currentImage;
currentImage = nextImage;
if (position+1 < files.size())
nextImage = loadImage(path + QLatin1Char('/') + files.at(position+1));
nextImage = loadImage(files.at(position + 1));
else
nextImage = QImage();
}
@ -204,7 +212,7 @@ void ImageWidget::goPrevImage()
nextImage = currentImage;
currentImage = prevImage;
if (position > 0)
prevImage = loadImage(path + QLatin1Char('/') + files.at(position-1));
prevImage = loadImage(files.at(position - 1));
else
prevImage = QImage();
}
@ -234,12 +242,12 @@ void ImageWidget::goToImage(int index)
position = index;
if (index > 0)
prevImage = loadImage(path + QLatin1Char('/') + files.at(position-1));
prevImage = loadImage(files.at(position - 1));
else
prevImage = QImage();
currentImage = loadImage(path + QLatin1Char('/') + files.at(position));
currentImage = loadImage(files.at(position));
if (position+1 < files.size())
nextImage = loadImage(path + QLatin1Char('/') + files.at(position+1));
nextImage = loadImage(files.at(position + 1));
else
nextImage = QImage();
update();

View File

@ -4,6 +4,7 @@
#ifndef IMAGEWIDGET_H
#define IMAGEWIDGET_H
#include <QFileInfo>
#include <QImage>
#include <QLoggingCategory>
#include <QWidget>
@ -40,14 +41,14 @@ private:
void swipeTriggered(QSwipeGesture*);
//! [class definition begin]
QImage loadImage(const QString &fileName) const;
QImage loadImage(const QFileInfo &fileInfo) const;
void loadImage();
void goNextImage();
void goPrevImage();
void goToImage(int index);
QString path;
QStringList files;
QFileInfoList files;
int position;
QImage prevImage, nextImage;