From 518c2a58ed6fdfd7449cb4476aa8ea0d32ad16e3 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 18 Apr 2011 14:54:24 +0200 Subject: Fix missing color in text when using static text back-end in QML Using QStaticTextItem as a back-end for QML text on GL caused a regression where parts of a text element would get the wrong color. This was because the color set on the painter which was passed into draw() was never transferred to the painter used to record the draw text calls issued by the underlying QTextLayout::draw()-function. Task-number: QTBUG-18428 Reviewed-by: Jiang Jiang --- src/declarative/graphicsitems/qdeclarativetextlayout.cpp | 5 +++-- src/declarative/graphicsitems/qdeclarativetextlayout_p.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextlayout.cpp b/src/declarative/graphicsitems/qdeclarativetextlayout.cpp index 31819f5..c5f40b3 100644 --- a/src/declarative/graphicsitems/qdeclarativetextlayout.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextlayout.cpp @@ -299,7 +299,7 @@ void QDeclarativeTextLayout::clearLayout() QTextLayout::clearLayout(); } -void QDeclarativeTextLayout::prepare() +void QDeclarativeTextLayout::prepare(QPainter *painter) { if (!d || !d->cached) { @@ -308,6 +308,7 @@ void QDeclarativeTextLayout::prepare() InertTextPainter *itp = inertTextPainter(); itp->device.begin(d); + itp->painter.setPen(painter->pen()); QTextLayout::draw(&itp->painter, QPointF(0, 0)); glyph_t *glyphPool = d->glyphs.data(); @@ -340,7 +341,7 @@ void QDeclarativeTextLayout::draw(QPainter *painter, const QPointF &p) return; } - prepare(); + prepare(painter); int itemCount = d->items.count(); diff --git a/src/declarative/graphicsitems/qdeclarativetextlayout_p.h b/src/declarative/graphicsitems/qdeclarativetextlayout_p.h index 2c9264e..23b22a6 100644 --- a/src/declarative/graphicsitems/qdeclarativetextlayout_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextlayout_p.h @@ -61,7 +61,7 @@ public: void beginLayout(); void clearLayout(); - void prepare(); + void prepare(QPainter *); void draw(QPainter *, const QPointF & = QPointF()); private: -- cgit v0.12 From 1d28996fd635eed07eff61502ab67f7158ba43cd Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Mon, 18 Apr 2011 15:20:11 +0200 Subject: Support text decoration in QML when using static text back-end When the QStaticTextItem code path in QML was copy-pasted, QStaticText did not support text decoration yet. It has since been implemented. We copy-paste the fix as well (which means we have to export a private function from QtGui to avoid duplicating that code as well.) Task-number: QTBUG-18428 Reviewed-by: Jiang Jiang --- .../graphicsitems/qdeclarativetextlayout.cpp | 10 ++++++++++ src/gui/painting/qpainter.cpp | 22 +++++++++++----------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextlayout.cpp b/src/declarative/graphicsitems/qdeclarativetextlayout.cpp index c5f40b3..75d9f67 100644 --- a/src/declarative/graphicsitems/qdeclarativetextlayout.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextlayout.cpp @@ -327,6 +327,12 @@ void QDeclarativeTextLayout::prepare(QPainter *painter) } } +// Defined in qpainter.cpp +extern Q_GUI_EXPORT void qt_draw_decoration_for_glyphs(QPainter *painter, const glyph_t *glyphArray, + const QFixedPoint *positions, int glyphCount, + QFontEngine *fontEngine, const QFont &font, + const QTextCharFormat &charFormat); + void QDeclarativeTextLayout::draw(QPainter *painter, const QPointF &p) { QPainterPrivate *priv = QPainterPrivate::get(painter); @@ -372,6 +378,10 @@ void QDeclarativeTextLayout::draw(QPainter *painter, const QPointF &p) currentColor = item.color; } priv->extended->drawStaticTextItem(&item); + + qt_draw_decoration_for_glyphs(painter, item.glyphs, item.glyphPositions, + item.numGlyphs, item.fontEngine(), painter->font(), + QTextCharFormat()); } if (currentColor != oldPen.color()) painter->setPen(oldPen); diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 76ac7db..0e279c9 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -95,10 +95,10 @@ static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const const QTextItem::RenderFlags flags, qreal width, const QTextCharFormat &charFormat); // Helper function to calculate left most position, width and flags for decoration drawing -static void drawDecorationForGlyphs(QPainter *painter, const glyph_t *glyphArray, - const QFixedPoint *positions, int glyphCount, - QFontEngine *fontEngine, const QFont &font, - const QTextCharFormat &charFormat); +Q_GUI_EXPORT void qt_draw_decoration_for_glyphs(QPainter *painter, const glyph_t *glyphArray, + const QFixedPoint *positions, int glyphCount, + QFontEngine *fontEngine, const QFont &font, + const QTextCharFormat &charFormat); static inline QGradient::CoordinateMode coordinateMode(const QBrush &brush) { @@ -5937,9 +5937,9 @@ void QPainter::drawStaticText(const QPointF &topLeftPosition, const QStaticText } d->extended->drawStaticTextItem(item); - drawDecorationForGlyphs(this, item->glyphs, item->glyphPositions, - item->numGlyphs, item->fontEngine(), staticText_d->font, - QTextCharFormat()); + qt_draw_decoration_for_glyphs(this, item->glyphs, item->glyphPositions, + item->numGlyphs, item->fontEngine(), staticText_d->font, + QTextCharFormat()); } if (currentColor != oldPen.color()) setPen(oldPen); @@ -6383,10 +6383,10 @@ static void drawTextItemDecoration(QPainter *painter, const QPointF &pos, const painter->setBrush(oldBrush); } -static void drawDecorationForGlyphs(QPainter *painter, const glyph_t *glyphArray, - const QFixedPoint *positions, int glyphCount, - QFontEngine *fontEngine, const QFont &font, - const QTextCharFormat &charFormat) +Q_GUI_EXPORT void qt_draw_decoration_for_glyphs(QPainter *painter, const glyph_t *glyphArray, + const QFixedPoint *positions, int glyphCount, + QFontEngine *fontEngine, const QFont &font, + const QTextCharFormat &charFormat) { if (!(font.underline() || font.strikeOut() || font.overline())) return; -- cgit v0.12 From 8c68e8ffa32ca26d0fd87f1349d6783e4242a9d1 Mon Sep 17 00:00:00 2001 From: Jiang Jiang Date: Thu, 24 Mar 2011 13:33:31 +0100 Subject: Let QTextLine decide its own x position in QPainter So that it can take trailing space width into account when doing right aligned text drawing. Backported from master. Task-number: QTBUG-18303 Reviewed-by: Eskil --- src/gui/painting/qpainter.cpp | 12 ++++++++---- src/gui/text/qtextengine.cpp | 16 ++++++++++++++++ src/gui/text/qtextengine_p.h | 1 + src/gui/text/qtextlayout.cpp | 19 +------------------ 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 0e279c9..3735e7c 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -8097,12 +8097,16 @@ start_lengthVariant: QTextLine line = textLayout.lineAt(i); qreal advance = line.horizontalAdvance(); - if (tf & Qt::AlignRight) - xoff = r.width() - advance; + xoff = 0; + if (tf & Qt::AlignRight) { + QTextEngine *eng = textLayout.engine(); + xoff = r.width() - advance - + eng->leadingSpaceWidth(eng->lines[line.lineNumber()]).toReal(); + } else if (tf & Qt::AlignHCenter) - xoff = (r.width() - advance)/2; + xoff = (r.width() - advance) / 2; - line.draw(painter, QPointF(r.x() + xoff + line.x(), r.y() + yoff)); + line.draw(painter, QPointF(r.x() + xoff, r.y() + yoff)); } if (restore) { diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp index 4378c62..4f86cff 100644 --- a/src/gui/text/qtextengine.cpp +++ b/src/gui/text/qtextengine.cpp @@ -2681,6 +2681,22 @@ void QTextEngine::resolveAdditionalFormats() const specialData->resolvedFormatIndices = indices; } +QFixed QTextEngine::leadingSpaceWidth(const QScriptLine &line) +{ + if (!line.hasTrailingSpaces + || (option.flags() & QTextOption::IncludeTrailingSpaces) + || !isRightToLeft()) + return QFixed(); + + int pos = line.length; + const HB_CharAttributes *attributes = this->attributes(); + if (!attributes) + return QFixed(); + while (pos > 0 && attributes[line.from + pos - 1].whiteSpace) + --pos; + return width(line.from + pos, line.length - pos); +} + QStackTextEngine::QStackTextEngine(const QString &string, const QFont &f) : QTextEngine(string, f), _layoutData(string, _memory, MemSize) diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h index 34723ab..67d7453 100644 --- a/src/gui/text/qtextengine_p.h +++ b/src/gui/text/qtextengine_p.h @@ -592,6 +592,7 @@ public: QString elidedText(Qt::TextElideMode mode, const QFixed &width, int flags = 0) const; void shapeLine(const QScriptLine &line); + QFixed leadingSpaceWidth(const QScriptLine &line); private: void setBoundary(int strPos) const; diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 905f81b..692620f 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -64,23 +64,6 @@ QT_BEGIN_NAMESPACE #define SuppressText 0x5012 #define SuppressBackground 0x513 -static inline QFixed leadingSpaceWidth(QTextEngine *eng, const QScriptLine &line) -{ - if (!line.hasTrailingSpaces - || (eng->option.flags() & QTextOption::IncludeTrailingSpaces) - || !(eng->option.alignment() & Qt::AlignRight) - || !eng->isRightToLeft()) - return QFixed(); - - int pos = line.length; - const HB_CharAttributes *attributes = eng->attributes(); - if (!attributes) - return QFixed(); - while (pos > 0 && attributes[line.from + pos - 1].whiteSpace) - --pos; - return eng->width(line.from + pos, line.length - pos); -} - static QFixed alignLine(QTextEngine *eng, const QScriptLine &line) { QFixed x = 0; @@ -91,7 +74,7 @@ static QFixed alignLine(QTextEngine *eng, const QScriptLine &line) if (align & Qt::AlignJustify && eng->isRightToLeft()) align = Qt::AlignRight; if (align & Qt::AlignRight) - x = line.width - (line.textAdvance + leadingSpaceWidth(eng, line)); + x = line.width - (line.textAdvance + eng->leadingSpaceWidth(line)); else if (align & Qt::AlignHCenter) x = (line.width - line.textAdvance)/2; } -- cgit v0.12 From af65fd979c5ab7bd1c20d8a015a53762e991c1a4 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Wed, 20 Apr 2011 12:34:40 +0200 Subject: Handle uppercase 'E' when parsing numbers in SVGs. Task-number: QT-4881 Reviewed-by: Samuel --- src/svg/qsvghandler.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/svg/qsvghandler.cpp b/src/svg/qsvghandler.cpp index 9698860..3fbc08c 100644 --- a/src/svg/qsvghandler.cpp +++ b/src/svg/qsvghandler.cpp @@ -584,7 +584,7 @@ static qreal toDouble(const QChar *&str) ++str; } bool exponent = false; - if (*str == QLatin1Char('e') && pos < maxLen) { + if ((*str == QLatin1Char('e') || *str == QLatin1Char('E')) && pos < maxLen) { exponent = true; temp[pos++] = 'e'; ++str; -- cgit v0.12 From 4e6ae1cae429e7598bed8c24981cb89ad96ef26c Mon Sep 17 00:00:00 2001 From: Jani Hautakangas Date: Fri, 15 Apr 2011 10:55:48 +0300 Subject: Update Symbian platform notes documentation Task-number: QTBUG-17357 Reviewed-by: Jason Barron --- doc/src/platforms/platform-notes.qdoc | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/doc/src/platforms/platform-notes.qdoc b/doc/src/platforms/platform-notes.qdoc index de6eb7f..f4eb8bd 100644 --- a/doc/src/platforms/platform-notes.qdoc +++ b/doc/src/platforms/platform-notes.qdoc @@ -645,28 +645,8 @@ \section1 Supported Devices - Qt is designed to work on any device which runs one of the following - versions of Symbian: - - \table - \header \o Symbian Version - \row \o S60 3.1 - \row \o S60 3.2 - \row \o S60 5.0 (Symbian ^1) - \endtable - - Qt has received \l{Tier 1 Platforms}{Tier 1} testing on the following phone models: - - \table - \header \o Phone - \row \o Nokia 5800 - \row \o Nokia E71 - \row \o Nokia E72 - \row \o Nokia N78 - \row \o Nokia N95 - \row \o Nokia N97 - \row \o Samsung i8910 - \endtable + See the list of supported devices at + http://wiki.forum.nokia.com/index.php/Nokia_Smart_Installer_for_Symbian#Supported_Devices \section1 Supported Functionality @@ -679,8 +659,6 @@ \o Planned for future release. \row \o QtDBus \o No current plans to support this feature. - \row \o QtOpenGL ES - \o Planned for future release. \row \o Printing support \o No current plans to support this feature. \row \o Qt3Support @@ -774,6 +752,12 @@ plugin. If the Helix plugin fails to load, the MMF plugin, if present on the device, will be loaded instead. + \section1 QtOpenGL Support + + Qt 4.7 introduces the QtOpenGL module to Symbian^3. QtOpenGL is supported on + devices which support OpenGL ES 2.0. Symbian platforms prior to Symbian^3 + are not supported. + \section1 UI Performance in devices prior to Symbian^3 Qt uses the QPainter class to perform low-level painting on widgets and -- cgit v0.12 From 7616da319f0c64bf18900fe17ee3c6dd60496174 Mon Sep 17 00:00:00 2001 From: Jani Hautakangas Date: Thu, 21 Apr 2011 14:07:09 +0300 Subject: Fix for GL graphcics system orientation which MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OpenGL context needs to be recreated on Symbian when orientation changes. Previously only the EGL surface was recreated which wasn't enough. Task-number: QTBUG-18850 Reviewed-by: Samuel Rødal --- src/opengl/qwindowsurface_gl.cpp | 48 ++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp index ed541ce..b056caa 100644 --- a/src/opengl/qwindowsurface_gl.cpp +++ b/src/opengl/qwindowsurface_gl.cpp @@ -706,7 +706,6 @@ void QGLWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint & } else { glFlush(); } - return; } @@ -856,8 +855,22 @@ void QGLWindowSurface::updateGeometry() { bool hijack(true); QWidgetPrivate *wd = window()->d_func(); - if (wd->extraData() && wd->extraData()->glContext) - hijack = false; // we already have gl context for widget + if (wd->extraData() && wd->extraData()->glContext) { +#ifdef Q_OS_SYMBIAN // Symbian needs to recreate the context when native window size changes + if (d_ptr->size != geometry().size()) { + if (window() != qt_gl_share_widget()) + --(_qt_gl_share_widget()->widgetRefCount); + + delete wd->extraData()->glContext; + wd->extraData()->glContext = 0; + d_ptr->ctx = 0; + } + else +#endif + { + hijack = false; // we already have gl context for widget + } + } if (hijack) hijackWindow(window()); @@ -878,35 +891,6 @@ void QGLWindowSurface::updateGeometry() { d_ptr->size = surfSize; -#ifdef Q_OS_SYMBIAN - if (!hijack) { // Symbian needs to recreate EGL surface when native window size changes - if (ctx->d_func()->eglSurface != EGL_NO_SURFACE) { - eglDestroySurface(ctx->d_func()->eglContext->display(), - ctx->d_func()->eglSurface); - } - - ctx->d_func()->eglSurface = QEgl::createSurface(ctx->device(), - ctx->d_func()->eglContext->config()); - - eglGetError(); // Clear error state. - if (hasPartialUpdateSupport()) { - eglSurfaceAttrib(ctx->d_func()->eglContext->display(), - ctx->d_func()->eglSurface, - EGL_SWAP_BEHAVIOR, EGL_BUFFER_PRESERVED); - - if (eglGetError() != EGL_SUCCESS) - qWarning("QGLWindowSurface: could not enable preserved swap behaviour"); - } else { - eglSurfaceAttrib(ctx->d_func()->eglContext->display(), - ctx->d_func()->eglSurface, - EGL_SWAP_BEHAVIOR, EGL_BUFFER_DESTROYED); - - if (eglGetError() != EGL_SUCCESS) - qWarning("QGLWindowSurface: could not enable destroyed swap behaviour"); - } - } -#endif - if (d_ptr->ctx) { #ifndef QT_OPENGL_ES_2 if (d_ptr->destructive_swap_buffers) -- cgit v0.12 From 507a819971cd0cb3d6acba96177ab3553dae9867 Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Tue, 26 Apr 2011 14:58:34 +0300 Subject: Input method hints are not correct if using proxy widget Input context should prefer focus proxy over regular focus widget. Task-number: QTBUG-18873 Reviewed-by: Miikka Heikkinen --- src/gui/inputmethod/qcoefepinputcontext_s60.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp index 92f8384..06dc25c 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp +++ b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp @@ -255,9 +255,13 @@ bool QCoeFepInputContext::filterEvent(const QEvent *event) // fall through intended case QEvent::KeyRelease: const QKeyEvent *keyEvent = static_cast(event); + //If proxy exists, always use hints from proxy. + QWidget *proxy = focusWidget()->focusProxy(); + Qt::InputMethodHints currentHints = proxy ? proxy->inputMethodHints() : focusWidget()->inputMethodHints(); + switch (keyEvent->key()) { case Qt::Key_F20: - Q_ASSERT(m_lastImHints == focusWidget()->inputMethodHints()); + Q_ASSERT(m_lastImHints == currentHints); if (m_lastImHints & Qt::ImhHiddenText) { // Special case in Symbian. On editors with secret text, F20 is for some reason // considered to be a backspace. @@ -287,7 +291,7 @@ bool QCoeFepInputContext::filterEvent(const QEvent *event) } if (keyEvent->type() == QEvent::KeyPress - && focusWidget()->inputMethodHints() & Qt::ImhHiddenText + && currentHints & Qt::ImhHiddenText && !keyEvent->text().isEmpty()) { // Send some temporary preedit text in order to make text visible for a moment. m_preeditString = keyEvent->text(); @@ -588,9 +592,10 @@ void QCoeFepInputContext::updateHints(bool mustUpdateInputCapabilities) { QWidget *w = focusWidget(); if (w) { - Qt::InputMethodHints hints = w->inputMethodHints(); + QWidget *proxy = w->focusProxy(); + Qt::InputMethodHints hints = proxy ? proxy->inputMethodHints() : w->inputMethodHints(); - // Since splitview support works like an input method hint, yet it is private flag, + // Since splitview support works like an input method hint, yet it is private flag, // we need to update its state separately. if (QSysInfo::s60Version() > QSysInfo::SV_S60_5_0) { TInt currentFlags = m_fepState->Flags(); -- cgit v0.12 From e945c5009881eac49fd9b54966643a7e9d24c433 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 26 Apr 2011 15:06:32 +0200 Subject: Add new exported symbol to QtGuiu.def Fix build on Symbian Reviewed-by: Jason Barron --- src/s60installs/eabi/QtGuiu.def | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/s60installs/eabi/QtGuiu.def b/src/s60installs/eabi/QtGuiu.def index b6a24ab..799ac43 100644 --- a/src/s60installs/eabi/QtGuiu.def +++ b/src/s60installs/eabi/QtGuiu.def @@ -12182,4 +12182,6 @@ EXPORTS _ZNK14QVolatileImage9constBitsEv @ 12181 NONAME _ZN15QGraphicsSystem22releaseCachedResourcesEv @ 12182 NONAME _Z32qt_s60_setPartialScreenInputModeb @ 12183 NONAME + _Z29qt_draw_decoration_for_glyphsP8QPainterPKjPK11QFixedPointiP11QFontEngineRK5QFontRK15QTextCharFormat @ 12184 NONAME + _ZNK10QTextBlock7isValidEv @ 12185 NONAME -- cgit v0.12 From 10830210607d08eeb2af5d091639506a7d8cc634 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Wed, 27 Apr 2011 11:16:04 +1000 Subject: Move the TextInput cursor delegate when the preedit position changes. Change-Id: Ia7150122444e465ffbcc02e921d42d01c2dfdac1 Task-number: QTBUG-18892 Reviewed-by: Martin Jones --- src/declarative/graphicsitems/qdeclarativetextinput.cpp | 6 +++++- .../qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 9 +++++++++ .../qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 9 +++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index ee241d6..6eb6b68 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -949,6 +949,8 @@ void QDeclarativeTextInput::setCursorDelegate(QDeclarativeComponent* c) //note that the components are owned by something else disconnect(d->control, SIGNAL(cursorPositionChanged(int,int)), this, SLOT(moveCursor())); + disconnect(d->control, SIGNAL(updateMicroFocus()), + this, SLOT(moveCursor())); delete d->cursorItem; }else{ d->startCreatingCursor(); @@ -961,7 +963,9 @@ void QDeclarativeTextInputPrivate::startCreatingCursor() { Q_Q(QDeclarativeTextInput); q->connect(control, SIGNAL(cursorPositionChanged(int,int)), - q, SLOT(moveCursor())); + q, SLOT(moveCursor()), Qt::UniqueConnection); + q->connect(control, SIGNAL(updateMicroFocus()), + q, SLOT(moveCursor()), Qt::UniqueConnection); if(cursorComponent->isReady()){ q->createCursor(); }else if(cursorComponent->isLoading()){ diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 26a6fd8..53f8a24 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -1546,6 +1546,15 @@ void tst_qdeclarativetextedit::cursorDelegate() QCOMPARE(textEditObject->cursorRectangle().x(), qRound(delegateObject->x())); QCOMPARE(textEditObject->cursorRectangle().y(), qRound(delegateObject->y())); } + const QString preedit = "preedit"; + for (int i = 0; i <= preedit.length(); i++) { + QInputMethodEvent event(preedit, QList() + << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, i, 1, QVariant())); + QApplication::sendEvent(view, &event); + + QCOMPARE(textEditObject->cursorRectangle().x(), qRound(delegateObject->x())); + QCOMPARE(textEditObject->cursorRectangle().y(), qRound(delegateObject->y())); + } textEditObject->setCursorPosition(0); QCOMPARE(textEditObject->cursorRectangle().x(), qRound(delegateObject->x())); QCOMPARE(textEditObject->cursorRectangle().y(), qRound(delegateObject->y())); diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index baaf862..d4b844c 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -1643,6 +1643,15 @@ void tst_qdeclarativetextinput::cursorDelegate() QCOMPARE(textInputObject->cursorRectangle().x(), qRound(delegateObject->x())); QCOMPARE(textInputObject->cursorRectangle().y(), qRound(delegateObject->y())); } + const QString preedit = "preedit"; + for (int i = 0; i <= preedit.length(); i++) { + QInputMethodEvent event(preedit, QList() + << QInputMethodEvent::Attribute(QInputMethodEvent::Cursor, i, 1, QVariant())); + QApplication::sendEvent(view, &event); + + QCOMPARE(textInputObject->cursorRectangle().x(), qRound(delegateObject->x())); + QCOMPARE(textInputObject->cursorRectangle().y(), qRound(delegateObject->y())); + } textInputObject->setCursorPosition(0); QCOMPARE(textInputObject->cursorRectangle().x(), qRound(delegateObject->x())); QCOMPARE(textInputObject->cursorRectangle().y(), qRound(delegateObject->y())); -- cgit v0.12 From 8878e2c53a0c9408d4b468e2dad485743c32f58b Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Wed, 27 Apr 2011 13:10:34 +1000 Subject: PathView offset out of sync with currentIndex when items are removed. If the view is animating due to currentIndex change and items are removed the target offset must be recalculated. Change-Id: Iee105712488070c086a24561a49daf17bcf14076 Task-number: QTBUG-18825 Reviewed-by: Michael Brasser --- src/declarative/graphicsitems/qdeclarativepathview.cpp | 2 ++ .../qdeclarativepathview/tst_qdeclarativepathview.cpp | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp index 778b8b9..aed849b 100644 --- a/src/declarative/graphicsitems/qdeclarativepathview.cpp +++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp @@ -1525,6 +1525,8 @@ void QDeclarativePathView::itemsRemoved(int modelIndex, int count) } else { d->regenerate(); d->updateCurrent(); + if (!d->flicking && !d->moving && d->haveHighlightRange && d->highlightRangeMode == QDeclarativePathView::StrictlyEnforceRange) + d->snapToCurrent(); } if (changedOffset) emit offsetChanged(); diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp index 8000137..46c3519 100644 --- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp +++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp @@ -458,6 +458,16 @@ void tst_QDeclarativePathView::dataModel() model.removeItem(model.count()-1); QCOMPARE(pathview->currentIndex(), model.count()-1); + // QTBUG-18825 + // Confirm that the target offset is adjusted when removing items + pathview->setCurrentIndex(model.count()-1); + QTRY_COMPARE(pathview->offset(), 1.); + pathview->setCurrentIndex(model.count()-5); + model.removeItem(model.count()-1); + model.removeItem(model.count()-1); + model.removeItem(model.count()-1); + QTRY_COMPARE(pathview->offset(), 2.); + delete canvas; } -- cgit v0.12 From 47712d1f330e4b22ce6dd30e7557288ef7f7fca0 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Wed, 27 Apr 2011 13:57:04 +1000 Subject: Ignore changes to selectByMouse during a selection. Use the value of selectByMouse at the time of a mouse press event in all subsequent mouse events in a sequence. This is the same as ignoring the intial mouse press except mouse events for other actions are still accepted. Change-Id: I59b50bf95d26c6320e6e74eeb679b4153e0edf4d Task-number: QTBUG-18887 Reviewed-by: Martin Jones --- .../graphicsitems/qdeclarativetextinput.cpp | 11 +- .../graphicsitems/qdeclarativetextinput_p_p.h | 4 +- src/gui/text/qtextcontrol.cpp | 16 +-- .../data/mouseselection_false_readonly.qml | 8 ++ .../data/mouseselection_true_readonly.qml | 8 ++ .../tst_qdeclarativetextedit.cpp | 84 ++++++++++++ .../data/mouseselection_default.qml | 7 + .../data/mouseselection_false.qml | 7 + .../data/mouseselection_false_readonly.qml | 8 ++ .../data/mouseselection_false_words.qml | 7 + .../data/mouseselection_true_readonly.qml | 8 ++ .../data/mouseselection_true_words.qml | 7 + .../tst_qdeclarativetextinput.cpp | 141 +++++++++++++++++++++ 13 files changed, 302 insertions(+), 14 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_readonly.qml create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_readonly.qml create mode 100644 tests/auto/declarative/qdeclarativetextinput/data/mouseselection_default.qml create mode 100644 tests/auto/declarative/qdeclarativetextinput/data/mouseselection_false.qml create mode 100644 tests/auto/declarative/qdeclarativetextinput/data/mouseselection_false_readonly.qml create mode 100644 tests/auto/declarative/qdeclarativetextinput/data/mouseselection_false_words.qml create mode 100644 tests/auto/declarative/qdeclarativetextinput/data/mouseselection_true_readonly.qml create mode 100644 tests/auto/declarative/qdeclarativetextinput/data/mouseselection_true_words.qml diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index 6eb6b68..9a91769 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -1168,9 +1168,10 @@ void QDeclarativeTextInput::mousePressEvent(QGraphicsSceneMouseEvent *event) } if (d->selectByMouse) { setKeepMouseGrab(false); + d->selectPressed = true; d->pressPos = event->pos(); } - bool mark = event->modifiers() & Qt::ShiftModifier; + bool mark = (event->modifiers() & Qt::ShiftModifier) && d->selectByMouse; int cursor = d->xToPos(event->pos().x()); d->control->moveCursor(cursor, mark); event->setAccepted(true); @@ -1181,7 +1182,7 @@ void QDeclarativeTextInput::mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_D(QDeclarativeTextInput); if (d->sendMouseEventToInputContext(event, QEvent::MouseMove)) return; - if (d->selectByMouse) { + if (d->selectPressed) { if (qAbs(int(event->pos().x() - d->pressPos.x())) > QApplication::startDragDistance()) setKeepMouseGrab(true); moveCursorSelection(d->xToPos(event->pos().x()), d->mouseSelectionMode); @@ -1200,8 +1201,10 @@ void QDeclarativeTextInput::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_D(QDeclarativeTextInput); if (d->sendMouseEventToInputContext(event, QEvent::MouseButtonRelease)) return; - if (d->selectByMouse) + if (d->selectPressed) { + d->selectPressed = false; setKeepMouseGrab(false); + } if (!d->showInputPanelOnFocus) { // input panel on click if (d->focusOnPress && !isReadOnly() && boundingRect().contains(event->pos())) { if (QGraphicsView * view = qobject_cast(qApp->focusWidget())) { @@ -1257,8 +1260,10 @@ bool QDeclarativeTextInputPrivate::sendMouseEventToInputContext( bool QDeclarativeTextInput::sceneEvent(QEvent *event) { + Q_D(QDeclarativeTextInput); bool rv = QDeclarativeItem::sceneEvent(event); if (event->type() == QEvent::UngrabMouse) { + d->selectPressed = false; setKeepMouseGrab(false); } return rv; diff --git a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h index ed53e8f..f6f6bd8 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextinput_p_p.h @@ -76,7 +76,8 @@ public: mouseSelectionMode(QDeclarativeTextInput::SelectCharacters), inputMethodHints(Qt::ImhNone), hscroll(0), oldScroll(0), oldValidity(false), focused(false), focusOnPress(true), showInputPanelOnFocus(true), clickCausedFocus(false), cursorVisible(false), - autoScroll(true), selectByMouse(false), canPaste(false), hAlignImplicit(true) + autoScroll(true), selectByMouse(false), canPaste(false), hAlignImplicit(true), + selectPressed(false) { #ifdef Q_OS_SYMBIAN if (QSysInfo::symbianVersion() == QSysInfo::SV_SF_1 || QSysInfo::symbianVersion() == QSysInfo::SV_SF_3) { @@ -142,6 +143,7 @@ public: bool selectByMouse:1; bool canPaste:1; bool hAlignImplicit:1; + bool selectPressed:1; static inline QDeclarativeTextInputPrivate *get(QDeclarativeTextInput *t) { return t->d_func(); diff --git a/src/gui/text/qtextcontrol.cpp b/src/gui/text/qtextcontrol.cpp index bee4d95..3fd3ab5 100644 --- a/src/gui/text/qtextcontrol.cpp +++ b/src/gui/text/qtextcontrol.cpp @@ -1518,7 +1518,7 @@ void QTextControlPrivate::mousePressEvent(QEvent *e, Qt::MouseButton button, con const QTextCursor oldSelection = cursor; const int oldCursorPos = cursor.position(); - mousePressed = true; + mousePressed = (interactionFlags & Qt::TextSelectableByMouse); #ifndef QT_NO_DRAGANDDROP mightStartDrag = false; #endif @@ -1607,13 +1607,11 @@ void QTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button, cons if (!(buttons & Qt::LeftButton)) return; - const bool selectable = interactionFlags & Qt::TextSelectableByMouse; const bool editable = interactionFlags & Qt::TextEditable; - if (!selectable && !editable) - return; - if (!(mousePressed + || editable + || mightStartDrag || selectedWordOnDoubleClick.hasSelection() || selectedBlockOnTrippleClick.hasSelection())) return; @@ -1627,7 +1625,7 @@ void QTextControlPrivate::mouseMoveEvent(QEvent *e, Qt::MouseButton button, cons return; } - if (!selectable) + if (!mousePressed) return; const qreal mouseX = qreal(mousePos.x()); @@ -1695,10 +1693,8 @@ void QTextControlPrivate::mouseReleaseEvent(QEvent *e, Qt::MouseButton button, c if (mousePressed) { mousePressed = false; #ifndef QT_NO_CLIPBOARD - if (interactionFlags & Qt::TextSelectableByMouse) { - setClipboardSelection(); - selectionChanged(true); - } + setClipboardSelection(); + selectionChanged(true); } else if (button == Qt::MidButton && (interactionFlags & Qt::TextEditable) && QApplication::clipboard()->supportsSelection()) { diff --git a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_readonly.qml b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_readonly.qml new file mode 100644 index 0000000..4aea611 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_readonly.qml @@ -0,0 +1,8 @@ +import QtQuick 1.0 + +TextEdit { + focus: true + text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + selectByMouse: false + readOnly: true +} diff --git a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_readonly.qml b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_readonly.qml new file mode 100644 index 0000000..959e683 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_readonly.qml @@ -0,0 +1,8 @@ +import QtQuick 1.0 + +TextEdit { + focus: true + text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + selectByMouse: true + readOnly: true +} diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 53f8a24..2fad88d 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -119,6 +119,10 @@ private slots: void moveCursorSelectionSequence(); void mouseSelection_data(); void mouseSelection(); + void deferEnableSelectByMouse_data(); + void deferEnableSelectByMouse(); + void deferDisableSelectByMouse_data(); + void deferDisableSelectByMouse(); void mouseSelectionMode_data(); void mouseSelectionMode(); void dragMouseSelection(); @@ -1360,6 +1364,86 @@ void tst_qdeclarativetextedit::mouseSelection() delete canvas; } +void tst_qdeclarativetextedit::deferEnableSelectByMouse_data() +{ + QTest::addColumn("qmlfile"); + + QTest::newRow("writable") << SRCDIR "/data/mouseselection_false.qml"; + QTest::newRow("read only") << SRCDIR "/data/mouseselection_false_readonly.qml"; +} + +void tst_qdeclarativetextedit::deferEnableSelectByMouse() +{ + // Verify text isn't selected if selectByMouse is enabled after the mouse button has been pressed. + QFETCH(QString, qmlfile); + + QDeclarativeView *canvas = createView(qmlfile); + + canvas->show(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast(canvas)); + + QVERIFY(canvas->rootObject() != 0); + QDeclarativeTextEdit *textEditObject = qobject_cast(canvas->rootObject()); + QVERIFY(textEditObject != 0); + + // press-and-drag-and-release from x1 to x2 + int x1 = 10; + int x2 = 70; + int y = textEditObject->height()/2; + + QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x1,y))); + textEditObject->setSelectByMouse(true); + //QTest::mouseMove(canvas->viewport(), canvas->mapFromScene(QPoint(x2,y))); // doesn't work + QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(QPoint(x2,y)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + QApplication::sendEvent(canvas->viewport(), &mv); + QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x2,y))); + QVERIFY(textEditObject->selectedText().isEmpty()); + + delete canvas; +} + +void tst_qdeclarativetextedit::deferDisableSelectByMouse_data() +{ + QTest::addColumn("qmlfile"); + + QTest::newRow("writable") << SRCDIR "/data/mouseselection_true.qml"; + QTest::newRow("read only") << SRCDIR "/data/mouseselection_true_readonly.qml"; +} + +void tst_qdeclarativetextedit::deferDisableSelectByMouse() +{ + // Verify text isn't selected if selectByMouse is enabled after the mouse button has been pressed. + QFETCH(QString, qmlfile); + + QDeclarativeView *canvas = createView(qmlfile); + + canvas->show(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast(canvas)); + + QVERIFY(canvas->rootObject() != 0); + QDeclarativeTextEdit *textEditObject = qobject_cast(canvas->rootObject()); + QVERIFY(textEditObject != 0); + + // press-and-drag-and-release from x1 to x2 + int x1 = 10; + int x2 = 70; + int y = textEditObject->height()/2; + + QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x1,y))); + textEditObject->setSelectByMouse(false); + //QTest::mouseMove(canvas->viewport(), canvas->mapFromScene(QPoint(x2,y))); // doesn't work + QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(QPoint(x2,y)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + QApplication::sendEvent(canvas->viewport(), &mv); + QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x2,y))); + QVERIFY(textEditObject->selectedText().length() > 3); + + delete canvas; +} + void tst_qdeclarativetextedit::dragMouseSelection() { QString qmlfile = SRCDIR "/data/mouseselection_true.qml"; diff --git a/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_default.qml b/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_default.qml new file mode 100644 index 0000000..eea83ed --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_default.qml @@ -0,0 +1,7 @@ +import QtQuick 1.0 + +TextInput { + focus: true + text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + selectByMouse: false +} diff --git a/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_false.qml b/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_false.qml new file mode 100644 index 0000000..eea83ed --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_false.qml @@ -0,0 +1,7 @@ +import QtQuick 1.0 + +TextInput { + focus: true + text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + selectByMouse: false +} diff --git a/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_false_readonly.qml b/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_false_readonly.qml new file mode 100644 index 0000000..36a9563 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_false_readonly.qml @@ -0,0 +1,8 @@ +import QtQuick 1.0 + +TextInput { + focus: true + text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + selectByMouse: false + readOnly: true +} diff --git a/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_false_words.qml b/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_false_words.qml new file mode 100644 index 0000000..eea83ed --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_false_words.qml @@ -0,0 +1,7 @@ +import QtQuick 1.0 + +TextInput { + focus: true + text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + selectByMouse: false +} diff --git a/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_true_readonly.qml b/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_true_readonly.qml new file mode 100644 index 0000000..678a89a --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_true_readonly.qml @@ -0,0 +1,8 @@ +import QtQuick 1.0 + +TextInput { + focus: true + text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + selectByMouse: true + readOnly: true +} diff --git a/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_true_words.qml b/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_true_words.qml new file mode 100644 index 0000000..8115ba0 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextinput/data/mouseselection_true_words.qml @@ -0,0 +1,7 @@ +import QtQuick 1.0 + +TextInput { + focus: true + text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + selectByMouse: true +} diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index d4b844c..a241241 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -95,6 +95,12 @@ private slots: void moveCursorSelection(); void moveCursorSelectionSequence_data(); void moveCursorSelectionSequence(); + void mouseSelection_data(); + void mouseSelection(); + void deferEnableSelectByMouse_data(); + void deferEnableSelectByMouse(); + void deferDisableSelectByMouse_data(); + void deferDisableSelectByMouse(); void dragMouseSelection(); void mouseSelectionMode_data(); void mouseSelectionMode(); @@ -911,6 +917,141 @@ void tst_qdeclarativetextinput::moveCursorSelectionSequence() QCOMPARE(textinputObject->selectionEnd(), selection2End); } +void tst_qdeclarativetextinput::mouseSelection_data() +{ + QTest::addColumn("qmlfile"); + QTest::addColumn("expectSelection"); + + // import installed + QTest::newRow("on") << SRCDIR "/data/mouseselection_true.qml" << true; + QTest::newRow("off") << SRCDIR "/data/mouseselection_false.qml" << false; + QTest::newRow("default") << SRCDIR "/data/mouseselection_default.qml" << false; + QTest::newRow("on word selection") << SRCDIR "/data/mouseselection_true_words.qml" << true; + QTest::newRow("off word selection") << SRCDIR "/data/mouseselection_false_words.qml" << false; + QTest::newRow("on read only") << SRCDIR "/data/mouseselection_true_readonly.qml" << true; + QTest::newRow("off read only") << SRCDIR "/data/mouseselection_false_readonly.qml" << false; +} + +void tst_qdeclarativetextinput::mouseSelection() +{ + QFETCH(QString, qmlfile); + QFETCH(bool, expectSelection); + + QDeclarativeView *canvas = createView(qmlfile); + + canvas->show(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast(canvas)); + + QVERIFY(canvas->rootObject() != 0); + QDeclarativeTextInput *textInputObject = qobject_cast(canvas->rootObject()); + QVERIFY(textInputObject != 0); + + // press-and-drag-and-release from x1 to x2 + int x1 = 10; + int x2 = 70; + int y = textInputObject->height()/2; + QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x1,y))); + //QTest::mouseMove(canvas->viewport(), canvas->mapFromScene(QPoint(x2,y))); // doesn't work + QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(QPoint(x2,y)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + QApplication::sendEvent(canvas->viewport(), &mv); + QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x2,y))); + QString str = textInputObject->selectedText(); + if (expectSelection) + QVERIFY(str.length() > 3); // don't reallly care *what* was selected (and it's too sensitive to platform) + else + QVERIFY(str.isEmpty()); + + // Clicking and shift to clicking between the same points should select the same text. + textInputObject->setCursorPosition(0); + QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::NoModifier, canvas->mapFromScene(QPoint(x1,y))); + QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::ShiftModifier, canvas->mapFromScene(QPoint(x2,y))); + QCOMPARE(textInputObject->selectedText(), str); + + delete canvas; +} + +void tst_qdeclarativetextinput::deferEnableSelectByMouse_data() +{ + QTest::addColumn("qmlfile"); + + QTest::newRow("writable") << SRCDIR "/data/mouseselection_false.qml"; + QTest::newRow("read only") << SRCDIR "/data/mouseselection_false_readonly.qml"; +} + +void tst_qdeclarativetextinput::deferEnableSelectByMouse() +{ + // Verify text isn't selected if selectByMouse is enabled after the mouse button has been pressed. + QFETCH(QString, qmlfile); + + QDeclarativeView *canvas = createView(qmlfile); + + canvas->show(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast(canvas)); + + QVERIFY(canvas->rootObject() != 0); + QDeclarativeTextInput *textInputObject = qobject_cast(canvas->rootObject()); + QVERIFY(textInputObject != 0); + + // press-and-drag-and-release from x1 to x2 + int x1 = 10; + int x2 = 70; + int y = textInputObject->height()/2; + + QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x1,y))); + textInputObject->setSelectByMouse(true); + //QTest::mouseMove(canvas->viewport(), canvas->mapFromScene(QPoint(x2,y))); // doesn't work + QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(QPoint(x2,y)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + QApplication::sendEvent(canvas->viewport(), &mv); + QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x2,y))); + QVERIFY(textInputObject->selectedText().isEmpty()); + + delete canvas; +} + +void tst_qdeclarativetextinput::deferDisableSelectByMouse_data() +{ + QTest::addColumn("qmlfile"); + + QTest::newRow("writable") << SRCDIR "/data/mouseselection_true.qml"; + QTest::newRow("read only") << SRCDIR "/data/mouseselection_true_readonly.qml"; +} + +void tst_qdeclarativetextinput::deferDisableSelectByMouse() +{ + // Verify text isn't selected if selectByMouse is enabled after the mouse button has been pressed. + QFETCH(QString, qmlfile); + + QDeclarativeView *canvas = createView(qmlfile); + + canvas->show(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast(canvas)); + + QVERIFY(canvas->rootObject() != 0); + QDeclarativeTextInput *textInputObject = qobject_cast(canvas->rootObject()); + QVERIFY(textInputObject != 0); + + // press-and-drag-and-release from x1 to x2 + int x1 = 10; + int x2 = 70; + int y = textInputObject->height()/2; + + QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x1,y))); + textInputObject->setSelectByMouse(false); + //QTest::mouseMove(canvas->viewport(), canvas->mapFromScene(QPoint(x2,y))); // doesn't work + QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(QPoint(x2,y)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + QApplication::sendEvent(canvas->viewport(), &mv); + QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x2,y))); + QVERIFY(textInputObject->selectedText().length() > 3); + + delete canvas; +} + void tst_qdeclarativetextinput::dragMouseSelection() { QString qmlfile = SRCDIR "/data/mouseselection_true.qml"; -- cgit v0.12 From 710aa7f8fbd72ee303c3348aa3aaf12d6984964d Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 27 Apr 2011 10:05:25 +0200 Subject: Specify swap behavior preserved bit in openvg engine. Unlike OpenGL, the EGL_SWAP_BEHAVIOR_PRESERVED_BIT was not set for the EGL configuration used with OpenVG. Yet the preserved swap was enabled still, which, according to the EGL spec, should fail. To make sure it still works with other EGL implementations, the bit is now set in the configuration. Reviewed-by: Jani Hautakangas --- src/openvg/qwindowsurface_vgegl.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/openvg/qwindowsurface_vgegl.cpp b/src/openvg/qwindowsurface_vgegl.cpp index 866453f..3205a11 100644 --- a/src/openvg/qwindowsurface_vgegl.cpp +++ b/src/openvg/qwindowsurface_vgegl.cpp @@ -269,19 +269,20 @@ static QEglContext *createContext(QPaintDevice *device) configProps.setPixelFormat(QImage::Format_ARGB32); // XXX configProps.setValue(EGL_ALPHA_MASK_SIZE, 1); #ifdef EGL_VG_ALPHA_FORMAT_PRE_BIT - configProps.setValue(EGL_SURFACE_TYPE, EGL_WINDOW_BIT | - EGL_VG_ALPHA_FORMAT_PRE_BIT); + configProps.setValue(EGL_SURFACE_TYPE, EGL_WINDOW_BIT + | EGL_SWAP_BEHAVIOR_PRESERVED_BIT + | EGL_VG_ALPHA_FORMAT_PRE_BIT); configProps.setRenderableType(QEgl::OpenVG); if (!context->chooseConfig(configProps)) { // Try again without the "pre" bit. - configProps.setValue(EGL_SURFACE_TYPE, EGL_WINDOW_BIT); + configProps.setValue(EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT); if (!context->chooseConfig(configProps)) { delete context; return 0; } } #else - configProps.setValue(EGL_SURFACE_TYPE, EGL_WINDOW_BIT); + configProps.setValue(EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_SWAP_BEHAVIOR_PRESERVED_BIT); configProps.setRenderableType(QEgl::OpenVG); if (!context->chooseConfig(configProps)) { delete context; -- cgit v0.12