File indexing completed on 2024-05-12 16:02:13
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 2004 Ariya Hidayat <ariya@kde.org> 0003 SPDX-FileCopyrightText: 2006 Peter Simonsson <peter.simonsson@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only 0006 */ 0007 0008 #ifndef KOZOOMACTION_H 0009 #define KOZOOMACTION_H 0010 0011 #include <kselectaction.h> 0012 #include <KoZoomMode.h> 0013 0014 #include "kritawidgets_export.h" 0015 0016 /** 0017 * Class KoZoomAction implements an action to provide zoom values. 0018 * In a toolbar, KoZoomAction will show a dropdown list (combobox), also with 0019 * the possibility for the user to enter arbitrary zoom value 0020 * (must be an integer). The values shown on the list are always 0021 * sorted. 0022 * In a statusbar it provides a scale (slider) plus an editable value plus 0023 * some buttons for special zoommodes 0024 */ 0025 class KRITAWIDGETS_EXPORT KoZoomAction : public KSelectAction 0026 { 0027 Q_OBJECT 0028 Q_PROPERTY(qreal effectiveZoom READ effectiveZoom NOTIFY zoomChanged) 0029 public: 0030 0031 /** 0032 * Creates a new zoom action. 0033 * @param zoomModes which zoom modes that should be shown 0034 * @param text The text that will be displayed. 0035 * @param parent The action's parent object. 0036 */ 0037 KoZoomAction( KoZoomMode::Modes zoomModes, const QString& text, QObject *parent); 0038 ~KoZoomAction() override; 0039 0040 /** 0041 * Reimplemented from QWidgetAction. 0042 */ 0043 QWidget* createWidget(QWidget* parent) override; 0044 0045 0046 qreal effectiveZoom() const; 0047 0048 public Q_SLOTS: 0049 0050 /** 0051 * Sets the zoom. If zoom not yet on the list of zoom values, it will be inserted 0052 * into the list at proper place so that the values remain sorted. 0053 * emits zoomChanged 0054 */ 0055 void setZoom( qreal zoom ); 0056 0057 /** 0058 * Change the zoom to a closer look than current 0059 * Zoom mode will be CONSTANT afterwards 0060 * emits zoomChanged 0061 */ 0062 void zoomIn( ); 0063 0064 /** 0065 * Change the zoom to a wider look than current 0066 * Zoom mode will be CONSTANT afterwards 0067 * emits zoomChanged 0068 */ 0069 void zoomOut( ); 0070 0071 /** 0072 * Set the actual zoom value used in the app. This is needed when using @ref zoomIn() , @ref zoomOut() and/or when 0073 * plugged into the viewbar. 0074 */ 0075 void setEffectiveZoom(qreal zoom); 0076 0077 /** 0078 * Change the selected zoom mode. 0079 */ 0080 void setSelectedZoomMode( KoZoomMode::Mode mode ); 0081 0082 /** 0083 * Change status of canvas size mapping button 0084 * (emits canvasMappingModeChanged(bool) after the change, ALWAYS) 0085 */ 0086 void setCanvasMappingMode(bool status); 0087 0088 /** 0089 * Returns next preferred zoom level that should be used for 0090 * zoom in operations. 0091 * 0092 * This can be used by the caller, when it needs some special 0093 * mode of zooming (e.g. relative to point) and needs 0094 * KoCanvasControllerWidget to accomplish this. 0095 */ 0096 qreal nextZoomLevel() const; 0097 0098 /** 0099 * Returns previous preferred zoom level that should be used for 0100 * zoom out operations. 0101 * 0102 * This can be used by the caller, when it needs some special 0103 * mode of zooming (e.g. relative to point) and needs 0104 * KoCanvasControllerWidget to accomplish this. 0105 */ 0106 qreal prevZoomLevel() const; 0107 0108 void slotUpdateZoomLevels(); 0109 0110 protected Q_SLOTS: 0111 0112 void triggered( const QString& text ); 0113 void sliderValueChanged(int value); 0114 void slotUpdateGuiAfterZoom(); 0115 0116 Q_SIGNALS: 0117 0118 /** 0119 * Signal zoomChanged is triggered when user changes the zoom value, either by 0120 * choosing it from the list or by entering new value. 0121 * @param mode The selected zoom mode 0122 * @param zoom the zoom, only defined if @p mode is KoZoomMode::ZOOM_CONSTANT 0123 */ 0124 void zoomChanged( KoZoomMode::Mode mode, qreal zoom ); 0125 0126 /** 0127 * Signal canvasMappingModeChanged is triggered when the user toggles the widget. 0128 * Nothing else happens except that this signal is emitted. 0129 * @param status Whether the special aspect mode is on 0130 */ 0131 void canvasMappingModeChanged( bool status ); 0132 0133 /** 0134 * Signal is triggered when the user clicks the zoom to selection button. 0135 * Nothing else happens except that this signal is emitted. 0136 */ 0137 void zoomedToSelection(); 0138 0139 /** 0140 * Signal is triggered when the user clicks the zoom to all button. 0141 * Nothing else happens except that this signal is emitted. 0142 */ 0143 void zoomedToAll(); 0144 0145 void sliderZoomLevelsChanged(int value); 0146 void zoomLevelsChanged(const QStringList &values); 0147 void currentZoomLevelChanged(const QString &valueString); 0148 void sliderChanged(int value); 0149 0150 public: 0151 /** 0152 * Return the minimum zoom possible for documents. 0153 * 0154 * \return The minimum zoom possible. 0155 */ 0156 qreal minimumZoom(); 0157 /** 0158 * Return the maximum zoom possible for documents. 0159 * 0160 * \return The maximum zoom possible. 0161 */ 0162 qreal maximumZoom(); 0163 /** 0164 * Clamp the zoom value so that mimimumZoom <= zoom <= maximumZoom. 0165 * 0166 * \param zoom The value to clamp. 0167 * 0168 * \return minimumZoom if zoom < minimumZoom, maximumZoom if zoom > 0169 * maximumZoom, zoom if otherwise. 0170 */ 0171 qreal clampZoom(qreal zoom); 0172 0173 /** 0174 * Set the minimum zoom possible for documents. 0175 * 0176 * Note that after calling this, any existing KoZoomAction instances 0177 * should be recreated. 0178 * 0179 * \param zoom The minimum zoom to use. 0180 */ 0181 void setMinimumZoom(qreal zoom); 0182 /** 0183 * Set the maximum zoom possible for documents. 0184 * 0185 * Note that after calling this, any existing KoZoomAction instances 0186 * should be recreated. 0187 * 0188 * \param zoom The maximum zoom to use. 0189 */ 0190 void setMaximumZoom(qreal zoom); 0191 0192 protected: 0193 /// Regenerates the action's items 0194 void regenerateItems( const qreal zoom); 0195 0196 private: 0197 void syncSliderWithZoom(); 0198 0199 Q_DISABLE_COPY( KoZoomAction ) 0200 0201 class Private; 0202 Private * const d; 0203 }; 0204 0205 #endif