Warning, file /office/calligra/libs/widgets/KoRuler.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) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
0003    Copyright (C) 2006 Peter Simonsson <peter.simonsson@gmail.com>
0004    Copyright (C) 2007 C. Boemann <cbo@boemann.dk>
0005    Copyright (C) 2007 Thomas Zander <zander@kde.org>
0006 
0007    This library is free software; you can redistribute it and/or
0008    modify it under the terms of the GNU Library General Public
0009    License as published by the Free Software Foundation; either
0010    version 2 of the License, or (at your option) any later version.
0011 
0012    This library is distributed in the hope that it will be useful,
0013    but WITHOUT ANY WARRANTY; without even the implied warranty of
0014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015    Library General Public License for more details.
0016 
0017    You should have received a copy of the GNU Library General Public License
0018    along with this library; see the file COPYING.LIB.  If not, write to
0019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020    Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #ifndef koRuler_h
0024 #define koRuler_h
0025 
0026 
0027 #include "kowidgets_export.h"
0028 
0029 #include <QWidget>
0030 #include <QTextOption>
0031 
0032 class QPaintEvent;
0033 
0034 class KoViewConverter;
0035 class KoCanvasBase;
0036 class KoRulerPrivate;
0037 class KoUnit;
0038 
0039 /**
0040  * Decorator widget to draw a single ruler around a canvas.
0041  */
0042 class KOWIDGETS_EXPORT KoRuler : public QWidget
0043 {
0044 Q_OBJECT
0045 public:
0046     /**
0047      * Creates a ruler with the orientation @p orientation
0048      * @param parent parent widget
0049      * @param orientation the orientation of the ruler
0050      * @param viewConverter the view converter used to convert from point to pixel
0051      */
0052     KoRuler(QWidget* parent, Qt::Orientation orientation, const KoViewConverter* viewConverter);
0053     ~KoRuler() override;
0054 
0055     /// For paragraphs each tab definition is represented by this struct.
0056     struct Tab {
0057         qreal position;    ///< distance in point from the start of the text-shape
0058         QTextOption::TabType type;       ///< Determine which type is used.
0059     };
0060 
0061     /// The ruler's unit
0062     KoUnit unit() const;
0063 
0064     /// The length of the ruler in points (pt)
0065     qreal rulerLength() const;
0066 
0067     /// The orientation of the ruler
0068     Qt::Orientation orientation() const;
0069 
0070     /// The start indent of the first line
0071     qreal firstLineIndent() const;
0072 
0073     /// The start indent of the rest of the lines
0074     qreal paragraphIndent() const;
0075 
0076     /// The end indent of all lines
0077     qreal endIndent() const;
0078 
0079     /// The tab chooser widget, which you must put into a layout along with the ruler.
0080     /// Returns 0 for vertical rulers,
0081     QWidget *tabChooser();
0082 
0083     /**
0084      * set a list of actions that will be shown in a popup should the user right click on this ruler.
0085      * @param popupActionList the list of actions
0086      * @see popupActionList()
0087      */
0088     void setPopupActionList(const QList<QAction*> &popupActionList);
0089     /**
0090      * Return the actions list.
0091      * @see setPopupActionList()
0092      */
0093     QList<QAction*> popupActionList() const;
0094 
0095     /// reimplemented
0096     QSize minimumSizeHint() const override;
0097 
0098     /// reimplemented
0099     QSize sizeHint() const override;
0100 
0101 public Q_SLOTS:
0102     /// Set the unit of the ruler
0103     void setUnit(const KoUnit &unit);
0104 
0105     /** Set the offset. Use this function to sync the ruler with
0106       * the canvas' position on screen
0107       * @param offset The offset in pixels
0108       */
0109     void setOffset(int offset);
0110 
0111     /// Sets the length of the ruler to @p length in points (pt)
0112     void setRulerLength(qreal length);
0113 
0114     /** Set the active range, ie the part of the ruler that is most likely used.
0115       * set to 0, 0 when there is no longer any active range
0116       * @param start the start of the range in pt
0117       * @param end the end of the range in pt
0118       */
0119     void setActiveRange(qreal start, qreal end);
0120 
0121     /** Set the override active range, ie the part of the ruler that is most likely used.
0122       * set to 0, 0 when there is no longer any active range
0123       * The override, means that if set it takes precedence over the normal active range.
0124       * @param start the start of the range in pt
0125       * @param end the end of the range in pt
0126       */
0127     void setOverrideActiveRange(qreal start, qreal end);
0128 
0129     /** Set the state of the ruler so that it shows everything in right to left mode.
0130       * @param isRightToLeft state of right to left mode. Default is false.
0131       */
0132     void setRightToLeft(bool isRightToLeft);
0133 
0134     /** Set if the ruler should show indents as used in textditors.
0135       * Set the indents with setFirstLineIndent(), setParagraphIndent(), setEndIndent() .
0136       * @param show show indents if true. Default is false.
0137       */
0138     void setShowIndents(bool show);
0139 
0140     /** Set the position of the first line start indent relative to the active range.
0141       * If Right To left is set the indent is relative to the right side of the active range .
0142       * @param indent the value relative to the active range.
0143       */
0144     void setFirstLineIndent(qreal indent);
0145 
0146     /** Set the position of the rest of the lines start indent relative to the active range.
0147       * If Right To left is set the indent is relative to the right side of the active range .
0148       * @param indent the value relative to the active range.
0149       */
0150     void setParagraphIndent(qreal indent);
0151 
0152     /** Set the position of the end indent relative to the active range.
0153       * If Right To left is set the indent is relative to the left side of the active range .
0154       * @param indent the value relative to the active range.
0155       */
0156     void setEndIndent(qreal indent);
0157 
0158     /** Set whether the ruler should show the current mouse position.
0159       * Update the position with updateMouseCoordinate().
0160       * @param show show mouse position if true. Default is false.
0161       */
0162     void setShowMousePosition(bool show);
0163 
0164     /** Update the current position of the mouse pointer, repainting if changed.
0165       * The ruler offset will be applied before painting.
0166       * @param coordinate Either the x or y coordinate of the mouse depending
0167       *                   of the orientation of the ruler.
0168       */
0169     void updateMouseCoordinate(int coordinate);
0170 
0171     /**
0172      * Set whether the ruler should show the selection borders
0173      * @param show show selection borders if true, default is false.
0174      */
0175     void setShowSelectionBorders(bool show);
0176 
0177     /**
0178      * Update the selection borders
0179      * @param first the first selection border in points
0180      * @param second the other selection border in points
0181      */
0182     void updateSelectionBorders(qreal first, qreal second);
0183 
0184     /**
0185      * Set whether the ruler should show tabs
0186      * @param show show selection borders if true, default is false.
0187      */
0188     void setShowTabs(bool show);
0189 
0190     /**
0191      * Set whether the tabs is relative to the paragraph indent
0192      * @param relative tabs are relative to pragraph indent if true, default is false.
0193      */
0194     void setRelativeTabs(bool relative);
0195 
0196     /**
0197      * Update the tabs
0198      * @param tabs a list of tabs that is shown on the ruler
0199      * @param tabDistance the distance between regular interval tabs
0200      */
0201     void updateTabs(const QList<Tab> &tabs, qreal tabDistance);
0202 
0203     /***
0204      * Return the list of tabs set on this ruler.
0205      */
0206     QList<Tab> tabs() const;
0207 
0208     /**
0209      * Clear all previously set hotspots.
0210      * A hotspot is a position on the ruler that the user can manipulate by dragging.
0211      */
0212     void clearHotSpots();
0213 
0214     /**
0215      * Add or set a hotspot.
0216      * A hotspot is a position on the ruler that the user can manipulate by dragging.
0217      * @param position the new position of the hotspot.
0218      * @param id the unique id for the hotspot. If the id has not been set before, it will be added.
0219      */
0220     void setHotSpot(qreal position, int id = -1);
0221 
0222     /**
0223      * Remove a previously set hotspot, returning true if one is actually returned.
0224      * @param id the unique id for the hotspot.
0225      * A hotspot is a position on the ruler that the user can manipulate by dragging.
0226      */
0227     bool removeHotSpot(int id);
0228 
0229     /**
0230      * Connect the ruler to a guides tool
0231      * This allows the user to drag a guide out of the ruler and get in one smooth operation
0232      * the guide tool to draw and position the guide line.
0233      * @param canvas the canvas that has had the KoToolManager create the tool for previously.
0234      */
0235     void createGuideToolConnection(KoCanvasBase *canvas);
0236 
0237 Q_SIGNALS:
0238     /**
0239      * emitted when any of the indents is moved by the user.
0240      * @param final false until the user releases the mouse. So you can implement live update.
0241      */
0242     void indentsChanged(bool final);
0243 
0244     /**
0245      * Emitted when any of the tabs are moved, deleted or inserted by the user.
0246      * @param originalTabIndex the index in the list of tabs before the user interaction
0247      *          started, or -1 if this is a new tab
0248      * @param tab the new tab, or zero when the tab has been removed.
0249      */
0250     void tabChanged(int originalTabIndex, KoRuler::Tab *tab);
0251 
0252     /// emitted when there the user is about to change a tab or hotspot
0253     void aboutToChange();
0254 
0255     void hotSpotChanged(int id, qreal newPosition);
0256 
0257     /// emitted when the mouse is drag+released outside the ruler
0258     void guideLineCreated(Qt::Orientation orientation, qreal viewPosition);
0259 
0260 protected:
0261     /// reimplemented
0262     void paintEvent(QPaintEvent* event) override;
0263     /// reimplemented
0264     void mousePressEvent(QMouseEvent *ev) override;
0265     /// reimplemented
0266     void mouseReleaseEvent(QMouseEvent *ev) override;
0267     /// reimplemented
0268     void mouseMoveEvent(QMouseEvent *ev) override;
0269 
0270 private:
0271     KoRulerPrivate * const d;
0272     friend class KoRulerPrivate;
0273 };
0274 
0275 #endif