From 2c198b3ace2fb09ed0eaa45aec6ce2c96a45aafb Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Mon, 22 Aug 2011 11:31:22 +1000 Subject: Fix left alignment of native RTL pre-edit text. If there is no committed text in a TextInput or TextEdit determine if the pre-edit text is right to left before falling back to the global keyboard settings. Change-Id: I7e5568e936341602b8faf7be120f9a770c115f48 Task-number: QMLNG-72 Reviewed-by: Michael Brasser --- src/declarative/graphicsitems/qdeclarativetextedit.cpp | 11 ++++++++++- src/declarative/graphicsitems/qdeclarativetextinput.cpp | 7 ++++++- .../data/horizontalAlignment_RightToLeft.qml | 1 + .../qdeclarativetextedit/tst_qdeclarativetextedit.cpp | 12 ++++++++++++ .../data/horizontalAlignment_RightToLeft.qml | 1 + .../qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 13 +++++++++++++ 6 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 42c520c..cc5279a 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -547,7 +547,15 @@ bool QDeclarativeTextEditPrivate::determineHorizontalAlignment() { Q_Q(QDeclarativeTextEdit); if (hAlignImplicit && q->isComponentComplete()) { - bool alignToRight = text.isEmpty() ? QApplication::keyboardInputDirection() == Qt::RightToLeft : rightToLeftText; + bool alignToRight; + if (text.isEmpty()) { + const QString preeditText = control->textCursor().block().layout()->preeditAreaText(); + alignToRight = preeditText.isEmpty() + ? QApplication::keyboardInputDirection() == Qt::RightToLeft + : preeditText.isRightToLeft(); + } else { + alignToRight = rightToLeftText; + } return setHAlign(alignToRight ? QDeclarativeTextEdit::AlignRight : QDeclarativeTextEdit::AlignLeft); } return false; @@ -1582,6 +1590,7 @@ void QDeclarativeTextEdit::q_textChanged() void QDeclarativeTextEdit::moveCursorDelegate() { Q_D(QDeclarativeTextEdit); + d->determineHorizontalAlignment(); updateMicroFocus(); emit cursorRectangleChanged(); if(!d->cursor) diff --git a/src/declarative/graphicsitems/qdeclarativetextinput.cpp b/src/declarative/graphicsitems/qdeclarativetextinput.cpp index f68f1c6..c5c9f5e 100644 --- a/src/declarative/graphicsitems/qdeclarativetextinput.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextinput.cpp @@ -407,7 +407,11 @@ bool QDeclarativeTextInputPrivate::determineHorizontalAlignment() if (hAlignImplicit) { // if no explicit alignment has been set, follow the natural layout direction of the text QString text = control->text(); - bool isRightToLeft = text.isEmpty() ? QApplication::keyboardInputDirection() == Qt::RightToLeft : text.isRightToLeft(); + if (text.isEmpty()) + text = control->preeditAreaText(); + bool isRightToLeft = text.isEmpty() + ? QApplication::keyboardInputDirection() == Qt::RightToLeft + : text.isRightToLeft(); return setHAlign(isRightToLeft ? QDeclarativeTextInput::AlignRight : QDeclarativeTextInput::AlignLeft); } return false; @@ -1909,6 +1913,7 @@ void QDeclarativeTextInput::cursorPosChanged() void QDeclarativeTextInput::updateCursorRectangle() { Q_D(QDeclarativeTextInput); + d->determineHorizontalAlignment(); d->updateHorizontalScroll(); updateRect();//TODO: Only update rect between pos's updateMicroFocus(); diff --git a/tests/auto/declarative/qdeclarativetextedit/data/horizontalAlignment_RightToLeft.qml b/tests/auto/declarative/qdeclarativetextedit/data/horizontalAlignment_RightToLeft.qml index 43ea8d8..6e739bf 100644 --- a/tests/auto/declarative/qdeclarativetextedit/data/horizontalAlignment_RightToLeft.qml +++ b/tests/auto/declarative/qdeclarativetextedit/data/horizontalAlignment_RightToLeft.qml @@ -18,6 +18,7 @@ Rectangle { objectName: "text" anchors.fill: parent text: top.text + focus: true } } } diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 5d6f2a2..5c7f36f 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -454,6 +454,8 @@ void tst_qdeclarativetextedit::hAlign_RightToLeft() QVERIFY(textEdit != 0); canvas->show(); + const QString rtlText = textEdit->text(); + // implicit alignment should follow the reading direction of text QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignRight); QVERIFY(textEdit->positionToRectangle(0).x() > canvas->width()/2); @@ -530,6 +532,16 @@ void tst_qdeclarativetextedit::hAlign_RightToLeft() QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignLeft); QVERIFY(textEdit->positionToRectangle(0).x() < canvas->width()/2); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast(canvas)); + + textEdit->setText(QString()); + { QInputMethodEvent ev(rtlText, QList()); QApplication::sendEvent(canvas, &ev); } + QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignRight); + { QInputMethodEvent ev("Hello world!", QList()); QApplication::sendEvent(canvas, &ev); } + QCOMPARE(textEdit->hAlign(), QDeclarativeTextEdit::AlignLeft); + #ifndef Q_OS_MAC // QTBUG-18040 // empty text with implicit alignment follows the system locale-based // keyboard input direction from QApplication::keyboardInputDirection diff --git a/tests/auto/declarative/qdeclarativetextinput/data/horizontalAlignment_RightToLeft.qml b/tests/auto/declarative/qdeclarativetextinput/data/horizontalAlignment_RightToLeft.qml index b11535e..7f27bbe 100644 --- a/tests/auto/declarative/qdeclarativetextinput/data/horizontalAlignment_RightToLeft.qml +++ b/tests/auto/declarative/qdeclarativetextinput/data/horizontalAlignment_RightToLeft.qml @@ -18,6 +18,7 @@ Rectangle { objectName: "text" anchors.fill: parent text: top.text + focus: true } } } diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 280f952..7f3b8a2 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -1198,6 +1198,8 @@ void tst_qdeclarativetextinput::horizontalAlignment_RightToLeft() QVERIFY(textInput != 0); canvas->show(); + const QString rtlText = textInput->text(); + QDeclarativeTextInputPrivate *textInputPrivate = QDeclarativeTextInputPrivate::get(textInput); QVERIFY(textInputPrivate != 0); QVERIFY(-textInputPrivate->hscroll > canvas->width()/2); @@ -1262,6 +1264,17 @@ void tst_qdeclarativetextinput::horizontalAlignment_RightToLeft() QCOMPARE(textInput->hAlign(), QDeclarativeTextInput::AlignLeft); QVERIFY(-textInputPrivate->hscroll < canvas->width()/2); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast(canvas)); + + // If there is no commited text, the preedit text should determine the alignment. + textInput->setText(QString()); + { QInputMethodEvent ev(rtlText, QList()); QApplication::sendEvent(canvas, &ev); } + QCOMPARE(textInput->hAlign(), QDeclarativeTextInput::AlignRight); + { QInputMethodEvent ev("Hello world!", QList()); QApplication::sendEvent(canvas, &ev); } + QCOMPARE(textInput->hAlign(), QDeclarativeTextInput::AlignLeft); + #ifndef Q_OS_MAC // QTBUG-18040 // empty text with implicit alignment follows the system locale-based // keyboard input direction from QApplication::keyboardInputDirection -- cgit v0.12 From 0b19ee5ecabfc516256f0a6db0f2e7bc37e703a0 Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Tue, 23 Aug 2011 14:55:46 +0300 Subject: In landscape mode QComboboBox popup can not be showed completely ComboBox popups have regressed in 4.7.4 lately. Combobox popup is shown as smallish square rectangle in landscape orientation. As a fix, let the width of the popup match the height of the screen (native dialogs most of the time have width matching the height of the screen). Task-number: QTBUG-20932 Reviewed-by: Miikka Heikkinen --- src/gui/widgets/qcombobox.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/qcombobox.cpp b/src/gui/widgets/qcombobox.cpp index f4a627b..8a69bdf 100644 --- a/src/gui/widgets/qcombobox.cpp +++ b/src/gui/widgets/qcombobox.cpp @@ -2473,7 +2473,7 @@ void QComboBox::showPopup() } else { TRect staConTopRect = TRect(); AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EStaconTop, staConTopRect); - listRect.setWidth(listRect.height()); + listRect.setWidth(screen.height()); //by default popup is centered on screen in landscape listRect.moveCenter(screen.center()); if (staConTopRect.IsEmpty()) { -- cgit v0.12 From 1ee6ff9fab218a8fa02a3cad1614730eb716bf45 Mon Sep 17 00:00:00 2001 From: Sergio Ahumada Date: Tue, 23 Aug 2011 20:13:43 +0200 Subject: Doc: Fixing typo --- .../declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp index 7f3b8a2..bb895bf 100644 --- a/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp +++ b/tests/auto/declarative/qdeclarativetextinput/tst_qdeclarativetextinput.cpp @@ -1268,7 +1268,7 @@ void tst_qdeclarativetextinput::horizontalAlignment_RightToLeft() QTest::qWaitForWindowShown(canvas); QTRY_COMPARE(QApplication::activeWindow(), static_cast(canvas)); - // If there is no commited text, the preedit text should determine the alignment. + // If there is no committed text, the preedit text should determine the alignment. textInput->setText(QString()); { QInputMethodEvent ev(rtlText, QList()); QApplication::sendEvent(canvas, &ev); } QCOMPARE(textInput->hAlign(), QDeclarativeTextInput::AlignRight); -- cgit v0.12 From 33eb83565466d3dc31ea90dcf18dc3c7b16fd5b6 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Wed, 24 Aug 2011 11:26:29 +1000 Subject: Make it easier to select words at the start of a line. QTextControl's word selection will only include a word if the cursor position is past the mid point of the word. This can make it difficult to select words near the edges of the screen on touch devices. For the TextEdit word selection mode select a word ignore the relative position within a word. Change-Id: I2bc61376f663836fedd7e157448f0b565a64d485 Task-number: QT-5206 Reviewed-by: Martin Jones --- src/gui/text/qtextcontrol.cpp | 34 +++++++++------ .../data/mouseselection_false_words.qml | 5 ++- .../data/mouseselection_true_words.qml | 5 ++- .../tst_qdeclarativetextedit.cpp | 49 ++++++++++++---------- 4 files changed, 56 insertions(+), 37 deletions(-) diff --git a/src/gui/text/qtextcontrol.cpp b/src/gui/text/qtextcontrol.cpp index 9081ab7..f3d42f8 100644 --- a/src/gui/text/qtextcontrol.cpp +++ b/src/gui/text/qtextcontrol.cpp @@ -679,20 +679,30 @@ void QTextControlPrivate::extendWordwiseSelection(int suggestedNewPosition, qrea if (!wordSelectionEnabled && (mouseXPosition < wordStartX || mouseXPosition > wordEndX)) return; - // keep the already selected word even when moving to the left - // (#39164) - if (suggestedNewPosition < selectedWordOnDoubleClick.position()) - cursor.setPosition(selectedWordOnDoubleClick.selectionEnd()); - else - cursor.setPosition(selectedWordOnDoubleClick.selectionStart()); + if (wordSelectionEnabled) { + if (suggestedNewPosition < selectedWordOnDoubleClick.position()) { + cursor.setPosition(selectedWordOnDoubleClick.selectionEnd()); + setCursorPosition(wordStartPos, QTextCursor::KeepAnchor); + } else { + cursor.setPosition(selectedWordOnDoubleClick.selectionStart()); + setCursorPosition(wordEndPos, QTextCursor::KeepAnchor); + } + } else { + // keep the already selected word even when moving to the left + // (#39164) + if (suggestedNewPosition < selectedWordOnDoubleClick.position()) + cursor.setPosition(selectedWordOnDoubleClick.selectionEnd()); + else + cursor.setPosition(selectedWordOnDoubleClick.selectionStart()); - const qreal differenceToStart = mouseXPosition - wordStartX; - const qreal differenceToEnd = wordEndX - mouseXPosition; + const qreal differenceToStart = mouseXPosition - wordStartX; + const qreal differenceToEnd = wordEndX - mouseXPosition; - if (differenceToStart < differenceToEnd) - setCursorPosition(wordStartPos, QTextCursor::KeepAnchor); - else - setCursorPosition(wordEndPos, QTextCursor::KeepAnchor); + if (differenceToStart < differenceToEnd) + setCursorPosition(wordStartPos, QTextCursor::KeepAnchor); + else + setCursorPosition(wordEndPos, QTextCursor::KeepAnchor); + } if (interactionFlags & Qt::TextSelectableByMouse) { #ifndef QT_NO_CLIPBOARD diff --git a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml index 22a9871..f8d2e4e 100644 --- a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml +++ b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_false_words.qml @@ -1,7 +1,8 @@ -import QtQuick 1.0 +import QtQuick 1.1 TextEdit { focus: true - text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + text: "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" selectByMouse: false + mouseSelectionMode: TextEdit.SelectWords } diff --git a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml index d61da46..f58fd45 100644 --- a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml +++ b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_true_words.qml @@ -1,7 +1,8 @@ -import QtQuick 1.0 +import QtQuick 1.1 TextEdit { focus: true - text: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" + text: "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ" selectByMouse: true + mouseSelectionMode: TextEdit.SelectWords } diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 5c7f36f..fde0588 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -1327,20 +1327,32 @@ void tst_qdeclarativetextedit::moveCursorSelectionSequence() void tst_qdeclarativetextedit::mouseSelection_data() { QTest::addColumn("qmlfile"); - QTest::addColumn("expectSelection"); + QTest::addColumn("from"); + QTest::addColumn("to"); + QTest::addColumn("selectedText"); // 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") << SRCDIR "/data/mouseselection_true.qml" << 4 << 9 << "45678"; + QTest::newRow("off") << SRCDIR "/data/mouseselection_false.qml" << 4 << 9 << QString(); + QTest::newRow("default") << SRCDIR "/data/mouseselection_default.qml" << 4 << 9 << QString(); + QTest::newRow("off word selection") << SRCDIR "/data/mouseselection_false_words.qml" << 4 << 9 << QString(); + QTest::newRow("on word selection (4,9)") << SRCDIR "/data/mouseselection_true_words.qml" << 4 << 9 << "0123456789"; + QTest::newRow("on word selection (2,13)") << SRCDIR "/data/mouseselection_true_words.qml" << 2 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + QTest::newRow("on word selection (2,30)") << SRCDIR "/data/mouseselection_true_words.qml" << 2 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + QTest::newRow("on word selection (9,13)") << SRCDIR "/data/mouseselection_true_words.qml" << 9 << 13 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + QTest::newRow("on word selection (9,30)") << SRCDIR "/data/mouseselection_true_words.qml" << 9 << 30 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + QTest::newRow("on word selection (13,2)") << SRCDIR "/data/mouseselection_true_words.qml" << 13 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + QTest::newRow("on word selection (20,2)") << SRCDIR "/data/mouseselection_true_words.qml" << 20 << 2 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + QTest::newRow("on word selection (12,9)") << SRCDIR "/data/mouseselection_true_words.qml" << 12 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + QTest::newRow("on word selection (30,9)") << SRCDIR "/data/mouseselection_true_words.qml" << 30 << 9 << "0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ"; } void tst_qdeclarativetextedit::mouseSelection() { QFETCH(QString, qmlfile); - QFETCH(bool, expectSelection); + QFETCH(int, from); + QFETCH(int, to); + QFETCH(QString, selectedText); QDeclarativeView *canvas = createView(qmlfile); @@ -1354,25 +1366,20 @@ void tst_qdeclarativetextedit::mouseSelection() 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))); + QPoint p1 = canvas->mapFromScene(textEditObject->positionToRectangle(from).center()); + QPoint p2 = canvas->mapFromScene(textEditObject->positionToRectangle(to).center()); + QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, p1); //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); + QMouseEvent mv(QEvent::MouseMove, canvas->mapFromScene(p2), 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 = textEditObject->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()); + QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, p2); + QCOMPARE(textEditObject->selectedText(), selectedText); // Clicking and shift to clicking between the same points should select the same text. textEditObject->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(textEditObject->selectedText(), str); + QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::NoModifier, p1); + QTest::mouseClick(canvas->viewport(), Qt::LeftButton, Qt::ShiftModifier, p2); + QCOMPARE(textEditObject->selectedText(), selectedText); delete canvas; } -- cgit v0.12 From 4eb50fbbf414103fb2f9dfb8260f4db5d61190c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Niemel=C3=A4?= Date: Wed, 24 Aug 2011 15:29:17 +0300 Subject: Fix for qml1shaderplugin GPU resource handling on Symbian qml1shaderplugin now automatically recovers from situations when GL context is destroyed and related FBOs and shaderprograms become invalid. Additionally the shaderprograms are created lazily so that no GPU memory is used if items are not visible. Task-number: QTBUG-20724 QTBUG-20736 Reviewed-by: Jani Hautakangas --- src/imports/shaders/shadereffectitem.cpp | 110 ++++++++++++++++++++++------- src/imports/shaders/shadereffectitem.h | 4 +- src/imports/shaders/shadereffectsource.cpp | 43 ++++++----- src/imports/shaders/shadereffectsource.h | 3 +- 4 files changed, 116 insertions(+), 44 deletions(-) mode change 100644 => 100755 src/imports/shaders/shadereffectitem.cpp diff --git a/src/imports/shaders/shadereffectitem.cpp b/src/imports/shaders/shadereffectitem.cpp old mode 100644 new mode 100755 index 056581c..04c81f5 --- a/src/imports/shaders/shadereffectitem.cpp +++ b/src/imports/shaders/shadereffectitem.cpp @@ -199,8 +199,13 @@ Rectangle { */ +#ifdef Q_OS_SYMBIAN +#define OBSERVE_GL_CONTEXT_LOSS 1 +#endif + ShaderEffectItem::ShaderEffectItem(QDeclarativeItem *parent) : QDeclarativeItem(parent) + , m_program(0) , m_meshResolution(1, 1) , m_geometry(QSGGeometry::defaultAttributes_TexturedPoint2D(), 4) , m_blending(true) @@ -214,15 +219,21 @@ ShaderEffectItem::ShaderEffectItem(QDeclarativeItem *parent) , m_hasShaderPrograms(false) , m_mirrored(false) , m_defaultVertexShader(true) + , m_contextObserver(0) { setFlag(QGraphicsItem::ItemHasNoContents, false); connect(this, SIGNAL(visibleChanged()), this, SLOT(handleVisibilityChange())); m_active = isVisible(); + +#ifndef OBSERVE_GL_CONTEXT_LOSS + m_program = new QGLShaderProgram(this); +#endif } ShaderEffectItem::~ShaderEffectItem() { reset(); + delete m_contextObserver; } @@ -422,10 +433,38 @@ void ShaderEffectItem::renderEffect(QPainter *painter, const QMatrix4x4 &matrix) if (!painter || !painter->device()) return; - if (!m_program.isLinked() || m_program_dirty) +#ifdef OBSERVE_GL_CONTEXT_LOSS + QGLContext *context = const_cast (QGLContext::currentContext()); + if (!m_program || !m_contextObserver || !m_contextObserver->isValid()) { + // Context has changed, re-create QGLShaderProgram + if (context) { + delete m_program; + m_program = 0; + + delete m_contextObserver; + m_contextObserver = 0; + + m_program = new QGLShaderProgram(this); + m_contextObserver = new QGLFramebufferObject(QSize(2,2)); + + if (!m_contextObserver || !m_program) { + delete m_program; + m_program = 0; + delete m_contextObserver; + m_contextObserver = 0; + qWarning() << "ShaderEffectItem::renderEffect - Creating QGLShaderProgram or QGLFrameBufferObject failed!"; + } + } + } +#endif + + if (!m_program) + return; + + if (!m_program->isLinked() || m_program_dirty) updateShaderProgram(); - m_program.bind(); + m_program->bind(); QMatrix4x4 combinedMatrix; combinedMatrix.scale(2.0 / painter->device()->width(), -2.0 / painter->device()->height(), 1.0); @@ -434,7 +473,7 @@ void ShaderEffectItem::renderEffect(QPainter *painter, const QMatrix4x4 &matrix) updateEffectState(combinedMatrix); for (int i = 0; i < m_attributeNames.size(); ++i) { - m_program.enableAttributeArray(m_geometry.attributes()[i].position); + m_program->enableAttributeArray(m_geometry.attributes()[i].position); } bindGeometry(); @@ -472,11 +511,14 @@ void ShaderEffectItem::renderEffect(QPainter *painter, const QMatrix4x4 &matrix) glDisable(GL_DEPTH_TEST); for (int i = 0; i < m_attributeNames.size(); ++i) - m_program.disableAttributeArray(m_geometry.attributes()[i].position); + m_program->disableAttributeArray(m_geometry.attributes()[i].position); } void ShaderEffectItem::updateEffectState(const QMatrix4x4 &matrix) { + if (!m_program) + return; + for (int i = m_sources.size() - 1; i >= 0; --i) { const ShaderEffectItem::SourceData &source = m_sources.at(i); if (!source.source) @@ -487,10 +529,10 @@ void ShaderEffectItem::updateEffectState(const QMatrix4x4 &matrix) } if (m_respectsOpacity) - m_program.setUniformValue("qt_Opacity", static_cast (effectiveOpacity())); + m_program->setUniformValue("qt_Opacity", static_cast (effectiveOpacity())); if (m_respectsMatrix){ - m_program.setUniformValue("qt_ModelViewProjectionMatrix", matrix); + m_program->setUniformValue("qt_ModelViewProjectionMatrix", matrix); } QSet::const_iterator it; @@ -500,37 +542,37 @@ void ShaderEffectItem::updateEffectState(const QMatrix4x4 &matrix) switch (v.type()) { case QVariant::Color: - m_program.setUniformValue(name.constData(), qvariant_cast(v)); + m_program->setUniformValue(name.constData(), qvariant_cast(v)); break; case QVariant::Double: - m_program.setUniformValue(name.constData(), (float) qvariant_cast(v)); + m_program->setUniformValue(name.constData(), (float) qvariant_cast(v)); break; case QVariant::Transform: - m_program.setUniformValue(name.constData(), qvariant_cast(v)); + m_program->setUniformValue(name.constData(), qvariant_cast(v)); break; case QVariant::Int: - m_program.setUniformValue(name.constData(), v.toInt()); + m_program->setUniformValue(name.constData(), GLint(v.toInt())); break; case QVariant::Bool: - m_program.setUniformValue(name.constData(), GLint(v.toBool())); + m_program->setUniformValue(name.constData(), GLint(v.toBool())); break; case QVariant::Size: case QVariant::SizeF: - m_program.setUniformValue(name.constData(), v.toSizeF()); + m_program->setUniformValue(name.constData(), v.toSizeF()); break; case QVariant::Point: case QVariant::PointF: - m_program.setUniformValue(name.constData(), v.toPointF()); + m_program->setUniformValue(name.constData(), v.toPointF()); break; case QVariant::Rect: case QVariant::RectF: { QRectF r = v.toRectF(); - m_program.setUniformValue(name.constData(), r.x(), r.y(), r.width(), r.height()); + m_program->setUniformValue(name.constData(), r.x(), r.y(), r.width(), r.height()); } break; case QVariant::Vector3D: - m_program.setUniformValue(name.constData(), qvariant_cast(v)); + m_program->setUniformValue(name.constData(), qvariant_cast(v)); break; default: break; @@ -558,6 +600,9 @@ static inline int size_of_type(GLenum type) void ShaderEffectItem::bindGeometry() { + if (!m_program) + return; + char const *const *attrNames = m_attributeNames.constData(); int offset = 0; for (int j = 0; j < m_attributeNames.size(); ++j) { @@ -574,7 +619,7 @@ void ShaderEffectItem::bindGeometry() if (normalize) qWarning() << "ShaderEffectItem::bindGeometry() - non supported attribute type!"; - m_program.setAttributeArray(a.position, (GLfloat*) (((char*) m_geometry.vertexData()) + offset), a.tupleSize, m_geometry.stride()); + m_program->setAttributeArray(a.position, (GLfloat*) (((char*) m_geometry.vertexData()) + offset), a.tupleSize, m_geometry.stride()); //glVertexAttribPointer(a.position, a.tupleSize, a.type, normalize, m_geometry.stride(), (char *) m_geometry.vertexData() + offset); offset += a.tupleSize * size_of_type(a.type); } @@ -657,6 +702,16 @@ void ShaderEffectItem::setActive(bool enable) } } + // QGLShaderProgram is deleted when not active (to minimize GPU memory usage). +#ifdef OBSERVE_GL_CONTEXT_LOSS + if (!m_active && m_program) { + delete m_program; + m_program = 0; + delete m_contextObserver; + m_contextObserver = 0; + } +#endif + emit activeChanged(); markDirty(); } @@ -776,7 +831,9 @@ void ShaderEffectItem::reset() { disconnectPropertySignals(); - m_program.removeAllShaders(); + if (m_program) + m_program->removeAllShaders(); + m_attributeNames.clear(); m_uniformNames.clear(); for (int i = 0; i < m_sources.size(); ++i) { @@ -821,6 +878,9 @@ void ShaderEffectItem::updateProperties() void ShaderEffectItem::updateShaderProgram() { + if (!m_program) + return; + QString vertexCode = m_vertex_code; QString fragmentCode = m_fragment_code; @@ -830,16 +890,16 @@ void ShaderEffectItem::updateShaderProgram() if (fragmentCode.isEmpty()) fragmentCode = QString::fromLatin1(qt_default_fragment_code); - m_program.addShaderFromSourceCode(QGLShader::Vertex, vertexCode); - m_program.addShaderFromSourceCode(QGLShader::Fragment, fragmentCode); + m_program->addShaderFromSourceCode(QGLShader::Vertex, vertexCode); + m_program->addShaderFromSourceCode(QGLShader::Fragment, fragmentCode); for (int i = 0; i < m_attributeNames.size(); ++i) { - m_program.bindAttributeLocation(m_attributeNames.at(i), m_geometry.attributes()[i].position); + m_program->bindAttributeLocation(m_attributeNames.at(i), m_geometry.attributes()[i].position); } - if (!m_program.link()) { + if (!m_program->link()) { qWarning("ShaderEffectItem: Shader compilation failed:"); - qWarning() << m_program.log(); + qWarning() << m_program->log(); } if (!m_attributeNames.contains(qt_postion_attribute_name)) @@ -849,10 +909,10 @@ void ShaderEffectItem::updateShaderProgram() if (!m_respectsMatrix) qWarning("ShaderEffectItem: Missing reference to \'qt_ModelViewProjectionMatrix\'."); - if (m_program.isLinked()) { - m_program.bind(); + if (m_program->isLinked()) { + m_program->bind(); for (int i = 0; i < m_sources.size(); ++i) - m_program.setUniformValue(m_sources.at(i).name.constData(), i); + m_program->setUniformValue(m_sources.at(i).name.constData(), (GLint) i); } m_program_dirty = false; diff --git a/src/imports/shaders/shadereffectitem.h b/src/imports/shaders/shadereffectitem.h index aebe897..6c225a2 100644 --- a/src/imports/shaders/shadereffectitem.h +++ b/src/imports/shaders/shadereffectitem.h @@ -115,7 +115,7 @@ private: private: QString m_fragment_code; QString m_vertex_code; - QGLShaderProgram m_program; + QGLShaderProgram* m_program; QVector m_attributeNames; QSet m_uniformNames; QSize m_meshResolution; @@ -143,6 +143,8 @@ private: bool m_hasShaderPrograms : 1; bool m_mirrored : 1; bool m_defaultVertexShader : 1; + + QGLFramebufferObject* m_contextObserver; }; QT_END_HEADER diff --git a/src/imports/shaders/shadereffectsource.cpp b/src/imports/shaders/shadereffectsource.cpp index 6210c41..21d814a 100644 --- a/src/imports/shaders/shadereffectsource.cpp +++ b/src/imports/shaders/shadereffectsource.cpp @@ -170,15 +170,11 @@ void ShaderEffectSource::setSourceRect(const QRectF &rect) return; m_sourceRect = rect; updateSizeAndTexture(); - updateBackbuffer(); emit sourceRectChanged(); emit repaintRequired(); - if (m_sourceItem) { - ShaderEffect* effect = qobject_cast (m_sourceItem->graphicsEffect()); - if (effect) - effect->m_changed = true; - } + m_dirtyTexture = true; + markSourceItemDirty(); } /*! @@ -207,11 +203,8 @@ void ShaderEffectSource::setTextureSize(const QSize &size) emit textureSizeChanged(); emit repaintRequired(); - if (m_sourceItem) { - ShaderEffect* effect = qobject_cast (m_sourceItem->graphicsEffect()); - if (effect) - effect->m_changed = true; - } + m_dirtyTexture = true; + markSourceItemDirty(); } /*! @@ -294,8 +287,10 @@ void ShaderEffectSource::setWrapMode(WrapMode mode) return; m_wrapMode = mode; - updateBackbuffer(); emit wrapModeChanged(); + + m_dirtyTexture = true; + markSourceItemDirty(); } /*! @@ -314,7 +309,7 @@ void ShaderEffectSource::grab() emit repaintRequired(); } -void ShaderEffectSource::bind() const +void ShaderEffectSource::bind() { GLint filtering = smooth() ? GL_LINEAR : GL_NEAREST; GLuint hwrap = (m_wrapMode == Repeat || m_wrapMode == RepeatHorizontally) ? GL_REPEAT : GL_CLAMP_TO_EDGE; @@ -323,9 +318,13 @@ void ShaderEffectSource::bind() const #if !defined(QT_OPENGL_ES_2) glEnable(GL_TEXTURE_2D); #endif - if (m_fbo) { + + if (m_fbo && m_fbo->isValid()) { glBindTexture(GL_TEXTURE_2D, m_fbo->texture()); } else { + m_dirtyTexture = true; + emit repaintRequired(); + markSourceItemDirty(); glBindTexture(GL_TEXTURE_2D, 0); } @@ -354,7 +353,7 @@ void ShaderEffectSource::derefFromEffectItem() void ShaderEffectSource::updateBackbuffer() { - if (!m_sourceItem) + if (!m_sourceItem || !QGLContext::currentContext()) return; // Multisampling is not (for now) supported. @@ -370,7 +369,7 @@ void ShaderEffectSource::updateBackbuffer() if (!m_fbo) { m_fbo = new ShaderEffectBuffer(size, format); } else { - if (m_fbo->size() != size || m_fbo->format().internalTextureFormat() != GLenum(m_format)) { + if (!m_fbo->isValid() || m_fbo->size() != size || m_fbo->format().internalTextureFormat() != GLenum(m_format)) { delete m_fbo; m_fbo = 0; m_fbo = new ShaderEffectBuffer(size, format); @@ -397,6 +396,16 @@ void ShaderEffectSource::markSourceSizeDirty() emit repaintRequired(); } +void ShaderEffectSource::markSourceItemDirty() +{ + m_dirtyTexture = true; + if (m_sourceItem) { + ShaderEffect* effect = qobject_cast (m_sourceItem->graphicsEffect()); + if (effect) + effect->m_changed = true; + } +} + void ShaderEffectSource::updateSizeAndTexture() { if (m_sourceItem) { @@ -407,7 +416,7 @@ void ShaderEffectSource::updateSizeAndTexture() size.setWidth(1); if (size.height() < 1) size.setHeight(1); - if (m_fbo && m_fbo->size() != size) { + if (m_fbo && (m_fbo->size() != size || !m_fbo->isValid())) { delete m_fbo; m_fbo = 0; delete m_multisampledFbo; diff --git a/src/imports/shaders/shadereffectsource.h b/src/imports/shaders/shadereffectsource.h index 0f03a6a..af8a815 100644 --- a/src/imports/shaders/shadereffectsource.h +++ b/src/imports/shaders/shadereffectsource.h @@ -99,7 +99,7 @@ public: void setWrapMode(WrapMode mode); bool isActive() const { return m_refs; } - void bind() const; + void bind(); void refFromEffectItem(); void derefFromEffectItem(); void updateBackbuffer(); @@ -124,6 +124,7 @@ Q_SIGNALS: public Q_SLOTS: void markSceneGraphDirty(); void markSourceSizeDirty(); + void markSourceItemDirty(); private: void updateSizeAndTexture(); -- cgit v0.12 From c691fc126a61a6153628a176d4375dd7ac76c0e1 Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Thu, 25 Aug 2011 11:11:28 +0300 Subject: QS60Style omits drawing theme background in some Symbian SDKs Latest internal RnD releases have upgraded Symbian version to 5.4. As QS60Style was not aware of this, all the textures that didn't define any version information (i.e. available in all versions) were not drawn at all. Task-number: QT-5176 Reviewed-by: Miikka Heikkinen --- src/gui/styles/qs60style_s60.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/gui/styles/qs60style_s60.cpp b/src/gui/styles/qs60style_s60.cpp index 67181af..f1cf2f6 100644 --- a/src/gui/styles/qs60style_s60.cpp +++ b/src/gui/styles/qs60style_s60.cpp @@ -91,6 +91,7 @@ enum TSupportRelease { ES60_5_1 = 0x0008, ES60_5_2 = 0x0010, ES60_5_3 = 0x0020, + ES60_5_4 = 0x0040, ES60_3_X = ES60_3_1 | ES60_3_2, // Releases before Symbian Foundation ES60_PreSF = ES60_3_1 | ES60_3_2 | ES60_5_0, @@ -98,8 +99,10 @@ enum TSupportRelease { ES60_Pre52 = ES60_3_1 | ES60_3_2 | ES60_5_0 | ES60_5_1, // Releases before S60 5.3 ES60_Pre53 = ES60_3_1 | ES60_3_2 | ES60_5_0 | ES60_5_1 | ES60_5_2, + // Releases before S60 5.4 + ES60_Pre54 = ES60_3_1 | ES60_3_2 | ES60_5_0 | ES60_5_1 | ES60_5_2 | ES60_5_3, // Add all new releases here - ES60_All = ES60_3_1 | ES60_3_2 | ES60_5_0 | ES60_5_1 | ES60_5_2 | ES60_5_3 + ES60_All = ES60_3_1 | ES60_3_2 | ES60_5_0 | ES60_5_1 | ES60_5_2 | ES60_5_3 | ES60_5_4 }; typedef struct { @@ -1264,7 +1267,8 @@ bool QS60StyleModeSpecifics::checkSupport(const int supportedRelease) (currentRelease == QSysInfo::SV_S60_5_0 && supportedRelease & ES60_5_0) || (currentRelease == QSysInfo::SV_S60_5_1 && supportedRelease & ES60_5_1) || (currentRelease == QSysInfo::SV_S60_5_2 && supportedRelease & ES60_5_2) || - (currentRelease == QSysInfo::SV_S60_5_3 && supportedRelease & ES60_5_3) ); + (currentRelease == QSysInfo::SV_S60_5_3 && supportedRelease & ES60_5_3) || + (currentRelease == QSysInfo::SV_S60_5_4 && supportedRelease & ES60_5_4) ); } TAknsItemID QS60StyleModeSpecifics::partSpecificThemeId(int part) -- cgit v0.12 From 338346ceae99ec0d8f7227af12333d63393992be Mon Sep 17 00:00:00 2001 From: Sami Merila Date: Thu, 25 Aug 2011 14:21:30 +0300 Subject: Crash when creating scroll bar skin graphics on S60 (debug only) When fetching bitmap graphics from native without fallback information, do not define fallback-mif file, since native side uses ASSERT_DEBUG to crash the client if file info exists, but bitmap ID is not defined. This started crashing when root theme removed default scrollbar graphics from its content for Belle release. Task-number: QTBUG-15993 Reviewed-by: Miikka Heikkinen --- src/gui/styles/qs60style_s60.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/gui/styles/qs60style_s60.cpp b/src/gui/styles/qs60style_s60.cpp index f1cf2f6..2051362 100644 --- a/src/gui/styles/qs60style_s60.cpp +++ b/src/gui/styles/qs60style_s60.cpp @@ -711,7 +711,7 @@ QPixmap QS60StyleModeSpecifics::colorSkinnedGraphicsLX( colorIndex, icon, iconMask, - AknIconUtils::AvkonIconFileName(), + (fallbackGraphicID != KErrNotFound ? AknIconUtils::AvkonIconFileName() : KNullDesC), fallbackGraphicID, fallbackGraphicsMaskID, defaultColor); @@ -949,7 +949,7 @@ QPixmap QS60StyleModeSpecifics::createSkinnedGraphicsLX( skinId, icon, iconMask, - AknIconUtils::AvkonIconFileName(), + (fallbackGraphicID != KErrNotFound ? AknIconUtils::AvkonIconFileName() : KNullDesC), fallbackGraphicID , fallbackGraphicsMaskID); @@ -1043,7 +1043,7 @@ QPixmap QS60StyleModeSpecifics::createSkinnedGraphicsLX( KAknsIIDDefault, //animation is not themed, lets force fallback graphics animationFrame, frameMask, - AknIconUtils::AvkonIconFileName(), + (fallbackGraphicID != KErrNotFound ? AknIconUtils::AvkonIconFileName() : KNullDesC), fallbackGraphicID , fallbackGraphicsMaskID); } -- cgit v0.12 From a4eae8a44ca38739755ba8994251e2b120878ec8 Mon Sep 17 00:00:00 2001 From: mread Date: Fri, 26 Aug 2011 12:07:31 +0100 Subject: Fixed use of deleted object in XmlPatterns EvaluationCache This problem was shown up by the Ilta-Sanomat QML app on Symbian. Changes to the EvaluationCache class in 23267553627ac3c4cbcd918283bee8e665deeff9 meant that it was now trying to access the declaration object after it had been deleted. This change takes the data needed from the declaration object (1 bool) and stores that instead Task-number: QTTH-1492 Reviewed-by: Honglei Zhang --- src/xmlpatterns/expr/qevaluationcache.cpp | 5 ++--- src/xmlpatterns/expr/qevaluationcache_p.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/xmlpatterns/expr/qevaluationcache.cpp b/src/xmlpatterns/expr/qevaluationcache.cpp index 67109eb..3b6fc92 100644 --- a/src/xmlpatterns/expr/qevaluationcache.cpp +++ b/src/xmlpatterns/expr/qevaluationcache.cpp @@ -49,10 +49,9 @@ template EvaluationCache::EvaluationCache(const Expression::Ptr &op, const VariableDeclaration *varDecl, const VariableSlotID aSlot) : SingleContainer(op) - , m_declaration(varDecl) + , m_declarationUsedByMany(varDecl->usedByMany()) , m_varSlot(aSlot) { - Q_ASSERT(m_declaration); Q_ASSERT(m_varSlot > -1); } @@ -199,7 +198,7 @@ Expression::Ptr EvaluationCache::compress(const StaticContext::Ptr if(m_operand->is(IDRangeVariableReference)) return m_operand; - if(m_declaration->usedByMany()) + if (m_declarationUsedByMany) { /* If it's only an atomic value an EvaluationCache is overkill. However, * it's still needed for functions like fn:current-time() that must adhere to diff --git a/src/xmlpatterns/expr/qevaluationcache_p.h b/src/xmlpatterns/expr/qevaluationcache_p.h index 6080157..77d9c11 100644 --- a/src/xmlpatterns/expr/qevaluationcache_p.h +++ b/src/xmlpatterns/expr/qevaluationcache_p.h @@ -124,7 +124,7 @@ namespace QPatternist private: static DynamicContext::Ptr topFocusContext(const DynamicContext::Ptr &context); - const VariableDeclaration *m_declaration; + bool m_declarationUsedByMany; /** * This variable must not be called m_slot. If it so, a compiler bug on * HP-UX-aCC-64 is triggered in the constructor initializor. See the -- cgit v0.12