Commit 0119e1b2 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

Changed: give the measurement numbers in the ruler a 1 pixel margin

makes assumption that digits for the number only use glyphs which do not go below the baseline

also make the rectangle of the horizontal ruler use the full height
improve centering of the number in the horizontal ruler
(vertical ruler has an offset due to an error in Qt?)

REVIEW: 104602
parent a6cee3df
......@@ -39,7 +39,13 @@
#include <KoViewConverter.h>
// the distance in pixels of a mouse position considered outside the rule
const int OutsideRulerThreshold = 20;
static const int OutsideRulerThreshold = 20;
//
static const int fullStepMarkerLength = 6;
static const int halfStepMarkerLength = 6;
static const int quarterStepMarkerLength = 3;
static const int measurementTextAboveBelowMargin = 1;
void RulerTabChooser::mousePressEvent(QMouseEvent *)
{
......@@ -112,9 +118,10 @@ QRectF HorizontalPaintingStrategy::drawBackground(const KoRulerPrivate *d, QPain
lengthInPixel = d->viewConverter->documentToViewX(d->rulerLength);
QRectF rectangle;
rectangle.setX(qMax(0, d->offset));
rectangle.setY(2);
rectangle.setWidth(qMin(qreal(d->ruler->width() - 1.0 - rectangle.x()), (d->offset >= 0 ) ? lengthInPixel : lengthInPixel + d->offset ));
rectangle.setHeight( d->ruler->height() - 6.0);
rectangle.setY(0);
rectangle.setWidth(qMin(qreal(d->ruler->width() - 1.0 - rectangle.x()),
(d->offset >= 0) ? lengthInPixel : lengthInPixel + d->offset));
rectangle.setHeight(d->ruler->height() - 1);
QRectF activeRangeRectangle;
activeRangeRectangle.setX(qMax(rectangle.x() + 1,
d->viewConverter->documentToViewX(d->effectiveActiveRangeStart()) + d->offset));
......@@ -151,7 +158,9 @@ void HorizontalPaintingStrategy::drawTabs(const KoRulerPrivate *d, QPainter &pai
return;
QPolygonF polygon;
painter.setBrush(d->ruler->palette().color(QPalette::Text));
const QColor tabColor = d->ruler->palette().color(QPalette::Text);
painter.setPen(tabColor);
painter.setBrush(tabColor);
painter.setRenderHint( QPainter::Antialiasing );
qreal position = -10000;
......@@ -170,29 +179,29 @@ void HorizontalPaintingStrategy::drawTabs(const KoRulerPrivate *d, QPainter &pai
polygon.clear();
switch (t.type) {
case QTextOption::LeftTab:
polygon << QPointF(x+0.5, d->ruler->height() - 8.5)
<< QPointF(x+6.5, d->ruler->height() - 2.5)
<< QPointF(x+0.5, d->ruler->height() - 2.5);
polygon << QPointF(x+0.5, d->ruler->height() - 6.5)
<< QPointF(x+6.5, d->ruler->height() - 0.5)
<< QPointF(x+0.5, d->ruler->height() - 0.5);
painter.drawPolygon(polygon);
break;
case QTextOption::RightTab:
polygon << QPointF(x+0.5, d->ruler->height() - 8.5)
<< QPointF(x-5.5, d->ruler->height() - 2.5)
<< QPointF(x+0.5, d->ruler->height() - 2.5);
polygon << QPointF(x+0.5, d->ruler->height() - 6.5)
<< QPointF(x-5.5, d->ruler->height() - 0.5)
<< QPointF(x+0.5, d->ruler->height() - 0.5);
painter.drawPolygon(polygon);
break;
case QTextOption::CenterTab:
polygon << QPointF(x+0.5, d->ruler->height() - 8.5)
<< QPointF(x-5.5, d->ruler->height() - 2.5)
<< QPointF(x+6.5, d->ruler->height() - 2.5);
polygon << QPointF(x+0.5, d->ruler->height() - 6.5)
<< QPointF(x-5.5, d->ruler->height() - 0.5)
<< QPointF(x+6.5, d->ruler->height() - 0.5);
painter.drawPolygon(polygon);
break;
case QTextOption::DelimiterTab:
polygon << QPointF(x-5.5, d->ruler->height() - 2.5)
<< QPointF(x+6.5, d->ruler->height() - 2.5);
polygon << QPointF(x-5.5, d->ruler->height() - 0.5)
<< QPointF(x+6.5, d->ruler->height() - 0.5);
painter.drawPolyline(polygon);
polygon << QPointF(x+0.5, d->ruler->height() - 2.5)
<< QPointF(x+0.5, d->ruler->height() - 8.5);
polygon << QPointF(x+0.5, d->ruler->height() - 0.5)
<< QPointF(x+0.5, d->ruler->height() - 6.5);
painter.drawPolyline(polygon);
break;
default:
......@@ -221,9 +230,9 @@ void HorizontalPaintingStrategy::drawTabs(const KoRulerPrivate *d, QPainter &pai
}
polygon.clear();
polygon << QPointF(x+0.5, d->ruler->height() - 5.5)
<< QPointF(x+4.5, d->ruler->height() - 2.5)
<< QPointF(x+0.5, d->ruler->height() - 2.5);
polygon << QPointF(x+0.5, d->ruler->height() - 3.5)
<< QPointF(x+4.5, d->ruler->height() - 0.5)
<< QPointF(x+0.5, d->ruler->height() - 0.5);
painter.drawPolygon(polygon);
position += d->tabDistance;
......@@ -276,7 +285,9 @@ void HorizontalPaintingStrategy::drawMeasurements(const KoRulerPrivate *d, QPain
int quarterStepCount = (start / qRound(numberStepPixel * 0.25)) + 1;
int pos = 0;
painter.setPen(d->ruler->palette().color(QPalette::Text));
const QPen numberPen(d->ruler->palette().color(QPalette::Text));
const QPen markerPen(d->ruler->palette().color(QPalette::Inactive, QPalette::Text));
painter.setPen(markerPen);
if(d->offset > 0)
painter.translate(d->offset, 0);
......@@ -294,7 +305,8 @@ void HorizontalPaintingStrategy::drawMeasurements(const KoRulerPrivate *d, QPain
if(i == nextStep) {
if(pos != 0)
painter.drawLine(QPointF(pos, rectangle.bottom()-1), QPointF(pos, rectangle.bottom() -6));
painter.drawLine(QPointF(pos, rectangle.bottom()-1),
QPointF(pos, rectangle.bottom() - fullStepMarkerLength));
int number = qRound(stepCount * numberStep);
if (adjustMillimeters)
......@@ -304,7 +316,11 @@ void HorizontalPaintingStrategy::drawMeasurements(const KoRulerPrivate *d, QPain
if (d->rightToLeft) { // this is done in a hacky way with the fine tuning done above
numberText = QString::number(hackyLength - stepCount * numberStep);
}
painter.drawText(QPointF(x-fontMetrics.width(numberText)/2, rectangle.bottom() -6), numberText);
painter.setPen(numberPen);
painter.drawText(QPointF(x-fontMetrics.width(numberText)/2.0,
rectangle.bottom() -fullStepMarkerLength -measurementTextAboveBelowMargin),
numberText);
painter.setPen(markerPen);
++stepCount;
nextStep = qRound(d->viewConverter->documentToViewX(
......@@ -318,7 +334,8 @@ void HorizontalPaintingStrategy::drawMeasurements(const KoRulerPrivate *d, QPain
}
else if(i == nextHalfStep) {
if(pos != 0)
painter.drawLine(QPointF(pos, rectangle.bottom()-1), QPointF(pos, rectangle.bottom() - 4));
painter.drawLine(QPointF(pos, rectangle.bottom()-1),
QPointF(pos, rectangle.bottom() - halfStepMarkerLength));
++halfStepCount;
nextHalfStep = qRound(d->viewConverter->documentToViewX(d->unit.fromUserValue(
......@@ -329,7 +346,8 @@ void HorizontalPaintingStrategy::drawMeasurements(const KoRulerPrivate *d, QPain
}
else if(i == nextQuarterStep) {
if(pos != 0)
painter.drawLine(QPointF(pos, rectangle.bottom()-1), QPointF(pos, rectangle.bottom() - 2));
painter.drawLine(QPointF(pos, rectangle.bottom()-1),
QPointF(pos, rectangle.bottom() - quarterStepMarkerLength));
++quarterStepCount;
nextQuarterStep = qRound(d->viewConverter->documentToViewX(d->unit.fromUserValue(
......@@ -401,15 +419,12 @@ void HorizontalPaintingStrategy::drawIndents(const KoRulerPrivate *d, QPainter &
QSize HorizontalPaintingStrategy::sizeHint()
{
QSize size;
QFont font = KGlobalSettings::toolBarFont();
QFontMetrics fm(font);
int minimum = fm.height() + 6;
// assumes that digits for the number only use glyphs which do not go below the baseline
const QFontMetrics fm(KGlobalSettings::toolBarFont());
const int digitsHeight = fm.ascent() + 1; // +1 for baseline
const int minimum = digitsHeight + fullStepMarkerLength + 2*measurementTextAboveBelowMargin;
size.setWidth( minimum );
size.setHeight( minimum );
return size;
return QSize(minimum, minimum);
}
QRectF VerticalPaintingStrategy::drawBackground(const KoRulerPrivate *d, QPainter &painter)
......@@ -419,7 +434,8 @@ QRectF VerticalPaintingStrategy::drawBackground(const KoRulerPrivate *d, QPainte
rectangle.setX(0);
rectangle.setY(qMax(0, d->offset));
rectangle.setWidth(d->ruler->width() - 1.0);
rectangle.setHeight(qMin(qreal(d->ruler->height() - 1.0 - rectangle.y()), (d->offset >= 0 ) ? lengthInPixel : lengthInPixel + d->offset ));
rectangle.setHeight(qMin(qreal(d->ruler->height() - 1.0 - rectangle.y()),
(d->offset >= 0) ? lengthInPixel : lengthInPixel + d->offset));
QRectF activeRangeRectangle;
activeRangeRectangle.setX(rectangle.x() + 1);
......@@ -434,7 +450,7 @@ QRectF VerticalPaintingStrategy::drawBackground(const KoRulerPrivate *d, QPainte
if(d->effectiveActiveRangeStart() != d->effectiveActiveRangeEnd())
painter.fillRect(activeRangeRectangle, d->ruler->palette().brush(QPalette::Base));
if(d->showSelectionBorders) {
// Draw first selection border
if(d->firstSelectionBorder > 0) {
......@@ -486,7 +502,9 @@ void VerticalPaintingStrategy::drawMeasurements(const KoRulerPrivate *d, QPainte
int halfStepCount = (start / qRound(numberStepPixel * 0.5)) + 1;
int quarterStepCount = (start / qRound(numberStepPixel * 0.25)) + 1;
painter.setPen(d->ruler->palette().color(QPalette::Text));
const QPen numberPen(d->ruler->palette().color(QPalette::Text));
const QPen markerPen(d->ruler->palette().color(QPalette::Inactive, QPalette::Text));
painter.setPen(markerPen);
if(d->offset > 0)
painter.translate(0, d->offset);
......@@ -505,16 +523,17 @@ void VerticalPaintingStrategy::drawMeasurements(const KoRulerPrivate *d, QPainte
if(i == nextStep) {
painter.save();
painter.translate(rectangle.right()-10, pos);
painter.translate(rectangle.right()-fullStepMarkerLength, pos);
if(pos != 0)
painter.drawLine(QPointF(0, 0), QPointF(9, 0));
painter.drawLine(QPointF(0, 0), QPointF(fullStepMarkerLength-1, 0));
painter.rotate(-90);
int number = qRound(stepCount * numberStep);
if (adjustMillimeters)
number /= 10;
QString numberText = QString::number(number);
painter.drawText(QPointF(-fontMetrics.width(numberText) / 2.0, 1), numberText);
painter.setPen(numberPen);
painter.drawText(QPointF(-fontMetrics.width(numberText) / 2.0, -measurementTextAboveBelowMargin), numberText);
painter.restore();
++stepCount;
......@@ -528,7 +547,8 @@ void VerticalPaintingStrategy::drawMeasurements(const KoRulerPrivate *d, QPainte
numberStep * 0.25 * quarterStepCount)));
} else if(i == nextHalfStep) {
if(pos != 0)
painter.drawLine(QPointF(rectangle.right() - 6, pos), QPointF(rectangle.right() - 1, pos));
painter.drawLine(QPointF(rectangle.right() - halfStepMarkerLength, pos),
QPointF(rectangle.right() - 1, pos));
++halfStepCount;
nextHalfStep = qRound(d->viewConverter->documentToViewY(d->unit.fromUserValue(
......@@ -538,7 +558,8 @@ void VerticalPaintingStrategy::drawMeasurements(const KoRulerPrivate *d, QPainte
numberStep * 0.25 * quarterStepCount)));
} else if(i == nextQuarterStep) {
if(pos != 0)
painter.drawLine(QPointF(rectangle.right() - 4, pos), QPointF(rectangle.right() - 1, pos));
painter.drawLine(QPointF(rectangle.right() - quarterStepMarkerLength, pos),
QPointF(rectangle.right() - 1, pos));
++quarterStepCount;
nextQuarterStep = qRound(d->viewConverter->documentToViewY(d->unit.fromUserValue(
......@@ -562,15 +583,12 @@ void VerticalPaintingStrategy::drawMeasurements(const KoRulerPrivate *d, QPainte
QSize VerticalPaintingStrategy::sizeHint()
{
QSize size;
QFont font = KGlobalSettings::toolBarFont();
QFontMetrics fm(font);
int minimum = fm.height() + 6;
// assumes that digits for the number only use glyphs which do not go below the baseline
const QFontMetrics fm(KGlobalSettings::toolBarFont());
const int digitsHeight = fm.ascent() + 1; // +1 for baseline
const int minimum = digitsHeight + fullStepMarkerLength + 2*measurementTextAboveBelowMargin;
size.setWidth( minimum );
size.setHeight( minimum );
return size;
return QSize(minimum, minimum);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment