Warning, file /office/calligra/libs/widgets/KoZoomAction.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 libraries
0002     Copyright (C) 2004 Ariya Hidayat <ariya@kde.org>
0003     Copyright (C) 2006 Peter Simonsson <peter.simonsson@gmail.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 version 2 as published by the Free Software Foundation.
0008 
0009     This library is distributed in the hope that it will be useful,
0010     but WITHOUT ANY WARRANTY; without even the implied warranty of
0011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012     Library General Public License for more details.
0013 
0014     You should have received a copy of the GNU Library General Public License
0015     along with this library; see the file COPYING.LIB.  If not, write to
0016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017     Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KOZOOMACTION_H
0021 #define KOZOOMACTION_H
0022 
0023 #include <kselectaction.h>
0024 #include <KoZoomMode.h>
0025 
0026 #include "kowidgets_export.h"
0027 
0028 /**
0029  * Class KoZoomAction implements an action to provide zoom values.
0030  * In a toolbar, KoZoomAction will show a dropdown list (combobox), also with
0031  * the possibility for the user to enter arbritrary zoom value
0032  * (must be an integer). The values shown on the list are always
0033  * sorted.
0034  * In a statusbar it provides a scale (slider) plus an editable value plus
0035  * some buttons for special zoommodes
0036  */
0037 class KOWIDGETS_EXPORT KoZoomAction : public KSelectAction
0038 {
0039     Q_OBJECT
0040     Q_PROPERTY(qreal effectiveZoom READ effectiveZoom NOTIFY zoomChanged)
0041 public:
0042 
0043   /**
0044    * Creates a new zoom action.
0045    * @param zoomModes which zoom modes that should be shown
0046    * @param text The text that will be displayed.
0047    * @param parent The action's parent object.
0048    */
0049     KoZoomAction( KoZoomMode::Modes zoomModes, const QString& text, QObject *parent);
0050     ~KoZoomAction() override;
0051 
0052     /**
0053      * Reimplemented from QWidgetAction.
0054      */
0055     QWidget* createWidget(QWidget* parent) override;
0056 
0057     enum SpecialButton {
0058         AspectMode = 1, ///< changing aspect mode
0059         ZoomToSelection = 2, ///< zooms to current selection
0060         ZoomToAll = 4 ///< zooms to the whole content of the document
0061     };
0062     Q_DECLARE_FLAGS(SpecialButtons, SpecialButton)
0063 
0064     /**
0065      * Enables specified special buttons.
0066      * This should be called immediately after calling the constructor.
0067      * @param buttons mask of the special button flags to enable
0068      */
0069     void setSpecialButtons( SpecialButtons buttons );
0070 
0071     qreal effectiveZoom() const;
0072 
0073 public Q_SLOTS:
0074 
0075   /**
0076    * Sets the zoom. If zoom not yet on the list of zoom values, it will be inserted
0077    * into the list at proper place so that the values remain sorted.
0078    * emits zoomChanged
0079    */
0080     void setZoom( qreal zoom );
0081 
0082   /**
0083    * Change the zoom modes that should be shown
0084    */
0085     void setZoomModes( KoZoomMode::Modes zoomModes );
0086 
0087   /**
0088    * Change the zoom to a closer look than current
0089    * Zoom mode will be CONSTANT afterwards
0090    * emits zoomChanged
0091    */
0092     void zoomIn( );
0093 
0094   /**
0095    * Change the zoom to a wider look than current
0096    * Zoom mode will be CONSTANT afterwards
0097    * emits zoomChanged
0098    */
0099     void zoomOut( );
0100 
0101   /**
0102    * Set the actual zoom value used in the app. This is needed when using @ref zoomIn() , @ref zoomOut() and/or when
0103    * plugged into the viewbar.
0104    */
0105     void setEffectiveZoom(qreal zoom);
0106 
0107   /**
0108    * Change the selected zoom mode.
0109    */
0110     void setSelectedZoomMode( KoZoomMode::Mode mode );
0111 
0112   /**
0113    * Change status of "Use same aspect as pixels" button
0114    * (emits aspectModeChanged(bool) after the change, ALWAYS)
0115    */
0116     void setAspectMode(bool status);
0117 
0118     /**
0119      * Returns next preferred zoom level that should be used for
0120      * zoom in operations.
0121      *
0122      * This can be used by the caller, when it needs some special
0123      * mode of zooming (e.g. relative to point) and needs
0124      * KoCanvasControllerWidget to accomplish this.
0125      */
0126     qreal nextZoomLevel() const;
0127 
0128     /**
0129      * Returns previous preferred zoom level that should be used for
0130      * zoom out operations.
0131      *
0132      * This can be used by the caller, when it needs some special
0133      * mode of zooming (e.g. relative to point) and needs
0134      * KoCanvasControllerWidget to accomplish this.
0135      */
0136     qreal prevZoomLevel() const;
0137 
0138 protected Q_SLOTS:
0139 
0140     void triggered( const QString& text );
0141     void sliderValueChanged(int value);
0142 
0143 Q_SIGNALS:
0144 
0145   /**
0146    * Signal zoomChanged is triggered when user changes the zoom value, either by
0147    * choosing it from the list or by entering new value.
0148    * @param mode The selected zoom mode
0149    * @param zoom the zoom, only defined if @p mode is KoZoomMode::ZOOM_CONSTANT
0150    */
0151     void zoomChanged( KoZoomMode::Mode mode, qreal zoom );
0152 
0153   /**
0154    * Signal aspectModeChanged is triggered when the user toggles the widget.
0155    * Nothing else happens except that this signal is emitted.
0156    * @param status Whether the special aspect mode is on
0157    */
0158     void aspectModeChanged( bool status );
0159 
0160     /**
0161      * Signal is triggered when the user clicks the zoom to selection button.
0162      * Nothing else happens except that this signal is emitted.
0163      */
0164     void zoomedToSelection();
0165 
0166     /**
0167      * Signal is triggered when the user clicks the zoom to all button.
0168      * Nothing else happens except that this signal is emitted.
0169      */
0170     void zoomedToAll();
0171 
0172     void zoomLevelsChanged(const QStringList &values);
0173     void currentZoomLevelChanged(const QString &valueString);
0174     void sliderChanged(int value);
0175 
0176 public:
0177     /**
0178      * Return the minimum zoom possible for documents.
0179      *
0180      * \return The minimum zoom possible.
0181      */
0182     qreal minimumZoom();
0183     /**
0184      * Return the maximum zoom possible for documents.
0185      *
0186      * \return The maximum zoom possible.
0187      */
0188     qreal maximumZoom();
0189     /**
0190      * Clamp the zoom value so that mimimumZoom <= zoom <= maximumZoom.
0191      *
0192      * \param zoom The value to clamp.
0193      *
0194      * \return minimumZoom if zoom < minimumZoom, maximumZoom if zoom >
0195      * maximumZoom, zoom if otherwise.
0196      */
0197     qreal clampZoom(qreal zoom);
0198 
0199     /**
0200      * Set the minimum zoom possible for documents.
0201      *
0202      * Note that after calling this, any existing KoZoomAction instances
0203      * should be recreated.
0204      *
0205      * \param zoom The minimum zoom to use.
0206      */
0207     void setMinimumZoom(qreal zoom);
0208     /**
0209      * Set the maximum zoom possible for documents.
0210      *
0211      * Note that after calling this, any existing KoZoomAction instances
0212      * should be recreated.
0213      *
0214      * \param zoom The maximum zoom to use.
0215      */
0216     void setMaximumZoom(qreal zoom);
0217 
0218 protected:
0219     /// Regenerates the action's items
0220     void regenerateItems( const qreal zoom, bool asCurrent = false );
0221 
0222 private:
0223     void syncSliderWithZoom();
0224 
0225     Q_DISABLE_COPY( KoZoomAction )
0226 
0227     class Private;
0228     Private * const d;
0229 };
0230 
0231 Q_DECLARE_OPERATORS_FOR_FLAGS(KoZoomAction::SpecialButtons)
0232 
0233 #endif