fix ui state save
This commit is contained in:
5 files changed
+56
-17
No files matched your search
@@ -112,7 +112,7 @@ Backend (C++) handles all file I/O, format parsing, text layout calculation, and
|
|||||||
| `book` (`Book`) | Open/close book, async loading, error state, metadata (title, author, coverImageUrl). Owns `FormatReader`. |
|
| `book` (`Book`) | Open/close book, async loading, error state, metadata (title, author, coverImageUrl). Owns `FormatReader`. |
|
||||||
| `readingModel` (`ReadingModel`) | `QAbstractListModel` exposing chunks (`ContentRole`, `LayoutRole`, `PixelHeightRole`), layout updates, reading mode (`isTextMode`, `isMangaMode`), manga page pairs, and per-book toggles (`pageShift`, `mangaRTL`, `useBookColours`). |
|
| `readingModel` (`ReadingModel`) | `QAbstractListModel` exposing chunks (`ContentRole`, `LayoutRole`, `PixelHeightRole`), layout updates, reading mode (`isTextMode`, `isMangaMode`), manga page pairs, and per-book toggles (`pageShift`, `mangaRTL`, `useBookColours`). |
|
||||||
| `readingPreferences` (`ReadingPreferences`) | Font size, line spacing, horizontal margin, vertical margin (`QSettings`). |
|
| `readingPreferences` (`ReadingPreferences`) | Font size, line spacing, horizontal margin, vertical margin (`QSettings`). |
|
||||||
| `uiState` (`UiState`) | Current theme, last page, sidebar open state, last file path, custom theme colors, window geometry. |
|
| `uiState` (`UiState`) | Current theme, last page, sidebar open state, reader bars visibility (`barsVisible`), last file path, custom theme colors, window geometry. |
|
||||||
| `historyModel` (`HistoryModel`) | `QAbstractListModel` of recent books with async metadata extraction and reading progress. |
|
| `historyModel` (`HistoryModel`) | `QAbstractListModel` of recent books with async metadata extraction and reading progress. |
|
||||||
| `isDebugBuild` | Boolean constant indicating debug build. |
|
| `isDebugBuild` | Boolean constant indicating debug build. |
|
||||||
|
|
||||||
@@ -187,6 +187,7 @@ public:
|
|||||||
|
|
||||||
## Position Restoration & State Persistence
|
## Position Restoration & State Persistence
|
||||||
- **Position Persistence**: `BookPositionStore` persists `BookPosition` (`chunkIndex`, `intraOffset`, `progress`, `pageShift`, `mangaRTL`, `useBookColours`) indexed by file content MD5 (`contentHash()`), ensuring state survives file renames or moves.
|
- **Position Persistence**: `BookPositionStore` persists `BookPosition` (`chunkIndex`, `intraOffset`, `progress`, `pageShift`, `mangaRTL`, `useBookColours`) indexed by file content MD5 (`contentHash()`), ensuring state survives file renames or moves.
|
||||||
|
- **UI State Persistence**: `UiState` persists `themeName`, `lastPage`, `sidebarOpen`, `barsVisible`, `lastFilePath`, `customTheme`, and window geometry. Distraction-free chrome toggling via spacebar toggles `barsVisible` without destroying the persistent `sidebarOpen` user preference; effective sidebar visibility in reader mode is gated by `(!inReader || barsVisible) && uiState.sidebarOpen`.
|
||||||
- **Restoration Flow**:
|
- **Restoration Flow**:
|
||||||
- Text mode: `ReadingModel` computes layout for the saved anchor chunk first, then emits `restoreReady(chunkIndex, intraOffset)`. `ScrollPageView` positions the `ListView` at `chunkIndex` and applies `intraOffset`.
|
- Text mode: `ReadingModel` computes layout for the saved anchor chunk first, then emits `restoreReady(chunkIndex, intraOffset)`. `ScrollPageView` positions the `ListView` at `chunkIndex` and applies `intraOffset`.
|
||||||
- Comic mode: `restoreReady(chunkIndex)` triggers `MangaPageView.showPair(pairIndexForChunk(chunkIndex))`.
|
- Comic mode: `restoreReady(chunkIndex)` triggers `MangaPageView.showPair(pairIndexForChunk(chunkIndex))`.
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ UiState::UiState(AppState &state, QObject *parent)
|
|||||||
m_themeName = d.value(QStringLiteral("themeName"), QStringLiteral("dark")).toString();
|
m_themeName = d.value(QStringLiteral("themeName"), QStringLiteral("dark")).toString();
|
||||||
m_lastPage = d.value(QStringLiteral("lastPage"), QStringLiteral("starter")).toString();
|
m_lastPage = d.value(QStringLiteral("lastPage"), QStringLiteral("starter")).toString();
|
||||||
m_sidebarOpen = d.value(QStringLiteral("sidebarOpen"), false).toBool();
|
m_sidebarOpen = d.value(QStringLiteral("sidebarOpen"), false).toBool();
|
||||||
|
m_barsVisible = d.value(QStringLiteral("barsVisible"), true).toBool();
|
||||||
m_lastFilePath = d.value(QStringLiteral("lastFilePath"), QString()).toString();
|
m_lastFilePath = d.value(QStringLiteral("lastFilePath"), QString()).toString();
|
||||||
m_customThemeColors = state.loadSection(QStringLiteral("customTheme"));
|
m_customThemeColors = state.loadSection(QStringLiteral("customTheme"));
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ UiState::UiState(AppState &state, QObject *parent)
|
|||||||
QString UiState::themeName() const { return m_themeName; }
|
QString UiState::themeName() const { return m_themeName; }
|
||||||
QString UiState::lastPage() const { return m_lastPage; }
|
QString UiState::lastPage() const { return m_lastPage; }
|
||||||
bool UiState::sidebarOpen() const { return m_sidebarOpen; }
|
bool UiState::sidebarOpen() const { return m_sidebarOpen; }
|
||||||
|
bool UiState::barsVisible() const { return m_barsVisible; }
|
||||||
QString UiState::lastFilePath() const { return m_lastFilePath; }
|
QString UiState::lastFilePath() const { return m_lastFilePath; }
|
||||||
QVariantMap UiState::customThemeColors() const { return m_customThemeColors; }
|
QVariantMap UiState::customThemeColors() const { return m_customThemeColors; }
|
||||||
int UiState::windowWidth() const { return m_width; }
|
int UiState::windowWidth() const { return m_width; }
|
||||||
@@ -48,6 +50,13 @@ void UiState::setSidebarOpen(bool open)
|
|||||||
emit sidebarOpenChanged();
|
emit sidebarOpenChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiState::setBarsVisible(bool visible)
|
||||||
|
{
|
||||||
|
if (m_barsVisible == visible) return;
|
||||||
|
m_barsVisible = visible;
|
||||||
|
emit barsVisibleChanged();
|
||||||
|
}
|
||||||
|
|
||||||
void UiState::setLastFilePath(const QString &path)
|
void UiState::setLastFilePath(const QString &path)
|
||||||
{
|
{
|
||||||
if (m_lastFilePath == path) return;
|
if (m_lastFilePath == path) return;
|
||||||
@@ -96,6 +105,7 @@ void UiState::save()
|
|||||||
{QStringLiteral("themeName"), m_themeName},
|
{QStringLiteral("themeName"), m_themeName},
|
||||||
{QStringLiteral("lastPage"), m_lastPage},
|
{QStringLiteral("lastPage"), m_lastPage},
|
||||||
{QStringLiteral("sidebarOpen"), m_sidebarOpen},
|
{QStringLiteral("sidebarOpen"), m_sidebarOpen},
|
||||||
|
{QStringLiteral("barsVisible"), m_barsVisible},
|
||||||
{QStringLiteral("lastFilePath"), m_lastFilePath},
|
{QStringLiteral("lastFilePath"), m_lastFilePath},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class UiState : public QObject {
|
|||||||
Q_PROPERTY(QString themeName READ themeName WRITE setThemeName NOTIFY themeNameChanged)
|
Q_PROPERTY(QString themeName READ themeName WRITE setThemeName NOTIFY themeNameChanged)
|
||||||
Q_PROPERTY(QString lastPage READ lastPage WRITE setLastPage NOTIFY lastPageChanged)
|
Q_PROPERTY(QString lastPage READ lastPage WRITE setLastPage NOTIFY lastPageChanged)
|
||||||
Q_PROPERTY(bool sidebarOpen READ sidebarOpen WRITE setSidebarOpen NOTIFY sidebarOpenChanged)
|
Q_PROPERTY(bool sidebarOpen READ sidebarOpen WRITE setSidebarOpen NOTIFY sidebarOpenChanged)
|
||||||
|
Q_PROPERTY(bool barsVisible READ barsVisible WRITE setBarsVisible NOTIFY barsVisibleChanged)
|
||||||
Q_PROPERTY(QString lastFilePath READ lastFilePath WRITE setLastFilePath NOTIFY lastFilePathChanged)
|
Q_PROPERTY(QString lastFilePath READ lastFilePath WRITE setLastFilePath NOTIFY lastFilePathChanged)
|
||||||
Q_PROPERTY(QVariantMap customThemeColors READ customThemeColors WRITE setCustomThemeColors NOTIFY customThemeColorsChanged)
|
Q_PROPERTY(QVariantMap customThemeColors READ customThemeColors WRITE setCustomThemeColors NOTIFY customThemeColorsChanged)
|
||||||
Q_PROPERTY(int windowWidth READ windowWidth WRITE setWindowWidth NOTIFY windowWidthChanged)
|
Q_PROPERTY(int windowWidth READ windowWidth WRITE setWindowWidth NOTIFY windowWidthChanged)
|
||||||
@@ -23,6 +24,7 @@ public:
|
|||||||
QString themeName() const;
|
QString themeName() const;
|
||||||
QString lastPage() const;
|
QString lastPage() const;
|
||||||
bool sidebarOpen() const;
|
bool sidebarOpen() const;
|
||||||
|
bool barsVisible() const;
|
||||||
QString lastFilePath() const;
|
QString lastFilePath() const;
|
||||||
QVariantMap customThemeColors() const;
|
QVariantMap customThemeColors() const;
|
||||||
int windowWidth() const;
|
int windowWidth() const;
|
||||||
@@ -33,6 +35,7 @@ public:
|
|||||||
void setThemeName(const QString &name);
|
void setThemeName(const QString &name);
|
||||||
void setLastPage(const QString &page);
|
void setLastPage(const QString &page);
|
||||||
void setSidebarOpen(bool open);
|
void setSidebarOpen(bool open);
|
||||||
|
void setBarsVisible(bool visible);
|
||||||
void setLastFilePath(const QString &path);
|
void setLastFilePath(const QString &path);
|
||||||
void setCustomThemeColors(const QVariantMap &colors);
|
void setCustomThemeColors(const QVariantMap &colors);
|
||||||
void setWindowWidth(int w);
|
void setWindowWidth(int w);
|
||||||
@@ -46,6 +49,7 @@ signals:
|
|||||||
void themeNameChanged();
|
void themeNameChanged();
|
||||||
void lastPageChanged();
|
void lastPageChanged();
|
||||||
void sidebarOpenChanged();
|
void sidebarOpenChanged();
|
||||||
|
void barsVisibleChanged();
|
||||||
void lastFilePathChanged();
|
void lastFilePathChanged();
|
||||||
void customThemeColorsChanged();
|
void customThemeColorsChanged();
|
||||||
void windowWidthChanged();
|
void windowWidthChanged();
|
||||||
@@ -58,6 +62,7 @@ private:
|
|||||||
QString m_themeName = QStringLiteral("dark");
|
QString m_themeName = QStringLiteral("dark");
|
||||||
QString m_lastPage = QStringLiteral("starter");
|
QString m_lastPage = QStringLiteral("starter");
|
||||||
bool m_sidebarOpen = false;
|
bool m_sidebarOpen = false;
|
||||||
|
bool m_barsVisible = true;
|
||||||
QString m_lastFilePath;
|
QString m_lastFilePath;
|
||||||
QVariantMap m_customThemeColors;
|
QVariantMap m_customThemeColors;
|
||||||
int m_width = 1024;
|
int m_width = 1024;
|
||||||
|
|||||||
+18
-16
@@ -17,25 +17,19 @@ ApplicationWindow {
|
|||||||
source: "qrc:/Asteria/src/assets/MaterialIconsOutlined-Regular.otf"
|
source: "qrc:/Asteria/src/assets/MaterialIconsOutlined-Regular.otf"
|
||||||
}
|
}
|
||||||
|
|
||||||
// uiState.sidebarOpen is the single source of truth; writers set it directly.
|
// uiState.sidebarOpen is user preference; visible sidebar is gated by barsVisible in reader mode.
|
||||||
readonly property bool sidebarOpen: uiState.sidebarOpen
|
readonly property bool barsVisible: uiState.barsVisible
|
||||||
|
readonly property bool inReader: currentPage === "reader" || (_startupRestore && uiState.lastPage === "reader")
|
||||||
|
readonly property bool sidebarOpen: (!inReader || barsVisible) && uiState.sidebarOpen
|
||||||
property string currentPage: "starter"
|
property string currentPage: "starter"
|
||||||
property bool settingsOpen: false
|
property bool settingsOpen: false
|
||||||
property bool barsVisible: true
|
|
||||||
property bool _savedSidebarOpen: false
|
|
||||||
// Set to true on the first book open at startup so we restore the last page.
|
// Set to true on the first book open at startup so we restore the last page.
|
||||||
property bool _startupRestore: false
|
property bool _startupRestore: uiState.lastFilePath !== ""
|
||||||
property bool _bookInitializing: false
|
property bool _bookInitializing: false
|
||||||
|
|
||||||
function toggleChrome() {
|
function toggleChrome() {
|
||||||
var anyVisible = barsVisible || sidebarOpen
|
if (currentPage === "reader") {
|
||||||
if (anyVisible) {
|
uiState.barsVisible = !uiState.barsVisible
|
||||||
_savedSidebarOpen = sidebarOpen
|
|
||||||
barsVisible = false
|
|
||||||
uiState.sidebarOpen = false
|
|
||||||
} else {
|
|
||||||
barsVisible = true
|
|
||||||
uiState.sidebarOpen = _savedSidebarOpen
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,13 +60,20 @@ ApplicationWindow {
|
|||||||
if (book.loading) window._bookInitializing = true
|
if (book.loading) window._bookInitializing = true
|
||||||
}
|
}
|
||||||
function onErrorMessageChanged() {
|
function onErrorMessageChanged() {
|
||||||
if (book.errorMessage !== "") window._bookInitializing = false
|
if (book.errorMessage !== "") {
|
||||||
|
window._bookInitializing = false
|
||||||
|
window._startupRestore = false
|
||||||
|
uiState.barsVisible = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
function onBookChanged() {
|
function onBookChanged() {
|
||||||
if (!book.hasBook && window.currentPage === "reader")
|
if (!book.hasBook) {
|
||||||
|
uiState.barsVisible = true
|
||||||
|
if (window.currentPage === "reader")
|
||||||
window.currentPage = "history"
|
window.currentPage = "history"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: geometrySaveTimer
|
id: geometrySaveTimer
|
||||||
@@ -125,7 +126,7 @@ ApplicationWindow {
|
|||||||
width: parent.width
|
width: parent.width
|
||||||
sidebarOpen: window.sidebarOpen
|
sidebarOpen: window.sidebarOpen
|
||||||
currentPage: window.currentPage
|
currentPage: window.currentPage
|
||||||
barsVisible: window.currentPage !== "reader" || window.barsVisible
|
barsVisible: !window.inReader || window.barsVisible
|
||||||
onMenuClicked: uiState.sidebarOpen = true
|
onMenuClicked: uiState.sidebarOpen = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,6 +293,7 @@ ApplicationWindow {
|
|||||||
if (savedPage === "history")
|
if (savedPage === "history")
|
||||||
window.currentPage = savedPage
|
window.currentPage = savedPage
|
||||||
uiState.sidebarOpen = true
|
uiState.sidebarOpen = true
|
||||||
|
uiState.barsVisible = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ private slots:
|
|||||||
QCOMPARE(ui.themeName(), QStringLiteral("dark"));
|
QCOMPARE(ui.themeName(), QStringLiteral("dark"));
|
||||||
QCOMPARE(ui.lastPage(), QStringLiteral("starter"));
|
QCOMPARE(ui.lastPage(), QStringLiteral("starter"));
|
||||||
QCOMPARE(ui.sidebarOpen(), false);
|
QCOMPARE(ui.sidebarOpen(), false);
|
||||||
|
QCOMPARE(ui.barsVisible(), true);
|
||||||
QCOMPARE(ui.lastFilePath(), QString());
|
QCOMPARE(ui.lastFilePath(), QString());
|
||||||
QCOMPARE(ui.windowWidth(), 1024);
|
QCOMPARE(ui.windowWidth(), 1024);
|
||||||
QCOMPARE(ui.windowHeight(), 768);
|
QCOMPARE(ui.windowHeight(), 768);
|
||||||
@@ -48,6 +49,7 @@ private slots:
|
|||||||
ui.setThemeName(QStringLiteral("light"));
|
ui.setThemeName(QStringLiteral("light"));
|
||||||
ui.setLastPage(QStringLiteral("settings"));
|
ui.setLastPage(QStringLiteral("settings"));
|
||||||
ui.setSidebarOpen(true);
|
ui.setSidebarOpen(true);
|
||||||
|
ui.setBarsVisible(false);
|
||||||
ui.setLastFilePath(QStringLiteral("/some/file.epub"));
|
ui.setLastFilePath(QStringLiteral("/some/file.epub"));
|
||||||
ui.setWindowWidth(1280);
|
ui.setWindowWidth(1280);
|
||||||
ui.setWindowHeight(800);
|
ui.setWindowHeight(800);
|
||||||
@@ -63,6 +65,7 @@ private slots:
|
|||||||
QCOMPARE(ui2.themeName(), QStringLiteral("light"));
|
QCOMPARE(ui2.themeName(), QStringLiteral("light"));
|
||||||
QCOMPARE(ui2.lastPage(), QStringLiteral("settings"));
|
QCOMPARE(ui2.lastPage(), QStringLiteral("settings"));
|
||||||
QCOMPARE(ui2.sidebarOpen(), true);
|
QCOMPARE(ui2.sidebarOpen(), true);
|
||||||
|
QCOMPARE(ui2.barsVisible(), false);
|
||||||
QCOMPARE(ui2.lastFilePath(), QStringLiteral("/some/file.epub"));
|
QCOMPARE(ui2.lastFilePath(), QStringLiteral("/some/file.epub"));
|
||||||
QCOMPARE(ui2.windowWidth(), 1280);
|
QCOMPARE(ui2.windowWidth(), 1280);
|
||||||
QCOMPARE(ui2.windowHeight(), 800);
|
QCOMPARE(ui2.windowHeight(), 800);
|
||||||
@@ -103,6 +106,24 @@ private slots:
|
|||||||
ui.setWindowWidth(999); // no-op
|
ui.setWindowWidth(999); // no-op
|
||||||
QCOMPARE(spy.count(), 1);
|
QCOMPARE(spy.count(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void barsVisibleSignal()
|
||||||
|
{
|
||||||
|
QTemporaryFile f;
|
||||||
|
f.setFileTemplate(QDir::tempPath() + QStringLiteral("/ui-sig-bv-XXXXXX.ini"));
|
||||||
|
(void)f.open(); f.close();
|
||||||
|
QSettings s(f.fileName(), QSettings::IniFormat);
|
||||||
|
AppState appState(s);
|
||||||
|
UiState ui(appState);
|
||||||
|
|
||||||
|
QSignalSpy spy(&ui, &UiState::barsVisibleChanged);
|
||||||
|
ui.setBarsVisible(false);
|
||||||
|
QCOMPARE(spy.count(), 1);
|
||||||
|
ui.setBarsVisible(false); // no-op
|
||||||
|
QCOMPARE(spy.count(), 1);
|
||||||
|
ui.setBarsVisible(true);
|
||||||
|
QCOMPARE(spy.count(), 2);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
QTEST_MAIN(UiStateTest)
|
QTEST_MAIN(UiStateTest)
|
||||||
|
|||||||
Reference in new issue
Block a user