Changeset View
Changeset View
Standalone View
Standalone View
src/wrtembed/KReportRuler_p.h
Show All 22 Lines | |||||
23 | #ifndef KREPORTRULER_P_H | 23 | #ifndef KREPORTRULER_P_H | ||
24 | #define KREPORTRULER_P_H | 24 | #define KREPORTRULER_P_H | ||
25 | 25 | | |||
26 | #include "KReportUnit.h" | 26 | #include "KReportUnit.h" | ||
27 | #include <QWidget> | 27 | #include <QWidget> | ||
28 | #include <QTextOption> | 28 | #include <QTextOption> | ||
29 | 29 | | |||
30 | class KReportZoomHandler; | 30 | class KReportZoomHandler; | ||
31 | class KReportRulerPrivate; | | |||
32 | | ||||
33 | class RulerTabChooser : public QWidget | | |||
34 | { | | |||
35 | public: | | |||
36 | RulerTabChooser(QWidget *parent) : QWidget(parent), m_type(QTextOption::LeftTab), m_showTabs(false) {} | | |||
37 | virtual ~RulerTabChooser() {} | | |||
38 | | ||||
39 | inline QTextOption::TabType type() {return m_type;} | | |||
40 | void setShowTabs(bool showTabs) { if (m_showTabs == showTabs) return; m_showTabs = showTabs; update(); } | | |||
41 | void mousePressEvent(QMouseEvent *); | | |||
42 | | ||||
43 | void paintEvent(QPaintEvent *); | | |||
44 | | ||||
45 | private: | | |||
46 | QTextOption::TabType m_type; | | |||
47 | bool m_showTabs :1; | | |||
48 | }; | | |||
49 | | ||||
50 | class PaintingStrategy | | |||
51 | { | | |||
52 | public: | | |||
53 | /// constructor | | |||
54 | PaintingStrategy() {} | | |||
55 | /// destructor | | |||
56 | virtual ~PaintingStrategy() {} | | |||
57 | | ||||
58 | /** | | |||
59 | * Draw the background of the ruler. | | |||
60 | * @param ruler the ruler to draw on. | | |||
61 | * @param painter the painter we can paint with. | | |||
62 | */ | | |||
63 | virtual QRectF drawBackground(const KReportRulerPrivate *ruler, QPainter *painter) = 0; | | |||
64 | | ||||
65 | /** | | |||
66 | * Draw the indicators for text-tabs. | | |||
67 | * @param ruler the ruler to draw on. | | |||
68 | * @param painter the painter we can paint with. | | |||
69 | */ | | |||
70 | virtual void drawTabs(const KReportRulerPrivate *ruler, QPainter *painter) = 0; | | |||
71 | | ||||
72 | /** | | |||
73 | * Draw the indicators for the measurements which typically are drawn every [unit]. | | |||
74 | * @param ruler the ruler to draw on. | | |||
75 | * @param painter the painter we can paint with. | | |||
76 | * @param rectangle | | |||
77 | */ | | |||
78 | virtual void drawMeasurements(const KReportRulerPrivate *ruler, QPainter *painter, const QRectF &rectangle) = 0; | | |||
79 | | ||||
80 | /** | | |||
81 | * Draw the indicators for the indents of a text paragraph | | |||
82 | * @param ruler the ruler to draw on. | | |||
83 | * @param painter the painter we can paint with. | | |||
84 | */ | | |||
85 | virtual void drawIndents(const KReportRulerPrivate *ruler, QPainter *painter) = 0; | | |||
86 | | ||||
87 | /** | | |||
88 | *returns the size suggestion for a ruler with this strategy. | | |||
89 | */ | | |||
90 | virtual QSize sizeHint() = 0; | | |||
91 | }; | | |||
92 | | ||||
93 | class HorizontalPaintingStrategy : public PaintingStrategy | | |||
94 | { | | |||
95 | public: | | |||
96 | HorizontalPaintingStrategy() : lengthInPixel(1) {} | | |||
97 | | ||||
98 | virtual QRectF drawBackground(const KReportRulerPrivate *ruler, QPainter *painter); | | |||
99 | virtual void drawTabs(const KReportRulerPrivate *ruler, QPainter *painter); | | |||
100 | virtual void drawMeasurements(const KReportRulerPrivate *ruler, QPainter *painter, const QRectF &rectangle); | | |||
101 | virtual void drawIndents(const KReportRulerPrivate *ruler, QPainter *painter); | | |||
102 | virtual QSize sizeHint(); | | |||
103 | | ||||
104 | private: | | |||
105 | qreal lengthInPixel; | | |||
106 | }; | | |||
107 | | ||||
108 | class VerticalPaintingStrategy : public PaintingStrategy | | |||
109 | { | | |||
110 | public: | | |||
111 | VerticalPaintingStrategy() : lengthInPixel(1) {} | | |||
112 | | ||||
113 | virtual QRectF drawBackground(const KReportRulerPrivate *ruler, QPainter *painter); | | |||
114 | virtual void drawTabs(const KReportRulerPrivate *, QPainter *) {} | | |||
115 | virtual void drawMeasurements(const KReportRulerPrivate *ruler, QPainter *painter, const QRectF &rectangle); | | |||
116 | virtual void drawIndents(const KReportRulerPrivate *, QPainter *) { } | | |||
117 | virtual QSize sizeHint(); | | |||
118 | | ||||
119 | private: | | |||
120 | qreal lengthInPixel; | | |||
121 | }; | | |||
122 | | ||||
123 | class HorizontalDistancesPaintingStrategy : public HorizontalPaintingStrategy | | |||
124 | { | | |||
125 | public: | | |||
126 | HorizontalDistancesPaintingStrategy() {} | | |||
127 | | ||||
128 | virtual void drawMeasurements(const KReportRulerPrivate *ruler, QPainter *painter, const QRectF &rectangle); | | |||
129 | | ||||
130 | private: | | |||
131 | void drawDistanceLine(const KReportRulerPrivate *d, QPainter *painter, qreal start, qreal end); | | |||
132 | }; | | |||
133 | 31 | | |||
134 | /** | 32 | /** | ||
135 | * Decorator widget to draw a single ruler around a canvas. | 33 | * Decorator widget to draw a single ruler around a canvas. | ||
136 | */ | 34 | */ | ||
137 | class KReportRuler : public QWidget | 35 | class KReportRuler : public QWidget | ||
138 | { | 36 | { | ||
139 | Q_OBJECT | 37 | Q_OBJECT | ||
140 | public: | 38 | public: | ||
141 | /** | 39 | /** | ||
142 | * Creates a ruler with the orientation @p orientation | 40 | * Creates a ruler with the orientation @p orientation | ||
143 | * @param parent parent widget | 41 | * @param parent parent widget | ||
144 | * @param orientation the orientation of the ruler | 42 | * @param orientation the orientation of the ruler | ||
145 | * @param viewConverter the view converter used to convert from point to pixel | 43 | * @param viewConverter the view converter used to convert from point to pixel | ||
146 | */ | 44 | */ | ||
147 | KReportRuler(QWidget* parent, Qt::Orientation orientation, const KReportZoomHandler* viewConverter); | 45 | KReportRuler(QWidget* parent, Qt::Orientation orientation, | ||
46 | const KReportZoomHandler &zoomHandler); | ||||
148 | ~KReportRuler(); | 47 | ~KReportRuler(); | ||
149 | 48 | | |||
150 | /// For paragraphs each tab definition is represented by this struct. | 49 | /// For paragraphs each tab definition is represented by this struct. | ||
151 | struct Tab { | 50 | struct Tab { | ||
152 | inline Tab(qreal aPosition, QTextOption::TabType aType) : position(aPosition), type(aType) {} | 51 | inline Tab(qreal aPosition, QTextOption::TabType aType) : position(aPosition), type(aType) {} | ||
153 | inline Tab() : position(0.0), type(QTextOption::LeftTab) {} | 52 | inline Tab() : position(0.0), type(QTextOption::LeftTab) {} | ||
154 | qreal position; ///< distance in point from the start of the text-shape | 53 | qreal position; ///< distance in point from the start of the text-shape | ||
155 | QTextOption::TabType type; ///< Determine which type is used. | 54 | QTextOption::TabType type; ///< Determine which type is used. | ||
Show All 34 Lines | |||||
190 | QList<QAction*> popupActionList() const; | 89 | QList<QAction*> popupActionList() const; | ||
191 | 90 | | |||
192 | /// reimplemented | 91 | /// reimplemented | ||
193 | virtual QSize minimumSizeHint() const; | 92 | virtual QSize minimumSizeHint() const; | ||
194 | 93 | | |||
195 | /// reimplemented | 94 | /// reimplemented | ||
196 | virtual QSize sizeHint() const; | 95 | virtual QSize sizeHint() const; | ||
197 | 96 | | |||
97 | class Private; | ||||
98 | | ||||
198 | public Q_SLOTS: | 99 | public Q_SLOTS: | ||
199 | /// Set the unit of the ruler | 100 | /// Set the unit of the ruler | ||
200 | void setUnit(const KReportUnit &unit); | 101 | void setUnit(const KReportUnit &unit); | ||
201 | 102 | | |||
202 | /** Set the offset. Use this function to sync the ruler with | 103 | /** Set the offset. Use this function to sync the ruler with | ||
203 | * the canvas' position on screen | 104 | * the canvas' position on screen | ||
204 | * @param offset The offset in pixels | 105 | * @param offset The offset in pixels | ||
205 | */ | 106 | */ | ||
▲ Show 20 Lines • Show All 146 Lines • ▼ Show 20 Line(s) | 250 | protected: | |||
352 | /// reimplemented | 253 | /// reimplemented | ||
353 | virtual void mousePressEvent(QMouseEvent *ev); | 254 | virtual void mousePressEvent(QMouseEvent *ev); | ||
354 | /// reimplemented | 255 | /// reimplemented | ||
355 | virtual void mouseReleaseEvent(QMouseEvent *ev); | 256 | virtual void mouseReleaseEvent(QMouseEvent *ev); | ||
356 | /// reimplemented | 257 | /// reimplemented | ||
357 | virtual void mouseMoveEvent(QMouseEvent *ev); | 258 | virtual void mouseMoveEvent(QMouseEvent *ev); | ||
358 | 259 | | |||
359 | private: | 260 | private: | ||
360 | KReportRulerPrivate * const d; | 261 | Private * const d; | ||
361 | friend class KReportRulerPrivate; | 262 | friend class KReportRuler::Private; | ||
362 | }; | | |||
363 | | ||||
364 | | ||||
365 | class KReportRulerPrivate | | |||
366 | { | | |||
367 | public: | | |||
368 | KReportRulerPrivate(KReportRuler *parent, const KReportZoomHandler *vc, Qt::Orientation orientation); | | |||
369 | ~KReportRulerPrivate(); | | |||
370 | | ||||
371 | void emitTabChanged(); | | |||
372 | | ||||
373 | KReportUnit unit; | | |||
374 | const Qt::Orientation orientation; | | |||
375 | const KReportZoomHandler * const viewConverter; | | |||
376 | | ||||
377 | int offset; | | |||
378 | qreal rulerLength; | | |||
379 | qreal activeRangeStart; | | |||
380 | qreal activeRangeEnd; | | |||
381 | qreal activeOverrideRangeStart; | | |||
382 | qreal activeOverrideRangeEnd; | | |||
383 | | ||||
384 | int mouseCoordinate; | | |||
385 | int showMousePosition; | | |||
386 | | ||||
387 | bool showSelectionBorders; | | |||
388 | qreal firstSelectionBorder; | | |||
389 | qreal secondSelectionBorder; | | |||
390 | | ||||
391 | bool showIndents; | | |||
392 | qreal firstLineIndent; | | |||
393 | qreal paragraphIndent; | | |||
394 | qreal endIndent; | | |||
395 | | ||||
396 | bool showTabs; | | |||
397 | bool relativeTabs; | | |||
398 | bool tabMoved; // set to true on first move of a selected tab | | |||
399 | QList<KReportRuler::Tab> tabs; | | |||
400 | int originalIndex; //index of selected tab before we started dragging it. | | |||
401 | int currentIndex; //index of selected tab or selected HotSpot - only valid when selected indicates tab or hotspot | | |||
402 | KReportRuler::Tab deletedTab; | | |||
403 | qreal tabDistance; | | |||
404 | | ||||
405 | struct HotSpotData { | | |||
406 | qreal position; | | |||
407 | int id; | | |||
408 | }; | | |||
409 | QList<HotSpotData> hotspots; | | |||
410 | | ||||
411 | bool rightToLeft; | | |||
412 | enum Selection { | | |||
413 | None, | | |||
414 | Tab, | | |||
415 | FirstLineIndent, | | |||
416 | ParagraphIndent, | | |||
417 | EndIndent, | | |||
418 | HotSpot | | |||
419 | }; | | |||
420 | Selection selected; | | |||
421 | int selectOffset; | | |||
422 | | ||||
423 | QList<QAction*> popupActions; | | |||
424 | | ||||
425 | RulerTabChooser *tabChooser; | | |||
426 | | ||||
427 | // Cached painting strategies | | |||
428 | PaintingStrategy * normalPaintingStrategy; | | |||
429 | PaintingStrategy * distancesPaintingStrategy; | | |||
430 | | ||||
431 | // Current painting strategy | | |||
432 | PaintingStrategy * paintingStrategy; | | |||
433 | | ||||
434 | KReportRuler *ruler; | | |||
435 | | ||||
436 | qreal numberStepForUnit() const; | | |||
437 | /// @return The rounding of value to the nearest multiple of stepValue | | |||
438 | qreal doSnapping(qreal value) const; | | |||
439 | Selection selectionAtPosition(const QPoint & pos, int *selectOffset = 0); | | |||
440 | int hotSpotIndex(const QPoint & pos); | | |||
441 | qreal effectiveActiveRangeStart() const; | | |||
442 | qreal effectiveActiveRangeEnd() const; | | |||
443 | | ||||
444 | friend class VerticalPaintingStrategy; | | |||
445 | friend class HorizontalPaintingStrategy; | | |||
446 | }; | 263 | }; | ||
447 | 264 | | |||
448 | #endif | 265 | #endif |