CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
viewport_manager.h
Go to the documentation of this file.
1
8#pragma once
9
10#include "viewport_config.h"
11#include <QObject>
12#include <QSize>
13#include <QPointF>
14
15namespace CaptureMoment::UI {
16namespace Display {
17
22struct ScreenInfo {
25 float dpr{1.0f};
26
27 [[nodiscard]] bool isValid() const noexcept {
28 return physical_width > 0 && physical_height > 0 && dpr > 0.0f;
29 }
30};
31
39 float fit_zoom{1.0f};
40 bool needs_downsample{false};
42
43 [[nodiscard]] bool isValid() const noexcept {
44 return downsample_size.isValid() && display_size.isValid();
45 }
46};
47
53 float zoom{1.0f};
54 QPointF pan{0.0, 0.0};
55 QPointF center_offset{0.0, 0.0};
56};
57
67class ViewportManager : public QObject {
68 Q_OBJECT
69
70public:
71 // =========================================================================
72 // Construction
73 // =========================================================================
74
75 explicit ViewportManager(QObject* parent = nullptr);
76 ~ViewportManager() override = default;
77
82
83 // =========================================================================
84 // Initialization
85 // =========================================================================
86
99 void initialize(const QSize& viewport_logical, const ScreenInfo& screen);
100
105 void setViewportSize(const QSize& viewport_logical);
106
111 void setQualityMargin(float margin);
112
117 void setMaxDownsample(int max_dim);
118
119 // =========================================================================
120 // Calculations
121 // =========================================================================
122
136 [[nodiscard]] ViewportCalculation calculateDisplay(const QSize& source_size) const;
137
147 [[nodiscard]] float calculateFitZoom(const QSize& source_size) const noexcept;
148
157 [[nodiscard]] QSize calculateDownsampleSize(const QSize& source_size) const;
158
165 [[nodiscard]] ViewportState calculateFitToView(const QSize& display_size) const noexcept;
166
167 // =========================================================================
168 // Getters
169 // =========================================================================
170
175 [[nodiscard]] QSize viewportSize() const noexcept { return m_viewport_logical; }
176
181 [[nodiscard]] QSize viewportPhysicalSize() const noexcept { return m_viewport_physical; }
182
187 [[nodiscard]] ScreenInfo screenInfo() const noexcept { return m_screen; }
188
193 [[nodiscard]] float devicePixelRatio() const noexcept { return m_screen.dpr; }
194
199 [[nodiscard]] float qualityMargin() const noexcept { return m_quality_margin; }
200
205 [[nodiscard]] int plafond() const noexcept { return m_plafond; }
206
211 [[nodiscard]] int maxDownsample() const noexcept { return m_max_downsample; }
212
217 [[nodiscard]] bool isInitialized() const noexcept { return m_initialized; }
218
219signals:
220 void viewportSizeChanged(const QSize& size);
221 void maxDownsampleChanged(int max_dim);
222
223private:
224
228 void updateMaxDownsample();
229
233 bool m_initialized{false};
234
238 QSize m_viewport_logical;
239
243 QSize m_viewport_physical;
244
248 ScreenInfo m_screen;
249
253 float m_quality_margin{DisplayConfig::defaultQualityMargin()};
254
258 int m_plafond{DisplayConfig::plafondSmallScreen()};
259
263 int m_max_downsample{DisplayConfig::plafondSmallScreen()};
264};
265
266} // namespace Display
267} // namespace CaptureMoment::UI
Manages viewport calculations for optimal display across all screen types.
QSize viewportPhysicalSize() const noexcept
Gets the physical viewport size.
ScreenInfo screenInfo() const noexcept
Gets the screen information.
QSize calculateDownsampleSize(const QSize &source_size) const
Calculates the downsample size for a source image.
int plafond() const noexcept
Gets the screen-based ceiling.
void setMaxDownsample(int max_dim)
Sets the maximum downsample dimension manually.
float calculateFitZoom(const QSize &source_size) const noexcept
Calculates the zoom factor to fit an image in the viewport.
bool isInitialized() const noexcept
Gets the initialization status.
void setQualityMargin(float margin)
Sets the quality margin for zoom headroom.
void initialize(const QSize &viewport_logical, const ScreenInfo &screen)
Initializes the manager with screen and viewport parameters.
ViewportCalculation calculateDisplay(const QSize &source_size) const
Calculates optimal display parameters for a source image.
ViewportManager(const ViewportManager &)=delete
float devicePixelRatio() const noexcept
Gets the device pixel ratio.
int maxDownsample() const noexcept
Gets the maximum downsample dimension.
void viewportSizeChanged(const QSize &size)
ViewportState calculateFitToView(const QSize &display_size) const noexcept
Calculates viewport state for fit-to-view.
void setViewportSize(const QSize &viewport_logical)
Updates the viewport size.
ViewportManager & operator=(ViewportManager &&)=default
float qualityMargin() const noexcept
Gets the current quality margin.
QSize viewportSize() const noexcept
Gets the logical viewport size.
ViewportManager(ViewportManager &&)=default
ViewportManager & operator=(const ViewportManager &)=delete
static consteval int plafondSmallScreen() noexcept
Plafond (ceiling) for small physical screens.
static consteval float defaultQualityMargin() noexcept
Default quality margin for zoom headroom.
Physical screen characteristics.
float dpr
Device pixel ratio (density)
int physical_width
Physical screen width in pixels.
int physical_height
Physical screen height in pixels.
Result of viewport calculation for an image.
QSize display_size
Size to display in QML (logical pixels)
bool needs_downsample
True if downsample is required.
QSize downsample_size
Size to downsample source image to (GPU texture)
float fit_zoom
Zoom factor to fit image in viewport (0.0-1.0)
size_t texture_memory_mb
Estimated GPU memory usage in MB.
Current viewport state for zoom/pan operations.
QPointF center_offset
Offset to center image in viewport.
QPointF pan
Current pan offset in logical pixels.
float zoom
Current zoom level (1.0 = 100%)
Configuration constants and helper functions for viewport management.
CaptureMoment — footer