Changeset View
Changeset View
Standalone View
Standalone View
src/wrtembed/KReportRuler_p.cpp
- This file was moved from src/wrtembed/KReportRuler.cpp.
Show All 16 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
17 | 17 | | |||
18 | You should have received a copy of the GNU Library General Public License | 18 | You should have received a copy of the GNU Library General Public License | ||
19 | along with this library; see the file COPYING.LIB. If not, write to | 19 | along with this library; see the file COPYING.LIB. If not, write to | ||
20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 20 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
21 | Boston, MA 02110-1301, USA. | 21 | Boston, MA 02110-1301, USA. | ||
22 | */ | 22 | */ | ||
23 | 23 | | |||
24 | #include "KReportRuler_p.h" | 24 | #include "KReportRuler_p.h" | ||
25 | #include "KReportZoomHandler.h" | 25 | #include "KReportZoomHandler_p.h" | ||
26 | 26 | | |||
27 | #include <QPainter> | 27 | #include <QPainter> | ||
28 | #include <QMenu> | 28 | #include <QMenu> | ||
29 | #include <QMouseEvent> | 29 | #include <QMouseEvent> | ||
30 | #include <QFontDatabase> | 30 | #include <QFontDatabase> | ||
31 | 31 | | |||
32 | // the distance in pixels of a mouse position considered outside the rule | 32 | // the distance in pixels of a mouse position considered outside the rule | ||
33 | static const int OutsideRulerThreshold = 20; | 33 | static const int OutsideRulerThreshold = 20; | ||
34 | // | 34 | // | ||
35 | static const int fullStepMarkerLength = 6; | 35 | static const int fullStepMarkerLength = 6; | ||
36 | static const int halfStepMarkerLength = 6; | 36 | static const int halfStepMarkerLength = 6; | ||
37 | static const int quarterStepMarkerLength = 3; | 37 | static const int quarterStepMarkerLength = 3; | ||
38 | static const int measurementTextAboveBelowMargin = 1; | 38 | static const int measurementTextAboveBelowMargin = 1; | ||
39 | 39 | | |||
40 | class RulerTabChooser : public QWidget | ||||
41 | { | ||||
42 | public: | ||||
43 | RulerTabChooser(QWidget *parent) : QWidget(parent), m_type(QTextOption::LeftTab), m_showTabs(false) {} | ||||
44 | virtual ~RulerTabChooser() {} | ||||
45 | | ||||
46 | inline QTextOption::TabType type() {return m_type;} | ||||
47 | void setShowTabs(bool showTabs) { if (m_showTabs == showTabs) return; m_showTabs = showTabs; update(); } | ||||
48 | void mousePressEvent(QMouseEvent *); | ||||
49 | | ||||
50 | void paintEvent(QPaintEvent *); | ||||
51 | | ||||
52 | private: | ||||
53 | QTextOption::TabType m_type; | ||||
54 | bool m_showTabs :1; | ||||
55 | }; | ||||
56 | | ||||
57 | // ---- | ||||
58 | | ||||
59 | class PaintingStrategy | ||||
60 | { | ||||
61 | public: | ||||
62 | /// constructor | ||||
63 | PaintingStrategy() {} | ||||
64 | /// destructor | ||||
65 | virtual ~PaintingStrategy() {} | ||||
66 | | ||||
67 | /** | ||||
68 | * Draw the background of the ruler. | ||||
69 | * @param ruler the ruler to draw on. | ||||
70 | * @param painter the painter we can paint with. | ||||
71 | */ | ||||
72 | virtual QRectF drawBackground(const KReportRuler::Private *ruler, QPainter *painter) = 0; | ||||
73 | | ||||
74 | /** | ||||
75 | * Draw the indicators for text-tabs. | ||||
76 | * @param ruler the ruler to draw on. | ||||
77 | * @param painter the painter we can paint with. | ||||
78 | */ | ||||
79 | virtual void drawTabs(const KReportRuler::Private *ruler, QPainter *painter) = 0; | ||||
80 | | ||||
81 | /** | ||||
82 | * Draw the indicators for the measurements which typically are drawn every [unit]. | ||||
83 | * @param ruler the ruler to draw on. | ||||
84 | * @param painter the painter we can paint with. | ||||
85 | * @param rectangle | ||||
86 | */ | ||||
87 | virtual void drawMeasurements(const KReportRuler::Private *ruler, QPainter *painter, const QRectF &rectangle) = 0; | ||||
88 | | ||||
89 | /** | ||||
90 | * Draw the indicators for the indents of a text paragraph | ||||
91 | * @param ruler the ruler to draw on. | ||||
92 | * @param painter the painter we can paint with. | ||||
93 | */ | ||||
94 | virtual void drawIndents(const KReportRuler::Private *ruler, QPainter *painter) = 0; | ||||
95 | | ||||
96 | /** | ||||
97 | *returns the size suggestion for a ruler with this strategy. | ||||
98 | */ | ||||
99 | virtual QSize sizeHint() = 0; | ||||
100 | }; | ||||
101 | | ||||
102 | // ---- | ||||
103 | | ||||
104 | class HorizontalPaintingStrategy : public PaintingStrategy | ||||
105 | { | ||||
106 | public: | ||||
107 | HorizontalPaintingStrategy() : lengthInPixel(1) {} | ||||
108 | | ||||
109 | virtual QRectF drawBackground(const KReportRuler::Private *ruler, QPainter *painter); | ||||
110 | virtual void drawTabs(const KReportRuler::Private *ruler, QPainter *painter); | ||||
111 | virtual void drawMeasurements(const KReportRuler::Private *ruler, QPainter *painter, const QRectF &rectangle); | ||||
112 | virtual void drawIndents(const KReportRuler::Private *ruler, QPainter *painter); | ||||
113 | virtual QSize sizeHint(); | ||||
114 | | ||||
115 | private: | ||||
116 | qreal lengthInPixel; | ||||
117 | }; | ||||
118 | | ||||
119 | // ---- | ||||
120 | | ||||
121 | class VerticalPaintingStrategy : public PaintingStrategy | ||||
122 | { | ||||
123 | public: | ||||
124 | VerticalPaintingStrategy() : lengthInPixel(1) {} | ||||
125 | | ||||
126 | virtual QRectF drawBackground(const KReportRuler::Private *ruler, QPainter *painter); | ||||
127 | virtual void drawTabs(const KReportRuler::Private *, QPainter *) {} | ||||
128 | virtual void drawMeasurements(const KReportRuler::Private *ruler, QPainter *painter, const QRectF &rectangle); | ||||
129 | virtual void drawIndents(const KReportRuler::Private *, QPainter *) { } | ||||
130 | virtual QSize sizeHint(); | ||||
131 | | ||||
132 | private: | ||||
133 | qreal lengthInPixel; | ||||
134 | }; | ||||
135 | | ||||
136 | class HorizontalDistancesPaintingStrategy : public HorizontalPaintingStrategy | ||||
137 | { | ||||
138 | public: | ||||
139 | HorizontalDistancesPaintingStrategy() {} | ||||
140 | | ||||
141 | virtual void drawMeasurements(const KReportRuler::Private *ruler, QPainter *painter, const QRectF &rectangle); | ||||
142 | | ||||
143 | private: | ||||
144 | void drawDistanceLine(const KReportRuler::Private *d, QPainter *painter, qreal start, qreal end); | ||||
145 | }; | ||||
146 | | ||||
147 | // ---- | ||||
148 | | ||||
149 | class KReportRuler::Private | ||||
150 | { | ||||
151 | public: | ||||
152 | Private(KReportRuler *parent, const KReportZoomHandler &zoomHandler, Qt::Orientation orientation); | ||||
153 | ~Private(); | ||||
154 | | ||||
155 | void emitTabChanged(); | ||||
156 | | ||||
157 | KReportUnit unit; | ||||
158 | const Qt::Orientation orientation; | ||||
159 | const KReportZoomHandler * const viewConverter; | ||||
160 | | ||||
161 | int offset; | ||||
162 | qreal rulerLength; | ||||
163 | qreal activeRangeStart; | ||||
164 | qreal activeRangeEnd; | ||||
165 | qreal activeOverrideRangeStart; | ||||
166 | qreal activeOverrideRangeEnd; | ||||
167 | | ||||
168 | int mouseCoordinate; | ||||
169 | int showMousePosition; | ||||
170 | | ||||
171 | bool showSelectionBorders; | ||||
172 | qreal firstSelectionBorder; | ||||
173 | qreal secondSelectionBorder; | ||||
174 | | ||||
175 | bool showIndents; | ||||
176 | qreal firstLineIndent; | ||||
177 | qreal paragraphIndent; | ||||
178 | qreal endIndent; | ||||
179 | | ||||
180 | bool showTabs; | ||||
181 | bool relativeTabs; | ||||
182 | bool tabMoved; // set to true on first move of a selected tab | ||||
183 | QList<KReportRuler::Tab> tabs; | ||||
184 | int originalIndex; //index of selected tab before we started dragging it. | ||||
185 | int currentIndex; //index of selected tab or selected HotSpot - only valid when selected indicates tab or hotspot | ||||
186 | KReportRuler::Tab deletedTab; | ||||
187 | qreal tabDistance; | ||||
188 | | ||||
189 | struct HotSpotData { | ||||
190 | qreal position; | ||||
191 | int id; | ||||
192 | }; | ||||
193 | QList<HotSpotData> hotspots; | ||||
194 | | ||||
195 | bool rightToLeft; | ||||
196 | enum Selection { | ||||
197 | None, | ||||
198 | Tab, | ||||
199 | FirstLineIndent, | ||||
200 | ParagraphIndent, | ||||
201 | EndIndent, | ||||
202 | HotSpot | ||||
203 | }; | ||||
204 | Selection selected; | ||||
205 | int selectOffset; | ||||
206 | | ||||
207 | QList<QAction*> popupActions; | ||||
208 | | ||||
209 | RulerTabChooser *tabChooser; | ||||
210 | | ||||
211 | // Cached painting strategies | ||||
212 | PaintingStrategy * normalPaintingStrategy; | ||||
213 | PaintingStrategy * distancesPaintingStrategy; | ||||
214 | | ||||
215 | // Current painting strategy | ||||
216 | PaintingStrategy * paintingStrategy; | ||||
217 | | ||||
218 | KReportRuler *ruler; | ||||
219 | | ||||
220 | qreal numberStepForUnit() const; | ||||
221 | /// @return The rounding of value to the nearest multiple of stepValue | ||||
222 | qreal doSnapping(qreal value) const; | ||||
223 | Selection selectionAtPosition(const QPoint & pos, int *selectOffset = 0); | ||||
224 | int hotSpotIndex(const QPoint & pos); | ||||
225 | qreal effectiveActiveRangeStart() const; | ||||
226 | qreal effectiveActiveRangeEnd() const; | ||||
227 | | ||||
228 | friend class VerticalPaintingStrategy; | ||||
229 | friend class HorizontalPaintingStrategy; | ||||
230 | }; | ||||
231 | | ||||
232 | // ---- | ||||
40 | 233 | | |||
41 | void RulerTabChooser::mousePressEvent(QMouseEvent *) | 234 | void RulerTabChooser::mousePressEvent(QMouseEvent *) | ||
42 | { | 235 | { | ||
43 | if (! m_showTabs) { | 236 | if (! m_showTabs) { | ||
44 | return; | 237 | return; | ||
45 | } | 238 | } | ||
46 | 239 | | |||
47 | switch(m_type) { | 240 | switch(m_type) { | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | 258 | { | |||
109 | } | 302 | } | ||
110 | } | 303 | } | ||
111 | 304 | | |||
112 | static int compareTabs(const KReportRuler::Tab &tab1, const KReportRuler::Tab &tab2) | 305 | static int compareTabs(const KReportRuler::Tab &tab1, const KReportRuler::Tab &tab2) | ||
113 | { | 306 | { | ||
114 | return tab1.position < tab2.position; | 307 | return tab1.position < tab2.position; | ||
115 | } | 308 | } | ||
116 | 309 | | |||
117 | QRectF HorizontalPaintingStrategy::drawBackground(const KReportRulerPrivate *d, QPainter *painter) | 310 | QRectF HorizontalPaintingStrategy::drawBackground(const KReportRuler::Private *d, QPainter *painter) | ||
118 | { | 311 | { | ||
119 | lengthInPixel = d->viewConverter->documentToViewX(d->rulerLength); | 312 | lengthInPixel = d->viewConverter->documentToViewX(d->rulerLength); | ||
120 | QRectF rectangle; | 313 | QRectF rectangle; | ||
121 | rectangle.setX(qMax(0, d->offset)); | 314 | rectangle.setX(qMax(0, d->offset)); | ||
122 | rectangle.setY(0); | 315 | rectangle.setY(0); | ||
123 | rectangle.setWidth(qMin(qreal(d->ruler->width() - 1.0 - rectangle.x()), | 316 | rectangle.setWidth(qMin(qreal(d->ruler->width() - 1.0 - rectangle.x()), | ||
124 | (d->offset >= 0) ? lengthInPixel : lengthInPixel + d->offset)); | 317 | (d->offset >= 0) ? lengthInPixel : lengthInPixel + d->offset)); | ||
125 | rectangle.setHeight(d->ruler->height() - 1); | 318 | rectangle.setHeight(d->ruler->height() - 1); | ||
Show All 22 Lines | 340 | if(d->secondSelectionBorder > 0) { | |||
148 | qreal border = d->viewConverter->documentToViewX(d->secondSelectionBorder) + d->offset; | 341 | qreal border = d->viewConverter->documentToViewX(d->secondSelectionBorder) + d->offset; | ||
149 | painter->drawLine(QPointF(border, rectangle.y() + 1), QPointF(border, rectangle.bottom() - 1)); | 342 | painter->drawLine(QPointF(border, rectangle.y() + 1), QPointF(border, rectangle.bottom() - 1)); | ||
150 | } | 343 | } | ||
151 | } | 344 | } | ||
152 | 345 | | |||
153 | return rectangle; | 346 | return rectangle; | ||
154 | } | 347 | } | ||
155 | 348 | | |||
156 | void HorizontalPaintingStrategy::drawTabs(const KReportRulerPrivate *d, QPainter *painter) | 349 | void HorizontalPaintingStrategy::drawTabs(const KReportRuler::Private *d, QPainter *painter) | ||
157 | { | 350 | { | ||
158 | if (! d->showTabs) | 351 | if (! d->showTabs) | ||
159 | return; | 352 | return; | ||
160 | QPolygonF polygon; | 353 | QPolygonF polygon; | ||
161 | 354 | | |||
162 | const QColor tabColor = d->ruler->palette().color(QPalette::Text); | 355 | const QColor tabColor = d->ruler->palette().color(QPalette::Text); | ||
163 | painter->setPen(tabColor); | 356 | painter->setPen(tabColor); | ||
164 | painter->setBrush(tabColor); | 357 | painter->setBrush(tabColor); | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 427 | polygon << QPointF(x+0.5, d->ruler->height() - 3.5) | |||
236 | << QPointF(x+0.5, d->ruler->height() - 0.5); | 429 | << QPointF(x+0.5, d->ruler->height() - 0.5); | ||
237 | painter->drawPolygon(polygon); | 430 | painter->drawPolygon(polygon); | ||
238 | 431 | | |||
239 | position += d->tabDistance; | 432 | position += d->tabDistance; | ||
240 | } | 433 | } | ||
241 | } | 434 | } | ||
242 | } | 435 | } | ||
243 | 436 | | |||
244 | void HorizontalPaintingStrategy::drawMeasurements(const KReportRulerPrivate *d, QPainter *painter, const QRectF &rectangle) | 437 | void HorizontalPaintingStrategy::drawMeasurements(const KReportRuler::Private *d, QPainter *painter, const QRectF &rectangle) | ||
245 | { | 438 | { | ||
246 | qreal numberStep = d->numberStepForUnit(); // number step in unit | 439 | qreal numberStep = d->numberStepForUnit(); // number step in unit | ||
247 | // QRectF activeRangeRectangle; | 440 | // QRectF activeRangeRectangle; | ||
248 | int numberStepPixel = qRound(d->viewConverter->documentToViewX(d->unit.fromUserValue(numberStep))); | 441 | int numberStepPixel = qRound(d->viewConverter->documentToViewX(d->unit.fromUserValue(numberStep))); | ||
249 | // const bool adjustMillimeters = (d->unit.type() == KReportUnit::Millimeter); | 442 | // const bool adjustMillimeters = (d->unit.type() == KReportUnit::Millimeter); | ||
250 | 443 | | |||
251 | const QFont font = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont); | 444 | const QFont font = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont); | ||
252 | const QFontMetrics fontMetrics(font); | 445 | const QFontMetrics fontMetrics(font); | ||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Line(s) | 542 | else if(i == nextQuarterStep) { | |||
354 | ++quarterStepCount; | 547 | ++quarterStepCount; | ||
355 | nextQuarterStep = qRound(d->viewConverter->documentToViewX(d->unit.fromUserValue( | 548 | nextQuarterStep = qRound(d->viewConverter->documentToViewX(d->unit.fromUserValue( | ||
356 | numberStep * 0.25 * quarterStepCount))); | 549 | numberStep * 0.25 * quarterStepCount))); | ||
357 | } | 550 | } | ||
358 | } | 551 | } | ||
359 | 552 | | |||
360 | // Draw the mouse indicator | 553 | // Draw the mouse indicator | ||
361 | const int mouseCoord = d->mouseCoordinate - start; | 554 | const int mouseCoord = d->mouseCoordinate - start; | ||
362 | if (d->selected == KReportRulerPrivate::None || d->selected == KReportRulerPrivate::HotSpot) { | 555 | if (d->selected == KReportRuler::Private::None || d->selected == KReportRuler::Private::HotSpot) { | ||
363 | const qreal top = rectangle.y() + 1; | 556 | const qreal top = rectangle.y() + 1; | ||
364 | const qreal bottom = rectangle.bottom() -1; | 557 | const qreal bottom = rectangle.bottom() -1; | ||
365 | if (d->selected == KReportRulerPrivate::None && d->showMousePosition && mouseCoord > 0 && mouseCoord < rectangle.width() ) | 558 | if (d->selected == KReportRuler::Private::None && d->showMousePosition && mouseCoord > 0 && mouseCoord < rectangle.width() ) | ||
366 | painter->drawLine(QPointF(mouseCoord, top), QPointF(mouseCoord, bottom)); | 559 | painter->drawLine(QPointF(mouseCoord, top), QPointF(mouseCoord, bottom)); | ||
367 | foreach (const KReportRulerPrivate::HotSpotData & hp, d->hotspots) { | 560 | foreach (const KReportRuler::Private::HotSpotData & hp, d->hotspots) { | ||
368 | const qreal x = d->viewConverter->documentToViewX(hp.position) + d->offset; | 561 | const qreal x = d->viewConverter->documentToViewX(hp.position) + d->offset; | ||
369 | painter->drawLine(QPointF(x, top), QPointF(x, bottom)); | 562 | painter->drawLine(QPointF(x, top), QPointF(x, bottom)); | ||
370 | } | 563 | } | ||
371 | } | 564 | } | ||
372 | } | 565 | } | ||
373 | 566 | | |||
374 | void HorizontalPaintingStrategy::drawIndents(const KReportRulerPrivate *d, QPainter *painter) | 567 | void HorizontalPaintingStrategy::drawIndents(const KReportRuler::Private *d, QPainter *painter) | ||
375 | { | 568 | { | ||
376 | QPolygonF polygon; | 569 | QPolygonF polygon; | ||
377 | 570 | | |||
378 | painter->setBrush(d->ruler->palette().brush(QPalette::Base)); | 571 | painter->setBrush(d->ruler->palette().brush(QPalette::Base)); | ||
379 | painter->setRenderHint( QPainter::Antialiasing ); | 572 | painter->setRenderHint( QPainter::Antialiasing ); | ||
380 | 573 | | |||
381 | qreal x; | 574 | qreal x; | ||
382 | // Draw first line start indent | 575 | // Draw first line start indent | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 616 | { | |||
424 | // assumes that digits for the number only use glyphs which do not go below the baseline | 617 | // assumes that digits for the number only use glyphs which do not go below the baseline | ||
425 | const QFontMetrics fm(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)); | 618 | const QFontMetrics fm(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)); | ||
426 | const int digitsHeight = fm.ascent() + 1; // +1 for baseline | 619 | const int digitsHeight = fm.ascent() + 1; // +1 for baseline | ||
427 | const int minimum = digitsHeight + fullStepMarkerLength + 2*measurementTextAboveBelowMargin; | 620 | const int minimum = digitsHeight + fullStepMarkerLength + 2*measurementTextAboveBelowMargin; | ||
428 | 621 | | |||
429 | return QSize(0, minimum); | 622 | return QSize(0, minimum); | ||
430 | } | 623 | } | ||
431 | 624 | | |||
432 | QRectF VerticalPaintingStrategy::drawBackground(const KReportRulerPrivate *d, QPainter *painter) | 625 | QRectF VerticalPaintingStrategy::drawBackground(const KReportRuler::Private *d, QPainter *painter) | ||
433 | { | 626 | { | ||
434 | lengthInPixel = d->viewConverter->documentToViewY(d->rulerLength); | 627 | lengthInPixel = d->viewConverter->documentToViewY(d->rulerLength); | ||
435 | QRectF rectangle; | 628 | QRectF rectangle; | ||
436 | rectangle.setX(0); | 629 | rectangle.setX(0); | ||
437 | rectangle.setY(qMax(0, d->offset)); | 630 | rectangle.setY(qMax(0, d->offset)); | ||
438 | rectangle.setWidth(d->ruler->width() - 1.0); | 631 | rectangle.setWidth(d->ruler->width() - 1.0); | ||
439 | rectangle.setHeight(qMin(qreal(d->ruler->height() - 1.0 - rectangle.y()), | 632 | rectangle.setHeight(qMin(qreal(d->ruler->height() - 1.0 - rectangle.y()), | ||
440 | (d->offset >= 0) ? lengthInPixel : lengthInPixel + d->offset)); | 633 | (d->offset >= 0) ? lengthInPixel : lengthInPixel + d->offset)); | ||
Show All 23 Lines | 656 | if(d->secondSelectionBorder > 0) { | |||
464 | qreal border = d->viewConverter->documentToViewY(d->secondSelectionBorder) + d->offset; | 657 | qreal border = d->viewConverter->documentToViewY(d->secondSelectionBorder) + d->offset; | ||
465 | painter->drawLine(QPointF(rectangle.x() + 1, border), QPointF(rectangle.right() - 1, border)); | 658 | painter->drawLine(QPointF(rectangle.x() + 1, border), QPointF(rectangle.right() - 1, border)); | ||
466 | } | 659 | } | ||
467 | } | 660 | } | ||
468 | 661 | | |||
469 | return rectangle; | 662 | return rectangle; | ||
470 | } | 663 | } | ||
471 | 664 | | |||
472 | void VerticalPaintingStrategy::drawMeasurements(const KReportRulerPrivate *d, QPainter *painter, const QRectF &rectangle) | 665 | void VerticalPaintingStrategy::drawMeasurements(const KReportRuler::Private *d, QPainter *painter, const QRectF &rectangle) | ||
473 | { | 666 | { | ||
474 | qreal numberStep = d->numberStepForUnit(); // number step in unit | 667 | qreal numberStep = d->numberStepForUnit(); // number step in unit | ||
475 | int numberStepPixel = qRound(d->viewConverter->documentToViewY( d->unit.fromUserValue(numberStep))); | 668 | int numberStepPixel = qRound(d->viewConverter->documentToViewY( d->unit.fromUserValue(numberStep))); | ||
476 | if (numberStepPixel <= 0) | 669 | if (numberStepPixel <= 0) | ||
477 | return; | 670 | return; | ||
478 | 671 | | |||
479 | const QFont font = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont); | 672 | const QFont font = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont); | ||
480 | const QFontMetrics fontMetrics(font); | 673 | const QFontMetrics fontMetrics(font); | ||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Line(s) | 753 | } else if(i == nextQuarterStep) { | |||
565 | ++quarterStepCount; | 758 | ++quarterStepCount; | ||
566 | nextQuarterStep = qRound(d->viewConverter->documentToViewY(d->unit.fromUserValue( | 759 | nextQuarterStep = qRound(d->viewConverter->documentToViewY(d->unit.fromUserValue( | ||
567 | numberStep * 0.25 * quarterStepCount))); | 760 | numberStep * 0.25 * quarterStepCount))); | ||
568 | } | 761 | } | ||
569 | } | 762 | } | ||
570 | 763 | | |||
571 | // Draw the mouse indicator | 764 | // Draw the mouse indicator | ||
572 | const int mouseCoord = d->mouseCoordinate - start; | 765 | const int mouseCoord = d->mouseCoordinate - start; | ||
573 | if (d->selected == KReportRulerPrivate::None || d->selected == KReportRulerPrivate::HotSpot) { | 766 | if (d->selected == KReportRuler::Private::None || d->selected == KReportRuler::Private::HotSpot) { | ||
574 | const qreal left = rectangle.left() + 1; | 767 | const qreal left = rectangle.left() + 1; | ||
575 | const qreal right = rectangle.right() -1; | 768 | const qreal right = rectangle.right() -1; | ||
576 | if (d->selected == KReportRulerPrivate::None && d->showMousePosition && mouseCoord > 0 && mouseCoord < rectangle.height() ) | 769 | if (d->selected == KReportRuler::Private::None && d->showMousePosition && mouseCoord > 0 && mouseCoord < rectangle.height() ) | ||
577 | painter->drawLine(QPointF(left, mouseCoord), QPointF(right, mouseCoord)); | 770 | painter->drawLine(QPointF(left, mouseCoord), QPointF(right, mouseCoord)); | ||
578 | foreach (const KReportRulerPrivate::HotSpotData & hp, d->hotspots) { | 771 | foreach (const KReportRuler::Private::HotSpotData & hp, d->hotspots) { | ||
579 | const qreal y = d->viewConverter->documentToViewY(hp.position) + d->offset; | 772 | const qreal y = d->viewConverter->documentToViewY(hp.position) + d->offset; | ||
580 | painter->drawLine(QPointF(left, y), QPointF(right, y)); | 773 | painter->drawLine(QPointF(left, y), QPointF(right, y)); | ||
581 | } | 774 | } | ||
582 | } | 775 | } | ||
583 | } | 776 | } | ||
584 | 777 | | |||
585 | QSize VerticalPaintingStrategy::sizeHint() | 778 | QSize VerticalPaintingStrategy::sizeHint() | ||
586 | { | 779 | { | ||
587 | // assumes that digits for the number only use glyphs which do not go below the baseline | 780 | // assumes that digits for the number only use glyphs which do not go below the baseline | ||
588 | const QFontMetrics fm(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)); | 781 | const QFontMetrics fm(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont)); | ||
589 | const int digitsHeight = fm.ascent() + 1; // +1 for baseline | 782 | const int digitsHeight = fm.ascent() + 1; // +1 for baseline | ||
590 | const int minimum = digitsHeight + fullStepMarkerLength + 2*measurementTextAboveBelowMargin; | 783 | const int minimum = digitsHeight + fullStepMarkerLength + 2*measurementTextAboveBelowMargin; | ||
591 | 784 | | |||
592 | return QSize(minimum, 0); | 785 | return QSize(minimum, 0); | ||
593 | } | 786 | } | ||
594 | 787 | | |||
595 | 788 | | |||
596 | void HorizontalDistancesPaintingStrategy::drawDistanceLine(const KReportRulerPrivate *d, | 789 | void HorizontalDistancesPaintingStrategy::drawDistanceLine(const KReportRuler::Private *d, | ||
597 | QPainter *painter, qreal start, | 790 | QPainter *painter, qreal start, | ||
598 | qreal end) | 791 | qreal end) | ||
599 | { | 792 | { | ||
600 | 793 | | |||
601 | // Don't draw too short lines | 794 | // Don't draw too short lines | ||
602 | if (qMax(start, end) - qMin(start, end) < 1) | 795 | if (qMax(start, end) - qMin(start, end) < 1) | ||
603 | return; | 796 | return; | ||
604 | 797 | | |||
Show All 32 Lines | |||||
637 | arrowHead.clear(); | 830 | arrowHead.clear(); | ||
638 | arrowHead << line.p2() << QPointF(line.x2()-3, line.y2()-3) | 831 | arrowHead << line.p2() << QPointF(line.x2()-3, line.y2()-3) | ||
639 | << QPointF(line.x2()-3, line.y2()+3); | 832 | << QPointF(line.x2()-3, line.y2()+3); | ||
640 | painter->drawPolygon(arrowHead); | 833 | painter->drawPolygon(arrowHead); | ||
641 | 834 | | |||
642 | painter->restore(); | 835 | painter->restore(); | ||
643 | } | 836 | } | ||
644 | 837 | | |||
645 | void HorizontalDistancesPaintingStrategy::drawMeasurements(const KReportRulerPrivate *d, | 838 | void HorizontalDistancesPaintingStrategy::drawMeasurements(const KReportRuler::Private *d, | ||
646 | QPainter *painter, const QRectF&) | 839 | QPainter *painter, const QRectF&) | ||
647 | { | 840 | { | ||
648 | QList<qreal> points; | 841 | QList<qreal> points; | ||
649 | points << 0.0; | 842 | points << 0.0; | ||
650 | points << d->effectiveActiveRangeStart() + d->paragraphIndent + d->firstLineIndent; | 843 | points << d->effectiveActiveRangeStart() + d->paragraphIndent + d->firstLineIndent; | ||
651 | points << d->effectiveActiveRangeStart() + d->paragraphIndent; | 844 | points << d->effectiveActiveRangeStart() + d->paragraphIndent; | ||
652 | points << d->effectiveActiveRangeEnd() - d->endIndent; | 845 | points << d->effectiveActiveRangeEnd() - d->endIndent; | ||
653 | points << d->effectiveActiveRangeStart(); | 846 | points << d->effectiveActiveRangeStart(); | ||
654 | points << d->effectiveActiveRangeEnd(); | 847 | points << d->effectiveActiveRangeEnd(); | ||
655 | points << d->rulerLength; | 848 | points << d->rulerLength; | ||
656 | qSort(points.begin(), points.end()); | 849 | qSort(points.begin(), points.end()); | ||
657 | QListIterator<qreal> i(points); | 850 | QListIterator<qreal> i(points); | ||
658 | i.next(); | 851 | i.next(); | ||
659 | while (i.hasNext() && i.hasPrevious()) { | 852 | while (i.hasNext() && i.hasPrevious()) { | ||
660 | drawDistanceLine(d, painter, i.peekPrevious(), i.peekNext()); | 853 | drawDistanceLine(d, painter, i.peekPrevious(), i.peekNext()); | ||
661 | i.next(); | 854 | i.next(); | ||
662 | } | 855 | } | ||
663 | } | 856 | } | ||
664 | 857 | | |||
665 | KReportRulerPrivate::KReportRulerPrivate(KReportRuler *parent, const KReportZoomHandler *vc, Qt::Orientation o) | 858 | KReportRuler::Private::Private(KReportRuler *parent, | ||
859 | const KReportZoomHandler &zoomHandler, Qt::Orientation o) | ||||
666 | : unit(KReportUnit(KReportUnit::Point)), | 860 | : unit(KReportUnit(KReportUnit::Point)), | ||
667 | orientation(o), | 861 | orientation(o), | ||
668 | viewConverter(vc), | 862 | viewConverter(&zoomHandler), | ||
669 | offset(0), | 863 | offset(0), | ||
670 | rulerLength(0), | 864 | rulerLength(0), | ||
671 | activeRangeStart(0), | 865 | activeRangeStart(0), | ||
672 | activeRangeEnd(0), | 866 | activeRangeEnd(0), | ||
673 | activeOverrideRangeStart(0), | 867 | activeOverrideRangeStart(0), | ||
674 | activeOverrideRangeEnd(0), | 868 | activeOverrideRangeEnd(0), | ||
675 | mouseCoordinate(-1), | 869 | mouseCoordinate(-1), | ||
676 | showMousePosition(0), | 870 | showMousePosition(0), | ||
Show All 17 Lines | |||||
694 | normalPaintingStrategy(o == Qt::Horizontal ? | 888 | normalPaintingStrategy(o == Qt::Horizontal ? | ||
695 | (PaintingStrategy*)new HorizontalPaintingStrategy() : (PaintingStrategy*)new VerticalPaintingStrategy()), | 889 | (PaintingStrategy*)new HorizontalPaintingStrategy() : (PaintingStrategy*)new VerticalPaintingStrategy()), | ||
696 | distancesPaintingStrategy((PaintingStrategy*)new HorizontalDistancesPaintingStrategy()), | 890 | distancesPaintingStrategy((PaintingStrategy*)new HorizontalDistancesPaintingStrategy()), | ||
697 | paintingStrategy(normalPaintingStrategy), | 891 | paintingStrategy(normalPaintingStrategy), | ||
698 | ruler(parent) | 892 | ruler(parent) | ||
699 | { | 893 | { | ||
700 | } | 894 | } | ||
701 | 895 | | |||
702 | KReportRulerPrivate::~KReportRulerPrivate() | 896 | KReportRuler::Private::~Private() | ||
703 | { | 897 | { | ||
704 | delete normalPaintingStrategy; | 898 | delete normalPaintingStrategy; | ||
705 | delete distancesPaintingStrategy; | 899 | delete distancesPaintingStrategy; | ||
706 | } | 900 | } | ||
707 | 901 | | |||
708 | qreal KReportRulerPrivate::numberStepForUnit() const | 902 | qreal KReportRuler::Private::numberStepForUnit() const | ||
709 | { | 903 | { | ||
710 | switch(unit.type()) { | 904 | switch(unit.type()) { | ||
711 | case KReportUnit::Inch: | 905 | case KReportUnit::Inch: | ||
712 | case KReportUnit::Centimeter: | 906 | case KReportUnit::Centimeter: | ||
713 | case KReportUnit::Decimeter: | 907 | case KReportUnit::Decimeter: | ||
714 | case KReportUnit::Millimeter: | 908 | case KReportUnit::Millimeter: | ||
715 | return 1.0; | 909 | return 1.0; | ||
716 | case KReportUnit::Pica: | 910 | case KReportUnit::Pica: | ||
717 | case KReportUnit::Cicero: | 911 | case KReportUnit::Cicero: | ||
718 | return 10.0; | 912 | return 10.0; | ||
719 | case KReportUnit::Point: | 913 | case KReportUnit::Point: | ||
720 | default: | 914 | default: | ||
721 | return 100.0; | 915 | return 100.0; | ||
722 | } | 916 | } | ||
723 | } | 917 | } | ||
724 | 918 | | |||
725 | qreal KReportRulerPrivate::doSnapping(qreal value) const | 919 | qreal KReportRuler::Private::doSnapping(qreal value) const | ||
726 | { | 920 | { | ||
727 | qreal numberStep = unit.fromUserValue(numberStepForUnit()/4.0); | 921 | qreal numberStep = unit.fromUserValue(numberStepForUnit()/4.0); | ||
728 | return numberStep * qRound(value / numberStep); | 922 | return numberStep * qRound(value / numberStep); | ||
729 | } | 923 | } | ||
730 | 924 | | |||
731 | KReportRulerPrivate::Selection KReportRulerPrivate::selectionAtPosition(const QPoint & pos, int *selectOffset ) | 925 | KReportRuler::Private::Selection KReportRuler::Private::selectionAtPosition(const QPoint & pos, int *selectOffset ) | ||
732 | { | 926 | { | ||
733 | const int height = ruler->height(); | 927 | const int height = ruler->height(); | ||
734 | if (rightToLeft) { | 928 | if (rightToLeft) { | ||
735 | int x = int(viewConverter->documentToViewX(effectiveActiveRangeEnd() - firstLineIndent - paragraphIndent) + offset); | 929 | int x = int(viewConverter->documentToViewX(effectiveActiveRangeEnd() - firstLineIndent - paragraphIndent) + offset); | ||
736 | if (pos.x() >= x - 8 && pos.x() <= x +8 && pos.y() < height / 2) { | 930 | if (pos.x() >= x - 8 && pos.x() <= x +8 && pos.y() < height / 2) { | ||
737 | if (selectOffset) | 931 | if (selectOffset) | ||
738 | *selectOffset = x - pos.x(); | 932 | *selectOffset = x - pos.x(); | ||
739 | return KReportRulerPrivate::FirstLineIndent; | 933 | return KReportRuler::Private::FirstLineIndent; | ||
740 | } | 934 | } | ||
741 | 935 | | |||
742 | x = int(viewConverter->documentToViewX(effectiveActiveRangeEnd() - paragraphIndent) + offset); | 936 | x = int(viewConverter->documentToViewX(effectiveActiveRangeEnd() - paragraphIndent) + offset); | ||
743 | if (pos.x() >= x - 8 && pos.x() <= x +8 && pos.y() > height / 2) { | 937 | if (pos.x() >= x - 8 && pos.x() <= x +8 && pos.y() > height / 2) { | ||
744 | if (selectOffset) | 938 | if (selectOffset) | ||
745 | *selectOffset = x - pos.x(); | 939 | *selectOffset = x - pos.x(); | ||
746 | return KReportRulerPrivate::ParagraphIndent; | 940 | return KReportRuler::Private::ParagraphIndent; | ||
747 | } | 941 | } | ||
748 | 942 | | |||
749 | x = int(viewConverter->documentToViewX(effectiveActiveRangeStart() + endIndent) + offset); | 943 | x = int(viewConverter->documentToViewX(effectiveActiveRangeStart() + endIndent) + offset); | ||
750 | if (pos.x() >= x - 8 && pos.x() <= x + 8) { | 944 | if (pos.x() >= x - 8 && pos.x() <= x + 8) { | ||
751 | if (selectOffset) | 945 | if (selectOffset) | ||
752 | *selectOffset = x - pos.x(); | 946 | *selectOffset = x - pos.x(); | ||
753 | return KReportRulerPrivate::EndIndent; | 947 | return KReportRuler::Private::EndIndent; | ||
754 | } | 948 | } | ||
755 | } | 949 | } | ||
756 | else { | 950 | else { | ||
757 | int x = int(viewConverter->documentToViewX(effectiveActiveRangeStart() + firstLineIndent + paragraphIndent) + offset); | 951 | int x = int(viewConverter->documentToViewX(effectiveActiveRangeStart() + firstLineIndent + paragraphIndent) + offset); | ||
758 | if (pos.x() >= x -8 && pos.x() <= x + 8 && pos.y() < height / 2) { | 952 | if (pos.x() >= x -8 && pos.x() <= x + 8 && pos.y() < height / 2) { | ||
759 | if (selectOffset) | 953 | if (selectOffset) | ||
760 | *selectOffset = x - pos.x(); | 954 | *selectOffset = x - pos.x(); | ||
761 | return KReportRulerPrivate::FirstLineIndent; | 955 | return KReportRuler::Private::FirstLineIndent; | ||
762 | } | 956 | } | ||
763 | 957 | | |||
764 | x = int(viewConverter->documentToViewX(effectiveActiveRangeStart() + paragraphIndent) + offset); | 958 | x = int(viewConverter->documentToViewX(effectiveActiveRangeStart() + paragraphIndent) + offset); | ||
765 | if (pos.x() >= x - 8 && pos.x() <= x + 8 && pos.y() > height/2) { | 959 | if (pos.x() >= x - 8 && pos.x() <= x + 8 && pos.y() > height/2) { | ||
766 | if (selectOffset) | 960 | if (selectOffset) | ||
767 | *selectOffset = x - pos.x(); | 961 | *selectOffset = x - pos.x(); | ||
768 | return KReportRulerPrivate::ParagraphIndent; | 962 | return KReportRuler::Private::ParagraphIndent; | ||
769 | } | 963 | } | ||
770 | 964 | | |||
771 | x = int(viewConverter->documentToViewX(effectiveActiveRangeEnd() - endIndent) + offset); | 965 | x = int(viewConverter->documentToViewX(effectiveActiveRangeEnd() - endIndent) + offset); | ||
772 | if (pos.x() >= x - 8 && pos.x() <= x + 8) { | 966 | if (pos.x() >= x - 8 && pos.x() <= x + 8) { | ||
773 | if (selectOffset) | 967 | if (selectOffset) | ||
774 | *selectOffset = x - pos.x(); | 968 | *selectOffset = x - pos.x(); | ||
775 | return KReportRulerPrivate::EndIndent; | 969 | return KReportRuler::Private::EndIndent; | ||
776 | } | 970 | } | ||
777 | } | 971 | } | ||
778 | 972 | | |||
779 | return KReportRulerPrivate::None; | 973 | return KReportRuler::Private::None; | ||
780 | } | 974 | } | ||
781 | 975 | | |||
782 | int KReportRulerPrivate::hotSpotIndex(const QPoint & pos) | 976 | int KReportRuler::Private::hotSpotIndex(const QPoint & pos) | ||
783 | { | 977 | { | ||
784 | for(int counter = 0; counter < hotspots.count(); counter++) { | 978 | for(int counter = 0; counter < hotspots.count(); counter++) { | ||
785 | bool hit; | 979 | bool hit; | ||
786 | if (orientation == Qt::Horizontal) | 980 | if (orientation == Qt::Horizontal) | ||
787 | hit = qAbs(viewConverter->documentToViewX(hotspots[counter].position) - pos.x() + offset) < 3; | 981 | hit = qAbs(viewConverter->documentToViewX(hotspots[counter].position) - pos.x() + offset) < 3; | ||
788 | else | 982 | else | ||
789 | hit = qAbs(viewConverter->documentToViewY(hotspots[counter].position) - pos.y() + offset) < 3; | 983 | hit = qAbs(viewConverter->documentToViewY(hotspots[counter].position) - pos.y() + offset) < 3; | ||
790 | 984 | | |||
791 | if (hit) | 985 | if (hit) | ||
792 | return counter; | 986 | return counter; | ||
793 | } | 987 | } | ||
794 | return -1; | 988 | return -1; | ||
795 | } | 989 | } | ||
796 | 990 | | |||
797 | qreal KReportRulerPrivate::effectiveActiveRangeStart() const | 991 | qreal KReportRuler::Private::effectiveActiveRangeStart() const | ||
798 | { | 992 | { | ||
799 | if (activeOverrideRangeStart != activeOverrideRangeEnd) { | 993 | if (activeOverrideRangeStart != activeOverrideRangeEnd) { | ||
800 | return activeOverrideRangeStart; | 994 | return activeOverrideRangeStart; | ||
801 | } else { | 995 | } else { | ||
802 | return activeRangeStart; | 996 | return activeRangeStart; | ||
803 | } | 997 | } | ||
804 | } | 998 | } | ||
805 | 999 | | |||
806 | qreal KReportRulerPrivate::effectiveActiveRangeEnd() const | 1000 | qreal KReportRuler::Private::effectiveActiveRangeEnd() const | ||
807 | { | 1001 | { | ||
808 | if (activeOverrideRangeStart != activeOverrideRangeEnd) { | 1002 | if (activeOverrideRangeStart != activeOverrideRangeEnd) { | ||
809 | return activeOverrideRangeEnd; | 1003 | return activeOverrideRangeEnd; | ||
810 | } else { | 1004 | } else { | ||
811 | return activeRangeEnd; | 1005 | return activeRangeEnd; | ||
812 | } | 1006 | } | ||
813 | } | 1007 | } | ||
814 | 1008 | | |||
815 | void KReportRulerPrivate::emitTabChanged() | 1009 | void KReportRuler::Private::emitTabChanged() | ||
816 | { | 1010 | { | ||
817 | KReportRuler::Tab tab; | 1011 | KReportRuler::Tab tab; | ||
818 | if (currentIndex >= 0) | 1012 | if (currentIndex >= 0) | ||
819 | tab = tabs[currentIndex]; | 1013 | tab = tabs[currentIndex]; | ||
820 | emit ruler->tabChanged(originalIndex, currentIndex >= 0 ? &tab : 0); | 1014 | emit ruler->tabChanged(originalIndex, currentIndex >= 0 ? &tab : 0); | ||
821 | } | 1015 | } | ||
822 | 1016 | | |||
823 | 1017 | | |||
824 | KReportRuler::KReportRuler(QWidget* parent, Qt::Orientation orientation, const KReportZoomHandler* viewConverter) | 1018 | KReportRuler::KReportRuler(QWidget* parent, Qt::Orientation orientation, | ||
1019 | const KReportZoomHandler &zoomHandler) | ||||
825 | : QWidget(parent) | 1020 | : QWidget(parent) | ||
826 | , d( new KReportRulerPrivate( this, viewConverter, orientation) ) | 1021 | , d(new KReportRuler::Private(this, zoomHandler, orientation)) | ||
827 | { | 1022 | { | ||
828 | setMouseTracking( true ); | 1023 | setMouseTracking( true ); | ||
829 | } | 1024 | } | ||
830 | 1025 | | |||
831 | KReportRuler::~KReportRuler() | 1026 | KReportRuler::~KReportRuler() | ||
832 | { | 1027 | { | ||
833 | delete d; | 1028 | delete d; | ||
834 | } | 1029 | } | ||
▲ Show 20 Lines • Show All 209 Lines • ▼ Show 20 Line(s) | |||||
1044 | QList<QAction*> KReportRuler::popupActionList() const | 1239 | QList<QAction*> KReportRuler::popupActionList() const | ||
1045 | { | 1240 | { | ||
1046 | return d->popupActions; | 1241 | return d->popupActions; | ||
1047 | } | 1242 | } | ||
1048 | 1243 | | |||
1049 | void KReportRuler::mousePressEvent ( QMouseEvent* ev ) | 1244 | void KReportRuler::mousePressEvent ( QMouseEvent* ev ) | ||
1050 | { | 1245 | { | ||
1051 | d->tabMoved = false; | 1246 | d->tabMoved = false; | ||
1052 | d->selected = KReportRulerPrivate::None; | 1247 | d->selected = KReportRuler::Private::None; | ||
1053 | if (ev->button() == Qt::RightButton && !d->popupActions.isEmpty()) | 1248 | if (ev->button() == Qt::RightButton && !d->popupActions.isEmpty()) | ||
1054 | QMenu::exec(d->popupActions, ev->globalPos()); | 1249 | QMenu::exec(d->popupActions, ev->globalPos()); | ||
1055 | if (ev->button() != Qt::LeftButton) { | 1250 | if (ev->button() != Qt::LeftButton) { | ||
1056 | ev->ignore(); | 1251 | ev->ignore(); | ||
1057 | return; | 1252 | return; | ||
1058 | } | 1253 | } | ||
1059 | 1254 | | |||
1060 | QPoint pos = ev->pos(); | 1255 | QPoint pos = ev->pos(); | ||
1061 | 1256 | | |||
1062 | if (d->showTabs) { | 1257 | if (d->showTabs) { | ||
1063 | int i = 0; | 1258 | int i = 0; | ||
1064 | int x; | 1259 | int x; | ||
1065 | foreach (const Tab & t, d->tabs) { | 1260 | foreach (const Tab & t, d->tabs) { | ||
1066 | if (d->rightToLeft) { | 1261 | if (d->rightToLeft) { | ||
1067 | x = d->viewConverter->documentToViewX(d->effectiveActiveRangeEnd() | 1262 | x = d->viewConverter->documentToViewX(d->effectiveActiveRangeEnd() | ||
1068 | - (d->relativeTabs ? d->paragraphIndent : 0) - t.position) + d->offset; | 1263 | - (d->relativeTabs ? d->paragraphIndent : 0) - t.position) + d->offset; | ||
1069 | } else { | 1264 | } else { | ||
1070 | x = d->viewConverter->documentToViewX(d->effectiveActiveRangeStart() | 1265 | x = d->viewConverter->documentToViewX(d->effectiveActiveRangeStart() | ||
1071 | + (d->relativeTabs ? d->paragraphIndent : 0) + t.position) + d->offset; | 1266 | + (d->relativeTabs ? d->paragraphIndent : 0) + t.position) + d->offset; | ||
1072 | } | 1267 | } | ||
1073 | if (pos.x() >= x-6 && pos.x() <= x+6) { | 1268 | if (pos.x() >= x-6 && pos.x() <= x+6) { | ||
1074 | d->selected = KReportRulerPrivate::Tab; | 1269 | d->selected = KReportRuler::Private::Tab; | ||
1075 | d->selectOffset = x - pos.x(); | 1270 | d->selectOffset = x - pos.x(); | ||
1076 | d->currentIndex = i; | 1271 | d->currentIndex = i; | ||
1077 | break; | 1272 | break; | ||
1078 | } | 1273 | } | ||
1079 | i++; | 1274 | i++; | ||
1080 | } | 1275 | } | ||
1081 | d->originalIndex = d->currentIndex; | 1276 | d->originalIndex = d->currentIndex; | ||
1082 | } | 1277 | } | ||
1083 | 1278 | | |||
1084 | if (d->selected == KReportRulerPrivate::None) | 1279 | if (d->selected == KReportRuler::Private::None) | ||
1085 | d->selected = d->selectionAtPosition(ev->pos(), &d->selectOffset); | 1280 | d->selected = d->selectionAtPosition(ev->pos(), &d->selectOffset); | ||
1086 | if (d->selected == KReportRulerPrivate::None) { | 1281 | if (d->selected == KReportRuler::Private::None) { | ||
1087 | int hotSpotIndex = d->hotSpotIndex(ev->pos()); | 1282 | int hotSpotIndex = d->hotSpotIndex(ev->pos()); | ||
1088 | if (hotSpotIndex >= 0) { | 1283 | if (hotSpotIndex >= 0) { | ||
1089 | d->selected = KReportRulerPrivate::HotSpot; | 1284 | d->selected = KReportRuler::Private::HotSpot; | ||
1090 | update(); | 1285 | update(); | ||
1091 | } | 1286 | } | ||
1092 | } | 1287 | } | ||
1093 | 1288 | | |||
1094 | if (d->showTabs && d->selected == KReportRulerPrivate::None) { | 1289 | if (d->showTabs && d->selected == KReportRuler::Private::None) { | ||
1095 | // still haven't found something so let assume the user wants to add a tab | 1290 | // still haven't found something so let assume the user wants to add a tab | ||
1096 | qreal tabpos; | 1291 | qreal tabpos; | ||
1097 | if (d->rightToLeft) { | 1292 | if (d->rightToLeft) { | ||
1098 | tabpos = d->viewConverter->viewToDocumentX(pos.x() - d->offset) | 1293 | tabpos = d->viewConverter->viewToDocumentX(pos.x() - d->offset) | ||
1099 | + d->effectiveActiveRangeEnd() + (d->relativeTabs ? d->paragraphIndent : 0); | 1294 | + d->effectiveActiveRangeEnd() + (d->relativeTabs ? d->paragraphIndent : 0); | ||
1100 | } else { | 1295 | } else { | ||
1101 | tabpos = d->viewConverter->viewToDocumentX(pos.x() - d->offset) | 1296 | tabpos = d->viewConverter->viewToDocumentX(pos.x() - d->offset) | ||
1102 | - d->effectiveActiveRangeStart() - (d->relativeTabs ? d->paragraphIndent : 0); | 1297 | - d->effectiveActiveRangeStart() - (d->relativeTabs ? d->paragraphIndent : 0); | ||
1103 | } | 1298 | } | ||
1104 | Tab t(tabpos, d->tabChooser ? d->tabChooser->type() : | 1299 | Tab t(tabpos, d->tabChooser ? d->tabChooser->type() : | ||
1105 | d->rightToLeft ? QTextOption::RightTab : | 1300 | d->rightToLeft ? QTextOption::RightTab : | ||
1106 | QTextOption::LeftTab); | 1301 | QTextOption::LeftTab); | ||
1107 | d->tabs.append(t); | 1302 | d->tabs.append(t); | ||
1108 | d->selectOffset = 0; | 1303 | d->selectOffset = 0; | ||
1109 | d->selected = KReportRulerPrivate::Tab; | 1304 | d->selected = KReportRuler::Private::Tab; | ||
1110 | d->currentIndex = d->tabs.count() - 1; | 1305 | d->currentIndex = d->tabs.count() - 1; | ||
1111 | d->originalIndex = -1; // new! | 1306 | d->originalIndex = -1; // new! | ||
1112 | update(); | 1307 | update(); | ||
1113 | } | 1308 | } | ||
1114 | if (d->orientation == Qt::Horizontal && (ev->modifiers() & Qt::ShiftModifier) && | 1309 | if (d->orientation == Qt::Horizontal && (ev->modifiers() & Qt::ShiftModifier) && | ||
1115 | (d->selected == KReportRulerPrivate::FirstLineIndent || | 1310 | (d->selected == KReportRuler::Private::FirstLineIndent || | ||
1116 | d->selected == KReportRulerPrivate::ParagraphIndent || | 1311 | d->selected == KReportRuler::Private::ParagraphIndent || | ||
1117 | d->selected == KReportRulerPrivate::Tab || | 1312 | d->selected == KReportRuler::Private::Tab || | ||
1118 | d->selected == KReportRulerPrivate::EndIndent)) | 1313 | d->selected == KReportRuler::Private::EndIndent)) | ||
1119 | d->paintingStrategy = d->distancesPaintingStrategy; | 1314 | d->paintingStrategy = d->distancesPaintingStrategy; | ||
1120 | 1315 | | |||
1121 | if (d->selected != KReportRulerPrivate::None) | 1316 | if (d->selected != KReportRuler::Private::None) | ||
1122 | emit aboutToChange(); | 1317 | emit aboutToChange(); | ||
1123 | } | 1318 | } | ||
1124 | 1319 | | |||
1125 | void KReportRuler::mouseReleaseEvent ( QMouseEvent* ev ) | 1320 | void KReportRuler::mouseReleaseEvent ( QMouseEvent* ev ) | ||
1126 | { | 1321 | { | ||
1127 | ev->accept(); | 1322 | ev->accept(); | ||
1128 | if (d->selected == KReportRulerPrivate::Tab) { | 1323 | if (d->selected == KReportRuler::Private::Tab) { | ||
1129 | if (d->originalIndex >= 0 && !d->tabMoved) { | 1324 | if (d->originalIndex >= 0 && !d->tabMoved) { | ||
1130 | int type = d->tabs[d->currentIndex].type; | 1325 | int type = d->tabs[d->currentIndex].type; | ||
1131 | type++; | 1326 | type++; | ||
1132 | if (type > 3) | 1327 | if (type > 3) | ||
1133 | type = 0; | 1328 | type = 0; | ||
1134 | d->tabs[d->currentIndex].type = static_cast<QTextOption::TabType> (type); | 1329 | d->tabs[d->currentIndex].type = static_cast<QTextOption::TabType> (type); | ||
1135 | update(); | 1330 | update(); | ||
1136 | } | 1331 | } | ||
1137 | d->emitTabChanged(); | 1332 | d->emitTabChanged(); | ||
1138 | } | 1333 | } | ||
1139 | else if( d->selected != KReportRulerPrivate::None) | 1334 | else if( d->selected != KReportRuler::Private::None) | ||
1140 | emit indentsChanged(true); | 1335 | emit indentsChanged(true); | ||
1141 | else | 1336 | else | ||
1142 | ev->ignore(); | 1337 | ev->ignore(); | ||
1143 | 1338 | | |||
1144 | d->paintingStrategy = d->normalPaintingStrategy; | 1339 | d->paintingStrategy = d->normalPaintingStrategy; | ||
1145 | d->selected = KReportRulerPrivate::None; | 1340 | d->selected = KReportRuler::Private::None; | ||
1146 | } | 1341 | } | ||
1147 | 1342 | | |||
1148 | void KReportRuler::mouseMoveEvent ( QMouseEvent* ev ) | 1343 | void KReportRuler::mouseMoveEvent ( QMouseEvent* ev ) | ||
1149 | { | 1344 | { | ||
1150 | QPoint pos = ev->pos(); | 1345 | QPoint pos = ev->pos(); | ||
1151 | 1346 | | |||
1152 | qreal activeLength = d->effectiveActiveRangeEnd() - d->effectiveActiveRangeStart(); | 1347 | qreal activeLength = d->effectiveActiveRangeEnd() - d->effectiveActiveRangeStart(); | ||
1153 | 1348 | | |||
1154 | switch (d->selected) { | 1349 | switch (d->selected) { | ||
1155 | case KReportRulerPrivate::FirstLineIndent: | 1350 | case KReportRuler::Private::FirstLineIndent: | ||
1156 | if (d->rightToLeft) | 1351 | if (d->rightToLeft) | ||
1157 | d->firstLineIndent = d->effectiveActiveRangeEnd() - d->paragraphIndent - | 1352 | d->firstLineIndent = d->effectiveActiveRangeEnd() - d->paragraphIndent - | ||
1158 | d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset - d->offset); | 1353 | d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset - d->offset); | ||
1159 | else | 1354 | else | ||
1160 | d->firstLineIndent = d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset | 1355 | d->firstLineIndent = d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset | ||
1161 | - d->offset) - d->effectiveActiveRangeStart() - d->paragraphIndent; | 1356 | - d->offset) - d->effectiveActiveRangeStart() - d->paragraphIndent; | ||
1162 | if( ! (ev->modifiers() & Qt::ShiftModifier)) { | 1357 | if( ! (ev->modifiers() & Qt::ShiftModifier)) { | ||
1163 | d->firstLineIndent = d->doSnapping(d->firstLineIndent); | 1358 | d->firstLineIndent = d->doSnapping(d->firstLineIndent); | ||
1164 | d->paintingStrategy = d->normalPaintingStrategy; | 1359 | d->paintingStrategy = d->normalPaintingStrategy; | ||
1165 | } else { | 1360 | } else { | ||
1166 | if (d->orientation == Qt::Horizontal) | 1361 | if (d->orientation == Qt::Horizontal) | ||
1167 | d->paintingStrategy = d->distancesPaintingStrategy; | 1362 | d->paintingStrategy = d->distancesPaintingStrategy; | ||
1168 | } | 1363 | } | ||
1169 | 1364 | | |||
1170 | emit indentsChanged(false); | 1365 | emit indentsChanged(false); | ||
1171 | break; | 1366 | break; | ||
1172 | case KReportRulerPrivate::ParagraphIndent: | 1367 | case KReportRuler::Private::ParagraphIndent: | ||
1173 | if (d->rightToLeft) | 1368 | if (d->rightToLeft) | ||
1174 | d->paragraphIndent = d->effectiveActiveRangeEnd() - | 1369 | d->paragraphIndent = d->effectiveActiveRangeEnd() - | ||
1175 | d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset - d->offset); | 1370 | d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset - d->offset); | ||
1176 | else | 1371 | else | ||
1177 | d->paragraphIndent = d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset | 1372 | d->paragraphIndent = d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset | ||
1178 | - d->offset) - d->effectiveActiveRangeStart(); | 1373 | - d->offset) - d->effectiveActiveRangeStart(); | ||
1179 | if( ! (ev->modifiers() & Qt::ShiftModifier)) { | 1374 | if( ! (ev->modifiers() & Qt::ShiftModifier)) { | ||
1180 | d->paragraphIndent = d->doSnapping(d->paragraphIndent); | 1375 | d->paragraphIndent = d->doSnapping(d->paragraphIndent); | ||
1181 | d->paintingStrategy = d->normalPaintingStrategy; | 1376 | d->paintingStrategy = d->normalPaintingStrategy; | ||
1182 | } else { | 1377 | } else { | ||
1183 | if (d->orientation == Qt::Horizontal) | 1378 | if (d->orientation == Qt::Horizontal) | ||
1184 | d->paintingStrategy = d->distancesPaintingStrategy; | 1379 | d->paintingStrategy = d->distancesPaintingStrategy; | ||
1185 | } | 1380 | } | ||
1186 | 1381 | | |||
1187 | if (d->paragraphIndent + d->endIndent > activeLength) | 1382 | if (d->paragraphIndent + d->endIndent > activeLength) | ||
1188 | d->paragraphIndent = activeLength - d->endIndent; | 1383 | d->paragraphIndent = activeLength - d->endIndent; | ||
1189 | emit indentsChanged(false); | 1384 | emit indentsChanged(false); | ||
1190 | break; | 1385 | break; | ||
1191 | case KReportRulerPrivate::EndIndent: | 1386 | case KReportRuler::Private::EndIndent: | ||
1192 | if (d->rightToLeft) | 1387 | if (d->rightToLeft) | ||
1193 | d->endIndent = d->viewConverter->viewToDocumentX(pos.x() | 1388 | d->endIndent = d->viewConverter->viewToDocumentX(pos.x() | ||
1194 | + d->selectOffset - d->offset) - d->effectiveActiveRangeStart(); | 1389 | + d->selectOffset - d->offset) - d->effectiveActiveRangeStart(); | ||
1195 | else | 1390 | else | ||
1196 | d->endIndent = d->effectiveActiveRangeEnd() - d->viewConverter->viewToDocumentX(pos.x() | 1391 | d->endIndent = d->effectiveActiveRangeEnd() - d->viewConverter->viewToDocumentX(pos.x() | ||
1197 | + d->selectOffset - d->offset); | 1392 | + d->selectOffset - d->offset); | ||
1198 | if (!(ev->modifiers() & Qt::ShiftModifier)) { | 1393 | if (!(ev->modifiers() & Qt::ShiftModifier)) { | ||
1199 | d->endIndent = d->doSnapping(d->endIndent); | 1394 | d->endIndent = d->doSnapping(d->endIndent); | ||
1200 | d->paintingStrategy = d->normalPaintingStrategy; | 1395 | d->paintingStrategy = d->normalPaintingStrategy; | ||
1201 | } else { | 1396 | } else { | ||
1202 | if (d->orientation == Qt::Horizontal) | 1397 | if (d->orientation == Qt::Horizontal) | ||
1203 | d->paintingStrategy = d->distancesPaintingStrategy; | 1398 | d->paintingStrategy = d->distancesPaintingStrategy; | ||
1204 | } | 1399 | } | ||
1205 | 1400 | | |||
1206 | if (d->paragraphIndent + d->endIndent > activeLength) | 1401 | if (d->paragraphIndent + d->endIndent > activeLength) | ||
1207 | d->endIndent = activeLength - d->paragraphIndent; | 1402 | d->endIndent = activeLength - d->paragraphIndent; | ||
1208 | emit indentsChanged(false); | 1403 | emit indentsChanged(false); | ||
1209 | break; | 1404 | break; | ||
1210 | case KReportRulerPrivate::Tab: | 1405 | case KReportRuler::Private::Tab: | ||
1211 | d->tabMoved = true; | 1406 | d->tabMoved = true; | ||
1212 | if (d->currentIndex < 0) { // tab is deleted. | 1407 | if (d->currentIndex < 0) { // tab is deleted. | ||
1213 | if (ev->pos().y() < height()) { // reinstante it. | 1408 | if (ev->pos().y() < height()) { // reinstante it. | ||
1214 | d->currentIndex = d->tabs.count(); | 1409 | d->currentIndex = d->tabs.count(); | ||
1215 | d->tabs.append(d->deletedTab); | 1410 | d->tabs.append(d->deletedTab); | ||
1216 | } else { | 1411 | } else { | ||
1217 | break; | 1412 | break; | ||
1218 | } | 1413 | } | ||
Show All 19 Lines | 1432 | if ( d->originalIndex == -1 ) | |||
1238 | emit guideLineCreated(d->orientation, | 1433 | emit guideLineCreated(d->orientation, | ||
1239 | d->orientation == Qt::Horizontal | 1434 | d->orientation == Qt::Horizontal | ||
1240 | ? d->viewConverter->viewToDocumentY(ev->pos().y()) | 1435 | ? d->viewConverter->viewToDocumentY(ev->pos().y()) | ||
1241 | : d->viewConverter->viewToDocumentX(ev->pos().x())); | 1436 | : d->viewConverter->viewToDocumentX(ev->pos().x())); | ||
1242 | } | 1437 | } | ||
1243 | 1438 | | |||
1244 | d->emitTabChanged(); | 1439 | d->emitTabChanged(); | ||
1245 | break; | 1440 | break; | ||
1246 | case KReportRulerPrivate::HotSpot: | 1441 | case KReportRuler::Private::HotSpot: | ||
1247 | qreal newPos; | 1442 | qreal newPos; | ||
1248 | if (d->orientation == Qt::Horizontal) | 1443 | if (d->orientation == Qt::Horizontal) | ||
1249 | newPos= d->viewConverter->viewToDocumentX(pos.x() - d->offset); | 1444 | newPos= d->viewConverter->viewToDocumentX(pos.x() - d->offset); | ||
1250 | else | 1445 | else | ||
1251 | newPos= d->viewConverter->viewToDocumentY(pos.y() - d->offset); | 1446 | newPos= d->viewConverter->viewToDocumentY(pos.y() - d->offset); | ||
1252 | d->hotspots[d->currentIndex].position = newPos; | 1447 | d->hotspots[d->currentIndex].position = newPos; | ||
1253 | emit hotSpotChanged(d->hotspots[d->currentIndex].id, newPos); | 1448 | emit hotSpotChanged(d->hotspots[d->currentIndex].id, newPos); | ||
1254 | break; | 1449 | break; | ||
1255 | case KReportRulerPrivate::None: | 1450 | case KReportRuler::Private::None: | ||
1256 | d->mouseCoordinate = (d->orientation == Qt::Horizontal ? pos.x() : pos.y()) - d->offset; | 1451 | d->mouseCoordinate = (d->orientation == Qt::Horizontal ? pos.x() : pos.y()) - d->offset; | ||
1257 | int hotSpotIndex = d->hotSpotIndex(pos); | 1452 | int hotSpotIndex = d->hotSpotIndex(pos); | ||
1258 | if (hotSpotIndex >= 0) { | 1453 | if (hotSpotIndex >= 0) { | ||
1259 | setCursor(QCursor( d->orientation == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor )); | 1454 | setCursor(QCursor( d->orientation == Qt::Horizontal ? Qt::SplitHCursor : Qt::SplitVCursor )); | ||
1260 | break; | 1455 | break; | ||
1261 | } | 1456 | } | ||
1262 | unsetCursor(); | 1457 | unsetCursor(); | ||
1263 | 1458 | | |||
1264 | KReportRulerPrivate::Selection selection = d->selectionAtPosition(pos); | 1459 | KReportRuler::Private::Selection selection = d->selectionAtPosition(pos); | ||
1265 | QString text; | 1460 | QString text; | ||
1266 | switch(selection) { | 1461 | switch(selection) { | ||
1267 | case KReportRulerPrivate::FirstLineIndent: text = tr("First line indent"); break; | 1462 | case KReportRuler::Private::FirstLineIndent: text = tr("First line indent"); break; | ||
1268 | case KReportRulerPrivate::ParagraphIndent: text = tr("Left indent"); break; | 1463 | case KReportRuler::Private::ParagraphIndent: text = tr("Left indent"); break; | ||
1269 | case KReportRulerPrivate::EndIndent: text = tr("Right indent"); break; | 1464 | case KReportRuler::Private::EndIndent: text = tr("Right indent"); break; | ||
1270 | case KReportRulerPrivate::None: | 1465 | case KReportRuler::Private::None: | ||
1271 | if (ev->buttons() & Qt::LeftButton) { | 1466 | if (ev->buttons() & Qt::LeftButton) { | ||
1272 | if (d->orientation == Qt::Horizontal && ev->pos().y() > height() + OutsideRulerThreshold) | 1467 | if (d->orientation == Qt::Horizontal && ev->pos().y() > height() + OutsideRulerThreshold) | ||
1273 | emit guideLineCreated(d->orientation, d->viewConverter->viewToDocumentY(ev->pos().y())); | 1468 | emit guideLineCreated(d->orientation, d->viewConverter->viewToDocumentY(ev->pos().y())); | ||
1274 | else if (d->orientation == Qt::Vertical && ev->pos().x() > width() + OutsideRulerThreshold) | 1469 | else if (d->orientation == Qt::Vertical && ev->pos().x() > width() + OutsideRulerThreshold) | ||
1275 | emit guideLineCreated(d->orientation, d->viewConverter->viewToDocumentX(ev->pos().x())); | 1470 | emit guideLineCreated(d->orientation, d->viewConverter->viewToDocumentX(ev->pos().x())); | ||
1276 | } | 1471 | } | ||
1277 | break; | 1472 | break; | ||
1278 | default: | 1473 | default: | ||
Show All 11 Lines | 1482 | { | |||
1290 | d->hotspots.clear(); | 1485 | d->hotspots.clear(); | ||
1291 | update(); | 1486 | update(); | ||
1292 | } | 1487 | } | ||
1293 | 1488 | | |||
1294 | void KReportRuler::setHotSpot(qreal position, int id) | 1489 | void KReportRuler::setHotSpot(qreal position, int id) | ||
1295 | { | 1490 | { | ||
1296 | int hotspotCount = d->hotspots.count(); | 1491 | int hotspotCount = d->hotspots.count(); | ||
1297 | for (int i = 0; i < hotspotCount; ++i) { | 1492 | for (int i = 0; i < hotspotCount; ++i) { | ||
1298 | KReportRulerPrivate::HotSpotData & hs = d->hotspots[i]; | 1493 | KReportRuler::Private::HotSpotData & hs = d->hotspots[i]; | ||
1299 | if (hs.id == id) { | 1494 | if (hs.id == id) { | ||
1300 | hs.position = position; | 1495 | hs.position = position; | ||
1301 | update(); | 1496 | update(); | ||
1302 | return; | 1497 | return; | ||
1303 | } | 1498 | } | ||
1304 | } | 1499 | } | ||
1305 | // not there yet, then insert it. | 1500 | // not there yet, then insert it. | ||
1306 | KReportRulerPrivate::HotSpotData hs; | 1501 | KReportRuler::Private::HotSpotData hs; | ||
1307 | hs.position = position; | 1502 | hs.position = position; | ||
1308 | hs.id = id; | 1503 | hs.id = id; | ||
1309 | d->hotspots.append(hs); | 1504 | d->hotspots.append(hs); | ||
1310 | } | 1505 | } | ||
1311 | 1506 | | |||
1312 | bool KReportRuler::removeHotSpot(int id) | 1507 | bool KReportRuler::removeHotSpot(int id) | ||
1313 | { | 1508 | { | ||
1314 | QList<KReportRulerPrivate::HotSpotData>::Iterator iter = d->hotspots.begin(); | 1509 | QList<KReportRuler::Private::HotSpotData>::Iterator iter = d->hotspots.begin(); | ||
1315 | while(iter != d->hotspots.end()) { | 1510 | while(iter != d->hotspots.end()) { | ||
1316 | if (iter->id == id) { | 1511 | if (iter->id == id) { | ||
1317 | d->hotspots.erase(iter); | 1512 | d->hotspots.erase(iter); | ||
1318 | update(); | 1513 | update(); | ||
1319 | return true; | 1514 | return true; | ||
1320 | } | 1515 | } | ||
1321 | } | 1516 | } | ||
1322 | return false; | 1517 | return false; | ||
1323 | } | 1518 | } |