Warning, file /office/calligra/libs/widgets/KoZoomController.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2007 Thomas Zander <zander@kde.org> 0003 * Copyright (C) 2007,2012 C. Boemann <cbo@boemann.dk> 0004 * Copyright (C) 2007 Jan Hambrecht <jaham@gmx.net> 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Library General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Library General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Library General Public License 0017 * along with this library; see the file COPYING.LIB. If not, write to 0018 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 */ 0021 #ifndef KOZOOMCONTROLLER_H 0022 #define KOZOOMCONTROLLER_H 0023 0024 #include "KoZoomAction.h" 0025 #include "kowidgets_export.h" 0026 #include <KoZoomMode.h> 0027 #include <QObject> 0028 #include <QSizeF> 0029 0030 class KoCanvasController; 0031 class KoZoomAction; 0032 class KoZoomHandler; 0033 class KActionCollection; 0034 class QSize; 0035 0036 0037 /** 0038 * This controller class handles zoom levels for any canvas. 0039 * 0040 * For each KoCanvasController you should have one instance of this 0041 * class to go with it. This class then creates a KoZoomAction and 0042 * basically handles all zooming for you. 0043 * 0044 * All you need to do is connect to the setDocumentSize() slot and 0045 * keep the controller up-to-date if your on-screen document ever 0046 * changes (note that this is in document units, so this is a zoom 0047 * independent size). 0048 * 0049 * If you choose to have zoom modes of 'page' and 'width' you are 0050 * required to set the page size using the setPageSize() method. 0051 * 0052 * Additionally you can connect to the zoomChanged() signal if you 0053 * want to store the latest zoom level and mode, for example to 0054 * restore the last used one at next restart. 0055 * 0056 * The specialAspectMode toggle is only a UI element. It does nothing 0057 * except emit the aspectModeChanged signal. 0058 * 0059 */ 0060 class KOWIDGETS_EXPORT KoZoomController : public QObject { 0061 Q_OBJECT 0062 public: 0063 /** 0064 * Constructor. Create one per canvasController. The zoomAction is created in the constructor and will 0065 * be available to the passed actionCollection for usage by XMLGui. 0066 * @param controller the canvasController 0067 * @param zoomHandler the zoom handler (viewconverter with setter methods) 0068 * @param actionCollection the action collection where the KoZoomAction is added to 0069 * @param specialButtons controls which special buttons to show 0070 * @param parent the parent QObject 0071 */ 0072 KoZoomController(KoCanvasController *controller, 0073 KoZoomHandler *zoomHandler, 0074 KActionCollection *actionCollection, 0075 KoZoomAction::SpecialButtons specialButtons = nullptr, 0076 QObject *parent = nullptr); 0077 0078 /** 0079 * A special override for for creation of a zoom controller 0080 * without automatic generation of standard zoom in and zoom out 0081 * actions. The caller is supposed create and connect the 0082 * corresponding actions himself. 0083 * 0084 * @param controller the canvasController 0085 * @param zoomHandler the zoom handler (viewconverter with setter methods) 0086 * @param actionCollection the action collection where the KoZoomAction is added to 0087 * @param createZoomShortcuts shows whether the zoom actions should be 0088 * created or not. 0089 * @param specialButtons controls which special buttons to show 0090 * @param parent the parent QObject 0091 * 0092 * Used in KisZoomController. 0093 */ 0094 KoZoomController(KoCanvasController *controller, 0095 KoZoomHandler *zoomHandler, 0096 KActionCollection *actionCollection, 0097 bool createZoomShortcuts, 0098 KoZoomAction::SpecialButtons specialButtons = nullptr, 0099 QObject *parent = nullptr); 0100 0101 /// destructor 0102 ~KoZoomController() override; 0103 0104 /// returns the zoomAction that is maintained by this controller 0105 KoZoomAction *zoomAction() const; 0106 0107 /** 0108 * Alter the current zoom mode which updates the Gui. 0109 * @param mode the new mode that will be used to auto-calculate a new zoom-level if needed. 0110 */ 0111 void setZoomMode(KoZoomMode::Mode mode); 0112 0113 /** 0114 * Set the resolution, zoom, the zoom mode for this zoom Controller. 0115 * Typically for use just after construction to restore the 0116 * persistent data. 0117 * 0118 * @param mode new zoom mode for the canvas 0119 * @param zoom (for ZOOM_CONSTANT zoom mode only) new zoom value for 0120 * the canvas 0121 * @param resolutionX new X resolution for the document 0122 * @param resolutionY new Y resolution for the document 0123 * @param stillPoint (for ZOOM_CONSTANT zoom mode only) the point 0124 * which will not change its position in widget 0125 * during the zooming. It is measured in view 0126 * coordinate system *before* zoom. 0127 */ 0128 void setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY, const QPointF &stillPoint); 0129 0130 0131 /** 0132 * Convenience function that changes resolution with 0133 * keeping the centering unchanged 0134 */ 0135 void setZoom(KoZoomMode::Mode mode, qreal zoom, qreal resolutionX, qreal resolutionY); 0136 0137 /** 0138 * Convenience function that does not touch the resolution of the 0139 * document 0140 */ 0141 void setZoom(KoZoomMode::Mode mode, qreal zoom, const QPointF &stillPoint); 0142 0143 /** 0144 * Convenience function with @p center always set to the current 0145 * center point of the canvas 0146 */ 0147 void setZoom(KoZoomMode::Mode mode, qreal zoom); 0148 0149 0150 /** 0151 * Set Aspect Mode button status and begin a chain of signals 0152 */ 0153 void setAspectMode(bool status); 0154 0155 public Q_SLOTS: 0156 /** 0157 * Set the size of the current page in document coordinates which allows zoom modes that use the pageSize 0158 * to update. 0159 * @param pageSize the new page size in points 0160 */ 0161 void setPageSize(const QSizeF &pageSize); 0162 0163 /** 0164 * Returns the size of the current page in document coordinates 0165 * @returns the page size in points 0166 */ 0167 QSizeF pageSize() const; 0168 0169 /** 0170 * Set the dimensions of where text can appear which allows zoom modes that use the text 0171 * to update. 0172 * @param min the minimum x value (in document coordinates) where text can appear 0173 * @param max the maximum x value (in document coordinates) where text can appear 0174 */ 0175 void setTextMinMax(qreal min, qreal max); 0176 0177 /** 0178 * Set the size of the whole document currently being shown on the canvas. 0179 * The document size will be used together with the current zoom level to calculate the size of the 0180 * canvas in the canvasController. 0181 * @param documentSize the new document size in points 0182 * @param recalculateCenter tells canvas controller not to touch 0183 * preferredCenterFraction 0184 */ 0185 void setDocumentSize(const QSizeF &documentSize, bool recalculateCenter = false); 0186 0187 /** 0188 * Returns the size of the whole document currently being shown on the canvas. 0189 * @returns the document size in points 0190 */ 0191 QSizeF documentSize() const; 0192 0193 Q_SIGNALS: 0194 /** 0195 * This signal is emitted whenever either the zoommode or the zoom level is changed by the user. 0196 * the application can use the emitted data for persistency purposes. 0197 */ 0198 void zoomChanged (KoZoomMode::Mode mode, qreal zoom); 0199 0200 /** 0201 * emitted when the special aspect mode toggle changes. 0202 * @see KoZoomAction::aspectModeChanged() 0203 */ 0204 void aspectModeChanged (bool aspectModeActivated); 0205 0206 /** 0207 * Signal is triggered when the user clicks the zoom to selection button. 0208 * Nothing else happens except that this signal is emitted. 0209 */ 0210 void zoomedToSelection(); 0211 0212 /** 0213 * Signal is triggered when the user clicks the zoom to all button. 0214 * Nothing else happens except that this signal is emitted. 0215 */ 0216 void zoomedToAll(); 0217 0218 protected: 0219 virtual QSize documentToViewport(const QSizeF &size); 0220 0221 private: 0222 Q_PRIVATE_SLOT(d, void setAvailableSize()) 0223 Q_PRIVATE_SLOT(d, void requestZoomRelative(const qreal, const QPointF&)) 0224 Q_PRIVATE_SLOT(d, void setZoom(KoZoomMode::Mode, qreal)) 0225 Q_DISABLE_COPY( KoZoomController ) 0226 0227 class Private; 0228 Private * const d; 0229 }; 0230 0231 #endif