wip: fix: stop logic
This commit is contained in:
+14
-1
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author: Uyanide pywang0608@foxmail.com
|
||||
* @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.
|
||||
*/
|
||||
#include "images_carousel.h"
|
||||
@@ -54,6 +54,18 @@ ImagesCarousel::ImagesCarousel(const Config::StyleConfigItems& styleConfig,
|
||||
this,
|
||||
&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
|
||||
m_scrollDebounceTimer = new QTimer(this);
|
||||
m_scrollDebounceTimer->setSingleShot(true);
|
||||
@@ -78,6 +90,7 @@ ImagesCarousel::ImagesCarousel(const Config::StyleConfigItems& styleConfig,
|
||||
|
||||
void ImagesCarousel::_onInitImagesLoaded() {
|
||||
disconnect(this, &ImagesCarousel::loadingCompleted, this, &ImagesCarousel::_onInitImagesLoaded);
|
||||
disconnect(this, &ImagesCarousel::stopped, this, &ImagesCarousel::_onInitImagesLoaded);
|
||||
|
||||
// No images loaded
|
||||
if (m_loadedImages.isEmpty()) {
|
||||
|
||||
+33
-26
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* @Author: Uyanide pywang0608@foxmail.com
|
||||
* @Date: 2025-08-05 00:37:58
|
||||
* @LastEditTime: 2025-11-30 22:37:48
|
||||
* @LastEditTime: 2025-12-01 00:44:06
|
||||
* @Description: MainWindow implementation.
|
||||
*/
|
||||
#include "main_window.h"
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <QKeyEvent>
|
||||
#include <QProcess>
|
||||
#include <QPushButton>
|
||||
#include <functional>
|
||||
|
||||
#include "./ui_main_window.h"
|
||||
#include "images_carousel.h"
|
||||
@@ -134,38 +135,45 @@ void MainWindow::keyPressEvent(QKeyEvent* event) {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::_stopLoadingAndQuit(const std::function<void()>& onStopped) {
|
||||
if (m_state != Loading) {
|
||||
return;
|
||||
}
|
||||
info("Stopping loading.");
|
||||
connect(
|
||||
m_carousel,
|
||||
&ImagesCarousel::stopped,
|
||||
this,
|
||||
[this, onStopped]() {
|
||||
if (onStopped) {
|
||||
onStopped();
|
||||
}
|
||||
});
|
||||
m_state = Stopping;
|
||||
emit stop();
|
||||
}
|
||||
|
||||
void MainWindow::_onCancelPressed() {
|
||||
switch (m_state) {
|
||||
case Loading:
|
||||
// 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();
|
||||
_stopLoadingAndQuit([this]() {
|
||||
info("Quitting app.");
|
||||
close();
|
||||
});
|
||||
}
|
||||
// otherwise, stop loading and display the loaded images
|
||||
else {
|
||||
info("Stopping loading.");
|
||||
connect(
|
||||
m_carousel,
|
||||
&ImagesCarousel::stopped,
|
||||
this,
|
||||
[this]() {
|
||||
_onLoadingCompleted(m_carousel->getLoadedImagesCount());
|
||||
m_carousel->focusCurrImage();
|
||||
});
|
||||
m_state = Stopping;
|
||||
emit stop();
|
||||
_stopLoadingAndQuit([this]() {
|
||||
_onLoadingCompleted(m_carousel->getLoadedImagesCount());
|
||||
m_carousel->focusCurrImage();
|
||||
});
|
||||
}
|
||||
break;
|
||||
case Ready:
|
||||
info("Quitting app.");
|
||||
onCancel();
|
||||
close();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -213,7 +221,10 @@ void MainWindow::wheelEvent(QWheelEvent* event) {
|
||||
void MainWindow::closeEvent(QCloseEvent* event) {
|
||||
if (m_state == Loading) {
|
||||
event->ignore();
|
||||
_onCancelPressed();
|
||||
_stopLoadingAndQuit([this]() {
|
||||
info("Quitting app.");
|
||||
close();
|
||||
});
|
||||
} else {
|
||||
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) {
|
||||
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
|
||||
* @Date: 2025-08-05 00:37:58
|
||||
* @LastEditTime: 2025-11-30 22:37:27
|
||||
* @LastEditTime: 2025-12-01 00:37:35
|
||||
* @Description: MainWindow implementation.
|
||||
*/
|
||||
#ifndef MAINWINDOW_H
|
||||
@@ -30,7 +30,6 @@ class MainWindow : public QMainWindow {
|
||||
|
||||
public slots:
|
||||
void onConfirm();
|
||||
void onCancel();
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event) override;
|
||||
@@ -39,6 +38,7 @@ class MainWindow : public QMainWindow {
|
||||
|
||||
private:
|
||||
void _setupUI();
|
||||
void _stopLoadingAndQuit(const std::function<void()>& onStopped = nullptr);
|
||||
|
||||
private slots:
|
||||
void _onImageFocused(const QString& path, const int index, const int count);
|
||||
|
||||
Reference in New Issue
Block a user