diff options
Diffstat (limited to 'src/quick/items/qquicktextedit.cpp')
-rw-r--r-- | src/quick/items/qquicktextedit.cpp | 65 |
1 files changed, 22 insertions, 43 deletions
diff --git a/src/quick/items/qquicktextedit.cpp b/src/quick/items/qquicktextedit.cpp index 6eed95767b..a9bff73bd9 100644 --- a/src/quick/items/qquicktextedit.cpp +++ b/src/quick/items/qquicktextedit.cpp @@ -399,9 +399,6 @@ void QQuickTextEdit::setColor(const QColor &color) return; d->color = color; - QPalette pal = d->control->palette(); - pal.setColor(QPalette::Text, color); - d->control->setPalette(pal); updateDocument(); emit colorChanged(d->color); } @@ -424,9 +421,6 @@ void QQuickTextEdit::setSelectionColor(const QColor &color) return; d->selectionColor = color; - QPalette pal = d->control->palette(); - pal.setColor(QPalette::Highlight, color); - d->control->setPalette(pal); updateDocument(); emit selectionColorChanged(d->selectionColor); } @@ -449,9 +443,6 @@ void QQuickTextEdit::setSelectedTextColor(const QColor &color) return; d->selectedTextColor = color; - QPalette pal = d->control->palette(); - pal.setColor(QPalette::HighlightedText, color); - d->control->setPalette(pal); updateDocument(); emit selectedTextColorChanged(d->selectedTextColor); } @@ -741,10 +732,10 @@ QRectF QQuickTextEdit::positionToRectangle(int pos) const Position 0 is before the first character, position 1 is after the first character but before the second, and so on until position \l {text}.length, which is after all characters. */ -int QQuickTextEdit::positionAt(int x, int y) const +int QQuickTextEdit::positionAt(qreal x, qreal y) const { Q_D(const QQuickTextEdit); - int r = d->document->documentLayout()->hitTest(QPoint(x,y-d->yoff), Qt::FuzzyHit); + int r = d->document->documentLayout()->hitTest(QPointF(x,y-d->yoff), Qt::FuzzyHit); QTextCursor cursor = d->control->textCursor(); if (r > cursor.position()) { // The cursor position includes positions within the preedit text, but only positions in the @@ -1299,10 +1290,10 @@ Qt::TextInteractionFlags QQuickTextEdit::textInteractionFlags() const automatically when it changes. The width of the delegate is unaffected by changes in the cursor rectangle. */ -QRect QQuickTextEdit::cursorRectangle() const +QRectF QQuickTextEdit::cursorRectangle() const { Q_D(const QQuickTextEdit); - return d->control->cursorRect().toRect().translated(0,d->yoff); + return d->control->cursorRect().translated(0, d->yoff); } bool QQuickTextEdit::event(QEvent *event) @@ -1634,10 +1625,8 @@ QSGNode *QQuickTextEdit::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData * QRectF bounds = boundingRect(); - QColor selectionColor = d->control->palette().color(QPalette::Highlight); - QColor selectedTextColor = d->control->palette().color(QPalette::HighlightedText); node->addTextDocument(bounds.topLeft(), d->document, d->color, QQuickText::Normal, QColor(), - selectionColor, selectedTextColor, selectionStart(), + d->selectionColor, d->selectedTextColor, selectionStart(), selectionEnd() - 1); // selectionEnd() returns first char after // selection @@ -1756,31 +1745,21 @@ void QQuickTextEditPrivate::init() document = new QQuickTextDocumentWithImageResources(q); control = new QQuickTextControl(document, q); - control->setView(q); control->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::TextSelectableByKeyboard | Qt::TextEditable); control->setAcceptRichText(false); control->setCursorIsFocusIndicator(true); - // QQuickTextControl follows the default text color - // defined by the platform, declarative text - // should be black by default - QPalette pal = control->palette(); - if (pal.color(QPalette::Text) != color) { - pal.setColor(QPalette::Text, color); - control->setPalette(pal); - } - - QObject::connect(control, SIGNAL(updateRequest(QRectF)), q, SLOT(updateDocument())); - QObject::connect(control, SIGNAL(updateCursorRequest()), q, SLOT(updateCursor())); - QObject::connect(control, SIGNAL(textChanged()), q, SLOT(q_textChanged())); - QObject::connect(control, SIGNAL(selectionChanged()), q, SIGNAL(selectionChanged())); - QObject::connect(control, SIGNAL(selectionChanged()), q, SLOT(updateSelectionMarkers())); - QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SLOT(updateSelectionMarkers())); - QObject::connect(control, SIGNAL(cursorPositionChanged()), q, SIGNAL(cursorPositionChanged())); - QObject::connect(control, SIGNAL(cursorRectangleChanged()), q, SLOT(moveCursorDelegate())); - QObject::connect(control, SIGNAL(linkActivated(QString)), q, SIGNAL(linkActivated(QString))); + FAST_CONNECT(control, SIGNAL(updateRequest(QRectF)), q, SLOT(updateDocument())); + FAST_CONNECT(control, SIGNAL(updateCursorRequest()), q, SLOT(updateCursor())); + FAST_CONNECT(control, SIGNAL(textChanged()), q, SLOT(q_textChanged())); + FAST_CONNECT(control, SIGNAL(selectionChanged()), q, SIGNAL(selectionChanged())); + FAST_CONNECT(control, SIGNAL(selectionChanged()), q, SLOT(updateSelectionMarkers())); + FAST_CONNECT(control, SIGNAL(cursorPositionChanged()), q, SLOT(updateSelectionMarkers())); + FAST_CONNECT(control, SIGNAL(cursorPositionChanged()), q, SIGNAL(cursorPositionChanged())); + FAST_CONNECT(control, SIGNAL(cursorRectangleChanged()), q, SLOT(moveCursorDelegate())); + FAST_CONNECT(control, SIGNAL(linkActivated(QString)), q, SIGNAL(linkActivated(QString))); #ifndef QT_NO_CLIPBOARD - QObject::connect(QGuiApplication::clipboard(), SIGNAL(dataChanged()), q, SLOT(q_canPasteChanged())); + FAST_CONNECT(QGuiApplication::clipboard(), SIGNAL(dataChanged()), q, SLOT(q_canPasteChanged())); #endif FAST_CONNECT(document, SIGNAL(undoAvailable(bool)), q, SIGNAL(canUndoChanged())); FAST_CONNECT(document, SIGNAL(redoAvailable(bool)), q, SIGNAL(canRedoChanged())); @@ -1884,11 +1863,11 @@ void QQuickTextEdit::updateSize() } else { d->document->setTextWidth(-1); } - QFontMetrics fm = QFontMetrics(d->font); - int dy = height(); - dy -= (int)d->document->size().height(); + QFontMetricsF fm(d->font); + qreal dy = height(); + dy -= d->document->size().height(); - int nyoff; + qreal nyoff; if (heightValid()) { if (d->vAlign == AlignBottom) nyoff = dy; @@ -1904,7 +1883,7 @@ void QQuickTextEdit::updateSize() setBaselineOffset(fm.ascent() + d->yoff + d->textMargin); //### need to comfirm cost of always setting these - int newWidth = qCeil(d->document->idealWidth()); + qreal newWidth = d->document->idealWidth(); if (!widthValid() && d->document->textWidth() != newWidth) d->document->setTextWidth(newWidth); // ### Text does not align if width is not set (QTextDoc bug) // ### Setting the implicitWidth triggers another updateSize(), and unless there are bindings nothing has changed. @@ -1913,13 +1892,13 @@ void QQuickTextEdit::updateSize() iWidth = newWidth; else if (d->requireImplicitWidth) iWidth = naturalWidth; - qreal newHeight = d->document->isEmpty() ? fm.height() : (int)d->document->size().height(); + qreal newHeight = d->document->isEmpty() ? fm.height() : d->document->size().height(); if (iWidth > -1) setImplicitSize(iWidth, newHeight); else setImplicitHeight(newHeight); - QSize size(newWidth, newHeight); + QSizeF size(newWidth, newHeight); if (d->contentSize != size) { d->contentSize = size; emit contentSizeChanged(); |