Verified Commit 96e3232a authored by Fushan Wen's avatar Fushan Wen 💬
Browse files

wallpapers/image: call `resetCurrentIndex` after the image list is loaded

This makes the current image focused again by default.
parent a5378b52
......@@ -19,6 +19,15 @@ Item {
readonly property var imageModel: (configDialog.currentWallpaper === "org.kde.image") ? imageWallpaper.wallpaperModel : imageWallpaper.slideFilterModel
Connections {
target: imageWallpaper
function onLoadingChanged() {
if (!imageWallpaper.loading) {
wallpapersGrid.resetCurrentIndex();
}
}
}
KCM.GridView {
id: wallpapersGrid
anchors.fill: parent
......@@ -33,7 +42,6 @@ Item {
view.model: thumbnailsComponent.imageModel
Component.onCompleted: {
thumbnailsComponent.imageModel.usedInConfig = true;
resetCurrentIndex()
}
//set the size of the cell, depending on Screen resolution to respect the aspect ratio
......
......@@ -231,6 +231,7 @@ QAbstractItemModel *ImageBackend::wallpaperModel()
if (!m_model) {
m_model = new ImageProxyModel({}, m_targetSize, this);
connect(this, &ImageBackend::targetSizeChanged, m_model, &ImageProxyModel::targetSizeChanged);
connect(m_model, &ImageProxyModel::loadingChanged, this, &ImageBackend::loadingChanged);
}
return m_model;
......@@ -244,6 +245,7 @@ SlideModel *ImageBackend::slideshowModel()
connect(this, &ImageBackend::uncheckedSlidesChanged, m_slideFilterModel, &SlideFilterModel::invalidateFilter);
connect(this, &ImageBackend::targetSizeChanged, m_slideshowModel, &SlideModel::targetSizeChanged);
connect(m_slideshowModel, &SlideModel::dataChanged, this, &ImageBackend::slotSlideModelDataChanged);
connect(m_slideshowModel, &SlideModel::loadingChanged, this, &ImageBackend::loadingChanged);
}
return m_slideshowModel;
}
......@@ -650,3 +652,14 @@ void ImageBackend::setUncheckedSlides(const QStringList &uncheckedSlides)
Q_EMIT uncheckedSlidesChanged();
startSlideshow();
}
bool ImageBackend::loading() const
{
if (renderingMode() == SingleImage && m_model) {
return m_model->loading();
} else if (renderingMode() == SlideShow && m_slideshowModel) {
return m_slideshowModel->loading();
}
return false;
}
......@@ -55,6 +55,11 @@ class ImageBackend : public QObject, public QQmlParserStatus, public SortingMode
Q_PROPERTY(QSize targetSize READ targetSize WRITE setTargetSize NOTIFY targetSizeChanged)
Q_PROPERTY(QStringList uncheckedSlides READ uncheckedSlides WRITE setUncheckedSlides NOTIFY uncheckedSlidesChanged)
/**
* @return @c true if the image list is loaded, @c false otherwise
*/
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
public:
enum RenderingMode {
SingleImage,
......@@ -115,6 +120,8 @@ public:
QStringList uncheckedSlides() const;
void setUncheckedSlides(const QStringList &uncheckedSlides);
bool loading() const;
public Q_SLOTS:
void nextSlide();
void slotSlideModelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles);
......@@ -133,6 +140,7 @@ Q_SIGNALS:
void resizeMethodChanged();
void customWallpaperPicked(const QString &path);
void uncheckedSlidesChanged();
void loadingChanged();
protected Q_SLOTS:
void showAddSlidePathsDialog();
......
......@@ -59,6 +59,9 @@ ImageProxyModel::ImageProxyModel(const QStringList &_customPaths, const QSize &t
connect(m_imageModel, &AbstractImageListModel::loaded, this, &ImageProxyModel::slotHandleLoaded);
connect(m_packageModel, &AbstractImageListModel::loaded, this, &ImageProxyModel::slotHandleLoaded);
m_loaded = 0;
Q_EMIT loadingChanged();
m_imageModel->load(customPaths);
m_packageModel->load(customPaths);
}
......@@ -108,6 +111,9 @@ void ImageProxyModel::reload()
for (const auto &m : models) {
static_cast<AbstractImageListModel *>(m)->reload();
}
m_loaded = 0;
Q_EMIT loadingChanged();
}
QStringList ImageProxyModel::addBackground(const QString &_path)
......
......@@ -26,7 +26,6 @@ class ImageProxyModel : public QConcatenateTablesProxyModel, public ImageRoles
Q_OBJECT
Q_PROPERTY(int count READ count NOTIFY countChanged)
Q_PROPERTY(bool loading READ loading NOTIFY loadingChanged)
public:
explicit ImageProxyModel(const QStringList &customPaths, const QSize &targetSize, QObject *parent);
......
......@@ -96,6 +96,11 @@ QStringList SlideModel::addDirs(const QStringList &dirs)
}
}
if (!added.empty()) {
m_loading = true;
Q_EMIT loadingChanged();
}
return added;
}
......@@ -145,6 +150,11 @@ void SlideModel::setUncheckedSlides(const QStringList &uncheckedSlides)
}
}
bool SlideModel::loading() const
{
return m_loading;
}
void SlideModel::slotSourceModelLoadingChanged()
{
auto m = qobject_cast<ImageProxyModel *>(sender());
......@@ -160,6 +170,8 @@ void SlideModel::slotSourceModelLoadingChanged()
addSourceModel(m);
if (++m_loaded == m_models.size()) {
m_loading = false;
Q_EMIT loadingChanged();
Q_EMIT done();
}
}
......@@ -36,15 +36,19 @@ public:
void setUncheckedSlides(const QStringList &uncheckedSlides);
bool loading() const;
Q_SIGNALS:
void done();
void targetSizeChanged(const QSize &size);
void loadingChanged();
private Q_SLOTS:
void slotSourceModelLoadingChanged();
private:
QSize m_targetSize;
bool m_loading = false;
QHash<QString, ImageProxyModel *> m_models;
int m_loaded = 0;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment