1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
/* This file is part of the KDE project
* Copyright (C) 2007 Thomas Zander <zander@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KORULER_P_H
#define KORULER_P_H
#include <KoUnit.h>
class RulerTabChooser : public QWidget
{
Q_OBJECT
public:
RulerTabChooser(QWidget *parent) : QWidget(parent), m_type(QTextOption::LeftTab), m_showTabs(false) {}
virtual ~RulerTabChooser() {}
inline QTextOption::TabType type() {return m_type;}
void setShowTabs(bool showTabs) { if (m_showTabs == showTabs) return; m_showTabs = showTabs; update(); }
void mousePressEvent(QMouseEvent *);
void paintEvent(QPaintEvent *);
private:
QTextOption::TabType m_type;
bool m_showTabs :1;
};
class PaintingStrategy
{
public:
/// constructor
PaintingStrategy() {}
/// destructor
virtual ~PaintingStrategy() {}
/**
* Draw the background of the ruler.
* @param ruler the ruler to draw on.
* @param painter the painter we can paint with.
*/
virtual QRectF drawBackground(const KoRulerPrivate *ruler, QPainter &painter) = 0;
/**
* Draw the indicators for text-tabs.
* @param ruler the ruler to draw on.
* @param painter the painter we can paint with.
*/
virtual void drawTabs(const KoRulerPrivate *ruler, QPainter &painter) = 0;
/**
* Draw the indicators for the measurements which typically are drawn every [unit].
* @param ruler the ruler to draw on.
* @param painter the painter we can paint with.
* @param rectangle
*/
virtual void drawMeasurements(const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle) = 0;
/**
* Draw the indicators for the indents of a text paragraph
* @param ruler the ruler to draw on.
* @param painter the painter we can paint with.
*/
virtual void drawIndents(const KoRulerPrivate *ruler, QPainter &painter) = 0;
/**
*returns the size suggestion for a ruler with this strategy.
*/
virtual QSize sizeHint() = 0;
};
class HorizontalPaintingStrategy : public PaintingStrategy
{
public:
HorizontalPaintingStrategy() : lengthInPixel(1) {}
virtual QRectF drawBackground(const KoRulerPrivate *ruler, QPainter &painter);
virtual void drawTabs(const KoRulerPrivate *ruler, QPainter &painter);
virtual void drawMeasurements(const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle);
virtual void drawIndents(const KoRulerPrivate *ruler, QPainter &painter);
virtual QSize sizeHint();
private:
qreal lengthInPixel;
};
class VerticalPaintingStrategy : public PaintingStrategy
{
public:
VerticalPaintingStrategy() : lengthInPixel(1) {}
virtual QRectF drawBackground(const KoRulerPrivate *ruler, QPainter &painter);
virtual void drawTabs(const KoRulerPrivate *, QPainter &) {}
virtual void drawMeasurements(const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle);
virtual void drawIndents(const KoRulerPrivate *, QPainter &) { }
virtual QSize sizeHint();
private:
qreal lengthInPixel;
};
class HorizontalDistancesPaintingStrategy : public HorizontalPaintingStrategy
{
public:
HorizontalDistancesPaintingStrategy() {}
virtual void drawMeasurements(const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle);
private:
void drawDistanceLine(const KoRulerPrivate *d, QPainter &painter, const qreal start, const qreal end);
};
class KoRulerPrivate
{
public:
KoRulerPrivate(KoRuler *parent, const KoViewConverter *vc, Qt::Orientation orientation);
~KoRulerPrivate();
void emitTabChanged();
KoUnit unit;
const Qt::Orientation orientation;
const KoViewConverter * const viewConverter;
int offset;
qreal rulerLength;
qreal activeRangeStart;
qreal activeRangeEnd;
qreal activeOverrideRangeStart;
qreal activeOverrideRangeEnd;
int mouseCoordinate;
int showMousePosition;
bool showSelectionBorders;
qreal firstSelectionBorder;
qreal secondSelectionBorder;
bool showIndents;
qreal firstLineIndent;
qreal paragraphIndent;
qreal endIndent;
bool showTabs;
bool relativeTabs;
bool tabMoved; // set to true on first move of a selected tab
QList<KoRuler::Tab> tabs;
int originalIndex; //index of selected tab before we started dragging it.
int currentIndex; //index of selected tab or selected HotSpot - only valid when selected indicates tab or hotspot
KoRuler::Tab deletedTab;
qreal tabDistance;
struct HotSpotData {
qreal position;
int id;
};
QList<HotSpotData> hotspots;
bool rightToLeft;
enum Selection {
None,
Tab,
FirstLineIndent,
ParagraphIndent,
EndIndent,
HotSpot
};
Selection selected;
int selectOffset;
QList<QAction*> popupActions;
RulerTabChooser *tabChooser;
// Cached painting strategies
PaintingStrategy * normalPaintingStrategy;
PaintingStrategy * distancesPaintingStrategy;
// Current painting strategy
PaintingStrategy * paintingStrategy;
KoRuler *ruler;
qreal numberStepForUnit() const;
/// @return The rounding of value to the nearest multiple of stepValue
qreal doSnapping(const qreal value) const;
Selection selectionAtPosition(const QPoint & pos, int *selectOffset = 0);
int hotSpotIndex(const QPoint & pos);
qreal effectiveActiveRangeStart() const;
qreal effectiveActiveRangeEnd() const;
friend class VerticalPaintingStrategy;
friend class HorizontalPaintingStrategy;
};
#endif
|