diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index db97033..4a222fd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,11 +32,21 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install -r requirements.txt + # The test suite imports pdfreader_lib.mcp_server, which needs the + # optional MCP SDK to define its tool list at import time. + python -m pip install -r requirements-mcp.txt + python -m pip install pytest - name: Compile-check Python sources run: | python -m compileall . -q + - name: Run regression test suite + env: + QT_QPA_PLATFORM: offscreen + run: | + python -m pytest tests/ -q + - name: Run update detection regression tests run: | python tools/test_updater_asset_flow.py diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a802ce4..47bc65d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,6 +4,15 @@ on: push: tags: - "v*.*.*" + # Two-phase release: a tag push builds and uploads the artifacts only. + # After the artifacts and version metadata are verified, publish explicitly: + # gh workflow run release.yml --ref vX.Y.Z -f publish=true + workflow_dispatch: + inputs: + publish: + description: "Publish the GitHub release (only after artifacts are verified)" + type: boolean + default: false permissions: contents: write @@ -100,9 +109,7 @@ jobs: } if (-not $makeAppx) { - Write-Host "MakeAppx.exe not found — skipping MSIX build." - Write-Host "Install Windows SDK or Visual Studio Build Tools for MSIX support." - exit 0 + throw "MakeAppx.exe not found — the MSIX package is required for a release." } # Normalize MakeAppx path @@ -287,6 +294,7 @@ jobs: publish: name: Publish GitHub Release + if: github.event_name == 'workflow_dispatch' && inputs.publish == true runs-on: ubuntu-latest needs: - build-windows @@ -308,12 +316,12 @@ jobs: test -f "release-assets/OpenReader-Setup.exe" || { echo "Missing Windows Setup.exe"; exit 1; } test -f "release-assets/OpenReader-macOS-Apple-Silicon.zip" || { echo "Missing macOS Apple Silicon ZIP"; exit 1; } test -f "release-assets/OpenReader-macOS-Intel.zip" || { echo "Missing macOS Intel ZIP"; exit 1; } - # MSIX is optional until signing is set up; warn if missing - if [ -f "release-assets/OpenReader.msix" ]; then - echo "MSIX package found — will attach to release" - else - echo "⚠️ MSIX package not found — MakeAppx.exe may not be available on this runner" - fi + # The Store package is mandatory for a release. + test -f "release-assets/OpenReader.msix" || { + echo "Missing OpenReader.msix — the Store package is required for a release." + exit 1 + } + echo "MSIX package verified" echo "All required assets verified" - name: Generate release notes diff --git a/AGENTS.md b/AGENTS.md index edd3598..bbee4a0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -4,7 +4,7 @@ This repository is a local-first desktop PDF utility. Keep maintenance changes b ## Product Boundaries -**Current version:** v1.2.7 (2026-08-02) — Store-aware updates, default-reader UX, Windows file associations +**Current version:** v1.2.8 (2026-11-08) — virtualized continuous scrolling and the unified Fluent toolbar - Do not add new user-facing PDF features unless the task explicitly asks for them. - Do not change the local-first privacy philosophy. diff --git a/CHANGELOG.md b/CHANGELOG.md index 296af19..22aeef1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## v1.2.8 — Continuous Reading & Toolbar Redesign — 2026-11-08 + +- **Fixed (continuous scrolling):** The continuous view no longer renders a sliding window around the current page. Every page now gets a correctly sized placeholder in one persistent document layout, so the scrollbar spans the whole PDF — a 76-page document exposes all 76 pages instead of roughly six. Pixmaps are rendered lazily for the viewport plus a small overscan and released once they leave the cache window, so memory stays bounded for very long documents. +- **Fixed (navigation):** Next/Previous, the page box, search results, and semantic-search jumps scroll directly to the target page without rebuilding the layout or discarding pages already scrolled past. Scrolling updates the page indicator, zoom changes preserve the reader's position, and small and large documents behave identically. +- **Fixed:** Removed a `NameError: name '_t' is not defined` at the end of `_render_continuous` that fired on every continuous render in v1.2.7. +- **Changed (toolbar):** Replaced the two stacked control rows and Windows 98-era styling with a single 44 px Fluent-style command bar. File, page, zoom, annotation, and search actions are grouped and separated; icons are vector-drawn at a consistent 18 px inside 32 px targets; the zoom percentage is shown live; the page control is a compact `N / total` counter; and search is an integrated field with previous/next match controls and a semantic toggle. +- **Changed (themes):** Rewrote the light and dark stylesheets around a shared neutral palette with the OpenReader accent — pill tabs, hairline separators, themed scrollbars, menus, status bar, and empty state. Toolbar icons and the empty-state glyph are regenerated when the theme changes. +- **Fixed (tabs):** Switching tabs now refreshes the page counter and page-box range to the newly active document. The tab strip hides when no documents are open. +- **Accessibility:** Every icon-only toolbar button has an accessible name and a tooltip; all existing keyboard shortcuts are unchanged. +- **Verification:** New continuous-scrolling regression suite (full-document range, scroll indicator, navigation persistence, jump-to-page, zoom retention, virtualization, small documents) and toolbar/UI suite (icon consistency, theme recoloring, shortcuts, navigation, zoom, annotations, search, multi-tab, mode toggle). Full suite: 160 passed, 18 skipped. + ## v1.2.5 — File Association & Branding — 2026-08-02 - **Version:** Bumped `__version__` to `1.2.5`, MSIX version to `1.2.5.0`; aligned the MCP package, packaging manifests, and release configuration to a single version source. `scripts/inject_version.py` now propagates the version to `main.py`, `packages/mcp-server/pyproject.toml`, and both MSIX manifests. diff --git a/CLAUDE.md b/CLAUDE.md index 694f26f..001a00c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -2,7 +2,7 @@ ## Overview -**Latest update:** v1.2.7 — Store-aware updates, default-reader UX, Windows file associations (2026-08-02) +**Latest update:** v1.2.8 — virtualized continuous scrolling, unified Fluent toolbar, light/dark redesign (2026-11-08) Privacy-first, local-only desktop PDF utility for Windows. macOS experimental; Linux unsupported. @@ -11,6 +11,7 @@ macOS experimental; Linux unsupported. | Version | Date | Summary | |---------|------|---------| +| v1.2.8 | 2026-11-08 | Continuous scrolling rebuilt as a virtualized full-document layout; unified 44 px Fluent toolbar with vector icons; light/dark chrome redesign; tab page-controls fix | | v1.2.7 | 2026-08-02 | Store-aware updates — install-source detection, channel-aware Software Updates dialog, persisted skip + last-checked | | v1.2.6 | 2026-08-02 | Default Reader Experience — Windows UserChoice detection, Settings dialog, first-launch default prompt | | v1.2.5 | 2026-08-02 | Windows File Association Fix — MSIX `.pdf` association, ChangesAssociations, single-source version injector, changelog cleanup | diff --git a/README.md b/README.md index f4d09c6..d99946b 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,10 @@ The focus is on reading and working with documents, not fighting the interface. | Release | Date | Milestone | |---------|------|-----------| +| **v1.2.8** | Nov 2026 | Continuous scrolling rebuilt on a virtualized full-document layout; unified Fluent toolbar and light/dark redesign | +| **v1.2.7** | Aug 2026 | Store-aware updates — install-source detection, channel-aware update dialog | +| **v1.2.6** | Aug 2026 | Default reader experience — Windows default-app detection and settings | +| **v1.2.5** | Aug 2026 | Windows file association (`windows.fileTypeAssociation`) and single-source versioning | | **v1.2.4** | Jun 2026 | Toolbar icon redesign — all buttons use QPainter vector icons | | **v1.2.3** | Jun 2026 | Reader UX polish — Fit Page on open, Ctrl+Mouse Wheel zoom | | **v1.2.2** | Jun 2026 | Store submission fix — XML DOM patching, CI validation | diff --git a/docs/Architecture.md b/docs/Architecture.md index f362aba..1ed6c23 100644 --- a/docs/Architecture.md +++ b/docs/Architecture.md @@ -34,7 +34,7 @@ OpenReader is a local-first desktop PDF utility built with Python and PySide6 (Q | Component | Module | Purpose | |-----------|--------|---------| -| GUI | `main.py` | PySide6 application window, menus, controls bar, PDF viewer | +| GUI | `main.py` | PySide6 application window, menus, unified toolbar, PDF viewer | | PDF Engine | — | PyMuPDF (MuPDF bindings) for rendering, text extraction, annotation | | Search | `pdfreader_lib/search_index.py` | SQLite FTS5 keyword index + TF-IDF semantic search | | Comparison | `pdfreader_lib/comparison.py` | Page-by-page text diff with color-coded output | @@ -47,6 +47,8 @@ OpenReader is a local-first desktop PDF utility built with Python and PySide6 (Q 3. **SQLite for indexing.** Library search uses SQLite FTS5 (keyword) and scikit-learn TF-IDF (semantic). Both are local, zero-configuration, and fast. 4. **MCP server as library.** The MCP server is built into `pdfreader_lib/` and can be used standalone or alongside the GUI. It shares the same underlying search and comparison modules. 5. **No self-update.** The app detects updates via GitHub API but never downloads or runs installers. MSIX updates are handled by Windows App Installer. +6. **Virtualized continuous rendering.** The default view keeps one correctly sized placeholder widget per page in a single persistent layout, so the scrollbar always spans the whole document and every page stays reachable. Page pixmaps are rendered lazily for the viewport plus a small overscan (`CONTINUOUS_OVERSCAN`) and released once they leave the cache window (`CONTINUOUS_CACHE`), keeping memory bounded at high zoom and for long documents. Scroll position drives the current page; Next/Previous, the page box, and search jumps scroll in place without rebuilding the layout. Explicit renders (zoom, annotations, search, theme) invalidate the cached pixmaps. Single-page mode remains available via **View → Continuous Scroll**. +7. **Theme-aware design system.** A single 44 px toolbar groups file, page, zoom, annotation, and search actions. Icons are drawn as vectors from one factory (`_make_toolbar_icon`) in the active theme's palette, and both light and dark stylesheets share the same neutral tokens with the OpenReader accent. ## Security Model diff --git a/docs/RELEASE.md b/docs/RELEASE.md index f2dc96e..d2b5ae0 100644 --- a/docs/RELEASE.md +++ b/docs/RELEASE.md @@ -54,16 +54,22 @@ no separate code-signing certificate is needed. 1. Make sure `main` is green in GitHub Actions. 2. Update `CHANGELOG.md`. 3. Commit all release notes/docs changes. -4. Create and push a semantic version tag: +4. Create and push an **annotated** semantic version tag: ```bash - git tag v1.2.2 - git push origin v1.2.2 + git tag -a v1.2.8 -m "OpenReader v1.2.8" + git push origin v1.2.8 ``` -5. GitHub Actions runs `.github/workflows/release.yml`. -6. The workflow builds Windows (MSIX + Setup.exe + ZIP), macOS Apple Silicon, and macOS Intel packages. -7. The workflow creates the GitHub Release and attaches all assets. +5. Pushing the tag runs `.github/workflows/release.yml` in **build-only** mode. The workflow builds and uploads Windows (MSIX + Setup.exe + ZIP), macOS Apple Silicon, and macOS Intel packages as workflow artifacts; it does **not** create the GitHub Release. +6. Verify the artifacts on the tag run: `OpenReader.msix` identity/version, `OpenReader-Setup.exe`, and the ZIPs. The MSIX is mandatory — the workflow fails if `MakeAppx.exe` is unavailable or the MSIX is missing. +7. Publish explicitly from the verified tag: + + ```bash + gh workflow run release.yml --ref vX.Y.Z -f publish=true + ``` + + The manual run rebuilds the packages and its `publish` job creates the GitHub Release with every artifact attached. ## Update Detection diff --git a/docs/store-acceptance-checklist.md b/docs/store-acceptance-checklist.md index ee25d5c..5aaa87a 100644 --- a/docs/store-acceptance-checklist.md +++ b/docs/store-acceptance-checklist.md @@ -4,7 +4,7 @@ The MSIX package cannot be produced or signed locally: production signing uses the Microsoft Store identity (no self-procured code-signing certificate), and the Windows SDK `MakeAppx.exe`/Store signing pipeline runs in Partner Center. This checklist covers the Store-specific validation that must happen **after** -the `v1.2.7` MSIX is submitted and signed by the Store. +the `v1.2.8` MSIX is submitted and signed by the Store. Frozen identity (do not alter): | Field | Value | @@ -16,7 +16,7 @@ Frozen identity (do not alter): ## On a clean Windows machine, after Store install -- [ ] Install from the Microsoft Store; app launches and reports **v1.2.7** (Help → About). +- [ ] Install from the Microsoft Store; app launches and reports **v1.2.8** (Help → About). - [ ] `Get-AppxPackage` shows the package with the frozen identity and PFN. - [ ] The process runs with a package identity — install-source detection reports the Store channel (no GitHub request on launch; Help → Check for @@ -41,7 +41,22 @@ Frozen identity (do not alter): - [ ] First-launch prompt: **Set as default** opens Default Apps; **Do not ask again** persists across launches. -### Updates (v1.2.7) +### Continuous reading & toolbar (v1.2.8) +- [ ] Open a 50+ page PDF; scroll from page 1 to the final page and back + without using navigation. Every page remains reachable and the page + indicator follows the viewport. +- [ ] Next/Previous, the page box, and search-result jumps scroll directly to + the requested page without removing access to other pages. +- [ ] Zoom (`−`/`+`, Fit, Ctrl+mouse-wheel) keeps the reading position and the + live zoom percentage updated. +- [ ] The single toolbar shows file/page/zoom/annotation/search groups; the + search field, match navigation, and zoom percentage fit without overflow + at the default window size. +- [ ] Light and dark themes render the toolbar, tabs, menus, scrollbars, and + empty state correctly. +- [ ] Switching tabs updates the page counter and page range (`/ N`). + +### Updates (v1.2.7+) - [ ] Store install never queries `api.github.com` (silent launch check and Help → Check for Updates both use the Store channel). - [ ] **Open Microsoft Store** button opens the Store listing. diff --git a/main.py b/main.py index 20251a7..e25aa56 100644 --- a/main.py +++ b/main.py @@ -11,17 +11,17 @@ from pathlib import Path import fitz -from PySide6.QtCore import QByteArray, QEvent, QPoint, QPointF, QRect, QSettings, QSize, QTimer, Qt, QUrl, Signal -from PySide6.QtGui import QAction, QColor, QDesktopServices, QIcon, QImage, QKeySequence, QPainter, QPainterPath, QPen, QPixmap, QShortcut +from PySide6.QtCore import QByteArray, QEvent, QPoint, QPointF, QRect, QRectF, QSettings, QSize, QTimer, Qt, QUrl, Signal +from PySide6.QtGui import QAction, QColor, QDesktopServices, QIcon, QImage, QKeySequence, QPainter, QPainterPath, QPalette, QPen, QPixmap, QShortcut from PySide6.QtNetwork import QLocalServer, QLocalSocket, QNetworkAccessManager, QNetworkReply, QNetworkRequest from PySide6.QtWidgets import ( + QAbstractSpinBox, QApplication, QCheckBox, QDialog, QDialogButtonBox, QFileDialog, QFrame, - QGraphicsOpacityEffect, QGroupBox, QHBoxLayout, QInputDialog, @@ -52,7 +52,7 @@ ) -__version__ = "1.2.7" +__version__ = "1.2.8" GITHUB_REPO = "sparshsam/openreader" IPC_SERVER_NAME = "OpenReader-IPC" RECENT_FILES_MAX = 10 @@ -141,433 +141,758 @@ class TabData: # --------------------------------------------------------------------------- LIGHT_STYLESHEET = """ -QMainWindow, QWidget { - background-color: #f5f5f5; - color: #1a1a1a; +/* OpenReader — Fluent light theme */ +QMainWindow, QDialog { + background-color: #f3f3f5; + color: #1b1b1f; +} +QWidget { + color: #1b1b1f; } QMainWindow::separator { - background-color: #d0d0d0; + background-color: #e4e4e8; + width: 1px; + height: 1px; +} +QMenuBar { + background-color: #fbfbfc; + color: #1b1b1f; + border: none; + border-bottom: 1px solid #e8e8ec; + padding: 2px 6px; + spacing: 2px; +} +QMenuBar::item { + padding: 5px 10px; + border-radius: 6px; + background: transparent; +} +QMenuBar::item:selected { + background-color: rgba(0, 0, 0, 0.06); +} +QMenu { + background-color: #ffffff; + color: #1b1b1f; + border: 1px solid #e2e2e6; + border-radius: 8px; + padding: 5px; +} +QMenu::item { + padding: 7px 28px 7px 14px; + border-radius: 5px; +} +QMenu::item:selected { + background-color: rgba(0, 0, 0, 0.06); +} +QMenu::item:disabled { + color: #a1a2a9; +} +QMenu::separator { + height: 1px; + background-color: #ececef; + margin: 5px 8px; +} +QToolBar#MainToolbar { + background-color: #fbfbfc; + border: none; + border-bottom: 1px solid #e8e8ec; + padding: 6px; + spacing: 3px; +} +QToolBar#MainToolbar::separator { + width: 1px; + background-color: #e6e6ea; + margin: 7px 7px; +} +QToolBar#MainToolbar::extension { + background: transparent; + border: none; +} +QToolBar#MainToolbar QToolButton { + background: transparent; + border: 1px solid transparent; + border-radius: 6px; + padding: 0px; +} +QToolBar#MainToolbar QToolButton:hover { + background-color: rgba(0, 0, 0, 0.05); +} +QToolBar#MainToolbar QToolButton:pressed { + background-color: rgba(0, 0, 0, 0.09); +} +QToolBar#MainToolbar QToolButton:checked { + background-color: rgba(255, 37, 95, 0.10); + border-color: rgba(255, 37, 95, 0.30); +} +QToolBar#MainToolbar QToolButton:disabled, +QToolBar#MainToolbar QToolButton:checked:disabled { + background: transparent; + border-color: transparent; +} +QSpinBox#PageSpin { + background: transparent; + border: 1px solid transparent; + border-radius: 6px; + padding: 3px 2px; + color: #1b1b1f; + font-weight: 600; + selection-background-color: #ff255f; + selection-color: #ffffff; +} +QSpinBox#PageSpin:hover { + background-color: #ffffff; + border-color: #e2e2e6; +} +QSpinBox#PageSpin:focus { + background-color: #ffffff; + border-color: #ff255f; +} +QLabel#PageCount, QLabel#ZoomLabel, QLabel#SearchCount { + color: #6e6f76; + font-size: 12px; + font-weight: 500; +} +QLineEdit#SearchInput { + background-color: #ffffff; + color: #1b1b1f; + border: 1px solid #e2e2e6; + border-radius: 6px; + padding: 4px 8px; + min-height: 22px; + selection-background-color: #ff255f; + selection-color: #ffffff; +} +QLineEdit#SearchInput:focus { + border-color: #ff255f; +} +QToolBar#MainToolbar QToolButton#SemanticToggle { + color: #6e6f76; + font-size: 12px; + font-weight: 500; + padding: 0px 10px; + min-height: 24px; + background: transparent; + border: 1px solid transparent; + border-radius: 6px; +} +QToolBar#MainToolbar QToolButton#SemanticToggle:hover { + background-color: rgba(0, 0, 0, 0.05); +} +QToolBar#MainToolbar QToolButton#SemanticToggle:checked { + background-color: rgba(255, 37, 95, 0.10); + border-color: rgba(255, 37, 95, 0.30); + color: #1b1b1f; +} +QToolBar#MainToolbar QToolButton#SemanticToggle:disabled { + color: #aaabb2; +} +QTabBar { + background: transparent; +} +QTabBar::tab { + background: transparent; + color: #6e6f76; + padding: 5px 14px; + margin: 5px 3px; + border: 1px solid transparent; + border-radius: 7px; + min-height: 18px; +} +QTabBar::tab:selected { + background-color: #ffffff; + color: #1b1b1f; + border-color: #e2e2e6; +} +QTabBar::tab:hover:!selected { + background-color: rgba(0, 0, 0, 0.05); + color: #1b1b1f; +} +#TabStrip { + background-color: #f3f3f5; + border-bottom: 1px solid #e8e8ec; +} +QToolButton#NewTabButton { + background-color: transparent; + border: 1px solid transparent; + border-radius: 6px; + padding: 0px; +} +QToolButton#NewTabButton:hover { + background-color: rgba(0, 0, 0, 0.05); +} +QToolButton#TabCloseButton { + background-color: transparent; + border: none; + border-radius: 5px; + color: #7b7c83; + font-size: 15px; + font-weight: 500; + padding: 0px; +} +QToolButton#TabCloseButton:hover { + background-color: rgba(0, 0, 0, 0.08); + color: #1b1b1f; +} +QToolButton#TabCloseButton:pressed { + background-color: rgba(0, 0, 0, 0.12); } QPushButton { background-color: #ffffff; - color: #1a1a1a; - border: 1px solid #c8c8c8; - padding: 4px 14px; - border-radius: 4px; + color: #1b1b1f; + border: 1px solid #dfe0e4; + padding: 5px 14px; + border-radius: 6px; min-height: 22px; } QPushButton:hover { - background-color: #e8e8e8; - border-color: #a0a0a0; + background-color: #f6f6f8; + border-color: #cfd0d5; } QPushButton:pressed { - background-color: #d0d0d0; + background-color: #ececef; } -QPushButton:checked { - background-color: #4a90d9; +QPushButton:default { + background-color: #ff255f; color: #ffffff; - border-color: #357abd; + border-color: #ff255f; +} +QPushButton:default:hover { + background-color: #f01650; + border-color: #f01650; +} +QPushButton:checked { + background-color: rgba(255, 37, 95, 0.10); + color: #1b1b1f; + border-color: rgba(255, 37, 95, 0.30); } QPushButton:disabled { - background-color: #e8e8e8; - color: #a0a0a0; - border-color: #e0e0e0; + background-color: #f2f2f4; + color: #aaabb2; + border-color: #e8e8ec; +} +QPushButton#OpenEmptyButton { + background-color: #ff255f; + color: #ffffff; + border: none; + border-radius: 7px; + padding: 9px 22px; + font-weight: 600; +} +QPushButton#OpenEmptyButton:hover { + background-color: #f01650; +} +QPushButton#OpenEmptyButton:pressed { + background-color: #d90f47; } QLineEdit { background-color: #ffffff; - color: #1a1a1a; - border: 1px solid #c8c8c8; - padding: 4px 6px; - border-radius: 4px; - selection-background-color: #4a90d9; + color: #1b1b1f; + border: 1px solid #dfe0e4; + padding: 5px 8px; + border-radius: 6px; + selection-background-color: #ff255f; selection-color: #ffffff; } QLineEdit:focus { - border-color: #4a90d9; + border-color: #ff255f; } QSpinBox { background-color: #ffffff; - color: #1a1a1a; - border: 1px solid #c8c8c8; + color: #1b1b1f; + border: 1px solid #dfe0e4; padding: 4px; - border-radius: 4px; + border-radius: 6px; } QSpinBox:focus { - border-color: #4a90d9; + border-color: #ff255f; } QSpinBox::up-button, QSpinBox::down-button { - background-color: #e8e8e8; + background-color: #f1f1f3; border: none; width: 18px; } QLabel { - color: #1a1a1a; + color: #1b1b1f; background-color: transparent; } +QLabel#EmptyTitle { + color: #1b1b1f; + font-size: 19px; + font-weight: 600; +} +QLabel#EmptySubtitle { + color: #6e6f76; + font-size: 13px; +} +QLabel#PdfPage, QLabel#ContinuousPage { + background-color: #ffffff; + border: 1px solid #d8d8dc; +} QStatusBar { - background-color: #e8e8e8; - color: #666666; - border-top: 1px solid #d0d0d0; + background-color: #fbfbfc; + color: #6e6f76; + border-top: 1px solid #e8e8ec; + padding: 2px 8px; } QScrollArea { - background-color: #e0e0e0; + background-color: #ececee; border: none; } -#TabStrip { - background-color: #e0e0e0; - border-bottom: 1px solid #d0d0d0; +QWidget#ContinuousDocument, QWidget#DocumentViewport { + background-color: #ececee; } -QTabBar::tab { - background-color: #e0e0e0; - color: #666666; - padding: 6px 16px 6px 18px; - border: none; - border-right: 1px solid #d0d0d0; - min-height: 24px; +QScrollBar:vertical { + background: transparent; + width: 12px; + margin: 2px; } -QTabBar::tab:selected { - background-color: #f5f5f5; - color: #1a1a1a; - border-bottom: 2px solid #4a90d9; +QScrollBar::handle:vertical { + background-color: #c4c5ca; + border-radius: 4px; + min-height: 36px; + margin: 0px 2px; } -QTabBar::tab:hover:!selected { - background-color: #d8d8d8; - color: #1a1a1a; +QScrollBar::handle:vertical:hover { + background-color: #a8a9af; } -QToolButton#NewTabButton { - background-color: transparent; - color: #666666; - border: 1px solid transparent; - border-radius: 3px; +QScrollBar:horizontal { + background: transparent; + height: 12px; + margin: 2px; } -QToolButton#NewTabButton { - font-size: 16px; - font-weight: 400; - margin: 0px 8px 0px 4px; +QScrollBar::handle:horizontal { + background-color: #c4c5ca; + border-radius: 4px; + min-width: 36px; + margin: 2px 0px; } -QToolButton#NewTabButton:hover { - background-color: #d6d6d6; - border-color: transparent; - color: #1a1a1a; +QScrollBar::handle:horizontal:hover { + background-color: #a8a9af; } -QToolButton#TabCloseButton { - background-color: transparent; - border: none; - border-radius: 4px; - color: #6b7280; - font-size: 17px; - font-weight: 400; - padding: 0px; +QScrollBar::add-line, QScrollBar::sub-line { + width: 0px; + height: 0px; } -QToolButton#TabCloseButton:hover { - background-color: #e05252; - color: #ffffff; +QScrollBar::add-page, QScrollBar::sub-page { + background: transparent; } -QToolButton#TabCloseButton:pressed { - background-color: #c83f3f; +QProgressDialog { + background-color: #f3f3f5; + color: #1b1b1f; +} +QMessageBox { + background-color: #f3f3f5; + color: #1b1b1f; +} +QMessageBox QLabel { + color: #1b1b1f; +} +QMessageBox QPushButton { + min-width: 84px; +} +QInputDialog { + background-color: #f3f3f5; + color: #1b1b1f; +} +QGroupBox { + background-color: #ffffff; + border: 1px solid #e2e2e6; + border-radius: 8px; + margin-top: 12px; + padding: 14px 12px 12px 12px; +} +QGroupBox::title { + subcontrol-origin: margin; + left: 10px; + padding: 0px 4px; + color: #6e6f76; + font-size: 12px; + font-weight: 600; +} +QToolTip { + background-color: #2b2b31; color: #ffffff; + border: 1px solid #3a3a42; + border-radius: 6px; + padding: 5px 8px; +} +""" + +DARK_STYLESHEET = """ +/* OpenReader — Fluent dark theme */ +QMainWindow, QDialog { + background-color: #1a1b1e; + color: #ececed; +} +QWidget { + color: #ececed; +} +QMainWindow::separator { + background-color: #2b2c31; + width: 1px; + height: 1px; } QMenuBar { - background-color: #e8e8e8; - color: #1a1a1a; - border-bottom: 1px solid #d0d0d0; - padding: 2px; + background-color: #222327; + color: #ececed; + border: none; + border-bottom: 1px solid #2b2c31; + padding: 2px 6px; + spacing: 2px; } QMenuBar::item { - padding: 4px 10px; - background-color: transparent; - border-radius: 4px; + padding: 5px 10px; + border-radius: 6px; + background: transparent; } QMenuBar::item:selected { - background-color: #d0d0d0; + background-color: rgba(255, 255, 255, 0.07); } QMenu { - background-color: #ffffff; - color: #1a1a1a; - border: 1px solid #c8c8c8; - padding: 4px; + background-color: #26272c; + color: #ececed; + border: 1px solid #35363c; + border-radius: 8px; + padding: 5px; } QMenu::item { - padding: 6px 28px 6px 20px; - border-radius: 4px; + padding: 7px 28px 7px 14px; + border-radius: 5px; } QMenu::item:selected { - background-color: #4a90d9; - color: #ffffff; + background-color: rgba(255, 255, 255, 0.07); } QMenu::item:disabled { - color: #a0a0a0; + color: #6a6b73; } QMenu::separator { height: 1px; - background-color: #d0d0d0; - margin: 4px 8px; + background-color: #35363c; + margin: 5px 8px; } -QProgressDialog { - background-color: #ffffff; - color: #1a1a1a; - border: 1px solid #c8c8c8; +QToolBar#MainToolbar { + background-color: #222327; + border: none; + border-bottom: 1px solid #2b2c31; + padding: 6px; + spacing: 3px; } -QMessageBox { - background-color: #f5f5f5; - color: #1a1a1a; +QToolBar#MainToolbar::separator { + width: 1px; + background-color: #34353b; + margin: 7px 7px; } -QMessageBox QLabel { - color: #1a1a1a; +QToolBar#MainToolbar::extension { + background: transparent; + border: none; } -QMessageBox QPushButton { - min-width: 80px; +QToolBar#MainToolbar QToolButton { + background: transparent; + border: 1px solid transparent; + border-radius: 6px; + padding: 0px; } -QInputDialog { - background-color: #f5f5f5; - color: #1a1a1a; +QToolBar#MainToolbar QToolButton:hover { + background-color: rgba(255, 255, 255, 0.06); } -QScrollBar:horizontal { - background-color: #e0e0e0; - height: 10px; - border: none; +QToolBar#MainToolbar QToolButton:pressed { + background-color: rgba(255, 255, 255, 0.10); } -QScrollBar::handle:horizontal { - background-color: #b0b0b0; - border-radius: 5px; - min-width: 30px; +QToolBar#MainToolbar QToolButton:checked { + background-color: rgba(255, 77, 122, 0.14); + border-color: rgba(255, 77, 122, 0.40); } -QScrollBar::handle:horizontal:hover { - background-color: #909090; +QToolBar#MainToolbar QToolButton:disabled, +QToolBar#MainToolbar QToolButton:checked:disabled { + background: transparent; + border-color: transparent; } -QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal { - width: 0px; +QSpinBox#PageSpin { + background: transparent; + border: 1px solid transparent; + border-radius: 6px; + padding: 3px 2px; + color: #ececed; + font-weight: 600; + selection-background-color: #ff4d7a; + selection-color: #1a1b1e; } -QScrollBar:vertical { - background-color: #e0e0e0; - width: 10px; - border: none; +QSpinBox#PageSpin:hover { + background-color: #2a2b30; + border-color: #34353b; } -QScrollBar::handle:vertical { - background-color: #b0b0b0; - border-radius: 5px; - min-height: 30px; +QSpinBox#PageSpin:focus { + background-color: #2a2b30; + border-color: #ff4d7a; } -QScrollBar::handle:vertical:hover { - background-color: #909090; +QLabel#PageCount, QLabel#ZoomLabel, QLabel#SearchCount { + color: #9b9ca4; + font-size: 12px; + font-weight: 500; } -QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical { - height: 0px; +QLineEdit#SearchInput { + background-color: #2a2b30; + color: #ececed; + border: 1px solid #34353b; + border-radius: 6px; + padding: 4px 8px; + min-height: 22px; + selection-background-color: #ff4d7a; + selection-color: #1a1b1e; } -""" - -DARK_STYLESHEET = """ -QMainWindow, QWidget { - background-color: #1a1b26; - color: #c0caf5; +QLineEdit#SearchInput:focus { + border-color: #ff4d7a; } -QMainWindow::separator { - background-color: #292e42; +QToolBar#MainToolbar QToolButton#SemanticToggle { + color: #9b9ca4; + font-size: 12px; + font-weight: 500; + padding: 0px 10px; + min-height: 24px; + background: transparent; + border: 1px solid transparent; + border-radius: 6px; +} +QToolBar#MainToolbar QToolButton#SemanticToggle:hover { + background-color: rgba(255, 255, 255, 0.06); +} +QToolBar#MainToolbar QToolButton#SemanticToggle:checked { + background-color: rgba(255, 77, 122, 0.14); + border-color: rgba(255, 77, 122, 0.40); + color: #ececed; +} +QToolBar#MainToolbar QToolButton#SemanticToggle:disabled { + color: #55565e; +} +QTabBar { + background: transparent; +} +QTabBar::tab { + background: transparent; + color: #9b9ca4; + padding: 5px 14px; + margin: 5px 3px; + border: 1px solid transparent; + border-radius: 7px; + min-height: 18px; +} +QTabBar::tab:selected { + background-color: #2a2b30; + color: #ececed; + border-color: #35363c; +} +QTabBar::tab:hover:!selected { + background-color: rgba(255, 255, 255, 0.06); + color: #ececed; +} +#TabStrip { + background-color: #1a1b1e; + border-bottom: 1px solid #2b2c31; +} +QToolButton#NewTabButton { + background-color: transparent; + border: 1px solid transparent; + border-radius: 6px; + padding: 0px; +} +QToolButton#NewTabButton:hover { + background-color: rgba(255, 255, 255, 0.06); +} +QToolButton#TabCloseButton { + background-color: transparent; + border: none; + border-radius: 5px; + color: #8b8c94; + font-size: 15px; + font-weight: 500; + padding: 0px; +} +QToolButton#TabCloseButton:hover { + background-color: rgba(255, 255, 255, 0.09); + color: #ececed; +} +QToolButton#TabCloseButton:pressed { + background-color: rgba(255, 255, 255, 0.13); } QPushButton { - background-color: #24283b; - color: #c0caf5; - border: 1px solid #3b4261; - padding: 4px 14px; - border-radius: 4px; + background-color: #2a2b30; + color: #ececed; + border: 1px solid #3a3b42; + padding: 5px 14px; + border-radius: 6px; min-height: 22px; } QPushButton:hover { - background-color: #33467c; - border-color: #565f89; + background-color: #33343a; + border-color: #46474f; } QPushButton:pressed { - background-color: #414868; + background-color: #3b3c44; +} +QPushButton:default { + background-color: #ff4d7a; + color: #1a1b1e; + border-color: #ff4d7a; +} +QPushButton:default:hover { + background-color: #ff6690; + border-color: #ff6690; } QPushButton:checked { - background-color: #7aa2f7; - color: #1a1b26; - border-color: #7aa2f7; + background-color: rgba(255, 77, 122, 0.14); + color: #ececed; + border-color: rgba(255, 77, 122, 0.40); } QPushButton:disabled { - background-color: #1a1b26; - color: #3b4261; - border-color: #24283b; + background-color: #212226; + color: #55565e; + border-color: #2c2d32; +} +QPushButton#OpenEmptyButton { + background-color: #ff4d7a; + color: #1a1b1e; + border: none; + border-radius: 7px; + padding: 9px 22px; + font-weight: 600; +} +QPushButton#OpenEmptyButton:hover { + background-color: #ff6690; +} +QPushButton#OpenEmptyButton:pressed { + background-color: #e63d67; } QLineEdit { - background-color: #24283b; - color: #c0caf5; - border: 1px solid #3b4261; - padding: 4px 6px; - border-radius: 4px; - selection-background-color: #7aa2f7; - selection-color: #1a1b26; + background-color: #2a2b30; + color: #ececed; + border: 1px solid #3a3b42; + padding: 5px 8px; + border-radius: 6px; + selection-background-color: #ff4d7a; + selection-color: #1a1b1e; } QLineEdit:focus { - border-color: #7aa2f7; + border-color: #ff4d7a; } QSpinBox { - background-color: #24283b; - color: #c0caf5; - border: 1px solid #3b4261; + background-color: #2a2b30; + color: #ececed; + border: 1px solid #3a3b42; padding: 4px; - border-radius: 4px; + border-radius: 6px; } QSpinBox:focus { - border-color: #7aa2f7; + border-color: #ff4d7a; } QSpinBox::up-button, QSpinBox::down-button { - background-color: #3b4261; + background-color: #34353b; border: none; width: 18px; } QLabel { - color: #c0caf5; + color: #ececed; background-color: transparent; } -QStatusBar { - background-color: #13141f; - color: #565f89; - border-top: 1px solid #292e42; -} -QScrollArea { - background-color: #1a1b26; - border: none; +QLabel#EmptyTitle { + color: #ececed; + font-size: 19px; + font-weight: 600; } -#TabStrip { - background-color: #13141f; - border-bottom: 1px solid #292e42; +QLabel#EmptySubtitle { + color: #9b9ca4; + font-size: 13px; } -QTabBar::tab { - background-color: #13141f; - color: #565f89; - padding: 6px 16px 6px 18px; - border: none; - border-right: 1px solid #292e42; - min-height: 24px; -} -QTabBar::tab:selected { - background-color: #1a1b26; - color: #7aa2f7; - border-bottom: 2px solid #7aa2f7; -} -QTabBar::tab:hover:!selected { - background-color: #292e42; - color: #c0caf5; -} -QToolButton#NewTabButton { - background-color: transparent; - color: #8b93b5; - border: 1px solid transparent; - border-radius: 3px; -} -QToolButton#NewTabButton { - font-size: 16px; - font-weight: 400; - margin: 0px 8px 0px 4px; +QLabel#PdfPage, QLabel#ContinuousPage { + background-color: #ffffff; + border: 1px solid #3a3b42; } -QToolButton#NewTabButton:hover { - background-color: #292e42; - border-color: transparent; - color: #c0caf5; +QStatusBar { + background-color: #222327; + color: #9b9ca4; + border-top: 1px solid #2b2c31; + padding: 2px 8px; } -QToolButton#TabCloseButton { - background-color: transparent; +QScrollArea { + background-color: #141518; border: none; - border-radius: 4px; - color: #7d86a9; - font-size: 17px; - font-weight: 400; - padding: 0px; } -QToolButton#TabCloseButton:hover { - background-color: #e05252; - color: #ffffff; -} -QToolButton#TabCloseButton:pressed { - background-color: #c83f3f; - color: #ffffff; +QWidget#ContinuousDocument, QWidget#DocumentViewport { + background-color: #141518; } -QMenuBar { - background-color: #13141f; - color: #c0caf5; - border-bottom: 1px solid #292e42; - padding: 2px; +QScrollBar:vertical { + background: transparent; + width: 12px; + margin: 2px; } -QMenuBar::item { - padding: 4px 10px; - background-color: transparent; +QScrollBar::handle:vertical { + background-color: #45464e; border-radius: 4px; + min-height: 36px; + margin: 0px 2px; } -QMenuBar::item:selected { - background-color: #292e42; +QScrollBar::handle:vertical:hover { + background-color: #5c5d66; } -QMenu { - background-color: #1a1b26; - color: #c0caf5; - border: 1px solid #3b4261; - padding: 4px; +QScrollBar:horizontal { + background: transparent; + height: 12px; + margin: 2px; } -QMenu::item { - padding: 6px 28px 6px 20px; +QScrollBar::handle:horizontal { + background-color: #45464e; border-radius: 4px; + min-width: 36px; + margin: 2px 0px; } -QMenu::item:selected { - background-color: #33467c; +QScrollBar::handle:horizontal:hover { + background-color: #5c5d66; } -QMenu::item:disabled { - color: #3b4261; +QScrollBar::add-line, QScrollBar::sub-line { + width: 0px; + height: 0px; } -QMenu::separator { - height: 1px; - background-color: #292e42; - margin: 4px 8px; +QScrollBar::add-page, QScrollBar::sub-page { + background: transparent; } QProgressDialog { - background-color: #1a1b26; - color: #c0caf5; - border: 1px solid #3b4261; + background-color: #1a1b1e; + color: #ececed; } QMessageBox { - background-color: #1a1b26; - color: #c0caf5; + background-color: #1a1b1e; + color: #ececed; } QMessageBox QLabel { - color: #c0caf5; + color: #ececed; } QMessageBox QPushButton { - min-width: 80px; + min-width: 84px; } QInputDialog { - background-color: #1a1b26; - color: #c0caf5; + background-color: #1a1b1e; + color: #ececed; } -QScrollBar:horizontal { - background-color: #13141f; - height: 10px; - border: none; +QGroupBox { + background-color: #222327; + border: 1px solid #34353b; + border-radius: 8px; + margin-top: 12px; + padding: 14px 12px 12px 12px; } -QScrollBar::handle:horizontal { - background-color: #3b4261; - border-radius: 5px; - min-width: 30px; +QGroupBox::title { + subcontrol-origin: margin; + left: 10px; + padding: 0px 4px; + color: #9b9ca4; + font-size: 12px; + font-weight: 600; } -QScrollBar::handle:horizontal:hover { - background-color: #565f89; -} -QScrollBar::add-line:horizontal, QScrollBar::sub-line:horizontal { - width: 0px; -} -QScrollBar:vertical { - background-color: #13141f; - width: 10px; - border: none; -} -QScrollBar::handle:vertical { - background-color: #3b4261; - border-radius: 5px; - min-height: 30px; -} -QScrollBar::handle:vertical:hover { - background-color: #565f89; -} -QScrollBar::add-line:vertical, QScrollBar::sub-line:vertical { - height: 0px; +QToolTip { + background-color: #33343a; + color: #f2f2f4; + border: 1px solid #45464e; + border-radius: 6px; + padding: 5px 8px; } """ @@ -656,230 +981,278 @@ def paintEvent(self, event): # --------------------------------------------------------------------------- -def _make_zoom_icon(icon_size: int, draw_fn) -> QIcon: - """Create a crisp vector icon for toolbar buttons using QPainter.""" - pixmap = QPixmap(icon_size, icon_size) - pixmap.fill(Qt.transparent) - painter = QPainter(pixmap) - painter.setRenderHint(QPainter.RenderHint.Antialiasing) - draw_fn(painter, icon_size) - painter.end() - return QIcon(pixmap) - - -def _make_zoom_buttons() -> tuple[QPushButton, QPushButton, QPushButton]: - """Build zoom control buttons with crisp vector icons instead of text.""" - btn_size = 34 - line_w = 2.5 - margin = 7 - - # --- Zoom out (-) icon --- - def _draw_minus(p: QPainter, s: int): - p.setPen(Qt.PenStyle.NoPen) - p.setBrush(QColor(80, 80, 80)) - y = s // 2 - p.drawRoundedRect(margin, y - line_w, s - 2 * margin, line_w * 2, 2, 2) - - # --- Zoom in (+) icon --- - def _draw_plus(p: QPainter, s: int): - p.setPen(Qt.PenStyle.NoPen) - p.setBrush(QColor(80, 80, 80)) - y = s // 2 - p.drawRoundedRect(margin, y - line_w, s - 2 * margin, line_w * 2, 2, 2) - x = s // 2 - p.drawRoundedRect(x - line_w, margin, line_w * 2, s - 2 * margin, 2, 2) - - # --- Fit icon (two diagonal arrows pointing inward) --- - def _draw_fit(p: QPainter, s: int): - p.setPen(QPen(QColor(80, 80, 80), 2.5, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap)) - p.setBrush(Qt.NoBrush) - m = 8 - # Top-left arrow - p.drawLine(m, s - m, s // 2 - 2, s // 2 - 2) - p.drawLine(m, m, s // 2 - 2, s // 2 - 2) - p.drawLine(m, m, s // 2 - 2, m) - # Bottom-right arrow - p.drawLine(s - m, m, s // 2 + 2, s // 2 + 2) - p.drawLine(s - m, s - m, s // 2 + 2, s // 2 + 2) - p.drawLine(s - m, s - m, s // 2 + 2, s - m) - - # --- Hover/checked variants with accent color --- - def _make_hovered(draw_fn): - return _make_zoom_icon(btn_size, draw_fn) - - zoom_out_icon = _make_zoom_icon(btn_size, _draw_minus) - zoom_in_icon = _make_zoom_icon(btn_size, _draw_plus) - fit_icon = _make_zoom_icon(btn_size, _draw_fit) - - zoom_out = QPushButton() - zoom_out.setIcon(zoom_out_icon) - zoom_out.setIconSize(QSize(btn_size, btn_size)) - zoom_out.setFixedSize(btn_size + 4, btn_size + 4) - zoom_out.setToolTip("Zoom out (Ctrl+Mouse Wheel Up / Ctrl+-)") - - zoom_in = QPushButton() - zoom_in.setIcon(zoom_in_icon) - zoom_in.setIconSize(QSize(btn_size, btn_size)) - zoom_in.setFixedSize(btn_size + 4, btn_size + 4) - zoom_in.setToolTip("Zoom in (Ctrl+Mouse Wheel Down / Ctrl+=)") - - fit = QPushButton() - fit.setIcon(fit_icon) - fit.setIconSize(QSize(btn_size, btn_size)) - fit.setFixedSize(btn_size + 4, btn_size + 4) - fit.setCheckable(True) - fit.setChecked(True) - fit.setToolTip("Fit page to window (Ctrl+0)") - - # Stylesheet for consistent sizing and hover feedback - zoom_btn_css = """ - QPushButton { - border: 1px solid transparent; - border-radius: 4px; - background-color: transparent; - padding: 0px; - } - QPushButton:hover { - background-color: rgba(128, 128, 128, 40); - border-color: rgba(128, 128, 128, 80); - } - QPushButton:pressed { - background-color: rgba(128, 128, 128, 80); - } - QPushButton:checked { - background-color: rgba(74, 144, 217, 40); - border-color: rgba(74, 144, 217, 120); - } - """ - zoom_out.setStyleSheet(zoom_btn_css) - zoom_in.setStyleSheet(zoom_btn_css) - fit.setStyleSheet(zoom_btn_css) - - return zoom_out, zoom_in, fit - - -def _make_tool_icons(icon_size: int): - """Build crisp vector icons for annotation toolbar buttons.""" +# --------------------------------------------------------------------------- +# Toolbar design system — theme-aware vector icons +# --------------------------------------------------------------------------- - btn_css = """ - QPushButton { - border: 1px solid transparent; - border-radius: 4px; - background-color: transparent; - padding: 0px; - } - QPushButton:hover { - background-color: rgba(128, 128, 128, 40); - border-color: rgba(128, 128, 128, 80); +TOOLBAR_ICON_SIZE = 18 +TOOLBAR_BUTTON_SIZE = 30 +TOOLBAR_SMALL_BUTTON_SIZE = 26 + + +def _toolbar_icon_colors(dark_mode: bool) -> dict[str, str]: + """Fluent-style icon palette for the active theme.""" + if dark_mode: + return { + "stroke": "#e9e9ee", + "muted": "#9b9ca4", + "accent": "#ff4d7a", + "highlight": "#f5c518", + "disabled": "#4c4d55", + "surface": "#232428", } - QPushButton:pressed { - background-color: rgba(128, 128, 128, 80); - } - """ + return { + "stroke": "#232329", + "muted": "#6f7076", + "accent": "#ff255f", + "highlight": "#e8a800", + "disabled": "#c3c4c9", + "surface": "#fbfbfc", + } + + +def _icon_pen(color: str, width: float = 1.6) -> QPen: + pen = QPen(QColor(color), width) + pen.setCapStyle(Qt.PenCapStyle.RoundCap) + pen.setJoinStyle(Qt.PenJoinStyle.RoundJoin) + return pen + + +def _draw_open_icon(p: QPainter, s: float, c: dict[str, str]): + p.setPen(_icon_pen(c["stroke"], 1.5)) + p.setBrush(Qt.BrushStyle.NoBrush) + path = QPainterPath() + path.moveTo(2.8, 5.4) + path.lineTo(7.1, 5.4) + path.lineTo(8.6, 7.3) + path.lineTo(15.2, 7.3) + path.lineTo(15.2, 14.3) + path.lineTo(2.8, 14.3) + path.closeSubpath() + p.drawPath(path) + + +def _draw_save_icon(p: QPainter, s: float, c: dict[str, str]): + p.setPen(_icon_pen(c["stroke"], 1.6)) + p.setBrush(Qt.BrushStyle.NoBrush) + p.drawLine(QPointF(9, 3.2), QPointF(9, 11.1)) + arrow = QPainterPath() + arrow.moveTo(5.9, 8.2) + arrow.lineTo(9, 11.3) + arrow.lineTo(12.1, 8.2) + p.drawPath(arrow) + tray = QPainterPath() + tray.moveTo(3.5, 12.2) + tray.lineTo(3.5, 15.0) + tray.lineTo(14.5, 15.0) + tray.lineTo(14.5, 12.2) + p.drawPath(tray) + + +def _chevron(p: QPainter, c: dict[str, str], points: tuple): + p.setPen(_icon_pen(c["stroke"], 1.8)) + p.setBrush(Qt.BrushStyle.NoBrush) + path = QPainterPath() + path.moveTo(*points[0]) + path.lineTo(*points[1]) + path.lineTo(*points[2]) + p.drawPath(path) + + +def _draw_chevron_left(p: QPainter, s: float, c: dict[str, str]): + _chevron(p, c, ((11.6, 4.6), (6.4, 9.0), (11.6, 13.4))) + + +def _draw_chevron_right(p: QPainter, s: float, c: dict[str, str]): + _chevron(p, c, ((6.4, 4.6), (11.6, 9.0), (6.4, 13.4))) + + +def _draw_chevron_up(p: QPainter, s: float, c: dict[str, str]): + _chevron(p, c, ((4.8, 11.4), (9.0, 6.6), (13.2, 11.4))) + + +def _draw_chevron_down(p: QPainter, s: float, c: dict[str, str]): + _chevron(p, c, ((4.8, 6.6), (9.0, 11.4), (13.2, 6.6))) + + +def _draw_plus_icon(p: QPainter, s: float, c: dict[str, str]): + p.setPen(_icon_pen(c["stroke"], 1.8)) + p.drawLine(QPointF(4.4, 9), QPointF(13.6, 9)) + p.drawLine(QPointF(9, 4.4), QPointF(9, 13.6)) + + +def _draw_minus_icon(p: QPainter, s: float, c: dict[str, str]): + p.setPen(_icon_pen(c["stroke"], 1.8)) + p.drawLine(QPointF(4.4, 9), QPointF(13.6, 9)) + + +def _draw_fit_icon(p: QPainter, s: float, c: dict[str, str]): + p.setPen(_icon_pen(c["stroke"], 1.6)) + # Four corner brackets. + p.drawLine(QPointF(3.2, 6.6), QPointF(3.2, 3.2)) + p.drawLine(QPointF(3.2, 3.2), QPointF(6.6, 3.2)) + p.drawLine(QPointF(11.4, 3.2), QPointF(14.8, 3.2)) + p.drawLine(QPointF(14.8, 3.2), QPointF(14.8, 6.6)) + p.drawLine(QPointF(3.2, 11.4), QPointF(3.2, 14.8)) + p.drawLine(QPointF(3.2, 14.8), QPointF(6.6, 14.8)) + p.drawLine(QPointF(11.4, 14.8), QPointF(14.8, 14.8)) + p.drawLine(QPointF(14.8, 14.8), QPointF(14.8, 11.4)) + + +def _draw_copy_icon(p: QPainter, s: float, c: dict[str, str]): + p.setPen(_icon_pen(c["muted"], 1.4)) + p.setBrush(Qt.BrushStyle.NoBrush) + p.drawRoundedRect(QRectF(4.2, 3.2, 7.8, 9.8), 1.8, 1.8) + # Front sheet occludes the back one. + p.setBrush(QColor(c["surface"])) + p.drawRoundedRect(QRectF(7.2, 6.2, 7.0, 9.0), 1.8, 1.8) + + +def _draw_highlight_icon(p: QPainter, s: float, c: dict[str, str]): + pen = QPen(QColor(c["highlight"]), 4.4) + pen.setCapStyle(Qt.PenCapStyle.RoundCap) + p.setPen(pen) + p.drawLine(QPointF(4.8, 13.2), QPointF(12.2, 4.9)) + p.setPen(_icon_pen(c["muted"], 1.5)) + p.drawLine(QPointF(12.9, 3.6), QPointF(14.6, 5.3)) + + +def _draw_underline_icon(p: QPainter, s: float, c: dict[str, str]): + p.setPen(_icon_pen(c["stroke"], 1.7)) + p.setBrush(Qt.BrushStyle.NoBrush) + path = QPainterPath() + path.moveTo(5.5, 3.4) + path.lineTo(5.5, 9.1) + path.cubicTo(5.5, 12.6, 12.5, 12.6, 12.5, 9.1) + path.lineTo(12.5, 3.4) + p.drawPath(path) + p.setPen(_icon_pen(c["accent"], 1.8)) + p.drawLine(QPointF(4.0, 15.1), QPointF(14.0, 15.1)) + + +def _draw_strike_icon(p: QPainter, s: float, c: dict[str, str]): + p.setPen(_icon_pen(c["stroke"], 1.55)) + p.setBrush(Qt.BrushStyle.NoBrush) + path = QPainterPath() + path.moveTo(12.2, 5.5) + path.cubicTo(12.2, 3.4, 6.2, 3.2, 6.2, 6.4) + path.cubicTo(6.2, 8.8, 12.4, 8.3, 12.4, 11.8) + path.cubicTo(12.4, 14.8, 6.0, 14.8, 6.0, 12.5) + p.drawPath(path) + p.setPen(_icon_pen(c["accent"], 1.8)) + p.drawLine(QPointF(3.6, 9.1), QPointF(14.4, 9.1)) + + +def _draw_sticky_icon(p: QPainter, s: float, c: dict[str, str]): + p.setPen(_icon_pen(c["muted"], 1.45)) + p.setBrush(Qt.BrushStyle.NoBrush) + p.drawRoundedRect(QRectF(4.2, 3.2, 9.6, 11.6), 1.7, 1.7) + fold = QPainterPath() + fold.moveTo(10.8, 3.2) + fold.lineTo(10.8, 6.8) + fold.lineTo(13.8, 6.8) + p.drawPath(fold) + p.setPen(Qt.PenStyle.NoPen) + p.setBrush(QColor(c["accent"])) + p.drawEllipse(QPointF(6.9, 6.5), 1.05, 1.05) + p.setPen(_icon_pen(c["muted"], 1.2)) + p.drawLine(QPointF(6.9, 9.5), QPointF(11.1, 9.5)) + p.drawLine(QPointF(6.9, 11.5), QPointF(10.1, 11.5)) + + +def _draw_search_icon(p: QPainter, s: float, c: dict[str, str]): + p.setPen(_icon_pen(c["muted"], 1.6)) + p.setBrush(Qt.BrushStyle.NoBrush) + p.drawEllipse(QPointF(7.8, 7.8), 4.5, 4.5) + p.drawLine(QPointF(11.2, 11.2), QPointF(14.8, 14.8)) + + +def _draw_close_icon(p: QPainter, s: float, c: dict[str, str]): + p.setPen(_icon_pen(c["muted"], 1.6)) + p.drawLine(QPointF(5.2, 5.2), QPointF(12.8, 12.8)) + p.drawLine(QPointF(12.8, 5.2), QPointF(5.2, 12.8)) + + +_TOOLBAR_ICONS = { + "open": _draw_open_icon, + "save": _draw_save_icon, + "chevron_left": _draw_chevron_left, + "chevron_right": _draw_chevron_right, + "chevron_up": _draw_chevron_up, + "chevron_down": _draw_chevron_down, + "plus": _draw_plus_icon, + "minus": _draw_minus_icon, + "fit": _draw_fit_icon, + "copy": _draw_copy_icon, + "highlight": _draw_highlight_icon, + "underline": _draw_underline_icon, + "strike": _draw_strike_icon, + "sticky": _draw_sticky_icon, + "search": _draw_search_icon, + "close": _draw_close_icon, +} - def _build(draw_fn): - pixmap = QPixmap(icon_size, icon_size) - pixmap.fill(Qt.transparent) + +def _make_toolbar_icon(draw_fn, dark_mode: bool, size: int = TOOLBAR_ICON_SIZE) -> QIcon: + """Render a crisp icon (plus a muted disabled variant) for the theme.""" + colors = _toolbar_icon_colors(dark_mode) + scale = 2.0 + icon = QIcon() + for mode, palette in ( + (QIcon.Mode.Normal, colors), + ( + QIcon.Mode.Disabled, + { + **colors, + "stroke": colors["disabled"], + "muted": colors["disabled"], + "accent": colors["disabled"], + "highlight": colors["disabled"], + }, + ), + ): + pixmap = QPixmap(int(size * scale), int(size * scale)) + pixmap.fill(Qt.GlobalColor.transparent) + pixmap.setDevicePixelRatio(scale) painter = QPainter(pixmap) - painter.setRenderHint(QPainter.RenderHint.Antialiasing) - draw_fn(painter, icon_size) + painter.setRenderHint(QPainter.RenderHint.Antialiasing, True) + # QPainter already works in logical pixels for a DPR-aware pixmap. + draw_fn(painter, size, palette) painter.end() - return QIcon(pixmap) - - # --- Copy: two overlapping document pages --- - def _draw_copy(p: QPainter, s: int): - p.setRenderHint(QPainter.RenderHint.Antialiasing) - # Back page - p.setPen(QPen(QColor(100, 100, 100), 1.5)) - p.setBrush(QColor(245, 245, 245)) - p.drawRoundedRect(7, 4, 15, 18, 2, 2) - # Front page - p.drawRoundedRect(10, 8, 17, 20, 2, 2) - # Lines on front page - p.setPen(QPen(QColor(140, 140, 140), 1.2)) - for y in [14, 18, 22]: - p.drawLine(14, y, 23, y) - - # --- Highlight: marker pen + highlight bar --- - def _draw_highlight(p: QPainter, s: int): - # Highlight bar (angled) - p.setPen(Qt.PenStyle.NoPen) - p.setBrush(QColor(255, 220, 60, 180)) - bar = QPainterPath() - bar.moveTo(7, 25) - bar.lineTo(26, 6) - bar.lineTo(30, 10) - bar.lineTo(11, 29) - bar.closeSubpath() - p.drawPath(bar) - # Pen tip - p.setPen(QPen(QColor(60, 60, 60), 2, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap)) - p.drawLine(26, 6, 29, 3) - - # --- Underline: "U" with underline --- - def _draw_underline(p: QPainter, s: int): - p.setPen(QPen(QColor(80, 80, 80), 2.5, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap)) - # U shape - path = QPainterPath() - path.moveTo(9, 8) - path.cubicTo(9, 8, 9, 24, 17, 24) - path.cubicTo(25, 24, 25, 8, 25, 8) - p.drawPath(path) - # Underline - p.drawLine(8, 27, 26, 27) - - # --- Strikethrough: "S" with strike line --- - def _draw_strikethrough(p: QPainter, s: int): - p.setPen(QPen(QColor(80, 80, 80), 2.5, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap)) - # S letter - path = QPainterPath() - path.moveTo(22, 8) - path.cubicTo(22, 8, 24, 7, 21, 7) - path.cubicTo(14, 7, 10, 18, 17, 18) - path.cubicTo(24, 18, 22, 27, 15, 27) - path.cubicTo(11, 27, 10, 26, 10, 26) - p.drawPath(path) - # Strike line - p.setPen(QPen(QColor(220, 50, 50), 2.5, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap)) - p.drawLine(7, 17, 27, 17) - - # --- Sticky Note: notepad with folded corner --- - def _draw_sticky(p: QPainter, s: int): - # Notepad body - p.setPen(QPen(QColor(100, 100, 100), 1.5)) - p.setBrush(QColor(255, 250, 200)) - p.drawRoundedRect(6, 4, 22, 26, 2, 2) - # Folded corner - fold = QPainterPath() - fold.moveTo(22, 4) - fold.lineTo(22, 12) - fold.lineTo(28, 12) - fold.closeSubpath() - p.setBrush(QColor(220, 215, 180)) - p.setPen(QPen(QColor(140, 140, 140), 1)) - p.drawPath(fold) - # Lined paper - p.setPen(QPen(QColor(180, 180, 150), 1.2)) - for y in [15, 19, 23]: - p.drawLine(10, y, 21, y) - # Pin dot - p.setPen(Qt.PenStyle.NoPen) - p.setBrush(QColor(200, 70, 70)) - p.drawEllipse(QPointF(s / 2, 6), 2.5, 2.5) - - names = ["copy", "highlight", "underline", "strike", "sticky"] - drawers = [_draw_copy, _draw_highlight, _draw_underline, _draw_strikethrough, _draw_sticky] - - buttons = [] - for name, draw_fn in zip(names, drawers): - btn = QPushButton() - btn.setIcon(_build(draw_fn)) - btn.setIconSize(QSize(icon_size, icon_size)) - btn.setFixedSize(icon_size + 4, icon_size + 4) - btn.setStyleSheet(btn_css) - buttons.append(btn) - - return buttons # [copy, highlight, underline, strike, sticky] + icon.addPixmap(pixmap, mode) + return icon + + +def _make_empty_state_icon(dark_mode: bool, size: int = 60) -> QPixmap: + """A quiet document glyph for the empty reading surface.""" + colors = _toolbar_icon_colors(dark_mode) + scale = 2.0 + pixmap = QPixmap(int(size * scale), int(size * scale)) + pixmap.fill(Qt.GlobalColor.transparent) + pixmap.setDevicePixelRatio(scale) + painter = QPainter(pixmap) + painter.setRenderHint(QPainter.RenderHint.Antialiasing, True) + pen = QPen(QColor(colors["muted"]), 1.5) + pen.setJoinStyle(Qt.PenJoinStyle.RoundJoin) + painter.setPen(pen) + painter.setBrush(Qt.BrushStyle.NoBrush) + sheet = QPainterPath() + sheet.moveTo(14, 4) + sheet.lineTo(38, 4) + sheet.lineTo(48, 14) + sheet.lineTo(48, 56) + sheet.lineTo(14, 56) + sheet.closeSubpath() + painter.drawPath(sheet) + painter.drawLine(QPointF(38, 4), QPointF(38, 14)) + painter.drawLine(QPointF(38, 14), QPointF(48, 14)) + line_color = QColor(colors["muted"]) + line_color.setAlpha(150) + painter.setPen(QPen(line_color, 1.4, Qt.PenStyle.SolidLine, Qt.PenCapStyle.RoundCap)) + for y in (26, 34, 42): + painter.drawLine(QPointF(21, y), QPointF(41, y)) + painter.end() + return pixmap # --------------------------------------------------------------------------- @@ -898,6 +1271,15 @@ class PdfReaderWindow(QMainWindow): MAX_ZOOM = 5.0 ZOOM_STEP = 0.15 + # Continuous scrolling (virtualized): every page keeps a sized placeholder + # so the scroll range always spans the whole document, while pixmaps exist + # only for the viewport plus a small overscan. + CONTINUOUS_OVERSCAN = 2 # pages rendered on each side of the viewport + CONTINUOUS_CACHE = 4 # rendered pages kept on each side before release + CONTINUOUS_PAGE_GAP = 12 + CONTINUOUS_PAGE_MARGIN = 16 + CONTINUOUS_RENDER_DELAY_MS = 40 + # Dark mode constants THEME_AUTO = 0 THEME_LIGHT = 1 @@ -936,18 +1318,28 @@ def __init__(self, ipc_server: QLocalServer | None = None): _perf_start_t = _perf_start() super().__init__() self.setWindowTitle(self.APP_NAME) - self.resize(1000, 800) + self.resize(1100, 820) + self.setMinimumSize(720, 480) # ---- IPC server for single-instance tab routing ---- self._ipc_server = ipc_server if ipc_server is not None: ipc_server.newConnection.connect(self._on_ipc_connection) - # ---- Continuous scroll ---- + # ---- Continuous scroll (virtualized) ---- self._continuous_mode = True # default to continuous self._continuous_pages: list[QLabel] = [] + self._continuous_rendered: set[int] = set() self._continuous_container = None self._continuous_layout = None + self._continuous_layout_zoom: float | None = None + self._continuous_layout_document = None + self._continuous_syncing_scroll = False + self._pending_scroll_page: int | None = None + self._continuous_render_timer = QTimer(self) + self._continuous_render_timer.setSingleShot(True) + self._continuous_render_timer.setInterval(self.CONTINUOUS_RENDER_DELAY_MS) + self._continuous_render_timer.timeout.connect(self._render_visible_continuous) # App icon self._set_app_icon() @@ -1060,11 +1452,11 @@ def _build_ui(self): tab_strip_layout.addWidget(self.tab_bar) self.new_tab_button = QToolButton() - self.new_tab_button.setText("+") self.new_tab_button.setObjectName("NewTabButton") + self.new_tab_button.setIconSize(QSize(16, 16)) self.new_tab_button.setFixedSize(28, 28) + self.tab_bar.setMinimumWidth(1) self.new_tab_button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) - self.new_tab_button.setAutoRaise(True) self.new_tab_button.setCursor(Qt.PointingHandCursor) self.new_tab_button.setToolTip("New Tab (Ctrl+T)") self.new_tab_button.setAccessibleName("New blank tab") @@ -1073,106 +1465,44 @@ def _build_ui(self): tab_strip_layout.addStretch(1) root.addWidget(tab_strip) + self._sync_tab_strip() - # Controls bar - controls_widget = QWidget() - controls_widget.setContentsMargins(8, 6, 8, 6) - controls = QHBoxLayout(controls_widget) - controls.setSpacing(4) - controls.setContentsMargins(0, 0, 0, 0) - - self.prev_button = QPushButton("Prev") - self.prev_button.setToolTip("Previous page (Page Up)") - self.next_button = QPushButton("Next") - self.next_button.setToolTip("Next page (Page Down)") - self.page_spin = QSpinBox() - self.page_spin.setMinimum(1) - self.page_spin.setMaximum(1) - self.page_spin.setFixedWidth(70) - self.page_spin.setToolTip("Jump to page number") - self.page_count_label = QLabel("/ 0") - - self.zoom_out_button, self.zoom_in_button, self.fit_button = _make_zoom_buttons() - self.copy_button, self.highlight_button, self.underline_button, self.strike_button, self.sticky_button = \ - _make_tool_icons(34) - self.copy_button.setToolTip("Copy selected text (Ctrl+C)") - self.highlight_button.setToolTip("Highlight selected text") - self.underline_button.setToolTip("Underline selected text") - self.strike_button.setToolTip("Strikethrough selected text") - self.sticky_button.setCheckable(True) - self.sticky_button.setToolTip("Place sticky note") - - controls.addSpacing(4) - controls.addWidget(self.prev_button) - controls.addWidget(self.next_button) - controls.addWidget(QLabel("Pg")) - controls.addWidget(self.page_spin) - controls.addWidget(self.page_count_label) - controls.addSpacing(6) - controls.addWidget(self.zoom_out_button) - controls.addWidget(self.zoom_in_button) - controls.addWidget(self.fit_button) - controls.addSpacing(6) - controls.addWidget(self.copy_button) - controls.addWidget(self.highlight_button) - controls.addWidget(self.underline_button) - controls.addWidget(self.strike_button) - controls.addWidget(self.sticky_button) - - controls.addSpacing(4) - self.semantic_cb = QCheckBox("Semantic") - self.semantic_cb.setToolTip("Enable semantic (meaning-based) search instead of keyword exact match") - - controls.addSpacing(4) - self.search_input = QLineEdit() - self.search_input.setPlaceholderText("Search text") - self.search_input.setClearButtonEnabled(True) - self.search_input.setMinimumWidth(160) - self.search_prev_button = QPushButton("\u25b2") - self.search_prev_button.setFixedWidth(30) - self.search_next_button = QPushButton("\u25bc") - self.search_next_button.setFixedWidth(30) - self.search_count_label = QLabel("0") - self.search_count_label.setFixedWidth(32) - - controls.addWidget(self.search_input, 1) - controls.addWidget(self.search_prev_button) - controls.addWidget(self.search_next_button) - controls.addWidget(self.search_count_label) - controls.addWidget(self.semantic_cb) - root.addWidget(controls_widget) - - # Page content — improved empty state + + # Page content — quiet empty state self.empty_state_widget = QWidget() empty_layout = QVBoxLayout(self.empty_state_widget) empty_layout.setAlignment(Qt.AlignCenter) - empty_layout.setSpacing(14) - - # Icon / visual marker - icon_label = QLabel() - icon_pixmap = self.style().standardIcon(QStyle.StandardPixmap.SP_FileDialogStart).pixmap(48, 48) - icon_label.setPixmap(icon_pixmap) - icon_label.setAlignment(Qt.AlignCenter) - icon_opacity = QGraphicsOpacityEffect() - icon_opacity.setOpacity(0.45) - icon_label.setGraphicsEffect(icon_opacity) - empty_layout.addWidget(icon_label) - - title_label = QLabel("
"
"Drag and drop a PDF here, or use File → Open PDF (Ctrl+O)
"
- "to get started reading locally and privately.