updated docs
This commit is contained in:
1 file changed
+177
-215
@@ -1,47 +1,62 @@
|
|||||||
# CLAUDE.md
|
# AGENTS.md
|
||||||
|
|
||||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
This file provides guidance to AI coding assistants (Claude Code, Antigravity, etc.) when working with code in this repository.
|
||||||
|
|
||||||
## Project Overview
|
## Project Overview
|
||||||
|
|
||||||
Asteria Qt is a cross-platform desktop book/document reader built with Qt6/C++. It is a reimplementation of [asteria-bookreader](../asteria-bookreader) (Electron/React) using a native Qt stack.
|
Asteria Qt is a cross-platform desktop book/document reader built with Qt6/C++. It is a reimplementation of [asteria-bookreader](../asteria-bookreader) (Electron/React) using a native Qt stack.
|
||||||
|
|
||||||
|
**Core Mission:** Asteria Qt is strictly focused on **rendering performance**. The architecture is engineered from the ground up for smooth scrolling, high refresh rates (60fps+), low UI latency, off-thread layout calculations, virtualized rendering, and instant image display across large documents and high-resolution comic archives.
|
||||||
|
|
||||||
**Target platforms:** Windows, Linux, and macOS
|
**Target platforms:** Windows, Linux, and macOS
|
||||||
|
|
||||||
### Format Support
|
---
|
||||||
|
|
||||||
Initial implementation: **TXT, FB2, EPUB, CBZ, CBR, Folder of images**
|
## Mandatory Rules for AI Agents
|
||||||
|
|
||||||
Full target format list (derived from actual library inventory):
|
1. **Keep Documentation Updated (AGENTS.md):** Whenever you make architectural changes, add/modify readers or models, change state persistence, alter layout pipelines, or add QML components, **you MUST update `AGENTS.md` in the same commit/task**. Never allow documentation to diverge from the codebase.
|
||||||
|
2. **Preserve Rendering Performance:** Do not introduce UI-thread blocking operations. Heavy file parsing, layout calculation, image scaling, and metadata extraction must run asynchronously or off-thread.
|
||||||
|
3. **Strictly Follow SOLID Principles:** Keep format decoders, layout engines, image providers, and UI models cleanly decoupled.
|
||||||
|
4. **Maintain High Test Coverage (80%+):** Use the `Qt Test` (`QTest`) framework. Always run `ctest --test-dir build --output-on-failure` after code modifications.
|
||||||
|
|
||||||
| Format | Count | Priority | Approach |
|
---
|
||||||
|---|-------|---|---|
|
|
||||||
| EPUB | ~2500 | initial | Unzip (QuaZip/minizip) + parse OPF spine + render HTML |
|
|
||||||
| FB2 | ~1900 | initial | `QXmlStreamReader` (pure XML) |
|
|
||||||
| TXT | ~170 | initial | `QTextStream` + encoding detection (uchardet/ICU) |
|
|
||||||
| CBZ | ??? | initial | Unzip (minizip) + parse optional ComicInfo.xml + one image per chunk |
|
|
||||||
| PDF | ~520 | high | `QtPdf` module (`QPdfDocument`, Qt 6.4+) |
|
|
||||||
| DOC | ~330 | high | `libwpd` or antiword subprocess |
|
|
||||||
| RTF | ~260 | high | `QTextDocumentReader` or RTF→HTML |
|
|
||||||
| HTML/HTM | ~350 | high | `QTextDocument` / `QWebEngineView` |
|
|
||||||
| DOCX | ~65 | medium | Unzip + parse `word/document.xml` (`QXmlStreamReader`) |
|
|
||||||
| DJVU | ~60 | medium | `DjVuLibre` |
|
|
||||||
| ODT | ~5 | medium | Unzip + parse OpenDocument XML |
|
|
||||||
| CHM | ~5 | medium | `CHMLib` |
|
|
||||||
| PDB | small | low | Palm/Mobipocket format |
|
|
||||||
| ZIP/RAR | ~210 | low | Inspect contents; open book files within archive |
|
|
||||||
|
|
||||||
> ACSM files are Adobe DRM tokens — not directly readable; skip.
|
## Format Support
|
||||||
> PPT/XLS and source code files (.py, .cs, etc.) are in the library from programming books; no need to render them.
|
|
||||||
|
Active implementation: **EPUB, CBZ, CBR, Folder of images**
|
||||||
|
Queued for reimplementation on new render pipeline: **TXT, FB2**
|
||||||
|
|
||||||
|
Full target format list:
|
||||||
|
|
||||||
|
| Format | Active | Approach |
|
||||||
|
|---|---|---|
|
||||||
|
| EPUB | Yes | Unzip (`ZipByteSource`) + parse OPF spine + CSS parser + Knuth-Plass text layout |
|
||||||
|
| CBZ | Yes | Unzip (`ZipByteSource`) + `ComicReader` + `MangaPagination` (single/dual page spread) |
|
||||||
|
| CBR | Yes | `libarchive` (`RarByteSource`) + `ComicReader` + `MangaPagination` |
|
||||||
|
| Folder | Yes | Directory scan (`DirByteSource`) + `ComicReader` + `MangaPagination` |
|
||||||
|
| FB2 | Queued | `QXmlStreamReader` + convert sections to chunks for `ChunkLayoutEngine` |
|
||||||
|
| TXT | Queued | `QTextStream` + encoding detection + paginate for `ChunkLayoutEngine` |
|
||||||
|
| PDF | Planned | `QtPdf` module (`QPdfDocument`, Qt 6.4+) |
|
||||||
|
| DOC | Planned | `libwpd` or antiword subprocess |
|
||||||
|
| RTF | Planned | `QTextDocumentReader` or RTF→HTML |
|
||||||
|
| HTML/HTM | Planned | `HtmlBlockParser` / `ChunkLayoutEngine` |
|
||||||
|
| DOCX | Planned | Unzip + parse `word/document.xml` (`QXmlStreamReader`) |
|
||||||
|
| DJVU | Planned | `DjVuLibre` |
|
||||||
|
| ODT | Planned | Unzip + parse OpenDocument XML |
|
||||||
|
| CHM | Planned | `CHMLib` |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## Build & Install
|
## Build & Install
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
- Qt 6.10+ components: `Core`, `Gui`, `Qml`, `Quick`, `Widgets`, `Concurrent`, `Svg`, `QuickControls2`, `Test`, `Xml`, `Network`, optional `DBus`.
|
||||||
|
- Third-party packages: `minizip`, `libarchive`.
|
||||||
|
- Graphics API: Vulkan (Windows, Linux), Metal (macOS) configured via `QQuickWindow::setGraphicsApi()`.
|
||||||
|
|
||||||
### Windows Build Environment
|
### Windows Build Environment
|
||||||
|
Qt 6.10.3 at `C:\msys64\opt\qt\6.10.3\mingw_64`. MinGW toolchain at `C:\msys64\mingw64\bin\`:
|
||||||
Qt 6.10.3 is installed at `C:\msys64\opt\qt\6.10.3\mingw_64` (by `scripts/install-deps-windows.sh`). The MinGW toolchain is at `C:\msys64\mingw64\bin\`. Call binaries directly with full paths, but prepend `/c/msys64/mingw64/bin` to `PATH` so the compiler and its runtime DLLs are resolvable:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# Configure
|
|
||||||
PATH="/c/msys64/mingw64/bin:$PATH" "C:/msys64/mingw64/bin/cmake.exe" \
|
PATH="/c/msys64/mingw64/bin:$PATH" "C:/msys64/mingw64/bin/cmake.exe" \
|
||||||
-S . -B build -G Ninja \
|
-S . -B build -G Ninja \
|
||||||
-DCMAKE_BUILD_TYPE=Debug \
|
-DCMAKE_BUILD_TYPE=Debug \
|
||||||
@@ -50,256 +65,203 @@ PATH="/c/msys64/mingw64/bin:$PATH" "C:/msys64/mingw64/bin/cmake.exe" \
|
|||||||
-DCMAKE_CXX_COMPILER="C:/msys64/mingw64/bin/g++.exe" \
|
-DCMAKE_CXX_COMPILER="C:/msys64/mingw64/bin/g++.exe" \
|
||||||
-DCMAKE_PREFIX_PATH="c:\msys64\opt\qt\6.10.3\mingw_64"
|
-DCMAKE_PREFIX_PATH="c:\msys64\opt\qt\6.10.3\mingw_64"
|
||||||
|
|
||||||
# Build
|
|
||||||
PATH="/c/msys64/mingw64/bin:$PATH" "C:/msys64/mingw64/bin/ninja.exe" -C build
|
PATH="/c/msys64/mingw64/bin:$PATH" "C:/msys64/mingw64/bin/ninja.exe" -C build
|
||||||
|
|
||||||
# Test (Qt DLLs must be on PATH so test executables can load them)
|
|
||||||
PATH="/c/msys64/opt/qt/6.10.3/mingw_64/bin:/c/msys64/mingw64/bin:$PATH" "C:/msys64/mingw64/bin/ctest.exe" --test-dir build --output-on-failure
|
PATH="/c/msys64/opt/qt/6.10.3/mingw_64/bin:/c/msys64/mingw64/bin:$PATH" "C:/msys64/mingw64/bin/ctest.exe" --test-dir build --output-on-failure
|
||||||
```
|
```
|
||||||
|
|
||||||
Use Unix-style paths (`/c/msys64/...`) for `PATH` assignments — Windows-style paths are not recognised by the shell.
|
### Linux Build Environment (Ubuntu 24.04)
|
||||||
|
|
||||||
### Linux Build Environment
|
|
||||||
|
|
||||||
Base: **Ubuntu 24.04**. Ubuntu apt only ships Qt 6.4, which is too old; Qt 6.10.3 is installed via `aqtinstall`.
|
|
||||||
|
|
||||||
Run `scripts/install-deps-ubuntu.sh` to install all system packages and Qt, then:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cmake -S . -B build -G Ninja \
|
cmake -S . -B build -G Ninja \
|
||||||
-DCMAKE_BUILD_TYPE=Debug \
|
-DCMAKE_BUILD_TYPE=Debug \
|
||||||
-DCMAKE_PREFIX_PATH=/opt/qt/6.10.3/gcc_64
|
-DCMAKE_PREFIX_PATH=/opt/qt/6.10.3/gcc_64
|
||||||
|
|
||||||
ninja -C build
|
ninja -C build
|
||||||
ctest --test-dir build --output-on-failure
|
ctest --test-dir build --output-on-failure
|
||||||
```
|
```
|
||||||
|
|
||||||
System packages installed by the script:
|
|
||||||
|
|
||||||
| Package | Purpose |
|
|
||||||
|---|---|
|
|
||||||
| `build-essential` | GCC/G++ compiler |
|
|
||||||
| `cmake`, `ninja-build` | Build system |
|
|
||||||
| `git` | Version control |
|
|
||||||
| `libgl1-mesa-dev` | OpenGL headers (Qt) |
|
|
||||||
| `libxkbcommon-dev` | XKB headers (Qt) |
|
|
||||||
| `libuchardet-dev` | Encoding detection (TXT reader) |
|
|
||||||
| `zlib1g-dev` | zlib headers (required by minizip) |
|
|
||||||
| `libminizip-dev` | ZIP/EPUB extraction |
|
|
||||||
| `libarchive-dev` | RAR extraction (CBR) |
|
|
||||||
| `libdjvulibre-dev` | DjVu format |
|
|
||||||
| `libwpd-dev` | Legacy .doc format |
|
|
||||||
| `python3-venv` | For aqtinstall |
|
|
||||||
|
|
||||||
### macOS Build Environment
|
### macOS Build Environment
|
||||||
|
|
||||||
Requires macOS 12+ with Xcode Command Line Tools (`xcode-select --install`) and [Homebrew](https://brew.sh).
|
|
||||||
|
|
||||||
Run `scripts/install-deps-macos.sh` to install Homebrew packages and Qt, then:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
export PKG_CONFIG_PATH="$(brew --prefix libarchive)/lib/pkgconfig:$PKG_CONFIG_PATH"
|
||||||
cmake -B build -G Ninja \
|
cmake -B build -G Ninja \
|
||||||
-DCMAKE_BUILD_TYPE=Debug \
|
-DCMAKE_BUILD_TYPE=Debug \
|
||||||
-DCMAKE_PREFIX_PATH=/opt/qt/6.10.3/macos
|
-DCMAKE_PREFIX_PATH=/opt/qt/6.10.3/macos
|
||||||
|
|
||||||
cmake --build build --parallel
|
cmake --build build --parallel
|
||||||
ctest --test-dir build --output-on-failure
|
ctest --test-dir build --output-on-failure
|
||||||
```
|
```
|
||||||
|
|
||||||
Homebrew packages installed by the script: `cmake`, `ninja`, `pkg-config`, `uchardet`, `minizip`, `libarchive`. Qt 6.10.3 is installed via `aqtinstall` to `/opt/qt/6.10.3/macos` (universal binary, runs on both Apple Silicon and Intel).
|
---
|
||||||
|
|
||||||
**Note:** `libarchive` is keg-only on Homebrew and not automatically on the pkg-config search path. Before running cmake, set:
|
|
||||||
```bash
|
|
||||||
export PKG_CONFIG_PATH="$(brew --prefix libarchive)/lib/pkgconfig:$PKG_CONFIG_PATH"
|
|
||||||
```
|
|
||||||
|
|
||||||
macOS builds use Metal for rendering (already handled in `main.cpp` via `Q_OS_MACOS`). macOS cannot be cross-compiled from Linux; CI must run on a native macOS host.
|
|
||||||
|
|
||||||
### CI Build Environment
|
|
||||||
|
|
||||||
GitLab CI (`.gitlab-ci.yml`), stages: `build` → `package` → `wiki`.
|
|
||||||
|
|
||||||
The CI Docker image is built from `docker/Dockerfile.build` (Ubuntu 24.04 base) and contains:
|
|
||||||
- Native Linux toolchain + Qt 6.10.3 at `$QT_LINUX_DIR` (`/opt/qt/6.10.3/gcc_64`)
|
|
||||||
- MinGW-w64 cross-compilation toolchain + Qt 6.10.3 for Windows at `$QT_WINDOWS_DIR` (`/opt/qt/6.10.3/mingw_64`)
|
|
||||||
- Cross-compiled Windows sysroot at `$MINGW_SYSROOT` (`/opt/mingw-sysroot`) with libiconv and uchardet
|
|
||||||
- AppImage packaging tools (linuxdeploy, appimagetool)
|
|
||||||
|
|
||||||
Windows builds are cross-compiled from Linux using `scripts/mingw-w64-toolchain.cmake`.
|
|
||||||
|
|
||||||
#### Adding a new C/C++ dependency
|
|
||||||
|
|
||||||
**CRITICAL: whenever any dependency changes, all three files below MUST be updated in the same commit. Never update one without the others.**
|
|
||||||
|
|
||||||
When `CMakeLists.txt` gains a new `find_package` or `pkg_check_modules` dependency, update **all** of the following:
|
|
||||||
|
|
||||||
| File | What to add |
|
|
||||||
|---|---|
|
|
||||||
| `scripts/install-deps-ubuntu.sh` | `apt` package for Linux host builds |
|
|
||||||
| `scripts/install-deps-windows.sh` | `pacman` package for Windows host builds |
|
|
||||||
| `docker/Dockerfile.build` | `apt` package for CI Linux build; cross-compiled lib for CI Windows cross-build if needed |
|
|
||||||
|
|
||||||
## Development
|
|
||||||
|
|
||||||
- Keep test coverage high (80%+)
|
|
||||||
- Use `Qt Test` (`QTest`) framework — include `find_package(Qt6 REQUIRED COMPONENTS Test)` in CMakeLists
|
|
||||||
- Run `ctest --test-dir build --output-on-failure` and check for test coverage before considering any task complete
|
|
||||||
|
|
||||||
## Architecture
|
## Architecture
|
||||||
|
|
||||||
**Strictly follow SOLID principles.**
|
Backend (C++) handles all file I/O, format parsing, text layout calculation, and image decoding. QML handles UI. Communication is through `QObject` models and context properties.
|
||||||
|
|
||||||
**Backend (C++)** handles all file I/O and format parsing. **QML** handles all UI. They communicate via `QObject` models exposed to the QML engine via `setContextProperty()`.
|
|
||||||
|
|
||||||
**Position restoration:** Pixel-perfect position restoration is mandatory. On every book open, `ChunkMeasurer` pre-measures chunk heights (in background, parallel, via `IImageLoader` for images) before restoring `contentY`. Never restore using pixel offsets that were calculated before heights were measured.
|
|
||||||
|
|
||||||
### QObjects Exposed to QML
|
### QObjects Exposed to QML
|
||||||
|
|
||||||
| Object | Responsibility |
|
| Object | Responsibility |
|
||||||
|---|---|
|
|---|---|
|
||||||
| `Book` | Open/close book, owns reader (via `FormatRegistry`), exposes metadata (title, author), TOC |
|
| `book` (`Book`) | Open/close book, async loading, error state, metadata (title, author, coverImageUrl). Owns `FormatReader`. |
|
||||||
| `ReadingModel` | QAbstractListModel exposing chapter chunks (ContentRole), position, next/prev navigation, progress |
|
| `readingModel` (`ReadingModel`) | `QAbstractListModel` exposing chunks (`ContentRole`, `LayoutRole`, `PixelHeightRole`), layout updates, reading mode (`isTextMode`, `isMangaMode`), and manga page pairs. |
|
||||||
| `AppState` | Window geometry, last file, preferences (`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. |
|
||||||
|
| `historyModel` (`HistoryModel`) | `QAbstractListModel` of recent books with async metadata extraction and reading progress. |
|
||||||
|
| `isDebugBuild` | Boolean constant indicating debug build. |
|
||||||
|
|
||||||
### Content Model
|
### Additional Registered Types & Providers
|
||||||
|
- **`KnuthPlassItem`** (`Asteria` module): Custom `QQuickPaintedItem` that draws `ChunkLayout` via `QPainter`.
|
||||||
|
- **`ChunkLayout`**: Declared metatype storing positioned text lines, word runs, inline/block images, rules, and block decorations.
|
||||||
|
- **Image Providers**:
|
||||||
|
- `image://fileicon/...`: `FileIconProvider`
|
||||||
|
- `image://web/...`: `WebImageProvider`
|
||||||
|
- `image://cbz/...`, `image://cbr/...`, `image://dir/...`, `image://epub/...`: `EntryImageProvider` registered via `FormatRegistry::registerImageProviders`.
|
||||||
|
- **`AppCoordinator`**: C++ coordinator wiring signals between `Book`, `ReadingModel`, `HistoryModel`, `UiState`, `ReadingPreferences`, and `AppState`.
|
||||||
|
|
||||||
All format readers produce normalized content organized into chapters. Each chapter's content is represented as chunks (a `QStringList` of standalone fragments) to enable virtualized rendering via `ListView` in QML. The content model is defined in `FormatReader.h`:
|
---
|
||||||
|
|
||||||
|
## Content Model & Reader Interface (`FormatReader.h`)
|
||||||
```cpp
|
```cpp
|
||||||
struct TocEntry {
|
enum class ReadingMode { Comic, Text };
|
||||||
QString title;
|
|
||||||
int chapterIndex;
|
struct PageInfo {
|
||||||
int depth; // 0 = top level
|
QString imageUrl;
|
||||||
|
QSize naturalSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Chapter {
|
class FormatReader {
|
||||||
int index;
|
public:
|
||||||
QString title;
|
virtual ~FormatReader() = default;
|
||||||
QStringList contentChunks; // standalone HTML fragments
|
virtual ReadingMode mode() const = 0;
|
||||||
|
virtual bool open(const QString &filePath) = 0;
|
||||||
|
virtual bool loadMetadata(const QString &filePath);
|
||||||
|
virtual QString lastError() const = 0;
|
||||||
|
virtual QString filePath() const = 0;
|
||||||
|
virtual QString title() const = 0;
|
||||||
|
virtual QString author() const;
|
||||||
|
virtual QString coverImageUrl() const;
|
||||||
|
virtual QByteArray contentHash() const = 0; // MD5 hash for stable persistent state
|
||||||
|
virtual QVector<PageInfo> pages() const; // Comic mode
|
||||||
|
virtual QStringList chunks() const; // Text mode: HTML fragments
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
`FormatReader` interface methods:
|
---
|
||||||
- `bool open(const QString &filePath)` — returns false on failure
|
|
||||||
- `QString lastError()` — error description after failed open
|
|
||||||
- `int chapterCount()`
|
|
||||||
- `Chapter loadChapter(int index)` — loads one chapter on demand
|
|
||||||
- `QList<TocEntry> tableOfContents()` — empty list if a format has no TOC (e.g., TXT)
|
|
||||||
- `QString title()`, `QString author()` — metadata
|
|
||||||
|
|
||||||
Chapter mapping by format: TXT = 1 chapter (whole file). FB2 = `<section>` elements. EPUB = spine items. CBZ = 1 chapter (whole archive). PDF = outline entries or individual pages.
|
## Rendering Architecture
|
||||||
|
|
||||||
**ReadingModel** is a `QAbstractListModel` exposing chunks via `ContentRole`. `PageView.qml` renders chunks in a `ListView` with `cacheBuffer` for seamless scrolling — no visible seams between chunks.
|
### 1. Text Mode (`ScrollPageView.qml`)
|
||||||
|
- `ReadingModel` manages a list of HTML chunks.
|
||||||
|
- When viewport geometry or font preferences change, `ReadingModel::updateLayoutMetrics()` runs `ChunkLayoutEngine` off-thread:
|
||||||
|
- `HtmlBlockParser` extracts structured blocks (`Paragraph`, `ImageBlock`, `Rule`, `Container`).
|
||||||
|
- `CssParser` evaluates stylesheets and styles inline tags.
|
||||||
|
- `KnuthPlass` computes optimal justified/aligned line breaks.
|
||||||
|
- `BookImageResolver` resolves embedded image dimensions and URLs.
|
||||||
|
- Off-thread calculation stores `ChunkLayout` and pixel heights.
|
||||||
|
- Rendered in a virtualized `ListView` (`cacheBuffer: 600`, high flick velocity) using `KnuthPlassItem`.
|
||||||
|
- Scrolling tracks top visible chunk and `intraOffset`.
|
||||||
|
|
||||||
**Progress tracking** to track reading position ONLY ListView y offset must be used. Current page / progress percentage must be calculated using this and total height only.
|
### 2. Manga / Comic Mode (`MangaPageView.qml`)
|
||||||
|
- Driven by `MangaPagination`.
|
||||||
|
- Dynamically pairs pages into two-page spreads when in landscape mode, maintaining spine alignment (no seams between pages).
|
||||||
|
- Supports RTL mode (`mangaRTL` property), cover page shift (`pageShift`), and touch/swipe gestures or 3-zone tap navigation.
|
||||||
|
|
||||||
### Format Registry
|
---
|
||||||
|
|
||||||
`FormatRegistry` is separate from `FormatReader`. It is driven by a `FormatSpec` table (one row per format: extension or directory match, image scheme, reader factory, byte-source factory) built in `main()`. Readers, image providers, sync image loaders, and QML scheme registration all derive from the same row, so adding a new format requires only a new table row — no modifications to existing factory logic (OCP). No plugin system needed.
|
## Position Restoration & State Persistence
|
||||||
|
- **Position Persistence**: `BookPositionStore` persists `BookPosition` (`chunkIndex`, `intraOffset`, `progress`, `pageShift`, `mangaRTL`) indexed by file content MD5 (`contentHash()`), ensuring state survives file renames or moves.
|
||||||
|
- **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`.
|
||||||
|
- Comic mode: `restoreReady(chunkIndex)` triggers `MangaPageView.showPair(pairIndexForChunk(chunkIndex))`.
|
||||||
|
|
||||||
### Async Book Opening
|
---
|
||||||
|
|
||||||
`Book::openBook()` runs reader creation + metadata loading in `QtConcurrent::run()`. Emits `bookReady()` or `bookError(QString)` when done.
|
## Format Registry
|
||||||
|
Driven by `FormatSpec` table built in `main.cpp`:
|
||||||
|
- `FormatSpec::comic(ext, matchesDirectory, scheme, makeSource)`
|
||||||
|
- `FormatSpec::epub(makeSource)`
|
||||||
|
Each format registers its file extension / directory matcher, reader factory, `IByteSource` factory, and image URL scheme in a single table entry.
|
||||||
|
|
||||||
### Error Handling
|
---
|
||||||
|
|
||||||
`FormatReader::open()` returns `bool`. Failed readers expose `QString lastError()`. `Book` translates errors to a `QString errorMessage` property + `error(QString)` signal. QML shows an `ErrorPopup.qml` component. Error cases: file not found, unsupported format, corrupt archive, encoding failure, permission denied.
|
## Design & Color Scheme
|
||||||
|
Asteria supports **Dark**, **Light**, and user-editable **Custom** themes:
|
||||||
|
- Managed by `ThemeManager.qml` singleton (`pragma Singleton`).
|
||||||
|
- Color definitions reside in `DarkTheme.qml`, `LightTheme.qml`, and `ThemeManager.customTheme`.
|
||||||
|
- In QML, all colors are referenced via `ThemeManager.currentTheme.<colorKey>` (e.g. `ThemeManager.currentTheme.surface`).
|
||||||
|
- Custom theme colors can be edited in `CustomThemePage.qml` and are persisted in `UiState`.
|
||||||
|
- Never hardcode hex values in QML components.
|
||||||
|
|
||||||
### File Structure
|
---
|
||||||
|
|
||||||
|
## File Structure
|
||||||
```
|
```
|
||||||
src/
|
src/
|
||||||
main.cpp
|
main.cpp
|
||||||
backend/
|
backend/
|
||||||
|
AppCoordinator.h/cpp
|
||||||
|
AppState.h/cpp
|
||||||
|
FormatReader.h
|
||||||
|
HistoryModel.h/cpp
|
||||||
|
IFileDialogService.h
|
||||||
|
NativeFileDialogService.h/cpp
|
||||||
|
PortalFileDialogService.h/cpp
|
||||||
|
ReadingModel.h/cpp
|
||||||
book/
|
book/
|
||||||
Book.h/cpp # Open/close, metadata, TOC — exposed to QML
|
Book.h/cpp
|
||||||
ReadingModel.h/cpp # Chapter content, position, navigation — exposed to QML
|
|
||||||
AppState.h/cpp # Window/session state (QSettings) — exposed to QML
|
|
||||||
FormatReader.h # Abstract interface + Chapter/TocEntry structs
|
|
||||||
AppCoordinator.h/cpp # Cross-class signal wiring (book open, history, quit)
|
|
||||||
reading/
|
|
||||||
MangaPagination.h/cpp # Pure page-pair layout for manga mode
|
|
||||||
MeasurementController.h/cpp # Off-thread chunk height measurement
|
|
||||||
formats/
|
formats/
|
||||||
FormatRegistry.h/cpp # FormatSpec table: readers, providers, schemes
|
AsyncImageResponse.h/cpp
|
||||||
IByteSource.h # Byte access to named entries (zip/rar/dir/fb2)
|
EntryImageProvider.h/cpp
|
||||||
EntryImageProvider.h/cpp # Generic image provider over any IByteSource
|
|
||||||
sources/ # ZipByteSource, RarByteSource, DirByteSource, Fb2ByteSource
|
|
||||||
TxtReader.h/cpp
|
|
||||||
Fb2Reader.h/cpp
|
|
||||||
EpubReader.h/cpp
|
EpubReader.h/cpp
|
||||||
PdfReader.h/cpp
|
FileIconProvider.h/cpp
|
||||||
RtfReader.h/cpp
|
FormatRegistry.h/cpp
|
||||||
DocReader.h/cpp
|
HtmlEntities.h/cpp
|
||||||
DocxReader.h/cpp
|
IByteSource.h
|
||||||
HtmlReader.h/cpp
|
ImageExtensions.h
|
||||||
DjvuReader.h/cpp
|
ImageScaling.h
|
||||||
OdtReader.h/cpp
|
ImageUrl.h/cpp
|
||||||
ChmReader.h/cpp
|
WebImageProvider.h/cpp
|
||||||
|
comic/
|
||||||
|
ComicReader.h/cpp
|
||||||
|
sources/
|
||||||
|
DirByteSource.h/cpp
|
||||||
|
RarByteSource.h/cpp
|
||||||
|
ZipByteSource.h/cpp
|
||||||
|
reading/
|
||||||
|
BookImageResolver.h/cpp
|
||||||
|
KnuthPlassItem.h/cpp
|
||||||
|
MangaPagination.h/cpp
|
||||||
|
layout/
|
||||||
|
ChunkLayoutEngine.h/cpp
|
||||||
|
CssParser.h/cpp
|
||||||
|
HtmlBlockParser.h/cpp
|
||||||
|
KnuthPlass.h/cpp
|
||||||
|
state/
|
||||||
|
BookPositionStore.h/cpp
|
||||||
|
ReadingPreferences.h/cpp
|
||||||
|
UiState.h/cpp
|
||||||
qml/
|
qml/
|
||||||
Theme.qml # Singleton — all color constants
|
DarkTheme.qml
|
||||||
|
LightTheme.qml
|
||||||
Main.qml
|
Main.qml
|
||||||
|
ThemeManager.qml
|
||||||
components/
|
components/
|
||||||
Header.qml
|
ErrorPopup.qml
|
||||||
SideBar.qml # Renders TOC from Book
|
FlatIconButton.qml
|
||||||
PageView.qml # ListView-based virtualized rendering of ReadingModel chunks
|
|
||||||
Footer.qml
|
Footer.qml
|
||||||
ErrorPopup.qml # Error display popup
|
Header.qml
|
||||||
|
LabeledSlider.qml
|
||||||
|
MangaPageView.qml
|
||||||
|
ScrollPageView.qml
|
||||||
|
SettingsPopup.qml
|
||||||
|
SideBar.qml
|
||||||
|
SideBarButton.qml
|
||||||
pages/
|
pages/
|
||||||
StarterPage.qml
|
CustomThemePage.qml
|
||||||
|
HistoryPage.qml
|
||||||
ReaderPage.qml
|
ReaderPage.qml
|
||||||
SettingsPage.qml
|
StarterPage.qml
|
||||||
tests/
|
|
||||||
formats/
|
|
||||||
TxtReaderTest.cpp
|
|
||||||
Fb2ReaderTest.cpp
|
|
||||||
EpubReaderTest.cpp
|
|
||||||
book/
|
|
||||||
BookTest.cpp
|
|
||||||
ReadingModelTest.cpp
|
|
||||||
AppStateTest.cpp
|
|
||||||
fixtures/
|
|
||||||
sample.txt
|
|
||||||
sample.fb2
|
|
||||||
sample.epub
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Cross-Platform
|
---
|
||||||
|
|
||||||
- Use only Qt APIs for filesystem, paths, and dialogs — no platform-specific code
|
|
||||||
- Third-party libs must be available on Windows and Linux; prefer those with CMake `find_package` or vcpkg support
|
|
||||||
|
|
||||||
## Design & Color Scheme
|
|
||||||
|
|
||||||
Dark theme only. Derived from asteria-bookreader:
|
|
||||||
|
|
||||||
| Role | Color |
|
|
||||||
|---|---|
|
|
||||||
| Background (deepest) | `#010620` |
|
|
||||||
| Background (default) | `#01082b` |
|
|
||||||
| Surface / paper | `#191d35` |
|
|
||||||
| Header / drawer bg | `#14172c` |
|
|
||||||
| Footer bg | `#1a1e36` |
|
|
||||||
| Scrollbar track | `#131628` |
|
|
||||||
| Scrollbar thumb | `#36486a` |
|
|
||||||
| Primary accent | `#3a5688` |
|
|
||||||
| Button accent | `#5785c1` |
|
|
||||||
| Sidebar button text | `#98aaf4` |
|
|
||||||
| Reading body text | `#c4c8d8` |
|
|
||||||
| UI text (primary) | `#a2a5b4` |
|
|
||||||
| Header typography | `#8488aa` |
|
|
||||||
| Dim / clock text | `#71738c` |
|
|
||||||
| Counter text | `#606175` |
|
|
||||||
|
|
||||||
|
|
||||||
All colors are defined in `src/qml/Theme.qml` (a QML singleton registered via `qmldir`). All QML files reference colors as `Theme.surface`, `Theme.backgroundDefault`, etc. Do not hardcode hex values in QML components. Do not use Qt Quick Styles (Material/Universal) — the singleton gives full control over the custom theme.
|
|
||||||
|
|
||||||
## Qt Conventions
|
## Qt Conventions
|
||||||
|
- **Qt 6.10+** preferred — no Qt5 compat shims.
|
||||||
- **Qt 6.10.x preferred** — no Qt5 compat shims
|
- All UI in **QML**; C++ for logic, parsing, and heavy computation.
|
||||||
- All UI in **QML**; C++ for logic only
|
- Expose C++ to QML via `rootContext()->setContextProperty()` or `qmlRegisterType`.
|
||||||
- Expose C++ to QML via `rootContext()->setContextProperty()` or `QML_ELEMENT`
|
- Main window starts with opacity 0 and ticks to 1 on a short timer to prevent white window flash during initial render.
|
||||||
- `QSettings` for persistent state
|
|
||||||
- Qt naming: `camelCase` properties/methods, `PascalCase` QML component names
|
|
||||||
- `Q_INVOKABLE` for QML-callable methods; signals for C++→QML notifications
|
|
||||||
- QT needs a moment to settle (otherwise there's a noticeable all-white window flash), so the main window MUST be opened with opacity 0 and then on timer ticked to 1 and continue initializing.
|
|
||||||
Reference in new issue
Block a user