CaptureMoment 0.1.0
Free and open-source non-destructive photo editor
Loading...
Searching...
No Matches
display_manager.h
Go to the documentation of this file.
1
16#pragma once
17
18#include <memory>
19#include <QObject>
20#include <QSize>
21#include <QPointF>
22
23#include "common/image_region.h"
24#include "viewport_manager.h"
25
26// Forward declaration
28class IRenderingItemBase;
29}
30
31namespace CaptureMoment::UI {
32
38namespace Display {
39
72class DisplayManager : public QObject {
73 Q_OBJECT
74
77
78
80
83
85 Q_PROPERTY(float zoom READ zoom WRITE setZoom NOTIFY zoomChanged)
86
88 Q_PROPERTY(QPointF pan READ pan WRITE setPan NOTIFY panChanged)
89
92
94 Q_PROPERTY(float displayScale READ displayScale NOTIFY displayScaleChanged)
95
98
99
100public:
105 explicit DisplayManager(QObject* parent = nullptr);
106
108 DisplayManager& operator=(const DisplayManager&) = delete;
110 DisplayManager& operator=(DisplayManager&&) = default;
111
113 ~DisplayManager() = default;
114
115
116 // =========================================================================
117 // Initialization
118 // =========================================================================
119
126 void initialize();
127
138 Q_INVOKABLE void initialize(const QSize& viewport_logical, const ScreenInfo& screen);
139
144 [[nodiscard]] bool isInitialized() const noexcept;
145
146 // =========================================================================
147 // Rendering Item
148 // =========================================================================
149
160 void setRenderingItem(Rendering::IRenderingItemBase* item);
161
166 [[nodiscard]] Rendering::IRenderingItemBase* renderingItem() const noexcept { return m_rendering_item; };
167
168 // =========================================================================
169 // Image Operations
170 // =========================================================================
171
180 void createDisplayImage(std::unique_ptr<Core::Common::ImageRegion> source_image);
181
189 void updateDisplayTile(std::unique_ptr<Core::Common::ImageRegion> source_tile);
190
200 Q_INVOKABLE void setSourceImageSize(int width, int height);
201
202 // =========================================================================
203 // Zoom & Pan
204 // =========================================================================
205
214 Q_INVOKABLE void setZoom(float zoom);
215
220 [[nodiscard]] float zoom() const noexcept { return m_zoom; };
221
229 Q_INVOKABLE void setPan(const QPointF& pan);
230
235 [[nodiscard]] QPointF pan() const noexcept { return m_pan; };
236
246 Q_INVOKABLE void zoomAt(const QPointF& point, float zoom_delta);
247
254 Q_INVOKABLE void fitToView();
255
261 Q_INVOKABLE void resetView();
262
266 Q_INVOKABLE void zoomIn();
267
271 Q_INVOKABLE void zoomOut();
272
273 // =========================================================================
274 // Viewport
275 // =========================================================================
276
286 Q_INVOKABLE void setViewportSize(const QSize& size);
287
292 [[nodiscard]] QSize viewportSize() const noexcept;
293
302 Q_INVOKABLE void setQualityMargin(float margin);
303
304 // =========================================================================
305 // Coordinate Mapping
306 // =========================================================================
307
318 Q_INVOKABLE QPointF mapBackendToDisplay(int backend_x, int backend_y) const;
319
330 Q_INVOKABLE QPoint mapDisplayToBackend(float display_x, float display_y) const;
331
332 // =========================================================================
333 // Property Getters
334 // =========================================================================
335
340 [[nodiscard]] QSize sourceImageSize() const noexcept { return m_source_image_size; };
341
346 [[nodiscard]] QSize displayImageSize() const noexcept { return m_display_image_size; };
347
352 [[nodiscard]] QSize downsampleSize() const noexcept { return m_downsample_size; };
353
358 [[nodiscard]] float displayScale() const noexcept { return m_display_scale; };
359
364 [[nodiscard]] int maxDownsample() const noexcept;
365
366signals:
376 void displayImageRequest(int target_width, int target_height);
377
382 void zoomChanged(float zoom);
383
388 void panChanged(const QPointF& pan);
389
394 void viewportSizeChanged(const QSize& size);
395
400 void sourceImageSizeChanged(const QSize& size);
401
406 void displayImageSizeChanged(const QSize& size);
407
412 void downsampleSizeChanged(const QSize& size);
413
418 void displayScaleChanged(float scale);
419
424 void maxDownsampleChanged(int max_dim);
425
430 void initializedChanged(bool initialized);
431
432private:
433 // =========================================================================
434 // Internal Methods
435 // =========================================================================
436
443 void constrainPan();
444
453 [[nodiscard]] QSize calculateDisplaySize(const QSize& source_size) const;
454
455 // =========================================================================
456 // Member Variables
457 // =========================================================================
458
462 std::unique_ptr<ViewportManager> m_viewport_manager;
463
465 float m_zoom{1.0f};
466
468 QPointF m_pan{0, 0};
469
471 QSize m_source_image_size;
472
474 QSize m_display_image_size;
475
477 QSize m_downsample_size;
478
480 float m_display_scale{1.0f};
481
483 Rendering::IRenderingItemBase* m_rendering_item{nullptr};
484
486 float m_fit_zoom{1.0f};
487};
488
489} // namespace Display
490} // namespace CaptureMoment::UI
Central manager for image display, zoom, pan, and viewport coordination.
void viewportSizeChanged(const QSize &size)
Emitted when viewport size changes.
void displayScaleChanged(float scale)
Emitted when display scale changes.
void initialize()
Initializes with auto-detection of screen properties.
void panChanged(const QPointF &pan)
Emitted when pan changes.
void updateDisplayTile(std::unique_ptr< Core::Common::ImageRegion > source_tile)
Updates a specific tile region of the display image.
QSize downsampleSize() const noexcept
Gets the downsampled image size (GPU texture size).
void displayImageSizeChanged(const QSize &size)
Emitted when display image size changes.
void setRenderingItem(Rendering::IRenderingItemBase *item)
Assigns the rendering item that will receive image updates.
void displayImageRequest(int target_width, int target_height)
Emitted when a new downsampled image is needed.
Rendering::IRenderingItemBase * renderingItem() const noexcept
Gets the current rendering item.
void createDisplayImage(std::unique_ptr< Core::Common::ImageRegion > source_image)
Creates the display buffer from a downsampled source image.
Q_INVOKABLE void setQualityMargin(float margin)
Sets the quality margin for zoom headroom.
Q_INVOKABLE QPointF mapBackendToDisplay(int backend_x, int backend_y) const
Maps backend (source) coordinates to display coordinates.
Q_INVOKABLE void setSourceImageSize(int width, int height)
Sets the source image size metadata.
Q_INVOKABLE void setZoom(float zoom)
Sets the zoom level.
Q_INVOKABLE QPoint mapDisplayToBackend(float display_x, float display_y) const
Maps display coordinates to backend (source) coordinates.
bool isInitialized() const noexcept
Checks if the manager has been initialized.
void maxDownsampleChanged(int max_dim)
Emitted when max downsample changes.
Q_INVOKABLE void resetView()
Resets the view to default fit state.
void downsampleSizeChanged(const QSize &size)
Emitted when downsample size changes.
Q_INVOKABLE void setViewportSize(const QSize &size)
Sets the viewport size.
void zoomChanged(float zoom)
Emitted when zoom changes.
Q_INVOKABLE void zoomAt(const QPointF &point, float zoom_delta)
Performs a zoom centered on a specific point.
Q_INVOKABLE void zoomOut()
Zooms out by 20% (divides zoom by 1.2).
float displayScale() const noexcept
Gets the display scale factor.
void sourceImageSizeChanged(const QSize &size)
Emitted when source image size changes.
QSize displayImageSize() const noexcept
Gets the display image size.
void initializedChanged(bool initialized)
Emitted when initialization completes.
Q_INVOKABLE void setPan(const QPointF &pan)
Sets the pan offset.
Q_INVOKABLE void zoomIn()
Zooms in by 20%.
float zoom() const noexcept
Gets the current zoom level.
Q_INVOKABLE void fitToView()
Fits the image to fill the viewport.
QPointF pan() const noexcept
Gets the current pan offset.
Manages viewport calculations for optimal display across all screen types.
Defines the ImageRegion structure for representing pixel buffers in the CaptureMoment Core library.
Namespace containing Qt-specific UI components for CaptureMoment.
Physical screen characteristics.
Central viewport management for optimal display across all screen types.
CaptureMoment — footer