From 708fcbe457304ac8035c20302e6dc6628a0f6aa4 Mon Sep 17 00:00:00 2001 From: Jani Hautakangas Date: Thu, 12 May 2011 13:54:46 +0300 Subject: Fix for rounded corners bug in QMenu Currently QMenus have opaque black corners in cases where theme supports rounded corners. This patch fixes it by setting WA_TranslucentBackground flag to QMenu widget. Task-number: QTBUG-16857 Reviewed-by: Sami Merila --- src/gui/widgets/qmenu.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index 2f4bb4b..d573ebf 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -82,6 +82,10 @@ # include #endif +#ifdef Q_WS_S60 +# include "private/qt_s60_p.h" +#endif + QT_BEGIN_NAMESPACE @@ -172,6 +176,14 @@ void QMenuPrivate::init() q->addAction(selectAction); q->addAction(cancelAction); #endif + +#ifdef Q_WS_S60 + if (S60->avkonComponentsSupportTransparency) { + bool noSystemBackground = q->testAttribute(Qt::WA_NoSystemBackground); + q->setAttribute(Qt::WA_TranslucentBackground); // also sets WA_NoSystemBackground + q->setAttribute(Qt::WA_NoSystemBackground, noSystemBackground); // restore system background attribute + } +#endif } int QMenuPrivate::scrollerHeight() const -- cgit v0.12 From b7b9a22ce263fcb430ff4228fb88ca5229a6e226 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Thu, 12 May 2011 14:10:56 +0200 Subject: Clear confusion between QMainWindow and QMainWindowLayout. The variables activateUnifiedToolbarAfterFullScreen and useHIToolBar were implemented in both classes. This was an obvious bug, where variable would be initialized in one class and use in the other one. Task-number: QTBUG-18874 Reviewed-by: Yoann Lopes (cherry picked from commit 15a5eaf0eeb44833a052b6201171fca4b9e8f74e) --- src/gui/widgets/qmainwindow.cpp | 2 -- src/gui/widgets/qmainwindowlayout.cpp | 1 + src/gui/widgets/qmainwindowlayout_p.h | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/gui/widgets/qmainwindow.cpp b/src/gui/widgets/qmainwindow.cpp index d8f8e91..0db5bba 100644 --- a/src/gui/widgets/qmainwindow.cpp +++ b/src/gui/widgets/qmainwindow.cpp @@ -78,7 +78,6 @@ public: : layout(0), explicitIconSize(false), toolButtonStyle(Qt::ToolButtonIconOnly) #ifdef Q_WS_MAC , useHIToolBar(false) - , activateUnifiedToolbarAfterFullScreen(false) #endif #if !defined(QT_NO_DOCKWIDGET) && !defined(QT_NO_CURSOR) , hasOldCursor(false) , cursorAdjusted(false) @@ -90,7 +89,6 @@ public: Qt::ToolButtonStyle toolButtonStyle; #ifdef Q_WS_MAC bool useHIToolBar; - bool activateUnifiedToolbarAfterFullScreen; #endif void init(); QList hoverSeparator; diff --git a/src/gui/widgets/qmainwindowlayout.cpp b/src/gui/widgets/qmainwindowlayout.cpp index 6bc07e1..51267c1 100644 --- a/src/gui/widgets/qmainwindowlayout.cpp +++ b/src/gui/widgets/qmainwindowlayout.cpp @@ -1695,6 +1695,7 @@ QMainWindowLayout::QMainWindowLayout(QMainWindow *mainwindow, QLayout *parentLay , gapIndicator(new QRubberBand(QRubberBand::Rectangle, mainwindow)) #endif //QT_NO_RUBBERBAND #ifdef Q_WS_MAC + , activateUnifiedToolbarAfterFullScreen(false) , blockVisiblityCheck(false) #endif { diff --git a/src/gui/widgets/qmainwindowlayout_p.h b/src/gui/widgets/qmainwindowlayout_p.h index 489e913..289a49c 100644 --- a/src/gui/widgets/qmainwindowlayout_p.h +++ b/src/gui/widgets/qmainwindowlayout_p.h @@ -334,7 +334,6 @@ public: void removeFromMacToolbar(QToolBar *toolbar); void cleanUpMacToolbarItems(); void fixSizeInUnifiedToolbar(QToolBar *tb) const; - bool useHIToolBar; bool activateUnifiedToolbarAfterFullScreen; void syncUnifiedToolbarVisibility(); bool blockVisiblityCheck; -- cgit v0.12 From f69e465e15930ef02dceba7175eed6f3f1df070e Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Fri, 13 May 2011 13:49:20 +1000 Subject: Make TextEdit word selection more natural. QTextControl will only extend the selection to a word if the cursor is directly over it which prevents the selection being extended if the mouse is dragged up or down a to a shorter line of text making it difficult to select multiple lines of text. Just disable that limitation when the TextEdit word selection is enabled. Change-Id: I3b9d1575c0141db8441197d740de94a90eacc077 Task-number: QTBUG-19230 Reviewed-by: Martin Jones --- src/gui/text/qtextcontrol.cpp | 2 +- .../data/mouseselection_multiline.qml | 8 +++++ .../tst_qdeclarativetextedit.cpp | 36 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/auto/declarative/qdeclarativetextedit/data/mouseselection_multiline.qml diff --git a/src/gui/text/qtextcontrol.cpp b/src/gui/text/qtextcontrol.cpp index cf8e313..88e0573 100644 --- a/src/gui/text/qtextcontrol.cpp +++ b/src/gui/text/qtextcontrol.cpp @@ -676,7 +676,7 @@ void QTextControlPrivate::extendWordwiseSelection(int suggestedNewPosition, qrea const qreal wordEndX = line.cursorToX(curs.position() - blockPos) + blockCoordinates.x(); - if (mouseXPosition < wordStartX || mouseXPosition > wordEndX) + if (!wordSelectionEnabled && (mouseXPosition < wordStartX || mouseXPosition > wordEndX)) return; // keep the already selected word even when moving to the left diff --git a/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_multiline.qml b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_multiline.qml new file mode 100644 index 0000000..af23f6d --- /dev/null +++ b/tests/auto/declarative/qdeclarativetextedit/data/mouseselection_multiline.qml @@ -0,0 +1,8 @@ +import QtQuick 1.1 + +TextEdit { + focus: true + text: "0123456789ABCDEFGHIJKLMNOPQRS\nTUVWXYZ" + selectByMouse: true + mouseSelectionMode: TextInput.SelectWords +} diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index 7bbef21..f8af433 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -119,6 +119,7 @@ private slots: void moveCursorSelectionSequence(); void mouseSelection_data(); void mouseSelection(); + void multilineMouseSelection(); void deferEnableSelectByMouse_data(); void deferEnableSelectByMouse(); void deferDisableSelectByMouse_data(); @@ -1364,6 +1365,41 @@ void tst_qdeclarativetextedit::mouseSelection() delete canvas; } +void tst_qdeclarativetextedit::multilineMouseSelection() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/mouseselection_multiline.qml"); + + 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 from x1,y1 to x2,y1 + int x1 = 10; + int x2 = textEditObject->width() - 10; + int y1 = textEditObject->height() / 4; + int y2 = textEditObject->height() * 3 / 4; + QTest::mousePress(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x1,y1))); + QMouseEvent mv1(QEvent::MouseMove, canvas->mapFromScene(QPoint(x2,y1)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + QApplication::sendEvent(canvas->viewport(), &mv1); + QString str1 = textEditObject->selectedText(); + QVERIFY(str1.length() > 3); // don't reallly care *what* was selected (and it's too sensitive to platform) + + // drag-and-release from x2,y1 to x2,y2 + QMouseEvent mv2(QEvent::MouseMove, canvas->mapFromScene(QPoint(x2,y2)), Qt::LeftButton, Qt::LeftButton,Qt::NoModifier); + QApplication::sendEvent(canvas->viewport(), &mv2); + QTest::mouseRelease(canvas->viewport(), Qt::LeftButton, 0, canvas->mapFromScene(QPoint(x2,y2))); + QString str2 = textEditObject->selectedText(); + QVERIFY(str1 != str2); + QVERIFY(str2.length() > 3); + + delete canvas; +} + void tst_qdeclarativetextedit::deferEnableSelectByMouse_data() { QTest::addColumn("qmlfile"); -- cgit v0.12 From 576d577438f1193bbc934e904b809d5b23b8d54e Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 13 May 2011 15:28:30 +1000 Subject: ListViews loses items if all visible items are removed. Occurs when at end of list and all visible items are removed in multiple steps, without entering the event loop. We were not updating visibleIndex if there were no visible items when handling itemsRemoved(). Also avoid skipping items in refill if there are no valid visible items for reference. Change-Id: I2ff58fb191f6b053f33d5446220d597eb15b66d4 Task-number: QTBUG-19198 Reviewed-by: Bea Lam --- src/declarative/graphicsitems/qdeclarativelistview.cpp | 11 +++++++---- .../qdeclarativelistview/tst_qdeclarativelistview.cpp | 10 ++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index cb40384..79d67e7 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -733,6 +733,7 @@ void QDeclarativeListViewPrivate::refill(qreal from, qreal to, bool doBuffer) if (doBuffer && (bufferMode & BufferBefore)) fillFrom = bufferFrom; + bool haveValidItems = false; int modelIndex = visibleIndex; qreal itemEnd = visiblePos-1; if (!visibleItems.isEmpty()) { @@ -741,11 +742,13 @@ void QDeclarativeListViewPrivate::refill(qreal from, qreal to, bool doBuffer) int i = visibleItems.count() - 1; while (i > 0 && visibleItems.at(i)->index == -1) --i; - if (visibleItems.at(i)->index != -1) + if (visibleItems.at(i)->index != -1) { + haveValidItems = true; modelIndex = visibleItems.at(i)->index + 1; + } } - if (visibleItems.count() && (fillFrom > itemEnd+averageSize+spacing + if (haveValidItems && (fillFrom > itemEnd+averageSize+spacing || fillTo < visiblePos - averageSize - spacing)) { // We've jumped more than a page. Estimate which items are now // visible and fill from there. @@ -3406,9 +3409,9 @@ void QDeclarativeListView::itemsRemoved(int modelIndex, int count) } } - if (removedVisible && !haveVisibleIndex) { + if (!haveVisibleIndex) { d->timeline.clear(); - if (d->itemCount == 0) { + if (removedVisible && d->itemCount == 0) { d->visibleIndex = 0; d->visiblePos = d->header ? d->header->size() : 0; d->setPosition(0); diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index 8b90030..23ac523 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -714,6 +714,16 @@ void tst_QDeclarativeListView::removed(bool animated) QTRY_VERIFY(name = findItem(contentItem, "textName", model.count()-1)); QCOMPARE(name->text(), QString("New")); + // Add some more items so that we don't run out + for (int i = 50; i < 100; i++) + model.addItem("Item" + QString::number(i), ""); + + // QTBUG-19198 move to end and remove all visible items one at a time. + listview->positionViewAtEnd(); + for (int i = 0; i < 18; ++i) + model.removeItems(model.count() - 1, 1); + QTRY_VERIFY(findItems(contentItem, "wrapper").count() > 16); + delete canvas; } -- cgit v0.12 From 80db0a1e59658f9e445219fc48d9236a79edca72 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Fri, 13 May 2011 17:01:28 +1000 Subject: QDeclarativeMouseArea: block context menu events If the MouseArea accepts the same button used to trigger a context menu event, it should not let the event to be delivered to item behind. This is important for items that do implement contextMenuEvent(), like QDeclarativeWebView. When there's a mouse area on top of this item and that accepts the right click (in Linux), the event was still being delivered and the WebView menu was incorrectly appearing. QtWebKit bug https://bugs.webkit.org/show_bug.cgi?id=56526 documents this problem. Change-Id: I386fac6c96f47b8616e2eeb7e5f97043ba418980 Merge-request: 1185 Reviewed-by: Martin Jones --- .../graphicsitems/qdeclarativemousearea.cpp | 26 +++++++++ .../graphicsitems/qdeclarativemousearea_p.h | 3 ++ .../data/preventContextMenu.qml | 22 ++++++++ .../tst_qdeclarativemousearea.cpp | 63 ++++++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 tests/auto/declarative/qdeclarativemousearea/data/preventContextMenu.qml diff --git a/src/declarative/graphicsitems/qdeclarativemousearea.cpp b/src/declarative/graphicsitems/qdeclarativemousearea.cpp index d4e7f7b..6633256 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea.cpp +++ b/src/declarative/graphicsitems/qdeclarativemousearea.cpp @@ -660,6 +660,32 @@ void QDeclarativeMouseArea::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) setHovered(false); } +#ifndef QT_NO_CONTEXTMENU +void QDeclarativeMouseArea::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) +{ + bool acceptsContextMenuButton; +#if defined(Q_OS_SYMBIAN) + // In Symbian a Long Tap on the screen will trigger. See QSymbianControl::HandleLongTapEventL(). + acceptsContextMenuButton = acceptedButtons() & Qt::LeftButton; +#elif defined(Q_WS_WINCE) + // ### WinCE can trigger context menu event with a gesture in the left button or a + // click with the right button. Since we have no way here to differentiate them when + // event happens, accepting either of the them will block the event. + acceptsContextMenuButton = acceptedButtons() & (Qt::LeftButton | Qt::RightButton); +#else + acceptsContextMenuButton = acceptedButtons() & Qt::RightButton; +#endif + + if (isEnabled() && event->reason() == QGraphicsSceneContextMenuEvent::Mouse + && acceptsContextMenuButton) { + // Do not let the context menu event propagate to items behind. + return; + } + + QDeclarativeItem::contextMenuEvent(event); +} +#endif // QT_NO_CONTEXTMENU + bool QDeclarativeMouseArea::sceneEvent(QEvent *event) { bool rv = QDeclarativeItem::sceneEvent(event); diff --git a/src/declarative/graphicsitems/qdeclarativemousearea_p.h b/src/declarative/graphicsitems/qdeclarativemousearea_p.h index 351d4de..0fe8c6a 100644 --- a/src/declarative/graphicsitems/qdeclarativemousearea_p.h +++ b/src/declarative/graphicsitems/qdeclarativemousearea_p.h @@ -190,6 +190,9 @@ protected: void hoverEnterEvent(QGraphicsSceneHoverEvent *event); void hoverMoveEvent(QGraphicsSceneHoverEvent *event); void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); +#ifndef QT_NO_CONTEXTMENU + void contextMenuEvent(QGraphicsSceneContextMenuEvent *event); +#endif // QT_NO_CONTEXTMENU bool sceneEvent(QEvent *); bool sendMouseEvent(QGraphicsSceneMouseEvent *event); bool sceneEventFilter(QGraphicsItem *i, QEvent *e); diff --git a/tests/auto/declarative/qdeclarativemousearea/data/preventContextMenu.qml b/tests/auto/declarative/qdeclarativemousearea/data/preventContextMenu.qml new file mode 100644 index 0000000..dcbb5d7 --- /dev/null +++ b/tests/auto/declarative/qdeclarativemousearea/data/preventContextMenu.qml @@ -0,0 +1,22 @@ +import QtQuick 1.1 +import Test 1.0 + +Item { + width: 200 + height: 200 + + property alias mouseAreaEnabled: mouseArea.enabled + property alias eventsReceived: receiver.eventCount + + ContextMenuEventReceiver { + id: receiver + anchors.fill: parent + } + + MouseArea { + id: mouseArea + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.MiddleButton | Qt.RightButton + enabled: true + } +} diff --git a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp index e1c34fc..fea7865 100644 --- a/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp +++ b/tests/auto/declarative/qdeclarativemousearea/tst_qdeclarativemousearea.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #ifdef Q_OS_SYMBIAN // In Symbian OS test data is located in applications private dir @@ -70,6 +71,9 @@ private slots: void preventStealing(); void testQtQuick11Attributes(); void testQtQuick11Attributes_data(); +#ifndef QT_NO_CONTEXTMENU + void preventContextMenu(); +#endif // QT_NO_CONTEXTMENU private: QDeclarativeView *createView(); @@ -637,6 +641,65 @@ void tst_QDeclarativeMouseArea::testQtQuick11Attributes_data() << ":1 \"MouseArea.preventStealing\" is not available in QtQuick 1.0.\n"; } +#ifndef QT_NO_CONTEXTMENU +class ContextMenuEventReceiver : public QDeclarativeItem +{ + Q_OBJECT + Q_PROPERTY(int eventCount READ eventCount NOTIFY eventCountChanged); +public: + ContextMenuEventReceiver(QDeclarativeItem *parent = 0) : QDeclarativeItem(parent), m_eventCount(0) { } + int eventCount() const { return m_eventCount; } +signals: + void eventCountChanged(int); +protected: + void contextMenuEvent(QGraphicsSceneContextMenuEvent *event) { + if (event->reason() == QGraphicsSceneContextMenuEvent::Mouse) { + m_eventCount++; + emit eventCountChanged(m_eventCount); + } + } +private: + int m_eventCount; +}; + +void tst_QDeclarativeMouseArea::preventContextMenu() +{ + // A MouseArea accepting Left, Middle and Right buttons should prevent context menu + // events with "Mouse" reason to hit the Item below. + + qmlRegisterType("Test", 1, 0, "ContextMenuEventReceiver"); + + QDeclarativeView *view = createView(); + view->setSource(QUrl::fromLocalFile(SRCDIR "/data/preventContextMenu.qml")); + view->show(); + QVERIFY(view->rootObject() != 0); + + QDeclarativeProperty mouseAreaEnabled(view->rootObject(), "mouseAreaEnabled"); + QVERIFY(mouseAreaEnabled.read().toBool()); + + QDeclarativeProperty eventsReceived(view->rootObject(), "eventsReceived"); + QCOMPARE(eventsReceived.read().toInt(), 0); + + QPoint targetPoint = view->mapFromScene(QPoint(80, 80)); + + QContextMenuEvent fakeEvent1(QContextMenuEvent::Mouse, targetPoint); + QApplication::sendEvent(view->viewport(), &fakeEvent1); + QCOMPARE(eventsReceived.read().toInt(), 0); + + mouseAreaEnabled.write(false); + QVERIFY(!mouseAreaEnabled.read().toBool()); + QContextMenuEvent fakeEvent2(QContextMenuEvent::Mouse, targetPoint); + QApplication::sendEvent(view->viewport(), &fakeEvent2); + QCOMPARE(eventsReceived.read().toInt(), 1); + + mouseAreaEnabled.write(true); + QVERIFY(mouseAreaEnabled.read().toBool()); + QContextMenuEvent fakeEvent3(QContextMenuEvent::Mouse, targetPoint); + QApplication::sendEvent(view->viewport(), &fakeEvent3); + QCOMPARE(eventsReceived.read().toInt(), 1); +} +#endif // QT_NO_CONTEXTMENU + QTEST_MAIN(tst_QDeclarativeMouseArea) #include "tst_qdeclarativemousearea.moc" -- cgit v0.12