summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/widgets/qplaintextedit.cpp36
-rw-r--r--src/gui/widgets/qplaintextedit_p.h5
2 files changed, 24 insertions, 17 deletions
diff --git a/src/gui/widgets/qplaintextedit.cpp b/src/gui/widgets/qplaintextedit.cpp
index 102e7fc4f8..efcca2e301 100644
--- a/src/gui/widgets/qplaintextedit.cpp
+++ b/src/gui/widgets/qplaintextedit.cpp
@@ -478,7 +478,7 @@ void QPlainTextEditControl::insertFromMimeData(const QMimeData *source) {
ed->insertFromMimeData(source);
}
-int QPlainTextEditPrivate::verticalOffset(int topBlock, int topLine) const
+qreal QPlainTextEditPrivate::verticalOffset(int topBlock, int topLine) const
{
qreal offset = 0;
QTextDocument *doc = control->document();
@@ -498,12 +498,12 @@ int QPlainTextEditPrivate::verticalOffset(int topBlock, int topLine) const
}
if (topBlock == 0 && topLine == 0)
offset -= doc->documentMargin(); // top margin
- return (int)offset;
+ return offset;
}
-int QPlainTextEditPrivate::verticalOffset() const {
- return verticalOffset(control->topBlock, topLine);
+qreal QPlainTextEditPrivate::verticalOffset() const {
+ return verticalOffset(control->topBlock, topLine) + topLineFracture;
}
@@ -649,8 +649,10 @@ void QPlainTextEditPrivate::setTopBlock(int blockNumber, int lineNumber, int dx)
if (viewport->updatesEnabled() && viewport->isVisible()) {
int dy = 0;
if (doc->findBlockByNumber(control->topBlock).isValid()) {
- dy = (int)(-q->blockBoundingGeometry(block).y())
- + verticalOffset() - verticalOffset(blockNumber, lineNumber);
+ qreal realdy = -q->blockBoundingGeometry(block).y()
+ + verticalOffset() - verticalOffset(blockNumber, lineNumber);
+ dy = (int)realdy;
+ topLineFracture = realdy - dy;
}
control->topBlock = blockNumber;
topLine = lineNumber;
@@ -659,14 +661,17 @@ void QPlainTextEditPrivate::setTopBlock(int blockNumber, int lineNumber, int dx)
vbar->setValue(block.firstLineNumber() + lineNumber);
vbar->blockSignals(vbarSignalsBlocked);
- if (dx || dy)
+ if (dx || dy) {
viewport->scroll(q->isRightToLeft() ? -dx : dx, dy);
- else
+ } else {
viewport->update();
+ topLineFracture = 0;
+ }
emit q->updateRequest(viewport->rect(), dy);
} else {
control->topBlock = blockNumber;
topLine = lineNumber;
+ topLineFracture = 0;
}
}
@@ -706,7 +711,7 @@ void QPlainTextEditPrivate::ensureVisible(int position, bool center, bool forceC
int l = 0;
int lineCount = block.layout()->lineCount();
- int voffset = verticalOffset(block.blockNumber(), 0);
+ qreal voffset = verticalOffset(block.blockNumber(), 0);
while (l < lineCount) {
QRectF lineRect = block.layout()->lineAt(l).naturalTextRect();
if (h - voffset - lineRect.top() <= height)
@@ -738,7 +743,7 @@ QPlainTextEditPrivate::QPlainTextEditPrivate()
tabChangesFocus(false),
lineWrap(QPlainTextEdit::WidgetWidth),
wordWrap(QTextOption::WrapAtWordBoundaryOrAnywhere),
- clickCausedFocus(0),topLine(0),
+ clickCausedFocus(0),topLine(0),topLineFracture(0),
pageUpDownLastCursorYIsValid(false)
{
showCursorOnInitialShow = true;
@@ -815,7 +820,7 @@ void QPlainTextEditPrivate::_q_repaintContents(const QRectF &contentsRect)
return;
}
const int xOffset = horizontalOffset();
- const int yOffset = verticalOffset();
+ const int yOffset = (int)verticalOffset();
const QRect visibleRect(xOffset, yOffset, viewport->width(), viewport->height());
QRect r = contentsRect.adjusted(-1, -1, 1, 1).intersected(visibleRect).toAlignedRect();
@@ -1340,7 +1345,7 @@ QTextCursor QPlainTextEdit::textCursor() const
QString QPlainTextEdit::anchorAt(const QPoint &pos) const
{
Q_D(const QPlainTextEdit);
- int cursorPos = d->control->hitTest(pos + QPoint(d->horizontalOffset(),
+ int cursorPos = d->control->hitTest(pos + QPointF(d->horizontalOffset(),
d->verticalOffset()),
Qt::ExactHit);
if (cursorPos < 0)
@@ -1443,7 +1448,7 @@ void QPlainTextEdit::clear()
{
Q_D(QPlainTextEdit);
// clears and sets empty content
- d->control->topBlock = d->topLine = 0;
+ d->control->topBlock = d->topLine = d->topLineFracture = 0;
d->control->clear();
}
@@ -1828,6 +1833,7 @@ static void fillBackground(QPainter *p, const QRectF &rect, QBrush brush, QRectF
*/
void QPlainTextEdit::paintEvent(QPaintEvent *e)
{
+ Q_D(QPlainTextEdit);
QPainter painter(viewport());
Q_ASSERT(qobject_cast<QPlainTextDocumentLayout*>(document()->documentLayout()));
@@ -2238,7 +2244,7 @@ QRect QPlainTextEdit::cursorRect(const QTextCursor &cursor) const
return QRect();
QRect r = d->control->cursorRect(cursor).toRect();
- r.translate(-d->horizontalOffset(),-d->verticalOffset());
+ r.translate(-d->horizontalOffset(),-(int)d->verticalOffset());
return r;
}
@@ -2250,7 +2256,7 @@ QRect QPlainTextEdit::cursorRect() const
{
Q_D(const QPlainTextEdit);
QRect r = d->control->cursorRect().toRect();
- r.translate(-d->horizontalOffset(),-d->verticalOffset());
+ r.translate(-d->horizontalOffset(),-(int)d->verticalOffset());
return r;
}
diff --git a/src/gui/widgets/qplaintextedit_p.h b/src/gui/widgets/qplaintextedit_p.h
index f044248137..2bf7a2fa60 100644
--- a/src/gui/widgets/qplaintextedit_p.h
+++ b/src/gui/widgets/qplaintextedit_p.h
@@ -129,8 +129,8 @@ public:
inline int horizontalOffset() const
{ return (q_func()->isRightToLeft() ? (hbar->maximum() - hbar->value()) : hbar->value()); }
- int verticalOffset(int topBlock, int topLine) const;
- int verticalOffset() const;
+ qreal verticalOffset(int topBlock, int topLine) const;
+ qreal verticalOffset() const;
inline void sendControlEvent(QEvent *e)
{ control->processEvent(e, QPointF(horizontalOffset(), verticalOffset()), viewport); }
@@ -154,6 +154,7 @@ public:
uint clickCausedFocus : 1;
int topLine;
+ qreal topLineFracture; // for non-int sized fonts
void setTopLine(int visualTopLine, int dx = 0);
void setTopBlock(int newTopBlock, int newTopLine, int dx = 0);