summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorYann Bodson <yann.bodson@nokia.com>2011-01-28 01:58:10 (GMT)
committerYann Bodson <yann.bodson@nokia.com>2011-01-28 04:12:00 (GMT)
commit7c1ab9b6a8e1b3d64c08a4f5067448884b068945 (patch)
tree2b3d3f787f42e2558e8f26475c2114e6d4b28704 /src/gui
parent64c0ee4e5f1f05105ab6168ebb4cb188e8fd838f (diff)
downloadQt-7c1ab9b6a8e1b3d64c08a4f5067448884b068945.zip
Qt-7c1ab9b6a8e1b3d64c08a4f5067448884b068945.tar.gz
Qt-7c1ab9b6a8e1b3d64c08a4f5067448884b068945.tar.bz2
Add support for line spacing in Text element.
This change adds the lineHeight and lineHeightMode properties. Task-number: QTBUG-14296 Reviewed-by: Martin Jones
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/text/qtextdocumentlayout.cpp17
-rw-r--r--src/gui/text/qtextdocumentlayout_p.h5
2 files changed, 19 insertions, 3 deletions
diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp
index d721c91..c1c3768 100644
--- a/src/gui/text/qtextdocumentlayout.cpp
+++ b/src/gui/text/qtextdocumentlayout.cpp
@@ -513,6 +513,9 @@ public:
qreal scaleToDevice(qreal value) const;
QFixed scaleToDevice(QFixed value) const;
+
+ qreal lineH;
+ QTextDocumentLayout::LineHeightMode lineHeightMode;
};
QTextDocumentLayoutPrivate::QTextDocumentLayoutPrivate()
@@ -520,7 +523,9 @@ QTextDocumentLayoutPrivate::QTextDocumentLayoutPrivate()
cursorWidth(1),
currentLazyLayoutPosition(-1),
lazyLayoutStepSize(1000),
- lastPageCount(-1)
+ lastPageCount(-1),
+ lineH(1),
+ lineHeightMode(QTextDocumentLayout::MultiplyHeight)
{
showLayoutProgress = true;
insideDocumentChange = false;
@@ -2639,7 +2644,8 @@ void QTextDocumentLayoutPrivate::layoutBlock(const QTextBlock &bl, int blockPosi
}
- QFixed lineHeight = QFixed::fromReal(line.height());
+ QFixed lineHeight = (lineHeightMode == QTextDocumentLayout::PixelHeight) ? QFixed::fromReal(lineH) : QFixed::fromReal(line.height() * lineH);
+
if (layoutStruct->pageHeight > 0 && layoutStruct->absoluteY() + lineHeight > layoutStruct->pageBottom) {
layoutStruct->newPage();
@@ -2714,6 +2720,13 @@ void QTextDocumentLayoutPrivate::layoutBlock(const QTextBlock &bl, int blockPosi
}
}
+void QTextDocumentLayout::setLineHeight(qreal lineH, QTextDocumentLayout::LineHeightMode mode = QTextDocumentLayout::MultiplyHeight)
+{
+ Q_D(QTextDocumentLayout);
+ d->lineH = lineH;
+ d->lineHeightMode = mode;
+}
+
void QTextDocumentLayoutPrivate::floatMargins(const QFixed &y, const QTextLayoutStruct *layoutStruct,
QFixed *left, QFixed *right) const
{
diff --git a/src/gui/text/qtextdocumentlayout_p.h b/src/gui/text/qtextdocumentlayout_p.h
index 3c0383c..efc408b 100644
--- a/src/gui/text/qtextdocumentlayout_p.h
+++ b/src/gui/text/qtextdocumentlayout_p.h
@@ -63,7 +63,7 @@ class QTextListFormat;
class QTextDocumentLayoutPrivate;
-class Q_AUTOTEST_EXPORT QTextDocumentLayout : public QAbstractTextDocumentLayout
+class Q_GUI_EXPORT QTextDocumentLayout : public QAbstractTextDocumentLayout
{
Q_DECLARE_PRIVATE(QTextDocumentLayout)
Q_OBJECT
@@ -109,6 +109,9 @@ protected:
void drawInlineObject(QPainter *p, const QRectF &rect, QTextInlineObject item,
int posInDocument, const QTextFormat &format);
virtual void timerEvent(QTimerEvent *e);
+ enum LineHeightMode { MultiplyHeight, PixelHeight };
+ void setLineHeight(qreal lineHeight, QTextDocumentLayout::LineHeightMode mode);
+
private:
QRectF doLayout(int from, int oldLength, int length);
void layoutFinished();