File indexing completed on 2024-04-28 04:42:11
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 KREPORTRULER_P_H 0024 #define KREPORTRULER_P_H 0025 0026 #include "KReportUnit.h" 0027 #include <QWidget> 0028 #include <QTextOption> 0029 0030 class KReportZoomHandler; 0031 0032 /** 0033 * Decorator widget to draw a single ruler around a canvas. 0034 */ 0035 class KReportRuler : public QWidget 0036 { 0037 Q_OBJECT 0038 public: 0039 /** 0040 * Creates a ruler with the orientation @a orientation 0041 * @param parent parent widget 0042 * @param orientation the orientation of the ruler 0043 * @param viewConverter the view converter used to convert from point to pixel 0044 */ 0045 KReportRuler(QWidget* parent, Qt::Orientation orientation, 0046 const KReportZoomHandler &zoomHandler); 0047 ~KReportRuler() override; 0048 0049 /// For paragraphs each tab definition is represented by this struct. 0050 struct Tab { 0051 inline Tab(qreal aPosition, QTextOption::TabType aType) : position(aPosition), type(aType) {} 0052 inline Tab() : position(0.0), type(QTextOption::LeftTab) {} 0053 qreal position; ///< distance in point from the start of the text-shape 0054 QTextOption::TabType type; ///< Determine which type is used. 0055 }; 0056 0057 /// The ruler's unit 0058 /// Default is Centimeter. 0059 KReportUnit unit() const; 0060 0061 /// The length of the ruler in points (pt) 0062 qreal rulerLength() const; 0063 0064 /// The orientation of the ruler 0065 Qt::Orientation orientation() const; 0066 0067 /// The start indent of the first line 0068 qreal firstLineIndent() const; 0069 0070 /// The start indent of the rest of the lines 0071 qreal paragraphIndent() const; 0072 0073 /// The end indent of all lines 0074 qreal endIndent() const; 0075 0076 /// The tab chooser widget, which you must put into a layout along with the ruler. 0077 /// Returns 0 for vertical rulers, 0078 QWidget *tabChooser(); 0079 0080 /** 0081 * set a list of actions that will be shown in a popup should the user right click on this ruler. 0082 * @param popupActionList the list of actions 0083 * @see popupActionList() 0084 */ 0085 void setPopupActionList(const QList<QAction*> &popupActionList); 0086 /** 0087 * Return the actions list. 0088 * @see setPopupActionList() 0089 */ 0090 QList<QAction*> popupActionList() const; 0091 0092 /// reimplemented 0093 QSize minimumSizeHint() const override; 0094 0095 /// reimplemented 0096 QSize sizeHint() const override; 0097 0098 class Private; 0099 0100 public Q_SLOTS: 0101 /// Set the unit of the ruler 0102 void setUnit(const KReportUnit &unit); 0103 0104 /** Set the offset. Use this function to sync the ruler with 0105 * the canvas' position on screen 0106 * @param offset The offset in pixels 0107 */ 0108 void setOffset(int offset); 0109 0110 /** 0111 * Sets the length of the ruler to @a length in points (pt) 0112 */ 0113 void setRulerLength(qreal length); 0114 0115 /** Set the active range, ie the part of the ruler that is most likely used. 0116 * set to 0, 0 when there is no longer any active range 0117 * @param start the start of the range in pt 0118 * @param end the end of the range in pt 0119 */ 0120 void setActiveRange(qreal start, qreal end); 0121 0122 /** Set the override active range, ie the part of the ruler that is most likely used. 0123 * set to 0, 0 when there is no longer any active range 0124 * The override, means that if set it takes precedence over the normal active range. 0125 * @param start the start of the range in pt 0126 * @param end the end of the range in pt 0127 */ 0128 void setOverrideActiveRange(qreal start, qreal end); 0129 0130 /** Set the state of the ruler so that it shows everything in right to left mode. 0131 * @param isRightToLeft state of right to left mode. Default is false. 0132 */ 0133 void setRightToLeft(bool isRightToLeft); 0134 0135 /** Set if the ruler should show indents as used in textditors. 0136 * Set the indents with setFirstLineIndent(), setParagraphIndent(), setEndIndent() . 0137 * @param show show indents if true. Default is false. 0138 */ 0139 void setShowIndents(bool show); 0140 0141 /** Set the position of the first line start indent relative to the active range. 0142 * If Right To left is set the indent is relative to the right side of the active range . 0143 * @param indent the value relative to the active range. 0144 */ 0145 void setFirstLineIndent(qreal indent); 0146 0147 /** Set the position of the rest of the lines start indent relative to the active range. 0148 * If Right To left is set the indent is relative to the right side of the active range . 0149 * @param indent the value relative to the active range. 0150 */ 0151 void setParagraphIndent(qreal indent); 0152 0153 /** Set the position of the end indent relative to the active range. 0154 * If Right To left is set the indent is relative to the left side of the active range . 0155 * @param indent the value relative to the active range. 0156 */ 0157 void setEndIndent(qreal indent); 0158 0159 /** Set whether the ruler should show the current mouse position. 0160 * Update the position with updateMouseCoordinate(). 0161 * @param show show mouse position if true. Default is false. 0162 */ 0163 void setShowMousePosition(bool show); 0164 0165 /** Update the current position of the mouse pointer, repainting if changed. 0166 * The ruler offset will be applied before painting. 0167 * @param coordinate Either the x or y coordinate of the mouse depending 0168 * of the orientation of the ruler. 0169 */ 0170 void updateMouseCoordinate(int coordinate); 0171 0172 /** 0173 * Set whether the ruler should show the selection borders 0174 * @param show show selection borders if true, default is false. 0175 */ 0176 void setShowSelectionBorders(bool show); 0177 0178 /** 0179 * Update the selection borders 0180 * @param first the first selection border in points 0181 * @param second the other selection border in points 0182 */ 0183 void updateSelectionBorders(qreal first, qreal second); 0184 0185 /** 0186 * Set whether the ruler should show tabs 0187 * @param show show selection borders if true, default is false. 0188 */ 0189 void setShowTabs(bool show); 0190 0191 /** 0192 * Set whether the tabs is relative to the paragraph indent 0193 * @param relative tabs are relative to pragraph indent if true, default is false. 0194 */ 0195 void setRelativeTabs(bool relative); 0196 0197 /** 0198 * Update the tabs 0199 * @param tabs a list of tabs that is shown on the ruler 0200 * @param tabDistance the distance between regular interval tabs 0201 */ 0202 void updateTabs(const QList<Tab> &tabs, qreal tabDistance); 0203 0204 /*** 0205 * Return the list of tabs set on this ruler. 0206 */ 0207 QList<Tab> tabs() const; 0208 0209 /** 0210 * Clear all previously set hotspots. 0211 * A hotspot is a position on the ruler that the user can manipulate by dragging. 0212 */ 0213 void clearHotSpots(); 0214 0215 /** 0216 * Add or set a hotspot. 0217 * A hotspot is a position on the ruler that the user can manipulate by dragging. 0218 * @param position the new position of the hotspot. 0219 * @param id the unique id for the hotspot. If the id has not been set before, it will be added. 0220 */ 0221 void setHotSpot(qreal position, int id = -1); 0222 0223 /** 0224 * Remove a previously set hotspot, returning true if one is actually returned. 0225 * @param id the unique id for the hotspot. 0226 * A hotspot is a position on the ruler that the user can manipulate by dragging. 0227 */ 0228 bool removeHotSpot(int id); 0229 0230 Q_SIGNALS: 0231 /** 0232 * emitted when any of the indents is moved by the user. 0233 * @param final false until the user releases the mouse. So you can implement live update. 0234 */ 0235 void indentsChanged(bool final); 0236 0237 /** 0238 * Emitted when any of the tabs are moved, deleted or inserted by the user. 0239 * @param originalTabIndex the index in the list of tabs before the user interaction 0240 * started, or -1 if this is a new tab 0241 * @param tab the new tab, or zero when the tab has been removed. 0242 */ 0243 void tabChanged(int originalTabIndex, KReportRuler::Tab *tab); 0244 0245 /// emitted when there the user is about to change a tab or hotspot 0246 void aboutToChange(); 0247 0248 void hotSpotChanged(int id, qreal newPosition); 0249 0250 /// emitted when the mouse is drag+released outside the ruler 0251 void guideLineCreated(Qt::Orientation orientation, qreal viewPosition); 0252 0253 protected: 0254 /// reimplemented 0255 void paintEvent(QPaintEvent* event) override; 0256 /// reimplemented 0257 void mousePressEvent(QMouseEvent *ev) override; 0258 /// reimplemented 0259 void mouseReleaseEvent(QMouseEvent *ev) override; 0260 /// reimplemented 0261 void mouseMoveEvent(QMouseEvent *ev) override; 0262 0263 private: 0264 Private * const d; 0265 friend class KReportRuler::Private; 0266 }; 0267 0268 #endif