Warning, file /office/calligra/libs/widgets/KoRuler_p.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) 2007 Thomas Zander <zander@kde.org>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
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 #ifndef KORULER_P_H
0020 #define KORULER_P_H
0021 
0022 #include <KoUnit.h>
0023 
0024 class RulerTabChooser : public QWidget
0025 {
0026 Q_OBJECT
0027 public:
0028     RulerTabChooser(QWidget *parent) : QWidget(parent), m_type(QTextOption::LeftTab), m_showTabs(false) {}
0029     ~RulerTabChooser() override {}
0030 
0031     inline QTextOption::TabType type() {return m_type;}
0032     void setShowTabs(bool showTabs) { if (m_showTabs == showTabs) return; m_showTabs = showTabs; update(); }
0033     void mousePressEvent(QMouseEvent *) override;
0034 
0035     void paintEvent(QPaintEvent *) override;
0036 
0037 private:
0038     QTextOption::TabType m_type;
0039     bool m_showTabs :1;
0040 };
0041 
0042 class PaintingStrategy
0043 {
0044 public:
0045     /// constructor
0046     PaintingStrategy() {}
0047     /// destructor
0048     virtual ~PaintingStrategy() {}
0049 
0050     /**
0051      * Draw the background of the ruler.
0052      * @param ruler the ruler to draw on.
0053      * @param painter the painter we can paint with.
0054      */
0055     virtual QRectF drawBackground(const KoRulerPrivate *ruler, QPainter &painter) = 0;
0056 
0057     /**
0058      * Draw the indicators for text-tabs.
0059      * @param ruler the ruler to draw on.
0060      * @param painter the painter we can paint with.
0061      */
0062     virtual void drawTabs(const KoRulerPrivate *ruler, QPainter &painter) = 0;
0063 
0064     /**
0065      * Draw the indicators for the measurements which typically are drawn every [unit].
0066      * @param ruler the ruler to draw on.
0067      * @param painter the painter we can paint with.
0068      * @param rectangle
0069      */
0070     virtual void drawMeasurements(const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle) = 0;
0071 
0072     /**
0073      * Draw the indicators for the indents of a text paragraph
0074      * @param ruler the ruler to draw on.
0075      * @param painter the painter we can paint with.
0076      */
0077     virtual void drawIndents(const KoRulerPrivate *ruler, QPainter &painter) = 0;
0078 
0079     /**
0080      *returns the size suggestion for a ruler with this strategy.
0081      */
0082     virtual QSize sizeHint() = 0;
0083 };
0084 
0085 class HorizontalPaintingStrategy : public PaintingStrategy
0086 {
0087 public:
0088     HorizontalPaintingStrategy() : lengthInPixel(1) {}
0089 
0090     QRectF drawBackground(const KoRulerPrivate *ruler, QPainter &painter) override;
0091     void drawTabs(const KoRulerPrivate *ruler, QPainter &painter) override;
0092     void drawMeasurements(const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle) override;
0093     void drawIndents(const KoRulerPrivate *ruler, QPainter &painter) override;
0094     QSize sizeHint() override;
0095 
0096 private:
0097     qreal lengthInPixel;
0098 };
0099 
0100 class VerticalPaintingStrategy : public PaintingStrategy
0101 {
0102 public:
0103     VerticalPaintingStrategy() : lengthInPixel(1) {}
0104 
0105     QRectF drawBackground(const KoRulerPrivate *ruler, QPainter &painter) override;
0106     void drawTabs(const KoRulerPrivate *, QPainter &) override {}
0107     void drawMeasurements(const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle) override;
0108     void drawIndents(const KoRulerPrivate *, QPainter &) override { }
0109     QSize sizeHint() override;
0110 
0111 private:
0112     qreal lengthInPixel;
0113 };
0114 
0115 class HorizontalDistancesPaintingStrategy : public HorizontalPaintingStrategy
0116 {
0117 public:
0118     HorizontalDistancesPaintingStrategy() {}
0119 
0120     void drawMeasurements(const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle) override;
0121 
0122 private:
0123     void drawDistanceLine(const KoRulerPrivate *d, QPainter &painter, const qreal start, const qreal end);
0124 };
0125 
0126 class KoRulerPrivate
0127 {
0128 public:
0129     KoRulerPrivate(KoRuler *parent, const KoViewConverter *vc, Qt::Orientation orientation);
0130     ~KoRulerPrivate();
0131 
0132     void emitTabChanged();
0133 
0134     KoUnit unit;
0135     const Qt::Orientation orientation;
0136     const KoViewConverter * const viewConverter;
0137 
0138     int offset;
0139     qreal rulerLength;
0140     qreal activeRangeStart;
0141     qreal activeRangeEnd;
0142     qreal activeOverrideRangeStart;
0143     qreal activeOverrideRangeEnd;
0144 
0145     int mouseCoordinate;
0146     int showMousePosition;
0147 
0148     bool showSelectionBorders;
0149     qreal firstSelectionBorder;
0150     qreal secondSelectionBorder;
0151 
0152     bool showIndents;
0153     qreal firstLineIndent;
0154     qreal paragraphIndent;
0155     qreal endIndent;
0156 
0157     bool showTabs;
0158     bool relativeTabs;
0159     bool tabMoved; // set to true on first move of a selected tab
0160     QList<KoRuler::Tab> tabs;
0161     int originalIndex; //index of selected tab before we started dragging it.
0162     int currentIndex; //index of selected tab or selected HotSpot - only valid when selected indicates tab or hotspot
0163     KoRuler::Tab deletedTab;
0164     qreal tabDistance;
0165 
0166     struct HotSpotData {
0167         qreal position;
0168         int id;
0169     };
0170     QList<HotSpotData> hotspots;
0171 
0172     bool rightToLeft;
0173     enum Selection {
0174         None,
0175         Tab,
0176         FirstLineIndent,
0177         ParagraphIndent,
0178         EndIndent,
0179         HotSpot
0180     };
0181     Selection selected;
0182     int selectOffset;
0183 
0184     QList<QAction*> popupActions;
0185 
0186     RulerTabChooser *tabChooser;
0187 
0188     // Cached painting strategies
0189     PaintingStrategy * normalPaintingStrategy;
0190     PaintingStrategy * distancesPaintingStrategy;
0191 
0192     // Current painting strategy
0193     PaintingStrategy * paintingStrategy;
0194 
0195     KoRuler *ruler;
0196 
0197     qreal numberStepForUnit() const;
0198     /// @return The rounding of value to the nearest multiple of stepValue
0199     qreal doSnapping(const qreal value) const;
0200     Selection selectionAtPosition(const QPoint & pos, int *selectOffset = 0);
0201     int hotSpotIndex(const QPoint & pos);
0202     qreal effectiveActiveRangeStart() const;
0203     qreal effectiveActiveRangeEnd() const;
0204 
0205     friend class VerticalPaintingStrategy;
0206     friend class HorizontalPaintingStrategy;
0207 };
0208 
0209 #endif