With xcb querying data from the clipboard can take as long as 50 ms.
Deferring the check until it is requested speeds up construction time
when it's not used and only checking the available formats when it is
requested should also help.
Change-Id: I796fc83d0457d9ac1490cfb9f510c6342eb8a872
Reviewed-by: Martin Jones <martin.jones@nokia.com>
{
Q_D(const QQuickTextControl);
if (d->acceptRichText)
- return (source->hasText() && !source->text().isEmpty())
+ return source->hasText()
|| source->hasHtml()
|| source->hasFormat(QLatin1String("application/x-qrichtext"))
|| source->hasFormat(QLatin1String("application/x-qt-richtext"));
else
- return source->hasText() && !source->text().isEmpty();
+ return source->hasText();
}
void QQuickTextControl::insertFromMimeData(const QMimeData *source)
bool QQuickTextEdit::canPaste() const
{
Q_D(const QQuickTextEdit);
+ if (!d->canPasteValid) {
+ const_cast<QQuickTextEditPrivate *>(d)->canPaste = d->control->canPaste();
+ const_cast<QQuickTextEditPrivate *>(d)->canPasteValid = true;
+ }
return d->canPaste;
}
#ifndef QT_NO_CLIPBOARD
QObject::connect(q, SIGNAL(readOnlyChanged(bool)), q, SLOT(q_canPasteChanged()));
QObject::connect(QGuiApplication::clipboard(), SIGNAL(dataChanged()), q, SLOT(q_canPasteChanged()));
- canPaste = control->canPaste();
#endif
document->setDefaultFont(font);
Q_D(QQuickTextEdit);
bool old = d->canPaste;
d->canPaste = d->control->canPaste();
- if (old!=d->canPaste)
+ bool changed = old!=d->canPaste || !d->canPasteValid;
+ d->canPasteValid = true;
+ if (changed)
emit canPasteChanged();
}
: color("black"), hAlign(QQuickTextEdit::AlignLeft), vAlign(QQuickTextEdit::AlignTop),
documentDirty(true), dirty(false), richText(false), cursorVisible(false), focusOnPress(true),
persistentSelection(true), requireImplicitWidth(false), selectByMouse(false), canPaste(false),
- hAlignImplicit(true), rightToLeftText(false), useImageFallback(false),
+ canPasteValid(false), hAlignImplicit(true), rightToLeftText(false), useImageFallback(false),
textMargin(0.0), lastSelectionStart(0), lastSelectionEnd(0), cursorComponent(0), cursor(0),
format(QQuickTextEdit::PlainText), document(0), wrapMode(QQuickTextEdit::NoWrap),
mouseSelectionMode(QQuickTextEdit::SelectCharacters),
bool requireImplicitWidth:1;
bool selectByMouse:1;
bool canPaste:1;
+ bool canPasteValid:1;
bool hAlignImplicit:1;
bool rightToLeftText:1;
bool useImageFallback:1;
bool QQuickTextInput::canPaste() const
{
Q_D(const QQuickTextInput);
+ if (!d->canPasteValid) {
+ if (const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData())
+ const_cast<QQuickTextInputPrivate *>(d)->canPaste = !d->m_readOnly && mimeData->hasText();
+ const_cast<QQuickTextInputPrivate *>(d)->canPasteValid = true;
+ }
return d->canPaste;
}
q, SLOT(q_canPasteChanged()));
q->connect(QGuiApplication::clipboard(), SIGNAL(dataChanged()),
q, SLOT(q_canPasteChanged()));
- canPaste = !m_readOnly && QGuiApplication::clipboard()->text().length() != 0;
#endif // QT_NO_CLIPBOARD
m_textLayout.beginLayout();
m_textLayout.createLine();
Q_D(QQuickTextInput);
bool old = d->canPaste;
#ifndef QT_NO_CLIPBOARD
- d->canPaste = !d->m_readOnly && QGuiApplication::clipboard()->text().length() != 0;
+ if (const QMimeData *mimeData = QGuiApplication::clipboard()->mimeData())
+ d->canPaste = !d->m_readOnly && mimeData->hasText();
+ else
+ d->canPaste = false;
#endif
- if (d->canPaste != old)
+
+ bool changed = d->canPaste != old || !d->canPasteValid;
+ d->canPasteValid = true;
+ if (changed)
emit canPasteChanged();
+
}
// ### these should come from QStyleHints
, autoScroll(true)
, selectByMouse(false)
, canPaste(false)
+ , canPasteValid(false)
, hAlignImplicit(true)
, selectPressed(false)
, textLayoutDirty(true)
bool autoScroll:1;
bool selectByMouse:1;
bool canPaste:1;
+ bool canPasteValid:1;
bool hAlignImplicit:1;
bool selectPressed:1;
bool textLayoutDirty:1;