Index: KoRuler.cpp
===================================================================
--- KoRuler.cpp	(revision 762855)
+++ KoRuler.cpp	(arbetskopia)
@@ -191,7 +191,7 @@
 #endif
 }
 
-void HorizontalPaintingStrategy::drawRulerStripes(const KoRulerPrivate *d, QPainter &painter, const QRectF &rectangle) {
+void HorizontalPaintingStrategy::drawMeasurements(const KoRulerPrivate *d, QPainter &painter, const QRectF &rectangle) {
     double numberStep = d->numberStepForUnit(); // number step in unit
     QRectF activeRangeRectangle;
     int numberStepPixel = qRound(d->viewConverter->documentToViewX(d->unit.fromUserValue(numberStep)));
@@ -406,7 +406,7 @@
     return rectangle;
 }
 
-void VerticalPaintingStrategy::drawRulerStripes(const KoRulerPrivate *d, QPainter &painter, const QRectF &rectangle) {
+void VerticalPaintingStrategy::drawMeasurements(const KoRulerPrivate *d, QPainter &painter, const QRectF &rectangle) {
     double numberStep = d->numberStepForUnit(); // number step in unit
     int numberStepPixel = qRound(d->viewConverter->documentToViewY( d->unit.fromUserValue(numberStep)));
     QFontMetrics fontMetrics(KGlobalSettings::toolBarFont());
@@ -523,6 +523,72 @@
     return size;
 }
 
+
+void HorizontalDistancesPaintingStrategy::drawDistanceLine(const KoRulerPrivate *d, QPainter &painter, const double start, const double end) {
+
+    // Don't draw too short lines
+    if (qMax(start, end) - qMin(start, end) < 1)
+        return;
+
+    painter.save();
+    painter.translate(d->offset, d->ruler->height() / 2);
+    painter.setPen(d->ruler->palette().color(QPalette::Text));
+    painter.setBrush(d->ruler->palette().color(QPalette::Text));
+
+    QLineF line(QPointF(d->viewConverter->documentToViewX(start), 0),
+            QPointF(d->viewConverter->documentToViewX(end), 0));
+    QPointF midPoint = line.pointAt(0.5);
+
+    // Draw the label text
+    QFont font = KGlobalSettings::smallestReadableFont();
+    font.setPointSize(6);
+    QFontMetrics fontMetrics(font);
+    QString label = d->unit.toUserStringValue(
+            d->viewConverter->viewToDocumentX(line.length())) + " " + KoUnit::unitName(d->unit);
+    QPointF labelPosition = QPointF(midPoint.x() - fontMetrics.width(label)/2,
+            midPoint.y() + fontMetrics.ascent()/2);
+    painter.setFont(font);
+    painter.drawText(labelPosition, label);
+
+    // Draw the arrow lines
+    double arrowLength = (line.length() - fontMetrics.width(label)) / 2 - 2;
+    arrowLength = qMax(0.0, arrowLength);
+    QLineF startArrow(line.p1(), line.pointAt(arrowLength / line.length()));
+    QLineF endArrow(line.p2(), line.pointAt(1.0 - arrowLength / line.length()));
+    painter.drawLine(startArrow);
+    painter.drawLine(endArrow);
+
+    // Draw the arrow heads
+    QPolygonF arrowHead;
+    arrowHead << line.p1() << QPointF(line.x1()+3, line.y1()-3)
+        << QPointF(line.x1()+3, line.y1()+3);
+    painter.drawPolygon(arrowHead);
+    arrowHead.clear();
+    arrowHead << line.p2() << QPointF(line.x2()-3, line.y2()-3)
+        << QPointF(line.x2()-3, line.y2()+3);
+    painter.drawPolygon(arrowHead);
+
+    painter.restore();
+}
+
+void HorizontalDistancesPaintingStrategy::drawMeasurements(const KoRulerPrivate *d, QPainter &painter, const QRectF&) {
+    QList<double> points;
+    points << 0.0;
+    points << d->activeRangeStart + d->paragraphIndent + d->firstLineIndent;
+    points << d->activeRangeStart + d->paragraphIndent;
+    points << d->activeRangeEnd - d->endIndent;
+    points << d->activeRangeStart;
+    points << d->activeRangeEnd;
+    points << d->rulerLength;
+    qSort(points.begin(), points.end());
+    QListIterator<double> i(points);
+    i.next();
+    while (i.hasNext() && i.hasPrevious()) {
+        drawDistanceLine(d, painter, i.peekPrevious(), i.peekNext());
+        i.next();
+    }
+}
+
 KoRulerPrivate::KoRulerPrivate(KoRuler *parent, const KoViewConverter *vc, Qt::Orientation o)
     : unit(KoUnit(KoUnit::Point)),
     orientation(o),
@@ -546,8 +612,10 @@
     selected(None),
     selectOffset(0),
     tabChooser(0),
-    paintingStrategy(o == Qt::Horizontal ?
+    normalPaintingStrategy(o == Qt::Horizontal ?
             (PaintingStrategy*)new HorizontalPaintingStrategy() : (PaintingStrategy*)new VerticalPaintingStrategy()),
+    distancesPaintingStrategy((PaintingStrategy*)new HorizontalDistancesPaintingStrategy()),
+    paintingStrategy(normalPaintingStrategy),
     ruler(parent)
 {
 #if QT_VERSION >= KDE_MAKE_VERSION(4,4,0)
@@ -558,7 +626,8 @@
 
 KoRulerPrivate::~KoRulerPrivate()
 {
-    delete paintingStrategy;
+    delete normalPaintingStrategy;
+    delete distancesPaintingStrategy;
 }
 
 double KoRulerPrivate::numberStepForUnit() const
@@ -701,7 +770,7 @@
     QRectF rectangle = d->paintingStrategy->drawBackground(d, painter);
     painter.restore();
     painter.save();
-    d->paintingStrategy->drawRulerStripes(d, painter, rectangle);
+    d->paintingStrategy->drawMeasurements(d, painter, rectangle);
     painter.restore();
     if (d->showIndents) {
         painter.save();
@@ -917,6 +986,11 @@
         update();
     }
 #endif
+    if (d->orientation == Qt::Horizontal && (ev->modifiers() & Qt::ShiftModifier) &&
+            (d->selected == KoRulerPrivate::FirstLineIndent ||
+             d->selected == KoRulerPrivate::ParagraphIndent ||
+             d->selected == KoRulerPrivate::EndIndent))
+        d->paintingStrategy = d->distancesPaintingStrategy;
 }
 
 void KoRuler::mouseReleaseEvent ( QMouseEvent* ev )
@@ -929,6 +1003,7 @@
     if( d->selected == KoRulerPrivate::Tab)
         emit tabsChanged(true);
 
+    d->paintingStrategy = d->normalPaintingStrategy;
     d->selected = KoRulerPrivate::None;
 }
 
@@ -946,8 +1021,13 @@
         else
             d->firstLineIndent = d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset
                 - d->offset) - d->activeRangeStart - d->paragraphIndent;
-        if( ! (ev->modifiers() & Qt::ShiftModifier))
+        if( ! (ev->modifiers() & Qt::ShiftModifier)) {
             d->firstLineIndent = d->doSnapping(d->firstLineIndent);
+            d->paintingStrategy = d->normalPaintingStrategy;
+        } else {
+            if (d->orientation == Qt::Horizontal)
+                d->paintingStrategy = d->distancesPaintingStrategy;
+        }
 
         emit indentsChanged(false);
         break;
@@ -958,8 +1038,14 @@
         else
             d->paragraphIndent = d->viewConverter->viewToDocumentX(pos.x() + d->selectOffset
                 - d->offset) - d->activeRangeStart;
-        if( ! (ev->modifiers() & Qt::ShiftModifier))
+        if( ! (ev->modifiers() & Qt::ShiftModifier)) {
             d->paragraphIndent = d->doSnapping(d->paragraphIndent);
+            d->paintingStrategy = d->normalPaintingStrategy;
+        } else {
+            if (d->orientation == Qt::Horizontal)
+                d->paintingStrategy = d->distancesPaintingStrategy;
+        }
+
         if (d->paragraphIndent < 0)
             d->paragraphIndent = 0;
         if (d->paragraphIndent + d->endIndent > activeLength)
@@ -973,8 +1059,14 @@
         else
             d->endIndent = d->activeRangeEnd - d->viewConverter->viewToDocumentX(pos.x()
                  + d->selectOffset - d->offset);
-        if( ! (ev->modifiers() & Qt::ShiftModifier))
+        if( ! (ev->modifiers() & Qt::ShiftModifier)) {
             d->endIndent = d->doSnapping(d->endIndent);
+            d->paintingStrategy = d->normalPaintingStrategy;
+        } else {
+            if (d->orientation == Qt::Horizontal)
+                d->paintingStrategy = d->distancesPaintingStrategy;
+        }
+
         if (d->endIndent < 0)
             d->endIndent = 0;
         if (d->paragraphIndent + d->endIndent > activeLength)
Index: KoRuler_p.h
===================================================================
--- KoRuler_p.h	(revision 762736)
+++ KoRuler_p.h	(arbetskopia)
@@ -42,7 +42,7 @@
 
     virtual QRectF drawBackground(const KoRulerPrivate *ruler, QPainter &painter) = 0;
     virtual void drawTabs(const KoRulerPrivate *ruler, QPainter &painter) = 0;
-    virtual void drawRulerStripes(const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle) = 0;
+    virtual void drawMeasurements(const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle) = 0;
     virtual void drawIndents(const KoRulerPrivate *ruler, QPainter &painter) = 0;
     virtual QSize sizeHint() = 0;
 
@@ -54,7 +54,7 @@
 
     virtual QRectF drawBackground(const KoRulerPrivate *ruler, QPainter &painter);
     virtual void drawTabs(const KoRulerPrivate *ruler, QPainter &painter);
-    virtual void drawRulerStripes(const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle);
+    virtual void drawMeasurements(const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle);
     virtual void drawIndents(const KoRulerPrivate *ruler, QPainter &painter);
     virtual QSize sizeHint();
 
@@ -68,7 +68,7 @@
 
     virtual QRectF drawBackground(const KoRulerPrivate *ruler, QPainter &painter);
     virtual void drawTabs(const KoRulerPrivate *, QPainter &) {}
-    virtual void drawRulerStripes(const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle);
+    virtual void drawMeasurements(const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle);
     virtual void drawIndents(const KoRulerPrivate *, QPainter &) { }
     virtual QSize sizeHint();
 
@@ -76,6 +76,16 @@
     double lengthInPixel;
 };
 
+class HorizontalDistancesPaintingStrategy : public HorizontalPaintingStrategy {
+public:
+    HorizontalDistancesPaintingStrategy() {}
+
+    virtual void drawMeasurements(const KoRulerPrivate *ruler, QPainter &painter, const QRectF &rectangle);
+
+private:
+    void drawDistanceLine(const KoRulerPrivate *d, QPainter &painter, const double start, const double end);
+};
+
 class KoRulerPrivate {
 public:
     KoRulerPrivate(KoRuler *parent, const KoViewConverter *vc, Qt::Orientation orientation);
@@ -127,7 +137,14 @@
     QList<QAction*> popupActions;
 
     RulerTabChooser *tabChooser;
-    PaintingStrategy * const paintingStrategy;
+
+    // Cached painting strategies
+    PaintingStrategy * normalPaintingStrategy;
+    PaintingStrategy * distancesPaintingStrategy;
+
+    // Current painting strategy
+    PaintingStrategy * paintingStrategy;
+
     KoRuler *ruler;
 
     double numberStepForUnit() const;
