File indexing completed on 2024-05-12 16:30:49
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2008 Jan Hambrecht <jaham@gmx.net> 0003 * Copyright (C) 2010 Boudewijn Rempt <boud@kogmbh.com> 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Library General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Library General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Library General Public License 0016 * along with this library; see the file COPYING.LIB. If not, write to 0017 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0018 * Boston, MA 02110-1301, USA. 0019 */ 0020 0021 #ifndef KARBONZOOMCONTROLLER_H 0022 #define KARBONZOOMCONTROLLER_H 0023 0024 #include <KoZoomMode.h> 0025 #include <QObject> 0026 0027 class KoCanvasController; 0028 class KActionCollection; 0029 class KoZoomAction; 0030 class QPointF; 0031 class QSizeF; 0032 0033 class KarbonZoomController : public QObject 0034 { 0035 Q_OBJECT 0036 public: 0037 /** 0038 * Constructor. Create one per canvasController. The zoomAction is created in the constructor and will 0039 * be available to the passed actionCollection for usage by XMLGui. 0040 * @param controller the canvasController 0041 * @param actionCollection the action collection where the KoZoomAction is added to 0042 * @param parent the parent QObject 0043 */ 0044 KarbonZoomController(KoCanvasController *controller, KActionCollection *actionCollection, QObject *parent = 0); 0045 0046 /// destructor 0047 ~KarbonZoomController(); 0048 0049 /// returns the zoomAction that is maintained by this controller 0050 KoZoomAction *zoomAction() const; 0051 0052 /** 0053 * Alter the current zoom mode which updates the Gui. 0054 * @param mode the new mode that will be used to auto-calculate a new zoom-level if needed. 0055 */ 0056 void setZoomMode(KoZoomMode::Mode mode); 0057 0058 Q_SIGNALS: 0059 /** 0060 * Signal is triggered when the user clicks the zoom to selection button. 0061 * Nothing else happens except that this signal is emitted. 0062 */ 0063 void zoomedToSelection(); 0064 0065 /** 0066 * Signal is triggered when the user clicks the zoom to all button. 0067 * Nothing else happens except that this signal is emitted. 0068 */ 0069 void zoomedToAll(); 0070 0071 public Q_SLOTS: 0072 0073 /** 0074 * Set the zoom and the zoom mode for this zoom Controller. 0075 * Typically for use just after construction to restore the 0076 * persistent data. 0077 * 0078 * @param mode new zoom mode for the canvas 0079 * @param zoom (for ZOOM_CONSTANT zoom mode only) new zoom value for 0080 * the canvas 0081 * @param stillPoint (for ZOOM_CONSTANT zoom mode only) the point 0082 * which will not change its position in widget 0083 * during the zooming. It is measured in view 0084 * coordinate system *before* zoom. 0085 */ 0086 void setZoom(KoZoomMode::Mode mode, qreal zoom, const QPointF &stillPoint); 0087 0088 /** 0089 * Convenience function with @p center always set to the current 0090 * center point of the canvas 0091 */ 0092 void setZoom(KoZoomMode::Mode mode, qreal zoom); 0093 0094 /** 0095 * Set the size of the current page in document coordinates which allows zoom modes that use the pageSize 0096 * to update. 0097 * @param pageSize the new page size in points 0098 */ 0099 void setPageSize(const QSizeF &pageSize); 0100 0101 private Q_SLOTS: 0102 /// so we know when the canvasController changes size 0103 void setAvailableSize(); 0104 0105 /// when the canvas controller wants us to change zoom 0106 void requestZoomRelative(const qreal factor, const QPointF &stillPoint); 0107 0108 /// so we know when the page size changed 0109 void canvasResourceChanged(int key, const QVariant & value); 0110 0111 /// zoom in relative to current zoom 0112 void zoomInRelative(); 0113 0114 /// zoom out relative to current zoom 0115 void zoomOutRelative(); 0116 0117 private: 0118 void requestZoomBy(const qreal factor); 0119 0120 private: 0121 class Private; 0122 Private * const d; 0123 }; 0124 0125 #endif // KARBONZOOMCONTROLLER_H