diff --git a/.gitea/workflows/build_and_test.yml b/.gitea/workflows/build_and_test.yml index c848c85ce..c1c65d9a6 100644 --- a/.gitea/workflows/build_and_test.yml +++ b/.gitea/workflows/build_and_test.yml @@ -88,7 +88,7 @@ jobs: cd build/tools ./jfjoch_hdf5_test ../../tests/test_data/compression_benchmark.h5 build-windows: - name: build:windows:${{ matrix.variant }} + name: build:viewer:windows-x86_64:${{ matrix.variant }} # Uploads to the release, so it waits for the job that creates it. needs: create-release runs-on: windows-11-cuda-qt @@ -136,7 +136,7 @@ jobs: if ($LASTEXITCODE -ne 0) { throw "Upload failed for $($file.Name)" } } build-viewer-tgz: - name: build:viewer-tgz:${{ matrix.variant }} + name: build:viewer:linux-x86_64:${{ matrix.variant }} # Uploads to the release, so it waits for the job that creates it. needs: create-release runs-on: jfjoch_rocky8 @@ -149,7 +149,7 @@ jobs: include: - variant: cuda use_cuda: 'ON' - - variant: cpu + - variant: nocuda use_cuda: 'OFF' steps: - uses: actions/checkout@v4 @@ -169,7 +169,7 @@ jobs: cd build # The "viewer" component is now jfjoch_viewer alone -- rugnux ships as its own artifact # (build:rugnux-tgz) and the two CLI tools are no longer packaged at all. The full tree is - # still built because the viewer links the Rugnux library for its in-process jobs. + # still built because the viewer links the JFJochRugnux library for its in-process jobs. ninja -j16 cpack - name: Upload viewer tgz to release @@ -193,7 +193,7 @@ jobs: python3 gitea_upload_file.py "$tgz" done build-rugnux-tgz: - name: build:rugnux-tgz (x86_64) + name: build:rugnux:linux-x86_64:cuda # Uploads to the release, so it waits for the job that creates it. needs: create-release runs-on: jfjoch_rocky8 @@ -251,7 +251,7 @@ jobs: done build-rugnux-windows: - name: build:rugnux:windows + name: build:rugnux:windows-x86_64:cuda # Uploads to the release, so it waits for the job that creates it. needs: create-release runs-on: windows-11-cuda-qt @@ -296,7 +296,7 @@ jobs: } build-rugnux-arm: - name: build:rugnux:aarch64 (cross) + name: build:rugnux:linux-aarch64:cuda # cross-compiled on x86_64 # Uploads to the release, so it waits for the job that creates it. needs: create-release # Cross-compiled on an x86_64 runner: nvcc, gcc and cmake all run native and only emit aarch64, @@ -377,8 +377,128 @@ jobs: python3 gitea_upload_file.py "$tgz" done + build-macos-viewer: + name: build:viewer:macos-arm64:nocuda + # Uploads to the release, so it waits for the job that creates it. + needs: create-release + # A Mac mini running act_runner in host mode (no containers on macOS): the job runs as the runner's + # user with that user's tools - Xcode command line tools, CMake.app and Qt under ~/Qt - so the + # paths below are this machine's, like the Windows runner's C:/Qt. + runs-on: macos-arm64 + timeout-minutes: 120 + env: + QT_PREFIX: /Users/jungfrau/Qt/6.11.2/macos + steps: + - uses: actions/checkout@v4 + - name: Clean previous build + shell: bash + run: rm -rf build-macos # host runners keep the workspace between runs + - name: Configure viewer build + shell: bash + # JFJOCH_VIEWER_ONLY is forced on macOS. No -mcpu: the arm64 baseline is what every Apple + # Silicon Mac runs, and NEON is part of it. + run: cmake -S . -B build-macos -DCMAKE_BUILD_TYPE=Release -DJFJOCH_USE_CUDA=OFF -DCMAKE_PREFIX_PATH="$QT_PREFIX" + - name: Build viewer and DMG + shell: bash + run: | + cmake --build build-macos -j "$(sysctl -n hw.ncpu)" + cd build-macos && cpack + - name: Verify the bundle is self-contained + shell: bash + run: | + set -euo pipefail + app=$(ls -d build-macos/_CPack_Packages/Darwin/DragNDrop/*/ALL_IN_ONE/jfjoch_viewer.app) + # The frameworks sit in the bundle; the executable must look for them there ... + otool -l "$app/Contents/MacOS/jfjoch_viewer" > /tmp/jfjv.load + if ! grep -q "@executable_path/../Frameworks" /tmp/jfjv.load; then echo "no rpath into the bundle"; exit 1; fi + # ... and nothing in the bundle may point at this machine's Qt (or anything else under /Users) + find "$app" -type f \( -perm +111 -o -name '*.dylib' \) -exec otool -L {} + > /tmp/jfjv.libs 2>/dev/null || true + if grep -q "/Users/" /tmp/jfjv.libs; then grep "/Users/" /tmp/jfjv.libs; echo "absolute path into the build machine"; exit 1; fi + # the (ad-hoc) signature must survive everything installed into the bundle + codesign --verify --deep --strict "$app" + echo "self-contained and validly signed" + # Notarization - needs an Apple Developer ID, which the project does not have yet. Once it + # does, the app has to be signed with it (hardened runtime, secure timestamp) BEFORE cpack + # packs it, e.g. by passing to macdeployqt, through qt_generate_deploy_app_script's + # DEPLOY_TOOL_OPTIONS in viewer/CMakeLists.txt: + # -codesign="Developer ID Application: ()" -hardened-runtime -timestamp + # and the DMG then notarized and stapled here, with an app-specific password stored once on + # the runner (xcrun notarytool store-credentials jfjoch-notary ...): + # xcrun notarytool submit build-macos/jfjoch-viewer-*.dmg --keychain-profile jfjoch-notary --wait + # xcrun stapler staple build-macos/jfjoch-viewer-*.dmg + # Until then a downloaded DMG is blocked by Gatekeeper on first open (right-click > Open). + - name: Upload DMG to release + if: github.event_name == 'workflow_dispatch' && (github.event.inputs.create_release == 'true' || github.event.inputs.create_release == true) + shell: bash + env: + TOKEN: ${{ secrets.PIP_REPOSITORY_API_TOKEN }} + run: | + set -euo pipefail + shopt -s nullglob + # CMakeLists.txt names it jfjoch-viewer--macos-arm64.dmg + files=(build-macos/jfjoch-viewer-*.dmg) + if [ ${#files[@]} -eq 0 ]; then + echo "No DMG found in build-macos/" + exit 1 + fi + for file in "${files[@]}"; do + python3 gitea_upload_file.py "$file" + done + + build-rugnux-macos: + name: build:rugnux:macos-arm64:nocuda + # Uploads to the release, so it waits for the job that creates it. + needs: create-release + runs-on: macos-arm64 # see build-macos-viewer + timeout-minutes: 120 + steps: + - uses: actions/checkout@v4 + - name: Clean previous build + shell: bash + run: rm -rf build-rugnux-macos + - name: Configure rugnux build + shell: bash + run: cmake -S . -B build-rugnux-macos -DJFJOCH_RUGNUX_ONLY=ON -DJFJOCH_USE_CUDA=OFF -DCMAKE_BUILD_TYPE=Release + - name: Build rugnux tgz + shell: bash + run: cmake --build build-rugnux-macos --target package -j "$(sysctl -n hw.ncpu)" + - name: Verify the artifact is self-contained + shell: bash + run: | + set -euo pipefail + rm -rf /tmp/rgxm && mkdir -p /tmp/rgxm + tar xf build-rugnux-macos/rugnux-*.tar.gz -C /tmp/rgxm + bin=$(find /tmp/rgxm -name rugnux -type f) + # Only the system's own libraries may be linked dynamically; everything else is static. + otool -L "$bin" | tail -n +2 > /tmp/rgxm.libs + if grep -v -e "/usr/lib/" -e "/System/Library/" /tmp/rgxm.libs; then echo "links a non-system library"; exit 1; fi + # and it runs: with no arguments rugnux prints its usage + "$bin" > /tmp/rgxm.out 2>&1 || true + if ! grep -qi "usage" /tmp/rgxm.out; then cat /tmp/rgxm.out; echo "rugnux did not start"; exit 1; fi + echo "self-contained and runs" + - name: Upload rugnux tgz to release + if: github.event_name == 'workflow_dispatch' && (github.event.inputs.create_release == 'true' || github.event.inputs.create_release == true) + shell: bash + env: + TOKEN: ${{ secrets.PIP_REPOSITORY_API_TOKEN }} + run: | + set -euo pipefail + shopt -s nullglob + # CMakeLists.txt names it rugnux--macos-arm64-cpu.tar.gz; rename to .tgz before + # upload, as the Linux archives are. + files=(build-rugnux-macos/rugnux-*.tar.gz) + if [ ${#files[@]} -eq 0 ]; then + echo "No rugnux archive found in build-rugnux-macos/" + exit 1 + fi + for file in "${files[@]}"; do + tgz="${file%.tar.gz}.tgz" + mv "$file" "$tgz" + python3 gitea_upload_file.py "$tgz" + done + build-rpm: - name: build:rpm (${{ matrix.distro }}) + name: build:jfjoch:${{ matrix.platform }}:${{ matrix.variant }} # Uploads to the release, so it waits for the job that creates it. needs: create-release runs-on: ${{ matrix.runner }} @@ -391,60 +511,80 @@ jobs: - runner: jfjoch_rocky8 image: gitea.psi.ch/leonarski_f/jfjoch_rocky8:2609 distro: rocky8 + platform: rocky8 + variant: cuda cmake_flags: -DJFJOCH_USE_CUDA=ON pkg_glob: "*.rpm" upload_url: https://gitea.psi.ch/api/packages/mx/rpm/centos/el8/slsdet8-cuda12/upload - runner: jfjoch_rocky8 image: gitea.psi.ch/leonarski_f/jfjoch_rocky8:2609 distro: rocky8_sls9 + platform: rocky8 + variant: cuda-sls9 cmake_flags: -DJFJOCH_USE_CUDA=ON -DSLS9=ON pkg_glob: "*.rpm" upload_url: https://gitea.psi.ch/api/packages/mx/rpm/centos/el8/slsdet9-cuda12/upload - runner: jfjoch_rocky8 image: gitea.psi.ch/leonarski_f/jfjoch_rocky8:2609 distro: rocky8_nocuda + platform: rocky8 + variant: nocuda cmake_flags: -DJFJOCH_USE_CUDA=OFF pkg_glob: "*.rpm" upload_url: https://gitea.psi.ch/api/packages/mx/rpm/centos/el8/slsdet8-nocuda/upload - runner: jfjoch_rocky9 image: gitea.psi.ch/leonarski_f/jfjoch_rocky9:2609 distro: rocky9 + platform: rocky9 + variant: cuda cmake_flags: -DJFJOCH_USE_CUDA=ON pkg_glob: "*.rpm" upload_url: https://gitea.psi.ch/api/packages/mx/rpm/centos/el9/slsdet8-cuda13/upload - runner: jfjoch_rocky9 image: gitea.psi.ch/leonarski_f/jfjoch_rocky9:2609 distro: rocky9_sls9 + platform: rocky9 + variant: cuda-sls9 cmake_flags: -DJFJOCH_USE_CUDA=ON -DSLS9=ON pkg_glob: "*.rpm" upload_url: https://gitea.psi.ch/api/packages/mx/rpm/centos/el9/slsdet9-cuda13/upload - runner: jfjoch_rocky9 image: gitea.psi.ch/leonarski_f/jfjoch_rocky9:2609 distro: rocky9_nocuda + platform: rocky9 + variant: nocuda cmake_flags: -DJFJOCH_USE_CUDA=OFF pkg_glob: "*.rpm" upload_url: https://gitea.psi.ch/api/packages/mx/rpm/centos/el9/slsdet8-nocuda/upload - runner: jfjoch_ubuntu2204 image: gitea.psi.ch/leonarski_f/jfjoch_ubuntu2204:2609 distro: ubuntu2204 + platform: ubuntu2204 + variant: cuda cmake_flags: -DJFJOCH_USE_CUDA=ON pkg_glob: "*.deb" upload_url: https://gitea.psi.ch/api/packages/mx/debian/pool/jammy/cuda13/upload - runner: jfjoch_ubuntu2204 image: gitea.psi.ch/leonarski_f/jfjoch_ubuntu2204:2609 distro: ubuntu2204_nocuda + platform: ubuntu2204 + variant: nocuda cmake_flags: -DJFJOCH_USE_CUDA=OFF pkg_glob: "*.deb" upload_url: https://gitea.psi.ch/api/packages/mx/debian/pool/jammy/nocuda/upload - runner: jfjoch_ubuntu2404 image: gitea.psi.ch/leonarski_f/jfjoch_ubuntu2404:2609 distro: ubuntu2404 + platform: ubuntu2404 + variant: cuda cmake_flags: -DJFJOCH_USE_CUDA=ON pkg_glob: "*.deb" upload_url: https://gitea.psi.ch/api/packages/mx/debian/pool/noble/cuda13/upload - runner: jfjoch_ubuntu2404 image: gitea.psi.ch/leonarski_f/jfjoch_ubuntu2404:2609 distro: ubuntu2404_nocuda + platform: ubuntu2404 + variant: nocuda cmake_flags: -DJFJOCH_USE_CUDA=OFF pkg_glob: "*.deb" upload_url: https://gitea.psi.ch/api/packages/mx/debian/pool/noble/nocuda/upload diff --git a/CLAUDE.md b/CLAUDE.md index 73f61737a..112165816 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -339,7 +339,7 @@ generated API model and internal types. `JFJochImageAnalysis`): - `jfjoch_broker` — online, real-time (FPGA + GPU). - `jfjoch_viewer` — interactive Qt desktop (`viewer/`), results not persisted. -- `rugnux` (`rugnux/rugnux_cli.cpp`, built on the `Rugnux` library in the same directory) — offline +- `rugnux` (`rugnux/rugnux_cli.cpp`, built on the `JFJochRugnux` library in the same directory) — offline batch over a stored HDF5, invoked as `rugnux {} ` (it has **no `--help`**; run it with no arguments to print the usage, which is the authority on its flags). Rotation vs stills is auto-detected from the goniometer axis. Merging is on by default (`--no-merge` to disable); diff --git a/CMakeLists.txt b/CMakeLists.txt index d01f22eff..33fd421d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,9 +9,10 @@ FILE(STRINGS VERSION JFJOCH_VERSION) STRING(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" JFJOCH_VERSION_NUMERIC "${JFJOCH_VERSION}") # Oldest macOS the binaries run on (ignored elsewhere). Without it CMake takes the version of the -# build machine, and a .dmg would refuse to start on anything older. 12 is the floor of current Qt 6; +# build machine, and a .dmg would refuse to start on anything older. 13 is what the Qt the .dmg +# bundles (6.11) is built for, so a lower value only makes the linker warn about every framework; # our own needs (, ) stop at 11. Has to be set before PROJECT(). -SET(CMAKE_OSX_DEPLOYMENT_TARGET "12.0" CACHE STRING "Minimum macOS version") +SET(CMAKE_OSX_DEPLOYMENT_TARGET "13.0" CACHE STRING "Minimum macOS version") PROJECT(jfjoch VERSION ${JFJOCH_VERSION_NUMERIC} LANGUAGES C CXX) SET(CMAKE_POLICY_DEFAULT_CMP0077 NEW) @@ -401,13 +402,12 @@ SET(ENABLE_FLOAT ON CACHE BOOL "" FORCE) SET(BUILD_TESTS OFF CACHE BOOL "" FORCE) # SIMD codelets are runtime-dispatched (cpuid), so enabling AVX2 does NOT require an AVX2 CPU # -- FFTW falls back at runtime. The codelet sets are arch-specific, so guard by processor: -# x86 gets SSE2/AVX/AVX2, aarch64 (e.g. Grace on DGX Spark) gets NEON; other arches build scalar. +# x86 gets SSE2/AVX/AVX2, aarch64 (Apple Silicon, Grace on DGX Spark) gets NEON - added below the +# FetchContent, as FFTW's CMake build has no switch for it; other arches build scalar. IF (CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64|amd64") SET(ENABLE_SSE2 ON CACHE BOOL "" FORCE) SET(ENABLE_AVX ON CACHE BOOL "" FORCE) SET(ENABLE_AVX2 ON CACHE BOOL "" FORCE) -ELSEIF (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64") - SET(ENABLE_NEON ON CACHE BOOL "" FORCE) ENDIF() FetchContent_Declare(fftw URL https://www.fftw.org/fftw-3.3.10.tar.gz @@ -418,6 +418,19 @@ FetchContent_MakeAvailable(fftw) # the build tree (FetchContent) leaves the header unreachable. On Linux a system-installed # fftw3.h masks this; on Windows it does not. Add the source-tree api/ dir for build-tree use. TARGET_INCLUDE_DIRECTORIES(fftw3f INTERFACE $) +# NEON: only FFTW's autotools build knows it (--enable-neon); its CMake build silently builds scalar +# code on ARM (and ignores an ENABLE_NEON, as this file once set). So the NEON codelets are added +# the way its CMakeLists adds the SSE2/AVX ones: the sources, and HAVE_NEON so that dft/conf.c and +# rdft/conf.c register them - as a definition, because its config.h template carries HAVE_NEON only +# as a comment. NEON is part of every aarch64 CPU, so no compiler flag is needed. It is single +# precision, which is all that is built here. Measured on Apple Silicon against the scalar build +# (same results to 1e-8): the indexer's batched 1D r2c 1.8x faster at a power-of-two length and 1.3x +# at 730, the 2D r2c of the beam-centre search 1.9x, a 128^3 c2r map 2.6x. +IF (CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|arm64|ARM64") + FILE(GLOB _fftw_neon_sources ${fftw_SOURCE_DIR}/dft/simd/neon/*.c ${fftw_SOURCE_DIR}/rdft/simd/neon/*.c) + TARGET_SOURCES(fftw3f PRIVATE ${_fftw_neon_sources}) + TARGET_COMPILE_DEFINITIONS(fftw3f PRIVATE HAVE_NEON=1) +ENDIF() ADD_COMPILE_DEFINITIONS(JFJOCH_USE_FFTW) # Eigen (header-only), consumed by the analysis libraries directly and by Ceres and ffbidx through @@ -520,6 +533,13 @@ IF (JFJOCH_VIEWER_BUILD OR JFJOCH_VIEWER_ONLY) ENDIF() ENDIF() +# The notices every package ships (installed at the end of this file). Set before the subdirectories +# because the macOS viewer puts them into its .app bundle itself - see viewer/CMakeLists.txt. +SET(JFJOCH_NOTICE_FILES + ${CMAKE_SOURCE_DIR}/LICENSE + ${CMAKE_SOURCE_DIR}/THIRD_PARTY_NOTICES.md + ${CMAKE_SOURCE_DIR}/docs/ACKNOWLEDGEMENT.md) + IF (JFJOCH_RUGNUX_ONLY) # The viewer-only subtree minus viewer/ and tools/: just rugnux and what it links. broker/ is # here for JFJochAPI alone (JFJochReader links it); its service targets are gated out. preview/ @@ -665,8 +685,11 @@ set(CPACK_PACKAGE_VERSION ${JFJOCH_VERSION}) # OS-aware packaging: DragNDrop (.dmg) on macOS, NSIS installer on Windows, DEB on Debian/Ubuntu, # RPM on RHEL/Rocky. macOS/Windows are checked first because the /etc/* probes below are Linux-only. if (APPLE AND NOT JFJOCH_RUGNUX_ONLY) - # .dmg containing jfjoch_viewer.app (Qt runtime already deployed into the bundle). + # .dmg containing jfjoch_viewer.app (Qt runtime already deployed into the bundle). Named like the + # Windows and Linux artifacts; CMAKE_SYSTEM_PROCESSOR is arm64 on Apple Silicon. set(CPACK_GENERATOR "DragNDrop") + set(CPACK_PACKAGE_FILE_NAME "jfjoch-viewer-${JFJOCH_VERSION}-macos-${CMAKE_SYSTEM_PROCESSOR}") + set(CPACK_DMG_VOLUME_NAME "Jungfraujoch Viewer ${JFJOCH_VERSION}") elseif (WIN32 AND NOT JFJOCH_RUGNUX_ONLY) # NSIS installer .exe (Qt runtime deployed next to the binary by windeployqt). set(CPACK_GENERATOR "NSIS") @@ -743,10 +766,16 @@ elseif (JFJOCH_VIEWER_ONLY OR JFJOCH_RUGNUX_ONLY) set(_jfjoch_tgz_name "jfjoch_viewer") set(_jfjoch_tgz_arch "") endif() - if (JFJOCH_CUDA_AVAILABLE) - set(CPACK_PACKAGE_FILE_NAME "${_jfjoch_tgz_name}-${JFJOCH_VERSION}-linux${_jfjoch_tgz_arch}-cuda${CUDAToolkit_VERSION_MAJOR}") + # A rugnux-only build is the one portable product that also packs as .tgz on macOS. + if (APPLE) + set(_jfjoch_tgz_os "macos") else() - set(CPACK_PACKAGE_FILE_NAME "${_jfjoch_tgz_name}-${JFJOCH_VERSION}-linux${_jfjoch_tgz_arch}-cpu") + set(_jfjoch_tgz_os "linux") + endif() + if (JFJOCH_CUDA_AVAILABLE) + set(CPACK_PACKAGE_FILE_NAME "${_jfjoch_tgz_name}-${JFJOCH_VERSION}-${_jfjoch_tgz_os}${_jfjoch_tgz_arch}-cuda${CUDAToolkit_VERSION_MAJOR}") + else() + set(CPACK_PACKAGE_FILE_NAME "${_jfjoch_tgz_name}-${JFJOCH_VERSION}-${_jfjoch_tgz_os}${_jfjoch_tgz_arch}-cpu") endif() elseif (EXISTS "/etc/debian_version") set(CPACK_PACKAGE_LICENSE "GPL-3.0-only") @@ -865,11 +894,10 @@ endif() # and leaving the main package on the old shared path would keep blocking it for anyone # upgrading from a release that still had the collision. These notices were the only files any # two components had in common. -SET(JFJOCH_NOTICE_FILES - ${CMAKE_SOURCE_DIR}/LICENSE - ${CMAKE_SOURCE_DIR}/THIRD_PARTY_NOTICES.md - ${CMAKE_SOURCE_DIR}/docs/ACKNOWLEDGEMENT.md) FOREACH(_component IN LISTS CPACK_COMPONENTS_ALL) + IF (APPLE AND _component STREQUAL "viewer") + CONTINUE() # inside the .app bundle instead, see viewer/CMakeLists.txt + ENDIF() IF (_component STREQUAL "jfjoch") SET(_suffix broker) ELSE() diff --git a/common/ParallelFor.h b/common/ParallelFor.h index 498e01cf3..a06a3a930 100644 --- a/common/ParallelFor.h +++ b/common/ParallelFor.h @@ -41,7 +41,7 @@ namespace parallel_detail { // True on a thread the pool owns. A parallel pass reached from inside one runs inline instead // of queueing: the workers are already occupied by the outer pass, so waiting for one of them // to pick up the inner work could wait forever. - static bool InWorker() { return in_worker; } + static bool InWorker() { return InWorkerFlag(); } size_t WorkerCount() const { return workers.size(); } @@ -58,7 +58,7 @@ namespace parallel_detail { const unsigned hw = std::max(1u, std::thread::hardware_concurrency()); workers.reserve(hw - 1); for (unsigned i = 0; i + 1 < hw; i++) // the submitting thread takes a share too - workers.emplace_back([this] { in_worker = true; Loop(); }); + workers.emplace_back([this] { InWorkerFlag() = true; Loop(); }); } ~WorkerPool() { @@ -89,10 +89,14 @@ namespace parallel_detail { std::deque > queue; std::vector workers; bool stop = false; - static thread_local bool in_worker; - }; - inline thread_local bool WorkerPool::in_worker = false; + // A function-local thread_local rather than an inline static member: Apple's linker rejects the + // TLS wrapper clang emits for the latter as a duplicate symbol once two libraries include this. + static bool &InWorkerFlag() { + static thread_local bool in_worker = false; + return in_worker; + } + }; // What the tasks of one pass share: the body to call, how many of them are still outstanding, and // the first exception any of them threw. diff --git a/docs/DEPLOYMENT.md b/docs/DEPLOYMENT.md index 219247224..b9f1872be 100644 --- a/docs/DEPLOYMENT.md +++ b/docs/DEPLOYMENT.md @@ -167,6 +167,9 @@ cmake -DJFJOCH_VIEWER_BUILD=ON -DCMAKE_INSTALL_PREFIX= .. make jfjoch_viewer ``` +Pre-built viewers for Windows and macOS, and a portable Linux archive, are on the Gitea release +page — see [Release contents](RELEASE_CONTENTS.md) and [jfjoch_viewer](JFJOCH_VIEWER.md). + ## Install Jungfraujoch Python client Use pip: @@ -196,5 +199,5 @@ tar xzf rugnux--linux-x86_64-cuda12.tgz -C /opt/rugnux- ``` The archive has no top-level directory, so the `-C` is required. See -[Installing Rugnux](RUGNUX_INSTALL.md) for the Arm and Windows archives, the driver +[Installing Rugnux](RUGNUX_INSTALL.md) for the Arm, Windows and macOS archives, the driver versions and building from source. \ No newline at end of file diff --git a/docs/JFJOCH_VIEWER.md b/docs/JFJOCH_VIEWER.md index 8695453fd..abf3663b3 100644 --- a/docs/JFJOCH_VIEWER.md +++ b/docs/JFJOCH_VIEWER.md @@ -5,10 +5,13 @@ datasets, displays each image together with the analysis overlay (spots, predict integration, per-image statistics), and can follow a live data collection by syncing with a running [`jfjoch_broker`](JFJOCH_BROKER.md) over its HTTP interface. -It is a standalone Qt 6 application, distributed pre-built for **Linux and Windows** on the Gitea -release page and in the Jungfraujoch RPM/APT repositories — see [Release contents](RELEASE_CONTENTS.md) -for what each package contains and what it requires, and [Deployment](DEPLOYMENT.md) for how to -install it. +It is a standalone Qt 6 application, distributed pre-built for **Linux, Windows and macOS** on the +Gitea release page, and for Linux also in the Jungfraujoch RPM/APT repositories — see +[Release contents](RELEASE_CONTENTS.md) for what each package contains and what it requires, and +[Deployment](DEPLOYMENT.md) for how to install it. The macOS build needs **macOS 13 (Ventura) or +newer on an Apple Silicon Mac** (M1 and newer; Intel Macs are not supported) and is CPU-only — see +[Release contents ▸ macOS](RELEASE_CONTENTS.md#macos), which also covers opening it for the first +time, as the release is not yet notarized by Apple. ## Where it fits among the three analysis tools @@ -92,6 +95,9 @@ installer and the `.tgz` are CUDA 13 and CUDA 12 respectively, which also decide they run on — a V100 needs the CUDA 12 `.tgz`. See [Release contents ▸ GPU generations and the NVIDIA driver](RELEASE_CONTENTS.md#gpu-generations-and-the-nvidia-driver). +On a Mac there is no CUDA: the viewer always runs the same pipeline on the CPU, with the FFTW +indexer, like the non-CUDA build elsewhere. + ### Remote displays The viewer detects a remote display session (`ssh -X` and the like) and limits how often panning, @@ -154,7 +160,8 @@ The same list is available in the application under **Help ▸ Mouse Shortcuts** ## D-Bus interface When enabled, the viewer registers the D-Bus interface `ch.psi.jfjoch_viewer`, so other processes -can drive it: +can drive it. D-Bus is **Linux only**: the Windows and macOS builds have no D-Bus interface, and +`--dbus` has no effect there. - `LoadFile(filename, image_number=0, summation=1)` — open a file (or an `http://host:port` URL) and display the given image. @@ -167,8 +174,8 @@ it needs no filename and avoids the file-identity comparison. ## Building from source on Windows -`jfjoch_viewer` is the one Jungfraujoch component that is cross-platform: it builds on Windows 11 -with MSVC and the full CUDA GPU path. (The rest of Jungfraujoch — broker, receiver, FPGA host — is +`jfjoch_viewer` is cross-platform: it builds on Windows 11 with MSVC and the full CUDA GPU path, and +on macOS (see [below](#building-from-source-on-macos)). (The rest of Jungfraujoch — broker, receiver, FPGA host — is Linux-only.) A pre-built installer is published with every release, so building from source is only needed to develop or to change the build options. On Windows the build is automatically restricted to the viewer and the libraries it needs (`JFJOCH_VIEWER_ONLY` is forced on), and the remaining @@ -216,3 +223,29 @@ cpack The NSIS generator is selected automatically on Windows (no `-G` needed). What comes out, and how the CUDA and CPU variants are named and told apart, is described in [Release contents ▸ Windows installer](RELEASE_CONTENTS.md#windows-installer). + +## Building from source on macOS + +The viewer also builds on macOS, **Apple Silicon only** and without CUDA; as on Windows, the build +is automatically restricted to the viewer and the libraries it needs (`JFJOCH_VIEWER_ONLY` is forced +on) and fetches every other dependency itself. A pre-built disk image is published with every +release, so building from source is only needed to develop or to change the build options. + +Verified toolchain — the same one the released `.dmg` is built with: + +- An Apple Silicon Mac; the resulting app needs macOS 13 or newer, whatever the build machine runs +- Xcode (Apple Clang) +- Qt 6.11 for macOS, including the **Qt Charts** module — e.g. `~/Qt/6.11.2/macos` from the Qt + online installer +- CMake (e.g. `CMake.app` from cmake.org, with `/Applications/CMake.app/Contents/bin` on `PATH`) + +``` +cmake -S . -B build-mac -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$HOME/Qt/6.11.2/macos +cmake --build build-mac -j$(sysctl -n hw.ncpu) --target jfjoch_viewer +open build-mac/viewer/jfjoch_viewer.app +``` + +As on Windows, `CMAKE_PREFIX_PATH` (Qt) is the only required flag. To produce the disk image — the +Qt frameworks and the license notices copied into the app with `macdeployqt`, packed into +`jfjoch-viewer--macos-arm64.dmg` — run `cpack` in the build directory. What comes out is +described in [Release contents ▸ macOS](RELEASE_CONTENTS.md#macos). diff --git a/docs/RELEASE_CONTENTS.md b/docs/RELEASE_CONTENTS.md index 75129bb79..528d90f65 100644 --- a/docs/RELEASE_CONTENTS.md +++ b/docs/RELEASE_CONTENTS.md @@ -16,9 +16,11 @@ result see [Deployment](DEPLOYMENT.md); for the package-repository URLs see | `.rpm` / `.deb` packages | [package repositories](REPOSITORIES.md) | The full server stack: `jfjoch` (broker, frontend, FPGA and detector tools), `jfjoch-writer`, `jfjoch-viewer` (incl. the XDS plugin), `jfjoch-driver-dkms`, and `rugnux` (offline analysis, independent of the rest) | | `jfjoch_viewer--linux-cuda.tgz`, `...-linux-cpu.tgz` | Gitea release page | Portable Linux viewer: `jfjoch_viewer`, its desktop entry, icon and D-Bus service, and the license notices | | `jfjoch-viewer--win64-cuda.exe`, `...-win64-cpu.exe` | Gitea release page | Windows installer for `jfjoch_viewer`, plus the Qt runtime | +| `jfjoch-viewer--macos-arm64.dmg` | Gitea release page | macOS disk image with `jfjoch_viewer.app` (Apple Silicon), the Qt runtime and the license notices inside the app | | `rugnux--linux-x86_64-cuda.tgz` | Gitea release page | Portable Linux [`rugnux`](RUGNUX.md), the offline analysis CLI, and the license notices. One executable | | `rugnux--linux-aarch64-cuda.tgz` | Gitea release page | The same, cross-built for 64-bit Arm — NVIDIA GH200 and DGX Spark | | `rugnux--win64-cuda.zip` | Gitea release page | The same for Windows, plus the cuFFT DLL | +| `rugnux--macos-arm64-cpu.tgz` | Gitea release page | The same for macOS on Apple Silicon, CPU only | | `jfjoch-writer` `.rpm` / `.deb` | Gitea release page | The writer alone, for a file-writing machine without the rest of the stack | | `libjfjoch_xds_plugin.so.` | Gitea release page | XDS HDF5 read plugin (built on RHEL 8); see [Integration with MX software](SOFTWARE_INTEGRATION.md) | | `jfjoch-client` | [PyPI](https://pypi.org/project/jfjoch-client/) and the Gitea PyPI index | Generated Python OpenAPI client | @@ -39,11 +41,13 @@ baseline the compiler defaults to). The released binaries are compiled to a fixe | --- | --- | --- | | Linux (all packages, and the portable `.tgz`) | `-march=x86-64-v3 -flto=auto` | AVX2 + FMA + BMI2 — Intel Haswell (2013) / AMD Zen (2017) and newer | | Windows installer | `/arch:AVX` | AVX — Intel Sandy Bridge (2011) / AMD Bulldozer and newer | +| macOS `.dmg` and `rugnux` `.tgz` | none (the compiler's default Apple Silicon target) | Any Apple Silicon Mac — M1 and newer | The Windows floor is lower because MSVC has no spelling for the `x86-64-v2` level; `/arch:AVX` is the nearest one and implies SSE4.1/4.2, which is what actually matters — without it Eigen has no vectorised `round` and falls back to a libm call per element. Link-time optimisation is applied on -Linux only. +Linux only. The macOS artefacts need no flag: the Apple compiler's default target is already the +M1, the oldest Apple Silicon chip. A binary will fault with an illegal instruction on a CPU below its floor. If you must run on older hardware, build from source without the flags. @@ -56,7 +60,9 @@ RHEL 8, the oldest supported distribution, so their glibc floor is low enough to Linux — that is what they are for, and why they replace the per-distro packaging of those programs on the release page. The **aarch64** `rugnux` `.tgz` is the exception: it is cross-built against Ubuntu 24.04, so it needs glibc 2.39 or newer (which DGX OS 7 and any current Arm server distribution -have). The Windows installer is built and verified on Windows 11. +have). The Windows installer is built and verified on Windows 11. The macOS artefacts need +**macOS 13 (Ventura) or newer** — the floor of the Qt 6.11 they bundle — and an **Apple Silicon** +Mac; see [macOS](#macos) below. **The portable archives have no top-level directory.** They unpack straight into `bin/` and `share/`, so always extract them into a directory of their own (`tar xzf … -C /opt/rugnux-`) @@ -64,7 +70,8 @@ rather than into a working directory. ## CUDA and non-CUDA builds -Every binary artefact is released in **two variants**, `cuda` and `cpu`. The CUDA variant adds +Every Linux and Windows binary artefact is released in **two variants**, `cuda` and `cpu` +(the macOS ones exist only as `cpu`: there is no CUDA on macOS). The CUDA variant adds the GPU fast-feedback indexer (`ffbidx`), the GPU FFT indexer and GPU image processing; the CPU-only variant runs the same pipeline on the CPU with the FFTW indexer, at much lower throughput. @@ -103,7 +110,7 @@ is no CUDA-toolkit version requirement on the host. | RHEL 8 packages, portable viewer `.tgz`, x86_64 `rugnux` `.tgz` | 12.9 | Volta (V100) through Blackwell: `sm_70`, `75`, `80`, `86`, `89`, `90`, `100`, `120`, `121` | 525.60.13 | | RHEL 9 and Ubuntu packages, Windows installer, Windows `rugnux` `.zip` | 13.x | Turing (T4) through Blackwell: the same list **without** `sm_70` | 580.65.06 (Linux), R580 (Windows) | | aarch64 `rugnux` `.tgz` | 13.x | `sm_90` (GH200) and `sm_121` (DGX Spark) only | 580.65.06 | -| any `cpu` / `nocuda` variant | — | — | none | +| any `cpu` / `nocuda` variant, and everything for macOS | — | — | none | The aarch64 build is cross-compiled and verified in CI to be Arm, self-contained and to carry both GPU targets, but it is **not exercised on hardware** — CI has no GH200 or Spark runner. @@ -151,10 +158,42 @@ superset); they are told apart by the installer filename and the Add/Remove Prog To build the viewer yourself on Windows, see [jfjoch_viewer ▸ Building from source on Windows](JFJOCH_VIEWER.md#building-from-source-on-windows). +## macOS + +The macOS artefacts are the `jfjoch_viewer` disk image and the `rugnux` `.tgz`; as on Windows, the +rest of Jungfraujoch is Linux-only. Both are **CPU-only** — macOS has no CUDA, so indexing uses the +FFTW indexer and the whole pipeline runs on the CPU — and both are built for **Apple Silicon only**. +They need **macOS 13 (Ventura) or newer**. + +**Intel Macs are not supported.** No Intel (`x86_64`) code is built for macOS, and Rosetta cannot +help here: it runs Intel programs on Apple Silicon, not the other way round. + +`jfjoch-viewer--macos-arm64.dmg` holds `jfjoch_viewer.app`; open the image and drag the +app onto the *Applications* shortcut next to it. The app is self-contained: the Qt frameworks are +inside it, and so are the license notices (`Contents/Resources`), which is where a macOS app keeps +them. + +**The release is not notarized yet** (that needs an Apple Developer account), so macOS refuses to +open a downloaded copy the first time. On macOS 15 and newer: try to open it once, then allow it in +*System Settings ▸ Privacy & Security* with *Open Anyway*. On macOS 13 and 14, Control-click the app +and choose *Open*. Alternatively, clear the download flag in Terminal: + +``` +xattr -dr com.apple.quarantine /Applications/jfjoch_viewer.app +``` + +The same applies to the `rugnux` binary from the `.tgz` — see +[Installing Rugnux](RUGNUX_INSTALL.md#from-the-release-archive). + +The toolchain of the released macOS artefacts is Xcode (Apple Clang) and Qt 6.11 for macOS, +including Qt Charts; to build the viewer yourself see +[jfjoch_viewer ▸ Building from source on macOS](JFJOCH_VIEWER.md#building-from-source-on-macos). + ## Licenses Every package variant carries the project license, the third-party manifest and the verbatim license texts of the bundled dependencies, each package under a directory of its own — `share/doc/jfjoch_broker`, `jfjoch_writer`, `jfjoch_viewer`, `jfjoch_rugnux`, `jfjoch_driver_dkms` — -so that no two packages claim the same path and they can be upgraded independently. See +so that no two packages claim the same path and they can be upgraded independently. The macOS +viewer is the exception: its notices are inside the app, in `jfjoch_viewer.app/Contents/Resources`. See [Third-party software notices](THIRD_PARTY_NOTICES.md). diff --git a/docs/RUGNUX_INSTALL.md b/docs/RUGNUX_INSTALL.md index 15f40fca7..c99316c27 100644 --- a/docs/RUGNUX_INSTALL.md +++ b/docs/RUGNUX_INSTALL.md @@ -30,14 +30,15 @@ detector libraries, no Qt — so it can go on a machine that only processes data ## From the release archive -For a machine no package manager covers — or for Windows and Arm, which have no repository — take -the archive for your architecture from the Gitea release page: +For a machine no package manager covers — or for Windows, macOS and Arm, which have no repository — +take the archive for your architecture from the Gitea release page: | Archive | For | | --- | --- | | `rugnux--linux-x86_64-cuda12.tgz` | 64-bit Intel/AMD Linux. Built on RHEL 8, so it runs on any newer Linux | | `rugnux--linux-aarch64-cuda13.tgz` | 64-bit Arm Linux — NVIDIA GH200 and DGX Spark. Built on Ubuntu 24.04, so it needs glibc 2.39 or newer. Cross-compiled and **not yet exercised on Arm hardware** | | `rugnux--win64-cuda13.zip` | 64-bit Windows | +| `rugnux--macos-arm64-cpu.tgz` | macOS 13 (Ventura) or newer on Apple Silicon (M1 and newer). CPU only — there is no CUDA on macOS. Intel Macs are not supported | **The archive has no top-level directory** — it unpacks straight into `bin/` and `share/`. Always give `tar` a destination of its own, or it will scatter those into whatever directory you are in: @@ -61,13 +62,26 @@ Nothing is written outside that directory, nothing needs root, and several versi side. To remove it, delete the directory. Put `bin/` on your `PATH` if you want to type `rugnux` rather than the full path. +> **macOS: the first run is blocked.** The release is not yet notarized by Apple, and a `.tgz` +> downloaded with a browser hands its download flag on to everything `tar` extracts from it, so +> macOS refuses to run `rugnux` ("cannot be opened because the developer cannot be verified"). Clear +> the flag once for the whole directory: +> +> ``` +> xattr -dr com.apple.quarantine ~/rugnux-1.0.0 +> ``` +> +> An archive fetched with `curl` carries no such flag. Unpacking into a directory under your home +> directory (`~/rugnux-`) rather than `/opt` avoids needing `sudo` on a Mac. + > **Mixing the two.** If a `rugnux` package is also installed, `/usr/bin/rugnux` will normally win > on `PATH`. Put the archive's `bin/` first, or call it by its full path, to be sure which one you > are running — `rugnux` prints its version on every run. ## GPU support -The released archives are CUDA builds. They need only an NVIDIA **driver** on the host — 525.60.13 +The released Linux and Windows archives are CUDA builds (the macOS one is CPU-only). They need only +an NVIDIA **driver** on the host — 525.60.13 or newer for the CUDA 12 archive, 580.65.06 or newer for the CUDA 13 ones — and no CUDA toolkit, because everything CUDA is linked statically. With no GPU or no driver, `rugnux` reports zero CUDA devices and falls back to the CPU path, which works but is far slower and offers only the `fftw` @@ -90,6 +104,10 @@ is downloaded and built during the first configure, which therefore needs networ build system on purpose, so a plain build is slower than the released one on the CPU-bound stages — see the note in `CMakeLists.txt`. +On a Mac (Apple Silicon), leave the two `-march` flags out — they name an x86 level; the Apple +compiler's default target is already the M1 — and use `sysctl -n hw.ncpu` for the job count. The +build has no CUDA there and needs nothing installed beyond Xcode and CMake. + ## Hardware As with the rest of Jungfraujoch, **serious performance requires an NVIDIA GPU**. The CUDA build diff --git a/rugnux/CMakeLists.txt b/rugnux/CMakeLists.txt index 569fc7d16..bdc15301c 100644 --- a/rugnux/CMakeLists.txt +++ b/rugnux/CMakeLists.txt @@ -1,7 +1,7 @@ # SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute # SPDX-License-Identifier: GPL-3.0-only -ADD_LIBRARY(Rugnux STATIC +ADD_LIBRARY(JFJochRugnux STATIC Rugnux.cpp RugnuxDefaults.cpp RugnuxDefaults.h @@ -35,12 +35,12 @@ ADD_LIBRARY(Rugnux STATIC WriteModel.h ) -TARGET_LINK_LIBRARIES(Rugnux JFJochReader JFJochImageAnalysis JFJochWriter JFJochPreview gemmi fftw3f) +TARGET_LINK_LIBRARIES(JFJochRugnux JFJochReader JFJochImageAnalysis JFJochWriter JFJochPreview gemmi fftw3f) # rugnux is the single offline analysis CLI; --mode picks what it does: mx (the full pipeline, the # default), azint, scale (re-scale/merge stored reflections) or calibration (powder-ring geometry). ADD_EXECUTABLE(rugnux rugnux_cli.cpp) -TARGET_LINK_LIBRARIES(rugnux Rugnux JFJochReader JFJochImageAnalysis JFJochWriter) +TARGET_LINK_LIBRARIES(rugnux JFJochRugnux JFJochReader JFJochImageAnalysis JFJochWriter) INSTALL(TARGETS rugnux RUNTIME COMPONENT rugnux) # libcufft_static.a carries a relocatable-device-code object (separate_callback.o), so an executable diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 78ee3427f..5990ac1f8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -126,7 +126,7 @@ ADD_EXECUTABLE(jfjoch_test ) target_link_libraries(jfjoch_test Catch2WithMain JFJochBroker JFJochReceiver JFJochReader JFJochStreamWriter - Rugnux JFJochImageAnalysis JFJochCommon JFJochHLSSimulation JFJochPreview + JFJochRugnux JFJochImageAnalysis JFJochCommon JFJochHLSSimulation JFJochPreview jfjoch_xds_plugin ZLIB::ZLIB) target_include_directories(jfjoch_test PRIVATE .) diff --git a/viewer/CMakeLists.txt b/viewer/CMakeLists.txt index 8affac6ea..b2c36913b 100644 --- a/viewer/CMakeLists.txt +++ b/viewer/CMakeLists.txt @@ -25,6 +25,8 @@ ADD_EXECUTABLE(jfjoch_viewer jfjoch_viewer.cpp JFJochViewerWindow.cpp JFJochView JFJochViewerMenu.h RemoteDisplayMode.cpp RemoteDisplayMode.h + ViewerTheme.cpp + ViewerTheme.h image_viewer/JFJochDiffractionImage.cpp image_viewer/JFJochDiffractionImage.h image_viewer/JFJochSimpleImage.cpp @@ -119,7 +121,7 @@ ADD_EXECUTABLE(jfjoch_viewer jfjoch_viewer.cpp JFJochViewerWindow.cpp JFJochView ) TARGET_LINK_LIBRARIES(jfjoch_viewer Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Charts Qt6::Concurrent - JFJochReader JFJochLogger JFJochCommon JFJochWriter JFJochImageAnalysis Rugnux + JFJochReader JFJochLogger JFJochCommon JFJochWriter JFJochImageAnalysis JFJochRugnux fftw3f libcurl_static) # vendored static libcurl by concrete name, not the CURL::libcurl # alias, which a system libcurl can shadow (see top-level CMakeLists) @@ -138,12 +140,38 @@ ELSEIF(APPLE) TARGET_SOURCES(jfjoch_viewer PRIVATE ${_viewer_icns}) SET_SOURCE_FILES_PROPERTIES(${_viewer_icns} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) SET_TARGET_PROPERTIES(jfjoch_viewer PROPERTIES MACOSX_BUNDLE_ICON_FILE jfjoch.icns) + # Info.plist identity. Notarization needs the identifier; the short version must be numeric, so + # the release-candidate suffix goes into the long version string (Finder's Get Info). The bundle + # name is what the macOS menu bar shows, and matches the Qt application name. + SET_TARGET_PROPERTIES(jfjoch_viewer PROPERTIES + MACOSX_BUNDLE_GUI_IDENTIFIER ch.psi.jfjoch.viewer + MACOSX_BUNDLE_BUNDLE_NAME "JFJoch Viewer" + MACOSX_BUNDLE_SHORT_VERSION_STRING ${JFJOCH_VERSION_NUMERIC} + MACOSX_BUNDLE_BUNDLE_VERSION ${JFJOCH_VERSION_NUMERIC} + MACOSX_BUNDLE_LONG_VERSION_STRING ${JFJOCH_VERSION} + MACOSX_BUNDLE_COPYRIGHT "Copyright (C) 2019-2026 Paul Scherrer Institute") + # Qt links as @rpath/Qt*.framework and the deploy step below copies the frameworks into the + # bundle's Frameworks folder; without this rpath the installed app (and the .dmg) cannot find + # them - install strips the build tree's rpath and leaves the executable with none. + SET_TARGET_PROPERTIES(jfjoch_viewer PROPERTIES INSTALL_RPATH "@executable_path/../Frameworks") ENDIF() INSTALL(TARGETS jfjoch_viewer BUNDLE DESTINATION . COMPONENT viewer # macOS .app bundle RUNTIME DESTINATION bin COMPONENT viewer) # Windows .exe / Linux binary +# On macOS the notices go inside the bundle: a user drags only the .app out of the .dmg, so anything +# beside it is left behind. They must be installed before the Qt deploy script below, which signs +# the bundle - a file added after the signature invalidates it. (Other platforms install them into +# share/doc/jfjoch_viewer at the end of the top-level CMakeLists.txt.) +IF(APPLE) + INSTALL(FILES ${JFJOCH_NOTICE_FILES} + DESTINATION jfjoch_viewer.app/Contents/Resources COMPONENT viewer) + INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/licenses/ + DESTINATION jfjoch_viewer.app/Contents/Resources/licenses COMPONENT viewer + PATTERN "COLLECT.sh" EXCLUDE) +ENDIF() + # libcufft_static.a carries a relocatable-device-code object (separate_callback.o), so an executable # linking it needs a CUDA device-link step -- without it the host link fails on an undefined # __cudaRegisterLinkedBinary_* symbol. CUDA 13 no longer ships libcufft_static_nocallback.a, which diff --git a/viewer/JFJochViewerMenu.cpp b/viewer/JFJochViewerMenu.cpp index 60f5cf129..c45523c14 100644 --- a/viewer/JFJochViewerMenu.cpp +++ b/viewer/JFJochViewerMenu.cpp @@ -3,6 +3,7 @@ #include "JFJochViewerMenu.h" #include "RemoteDisplayMode.h" +#include "ViewerTheme.h" #include #include @@ -90,6 +91,25 @@ JFJochViewerMenu::JFJochViewerMenu(QWidget *parent) : QMenuBar(parent) { remoteMode->setChecked(RemoteDisplayMode()); connect(remoteMode, &QAction::toggled, this, [](bool on) { SetRemoteDisplayMode(on); }); + viewMenu->addSeparator(); + QMenu *themeMenu = viewMenu->addMenu("Theme"); + auto *themeGroup = new QActionGroup(this); + const ThemeChoice currentTheme = LoadThemeChoice(); + const std::pair themes[] = {{ThemeChoice::System, "Follow system"}, + {ThemeChoice::Light, "Light"}, + {ThemeChoice::Dark, "Dark"}}; + for (const auto &theme: themes) { + const ThemeChoice choice = theme.first; + QAction *action = themeMenu->addAction(theme.second); + action->setCheckable(true); + action->setChecked(choice == currentTheme); + themeGroup->addAction(action); + connect(action, &QAction::triggered, this, [choice] { SetThemeChoice(choice); }); + // The display toolbar switches the theme too; keep the tick on the choice in force. + connect(ThemeNotifier::Instance(), &ThemeNotifier::changed, action, + [action, choice] { action->setChecked(LoadThemeChoice() == choice); }); + } + viewMenu->addSeparator(); // The desktop's own text scaling stays the primary mechanism, but few users know where it lives, // so the viewer carries a zoom of its own. It multiplies the font the desktop handed us, so it @@ -100,11 +120,11 @@ JFJochViewerMenu::JFJochViewerMenu(QWidget *parent) : QMenuBar(parent) { fontLarger->setShortcuts({QKeySequence::ZoomIn, QKeySequence(Qt::ControlModifier | Qt::Key_Equal), QKeySequence(Qt::ControlModifier | Qt::KeypadModifier | Qt::Key_Plus)}); - connect(fontLarger, &QAction::triggered, this, [this] { ApplyFontZoom(fontZoom + 25); }); + connect(fontLarger, &QAction::triggered, this, [this] { SetFontZoom(fontZoom + 25); }); QAction *fontSmaller = fontMenu->addAction("Smaller"); fontSmaller->setShortcuts({QKeySequence::ZoomOut, QKeySequence(Qt::ControlModifier | Qt::KeypadModifier | Qt::Key_Minus)}); - connect(fontSmaller, &QAction::triggered, this, [this] { ApplyFontZoom(fontZoom - 25); }); + connect(fontSmaller, &QAction::triggered, this, [this] { SetFontZoom(fontZoom - 25); }); fontMenu->addSeparator(); fontZoomGroup = new QActionGroup(this); for (int percent: {100, 125, 150}) { @@ -112,9 +132,9 @@ JFJochViewerMenu::JFJochViewerMenu(QWidget *parent) : QMenuBar(parent) { level->setCheckable(true); level->setData(percent); fontZoomGroup->addAction(level); - connect(level, &QAction::triggered, this, [this, percent] { ApplyFontZoom(percent); }); + connect(level, &QAction::triggered, this, [this, percent] { SetFontZoom(percent); }); } - ApplyFontZoom(QSettings("PSI", "jfjoch_viewer").value("fontZoom", 100).toInt()); + SetFontZoom(QSettings("PSI", "jfjoch_viewer").value("fontZoom", 100).toInt()); QMenu *helpMenu = addMenu("Help"); // Add "About" action @@ -132,7 +152,7 @@ JFJochViewerMenu::JFJochViewerMenu(QWidget *parent) : QMenuBar(parent) { } // Three levels, 25 % apart: clamping here is what stops the two stepping actions at the ends. -void JFJochViewerMenu::ApplyFontZoom(int percent) { +void JFJochViewerMenu::SetFontZoom(int percent) { fontZoom = std::clamp(percent, 100, 150); QFont font = baseFont; font.setPointSizeF(baseFont.pointSizeF() * fontZoom / 100.0); @@ -145,10 +165,11 @@ void JFJochViewerMenu::ApplyFontZoom(int percent) { QSettings("PSI", "jfjoch_viewer").setValue("fontZoom", fontZoom); for (QAction *level: fontZoomGroup->actions()) level->setChecked(level->data().toInt() == fontZoom); + emit fontZoomChanged(fontZoom); } void JFJochViewerMenu::ResetFontZoom() { - ApplyFontZoom(100); + SetFontZoom(100); } void JFJochViewerMenu::AddWindowEntry(JFJochHelperWindow *window, const QString &name) { diff --git a/viewer/JFJochViewerMenu.h b/viewer/JFJochViewerMenu.h index b55140d8c..5825c1c18 100644 --- a/viewer/JFJochViewerMenu.h +++ b/viewer/JFJochViewerMenu.h @@ -39,6 +39,9 @@ public: void AddDockEntry(QDockWidget *dock, const QString &name); // Back to 100 %, for "Reset all settings to defaults". void ResetFontZoom(); + // 100, 125 or 150 per cent; also reachable from the display toolbar's size buttons. + void SetFontZoom(int percent); + [[nodiscard]] int FontZoom() const { return fontZoom; } public slots: void openSelected(); // also reachable from the toolbar's open-dataset button @@ -58,6 +61,7 @@ signals: void processingLayoutSelected(); void resetLayoutSelected(); void resetSettingsSelected(); + void fontZoomChanged(int percent); private slots: void aboutSelected(); @@ -72,5 +76,4 @@ private slots: private: void openLoadUserMaskTiff(bool replace); - void ApplyFontZoom(int percent); }; diff --git a/viewer/JFJochViewerStatusBar.cpp b/viewer/JFJochViewerStatusBar.cpp index 64ba1ed4b..f8c350ee2 100644 --- a/viewer/JFJochViewerStatusBar.cpp +++ b/viewer/JFJochViewerStatusBar.cpp @@ -18,6 +18,8 @@ JFJochViewerStatusBar::JFJochViewerStatusBar(QWidget *parent) : QStatusBar(paren state_box->setTextVisible(true); state_box->setAlignment(Qt::AlignCenter); state_box->setFormat(""); + // No detector session yet: the badge keeps its place but draws nothing (see setHttpConnection). + state_box->setStyleSheet("QProgressBar { border: none; background: transparent; }"); addPermanentWidget(state_box); } @@ -58,7 +60,7 @@ void JFJochViewerStatusBar::setHttpConnection(bool connected, QString addr) { // No detector session at all -> blank the whole cluster (but keep the reserved space). state_box->setFormat(""); state_box->setValue(0); - state_box->setStyleSheet(""); + state_box->setStyleSheet("QProgressBar { border: none; background: transparent; }"); state_box->setToolTip(""); rate_label->setText(""); return; diff --git a/viewer/JFJochViewerWindow.cpp b/viewer/JFJochViewerWindow.cpp index 0087d63f7..c5d9f9545 100644 --- a/viewer/JFJochViewerWindow.cpp +++ b/viewer/JFJochViewerWindow.cpp @@ -17,6 +17,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -89,6 +92,10 @@ JFJochViewerWindow::JFJochViewerWindow(QWidget *parent, bool dbus, const QString toolBarDisplay = new JFJochViewerToolbarDisplay(this); toolBarDisplay->setObjectName("toolBarDisplay"); addToolBar(Qt::TopToolBarArea, toolBarDisplay); + // The font size lives in the menu; the toolbar's "A" buttons are a second way to it. + connect(toolBarDisplay, &JFJochViewerToolbarDisplay::fontZoomSelected, menuBar, &JFJochViewerMenu::SetFontZoom); + connect(menuBar, &JFJochViewerMenu::fontZoomChanged, toolBarDisplay, &JFJochViewerToolbarDisplay::updateFontZoom); + toolBarDisplay->updateFontZoom(menuBar->FontZoom()); statusbar = new JFJochViewerStatusBar(this); setStatusBar(statusbar); @@ -159,6 +166,10 @@ JFJochViewerWindow::JFJochViewerWindow(QWidget *parent, bool dbus, const QString splitDockWidget(inspectorDock, magnifierDock, Qt::Vertical); resizeDocks({inspectorDock, magnifierDock}, {600, 400}, Qt::Vertical); menuBar->AddDockEntry(magnifierDock, "Magnifier"); + // Shown by anyone - the Window menu, a layout, a reset - it is no longer the window's to restore. + for (auto *dock: {inspectorDock, magnifierDock}) + connect(dock, &QDockWidget::visibilityChanged, this, + [this, dock](bool visible) { if (visible) autoHiddenDocks.removeAll(dock); }); magnifierWindow = new JFJochHelperWindow(this); magnifierWindow->setWindowTitle("Magnifier"); @@ -715,26 +726,59 @@ void JFJochViewerWindow::ResetAllSettings() { menuBar->ResetFontZoom(); } -// The inspector's width bounds are a character count, not a pixel count, so the value column keeps -// up with the text - the View menu's font zoom or the desktop's scaling. At the default font this -// is the 450/600 px it has always been. The count comes from the application font rather than the -// scroll area's: on a font change the window is told before its children are. +// The inspector's width bounds are measured from its content: at least what its widest section needs +// (folded ones included, see CollapsibleSection) plus the scroll bar, so nothing is cut off, and a third +// more at most - wider only adds empty space next to the text, and takes it from the image. Measured +// rather than counted in characters, as they once were, because a character count that suits one +// platform's font is far too wide on another's (600 px for 400 px of content on macOS). void JFJochViewerWindow::UpdateInspectorWidth() { - const int char_width = QFontMetrics(QApplication::font()).averageCharWidth(); - inspectorScroll->setMinimumWidth(75 * char_width); - inspectorScroll->setMaximumWidth(100 * char_width); + const int need = inspectorScroll->widget()->minimumSizeHint().width() + + inspectorScroll->verticalScrollBar()->sizeHint().width(); + inspectorScroll->setMinimumWidth(need); + inspectorScroll->setMaximumWidth(need * 4 / 3); } void JFJochViewerWindow::changeEvent(QEvent *event) { QMainWindow::changeEvent(event); // The menu bar sets the application font while the window is still being built, so the inspector - // is not there yet on the first one. + // is not there yet on the first one. The window hears of a font change before its children do, + // so the content is measured once they have all taken the new font. if (event->type() == QEvent::FontChange && inspectorScroll) - UpdateInspectorWidth(); + QTimer::singleShot(0, this, &JFJochViewerWindow::UpdateInspectorWidth); +} + +// The image comes first. When shrinking the window would leave it narrower than the inspector next +// to it, the inspector folds away, with the magnifier if it shares the inspector's column. They come +// back once the image would still be at least as wide as the inspector with it restored (plus a +// margin, so a window resized around the threshold does not flicker). Only a shrink folds: a panel +// the user reopens on a narrow window stays open, and one the user closed is never brought back. +void JFJochViewerWindow::resizeEvent(QResizeEvent *event) { + QMainWindow::resizeEvent(event); + if (!inspectorDock || !magnifierDock) + return; + const int image_width = centralWidget()->width(); + const bool shrinking = event->oldSize().width() < 0 || event->size().width() < event->oldSize().width(); + if (shrinking && inspectorDock->isVisible() && image_width < inspectorDock->width()) { + autoHiddenWidth = inspectorDock->width(); + QList docks = {inspectorDock}; + if (magnifierDock->isVisible() && dockWidgetArea(magnifierDock) == dockWidgetArea(inspectorDock)) + docks.append(magnifierDock); + for (auto *dock: docks) { + dock->hide(); + if (!autoHiddenDocks.contains(dock)) + autoHiddenDocks.append(dock); + } + } else if (!autoHiddenDocks.isEmpty() && image_width - autoHiddenWidth >= autoHiddenWidth + 40) { + for (auto *dock: std::exchange(autoHiddenDocks, {})) + dock->show(); + } } void JFJochViewerWindow::closeEvent(QCloseEvent *event) { - // Persist the dock/toolbar arrangement and window geometry so the next launch resumes it. + // Persist the dock/toolbar arrangement and window geometry so the next launch resumes it. Docks + // folded away only for a narrow window are saved as open: the next start may have the room. + for (auto *dock: std::exchange(autoHiddenDocks, {})) + dock->show(); QSettings settings("PSI", "jfjoch_viewer"); settings.setValue("geometry", saveGeometry()); settings.setValue("windowState", saveState(kLayoutVersion)); diff --git a/viewer/JFJochViewerWindow.h b/viewer/JFJochViewerWindow.h index 7e9ecfbbd..67accfb2c 100644 --- a/viewer/JFJochViewerWindow.h +++ b/viewer/JFJochViewerWindow.h @@ -68,6 +68,12 @@ private: void ResetAllSettings(); void UpdateInspectorWidth(); + // A narrow window folds the inspector away (with the magnifier, when it is docked in the same + // column) so the image keeps its room, and brings it back once the window is wide enough again. + QList autoHiddenDocks; // hidden by the window, not by the user + int autoHiddenWidth = 0; // the inspector column's width when it was folded away + void resizeEvent(QResizeEvent *event) override; + // Both ways of opening a dataset from outside the file manager - the File menu and D-Bus - // come through here, so the browser follows the same way for either. void FollowInFileBrowser(const QString &filename); diff --git a/viewer/ViewerTheme.cpp b/viewer/ViewerTheme.cpp new file mode 100644 index 000000000..2ada2c4be --- /dev/null +++ b/viewer/ViewerTheme.cpp @@ -0,0 +1,168 @@ +// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute +// SPDX-License-Identifier: GPL-3.0-only + +#include "ViewerTheme.h" + +#include +#include +#include +#include +#include +#include +#include + +namespace { + bool dark_theme = false; + + const QColor DARK_WINDOW(0x1A, 0x1D, 0x3A); // a deep indigo + const QColor DARK_TEXT(0xE3, 0xE7, 0xEC); + + bool SystemIsDark() { +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + return QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark; +#else + return false; +#endif + } + + // Text roles are set for the active and inactive groups only, so disabled text keeps the greyed + // colour the palette derived for it. + void SetTextColor(QPalette &pal, const QColor &color) { + for (auto group: {QPalette::Active, QPalette::Inactive}) + for (auto role: {QPalette::WindowText, QPalette::Text, QPalette::ButtonText, QPalette::ToolTipText}) + pal.setColor(group, role, color); + } + + // Salmon panels, white entry fields that fall back to salmon when disabled, and a navy accent for + // selections and progress-bar chunks. It starts from Fusion's own (light) palette, not the system + // one, which is dark under a dark OS theme; the text is set to black because on macOS the palette's + // text colours come from the platform theme and are grey. + QPalette LightPalette() { + QPalette pal = QApplication::style()->standardPalette(); + pal.setColor(QPalette::Window, QColor(255, 235, 230)); + pal.setColor(QPalette::Base, Qt::white); + pal.setColor(QPalette::AlternateBase, QColor(255, 245, 242)); + pal.setColor(QPalette::Button, QColor(255, 235, 230)); + pal.setColor(QPalette::Disabled, QPalette::Base, QColor(255, 235, 230)); + pal.setColor(QPalette::Highlight, QColor(0x1f, 0x3a, 0x5f)); + pal.setColor(QPalette::HighlightedText, Qt::white); + SetTextColor(pal, Qt::black); + return pal; + } + + // The same layout in the dark: indigo panels, entry fields darker still, and a lighter navy for + // selections so they stand out from the panels. QPalette(button) derives the bevel shades and the + // disabled text from the one colour. + QPalette DarkPalette() { + QPalette pal(DARK_WINDOW); + pal.setColor(QPalette::Window, DARK_WINDOW); + pal.setColor(QPalette::Base, QColor(0x12, 0x14, 0x2B)); + pal.setColor(QPalette::AlternateBase, QColor(0x24, 0x28, 0x4A)); + pal.setColor(QPalette::Button, DARK_WINDOW); + pal.setColor(QPalette::Disabled, QPalette::Base, DARK_WINDOW); + pal.setColor(QPalette::ToolTipBase, QColor(0x2A, 0x2E, 0x55)); + pal.setColor(QPalette::Highlight, QColor(0x2F, 0x5A, 0x8F)); + pal.setColor(QPalette::HighlightedText, Qt::white); + pal.setColor(QPalette::Link, QColor(0x8A, 0xB4, 0xF8)); + pal.setColor(QPalette::PlaceholderText, QColor(0x80, 0x84, 0xA8)); + SetTextColor(pal, DARK_TEXT); + // The derived disabled text is nearly the panel colour, so a greyed-out field looked empty. + // A muted lavender still reads (about 4.8:1 on the panels, against 13:1 for normal text). + for (auto role: {QPalette::WindowText, QPalette::Text, QPalette::ButtonText}) + pal.setColor(QPalette::Disabled, role, QColor(0x85, 0x8A, 0xAE)); + return pal; + } + + void ApplyTheme() { + const ThemeChoice choice = LoadThemeChoice(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + // Once the application has asked for a scheme, Qt reports that scheme instead of the desktop's, + // so the request is withdrawn before System looks at what the desktop is using. + if (choice == ThemeChoice::System) + QGuiApplication::styleHints()->setColorScheme(Qt::ColorScheme::Unknown); +#endif + dark_theme = choice == ThemeChoice::Dark || (choice == ThemeChoice::System && SystemIsDark()); +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) + // The window frame is drawn by the OS (macOS, Windows), not by Qt, and follows the desktop's + // scheme unless the application asks for one - as apps with their own theme switch do, so the + // title bar matches the window under it. + if (choice != ThemeChoice::System) + QGuiApplication::styleHints()->setColorScheme(dark_theme ? Qt::ColorScheme::Dark + : Qt::ColorScheme::Light); +#endif + QApplication::setPalette(dark_theme ? DarkPalette() : LightPalette()); + // With an application stylesheet in place, widgets take their palette when they are polished + // and do not see a later palette change; setting the stylesheet again re-polishes them all. + // Fusion fills QGroupBox interiors with a flat colour of its own; transparent makes them show + // the window background like the rest of the UI (the dock resize handles are drawn by + // SeparatorHandleStyle, not the stylesheet). + qApp->setStyleSheet("QGroupBox { background-color: transparent; }"); + emit ThemeNotifier::Instance()->changed(); + } +} + +ThemeNotifier *ThemeNotifier::Instance() { + static ThemeNotifier notifier; + return ¬ifier; +} + +ThemeChoice LoadThemeChoice() { + const QString value = QSettings("PSI", "jfjoch_viewer").value("theme", "system").toString(); + if (value == "light") return ThemeChoice::Light; + if (value == "dark") return ThemeChoice::Dark; + return ThemeChoice::System; +} + +void SetThemeChoice(ThemeChoice choice) { + const char *value = "system"; + if (choice == ThemeChoice::Light) value = "light"; + if (choice == ThemeChoice::Dark) value = "dark"; + QSettings("PSI", "jfjoch_viewer").setValue("theme", value); + ApplyTheme(); +} + +void InitTheme() { + ApplyTheme(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) + // Re-applied on any desktop scheme change, not only under System: the palette set here must also + // survive the platform reacting to the change with a palette of its own. + QObject::connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, + ThemeNotifier::Instance(), [] { ApplyTheme(); }); +#endif +} + +bool DarkTheme() { + return dark_theme; +} + +void SetThemedStyleSheet(QWidget *widget, const std::function &style) { + widget->setStyleSheet(style()); + QObject::connect(ThemeNotifier::Instance(), &ThemeNotifier::changed, widget, + [widget, style] { widget->setStyleSheet(style()); }); +} + +QColor AccentTextColor() { + return dark_theme ? QColor(0x9D, 0xBB, 0xE3) : QColor(0x1F, 0x3A, 0x5F); +} + +QColor IconInkColor() { + return dark_theme ? DARK_TEXT : QColor(0x2B, 0x2B, 0x2B); +} + +QString SliderStyle() { + // On the dark panels the navy handle would vanish, so it takes the light blue of the headings. + const QString groove = dark_theme ? "#363A66" : "#F3D9D4"; + const QString handle = dark_theme ? "#9DBBE3" : "#1F3A5F"; + const QString handle_hover = dark_theme ? "#BCD2EE" : "#16314F"; + return QString( + "QSlider::groove:horizontal { height:6px; background:%1; border-radius:3px; }" + "QSlider::sub-page:horizontal { background:#FA7268; border-radius:3px; }" + "QSlider::handle:horizontal { background:%2; width:14px; margin:-5px 0; border-radius:7px; }" + "QSlider::handle:horizontal:hover { background:%3; }").arg(groove, handle, handle_hover); +} + +void StyleChart(QChart *chart) { + chart->setTheme(dark_theme ? QChart::ChartThemeDark : QChart::ChartThemeLight); + if (dark_theme) + chart->setBackgroundBrush(QApplication::palette().color(QPalette::Base)); +} diff --git a/viewer/ViewerTheme.h b/viewer/ViewerTheme.h new file mode 100644 index 000000000..022c218d4 --- /dev/null +++ b/viewer/ViewerTheme.h @@ -0,0 +1,45 @@ +// SPDX-FileCopyrightText: 2026 Filip Leonarski, Paul Scherrer Institute +// SPDX-License-Identifier: GPL-3.0-only + +#pragma once + +#include +#include +#include +#include + +class QChart; +class QWidget; + +// The viewer's colour scheme: the light salmon one, or a dark indigo one. The View menu offers +// System, Light and Dark; System follows the desktop where Qt can read it (Qt 6.5+) and is light +// otherwise. A change applies at once: widgets that follow the palette repaint by themselves, and +// the ones that put colours into stylesheets, icons or charts listen to ThemeNotifier. +enum class ThemeChoice { System, Light, Dark }; +ThemeChoice LoadThemeChoice(); +void SetThemeChoice(ThemeChoice choice); // stores the choice and applies it + +// Sets the palette and starts following the desktop's scheme. Call once, after the Fusion style is +// set and before any window is made. +void InitTheme(); +bool DarkTheme(); + +class ThemeNotifier : public QObject { + Q_OBJECT +public: + static ThemeNotifier *Instance(); +signals: + void changed(); +}; + +// Sets the widget's stylesheet from `style`, now and again after every theme change. +void SetThemedStyleSheet(QWidget *widget, const std::function &style); + +// Colours that widgets put into their own stylesheets and drawings. +QColor AccentTextColor(); // headings and headline values: navy on light, light blue on dark +QColor IconInkColor(); // toolbar glyphs and flat toolbar-button text +QString SliderStyle(); // the coral/navy sliders of the toolbars + +// Qt Charts do not follow the widget palette; this gives a chart the current scheme's colours. It +// recolours the series too, so call it before adding series that carry colours of their own. +void StyleChart(QChart *chart); diff --git a/viewer/charts/JFJochDatasetInfoChartView.cpp b/viewer/charts/JFJochDatasetInfoChartView.cpp index c22b83c44..9093c04c4 100644 --- a/viewer/charts/JFJochDatasetInfoChartView.cpp +++ b/viewer/charts/JFJochDatasetInfoChartView.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include +#include "../ViewerTheme.h" #include #include #include @@ -26,6 +27,12 @@ namespace { JFJochDatasetInfoChartView::JFJochDatasetInfoChartView(QWidget *parent) : QChartView(new QChart(), parent) { + StyleChart(chart()); + // The theme recolours every series, the run colours included, so the chart is rebuilt after it. + connect(ThemeNotifier::Instance(), &ThemeNotifier::changed, this, [this] { + StyleChart(chart()); + updateChart(); + }); chart()->legend()->hide(); // Reclaim Qt Charts' outer layout padding so the axis labels keep their room even when the dock // is short (otherwise they are the first thing Qt drops); the inner margins are set per rebuild. @@ -400,7 +407,7 @@ void JFJochDatasetInfoChartView::buildTimeDomainChart() { series->setColor(primary_color_); setSeriesPenWidth(series, fontMetrics().height()); currentSeries = new QScatterSeries(this); - currentSeries->setColor(Qt::black); // "current image" marker: fixed, not a run colour + currentSeries->setColor(palette().color(QPalette::WindowText)); // "current image" marker: not a run colour currentSeries->setMarkerSize(9.0); double dispMin = std::numeric_limits::infinity(); diff --git a/viewer/charts/JFJochSimpleChartView.cpp b/viewer/charts/JFJochSimpleChartView.cpp index 6a8ce3e7d..36be54608 100644 --- a/viewer/charts/JFJochSimpleChartView.cpp +++ b/viewer/charts/JFJochSimpleChartView.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include "JFJochSimpleChartView.h" +#include "../ViewerTheme.h" #include #include @@ -12,6 +13,8 @@ JFJochSimpleChartView::JFJochSimpleChartView(QWidget *parent) : QChartView(new QChart(), parent) { + StyleChart(chart()); + connect(ThemeNotifier::Instance(), &ThemeNotifier::changed, this, [this] { StyleChart(chart()); }); chart()->legend()->hide(); chart()->layout()->setContentsMargins(0, 0, 0, 0); // reclaim padding for the plot + labels chart()->setMargins(QMargins(2, 10, 8, 2)); // top room so the highest Y label is not clipped diff --git a/viewer/jfjoch_viewer.cpp b/viewer/jfjoch_viewer.cpp index a0f75c4dd..d205029fd 100644 --- a/viewer/jfjoch_viewer.cpp +++ b/viewer/jfjoch_viewer.cpp @@ -10,6 +10,7 @@ #include "JFJochViewerWindow.h" #include "RemoteDisplayMode.h" +#include "ViewerTheme.h" #include "../writer/HDF5Objects.h" #include "../common/GitInfo.h" @@ -65,22 +66,8 @@ int main(int argc, char *argv[]) { RegisterHDF5Filter(); QApplication app(argc, argv); - // Theme via the palette (robust across widgets): salmon panels, white entry fields that fall back - // to salmon when disabled, and a navy accent for selections and progress-bar chunks. app.setStyle(new SeparatorHandleStyle("Fusion")); - QPalette pal = app.palette(); - pal.setColor(QPalette::Window, QColor(255, 235, 230)); - pal.setColor(QPalette::Base, Qt::white); - pal.setColor(QPalette::AlternateBase, QColor(255, 245, 242)); - pal.setColor(QPalette::Button, QColor(255, 235, 230)); - pal.setColor(QPalette::Disabled, QPalette::Base, QColor(255, 235, 230)); - pal.setColor(QPalette::Highlight, QColor(0x1f, 0x3a, 0x5f)); - pal.setColor(QPalette::HighlightedText, Qt::white); - app.setPalette(pal); - // Fusion fills QGroupBox interiors with a flat light colour; make them transparent so they show - // the salmon window background like the rest of the UI (entry widgets stay white via the palette). - // The dock resize handles are drawn by SeparatorHandleStyle above, not the stylesheet. - app.setStyleSheet("QGroupBox { background-color: transparent; }"); + InitTheme(); // light or dark palette and the application stylesheet, per the View menu's choice QIcon appIcon(":/jfjoch.png"); app.setWindowIcon(appIcon); @@ -140,8 +127,11 @@ int main(int argc, char *argv[]) { QSplashScreen *splash = new QSplashScreen(splash_pixmap); splash->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::SplashScreen); QString version(QString::fromStdString(jfjoch_version())); + // The splash is white in either theme, so its text is black in either theme too. The message is + // rich text, and rich text takes its colour from the palette, not from showMessage's colour. splash->showMessage( - "Jungfrujoch image viewer
Version " + version + "
Paul Scherrer Institut", + "Jungfrujoch image viewer
Version " + version + + "
Paul Scherrer Institut
", Qt::AlignBottom | Qt::AlignHCenter, Qt::black ); diff --git a/viewer/toolbar/JFJochViewerToolbarDisplay.cpp b/viewer/toolbar/JFJochViewerToolbarDisplay.cpp index d9fac3972..33893b9db 100644 --- a/viewer/toolbar/JFJochViewerToolbarDisplay.cpp +++ b/viewer/toolbar/JFJochViewerToolbarDisplay.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include "JFJochViewerToolbarDisplay.h" +#include "../ViewerTheme.h" #include #include "../../common/ColorScale.h" #include "../RemoteDisplayMode.h" @@ -23,11 +24,6 @@ JFJochViewerToolbarDisplay::JFJochViewerToolbarDisplay(QWidget *parent) connect(background_tail_timer_, &QTimer::timeout, this, &JFJochViewerToolbarDisplay::ApplyPendingBackground); - const QString sliderStyle = - "QSlider::groove:horizontal { height:6px; background:#F3D9D4; border-radius:3px; }" - "QSlider::sub-page:horizontal { background:#FA7268; border-radius:3px; }" - "QSlider::handle:horizontal { background:#1F3A5F; width:14px; margin:-5px 0; border-radius:7px; }" - "QSlider::handle:horizontal:hover { background:#16314F; }"; // Two sliders share the strip, so each is capped rather than expanding across the window. const int slider_cap = fontMetrics().averageCharWidth() * 36; @@ -38,7 +34,7 @@ JFJochViewerToolbarDisplay::JFJochViewerToolbarDisplay(QWidget *parent) foreground_slider->setValue(10); foreground_slider->setToolTip("White point of the color map (image contrast); hold F and use" " the mouse wheel, Ctrl+wheel for coarse steps"); - foreground_slider->setStyleSheet(sliderStyle); + SetThemedStyleSheet(foreground_slider, SliderStyle); foreground_slider->setMaximumWidth(slider_cap); addWidget(foreground_slider); @@ -49,7 +45,7 @@ JFJochViewerToolbarDisplay::JFJochViewerToolbarDisplay(QWidget *parent) background_slider->setValue(0); background_slider->setToolTip("Black point of the color map (0 = off); hold B and use" " the mouse wheel"); - background_slider->setStyleSheet(sliderStyle); + SetThemedStyleSheet(background_slider, SliderStyle); background_slider->setMaximumWidth(slider_cap); addWidget(background_slider); @@ -60,7 +56,7 @@ JFJochViewerToolbarDisplay::JFJochViewerToolbarDisplay(QWidget *parent) b->setCheckable(true); b->setToolTip(tip); b->setCursor(Qt::PointingHandCursor); - b->setStyleSheet(ToolbarIcons::buttonStyle()); + SetThemedStyleSheet(b, ToolbarIcons::buttonStyle); return b; }; auto_foreground_button = makeToggle("Auto", "Auto-contrast to the current image"); @@ -93,6 +89,43 @@ JFJochViewerToolbarDisplay::JFJochViewerToolbarDisplay(QWidget *parent) auto *stretch = new QWidget(this); stretch->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); addWidget(stretch); + + auto makeIconButton = [this](const QIcon &icon, const QString &tip, bool checkable) { + auto *b = new QToolButton(this); + b->setIcon(icon); + b->setIconSize(QSize(20, 20)); + b->setToolTip(tip); + b->setCheckable(checkable); + b->setCursor(Qt::PointingHandCursor); + SetThemedStyleSheet(b, ToolbarIcons::buttonStyle); + return b; + }; + font_zoom_group = new QButtonGroup(this); + font_zoom_group->setExclusive(true); + for (int step = 0; step < 3; step++) { + const int percent = 100 + 25 * step; + auto *b = makeIconButton(ToolbarIcons::letterA(step), QString("Font size %1 %").arg(percent), true); + font_zoom_group->addButton(b, percent); + addWidget(b); + } + connect(font_zoom_group, &QButtonGroup::idClicked, this, &JFJochViewerToolbarDisplay::fontZoomSelected); + addSeparator(); + + theme_button = makeIconButton(ToolbarIcons::halfSun(), QString(), false); + addWidget(theme_button); + connect(theme_button, &QToolButton::clicked, this, + [] { SetThemeChoice(DarkTheme() ? ThemeChoice::Light : ThemeChoice::Dark); }); + connect(ThemeNotifier::Instance(), &ThemeNotifier::changed, this, &JFJochViewerToolbarDisplay::UpdateThemeButton); + UpdateThemeButton(); +} + +void JFJochViewerToolbarDisplay::UpdateThemeButton() { + theme_button->setToolTip(DarkTheme() ? "Switch to the light theme" : "Switch to the dark theme"); +} + +void JFJochViewerToolbarDisplay::updateFontZoom(int percent) { + if (auto *b = font_zoom_group->button(percent)) + b->setChecked(true); } void JFJochViewerToolbarDisplay::foregroundSet(double val) { diff --git a/viewer/toolbar/JFJochViewerToolbarDisplay.h b/viewer/toolbar/JFJochViewerToolbarDisplay.h index 0f41efe33..0606f0ff7 100644 --- a/viewer/toolbar/JFJochViewerToolbarDisplay.h +++ b/viewer/toolbar/JFJochViewerToolbarDisplay.h @@ -7,13 +7,14 @@ #include #include #include "../widgets/SliderPlusBox.h" +#include #include #include #include "../../reader/JFJochReaderImage.h" // Display toolbar: how the image is rendered — foreground (white-point) and background -// (black-point) sliders, auto-contrast, HDR (full dynamic range), and the colour map. The two -// "Reanalyze" hero buttons are appended to this bar by the main window. +// (black-point) sliders, auto-contrast, HDR (full dynamic range), and the colour map; at its right +// end the font size and the light/dark switch, which are also in the View menu but easy to miss there. class JFJochViewerToolbarDisplay : public QToolBar { Q_OBJECT @@ -24,6 +25,9 @@ class JFJochViewerToolbarDisplay : public QToolBar { QToolButton *auto_foreground_button; QToolButton *hdr_mode_button; QComboBox *color_map_select; + QButtonGroup *font_zoom_group; // three "A" buttons; the id is the zoom in per cent + QToolButton *theme_button; // light/dark switch; its tooltip names the theme it switches to + void UpdateThemeButton(); // A ctrl-wheel or auto-foreground burst reports a new foreground per event, and on a remote // display each slider update is a repaint of its own. Hold the readback to the remote @@ -51,6 +55,7 @@ signals: void colorMapChanged(int val); void setAutoForeground(bool val); void setHDRMode(bool val); + void fontZoomSelected(int percent); public slots: void updateForeground(float val); @@ -58,6 +63,7 @@ public slots: void updateAutoForeground(bool val); void updateColorMap(int val); void updateHDRMode(bool val); + void updateFontZoom(int percent); void imageLoaded(std::shared_ptr image); private slots: void foregroundSet(double val); diff --git a/viewer/toolbar/JFJochViewerToolbarImage.cpp b/viewer/toolbar/JFJochViewerToolbarImage.cpp index 3362a8905..17403d372 100644 --- a/viewer/toolbar/JFJochViewerToolbarImage.cpp +++ b/viewer/toolbar/JFJochViewerToolbarImage.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include "JFJochViewerToolbarImage.h" +#include "../ViewerTheme.h" #include #include #include "../RemoteDisplayMode.h" @@ -18,7 +19,7 @@ JFJochViewerToolbarImage::JFJochViewerToolbarImage(QWidget *parent) : QToolBar(p b->setToolTip(tip); b->setCheckable(checkable); b->setCursor(Qt::PointingHandCursor); - b->setStyleSheet(ToolbarIcons::buttonStyle()); + SetThemedStyleSheet(b, ToolbarIcons::buttonStyle); return b; }; @@ -38,11 +39,7 @@ JFJochViewerToolbarImage::JFJochViewerToolbarImage(QWidget *parent) : QToolBar(p image_number_slider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); image_number_slider->setMinimumWidth(140); image_number_slider->setToolTip("Scrub through the dataset"); - image_number_slider->setStyleSheet( - "QSlider::groove:horizontal { height:6px; background:#F3D9D4; border-radius:3px; }" - "QSlider::sub-page:horizontal { background:#FA7268; border-radius:3px; }" - "QSlider::handle:horizontal { background:#1F3A5F; width:14px; margin:-5px 0; border-radius:7px; }" - "QSlider::handle:horizontal:hover { background:#16314F; }"); + SetThemedStyleSheet(image_number_slider, SliderStyle); image_number_slider_timer = new QTimer(this); image_number_slider_timer->setSingleShot(true); @@ -63,7 +60,7 @@ JFJochViewerToolbarImage::JFJochViewerToolbarImage(QWidget *parent) : QToolBar(p current_image_edit->setValidator(current_image_edit_validator); current_image_edit->setToolTip("Current image — type a number to jump"); - total_number_label = new QLabel("/0", this); + total_number_label = new QLabel("/ 0", this); right_button = makeButton(ToolbarIcons::next(), "Next (by jump)", false); rightmost_button = makeButton(ToolbarIcons::last(), "Last image", false); @@ -136,7 +133,7 @@ void JFJochViewerToolbarImage::updateButtons() { if (image_count_in_dataset == 0) total_number_label->setText("/ - "); else - total_number_label->setText("/" + QString::number(image_count_in_dataset)); + total_number_label->setText("/ " + QString::number(image_count_in_dataset)); } void JFJochViewerToolbarImage::updateHttpButton() { diff --git a/viewer/widgets/CollapsibleSection.cpp b/viewer/widgets/CollapsibleSection.cpp index f60602089..106c1c37e 100644 --- a/viewer/widgets/CollapsibleSection.cpp +++ b/viewer/widgets/CollapsibleSection.cpp @@ -2,7 +2,9 @@ // SPDX-License-Identifier: GPL-3.0-only #include "CollapsibleSection.h" +#include "../ViewerTheme.h" +#include #include #include @@ -18,10 +20,12 @@ CollapsibleSection::CollapsibleSection(const QString &title, QWidget *parent) : header_->setArrowType(Qt::RightArrow); header_->setCursor(Qt::PointingHandCursor); header_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - header_->setStyleSheet( - "QToolButton { color:#1F3A5F; font-weight:bold; text-align:left;" - " padding:3px 6px 3px 6px; border:none;" - " border-left:3px solid #FA7268; border-bottom:1px solid #FA7268; background:transparent; }"); + SetThemedStyleSheet(header_, [] { + return QString("QToolButton { color:%1; font-weight:bold; text-align:left;" + " padding:3px 6px 3px 6px; border:none;" + " border-left:3px solid #FA7268; border-bottom:1px solid #FA7268; background:transparent; }") + .arg(AccentTextColor().name()); + }); content_ = new QWidget(this); content_->setVisible(false); @@ -42,3 +46,10 @@ void CollapsibleSection::setContentLayout(QLayout *layout) { void CollapsibleSection::setExpanded(bool on) { header_->setChecked(on); } + +QSize CollapsibleSection::minimumSizeHint() const { + // A hidden widget does not count towards its parent's layout, so the folded content is measured here. + QSize s = QWidget::minimumSizeHint(); + s.setWidth(std::max(s.width(), content_->minimumSizeHint().width())); + return s; +} diff --git a/viewer/widgets/CollapsibleSection.h b/viewer/widgets/CollapsibleSection.h index b66720eaa..225b59761 100644 --- a/viewer/widgets/CollapsibleSection.h +++ b/viewer/widgets/CollapsibleSection.h @@ -17,6 +17,8 @@ public: explicit CollapsibleSection(const QString &title, QWidget *parent = nullptr); void setContentLayout(QLayout *layout); void setExpanded(bool on); + // As wide as the content needs even while folded, so a panel keeps its width when a section opens. + QSize minimumSizeHint() const override; private: QToolButton *header_; diff --git a/viewer/widgets/JFJochViewerImageStatistics.cpp b/viewer/widgets/JFJochViewerImageStatistics.cpp index 51ae89045..a1b816586 100644 --- a/viewer/widgets/JFJochViewerImageStatistics.cpp +++ b/viewer/widgets/JFJochViewerImageStatistics.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include "JFJochViewerImageStatistics.h" +#include "../ViewerTheme.h" #include "../../common/time_utc.h" #include #include @@ -403,7 +404,7 @@ void JFJochViewerImageStatistics::loadImage(std::shared_ptrImageData().indexing_lattice; if (latt) { - text = mkUnitCell(latt->GetUnitCell(), "purple"); + text = mkUnitCell(latt->GetUnitCell(), DarkTheme() ? "violet" : "purple"); auto vec0 = latt->Vec0(); auto vec1 = latt->Vec1(); diff --git a/viewer/widgets/JFJochViewerROIList.cpp b/viewer/widgets/JFJochViewerROIList.cpp index 2fbdc395e..78800a731 100644 --- a/viewer/widgets/JFJochViewerROIList.cpp +++ b/viewer/widgets/JFJochViewerROIList.cpp @@ -54,7 +54,6 @@ JFJochViewerROIList::JFJochViewerROIList(QWidget *parent) : QWidget(parent) { fedit_[i] = new QLineEdit(this); fedit_[i]->setAlignment(Qt::AlignRight); fedit_[i]->setMaximumWidth(90); - fedit_[i]->setStyleSheet("background-color: white; color: black;"); grid->addWidget(flabel_[i], i, 0); grid->addWidget(fedit_[i], i, 1, Qt::AlignRight); connect(fedit_[i], &QLineEdit::editingFinished, this, &JFJochViewerROIList::ApplyEditor); diff --git a/viewer/widgets/NumberLineEdit.cpp b/viewer/widgets/NumberLineEdit.cpp index de6939e5a..8727ac0e2 100644 --- a/viewer/widgets/NumberLineEdit.cpp +++ b/viewer/widgets/NumberLineEdit.cpp @@ -13,7 +13,6 @@ NumberLineEdit::NumberLineEdit(float minVal, , decimalCount(decimals) , savedValue(def_value) { - setStyleSheet("background-color: rgb(255, 255, 255);"); setRange(minVal, maxVal); setDecimals(decimalCount); setButtonSymbols(QAbstractSpinBox::ButtonSymbols::NoButtons); diff --git a/viewer/widgets/NumericComboBox.cpp b/viewer/widgets/NumericComboBox.cpp index 688dfb155..caf7159bd 100644 --- a/viewer/widgets/NumericComboBox.cpp +++ b/viewer/widgets/NumericComboBox.cpp @@ -16,8 +16,6 @@ NumericComboBox::NumericComboBox(std::vector options, int min, int max, QWi setCurrentText(QString::number(min)); - setStyleSheet("background-color: rgb(255, 255, 255);"); - connect(this, QOverload::of(&QComboBox::currentIndexChanged), this, &NumericComboBox::onCurrentIndexChanged); connect(this, &QComboBox::editTextChanged, @@ -35,7 +33,7 @@ void NumericComboBox::setValue(int value) { void NumericComboBox::onCurrentIndexChanged(int index) { if (index >= 0) { - setStyleSheet("background-color: rgb(255, 255, 255);"); + setStyleSheet(""); emit valueChanged(getValue()); } } @@ -44,7 +42,7 @@ void NumericComboBox::onEditTextChanged(const QString &text) { bool ok; int value = text.toInt(&ok); if (ok) { - setStyleSheet("background-color: rgb(255, 255, 255);"); + setStyleSheet(""); emit valueChanged(value); } else { setStyleSheet("background-color: rgb(125, 0, 0);"); diff --git a/viewer/widgets/SliderPlusBox.cpp b/viewer/widgets/SliderPlusBox.cpp index 98e06cd09..b81776346 100644 --- a/viewer/widgets/SliderPlusBox.cpp +++ b/viewer/widgets/SliderPlusBox.cpp @@ -33,7 +33,6 @@ SliderPlusBox::SliderPlusBox(double min, double max, double step, int decimals, m_doubleSpinBox->setDecimals(decimals); m_doubleSpinBox->setSingleStep(step); m_doubleSpinBox->setValue(v); - m_doubleSpinBox->setStyleSheet("background-color: rgb(255, 255, 255);"); m_updateTimer = new QTimer(this); m_updateTimer->setInterval(500); // 500ms throttle diff --git a/viewer/widgets/TitleLabel.cpp b/viewer/widgets/TitleLabel.cpp index 2f4ded107..fa9ffc986 100644 --- a/viewer/widgets/TitleLabel.cpp +++ b/viewer/widgets/TitleLabel.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include "TitleLabel.h" +#include "../ViewerTheme.h" TitleLabel::TitleLabel(QString text, QWidget *parent) : QLabel(parent) { // Slim section header: navy bold text with a coral accent rule, in place of a heavy 50px @@ -10,12 +11,14 @@ TitleLabel::TitleLabel(QString text, QWidget *parent) : QLabel(parent) { QFont f = font(); f.setBold(true); setFont(f); - setStyleSheet("QLabel {" - " color: #1F3A5F;" - " background-color: transparent;" - " border-left: 3px solid #FA7268;" - " border-bottom: 1px solid #FA7268;" - " padding: 3px 6px 3px 8px; }"); + SetThemedStyleSheet(this, [] { + return QString("QLabel {" + " color: %1;" + " background-color: transparent;" + " border-left: 3px solid #FA7268;" + " border-bottom: 1px solid #FA7268;" + " padding: 3px 6px 3px 8px; }").arg(AccentTextColor().name()); + }); setAlignment(Qt::AlignLeft | Qt::AlignVCenter); setFixedHeight(26); } diff --git a/viewer/widgets/ToolbarIcons.cpp b/viewer/widgets/ToolbarIcons.cpp index 3a5241ee7..fe41df07d 100644 --- a/viewer/widgets/ToolbarIcons.cpp +++ b/viewer/widgets/ToolbarIcons.cpp @@ -2,36 +2,61 @@ // SPDX-License-Identifier: GPL-3.0-only #include "ToolbarIcons.h" +#include "../ViewerTheme.h" +#include #include #include #include +#include #include +#include namespace { constexpr int S = 32; - const QColor INK("#2B2B2B"); const QColor DISABLED("#9AA6B3"); using DrawFn = std::function; - QPixmap render(const DrawFn &fn, const QColor &color) { - QPixmap pm(S, S); + // The glyphs are drawn on an S x S canvas; the painter is scaled so they come out sharp at any size. + QPixmap render(const DrawFn &fn, const QColor &color, const QSize &size) { + QPixmap pm(size); pm.fill(Qt::transparent); QPainter p(&pm); p.setRenderHint(QPainter::Antialiasing); + p.scale(size.width() / double(S), size.height() / double(S)); fn(p, color); return pm; } - // Toggle-capable icon: ink when off, white when on (checked, navy background), grey when disabled. + // Draws the glyph when the icon is painted rather than when it is made, so the ink follows the + // theme: ink when off, white when on (a toggle on its navy checked background), grey when disabled. + class InkIconEngine final : public QIconEngine { + public: + InkIconEngine(DrawFn fn, bool toggle) : fn_(std::move(fn)), toggle_(toggle) {} + + void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override { + painter->drawPixmap(rect, pixmap(rect.size(), mode, state)); + } + + QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override { + QColor color = IconInkColor(); + if (mode == QIcon::Disabled) + color = DISABLED; + else if (toggle_ && state == QIcon::On) + color = Qt::white; + return render(fn_, color, size); + } + + QIconEngine *clone() const override { return new InkIconEngine(fn_, toggle_); } + + private: + DrawFn fn_; + bool toggle_; + }; + QIcon toggleIcon(const DrawFn &fn) { - QIcon ic; - ic.addPixmap(render(fn, INK), QIcon::Normal, QIcon::Off); - ic.addPixmap(render(fn, Qt::white), QIcon::Normal, QIcon::On); - ic.addPixmap(render(fn, Qt::white), QIcon::Active, QIcon::On); - ic.addPixmap(render(fn, DISABLED), QIcon::Disabled, QIcon::Off); - return ic; + return QIcon(new InkIconEngine(fn, true)); } void fillTriangle(QPainter &p, const QColor &c, QPointF a, QPointF b, QPointF tip) { @@ -167,6 +192,43 @@ QIcon table() { }); } +QIcon halfSun() { + return toggleIcon([](QPainter &p, const QColor &c) { + // A sun whose disc is half filled, split along the diagonal: light and dark in one glyph. + p.setPen(QPen(c, 2.0)); + p.setBrush(Qt::NoBrush); + p.drawEllipse(QPointF(16, 16), 7, 7); + QPainterPath disc, half; + disc.addEllipse(QPointF(16, 16), 7, 7); + half.addPolygon(QPolygonF({QPointF(32, 0), QPointF(32, 32), QPointF(0, 32)})); + p.setPen(Qt::NoPen); + p.setBrush(c); + p.drawPath(disc.intersected(half)); + p.setPen(QPen(c, 2.2, Qt::SolidLine, Qt::RoundCap)); + for (int i = 0; i < 8; i++) { + const double a = i * std::numbers::pi / 4.0; + p.drawLine(QPointF(16 + 10.5 * std::cos(a), 16 + 10.5 * std::sin(a)), + QPointF(16 + 13.5 * std::cos(a), 16 + 13.5 * std::sin(a))); + } + }); +} + +QIcon letterA(int size_step) { + return toggleIcon([size_step](QPainter &p, const QColor &c) { + // A bold "A" at 16, 21 or 26 units; all three stand on the same baseline, so side by side + // they read as a ladder of sizes. + QFont font; + font.setBold(true); + font.setPixelSize(16 + 5 * size_step); + QPainterPath path; + path.addText(0, 0, font, "A"); + const QRectF r = path.boundingRect(); + p.setPen(Qt::NoPen); + p.setBrush(c); + p.drawPath(path.translated(16 - r.center().x(), 28 - r.bottom())); + }); +} + QIcon httpSync(HttpState state) { QColor dot; switch (state) { @@ -180,19 +242,16 @@ QIcon httpSync(HttpState state) { p.setBrush(dot); p.drawEllipse(QPointF(24, 24), 4.2, 4.2); // status dot }; - QIcon ic; - ic.addPixmap(render(draw, INK), QIcon::Normal, QIcon::Off); - ic.addPixmap(render(draw, DISABLED), QIcon::Disabled, QIcon::Off); - return ic; + return QIcon(new InkIconEngine(draw, false)); } QString buttonStyle() { - return QStringLiteral( - "QToolButton { border:none; border-radius:4px; padding:4px 6px; color:#2B2B2B;" + return QString( + "QToolButton { border:none; border-radius:4px; padding:4px 6px; color:%1;" " background:transparent; }" " QToolButton:hover { background:rgba(250,114,104,0.20); }" " QToolButton:checked { background:#1F3A5F; color:white; }" - " QToolButton:disabled { color:#9AA6B3; }"); + " QToolButton:disabled { color:#9AA6B3; }").arg(IconInkColor().name()); } } // namespace ToolbarIcons diff --git a/viewer/widgets/ToolbarIcons.h b/viewer/widgets/ToolbarIcons.h index 74b49391a..04514a2d7 100644 --- a/viewer/widgets/ToolbarIcons.h +++ b/viewer/widgets/ToolbarIcons.h @@ -19,6 +19,8 @@ namespace ToolbarIcons { QIcon reanalyzeDataset(); // a stack of frames QIcon linePlot(); // line chart on axes (per-resolution plot view) QIcon table(); // grid of rows/columns (table view) + QIcon halfSun(); // light/dark theme switch: a sun with a half-filled disc + QIcon letterA(int size_step); // font size 0 (small), 1, 2 (large) enum class HttpState { Disconnected, Live, Frozen }; QIcon httpSync(HttpState state); // sync arrows + a status dot (grey / green / amber) diff --git a/viewer/windows/JFJochCalibrationResultWindow.cpp b/viewer/windows/JFJochCalibrationResultWindow.cpp index 33f042077..afaf1e56d 100644 --- a/viewer/windows/JFJochCalibrationResultWindow.cpp +++ b/viewer/windows/JFJochCalibrationResultWindow.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include "JFJochCalibrationResultWindow.h" +#include "../ViewerTheme.h" #include #include @@ -27,7 +28,7 @@ namespace { f.setPointSizeF(f.pointSizeF() * 2.2); f.setBold(true); v->setFont(f); - v->setStyleSheet("color: #1F3A5F;"); + SetThemedStyleSheet(v, [] { return "color: " + AccentTextColor().name() + ";"; }); v->setAlignment(Qt::AlignCenter); auto *c = new QLabel(caption, card); c->setStyleSheet("color: gray;"); diff --git a/viewer/windows/JFJochMergeStatsWindow.cpp b/viewer/windows/JFJochMergeStatsWindow.cpp index d04de09a0..db7c50401 100644 --- a/viewer/windows/JFJochMergeStatsWindow.cpp +++ b/viewer/windows/JFJochMergeStatsWindow.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-3.0-only #include "JFJochMergeStatsWindow.h" +#include "../ViewerTheme.h" #include #include @@ -57,7 +58,7 @@ namespace { f.setPointSizeF(f.pointSizeF() * 2.2); f.setBold(true); v->setFont(f); - v->setStyleSheet("color: #1F3A5F;"); + SetThemedStyleSheet(v, [] { return "color: " + AccentTextColor().name() + ";"; }); v->setAlignment(Qt::AlignCenter); auto *c = new QLabel(caption, card); c->setStyleSheet("color: gray;"); @@ -170,7 +171,10 @@ JFJochMergeStatsWindow::JFJochMergeStatsWindow(const QString &title, const Merge auto *banner = new QLabel(text, this); banner->setContentsMargins(10, 6, 10, 6); if (twinning.twinning_suspected) - banner->setStyleSheet("color: rgb(160,0,0); border: 1px solid red; border-radius: 4px;"); + SetThemedStyleSheet(banner, [] { + return QString("color: %1; border: 1px solid red; border-radius: 4px;") + .arg(DarkTheme() ? "#FF7B72" : "rgb(160,0,0)"); + }); else banner->setStyleSheet("color: gray;"); layout->addWidget(banner); @@ -183,22 +187,22 @@ JFJochMergeStatsWindow::JFJochMergeStatsWindow(const QString &title, const Merge plotBtn->setCheckable(true); plotBtn->setChecked(true); plotBtn->setToolTip("Per-resolution plot"); - plotBtn->setStyleSheet(ToolbarIcons::buttonStyle()); + SetThemedStyleSheet(plotBtn, ToolbarIcons::buttonStyle); auto *tableBtn = new QToolButton(this); tableBtn->setIcon(ToolbarIcons::table()); tableBtn->setCheckable(true); tableBtn->setToolTip("Per-shell table"); - tableBtn->setStyleSheet(ToolbarIcons::buttonStyle()); + SetThemedStyleSheet(tableBtn, ToolbarIcons::buttonStyle); auto *isaBtn = new QToolButton(this); isaBtn->setIcon(ToolbarIcons::linePlot()); isaBtn->setCheckable(true); isaBtn->setToolTip("ISa diagnostic: merged I/σ against I"); - isaBtn->setStyleSheet(ToolbarIcons::buttonStyle()); + SetThemedStyleSheet(isaBtn, ToolbarIcons::buttonStyle); auto *reportBtn = new QToolButton(this); reportBtn->setText("Report"); reportBtn->setCheckable(true); reportBtn->setToolTip("The rugnux result report, as written to _report.txt"); - reportBtn->setStyleSheet(ToolbarIcons::buttonStyle()); + SetThemedStyleSheet(reportBtn, ToolbarIcons::buttonStyle); auto *viewGroup = new QButtonGroup(this); viewGroup->setExclusive(true); viewGroup->addButton(plotBtn, 0); @@ -277,7 +281,9 @@ QWidget *JFJochMergeStatsWindow::buildIsaDiagnostic(const std::vectorsetName("merged reflections"); points->setMarkerSize(4.0); points->setBorderColor(Qt::transparent); - points->setColor(QColor(0x1F, 0x3A, 0x5F, 0x60)); + QColor point_color = AccentTextColor(); + point_color.setAlpha(0x60); + points->setColor(point_color); double i_lo = std::numeric_limits::max(), i_hi = 0.0, r_hi = 0.0; for (const auto &[I, sigma] : i_sigma) { @@ -295,6 +301,7 @@ QWidget *JFJochMergeStatsWindow::buildIsaDiagnostic(const std::vectorlegend()->setVisible(false); chart->addSeries(points); diff --git a/viewer/windows/JFJochViewerImageListWindow.cpp b/viewer/windows/JFJochViewerImageListWindow.cpp index 10b13c4fd..909117cde 100644 --- a/viewer/windows/JFJochViewerImageListWindow.cpp +++ b/viewer/windows/JFJochViewerImageListWindow.cpp @@ -223,7 +223,7 @@ void JFJochViewerImageListWindow::imageLoaded(std::shared_ptrverticalHeader()->setVisible(false); tableView->horizontalHeader()->setSectionsClickable(true); tableView->horizontalHeader()->setSortIndicatorShown(true); - tableView->setStyleSheet("background-color: white;"); tableView->setSelectionBehavior(QAbstractItemView::SelectRows); tableView->setSelectionMode(QAbstractItemView::SingleSelection); diff --git a/viewer/windows/JFJochViewerSpotListWindow.cpp b/viewer/windows/JFJochViewerSpotListWindow.cpp index 300a85984..2ab0aaedf 100644 --- a/viewer/windows/JFJochViewerSpotListWindow.cpp +++ b/viewer/windows/JFJochViewerSpotListWindow.cpp @@ -29,7 +29,6 @@ JFJochViewerSpotListWindow::JFJochViewerSpotListWindow(QWidget* parent) tableView->verticalHeader()->setVisible(false); tableView->horizontalHeader()->setSectionsClickable(true); tableView->horizontalHeader()->setSortIndicatorShown(true); - tableView->setStyleSheet("background-color: white;"); tableView->setSelectionBehavior(QAbstractItemView::SelectRows); tableView->setSelectionMode(QAbstractItemView::SingleSelection);