File indexing completed on 2025-04-27 03:58:25
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2010-04-30 0007 * Description : Layout for an item on image preview 0008 * 0009 * SPDX-FileCopyrightText: 2010-2011 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de> 0010 * 0011 * SPDX-License-Identifier: GPL-2.0-or-later 0012 * 0013 * ============================================================ */ 0014 0015 #ifndef DIGIKAM_PREVIEW_LAYOUT_H 0016 #define DIGIKAM_PREVIEW_LAYOUT_H 0017 0018 // Qt includes 0019 0020 #include <QFlags> 0021 #include <QObject> 0022 #include <QPointF> 0023 0024 // Local includes 0025 0026 #include "digikam_export.h" 0027 0028 namespace Digikam 0029 { 0030 0031 class GraphicsDImgItem; 0032 class GraphicsDImgView; 0033 0034 class DIGIKAM_EXPORT SinglePhotoPreviewLayout : public QObject 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 0040 enum SetZoomFlag 0041 { 0042 JustSetFactor = 0, 0043 CenterView = 1 << 0, 0044 SnapZoomFactor = 1 << 1 0045 }; 0046 Q_DECLARE_FLAGS(SetZoomFlags, SetZoomFlag) 0047 0048 public: 0049 0050 explicit SinglePhotoPreviewLayout(QObject* const parent); 0051 ~SinglePhotoPreviewLayout() override; 0052 0053 /** 0054 * Set the graphics view, and associated scene, to operate on. 0055 */ 0056 void setGraphicsView(GraphicsDImgView* const view); 0057 0058 /** 0059 * Set to true to scale small images to fit to window. 0060 */ 0061 void setScaleFitToWindow(bool value); 0062 0063 /** 0064 * Set the item to layout. For a SinglePhoto layout, typically, 0065 * you can add only one item. 0066 */ 0067 void addItem(GraphicsDImgItem* const item); 0068 0069 bool isFitToWindow() const; 0070 double zoomFactor() const; 0071 double realZoomFactor() const; 0072 0073 /** 0074 * The zoom range for incrementing and decrementing. 0075 */ 0076 double maxZoomFactor() const; 0077 double minZoomFactor() const; 0078 void setMaxZoomFactor(double z); 0079 void setMinZoomFactor(double z); 0080 bool atMaxZoom() const; 0081 bool atMinZoom() const; 0082 0083 Q_SIGNALS: 0084 0085 void fitToWindowToggled(bool fitToWindow); 0086 void zoomFactorChanged(double); 0087 0088 public Q_SLOTS: 0089 0090 void increaseZoom(const QPoint& viewportAnchor = QPoint()); 0091 void decreaseZoom(const QPoint& viewportAnchor = QPoint()); 0092 void setZoomFactor(double z, const QPoint& viewportAnchor = QPoint(), SetZoomFlags flags = JustSetFactor); 0093 void setZoomFactor(double z, SetZoomFlags flags); 0094 void setZoomFactorSnapped(double z); 0095 void fitToWindow(); 0096 0097 /// Toggle between fitToWindow and previous zoom factor 0098 void toggleFitToWindow(); 0099 0100 /// Toggle between fitToWindow and zoom factor 1 0101 void toggleFitToWindowOr100(); 0102 0103 /// Update settings when size of image or view changed 0104 void updateZoomAndSize(); 0105 0106 protected: 0107 0108 void updateLayout(); 0109 0110 private: 0111 0112 SinglePhotoPreviewLayout(); // Disable default constructor. 0113 0114 class Private; 0115 Private* const d; 0116 }; 0117 0118 Q_DECLARE_OPERATORS_FOR_FLAGS(SinglePhotoPreviewLayout::SetZoomFlags) 0119 0120 } // namespace Digikam 0121 0122 #endif // DIGIKAM_PREVIEW_LAYOUT_H