Krita Source Code Documentation
Loading...
Searching...
No Matches
VerticalPaintingStrategy Class Reference

#include <KoRuler_p.h>

+ Inheritance diagram for VerticalPaintingStrategy:

Public Member Functions

QRectF drawBackground (const KoRulerPrivate *ruler, QPainter &painter) override
 
void drawIndents (const KoRulerPrivate *, QPainter &) override
 
void drawMeasurements (const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle) override
 
void drawTabs (const KoRulerPrivate *, QPainter &) override
 
QSize sizeHint () override
 
 VerticalPaintingStrategy ()
 
- Public Member Functions inherited from PaintingStrategy
 PaintingStrategy ()
 constructor
 
virtual ~PaintingStrategy ()
 destructor
 

Private Attributes

qreal lengthInPixel {0.0}
 

Detailed Description

Definition at line 86 of file KoRuler_p.h.

Constructor & Destructor Documentation

◆ VerticalPaintingStrategy()

VerticalPaintingStrategy::VerticalPaintingStrategy ( )
inline

Definition at line 89 of file KoRuler_p.h.

Member Function Documentation

◆ drawBackground()

QRectF VerticalPaintingStrategy::drawBackground ( const KoRulerPrivate * ruler,
QPainter & painter )
overridevirtual

Draw the background of the ruler.

Parameters
rulerthe ruler to draw on.
painterthe painter we can paint with.

Implements PaintingStrategy.

Definition at line 436 of file KoRuler.cpp.

437{
438 lengthInPixel = d->viewConverter->documentToViewY(d->rulerLength);
439 QRectF rectangle;
440 rectangle.setX(0);
441 rectangle.setY(qMax(0, d->offset));
442 rectangle.setWidth(d->ruler->width() - 1.0);
443 rectangle.setHeight(qMin(qreal(d->ruler->height() - 1.0 - rectangle.y()),
444 (d->offset >= 0) ? lengthInPixel : lengthInPixel + d->offset));
445
446 QRectF activeRangeRectangle;
447 activeRangeRectangle.setX(rectangle.x() + 1);
448 activeRangeRectangle.setY(qMax(rectangle.y() + 1,
449 d->viewConverter->documentToViewY(d->effectiveActiveRangeStart()) + d->offset));
450 activeRangeRectangle.setWidth(rectangle.width() - 2);
451 activeRangeRectangle.setBottom(qMin(rectangle.bottom() - 1,
452 d->viewConverter->documentToViewY(d->effectiveActiveRangeEnd()) + d->offset));
453
454 painter.setPen(QPen(d->ruler->palette().color(QPalette::Mid), 0));
455
456 painter.fillRect(rectangle,d->ruler->palette().color(QPalette::AlternateBase));
457 painter.drawRect(rectangle);
458
459 if(d->effectiveActiveRangeStart() != d->effectiveActiveRangeEnd())
460 painter.fillRect(activeRangeRectangle, d->ruler->palette().brush(QPalette::Base));
461
462 if(d->showSelectionBorders) {
463 // Draw first selection border
464 if(d->firstSelectionBorder > 0) {
465 qreal border = d->viewConverter->documentToViewY(d->firstSelectionBorder) + d->offset;
466 painter.drawLine(QPointF(rectangle.x() + 1, border), QPointF(rectangle.right() - 1, border));
467 }
468 // Draw second selection border
469 if(d->secondSelectionBorder > 0) {
470 qreal border = d->viewConverter->documentToViewY(d->secondSelectionBorder) + d->offset;
471 painter.drawLine(QPointF(rectangle.x() + 1, border), QPointF(rectangle.right() - 1, border));
472 }
473 }
474
475 return rectangle;
476}

References lengthInPixel.

◆ drawIndents()

void VerticalPaintingStrategy::drawIndents ( const KoRulerPrivate * ruler,
QPainter & painter )
inlineoverridevirtual

Draw the indicators for the indents of a text paragraph

Parameters
rulerthe ruler to draw on.
painterthe painter we can paint with.

Implements PaintingStrategy.

Definition at line 94 of file KoRuler_p.h.

94{ }

◆ drawMeasurements()

void VerticalPaintingStrategy::drawMeasurements ( const KoRulerPrivate * ruler,
QPainter & painter,
const QRectF & rectangle )
overridevirtual

Draw the indicators for the measurements which typically are drawn every [unit].

Parameters
rulerthe ruler to draw on.
painterthe painter we can paint with.
rectangle

Implements PaintingStrategy.

Definition at line 478 of file KoRuler.cpp.

479{
480 const QFont font = QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont);
481 const QFontMetrics fontMetrics(font);
482 const QPen numberPen(d->ruler->palette().color(QPalette::Text), 0);
483 const QPen markerPen(d->ruler->palette().color(QPalette::Inactive, QPalette::Text), 0);
484 painter.setPen(markerPen);
485 painter.setFont(font);
486
487 // length of the ruler in pixels
488 const int rulerLengthPixel = d->viewConverter->documentToViewY(d->rulerLength);
489 // length of the ruler in the chosen unit
490 const qreal rulerLengthUnit = d->unit.toUserValue(d->rulerLength);
491 // length of a unit in pixels
492 const qreal unitLength = d->viewConverter->documentToViewY(d->unit.fromUserValue(1.0));
493 // length of the text for longest number with some padding
494 const int textLength = fontMetrics.horizontalAdvance(QString::number(qCeil(rulerLengthUnit))) + 20;
495
496 // the minimal separation of numbers that won't make the text a mess
497 const qreal minimalNumberSeparation = qCeil(textLength / unitLength);
498 // the chosen separation of numbers so that we have "whole" numbers
499 qreal numberSeparation = minimalNumberSeparation;
500 if (minimalNumberSeparation <= 5) {
501 } else if (minimalNumberSeparation <= 10) {
502 numberSeparation = 10;
503 } else if (minimalNumberSeparation <= 20) {
504 numberSeparation = 20;
505 } else if (minimalNumberSeparation <= 50) {
506 numberSeparation = 50;
507 } else if (minimalNumberSeparation <= 100) {
508 numberSeparation = 100;
509 } else if (minimalNumberSeparation <= 200) {
510 numberSeparation = 200;
511 } else if (minimalNumberSeparation <= 500) {
512 numberSeparation = 500;
513 } else {
514 numberSeparation = qRound(qreal(numberSeparation / 100.0)) * 100;
515 }
516 // the chosen separation converted to pixel
517 const int pixelSeparation = qRound(d->viewConverter->documentToViewY(d->unit.fromUserValue(numberSeparation)));
518
519 // Draw the marks
520 const int rulerEnd = rulerLengthPixel + d->offset;
521 qreal numberStart = d->unit.toUserValue(d->viewConverter->viewToDocumentY(
522 rectangle.top() - d->offset));
523 // draw the partly hidden mark when the bottom part of the ruler is
524 // invisible
525 int pixelEnd = rectangle.bottom() - d->offset;
526 if (rulerEnd - textLength > rectangle.bottom()) {
527 pixelEnd += textLength;
528 }
529 qreal numberEnd = d->unit.toUserValue(d->viewConverter->viewToDocumentX(
530 pixelEnd));
531 if (d->offset < 0) {
532 numberStart -= fmod(numberStart, numberSeparation);
533 }
534 for(qreal n = numberStart; n < numberEnd; n += numberSeparation) {
535 int posOnRuler = qRound(d->viewConverter->documentToViewY(d->unit.fromUserValue(n)));
536 int y = d->offset + posOnRuler;
537
538 // to draw the primary mark
539 QString numberText = QString::number(n);
540 painter.save();
541 painter.translate(rectangle.right() - fullStepMarkerLength, y);
542 painter.drawLine(QPointF(0, 0),
543 QPointF(rectangle.right() - fullStepMarkerLength, 0));
544 painter.setPen(numberPen);
545 painter.rotate(-90);
546 painter.drawText(QPointF(-fontMetrics.horizontalAdvance(numberText) / 2.0, 0),
547 numberText);
548 painter.restore();
549
550 // start to draw secondary marks following the primary mark
551 painter.setPen(markerPen);
552
553 int yQuarterMark1 = qRound(qreal(y + pixelSeparation / 4.0));
554 if (yQuarterMark1 > rulerEnd)
555 break;
556 painter.drawLine(QPointF(rectangle.right() - 1, yQuarterMark1),
557 QPointF(rectangle.right() - quarterStepMarkerLength, yQuarterMark1));
558
559 int yHalfMark = qRound(qreal(y + pixelSeparation / 2.0));
560 if (yHalfMark > rulerEnd)
561 break;
562 painter.drawLine(QPointF(rectangle.right() - 1, yHalfMark),
563 QPointF(rectangle.right() - halfStepMarkerLength, yHalfMark));
564
565 int yQuarterMark2 = qRound(qreal(y + 3.0 * pixelSeparation / 4.0));
566 if (yQuarterMark2 > rulerEnd)
567 break;
568 painter.drawLine(QPointF(rectangle.right() - 1, yQuarterMark2),
569 QPointF(rectangle.right() - quarterStepMarkerLength, yQuarterMark2));
570 }
571
572 // Draw the mouse indicator
573 const int mouseCoord = d->mouseCoordinate + d->offset;
574 if (d->selected == KoRulerPrivate::None || d->selected == KoRulerPrivate::HotSpot) {
575 const qreal left = rectangle.left() + 1;
576 const qreal right = rectangle.right() -1;
577 if (d->selected == KoRulerPrivate::None
578 && d->showMousePosition
579 && d->mouseCoordinate > 0
580 && d->mouseCoordinate < rulerLengthPixel)
581 painter.drawLine(QPointF(left, mouseCoord), QPointF(right, mouseCoord));
582 foreach (const KoRulerPrivate::HotSpotData & hp, d->hotspots) {
583 const qreal y = d->viewConverter->documentToViewY(hp.position) + d->offset;
584 painter.drawLine(QPointF(left, y), QPointF(right, y));
585 }
586 }
587}
static const int halfStepMarkerLength
Definition KoRuler.cpp:34
static const int fullStepMarkerLength
Definition KoRuler.cpp:33
static const int quarterStepMarkerLength
Definition KoRuler.cpp:35

References fullStepMarkerLength, halfStepMarkerLength, KoRulerPrivate::HotSpot, KoRulerPrivate::None, KoRulerPrivate::HotSpotData::position, and quarterStepMarkerLength.

◆ drawTabs()

void VerticalPaintingStrategy::drawTabs ( const KoRulerPrivate * ruler,
QPainter & painter )
inlineoverridevirtual

Draw the indicators for text-tabs.

Parameters
rulerthe ruler to draw on.
painterthe painter we can paint with.

Implements PaintingStrategy.

Definition at line 92 of file KoRuler_p.h.

92{}

◆ sizeHint()

QSize VerticalPaintingStrategy::sizeHint ( )
overridevirtual

returns the size suggestion for a ruler with this strategy.

Implements PaintingStrategy.

Definition at line 589 of file KoRuler.cpp.

590{
591 // assumes that digits for the number only use glyphs which do not go below the baseline
592 const QFontMetrics fm(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
593 const int digitsHeight = fm.ascent() + 1; // +1 for baseline
594 const int minimum = digitsHeight + fullStepMarkerLength + 2*measurementTextAboveBelowMargin;
595
596 return QSize(minimum, 0);
597}
static const int measurementTextAboveBelowMargin
Definition KoRuler.cpp:36

References fullStepMarkerLength, and measurementTextAboveBelowMargin.

Member Data Documentation

◆ lengthInPixel

qreal VerticalPaintingStrategy::lengthInPixel {0.0}
private

Definition at line 98 of file KoRuler_p.h.

98{0.0};

The documentation for this class was generated from the following files: