Draw the indicators for the measurements which typically are drawn every [unit].
249{
250 const QFont font = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont);
251 const QFontMetrics fontMetrics(font);
252 const QPen numberPen(
d->ruler->palette().color(QPalette::Text), 0);
253 const QPen markerPen(
d->ruler->palette().color(QPalette::Inactive, QPalette::Text), 0);
254 painter.setPen(markerPen);
255 painter.setFont(font);
256
257
258 const int rulerLengthPixel =
d->viewConverter->documentToViewX(
d->rulerLength);
259
260 const qreal rulerLengthUnit =
d->unit.toUserValue(
d->rulerLength);
261
262 const qreal unitLength =
d->viewConverter->documentToViewX(
d->unit.fromUserValue(1.0));
263
264 const int textLength = fontMetrics.horizontalAdvance(QString::number(qCeil(rulerLengthUnit))) + 20;
265
266 const qreal minimalNumberSeparation = qCeil(textLength / unitLength);
267
268 qreal numberSeparation = minimalNumberSeparation;
269 if (minimalNumberSeparation <= 5) {
270 } else if (minimalNumberSeparation <= 10) {
271 numberSeparation = 10;
272 } else if (minimalNumberSeparation <= 20) {
273 numberSeparation = 20;
274 } else if (minimalNumberSeparation <= 50) {
275 numberSeparation = 50;
276 } else if (minimalNumberSeparation <= 100) {
277 numberSeparation = 100;
278 } else if (minimalNumberSeparation <= 200) {
279 numberSeparation = 200;
280 } else if (minimalNumberSeparation <= 500) {
281 numberSeparation = 500;
282 } else {
283 numberSeparation = qRound(qreal(numberSeparation / 100)) * 100;
284 }
285
286 const int pixelSeparation = qRound(
d->viewConverter->documentToViewX(
d->unit.fromUserValue(numberSeparation)));
287
288 const int secondarydisplacement =
d->rightToLeft ? -pixelSeparation : pixelSeparation;
289
290
291 int rulerEnd;
292 qreal numberStart, numberEnd;
293 if (
d->rightToLeft) {
294 rulerEnd =
d->offset;
295 numberStart =
d->unit.toUserValue(
d->viewConverter->viewToDocumentX(
296 rulerLengthPixel +
d->offset - rectangle.right()));
297
298
299 int pixelEnd = rulerLengthPixel +
d->offset - rectangle.left();
300 if (rulerEnd + textLength < rectangle.left()) {
301 pixelEnd -= textLength;
302 }
303 numberEnd =
d->unit.toUserValue(
d->viewConverter->viewToDocumentX(
304 pixelEnd));
305 if (rulerLengthPixel +
d->offset > rectangle.right()) {
306 numberStart -= fmod(numberStart, numberSeparation);
307 }
308 } else {
309 rulerEnd =
d->offset + rulerLengthPixel;
310 numberStart =
d->unit.toUserValue(
d->viewConverter->viewToDocumentX(
311 rectangle.left() -
d->offset));
312
313
314 int pixelEnd = rectangle.right() -
d->offset;
315 if (rulerEnd - textLength > rectangle.right()) {
316 pixelEnd += textLength;
317 }
318 numberEnd =
d->unit.toUserValue(
d->viewConverter->viewToDocumentX(
319 pixelEnd));
321 numberStart -= fmod(numberStart, numberSeparation);
322 }
323 }
324 for(qreal n = numberStart; n < numberEnd; n += numberSeparation) {
325 int posOnRuler = qRound(
d->viewConverter->documentToViewX(
d->unit.fromUserValue(n)));
326 int x = posOnRuler +
d->offset;
327 if (
d->rightToLeft) {
328 x =
d->offset + rulerLengthPixel - posOnRuler;
329 }
330
331
332 painter.drawLine(QPointF(x, rectangle.bottom()-1),
334 QString numberText = QString::number(n);
335 painter.setPen(numberPen);
336 painter.drawText(QPointF(x - fontMetrics.horizontalAdvance(numberText)/2.0,
338 numberText);
339
340 painter.setPen(markerPen);
341
342 int xQuarterMark1 = qRound(qreal(x) + qreal(secondarydisplacement) / 4.0);
343 if (
d->rightToLeft ? xQuarterMark1 < rulerEnd : xQuarterMark1 > rulerEnd)
344 break;
345 painter.drawLine(QPointF(xQuarterMark1, rectangle.bottom() - 1),
347
348 int xHalfMark = qRound(qreal(x) + qreal(secondarydisplacement) / 2.0);
349 if (
d->rightToLeft ? xHalfMark < rulerEnd : xHalfMark > rulerEnd)
350 break;
351 painter.drawLine(QPointF(xHalfMark, rectangle.bottom() - 1),
353
354 int xQuarterMark2 = qRound(qreal(x) + 3.0 * qreal(secondarydisplacement) / 4.0);
355 if (
d->rightToLeft ? xQuarterMark2 < rulerEnd : xQuarterMark2 > rulerEnd)
356 break;
357 painter.drawLine(QPointF(xQuarterMark2, rectangle.bottom() - 1),
359 }
360
361
362 const int mouseCoord =
d->mouseCoordinate +
d->offset;
364 const qreal top = rectangle.y() + 1;
365 const qreal bottom = rectangle.bottom() -1;
367 &&
d->showMousePosition
368 &&
d->mouseCoordinate > 0
369 &&
d->mouseCoordinate < rulerLengthPixel)
370 painter.drawLine(QPointF(mouseCoord, top), QPointF(mouseCoord, bottom));
372 const qreal
x =
d->viewConverter->documentToViewX(hp.
position) +
d->offset;
373 painter.drawLine(QPointF(x, top), QPointF(x, bottom));
374 }
375 }
376}
static const int measurementTextAboveBelowMargin
static const int halfStepMarkerLength
static const int fullStepMarkerLength
static const int quarterStepMarkerLength