File indexing completed on 2024-05-12 16:02:13
0001 /* This file is part of the KDE project 0002 * SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org> 0003 * SPDX-FileCopyrightText: 2007, 2012 C. Boemann <cbo@boemann.dk> 0004 * SPDX-FileCopyrightText: 2007 Jan Hambrecht <jaham@gmx.net> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 #ifndef KOZOOMCONTROLLER_H 0009 #define KOZOOMCONTROLLER_H 0010 0011 #include "KoZoomAction.h" 0012 #include "kritawidgets_export.h" 0013 #include <KoZoomMode.h> 0014 #include <QObject> 0015 #include <QSizeF> 0016 0017 class KoCanvasController; 0018 class KoZoomAction; 0019 class KoZoomHandler; 0020 class KisKActionCollection; 0021 class QSize; 0022 0023 0024 /** 0025 * This controller class handles zoom levels for any canvas. 0026 * 0027 * For each KoCanvasController you should have one instance of this 0028 * class to go with it. This class then creates a KoZoomAction and 0029 * basically handles all zooming for you. 0030 * 0031 * All you need to do is connect to the setDocumentSize() slot and 0032 * keep the controller up-to-date if your on-screen document ever 0033 * changes (note that this is in document units, so this is a zoom 0034 * independent size). 0035 * 0036 * If you choose to have zoom modes of 'page' and 'width' you are 0037 * required to set the page size using the setPageSize() method. 0038 * 0039 * Additionally you can connect to the zoomChanged() signal if you 0040 * want to store the latest zoom level and mode, for example to 0041 * restore the last used one at next restart. 0042 * 0043 * The special canvasMappingMode toggle is only a UI element. It does nothing 0044 * except emit the canvasMappingModeChanged signal. 0045 * 0046 */ 0047 class KRITAWIDGETS_EXPORT KoZoomController : public QObject { 0048 Q_OBJECT 0049 public: 0050 /** 0051 * Constructor. Create one per canvasController. The zoomAction is created in the constructor and will 0052 * be available to the passed actionCollection for usage by XMLGui. 0053 * @param controller the canvasController 0054 * @param zoomHandler the zoom handler (viewconverter with setter methods) 0055 * @param actionCollection the action collection where the KoZoomAction is added to 0056 * @param parent the parent QObject 0057 */ 0058 KoZoomController(KoCanvasController *controller, 0059 KoZoomHandler *zoomHandler, 0060 KisKActionCollection *actionCollection, 0061 QObject *parent = 0); 0062 0063 /// destructor 0064 ~KoZoomController() override; 0065 0066 /// returns the zoomAction that is maintained by this controller 0067 KoZoomAction *zoomAction() const; 0068 0069 /** 0070 * Alter the current zoom mode which updates the Gui. 0071 * @param mode the new mode that will be used to auto-calculate a new zoom-level if needed. 0072 */ 0073 void setZoomMode(KoZoomMode::Mode mode); 0074 0075 /** 0076 * @return the current zoom mode. 0077 */ 0078 KoZoomMode::Mode zoomMode() const; 0079 0080 /** 0081 * Set the resolution, zoom, the zoom mode for this zoom Controller. 0082 * Typically for use just after construction to restore the 0083 * persistent data. 0084 * 0085 * @param mode new zoom mode for the canvas 0086 * @param zoom (for ZOOM_CONSTANT zoom mode only) new zoom value for 0087 * the canvas 0088 * @param resolutionX new X resolution for the document 0089 * @param resolutionY new Y resolution for the document 0090 * @param stillPoint (for ZOOM_CONSTANT zoom mode only) the point 0091 * which will not change its position in widget 0092 * during the zooming. It is measured in view 0093 * coordinate system *before* zoom. 0094 */ 0095 void setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const QPointF &stillPoint); 0096 0097 0098 /** 0099 * Convenience function that changes resolution with 0100 * keeping the centering unchanged 0101 */ 0102 void setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY); 0103 0104 /** 0105 * Convenience function that does not touch the resolution of the 0106 * document 0107 */ 0108 void setZoom(KoZoomMode::Mode mode, qreal zoom, const QPointF &stillPoint); 0109 0110 /** 0111 * Convenience function with @p center always set to the current 0112 * center point of the canvas 0113 */ 0114 void setZoom(KoZoomMode::Mode mode, qreal zoom); 0115 0116 0117 /** 0118 * Set Canvas Mapping Mode button status and begin a chain of signals 0119 */ 0120 void setCanvasMappingMode(bool status); 0121 0122 void setZoomMarginSize(int size); 0123 0124 public Q_SLOTS: 0125 /** 0126 * Set the size of the current page in document coordinates which allows zoom modes that use the pageSize 0127 * to update. 0128 * @param pageSize the new page size in points 0129 */ 0130 void setPageSize(const QSizeF &pageSize); 0131 0132 /** 0133 * Returns the size of the current page in document coordinates 0134 * @returns the page size in points 0135 */ 0136 QSizeF pageSize() const; 0137 0138 /** 0139 * Set the size of the whole document currently being shown on the canvas. 0140 * The document size will be used together with the current zoom level to calculate the size of the 0141 * canvas in the canvasController. 0142 * @param documentSize the new document size in points 0143 * @param recalculateCenter tells canvas controller not to touch 0144 * preferredCenterFraction 0145 */ 0146 void setDocumentSize(const QSizeF &documentSize, bool recalculateCenter = false); 0147 0148 /** 0149 * Returns the size of the whole document currently being shown on the canvas. 0150 * @returns the document size in points 0151 */ 0152 QSizeF documentSize() const; 0153 0154 Q_SIGNALS: 0155 /** 0156 * This signal is emitted whenever either the zoommode or the zoom level is changed by the user. 0157 * the application can use the emitted data for persistency purposes. 0158 */ 0159 void zoomChanged (KoZoomMode::Mode mode, qreal zoom); 0160 0161 /** 0162 * emitted when the special canvas mapping mode toggle changes. 0163 * @see KoZoomAction::canvasMappingModeChanged() 0164 */ 0165 void canvasMappingModeChanged (bool canvasMappingModeActivated); 0166 0167 /** 0168 * Signal is triggered when the user clicks the zoom to selection button. 0169 * Nothing else happens except that this signal is emitted. 0170 */ 0171 void zoomedToSelection(); 0172 0173 /** 0174 * Signal is triggered when the user clicks the zoom to all button. 0175 * Nothing else happens except that this signal is emitted. 0176 */ 0177 void zoomedToAll(); 0178 0179 protected: 0180 virtual QSizeF documentToViewport(const QSizeF &size); 0181 QSize documentToViewportCeil(const QSizeF &size); 0182 0183 private: 0184 Q_PRIVATE_SLOT(d, void setAvailableSize()) 0185 Q_PRIVATE_SLOT(d, void requestZoomRelative(const qreal, const QPointF&)) 0186 Q_PRIVATE_SLOT(d, void setZoom(KoZoomMode::Mode, qreal)) 0187 Q_DISABLE_COPY( KoZoomController ) 0188 0189 class Private; 0190 Private * const d; 0191 }; 0192 0193 #endif