wip: fix: stop logic
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
.cache
|
.cache
|
||||||
.vscode
|
.vscode
|
||||||
|
build-dbg
|
||||||
build
|
build
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
|
|||||||
+14
-1
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author: Uyanide pywang0608@foxmail.com
|
* @Author: Uyanide pywang0608@foxmail.com
|
||||||
* @Date: 2025-08-05 01:22:53
|
* @Date: 2025-08-05 01:22:53
|
||||||
* @LastEditTime: 2025-11-30 23:21:30
|
* @LastEditTime: 2025-12-01 00:45:52
|
||||||
* @Description: Animated carousel widget for displaying and selecting images.
|
* @Description: Animated carousel widget for displaying and selecting images.
|
||||||
*/
|
*/
|
||||||
#include "images_carousel.h"
|
#include "images_carousel.h"
|
||||||
@@ -54,6 +54,18 @@ ImagesCarousel::ImagesCarousel(const Config::StyleConfigItems& styleConfig,
|
|||||||
this,
|
this,
|
||||||
&ImagesCarousel::_onImagesLoaded);
|
&ImagesCarousel::_onImagesLoaded);
|
||||||
|
|
||||||
|
// Load initial images
|
||||||
|
connect(this,
|
||||||
|
&ImagesCarousel::stopped,
|
||||||
|
this,
|
||||||
|
&ImagesCarousel::_onInitImagesLoaded);
|
||||||
|
|
||||||
|
// Also handle subsequent image loads
|
||||||
|
connect(this,
|
||||||
|
&ImagesCarousel::stopped,
|
||||||
|
this,
|
||||||
|
&ImagesCarousel::_onImagesLoaded);
|
||||||
|
|
||||||
// Auto focus when scrolling
|
// Auto focus when scrolling
|
||||||
m_scrollDebounceTimer = new QTimer(this);
|
m_scrollDebounceTimer = new QTimer(this);
|
||||||
m_scrollDebounceTimer->setSingleShot(true);
|
m_scrollDebounceTimer->setSingleShot(true);
|
||||||
@@ -78,6 +90,7 @@ ImagesCarousel::ImagesCarousel(const Config::StyleConfigItems& styleConfig,
|
|||||||
|
|
||||||
void ImagesCarousel::_onInitImagesLoaded() {
|
void ImagesCarousel::_onInitImagesLoaded() {
|
||||||
disconnect(this, &ImagesCarousel::loadingCompleted, this, &ImagesCarousel::_onInitImagesLoaded);
|
disconnect(this, &ImagesCarousel::loadingCompleted, this, &ImagesCarousel::_onInitImagesLoaded);
|
||||||
|
disconnect(this, &ImagesCarousel::stopped, this, &ImagesCarousel::_onInitImagesLoaded);
|
||||||
|
|
||||||
// No images loaded
|
// No images loaded
|
||||||
if (m_loadedImages.isEmpty()) {
|
if (m_loadedImages.isEmpty()) {
|
||||||
|
|||||||
+32
-25
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author: Uyanide pywang0608@foxmail.com
|
* @Author: Uyanide pywang0608@foxmail.com
|
||||||
* @Date: 2025-08-05 00:37:58
|
* @Date: 2025-08-05 00:37:58
|
||||||
* @LastEditTime: 2025-11-30 22:37:48
|
* @LastEditTime: 2025-12-01 00:44:06
|
||||||
* @Description: MainWindow implementation.
|
* @Description: MainWindow implementation.
|
||||||
*/
|
*/
|
||||||
#include "main_window.h"
|
#include "main_window.h"
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
#include "./ui_main_window.h"
|
#include "./ui_main_window.h"
|
||||||
#include "images_carousel.h"
|
#include "images_carousel.h"
|
||||||
@@ -134,38 +135,45 @@ void MainWindow::keyPressEvent(QKeyEvent* event) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::_onCancelPressed() {
|
void MainWindow::_stopLoadingAndQuit(const std::function<void()>& onStopped) {
|
||||||
switch (m_state) {
|
if (m_state != Loading) {
|
||||||
case Loading:
|
return;
|
||||||
// case loading screen is disabled, quit the app
|
|
||||||
if (m_config.getStyleConfig().noLoadingScreen) {
|
|
||||||
info("Stopping loading and quitting app.");
|
|
||||||
connect(
|
|
||||||
m_carousel,
|
|
||||||
&ImagesCarousel::stopped,
|
|
||||||
this,
|
|
||||||
&MainWindow::onCancel);
|
|
||||||
m_state = Stopping;
|
|
||||||
emit stop();
|
|
||||||
}
|
}
|
||||||
// otherwise, stop loading and display the loaded images
|
|
||||||
else {
|
|
||||||
info("Stopping loading.");
|
info("Stopping loading.");
|
||||||
connect(
|
connect(
|
||||||
m_carousel,
|
m_carousel,
|
||||||
&ImagesCarousel::stopped,
|
&ImagesCarousel::stopped,
|
||||||
this,
|
this,
|
||||||
[this]() {
|
[this, onStopped]() {
|
||||||
_onLoadingCompleted(m_carousel->getLoadedImagesCount());
|
if (onStopped) {
|
||||||
m_carousel->focusCurrImage();
|
onStopped();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
m_state = Stopping;
|
m_state = Stopping;
|
||||||
emit stop();
|
emit stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::_onCancelPressed() {
|
||||||
|
switch (m_state) {
|
||||||
|
case Loading:
|
||||||
|
// case loading screen is disabled, quit the app
|
||||||
|
if (m_config.getStyleConfig().noLoadingScreen) {
|
||||||
|
_stopLoadingAndQuit([this]() {
|
||||||
|
info("Quitting app.");
|
||||||
|
close();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// otherwise, stop loading and display the loaded images
|
||||||
|
else {
|
||||||
|
_stopLoadingAndQuit([this]() {
|
||||||
|
_onLoadingCompleted(m_carousel->getLoadedImagesCount());
|
||||||
|
m_carousel->focusCurrImage();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Ready:
|
case Ready:
|
||||||
info("Quitting app.");
|
info("Quitting app.");
|
||||||
onCancel();
|
close();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -213,7 +221,10 @@ void MainWindow::wheelEvent(QWheelEvent* event) {
|
|||||||
void MainWindow::closeEvent(QCloseEvent* event) {
|
void MainWindow::closeEvent(QCloseEvent* event) {
|
||||||
if (m_state == Loading) {
|
if (m_state == Loading) {
|
||||||
event->ignore();
|
event->ignore();
|
||||||
_onCancelPressed();
|
_stopLoadingAndQuit([this]() {
|
||||||
|
info("Quitting app.");
|
||||||
|
close();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
@@ -243,10 +254,6 @@ void MainWindow::onConfirm() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::onCancel() {
|
|
||||||
close();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MainWindow::_onImageFocused(const QString& path, const int index, const int count) {
|
void MainWindow::_onImageFocused(const QString& path, const int index, const int count) {
|
||||||
ui->topLabel->setText(QString("%1 (%2/%3)").arg(splitNameFromPath(path)).arg(index + 1).arg(count));
|
ui->topLabel->setText(QString("%1 (%2/%3)").arg(splitNameFromPath(path)).arg(index + 1).arg(count));
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author: Uyanide pywang0608@foxmail.com
|
* @Author: Uyanide pywang0608@foxmail.com
|
||||||
* @Date: 2025-08-05 00:37:58
|
* @Date: 2025-08-05 00:37:58
|
||||||
* @LastEditTime: 2025-11-30 22:37:27
|
* @LastEditTime: 2025-12-01 00:37:35
|
||||||
* @Description: MainWindow implementation.
|
* @Description: MainWindow implementation.
|
||||||
*/
|
*/
|
||||||
#ifndef MAINWINDOW_H
|
#ifndef MAINWINDOW_H
|
||||||
@@ -30,7 +30,6 @@ class MainWindow : public QMainWindow {
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void onConfirm();
|
void onConfirm();
|
||||||
void onCancel();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent* event) override;
|
void keyPressEvent(QKeyEvent* event) override;
|
||||||
@@ -39,6 +38,7 @@ class MainWindow : public QMainWindow {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void _setupUI();
|
void _setupUI();
|
||||||
|
void _stopLoadingAndQuit(const std::function<void()>& onStopped = nullptr);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void _onImageFocused(const QString& path, const int index, const int count);
|
void _onImageFocused(const QString& path, const int index, const int count);
|
||||||
|
|||||||
Reference in New Issue
Block a user