From 2ef40cee608ddc57a5bfc4ceb91c149b526fe53a Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Wed, 25 Nov 2009 13:27:36 -0300 Subject: QGAL: default spacing can be unset using a negative value After a default spacing is set through QGAL::setSpacing() family of methods, the user must be able to unset it. To avoid adding another public method, we enabled this feature by allowing a negative value to be passed to those methods. Signed-off-by: Eduardo M. Fleury Reviewed-by: Anselmo Lacerda S. de Melo --- src/gui/graphicsview/qgraphicsanchorlayout.cpp | 23 ++---------- .../tst_qgraphicsanchorlayout.cpp | 41 ++++++++++++++++++++++ 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp index 7e5929e..686096c 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp @@ -370,12 +370,6 @@ void QGraphicsAnchorLayout::setHorizontalSpacing(qreal spacing) { Q_D(QGraphicsAnchorLayout); - // ### We don't support negative spacing yet - if (spacing < 0) { - spacing = 0; - qWarning() << "QGraphicsAnchorLayout does not support negative spacing."; - } - d->spacings[0] = spacing; invalidate(); } @@ -389,12 +383,6 @@ void QGraphicsAnchorLayout::setVerticalSpacing(qreal spacing) { Q_D(QGraphicsAnchorLayout); - // ### We don't support negative spacing yet - if (spacing < 0) { - spacing = 0; - qWarning() << "QGraphicsAnchorLayout does not support negative spacing."; - } - d->spacings[1] = spacing; invalidate(); } @@ -405,7 +393,8 @@ void QGraphicsAnchorLayout::setVerticalSpacing(qreal spacing) If an item is anchored with no spacing associated with the anchor, it will use the default spacing. - Currently QGraphicsAnchorLayout does not support negative default spacings. + QGraphicsAnchorLayout does not support negative spacings. Setting a negative value will unset the + previous spacing and make the layout use the spacing provided by the current widget style. \sa setHorizontalSpacing(), setVerticalSpacing() */ @@ -413,14 +402,6 @@ void QGraphicsAnchorLayout::setSpacing(qreal spacing) { Q_D(QGraphicsAnchorLayout); - // ### Currently we do not support negative anchors inside the graph. - // To avoid those being created by a negative spacing, we must - // make this test. - if (spacing < 0) { - spacing = 0; - qWarning() << "QGraphicsAnchorLayout does not support negative spacing."; - } - d->spacings[0] = d->spacings[1] = spacing; invalidate(); } diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index e2f87b8..aa67ac5 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -88,6 +88,7 @@ private slots: void spacingPersistency(); void snakeParallelWithLayout(); void parallelToHalfLayout(); + void globalSpacing(); }; class RectWidget : public QGraphicsWidget @@ -1976,5 +1977,45 @@ void tst_QGraphicsAnchorLayout::parallelToHalfLayout() QCOMPARE(maximumSizeHint, QSizeF(400, 100) + overhead); } +void tst_QGraphicsAnchorLayout::globalSpacing() +{ + QGraphicsWidget *a = createItem(); + QGraphicsWidget *b = createItem(); + + QGraphicsWidget w; + QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(&w); + + l->addCornerAnchors(l, Qt::TopLeftCorner, a, Qt::TopLeftCorner); + l->addCornerAnchors(a, Qt::BottomRightCorner, b, Qt::TopLeftCorner); + l->addCornerAnchors(b, Qt::BottomRightCorner, l, Qt::BottomRightCorner); + + w.resize(w.effectiveSizeHint(Qt::PreferredSize)); + qreal vSpacing = b->geometry().top() - a->geometry().bottom(); + qreal hSpacing = b->geometry().left() - a->geometry().right(); + + // Set spacings manually + l->setVerticalSpacing(vSpacing + 10); + l->setHorizontalSpacing(hSpacing + 5); + + w.resize(w.effectiveSizeHint(Qt::PreferredSize)); + qreal newVSpacing = b->geometry().top() - a->geometry().bottom(); + qreal newHSpacing = b->geometry().left() - a->geometry().right(); + + QCOMPARE(newVSpacing, vSpacing + 10); + QCOMPARE(newHSpacing, hSpacing + 5); + + // Set a negative spacing. This will unset the previous spacing and + // bring back the widget-defined spacing. + l->setSpacing(-1); + + w.resize(w.effectiveSizeHint(Qt::PreferredSize)); + newVSpacing = b->geometry().top() - a->geometry().bottom(); + newHSpacing = b->geometry().left() - a->geometry().right(); + + QCOMPARE(newVSpacing, vSpacing); + QCOMPARE(newHSpacing, hSpacing); +} + + QTEST_MAIN(tst_QGraphicsAnchorLayout) #include "tst_qgraphicsanchorlayout.moc" -- cgit v0.12 From a8893f8d17d37ac4a68fc2cf0bdec1c3b124c8f4 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Fri, 27 Nov 2009 14:52:21 -0300 Subject: QGAL (Test): Add QGraphicsAnchor handling test This test ensures that internal anchors are not exposed through the QGAL::anchor() API and also that the QGraphicsAnchors are deleted when the associated anchors are deleted internally. Signed-off-by: Eduardo M. Fleury Reviewed-by: Artur Duque de Souza --- .../tst_qgraphicsanchorlayout.cpp | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index aa67ac5..a7297c9 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -89,6 +89,7 @@ private slots: void snakeParallelWithLayout(); void parallelToHalfLayout(); void globalSpacing(); + void graphicsAnchorHandling(); }; class RectWidget : public QGraphicsWidget @@ -2016,6 +2017,42 @@ void tst_QGraphicsAnchorLayout::globalSpacing() QCOMPARE(newHSpacing, hSpacing); } +void tst_QGraphicsAnchorLayout::graphicsAnchorHandling() +{ + QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(); + QGraphicsWidget *a = createItem(); + + l->addAnchors(l, a); + + QGraphicsAnchor *layoutAnchor = l->anchor(l, Qt::AnchorTop, l, Qt::AnchorBottom); + QGraphicsAnchor *itemAnchor = l->anchor(a, Qt::AnchorTop, a, Qt::AnchorBottom); + QGraphicsAnchor *invalidAnchor = l->anchor(a, Qt::AnchorTop, l, Qt::AnchorBottom); + + // Ensure none of these anchors are accessible. + QVERIFY(layoutAnchor == 0); + QVERIFY(itemAnchor == 0); + QVERIFY(invalidAnchor == 0); + + // Hook the anchors to a QObject + QObject object; + QGraphicsAnchor *userAnchor = l->anchor(l, Qt::AnchorTop, a, Qt::AnchorTop); + userAnchor->setParent(&object); + userAnchor = l->anchor(l, Qt::AnchorBottom, a, Qt::AnchorBottom); + userAnchor->setParent(&object); + userAnchor = l->anchor(l, Qt::AnchorRight, a, Qt::AnchorRight); + userAnchor->setParent(&object); + userAnchor = l->anchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); + userAnchor->setParent(&object); + + QCOMPARE(object.children().size(), 4); + + // Delete layout, this will cause all anchors to be deleted internally. + // We expect the public QGraphicsAnchor instances to be deleted too. + delete l; + QCOMPARE(object.children().size(), 0); + + delete a; +} QTEST_MAIN(tst_QGraphicsAnchorLayout) #include "tst_qgraphicsanchorlayout.moc" -- cgit v0.12 From 5b9d7f05aa369c07c2f498280d8a8b9c81f7aff1 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Fri, 27 Nov 2009 11:14:23 -0300 Subject: QGAL: Prevent internal anchors from being exposed by QGAL::anchor() Adding check to prevent the structural layout anchors as well as those internal to items, from being exposed through the public API. These checks also ensure no QGraphicsAnchor instances will be created for those anchors. Signed-off-by: Eduardo M. Fleury Reviewed-by: Artur Duque de Souza --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index a6f5992..137806a 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -1652,6 +1652,10 @@ QGraphicsAnchor *QGraphicsAnchorLayoutPrivate::getAnchor(QGraphicsLayoutItem *fi QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge) { + // Do not expose internal anchors + if (firstItem == secondItem) + return 0; + const Orientation orientation = edgeOrientation(firstEdge); AnchorVertex *v1 = internalVertex(firstItem, firstEdge); AnchorVertex *v2 = internalVertex(secondItem, secondEdge); @@ -1659,8 +1663,16 @@ QGraphicsAnchor *QGraphicsAnchorLayoutPrivate::getAnchor(QGraphicsLayoutItem *fi QGraphicsAnchor *graphicsAnchor = 0; AnchorData *data = graph[orientation].edgeData(v1, v2); - if (data) - graphicsAnchor = acquireGraphicsAnchor(data); + if (data) { + // We could use "acquireGraphicsAnchor" here, but to avoid a regression where + // an internal anchor was wrongly exposed, I want to ensure no new + // QGraphicsAnchor instances are created by this call. + // This assumption must hold because anchors are either user-created (and already + // have their public object created), or they are internal (and must not reach + // this point). + Q_ASSERT(data->graphicsAnchor); + graphicsAnchor = data->graphicsAnchor; + } return graphicsAnchor; } -- cgit v0.12 From b70256432c2393afb5686c9ef61e38ff399be954 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Fri, 27 Nov 2009 15:38:48 -0300 Subject: QGAL: Fix memory management issues (leak + invalid read) Fixing QGraphicsAnchor memory leak and access to free'd region. -- Leak: User-created anchors have two representations in QGAL, one visible externally (QGraphicsAnchor) and other internal (AnchorData). When such anchors are removed externally (QGraphicsAnchor is deleted), the former implementation ensured that the internal representation would be deleted too. However the opposite was not true. In cases where the anchors are deleted internally (in the layout destructor, for instance, or when an item is removed through the removeAt API), the public QGraphicsAnchor object would leak. This commit ensures the deletion will happen in both directions and adds protection to avoid a deletion loop. -- Invalid read: In QGAL::removeAnchor(vertex1, vertex2), we read vertex information after calling removeAnchor_helper(vertex1, vertex2). The problem is that in cases where the removed anchor is the last anchor to connect to a center vertex, its removal will cause also the removal of such vertex. Thus, accessing the vertices after the removeAnchor_helper() call is unsafe. To solve that we cache the information we need and then clear the vertex pointers to avoid errors in the future. Signed-off-by: Eduardo M. Fleury Reviewed-by: Artur Duque de Souza --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 30 ++++++++++++++++++++---- src/gui/graphicsview/qgraphicsanchorlayout_p.h | 3 +-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 137806a..b698c02 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -62,7 +62,13 @@ QGraphicsAnchorPrivate::QGraphicsAnchorPrivate(int version) QGraphicsAnchorPrivate::~QGraphicsAnchorPrivate() { - layoutPrivate->removeAnchor(data->from, data->to); + if (data) { + // The QGraphicsAnchor was already deleted at this moment. We must clean + // the dangling pointer to avoid double deletion in the AnchorData dtor. + data->graphicsAnchor = 0; + + layoutPrivate->removeAnchor(data->from, data->to); + } } void QGraphicsAnchorPrivate::setSizePolicy(QSizePolicy::Policy policy) @@ -167,6 +173,18 @@ static void internalSizeHints(QSizePolicy::Policy policy, *prefSize = prefSizeHint; } +AnchorData::~AnchorData() +{ + if (graphicsAnchor) { + // Remove reference to ourself to avoid double removal in + // QGraphicsAnchorPrivate dtor. + graphicsAnchor->d_func()->data = 0; + + delete graphicsAnchor; + } +} + + void AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo) { QSizePolicy::Policy policy; @@ -1687,12 +1705,16 @@ void QGraphicsAnchorLayoutPrivate::removeAnchor(AnchorVertex *firstVertex, { Q_Q(QGraphicsAnchorLayout); - // Actually delete the anchor - removeAnchor_helper(firstVertex, secondVertex); - + // Save references to items while it's safe to assume the vertices exist QGraphicsLayoutItem *firstItem = firstVertex->m_item; QGraphicsLayoutItem *secondItem = secondVertex->m_item; + // Delete the anchor (may trigger deletion of center vertices) + removeAnchor_helper(firstVertex, secondVertex); + + // Ensure no dangling pointer is left behind + firstVertex = secondVertex = 0; + // Checking if the item stays in the layout or not bool keepFirstItem = false; bool keepSecondItem = false; diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h index 8529e2e..e96110c 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h @@ -128,12 +128,11 @@ struct AnchorData : public QSimplexVariable { type(Normal), isLayoutAnchor(false), isCenterAnchor(false), orientation(0), dependency(Independent) {} + virtual ~AnchorData(); virtual void updateChildrenSizes() {} void refreshSizeHints(const QLayoutStyleInfo *styleInfo = 0); - virtual ~AnchorData() {} - #ifdef QT_DEBUG void dump(int indent = 2); inline QString toString() const; -- cgit v0.12 From 7a930ec85684a38212165aff29ed84d95bd43d32 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Thu, 26 Nov 2009 20:13:35 -0300 Subject: QGAL (Test): Fix memory leaks in example and tests Some tests and the example were leaking memory what made it harder to investigate leaks on the layout itself. Those were simple errors like not deleting the layout at the end of the test and were corrected. Signed-off-by: Eduardo M. Fleury Reviewed-by: Artur Duque de Souza --- examples/graphicsview/anchorlayout/main.cpp | 4 +-- .../tst_qgraphicsanchorlayout.cpp | 19 ++++++++----- .../tst_qgraphicsanchorlayout1.cpp | 31 ++++++++++++++-------- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/examples/graphicsview/anchorlayout/main.cpp b/examples/graphicsview/anchorlayout/main.cpp index f898d1d..389bc9e 100644 --- a/examples/graphicsview/anchorlayout/main.cpp +++ b/examples/graphicsview/anchorlayout/main.cpp @@ -122,8 +122,8 @@ int main(int argc, char **argv) scene.addItem(w); scene.setBackgroundBrush(Qt::darkGreen); - QGraphicsView *view = new QGraphicsView(&scene); - view->show(); + QGraphicsView view(&scene); + view.show(); return app.exec(); } diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index a7297c9..d566498 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -1197,7 +1197,7 @@ void tst_QGraphicsAnchorLayout::styleDefaults() QSizeF pref(20, 20); QSizeF max (50, 50); - /* + /* create this layout, where a,b have controlType QSizePolicy::RadioButton c,d have controlType QSizePolicy::PushButton: +-------+ @@ -1244,9 +1244,9 @@ void tst_QGraphicsAnchorLayout::styleDefaults() scene.addItem(window); window->show(); - QGraphicsView *view = new QGraphicsView(&scene); - view->resize(200, 200); - view->show(); + QGraphicsView view(&scene); + view.resize(200, 200); + view.show(); window->adjustSize(); QCOMPARE(a->geometry(), QRectF(0, 3, 20, 20)); //radio @@ -1265,10 +1265,13 @@ void tst_QGraphicsAnchorLayout::styleDefaults() window->setStyle(style); window->adjustSize(); QCOMPARE(a->geometry(), QRectF(0, 3, 20, 20)); - QCOMPARE(b->geometry(), QRectF(21, 25, 20, 20)); + QCOMPARE(b->geometry(), QRectF(21, 25, 20, 20)); QCOMPARE(c->geometry(), QRectF(42, 47, 20, 20)); QCOMPARE(d->geometry(), QRectF(63, 69, 20, 20)); QCOMPARE(l->geometry(), QRectF(0, 0, 89, 98)); + + window->setStyle(0); + delete style; } @@ -1777,7 +1780,8 @@ void tst_QGraphicsAnchorLayout::simplificationVsOrder() QGraphicsWidget *b = createItem(min, pref, max, "B"); QGraphicsWidget *c = createItem(min, pref, max, "C"); - QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; + QGraphicsWidget frame; + QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(&frame); // Bulk anchors l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); @@ -1847,7 +1851,8 @@ void tst_QGraphicsAnchorLayout::simplificationVsRedundance() QGraphicsWidget *b = createItem(min, pref, max, "B"); QGraphicsWidget *c = createItem(min, pref, max, "C"); - QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; + QGraphicsWidget frame; + QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(&frame); l->addCornerAnchors(a, Qt::TopLeftCorner, l, Qt::TopLeftCorner); l->addCornerAnchors(a, Qt::BottomLeftCorner, l, Qt::BottomLeftCorner); diff --git a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp index baa1ba1..57dc90d 100644 --- a/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp +++ b/tests/auto/qgraphicsanchorlayout1/tst_qgraphicsanchorlayout1.cpp @@ -356,6 +356,8 @@ void tst_QGraphicsAnchorLayout1::testItemAt() QVERIFY( layout->itemAt(0) == widget2 ); + delete widget1; + widget->setLayout(layout); delete widget; } @@ -460,6 +462,12 @@ void tst_QGraphicsAnchorLayout1::testAddAndRemoveAnchor() QCOMPARE( layout->count(), 0 ); + delete widget1; + delete widget2; + delete widget3; + delete widget4; + delete widget5; + widget->setLayout(layout); delete widget; } @@ -1740,9 +1748,9 @@ void tst_QGraphicsAnchorLayout1::testBasicLayout() QRectF actual = truncate(widgets[item.index]->geometry()); QCOMPARE(actual, expected); - delete widgets[item.index]; } + qDeleteAll(widgets); delete widget; } @@ -2231,8 +2239,9 @@ void tst_QGraphicsAnchorLayout1::testRemoveCenterAnchor() const BasicLayoutTestResult item = result[i]; QCOMPARE(widgets[item.index]->geometry(), item.rect); - delete widgets[item.index]; } + + qDeleteAll(widgets); delete widget; } @@ -2360,7 +2369,7 @@ void tst_QGraphicsAnchorLayout1::testSingleSizePolicy() QFETCH(bool, valid); // create objects - QGraphicsWidget *widget = new QGraphicsWidget; + QGraphicsWidget widget; TheAnchorLayout *layout = new TheAnchorLayout; TestWidget *childWidget = new TestWidget; @@ -2370,11 +2379,11 @@ void tst_QGraphicsAnchorLayout1::testSingleSizePolicy() layout->setAnchor( layout, Qt::AnchorTop, childWidget, Qt::AnchorTop, 10 ); layout->setAnchor( childWidget, Qt::AnchorBottom, layout, Qt::AnchorBottom, 10 ); - widget->setLayout( layout ); + widget.setLayout( layout ); // set test case specific: policy and size childWidget->setSizePolicy( policy ); - widget->setGeometry( QRectF( QPoint(0,0), size ) ); + widget.setGeometry( QRectF( QPoint(0,0), size ) ); QCOMPARE( layout->isValid() , valid ); @@ -2516,7 +2525,7 @@ void tst_QGraphicsAnchorLayout1::testDoubleSizePolicy() QFETCH(qreal, width2); // create objects - QGraphicsWidget *widget = new QGraphicsWidget; + QGraphicsWidget widget; TheAnchorLayout *layout = new TheAnchorLayout; TestWidget *childWidget1 = new TestWidget; TestWidget *childWidget2 = new TestWidget; @@ -2526,13 +2535,13 @@ void tst_QGraphicsAnchorLayout1::testDoubleSizePolicy() layout->setAnchor( childWidget1, Qt::AnchorRight, childWidget2, Qt::AnchorLeft, 10 ); layout->setAnchor( childWidget2, Qt::AnchorRight, layout, Qt::AnchorRight, 10 ); - widget->setLayout( layout ); + widget.setLayout( layout ); // set test case specific: policy childWidget1->setSizePolicy( policy1 ); childWidget2->setSizePolicy( policy2 ); - widget->setGeometry( QRectF( QPoint(0,0), QSize( 100,100 ) ) ); + widget.setGeometry( QRectF( QPoint(0,0), QSize( 100,100 ) ) ); // check results: if ( width1 == -1.0f ) { @@ -2649,7 +2658,7 @@ void tst_QGraphicsAnchorLayout1::testSizeDistribution() QFETCH(qreal, width2); // create objects - QGraphicsWidget *widget = new QGraphicsWidget; + QGraphicsWidget widget; TheAnchorLayout *layout = new TheAnchorLayout; TestWidget *childWidget1 = new TestWidget; TestWidget *childWidget2 = new TestWidget; @@ -2659,7 +2668,7 @@ void tst_QGraphicsAnchorLayout1::testSizeDistribution() layout->setAnchor( childWidget1, Qt::AnchorRight, childWidget2, Qt::AnchorLeft, 10 ); layout->setAnchor( childWidget2, Qt::AnchorRight, layout, Qt::AnchorRight, 10 ); - widget->setLayout( layout ); + widget.setLayout( layout ); // set test case specific: size hints childWidget1->setMinimumWidth( sizeHints1.value( Qt::MinimumSize ) ); @@ -2670,7 +2679,7 @@ void tst_QGraphicsAnchorLayout1::testSizeDistribution() childWidget2->setPreferredWidth( sizeHints2.value( Qt::PreferredSize ) ); childWidget2->setMaximumWidth( sizeHints2.value( Qt::MaximumSize ) ); - widget->setGeometry( QRectF( QPoint(0,0), QSize( 100,100 ) ) ); + widget.setGeometry( QRectF( QPoint(0,0), QSize( 100,100 ) ) ); // check results: if ( width1 == -1.0f ) { -- cgit v0.12 From a801b57a403548cccd081d8a0ae1f174d2201f9a Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Thu, 19 Nov 2009 17:07:02 -0300 Subject: QGAL: Rename internalSizeHints to applySizePolicy Former name did not reflect actual work done by the function. Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 25 ++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index b698c02..d9f4e32 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -138,10 +138,10 @@ qreal QGraphicsAnchorPrivate::spacing() const } -static void internalSizeHints(QSizePolicy::Policy policy, - qreal minSizeHint, qreal prefSizeHint, qreal maxSizeHint, - qreal *minSize, qreal *prefSize, - qreal *maxSize) +static void applySizePolicy(QSizePolicy::Policy policy, + qreal minSizeHint, qreal prefSizeHint, qreal maxSizeHint, + qreal *minSize, qreal *prefSize, + qreal *maxSize) { // minSize, prefSize and maxSize are initialized // with item's preferred Size: this is QSizePolicy::Fixed. @@ -224,14 +224,18 @@ void AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo) // It is a user-created anchor, fetch size information from the associated QGraphicsAnchor Q_ASSERT(graphicsAnchor); QGraphicsAnchorPrivate *anchorPrivate = graphicsAnchor->d_func(); + + // Policy, min and max sizes are straightforward policy = anchorPrivate->sizePolicy; minSizeHint = 0; + maxSizeHint = QWIDGETSIZE_MAX; + + // Preferred Size if (anchorPrivate->hasSize) { - // One can only configure the preferred size of a normal anchor. Their minimum and - // maximum "size hints" are always 0 and QWIDGETSIZE_MAX, correspondingly. However, - // their effective size hints might be narrowed down due to their size policies. + // Anchor has user-defined size prefSizeHint = anchorPrivate->preferredSize; } else { + // Fetch size information from style const Qt::Orientation orient = Qt::Orientation(QGraphicsAnchorLayoutPrivate::edgeOrientation(from->m_edge) + 1); qreal s = styleInfo->defaultSpacing(orient); if (s < 0) { @@ -247,10 +251,11 @@ void AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo) } prefSizeHint = s; } - maxSizeHint = QWIDGETSIZE_MAX; } - internalSizeHints(policy, minSizeHint, prefSizeHint, maxSizeHint, - &minSize, &prefSize, &maxSize); + + // Fill minSize, prefSize and maxSize based on policy and sizeHints + applySizePolicy(policy, minSizeHint, prefSizeHint, maxSizeHint, + &minSize, &prefSize, &maxSize); // Set the anchor effective sizes to preferred. // -- cgit v0.12 From 2aa9303031d9d9f4b123034f4a7fd84f1d1270ba Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Tue, 27 Oct 2009 18:04:17 -0300 Subject: QGAL: Limit absolute size of anchors and add offset to calculation This commit is groundwork for the support of negative-sized anchors by the simplex solver. The idea is to add to all variables an offset large enough to ensure they are never negative. The implementation limits all variable sizes in the range [-limit, limit] and feed them into the simplex with an offset of "limit". Subtracting this offset later to find out the real values. "limit" is defined as QWIDGETSIZE_MAX for platforms where qreal is double and as QWIDGETSIZE_MAX / 32 when it is float. This is to avoid numerical errors in the simplex solver. This commit also modifies the ASSERT clause inside QSimplex so it becomes less prone to false positives due to numerical errors. Signed-off-by: Eduardo M. Fleury Signed-off-by: Caio Marcelo de Oliveira Filho --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 67 ++++++++++++++++++++---- src/gui/graphicsview/qsimplex_p.h | 2 +- 2 files changed, 57 insertions(+), 12 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index d9f4e32..f3a1a69 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -49,9 +49,17 @@ #endif #include "qgraphicsanchorlayout_p.h" + #ifndef QT_NO_GRAPHICSVIEW QT_BEGIN_NAMESPACE +// To ensure that all variables inside the simplex solver are non-negative, +// we limit the size of anchors in the interval [-limit, limit]. Then before +// sending them to the simplex solver we add "limit" as an offset, so that +// they are actually calculated in the interval [0, 2 * limit] +// To avoid numerical errors in platforms where we use single precision, +// we use a tighter limit for the variables range. +const qreal limit = (sizeof(qreal) == sizeof(double)) ? QWIDGETSIZE_MAX : QWIDGETSIZE_MAX / 32; QGraphicsAnchorPrivate::QGraphicsAnchorPrivate(int version) : QObjectPrivate(version), layoutPrivate(0), data(0), @@ -2086,6 +2094,25 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs( /*! \internal + Shift all the constraints by a certain amount. This allows us to deal with negative values in + the linear program if they are bounded by a certain limit. Functions should be careful to + call it again with a negative amount, to shift the constraints back. +*/ +static void shiftConstraints(const QList &constraints, qreal amount) +{ + for (int i = 0; i < constraints.count(); ++i) { + QSimplexConstraint *c = constraints.at(i); + qreal multiplier = 0; + foreach (qreal v, c->variables.values()) { + multiplier += v; + } + c->constant += multiplier * amount; + } +} + +/*! + \internal + Calculate the sizes for all anchors which are part of the trunk. This works on top of a (possibly) simplified graph. */ @@ -2106,6 +2133,8 @@ bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const QList sizeHintConstraints = constraintsFromSizeHints(variables); QList allConstraints = constraints + sizeHintConstraints; + shiftConstraints(allConstraints, limit); + // Solve min and max size hints qreal min, max; feasible = solveMinMax(allConstraints, path, &min, &max); @@ -2129,6 +2158,7 @@ bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const } qDeleteAll(sizeHintConstraints); + shiftConstraints(constraints, -limit); } else { // No Simplex is necessary because the path was simplified all the way to a single @@ -2160,6 +2190,10 @@ bool QGraphicsAnchorLayoutPrivate::calculateNonTrunk(const QList &variables) { QList sizeHintConstraints = constraintsFromSizeHints(variables); + + shiftConstraints(sizeHintConstraints, limit); + shiftConstraints(constraints, limit); + bool feasible = solvePreferred(constraints + sizeHintConstraints, variables); if (feasible) { @@ -2174,6 +2208,9 @@ bool QGraphicsAnchorLayoutPrivate::calculateNonTrunk(const QList QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin if (ad->dependency == AnchorData::Slave) continue; - if ((ad->minSize == ad->maxSize) || qFuzzyCompare(ad->minSize, ad->maxSize)) { + // To use negative variables inside simplex, we shift them so the minimum negative value is + // mapped to zero before solving. To make sure that it works, we need to guarantee that the + // variables are all inside a certain boundary. + qreal boundedMin = qBound(-limit, ad->minSize, limit); + qreal boundedMax = qBound(-limit, ad->maxSize, limit); + + if ((boundedMin == boundedMax) || qFuzzyCompare(boundedMin, boundedMax)) { QSimplexConstraint *c = new QSimplexConstraint; c->variables.insert(ad, 1.0); - c->constant = ad->minSize; + c->constant = boundedMin; c->ratio = QSimplexConstraint::Equal; anchorConstraints += c; unboundedProblem = false; } else { QSimplexConstraint *c = new QSimplexConstraint; c->variables.insert(ad, 1.0); - c->constant = ad->minSize; + c->constant = boundedMin; c->ratio = QSimplexConstraint::MoreOrEqual; anchorConstraints += c; @@ -2359,7 +2402,7 @@ QList QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin c = new QSimplexConstraint; c->variables.insert(ad, 1.0); - c->constant = ad->maxSize; + c->constant = boundedMax; c->ratio = QSimplexConstraint::LessOrEqual; anchorConstraints += c; unboundedProblem = false; @@ -2370,7 +2413,8 @@ QList QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin if (unboundedProblem) { QSimplexConstraint *c = new QSimplexConstraint; c->variables.insert(layoutEdge, 1.0); - c->constant = QWIDGETSIZE_MAX; + // The maximum size that the layout can take + c->constant = limit; c->ratio = QSimplexConstraint::LessOrEqual; anchorConstraints += c; } @@ -2691,27 +2735,28 @@ bool QGraphicsAnchorLayoutPrivate::solveMinMax(const QList for (iter = path.negatives.constBegin(); iter != path.negatives.constEnd(); ++iter) objective.variables.insert(*iter, -1.0); + const qreal objectiveOffset = (path.positives.count() - path.negatives.count()) * limit; simplex.setObjective(&objective); // Calculate minimum values - *min = simplex.solveMin(); + *min = simplex.solveMin() - objectiveOffset; // Save sizeAtMinimum results QList variables = getVariables(constraints); for (int i = 0; i < variables.size(); ++i) { AnchorData *ad = static_cast(variables.at(i)); - ad->sizeAtMinimum = ad->result; + ad->sizeAtMinimum = ad->result - limit; Q_ASSERT(ad->sizeAtMinimum >= ad->minSize || qAbs(ad->sizeAtMinimum - ad->minSize) < 0.00000001); } // Calculate maximum values - *max = simplex.solveMax(); + *max = simplex.solveMax() - objectiveOffset; // Save sizeAtMaximum results for (int i = 0; i < variables.size(); ++i) { AnchorData *ad = static_cast(variables.at(i)); - ad->sizeAtMaximum = ad->result; + ad->sizeAtMaximum = ad->result - limit; // Q_ASSERT(ad->sizeAtMaximum <= ad->maxSize || // qAbs(ad->sizeAtMaximum - ad->maxSize) < 0.00000001); } @@ -2756,7 +2801,7 @@ bool QGraphicsAnchorLayoutPrivate::solvePreferred(const QListvariables.insert(ad, 1.0); c->variables.insert(shrinker, 1.0); c->variables.insert(grower, -1.0); - c->constant = ad->prefSize; + c->constant = ad->prefSize + limit; preferredConstraints += c; preferredVariables += grower; @@ -2778,7 +2823,7 @@ bool QGraphicsAnchorLayoutPrivate::solvePreferred(const QListsizeAtPreferred = ad->result; + ad->sizeAtPreferred = ad->result - limit; } // Make sure we delete the simplex solver -before- we delete the diff --git a/src/gui/graphicsview/qsimplex_p.h b/src/gui/graphicsview/qsimplex_p.h index a5816d1..2004471 100644 --- a/src/gui/graphicsview/qsimplex_p.h +++ b/src/gui/graphicsview/qsimplex_p.h @@ -107,7 +107,7 @@ struct QSimplexConstraint Q_ASSERT(constant > 0 || qFuzzyCompare(1, 1 + constant)); - if ((leftHandSide == constant) || qAbs(leftHandSide - constant) < 0.00000001) + if ((leftHandSide == constant) || qAbs(leftHandSide - constant) < 0.0000001) return true; switch (ratio) { -- cgit v0.12 From 33116cf737b6ded48ccbb14af401ecb18adeec96 Mon Sep 17 00:00:00 2001 From: Jesus Sanchez-Palencia Date: Thu, 5 Nov 2009 13:41:36 -0300 Subject: QGAL: Do not revert negative anchors Since we now support anchors with size less then zero, we no longer need to revert anchors with negative spacing. Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 26 ++++-------------------- src/gui/graphicsview/qgraphicsanchorlayout_p.h | 1 - 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index f3a1a69..3154630 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -64,7 +64,7 @@ const qreal limit = (sizeof(qreal) == sizeof(double)) ? QWIDGETSIZE_MAX : QWIDGE QGraphicsAnchorPrivate::QGraphicsAnchorPrivate(int version) : QObjectPrivate(version), layoutPrivate(0), data(0), sizePolicy(QSizePolicy::Fixed), preferredSize(0), - hasSize(true), reversed(false) + hasSize(true) { } @@ -94,27 +94,12 @@ void QGraphicsAnchorPrivate::setSpacing(qreal value) return; } - const qreal rawValue = reversed ? -preferredSize : preferredSize; - if (hasSize && (rawValue == value)) + if (hasSize && (preferredSize == value)) return; // The anchor has an user-defined size hasSize = true; - - // The simplex solver cannot handle negative sizes. To workaround that, - // if value is less than zero, we reverse the anchor and set the absolute - // value; - if (value >= 0) { - preferredSize = value; - if (reversed) - qSwap(data->from, data->to); - reversed = false; - } else { - preferredSize = -value; - if (!reversed) - qSwap(data->from, data->to); - reversed = true; - } + preferredSize = value; layoutPrivate->q_func()->invalidate(); } @@ -128,9 +113,6 @@ void QGraphicsAnchorPrivate::unsetSpacing() // Return to standard direction hasSize = false; - if (reversed) - qSwap(data->from, data->to); - reversed = false; layoutPrivate->q_func()->invalidate(); } @@ -142,7 +124,7 @@ qreal QGraphicsAnchorPrivate::spacing() const return 0; } - return reversed ? -preferredSize : preferredSize; + return preferredSize; } diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h index e96110c..925d7ef 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h @@ -342,7 +342,6 @@ public: qreal preferredSize; uint hasSize : 1; // if false, get size from style. - uint reversed : 1; // if true, the anchor was inverted to keep its value positive }; -- cgit v0.12 From 666576b39da04f4185036d9eee1b8edeae10ccf7 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Thu, 5 Nov 2009 11:54:33 -0300 Subject: QGAL: Support for out-of-order sequential anchors Now sequential anchors account for the fact they may be composed of anchors with different directions. Both refreshSizeHints and updateChildrenSizes have been updated to support this situation. Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 40 ++++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 3154630..1f1769f 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -416,12 +416,27 @@ void SequentialAnchorData::updateChildrenSizes() const QPair maxFactor = getFactor(sizeAtMaximum, minSize, prefSize, maxSize); + // XXX This is not safe if Vertex simplification takes place after the sequential + // anchor is created. In that case, "prev" will be a group-vertex, different from + // "from" or "to", that _contains_ one of them. + AnchorVertex *prev = from; + for (int i = 0; i < m_edges.count(); ++i) { AnchorData *e = m_edges.at(i); - e->sizeAtMinimum = interpolate(minFactor, e->minSize, e->prefSize, e->maxSize); - e->sizeAtPreferred = interpolate(prefFactor, e->minSize, e->prefSize, e->maxSize); - e->sizeAtMaximum = interpolate(maxFactor, e->minSize, e->prefSize, e->maxSize); + const bool edgeIsForward = (e->from == prev); + if (edgeIsForward) { + e->sizeAtMinimum = interpolate(minFactor, e->minSize, e->prefSize, e->maxSize); + e->sizeAtPreferred = interpolate(prefFactor, e->minSize, e->prefSize, e->maxSize); + e->sizeAtMaximum = interpolate(maxFactor, e->minSize, e->prefSize, e->maxSize); + prev = e->to; + } else { + Q_ASSERT(prev == e->to); + e->sizeAtMinimum = interpolate(minFactor, e->maxSize, e->prefSize, e->minSize); + e->sizeAtPreferred = interpolate(prefFactor, e->maxSize, e->prefSize, e->minSize); + e->sizeAtMaximum = interpolate(maxFactor, e->maxSize, e->prefSize, e->minSize); + prev = e->from; + } e->updateChildrenSizes(); } @@ -433,11 +448,24 @@ void SequentialAnchorData::calculateSizeHints() prefSize = 0; maxSize = 0; + AnchorVertex *prev = from; + for (int i = 0; i < m_edges.count(); ++i) { AnchorData *edge = m_edges.at(i); - minSize += edge->minSize; - prefSize += edge->prefSize; - maxSize += edge->maxSize; + + const bool edgeIsForward = (edge->from == prev); + if (edgeIsForward) { + minSize += edge->minSize; + prefSize += edge->prefSize; + maxSize += edge->maxSize; + prev = edge->to; + } else { + Q_ASSERT(prev == edge->to); + minSize -= edge->maxSize; + prefSize -= edge->prefSize; + maxSize -= edge->minSize; + prev = edge->from; + } } // See comment in AnchorData::refreshSizeHints() about sizeAt* values -- cgit v0.12 From 89f83f99242d67b5079f16c8db0960fc71bda3f0 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Thu, 5 Nov 2009 23:19:29 -0300 Subject: QGAL: Enable out-of-order sequential simplification Modify the simplification code to allow the creation of out-of-order sequential anchors. Basically the "changedDirection" end-of-sequence condition was removed, also note that createSequence no longer bothers to revert the direction of anchors if the order it receives is not standard. Removing expect-fail clause from test since now we pass :-) Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 69 ++++++++-------------- .../tst_qgraphicsanchorlayout.cpp | 1 - 2 files changed, 23 insertions(+), 47 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 1f1769f..a69d8f3 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -669,24 +669,10 @@ static AnchorData *createSequence(Graph *graph, const QVector &vertices, AnchorVertex *after) { - AnchorData *data = graph->edgeData(before, vertices.first()); - Q_ASSERT(data); - - const bool forward = (before == data->from); - QVector orderedVertices; - - if (forward) { - orderedVertices = vertices; - } else { - qSwap(before, after); - for (int i = vertices.count() - 1; i >= 0; --i) - orderedVertices.append(vertices.at(i)); - } - #if defined(QT_DEBUG) && 0 QString strVertices; - for (int i = 0; i < orderedVertices.count(); ++i) { - strVertices += QString::fromAscii("%1 - ").arg(orderedVertices.at(i)->toString()); + for (int i = 0; i < vertices.count(); ++i) { + strVertices += QString::fromAscii("%1 - ").arg(vertices.at(i)->toString()); } QString strPath = QString::fromAscii("%1 - %2%3").arg(before->toString(), strVertices, after->toString()); qDebug("simplifying [%s] to [%s - %s]", qPrintable(strPath), qPrintable(before->toString()), qPrintable(after->toString())); @@ -695,15 +681,22 @@ static AnchorData *createSequence(Graph *graph, AnchorVertex *prev = before; QVector edges; - for (int i = 0; i <= orderedVertices.count(); ++i) { - AnchorVertex *next = (i < orderedVertices.count()) ? orderedVertices.at(i) : after; + // Take from the graph, the edges that will be simplificated + for (int i = 0; i < vertices.count(); ++i) { + AnchorVertex *next = vertices.at(i); AnchorData *ad = graph->takeEdge(prev, next); Q_ASSERT(ad); edges.append(ad); prev = next; } - SequentialAnchorData *sequence = new SequentialAnchorData(orderedVertices, edges); + // Take the last edge (not covered in the loop above) + AnchorData *ad = graph->takeEdge(vertices.last(), after); + Q_ASSERT(ad); + edges.append(ad); + + // Create sequence + SequentialAnchorData *sequence = new SequentialAnchorData(vertices, edges); sequence->from = before; sequence->to = after; @@ -963,7 +956,6 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP QStack > stack; stack.push(qMakePair(static_cast(0), layoutFirstVertex[orientation])); QVector candidates; - bool candidatesForward = true; // Walk depth-first, in the stack we store start of the candidate sequence (beforeSequence) // and the vertex to be visited. @@ -979,9 +971,8 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP // A vertex can trigger an end of sequence if // (a) it is a layout vertex, we don't simplify away the layout vertices; // (b) it does not have exactly 2 adjacents; - // (c) it will change the direction of the sequence; - // (d) its next adjacent is already visited (a cycle in the graph); - // (e) the next anchor is a center anchor. + // (c) its next adjacent is already visited (a cycle in the graph). + // (d) the next anchor is a center anchor. const QList &adjacents = g.adjacentVertices(v); const bool isLayoutVertex = v->m_item == q; @@ -996,19 +987,10 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP endOfSequence = isLayoutVertex || adjacents.count() != 2; if (!endOfSequence) { - // If this is the first vertice, determine what is the direction to use for this - // sequence. - if (candidates.isEmpty()) { - const AnchorData *data = g.edgeData(beforeSequence, v); - Q_ASSERT(data); - candidatesForward = (beforeSequence == data->from); - } - // This is a tricky part. We peek at the next vertex to find out whether // - // - the edge from this vertex to the next vertex has the same direction; - // - we already visited the next vertex; - // - the next anchor is a center. + // - we already visited the next vertex (c); + // - the next anchor is a center (d). // // Those are needed to identify the remaining end of sequence cases. Note that unlike // (a) and (b), we preempt the end of sequence by looking into the next vertex. @@ -1026,22 +1008,17 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP const AnchorData *data = g.edgeData(v, after); Q_ASSERT(data); - const bool willChangeDirection = (candidatesForward != (v == data->from)); const bool cycleFound = visited.contains(after); - // Now cases (c), (d) and (e)... - endOfSequence = willChangeDirection || cycleFound || data->isCenterAnchor; + // Now cases (c) and (d)... + endOfSequence = cycleFound || data->isCenterAnchor; - if (endOfSequence) { - if (!willChangeDirection) { - // If the direction will not change, we can add the current vertex to the - // candidates list and we know that 'after' can be used as afterSequence. - candidates.append(v); - afterSequence = after; - } - } else { + if (!endOfSequence) { // If it's not an end of sequence, then the vertex didn't trigger neither of the - // previously four cases, so it can be added to the candidates list. + // previously three cases, so it can be added to the candidates list. + candidates.append(v); + } else if (cycleFound && (beforeSequence != after)) { + afterSequence = after; candidates.append(v); } } diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index d566498..6e78522 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -1806,7 +1806,6 @@ void tst_QGraphicsAnchorLayout::simplificationVsOrder() l->effectiveSizeHint(Qt::MinimumSize); if (hasSimplification) { - QEXPECT_FAIL("", "Sequential anchors cannot handle children of opposite directions", Continue); QCOMPARE(usedSimplex(l, Qt::Horizontal), false); QCOMPARE(usedSimplex(l, Qt::Vertical), false); } -- cgit v0.12 From 12341a4e33a498037679e27edee829fa245a0148 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Tue, 17 Nov 2009 16:35:28 -0300 Subject: QGAL: Use single arrow in "dumpGraph" Modify the "dot" format graph to use a single arrow between each pair of vertices. Previously we would use two anchors (a black forward one and a gray backwards). With a single arrow the graph loooks cleaner. Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- src/gui/graphicsview/qgraph_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraph_p.h b/src/gui/graphicsview/qgraph_p.h index 0a2bf27..d429714 100644 --- a/src/gui/graphicsview/qgraph_p.h +++ b/src/gui/graphicsview/qgraph_p.h @@ -236,7 +236,7 @@ public: EdgeData *data = edgeData(v, v1); bool forward = data->from == v; if (forward) { - edges += QString::fromAscii("\"%1\"->\"%2\" [label=\"[%3,%4,%5]\" dir=both color=\"#000000:#a0a0a0\"] \n") + edges += QString::fromAscii("\"%1\"->\"%2\" [label=\"[%3,%4,%5]\" color=\"#000000\"] \n") .arg(v->toString()) .arg(v1->toString()) .arg(data->minSize) -- cgit v0.12 From d622aef01e5c2624cd64c92ce77064718c6576af Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Wed, 18 Nov 2009 16:00:32 -0300 Subject: QGAL: move second child direction check to a function In a parallel anchor, the second child anchor may be forward or backwards in relation to the parallel itself. Moves the directionality check to a function. It'll be useful in the next commit. Signed-off-by: Caio Marcelo de Oliveira Filho Reviewed-by: Eduardo M. Fleury --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 26 ++++++++++++++---------- src/gui/graphicsview/qgraphicsanchorlayout_p.h | 10 ++++++++- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index a69d8f3..4ee58d1 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -265,13 +265,7 @@ void ParallelAnchorData::updateChildrenSizes() firstEdge->sizeAtPreferred = sizeAtPreferred; firstEdge->sizeAtMaximum = sizeAtMaximum; - // We have the convention that the first children will define the direction of the - // pararell group. So we can check whether the second edge is "forward" in relation - // to the group if it have the same direction as the first edge. Note that we don't - // use 'this->from' because it might be changed by vertex simplification. - const bool secondForward = (firstEdge->from == secondEdge->from); - - if (secondForward) { + if (secondForward()) { secondEdge->sizeAtMinimum = sizeAtMinimum; secondEdge->sizeAtPreferred = sizeAtPreferred; secondEdge->sizeAtMaximum = sizeAtMaximum; @@ -296,10 +290,20 @@ bool ParallelAnchorData::calculateSizeHints() // to a backwards anchor of size (-max, -pref, -min) // Also see comments in updateChildrenSizes(). - const bool secondForward = (firstEdge->from == secondEdge->from); - const qreal secondMin = secondForward ? secondEdge->minSize : -secondEdge->maxSize; - const qreal secondPref = secondForward ? secondEdge->prefSize : -secondEdge->prefSize; - const qreal secondMax = secondForward ? secondEdge->maxSize : -secondEdge->minSize; + + qreal secondMin; + qreal secondPref; + qreal secondMax; + + if (secondForward()) { + secondMin = secondEdge->minSize; + secondPref = secondEdge->prefSize; + secondMax = secondEdge->maxSize; + } else { + secondMin = -secondEdge->maxSize; + secondPref = -secondEdge->prefSize; + secondMax = -secondEdge->minSize; + } minSize = qMax(firstEdge->minSize, secondMin); maxSize = qMin(firstEdge->maxSize, secondMax); diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h index 925d7ef..8d2d691 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h @@ -212,7 +212,8 @@ struct ParallelAnchorData : public AnchorData Q_ASSERT(((first->from == second->from) && (first->to == second->to)) || ((first->from == second->to) && (first->to == second->from))); - // We arbitrarily choose the direction of the first child as "our" direction + // Our convention will be that the parallel group anchor will have the same + // direction as the first anchor. from = first->from; to = first->to; #ifdef QT_DEBUG @@ -223,6 +224,13 @@ struct ParallelAnchorData : public AnchorData virtual void updateChildrenSizes(); bool calculateSizeHints(); + bool secondForward() const { + // We have the convention that the first children will define the direction of the + // pararell group. Note that we can't rely on 'this->from' or 'this->to' because they + // might be changed by vertex simplification. + return firstEdge->from == secondEdge->from; + } + AnchorData* firstEdge; AnchorData* secondEdge; -- cgit v0.12 From c7d63a44b315bf945c055330c24b24bca6ef7fdb Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Wed, 18 Nov 2009 17:46:52 -0300 Subject: QGAL: parallel anchors sometimes have to fix constraints For an out-of-order parallel anchor, i.e. when the second child is backwards in relation to the parallel anchor, we need to fix the constraints that used to have the second child. The parallel anchor will replace its child, but we must change the multiplier signal, so the constraint remain valid. This commit also changes the order of restoration steps, since now we depend on correct vertex information to fix back the constraints, we do it before the restoring of pair vertices. Signed-off-by: Caio Marcelo de Oliveira Filho Reviewed-by: Eduardo M. Fleury --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 51 ++++++++++++++++-------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 4ee58d1..9114fc3 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -633,16 +633,25 @@ AnchorData *QGraphicsAnchorLayoutPrivate::addAnchorMaybeParallel(AnchorData *new AnchorData *child = children[i]; QList *childConstraints = childrenConstraints[i]; + // We need to fix the second child constraints if the parallel group will have the + // opposite direction of the second child anchor. For the point of view of external + // entities, this anchor was reversed. So if at some point we say that the parallel + // has a value of 20, this mean that the second child (when reversed) will be + // assigned -20. + const bool needsReverse = i == 1 && !parallel->secondForward(); + if (!child->isCenterAnchor) continue; parallel->isCenterAnchor = true; - for (int i = 0; i < constraints.count(); ++i) { - QSimplexConstraint *c = constraints[i]; + for (int j = 0; j < constraints.count(); ++j) { + QSimplexConstraint *c = constraints[j]; if (c->variables.contains(child)) { childConstraints->append(c); qreal v = c->variables.take(child); + if (needsReverse) + v *= -1; c->variables.insert(parallel, v); } } @@ -1165,9 +1174,15 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedConstraints(ParallelAnchorDa c->variables.insert(parallel->firstEdge, v); } + // When restoring, we might have to revert constraints back. See comments on + // addAnchorMaybeParallel(). + const bool needsReverse = !parallel->secondForward(); + for (int i = 0; i < parallel->m_secondConstraints.count(); ++i) { QSimplexConstraint *c = parallel->m_secondConstraints.at(i); qreal v = c->variables[parallel]; + if (needsReverse) + v *= -1; c->variables.remove(parallel); c->variables.insert(parallel->secondEdge, v); } @@ -1209,7 +1224,24 @@ void QGraphicsAnchorLayoutPrivate::restoreVertices(Orientation orientation) Graph &g = graph[orientation]; QList &toRestore = simplifiedVertices[orientation]; - // We will restore the vertices in the inverse order of creation, this way we ensure that + // Since we keep a list of parallel anchors and vertices that were created during vertex + // simplification, we can now iterate on those lists instead of traversing the graph + // recursively. + + // First, restore the constraints changed when we created parallel anchors. Note that this + // works at this point because the constraints doesn't depend on vertex information and at + // this point it's always safe to identify whether the second child is forward or backwards. + // In the next step, we'll change the anchors vertices so that would not be possible anymore. + QList ¶llelAnchors = anchorsFromSimplifiedVertices[orientation]; + + for (int i = parallelAnchors.count() - 1; i >= 0; --i) { + ParallelAnchorData *parallel = static_cast(parallelAnchors.at(i)); + restoreSimplifiedConstraints(parallel); + delete parallel; + } + parallelAnchors.clear(); + + // Then, we will restore the vertices in the inverse order of creation, this way we ensure that // the vertex being restored was not wrapped by another simplification. for (int i = toRestore.count() - 1; i >= 0; --i) { AnchorVertexPair *pair = toRestore.at(i); @@ -1254,19 +1286,6 @@ void QGraphicsAnchorLayoutPrivate::restoreVertices(Orientation orientation) delete pair; } toRestore.clear(); - - // The restoration process for vertex simplification also restored the effect of the - // parallel anchors created during vertex simplification, so we just need to restore - // the constraints in case of parallels that contain center anchors. For the same - // reason as above, order matters here. - QList ¶llelAnchors = anchorsFromSimplifiedVertices[orientation]; - - for (int i = parallelAnchors.count() - 1; i >= 0; --i) { - ParallelAnchorData *parallel = static_cast(parallelAnchors.at(i)); - restoreSimplifiedConstraints(parallel); - delete parallel; - } - parallelAnchors.clear(); } QGraphicsAnchorLayoutPrivate::Orientation -- cgit v0.12 From 7fbb8aae666a86091cb7f7f3326e9e05781c02f3 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Wed, 18 Nov 2009 17:20:24 -0300 Subject: QGAL: Add AnchorData::minPrefSize and maxPrefSize With the addition of out-of-order sequential simplification, the calculation of preferred sizes became more complicated. In the past, when parallel anchors or the simplex solver had to decide between conflicting preferred sizes, they could assume that increasing the size of an anchor was better than decreasing it. That assumption comes from early discussions with Jan-Arve regarding the preferred size calculation algorithm. However, when ooo-sequential anchors exist, we can have a situation where increasing the size of an anchor can actually reduce the size of a simplified anchor inside it. To solve that, we need to expose some information regarding the internal anchors to the decision makers outside, ie. the simplex solver and parallel anchors. This information is now being provided in terms of two additional values present in each anchor, as follows: - minPrefSize: Always in the interval [minSize, prefSize]. Denotes the minimum size an anchor can assume as to avoid shrinking anchors below their preferred sizes. - maxPrefSize: Always in the interval [prefSize, maxSize]. Similar to the value above, but refering to the maximum size the anchor should assume. Some examples: 1) Standard anchor: 10 / 50 / 500 o----------------------------> Becomes: 10 / 50 / 50 / 500 / 500 o----------------------------> We'd rather grow than shrink, so we say that our preferred size is 50, but if we need to grow up to 500, that's OK. Note that we are still able to shrink all the way to 10, but it will hurt us more. 2) Two anchors: 100 / 200 / 500 10 / 20 / 40 o--------------------> <-------------------o Resulting sequential anchor: 60 / 160 / 180 / 480 / 490 o------------------------------------------> The resulting anchor have a preferred size of 180 but it can "easily" grow to 480 (only the first half grows). If it had to go all the way to 490 the second half would have to shrink below its preferred size. OTOH, if it had to shrink, it could go to 160 if the second half grew. However, shrinking even more, towards 60, would require the first half to shrink below its preferred size. With this information parallel and simplex are now able to choose the best solutions when solving conflicts. Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- src/gui/graphicsview/qgraph_p.h | 4 +- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 181 +++++++++++++++++------ src/gui/graphicsview/qgraphicsanchorlayout_p.h | 10 +- 3 files changed, 149 insertions(+), 46 deletions(-) diff --git a/src/gui/graphicsview/qgraph_p.h b/src/gui/graphicsview/qgraph_p.h index d429714..076b8fa 100644 --- a/src/gui/graphicsview/qgraph_p.h +++ b/src/gui/graphicsview/qgraph_p.h @@ -236,11 +236,13 @@ public: EdgeData *data = edgeData(v, v1); bool forward = data->from == v; if (forward) { - edges += QString::fromAscii("\"%1\"->\"%2\" [label=\"[%3,%4,%5]\" color=\"#000000\"] \n") + edges += QString::fromAscii("\"%1\"->\"%2\" [label=\"[%3,%4,%5,%6,%7]\" color=\"#000000\"] \n") .arg(v->toString()) .arg(v1->toString()) .arg(data->minSize) + .arg(data->minPrefSize) .arg(data->prefSize) + .arg(data->maxPrefSize) .arg(data->maxSize) ; } diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 9114fc3..6d90d3a 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -190,6 +190,9 @@ void AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo) maxSize = QWIDGETSIZE_MAX; if (isCenterAnchor) maxSize /= 2; + + minPrefSize = prefSize; + maxPrefSize = maxSize; return; } else { if (orientation == QGraphicsAnchorLayoutPrivate::Horizontal) { @@ -247,6 +250,9 @@ void AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo) applySizePolicy(policy, minSizeHint, prefSizeHint, maxSizeHint, &minSize, &prefSize, &maxSize); + minPrefSize = prefSize; + maxPrefSize = maxSize; + // Set the anchor effective sizes to preferred. // // Note: The idea here is that all items should remain at their @@ -279,29 +285,38 @@ void ParallelAnchorData::updateChildrenSizes() secondEdge->updateChildrenSizes(); } -bool ParallelAnchorData::calculateSizeHints() -{ - // Note that parallel groups can lead to unfeasibility, so during calculation, we can - // find out one unfeasibility. Because of that this method return boolean. This can't - // happen in sequential, so there the method is void. - - // Account for parallel anchors where the second edge is backwards. - // We rely on the fact that a forward anchor of sizes min, pref, max is equivalent - // to a backwards anchor of size (-max, -pref, -min) +/* + \internal - // Also see comments in updateChildrenSizes(). + Initialize the parallel anchor size hints using the sizeHint information from + its children. + Note that parallel groups can lead to unfeasibility, so during calculation, we can + find out one unfeasibility. Because of that this method return boolean. This can't + happen in sequential, so there the method is void. + */ +bool ParallelAnchorData::calculateSizeHints() +{ + // Normalize second child sizes. + // A negative anchor of sizes min, minPref, pref, maxPref and max, is equivalent + // to a forward anchor of sizes -max, -maxPref, -pref, -minPref, -min qreal secondMin; + qreal secondMinPref; qreal secondPref; + qreal secondMaxPref; qreal secondMax; if (secondForward()) { secondMin = secondEdge->minSize; + secondMinPref = secondEdge->minPrefSize; secondPref = secondEdge->prefSize; + secondMaxPref = secondEdge->maxPrefSize; secondMax = secondEdge->maxSize; } else { secondMin = -secondEdge->maxSize; + secondMinPref = -secondEdge->maxPrefSize; secondPref = -secondEdge->prefSize; + secondMaxPref = -secondEdge->minPrefSize; secondMax = -secondEdge->minSize; } @@ -315,23 +330,72 @@ bool ParallelAnchorData::calculateSizeHints() return false; } - // The equivalent preferred Size of a parallel anchor is calculated as to - // reduce the deviation from the original preferred sizes _and_ to avoid shrinking - // items below their preferred sizes, unless strictly needed. - - // ### This logic only holds if all anchors in the layout are "well-behaved" in the - // following terms: + // Preferred size calculation + // The calculation of preferred size is done as follows: + // + // 1) Check whether one of the child anchors is the layout structural anchor + // If so, we can simply copy the preferred information from the other child, + // after bounding it to our minimum and maximum sizes. + // If not, then we proceed with the actual calculations. // - // - There are no negative-sized anchors - // - All sequential anchors are composed of children in the same direction as the - // sequential anchor itself + // 2) The whole algorithm for preferred size calculation is based on the fact + // that, if a given anchor cannot remain at its preferred size, it'd rather + // grow than shrink. // - // With these assumptions we can grow a child knowing that no hidden items will - // have to shrink as the result of that. - // If any of these does not hold, we have a situation where the ParallelAnchor - // does not have enough information to calculate its equivalent prefSize. - prefSize = qMax(firstEdge->prefSize, secondPref); - prefSize = qMin(prefSize, maxSize); + // What happens though is that while this affirmative is true for simple + // anchors, it may not be true for sequential anchors that have one or more + // reversed anchors inside it. That happens because when a sequential anchor + // grows, any reversed anchors inside it may be required to shrink, something + // we try to avoid, as said above. + // + // To overcome this, besides their actual preferred size "prefSize", each anchor + // exports what we call "minPrefSize" and "maxPrefSize". These two values define + // a surrounding interval where, if required to move, the anchor would rather + // remain inside. + // + // For standard anchors, this area simply represents the region between + // prefSize and maxSize, which makes sense since our first affirmation. + // For composed anchors, these values are calculated as to reduce the global + // "damage", that is, to reduce the total deviation and the total amount of + // anchors that had to shrink. + + if (firstEdge->isLayoutAnchor) { + prefSize = qBound(minSize, secondPref, maxSize); + minPrefSize = qBound(minSize, secondMinPref, maxSize); + maxPrefSize = qBound(minSize, secondMaxPref, maxSize); + } else if (secondEdge->isLayoutAnchor) { + prefSize = qBound(minSize, firstEdge->prefSize, maxSize); + minPrefSize = qBound(minSize, firstEdge->minPrefSize, maxSize); + maxPrefSize = qBound(minSize, firstEdge->maxPrefSize, maxSize); + } else { + // Calculate the intersection between the "preferred" regions of each child + const qreal lowerBoundary = + qBound(minSize, qMax(firstEdge->minPrefSize, secondMinPref), maxSize); + const qreal upperBoundary = + qBound(minSize, qMin(firstEdge->maxPrefSize, secondMaxPref), maxSize); + const qreal prefMean = + qBound(minSize, (firstEdge->prefSize + secondPref) / 2, maxSize); + + if (lowerBoundary < upperBoundary) { + // If there is an intersection between the two regions, this intersection + // will be used as the preferred region of the parallel anchor itself. + // The preferred size will be the bounded average between the two preferred + // sizes. + prefSize = qBound(lowerBoundary, prefMean, upperBoundary); + minPrefSize = lowerBoundary; + maxPrefSize = upperBoundary; + } else { + // If there is no intersection, we have to attribute "damage" to at least + // one of the children. The minimum total damage is achieved in points + // inside the region that extends from (1) the upper boundary of the lower + // region to (2) the lower boundary of the upper region. + // Then, we expose this region as _our_ preferred region and once again, + // use the bounded average as our preferred size. + prefSize = qBound(upperBoundary, prefMean, lowerBoundary); + minPrefSize = upperBoundary; + maxPrefSize = lowerBoundary; + } + } // See comment in AnchorData::refreshSizeHints() about sizeAt* values sizeAtMinimum = prefSize; @@ -349,19 +413,28 @@ bool ParallelAnchorData::calculateSizeHints() 1 is at Maximum */ static QPair getFactor(qreal value, qreal min, - qreal pref, qreal max) + qreal minPref, qreal pref, + qreal maxPref, qreal max) { QGraphicsAnchorLayoutPrivate::Interval interval; qreal lower; qreal upper; - if (value < pref) { - interval = QGraphicsAnchorLayoutPrivate::MinToPreferred; + if (value < minPref) { + interval = QGraphicsAnchorLayoutPrivate::MinimumToMinPreferred; lower = min; + upper = minPref; + } else if (value < pref) { + interval = QGraphicsAnchorLayoutPrivate::MinPreferredToPreferred; + lower = minPref; upper = pref; - } else { - interval = QGraphicsAnchorLayoutPrivate::PreferredToMax; + } else if (value < maxPref) { + interval = QGraphicsAnchorLayoutPrivate::PreferredToMaxPreferred; lower = pref; + upper = maxPref; + } else { + interval = QGraphicsAnchorLayoutPrivate::MaxPreferredToMaximum; + lower = maxPref; upper = max; } @@ -376,19 +449,26 @@ static QPair getFactor(qreal valu } static qreal interpolate(const QPair &factor, - qreal min, qreal pref, - qreal max) + qreal min, qreal minPref, qreal pref, qreal maxPref, qreal max) { qreal lower; qreal upper; switch (factor.first) { - case QGraphicsAnchorLayoutPrivate::MinToPreferred: + case QGraphicsAnchorLayoutPrivate::MinimumToMinPreferred: lower = min; + upper = minPref; + break; + case QGraphicsAnchorLayoutPrivate::MinPreferredToPreferred: + lower = minPref; upper = pref; break; - case QGraphicsAnchorLayoutPrivate::PreferredToMax: + case QGraphicsAnchorLayoutPrivate::PreferredToMaxPreferred: lower = pref; + upper = maxPref; + break; + case QGraphicsAnchorLayoutPrivate::MaxPreferredToMaximum: + lower = maxPref; upper = max; break; } @@ -414,11 +494,11 @@ void SequentialAnchorData::updateChildrenSizes() // band (the lower band) or the Preferred To Maximum (the upper band). const QPair minFactor = - getFactor(sizeAtMinimum, minSize, prefSize, maxSize); + getFactor(sizeAtMinimum, minSize, minPrefSize, prefSize, maxPrefSize, maxSize); const QPair prefFactor = - getFactor(sizeAtPreferred, minSize, prefSize, maxSize); + getFactor(sizeAtPreferred, minSize, minPrefSize, prefSize, maxPrefSize, maxSize); const QPair maxFactor = - getFactor(sizeAtMaximum, minSize, prefSize, maxSize); + getFactor(sizeAtMaximum, minSize, minPrefSize, prefSize, maxPrefSize, maxSize); // XXX This is not safe if Vertex simplification takes place after the sequential // anchor is created. In that case, "prev" will be a group-vertex, different from @@ -430,15 +510,21 @@ void SequentialAnchorData::updateChildrenSizes() const bool edgeIsForward = (e->from == prev); if (edgeIsForward) { - e->sizeAtMinimum = interpolate(minFactor, e->minSize, e->prefSize, e->maxSize); - e->sizeAtPreferred = interpolate(prefFactor, e->minSize, e->prefSize, e->maxSize); - e->sizeAtMaximum = interpolate(maxFactor, e->minSize, e->prefSize, e->maxSize); + e->sizeAtMinimum = interpolate(minFactor, e->minSize, e->minPrefSize, + e->prefSize, e->maxPrefSize, e->maxSize); + e->sizeAtPreferred = interpolate(prefFactor, e->minSize, e->minPrefSize, + e->prefSize, e->maxPrefSize, e->maxSize); + e->sizeAtMaximum = interpolate(maxFactor, e->minSize, e->minPrefSize, + e->prefSize, e->maxPrefSize, e->maxSize); prev = e->to; } else { Q_ASSERT(prev == e->to); - e->sizeAtMinimum = interpolate(minFactor, e->maxSize, e->prefSize, e->minSize); - e->sizeAtPreferred = interpolate(prefFactor, e->maxSize, e->prefSize, e->minSize); - e->sizeAtMaximum = interpolate(maxFactor, e->maxSize, e->prefSize, e->minSize); + e->sizeAtMinimum = interpolate(minFactor, e->maxSize, e->maxPrefSize, + e->prefSize, e->minPrefSize, e->minSize); + e->sizeAtPreferred = interpolate(prefFactor, e->maxSize, e->maxPrefSize, + e->prefSize, e->minPrefSize, e->minSize); + e->sizeAtMaximum = interpolate(maxFactor, e->maxSize, e->maxPrefSize, + e->prefSize, e->minPrefSize, e->minSize); prev = e->from; } @@ -451,6 +537,8 @@ void SequentialAnchorData::calculateSizeHints() minSize = 0; prefSize = 0; maxSize = 0; + minPrefSize = 0; + maxPrefSize = 0; AnchorVertex *prev = from; @@ -462,12 +550,16 @@ void SequentialAnchorData::calculateSizeHints() minSize += edge->minSize; prefSize += edge->prefSize; maxSize += edge->maxSize; + minPrefSize += edge->minPrefSize; + maxPrefSize += edge->maxPrefSize; prev = edge->to; } else { Q_ASSERT(prev == edge->to); minSize -= edge->maxSize; prefSize -= edge->prefSize; maxSize -= edge->minSize; + minPrefSize -= edge->maxPrefSize; + maxPrefSize -= edge->minPrefSize; prev = edge->from; } } @@ -2690,6 +2782,8 @@ void QGraphicsAnchorLayoutPrivate::setupEdgesInterpolation( result = getFactor(current, sizeHints[orientation][Qt::MinimumSize], sizeHints[orientation][Qt::PreferredSize], + sizeHints[orientation][Qt::PreferredSize], + sizeHints[orientation][Qt::PreferredSize], sizeHints[orientation][Qt::MaximumSize]); interpolationInterval[orientation] = result.first; @@ -2718,6 +2812,7 @@ void QGraphicsAnchorLayoutPrivate::interpolateEdge(AnchorVertex *base, AnchorDat interpolationProgress[orientation]); qreal edgeDistance = interpolate(factor, edge->sizeAtMinimum, edge->sizeAtPreferred, + edge->sizeAtPreferred, edge->sizeAtPreferred, edge->sizeAtMaximum); Q_ASSERT(edge->from == base || edge->to == base); diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h index 8d2d691..3be9d41 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h @@ -123,6 +123,7 @@ struct AnchorData : public QSimplexVariable { AnchorData() : QSimplexVariable(), from(0), to(0), minSize(0), prefSize(0), maxSize(0), + minPrefSize(0), maxPrefSize(0), sizeAtMinimum(0), sizeAtPreferred(0), sizeAtMaximum(0), item(0), graphicsAnchor(0), type(Normal), isLayoutAnchor(false), @@ -153,6 +154,9 @@ struct AnchorData : public QSimplexVariable { qreal prefSize; qreal maxSize; + qreal minPrefSize; + qreal maxPrefSize; + // Calculated sizes // These attributes define which sizes should that anchor be in when the // layout is at its minimum, preferred or maximum sizes. Values are @@ -371,8 +375,10 @@ public: // // Interval represents which interpolation interval are we operating in. enum Interval { - MinToPreferred = 0, - PreferredToMax + MinimumToMinPreferred = 0, + MinPreferredToPreferred, + PreferredToMaxPreferred, + MaxPreferredToMaximum }; // Several structures internal to the layout are duplicated to handle -- cgit v0.12 From f2eeef396296a3563c006b77c0ce3708d6256bd3 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Wed, 18 Nov 2009 17:15:23 -0300 Subject: QGAL: Refactor solvePreferred to support min/maxPrefSize With the addition of min and maxPrefSizeHints, the logic used in the preferred simplex had to be changed. The concept behind it is still the same, we minimize the deviation from each item's preferred size. Previously we would make an special effort to avoid items being shrunk, that's why the "shinker" simplex variables had larger multipliers in the objective function. Now we still have variables with large multipliers and others with small mutlipliers, but rather than differentiating between shrinker and/or grower variables, we classify them as "soft" or "hard". "Soft" variables, or slacks, are those that allow the anchor to change its value up to the minPref or maxPref boundaries, OTOH, "hard" slacks are those that allow the item to go all the way to its minimum or maximum sizes. Naturally, the "hard" slacks get large coeficients in the objective function while the "soft" ones get small ones. Now all the slack variables are restricted in size as to respect the boundaries of each interval: - Minimum to MinimumPreferred, - MinimumPreferred to Preferred, - Preferred to MaximumPreferred and - MaximumPreferred to Maximum With such limits, the SizeHint constraints became redundant in the calculation of preferred sizes so they are no longer used. Additionally, as an optimization, if a given interval is NULL (for instance, MinimumPreferred is equal to Preferred), then the associated slack variable would have its size restricted to zero, therefore it is not created at all. Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 93 ++++++++++++++++++------ 1 file changed, 69 insertions(+), 24 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 6d90d3a..2f4ec26 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -2242,7 +2242,7 @@ bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const feasible = solveMinMax(allConstraints, path, &min, &max); if (feasible) { - solvePreferred(allConstraints, variables); + solvePreferred(constraints, variables); // Calculate and set the preferred size for the layout, // from the edge sizes that were calculated above. @@ -2291,12 +2291,8 @@ bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const bool QGraphicsAnchorLayoutPrivate::calculateNonTrunk(const QList &constraints, const QList &variables) { - QList sizeHintConstraints = constraintsFromSizeHints(variables); - - shiftConstraints(sizeHintConstraints, limit); shiftConstraints(constraints, limit); - - bool feasible = solvePreferred(constraints + sizeHintConstraints, variables); + bool feasible = solvePreferred(constraints, variables); if (feasible) { // Propagate size at preferred to other sizes. Semi-floats always will be @@ -2309,10 +2305,7 @@ bool QGraphicsAnchorLayoutPrivate::calculateNonTrunk(const QList return feasible; } +enum slackType { Grower = -1, Shrinker = 1 }; +static QPair createSlack(QSimplexConstraint *sizeConstraint, + qreal interval, slackType type) +{ + QSimplexVariable *slack = new QSimplexVariable; + sizeConstraint->variables.insert(slack, type); + + QSimplexConstraint *limit = new QSimplexConstraint; + limit->variables.insert(slack, 1.0); + limit->ratio = QSimplexConstraint::LessOrEqual; + limit->constant = interval; + + return qMakePair(slack, limit); +} + bool QGraphicsAnchorLayoutPrivate::solvePreferred(const QList &constraints, const QList &variables) { @@ -2879,7 +2887,8 @@ bool QGraphicsAnchorLayoutPrivate::solvePreferred(const QListisLayoutAnchor) continue; - QSimplexVariable *grower = new QSimplexVariable; - QSimplexVariable *shrinker = new QSimplexVariable; - QSimplexConstraint *c = new QSimplexConstraint; - c->variables.insert(ad, 1.0); - c->variables.insert(shrinker, 1.0); - c->variables.insert(grower, -1.0); - c->constant = ad->prefSize + limit; + // By default, all variables are equal to their preferred size. If they have room to + // grow or shrink, such flexibility will be added by the additional variables below. + QSimplexConstraint *sizeConstraint = new QSimplexConstraint; + preferredConstraints += sizeConstraint; + sizeConstraint->variables.insert(ad, 1.0); + sizeConstraint->constant = ad->prefSize + limit; + + // Can easily shrink + QPair slack; + const qreal softShrinkInterval = ad->prefSize - ad->minPrefSize; + if (softShrinkInterval) { + slack = createSlack(sizeConstraint, softShrinkInterval, Shrinker); + preferredVariables += slack.first; + preferredConstraints += slack.second; + + // Add to objective with ratio == 1 (soft) + objective.variables.insert(slack.first, 1.0); + } - preferredConstraints += c; - preferredVariables += grower; - preferredVariables += shrinker; + // Can easily grow + const qreal softGrowInterval = ad->maxPrefSize - ad->prefSize; + if (softGrowInterval) { + slack = createSlack(sizeConstraint, softGrowInterval, Grower); + preferredVariables += slack.first; + preferredConstraints += slack.second; - objective.variables.insert(grower, 1.0); - objective.variables.insert(shrinker, variables.size()); - } + // Add to objective with ratio == 1 (soft) + objective.variables.insert(slack.first, 1.0); + } + // Can shrink if really necessary + const qreal hardShrinkInterval = ad->minPrefSize - ad->minSize; + if (hardShrinkInterval) { + slack = createSlack(sizeConstraint, hardShrinkInterval, Shrinker); + preferredVariables += slack.first; + preferredConstraints += slack.second; + + // Add to objective with ratio == N (hard) + objective.variables.insert(slack.first, variables.size()); + } + + // Can grow if really necessary + const qreal hardGrowInterval = ad->maxSize - ad->maxPrefSize; + if (hardGrowInterval) { + slack = createSlack(sizeConstraint, hardGrowInterval, Grower); + preferredVariables += slack.first; + preferredConstraints += slack.second; + + // Add to objective with ratio == N (hard) + objective.variables.insert(slack.first, variables.size()); + } + } QSimplex *simplex = new QSimplex; bool feasible = simplex->setConstraints(constraints + preferredConstraints); -- cgit v0.12 From 89e26da4374563c9419da1357a24cf9618d804d6 Mon Sep 17 00:00:00 2001 From: "Eduardo M. Fleury" Date: Thu, 19 Nov 2009 19:35:53 -0300 Subject: QGAL: Remove deprecated assert clauses These assert messages are no longer valid since some anchors can have their size not respected if they are in parallel with the layout and have size equal to "QWIDGETSIZE_MAX". Signed-off-by: Eduardo M. Fleury Reviewed-by: Caio Marcelo de Oliveira Filho --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 2f4ec26..b35ee46 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -478,18 +478,6 @@ static qreal interpolate(const QPair minSize || qAbs(sizeAtMinimum - minSize) < 0.00000001); - Q_ASSERT(sizeAtPreferred > minSize || qAbs(sizeAtPreferred - minSize) < 0.00000001); - Q_ASSERT(sizeAtMaximum > minSize || qAbs(sizeAtMaximum - minSize) < 0.00000001); - - // These may be false if this anchor was in parallel with the layout stucture - // Q_ASSERT(sizeAtMinimum < maxSize || qAbs(sizeAtMinimum - maxSize) < 0.00000001); - // Q_ASSERT(sizeAtPreferred < maxSize || qAbs(sizeAtPreferred - maxSize) < 0.00000001); - // Q_ASSERT(sizeAtMaximum < maxSize || qAbs(sizeAtMaximum - maxSize) < 0.00000001); - // Band here refers if the value is in the Minimum To Preferred // band (the lower band) or the Preferred To Maximum (the upper band). @@ -2844,8 +2832,6 @@ bool QGraphicsAnchorLayoutPrivate::solveMinMax(const QList for (int i = 0; i < variables.size(); ++i) { AnchorData *ad = static_cast(variables.at(i)); ad->sizeAtMinimum = ad->result - limit; - Q_ASSERT(ad->sizeAtMinimum >= ad->minSize || - qAbs(ad->sizeAtMinimum - ad->minSize) < 0.00000001); } // Calculate maximum values @@ -2855,8 +2841,6 @@ bool QGraphicsAnchorLayoutPrivate::solveMinMax(const QList for (int i = 0; i < variables.size(); ++i) { AnchorData *ad = static_cast(variables.at(i)); ad->sizeAtMaximum = ad->result - limit; - // Q_ASSERT(ad->sizeAtMaximum <= ad->maxSize || - // qAbs(ad->sizeAtMaximum - ad->maxSize) < 0.00000001); } } return feasible; -- cgit v0.12 From 9e4cefd82d3c4f67f8f182ed3956f5e92e4356e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Mon, 30 Nov 2009 09:49:01 +0100 Subject: Revert "Compile fix for win32-icc." This reverts commit db5e4496229a776768464d1d3d2e1f8e81bd6ba0. --- src/corelib/kernel/qobject.cpp | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 4321c59..30cd011 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -153,15 +153,6 @@ QObjectPrivate::QObjectPrivate(int version) hasGuards = false; } -#ifdef Q_CC_INTEL -/* Workaround for a bug in win32-icc where it seems to inline ~QObjectPrivate too aggressive. - When icc compiles QtGui, it inlines ~QObjectPrivate so that it would generate a call to - ~QObjectData. However, ~QObjectData is not exported from QtCore, so it does not link. - See also QTBUG-5145 for info on how this manifested itself. - */ -# pragma auto_inline(off) -#endif - QObjectPrivate::~QObjectPrivate() { delete static_cast(metaObject); @@ -173,9 +164,6 @@ QObjectPrivate::~QObjectPrivate() delete extraData; #endif } -#ifdef Q_CC_INTEL -# pragma auto_inline(on) -#endif int *QObjectPrivate::setDeleteWatch(QObjectPrivate *d, int *w) { -- cgit v0.12 From e112bc5d2e1eb567aef3077a014a021244ed2ece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Thu, 3 Dec 2009 10:03:19 +0100 Subject: Rename the global limit to g_offset. It is both a limit and an offset (the offset is dictated by the limit), but in the code is it interpreted as an offset. --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index b35ee46..b33e228 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE // they are actually calculated in the interval [0, 2 * limit] // To avoid numerical errors in platforms where we use single precision, // we use a tighter limit for the variables range. -const qreal limit = (sizeof(qreal) == sizeof(double)) ? QWIDGETSIZE_MAX : QWIDGETSIZE_MAX / 32; +const qreal g_offset = (sizeof(qreal) == sizeof(double)) ? QWIDGETSIZE_MAX : QWIDGETSIZE_MAX / 32; QGraphicsAnchorPrivate::QGraphicsAnchorPrivate(int version) : QObjectPrivate(version), layoutPrivate(0), data(0), @@ -2223,7 +2223,7 @@ bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const QList sizeHintConstraints = constraintsFromSizeHints(variables); QList allConstraints = constraints + sizeHintConstraints; - shiftConstraints(allConstraints, limit); + shiftConstraints(allConstraints, g_offset); // Solve min and max size hints qreal min, max; @@ -2248,7 +2248,7 @@ bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const } qDeleteAll(sizeHintConstraints); - shiftConstraints(constraints, -limit); + shiftConstraints(constraints, -g_offset); } else { // No Simplex is necessary because the path was simplified all the way to a single @@ -2279,7 +2279,7 @@ bool QGraphicsAnchorLayoutPrivate::calculateTrunk(Orientation orientation, const bool QGraphicsAnchorLayoutPrivate::calculateNonTrunk(const QList &constraints, const QList &variables) { - shiftConstraints(constraints, limit); + shiftConstraints(constraints, g_offset); bool feasible = solvePreferred(constraints, variables); if (feasible) { @@ -2293,7 +2293,7 @@ bool QGraphicsAnchorLayoutPrivate::calculateNonTrunk(const QList QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin // To use negative variables inside simplex, we shift them so the minimum negative value is // mapped to zero before solving. To make sure that it works, we need to guarantee that the // variables are all inside a certain boundary. - qreal boundedMin = qBound(-limit, ad->minSize, limit); - qreal boundedMax = qBound(-limit, ad->maxSize, limit); + qreal boundedMin = qBound(-g_offset, ad->minSize, g_offset); + qreal boundedMax = qBound(-g_offset, ad->maxSize, g_offset); if ((boundedMin == boundedMax) || qFuzzyCompare(boundedMin, boundedMax)) { QSimplexConstraint *c = new QSimplexConstraint; @@ -2497,7 +2497,7 @@ QList QGraphicsAnchorLayoutPrivate::constraintsFromSizeHin QSimplexConstraint *c = new QSimplexConstraint; c->variables.insert(layoutEdge, 1.0); // The maximum size that the layout can take - c->constant = limit; + c->constant = g_offset; c->ratio = QSimplexConstraint::LessOrEqual; anchorConstraints += c; } @@ -2821,7 +2821,7 @@ bool QGraphicsAnchorLayoutPrivate::solveMinMax(const QList for (iter = path.negatives.constBegin(); iter != path.negatives.constEnd(); ++iter) objective.variables.insert(*iter, -1.0); - const qreal objectiveOffset = (path.positives.count() - path.negatives.count()) * limit; + const qreal objectiveOffset = (path.positives.count() - path.negatives.count()) * g_offset; simplex.setObjective(&objective); // Calculate minimum values @@ -2831,7 +2831,7 @@ bool QGraphicsAnchorLayoutPrivate::solveMinMax(const QList QList variables = getVariables(constraints); for (int i = 0; i < variables.size(); ++i) { AnchorData *ad = static_cast(variables.at(i)); - ad->sizeAtMinimum = ad->result - limit; + ad->sizeAtMinimum = ad->result - g_offset; } // Calculate maximum values @@ -2840,7 +2840,7 @@ bool QGraphicsAnchorLayoutPrivate::solveMinMax(const QList // Save sizeAtMaximum results for (int i = 0; i < variables.size(); ++i) { AnchorData *ad = static_cast(variables.at(i)); - ad->sizeAtMaximum = ad->result - limit; + ad->sizeAtMaximum = ad->result - g_offset; } } return feasible; @@ -2898,7 +2898,7 @@ bool QGraphicsAnchorLayoutPrivate::solvePreferred(const QListvariables.insert(ad, 1.0); - sizeConstraint->constant = ad->prefSize + limit; + sizeConstraint->constant = ad->prefSize + g_offset; // Can easily shrink QPair slack; @@ -2957,7 +2957,7 @@ bool QGraphicsAnchorLayoutPrivate::solvePreferred(const QListsizeAtPreferred = ad->result - limit; + ad->sizeAtPreferred = ad->result - g_offset; } // Make sure we delete the simplex solver -before- we delete the -- cgit v0.12 From 39609930e066f93197d518f33e320b58ae7f618b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Thu, 3 Dec 2009 10:24:20 +0100 Subject: Make lrelease link again with the win32-icc and win32-g++ mkspecs Reviewed-by: Thierry --- tools/linguist/lrelease/lrelease.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/linguist/lrelease/lrelease.pro b/tools/linguist/lrelease/lrelease.pro index b13c03e..6beafa3 100644 --- a/tools/linguist/lrelease/lrelease.pro +++ b/tools/linguist/lrelease/lrelease.pro @@ -16,7 +16,7 @@ include(../../../src/tools/bootstrap/bootstrap.pri) include(../shared/formats.pri) include(../shared/proparser.pri) -win32-msvc*:LIBS += advapi32.lib # for qsettings_win.cpp +win32:LIBS += -ladvapi32 # for qsettings_win.cpp target.path=$$[QT_INSTALL_BINS] INSTALLS += target -- cgit v0.12 From a024829184dcde9b6fdaf5ea884fe7e42efdaf29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Meril=C3=A4?= Date: Thu, 3 Dec 2009 12:18:04 +0200 Subject: QS60Style: Always store changed theme palette When style updates its background brush, it updates QApplication's palette with new background. Also member variable m_backgroundBrush is updated. What is NOT updated is the member variable m_themePalette, which should also contain correct updated palette. This change updates m_themePalette and moves palette updations to occur in one place so that in all use-cases the palettes are modified in a unified way. Task-number: QTBUG-6427 Reviewed-by: Alessandro Portale --- src/gui/styles/qs60style.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index dca78ca..5f7ec69 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -454,9 +454,6 @@ void QS60StylePrivate::setThemePalette(QApplication *app) const Q_UNUSED(app) QPalette widgetPalette = QPalette(Qt::white); setThemePalette(&widgetPalette); - QApplication::setPalette(widgetPalette); //calling QApplication::setPalette clears palette hash - setThemePaletteHash(&widgetPalette); - storeThemePalette(&widgetPalette); } QPalette* QS60StylePrivate::themePalette() @@ -470,8 +467,6 @@ void QS60StylePrivate::setBackgroundTexture(QApplication *app) const QPalette applicationPalette = QApplication::palette(); applicationPalette.setBrush(QPalette::Window, backgroundTexture()); setThemePalette(&applicationPalette); - QApplication::setPalette(applicationPalette); - setThemePaletteHash(&applicationPalette); } void QS60StylePrivate::deleteBackground() @@ -687,6 +682,10 @@ void QS60StylePrivate::setThemePalette(QPalette *palette) const palette->setColor(QPalette::Midlight, palette->color(QPalette::Button).lighter(125)); palette->setColor(QPalette::Mid, palette->color(QPalette::Button).darker(150)); palette->setColor(QPalette::Shadow, Qt::black); + + QApplication::setPalette(*palette); //calling QApplication::setPalette clears palette hash + setThemePaletteHash(palette); + storeThemePalette(palette); } void QS60StylePrivate::deleteThemePalette() -- cgit v0.12 From d672687a3dc79d3b59887986cf4d64cf339d7981 Mon Sep 17 00:00:00 2001 From: Jouni Hiltunen Date: Tue, 24 Nov 2009 16:11:57 +0200 Subject: Unnecessary symbian version checks in sqldrivers.pro Version checks in sqldrivers.pro are not needed. These version checks also fail if symbian version does not match to 3.1 3.2 or 5.0. The included sqlite_symbian.pro checks if the binaries are already present or not. Reviewed-By: Shane Kearns --- src/plugins/sqldrivers/sqldrivers.pro | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/plugins/sqldrivers/sqldrivers.pro b/src/plugins/sqldrivers/sqldrivers.pro index 2bd5f2c..83d71e4 100644 --- a/src/plugins/sqldrivers/sqldrivers.pro +++ b/src/plugins/sqldrivers/sqldrivers.pro @@ -10,6 +10,4 @@ contains(sql-plugins, sqlite) : SUBDIRS += sqlite contains(sql-plugins, sqlite2) : SUBDIRS += sqlite2 contains(sql-plugins, ibase) : SUBDIRS += ibase -contains(S60_VERSION, 3.1)|contains(S60_VERSION, 3.2)|contains(S60_VERSION, 5.0) { - symbian:contains(CONFIG, system-sqlite): SUBDIRS += sqlite_symbian - } +symbian:contains(CONFIG, system-sqlite): SUBDIRS += sqlite_symbian -- cgit v0.12 From 14c01d35cd132bb1a5e5725877d28d5f75c086ab Mon Sep 17 00:00:00 2001 From: Janne Anttila Date: Thu, 3 Dec 2009 13:50:43 +0200 Subject: Fixed "...QString::QString(const char *)... is deprecated" warning. Task-number: QTBUG-6290 Reviewed-by: TrustMe --- src/gui/kernel/qsoftkeymanager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/kernel/qsoftkeymanager.cpp b/src/gui/kernel/qsoftkeymanager.cpp index 1acc9b3..30c67f4 100644 --- a/src/gui/kernel/qsoftkeymanager.cpp +++ b/src/gui/kernel/qsoftkeymanager.cpp @@ -246,7 +246,7 @@ void QSoftKeyManagerPrivate::updateSoftKeys_sys(const QList &softkeys) break; } - int command = (softKeyAction->objectName().contains("_q_menuSoftKeyAction")) + int command = (softKeyAction->objectName().contains(QLatin1String("_q_menuSoftKeyAction"))) ? EAknSoftkeyOptions : s60CommandStart + index; -- cgit v0.12 From 43e4e8969942e58ca0ecb3b8ad23ebe32ac4aa44 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Fri, 4 Dec 2009 11:12:01 +0100 Subject: Fix crash when QGraphicsItem destructor deletes other QGraphicsItem Same fix as e7a10b00be3e4aa197900ecf424e6d44b07248ae Reviewed-by: Alexis --- src/gui/graphicsview/qgraphicsitem.cpp | 4 ++-- tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index bb45e7e..b54596b 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -1341,8 +1341,8 @@ QGraphicsItem::~QGraphicsItem() } if (!d_ptr->children.isEmpty()) { - QList oldChildren = d_ptr->children; - qDeleteAll(oldChildren); + while (!d_ptr->children.isEmpty()) + delete d_ptr->children.first(); Q_ASSERT(d_ptr->children.isEmpty()); } diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp index 38abc3d..32206db 100644 --- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp @@ -1462,6 +1462,7 @@ void tst_QGraphicsScene::focusItemLostFocus() class ClearTestItem : public QGraphicsRectItem { public: + ClearTestItem(QGraphicsItem *parent = 0) : QGraphicsRectItem(parent) {} ~ClearTestItem() { qDeleteAll(items); } QList items; }; @@ -1486,6 +1487,11 @@ void tst_QGraphicsScene::clear() scene.addItem(secondItem); QCOMPARE(scene.items().at(0), firstItem); QCOMPARE(scene.items().at(1), secondItem); + + ClearTestItem *thirdItem = new ClearTestItem(firstItem); + QGraphicsItem *forthItem = new QGraphicsRectItem(firstItem); + thirdItem->items += forthItem; + // must not crash even if firstItem deletes secondItem scene.clear(); QVERIFY(scene.items().isEmpty()); -- cgit v0.12 From a9303804ab9f46c21f6c5592907449876e7e2f89 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Fri, 4 Dec 2009 13:02:18 +0100 Subject: Remove the linux-g++-gles2-experimental mkspec This mkspec has been replaced by linux-g++-maemo. Reviewed-by: Harald Fernengel --- mkspecs/linux-g++-gles2-experimental/qmake.conf | 22 --- .../linux-g++-gles2-experimental/qplatformdefs.h | 166 --------------------- 2 files changed, 188 deletions(-) delete mode 100644 mkspecs/linux-g++-gles2-experimental/qmake.conf delete mode 100644 mkspecs/linux-g++-gles2-experimental/qplatformdefs.h diff --git a/mkspecs/linux-g++-gles2-experimental/qmake.conf b/mkspecs/linux-g++-gles2-experimental/qmake.conf deleted file mode 100644 index 9c28d17..0000000 --- a/mkspecs/linux-g++-gles2-experimental/qmake.conf +++ /dev/null @@ -1,22 +0,0 @@ -# -# Experimental qmake configuration for GLES2 -# - -MAKEFILE_GENERATOR = UNIX -TEMPLATE = app -CONFIG += qt warn_on release incremental link_prl -QT += core gui -QMAKE_INCREMENTAL_STYLE = sublib - -include(../common/g++.conf) - -QMAKE_LFLAGS += -Wl,-rpath-link=/usr/lib - -include(../common/linux.conf) - -QMAKE_LIBS_EGL = -lEGL -QMAKE_LIBS_OPENGL = -lGLESv2 -QMAKE_LIBS_OPENGL_QT = -lGLESv2 -lEGL - - -load(qt_config) diff --git a/mkspecs/linux-g++-gles2-experimental/qplatformdefs.h b/mkspecs/linux-g++-gles2-experimental/qplatformdefs.h deleted file mode 100644 index ecfbc73..0000000 --- a/mkspecs/linux-g++-gles2-experimental/qplatformdefs.h +++ /dev/null @@ -1,166 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the qmake spec of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** No Commercial Usage -** This file contains pre-release code and may not be distributed. -** You may use this file in accordance with the terms and conditions -** contained in the Technology Preview License Agreement accompanying -** this package. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 2.1 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 2.1 requirements -** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** If you have questions regarding the use of this file, please contact -** Nokia at qt-info@nokia.com. -** -** -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QPLATFORMDEFS_H -#define QPLATFORMDEFS_H - -// Get Qt defines/settings - -#include "qglobal.h" - -// Set any POSIX/XOPEN defines at the top of this file to turn on specific APIs - -// 1) need to reset default environment if _BSD_SOURCE is defined -// 2) need to specify POSIX thread interfaces explicitly in glibc 2.0 -// 3) it seems older glibc need this to include the X/Open stuff -#ifndef _GNU_SOURCE -# define _GNU_SOURCE -#endif - -#include - - -// We are hot - unistd.h should have turned on the specific APIs we requested - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifndef QT_NO_IPV6IFNAME -#include -#endif - -#ifdef QT_LARGEFILE_SUPPORT -#define QT_STATBUF struct stat64 -#define QT_STATBUF4TSTAT struct stat64 -#define QT_STAT ::stat64 -#define QT_FSTAT ::fstat64 -#define QT_LSTAT ::lstat64 -#define QT_OPEN ::open64 -#define QT_TRUNCATE ::truncate64 -#define QT_FTRUNCATE ::ftruncate64 -#define QT_LSEEK ::lseek64 -#else -#define QT_STATBUF struct stat -#define QT_STATBUF4TSTAT struct stat -#define QT_STAT ::stat -#define QT_FSTAT ::fstat -#define QT_LSTAT ::lstat -#define QT_OPEN ::open -#define QT_TRUNCATE ::truncate -#define QT_FTRUNCATE ::ftruncate -#define QT_LSEEK ::lseek -#endif - -#ifdef QT_LARGEFILE_SUPPORT -#define QT_FOPEN ::fopen64 -#define QT_FSEEK ::fseeko64 -#define QT_FTELL ::ftello64 -#define QT_FGETPOS ::fgetpos64 -#define QT_FSETPOS ::fsetpos64 -#define QT_MMAP ::mmap64 -#define QT_FPOS_T fpos64_t -#define QT_OFF_T off64_t -#else -#define QT_FOPEN ::fopen -#define QT_FSEEK ::fseek -#define QT_FTELL ::ftell -#define QT_FGETPOS ::fgetpos -#define QT_FSETPOS ::fsetpos -#define QT_MMAP ::mmap -#define QT_FPOS_T fpos_t -#define QT_OFF_T long -#endif - -#define QT_STAT_REG S_IFREG -#define QT_STAT_DIR S_IFDIR -#define QT_STAT_MASK S_IFMT -#define QT_STAT_LNK S_IFLNK -#define QT_SOCKET_CONNECT ::connect -#define QT_SOCKET_BIND ::bind -#define QT_FILENO fileno -#define QT_CLOSE ::close -#define QT_READ ::read -#define QT_WRITE ::write -#define QT_ACCESS ::access -#define QT_GETCWD ::getcwd -#define QT_CHDIR ::chdir -#define QT_MKDIR ::mkdir -#define QT_RMDIR ::rmdir -#define QT_OPEN_LARGEFILE O_LARGEFILE -#define QT_OPEN_RDONLY O_RDONLY -#define QT_OPEN_WRONLY O_WRONLY -#define QT_OPEN_RDWR O_RDWR -#define QT_OPEN_CREAT O_CREAT -#define QT_OPEN_TRUNC O_TRUNC -#define QT_OPEN_APPEND O_APPEND - -#define QT_SIGNAL_RETTYPE void -#define QT_SIGNAL_ARGS int -#define QT_SIGNAL_IGNORE SIG_IGN - -#if defined(__GLIBC__) && (__GLIBC__ >= 2) -#define QT_SOCKLEN_T socklen_t -#else -#define QT_SOCKLEN_T int -#endif - -#if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE >= 500) -#define QT_SNPRINTF ::snprintf -#define QT_VSNPRINTF ::vsnprintf -#endif - - -#endif // QPLATFORMDEFS_H -- cgit v0.12 From 9a76f02a3147c2da969cb1b942ee7228b13c84cc Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Fri, 4 Dec 2009 13:03:21 +0100 Subject: Add QMake configuration for Scratchbox's host-gcc compilera Reviewed-by: Harald Fernengel --- mkspecs/unsupported/linux-host-g++/qmake.conf | 138 +++++++++++++++++++++ mkspecs/unsupported/linux-host-g++/qplatformdefs.h | 42 +++++++ 2 files changed, 180 insertions(+) create mode 100644 mkspecs/unsupported/linux-host-g++/qmake.conf create mode 100644 mkspecs/unsupported/linux-host-g++/qplatformdefs.h diff --git a/mkspecs/unsupported/linux-host-g++/qmake.conf b/mkspecs/unsupported/linux-host-g++/qmake.conf new file mode 100644 index 0000000..237477c --- /dev/null +++ b/mkspecs/unsupported/linux-host-g++/qmake.conf @@ -0,0 +1,138 @@ +# +# QMake configuration for Scratchbox's host-gcc compiler. +# +# This mkspec can be used as the platform mkspec when building +# Qt in scratchbox. If used as such, qmake and similar host +# tools will be compiled for the host architecture (E.g. x86) +# and thus not run in the emulator. This results in a +# significant improvement in build times. +# +# Note: The mkspec copied & pasted parts from common/gcc.conf +# and common/linux.conf as setBootstrapVariable in +# configure has a bug which stops re-assignments working +# for QMake variables (I.e. "QMAKE_foo = bar" is broken). + +MAKEFILE_GENERATOR = UNIX +TEMPLATE = app +CONFIG += qt warn_on release incremental link_prl +QT += core gui +QMAKE_INCREMENTAL_STYLE = sublib + +# +# qmake configuration for common gcc +# + +QMAKE_CC = host-gcc +QMAKE_CFLAGS += -pipe +QMAKE_CFLAGS_DEPS += -M +QMAKE_CFLAGS_WARN_ON += -Wall -W +QMAKE_CFLAGS_WARN_OFF += -w +QMAKE_CFLAGS_RELEASE += -O2 +QMAKE_CFLAGS_DEBUG += -g +QMAKE_CFLAGS_SHLIB += -fPIC +QMAKE_CFLAGS_STATIC_LIB += -fPIC +QMAKE_CFLAGS_YACC += -Wno-unused -Wno-parentheses +QMAKE_CFLAGS_HIDESYMS += -fvisibility=hidden +QMAKE_CFLAGS_PRECOMPILE += -x c-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT} +QMAKE_CFLAGS_USE_PRECOMPILE += -include ${QMAKE_PCH_OUTPUT_BASE} + +QMAKE_CXX = host-g++ +QMAKE_CXXFLAGS += $$QMAKE_CFLAGS +QMAKE_CXXFLAGS_DEPS += $$QMAKE_CFLAGS_DEPS +QMAKE_CXXFLAGS_WARN_ON += $$QMAKE_CFLAGS_WARN_ON +QMAKE_CXXFLAGS_WARN_OFF += $$QMAKE_CFLAGS_WARN_OFF +QMAKE_CXXFLAGS_RELEASE += $$QMAKE_CFLAGS_RELEASE +QMAKE_CXXFLAGS_DEBUG += $$QMAKE_CFLAGS_DEBUG +QMAKE_CXXFLAGS_SHLIB += $$QMAKE_CFLAGS_SHLIB +QMAKE_CXXFLAGS_STATIC_LIB += $$QMAKE_CFLAGS_STATIC_LIB +QMAKE_CXXFLAGS_YACC += $$QMAKE_CFLAGS_YACC +QMAKE_CXXFLAGS_HIDESYMS += $$QMAKE_CFLAGS_HIDESYMS -fvisibility-inlines-hidden +QMAKE_CXXFLAGS_PRECOMPILE += -x c++-header -c ${QMAKE_PCH_INPUT} -o ${QMAKE_PCH_OUTPUT} +QMAKE_CXXFLAGS_USE_PRECOMPILE = $$QMAKE_CFLAGS_USE_PRECOMPILE + +QMAKE_LINK = host-g++ +QMAKE_LINK_SHLIB = host-g++ +QMAKE_LINK_C = host-gcc +QMAKE_LINK_C_SHLIB = host-gcc +QMAKE_LFLAGS += +QMAKE_LFLAGS_RELEASE += -Wl,-O1 +QMAKE_LFLAGS_DEBUG += +QMAKE_LFLAGS_APP += +QMAKE_LFLAGS_SHLIB += -shared +QMAKE_LFLAGS_PLUGIN += $$QMAKE_LFLAGS_SHLIB +QMAKE_LFLAGS_SONAME += -Wl,-soname, +QMAKE_LFLAGS_THREAD += +QMAKE_LFLAGS_NOUNDEF += -Wl,--no-undefined +QMAKE_RPATH = -Wl,-rpath, + +QMAKE_PCH_OUTPUT_EXT = .gch + +# -Bsymbolic-functions (ld) support +QMAKE_LFLAGS_BSYMBOLIC_FUNC = -Wl,-Bsymbolic-functions +QMAKE_LFLAGS_DYNAMIC_LIST = -Wl,--dynamic-list, + +# +# qmake configuration for common linux +# + +QMAKE_CFLAGS_THREAD += -D_REENTRANT +QMAKE_CXXFLAGS_THREAD += $$QMAKE_CFLAGS_THREAD + +QMAKE_INCDIR = +QMAKE_LIBDIR = +QMAKE_INCDIR_X11 = /usr/X11R6/include +QMAKE_LIBDIR_X11 = /usr/X11R6/lib +QMAKE_INCDIR_QT = $$[QT_INSTALL_HEADERS] +QMAKE_LIBDIR_QT = $$[QT_INSTALL_LIBS] +QMAKE_INCDIR_OPENGL = /usr/X11R6/include +QMAKE_LIBDIR_OPENGL = /usr/X11R6/lib +QMAKE_INCDIR_OPENGL_ES1 = $$QMAKE_INCDIR_OPENGL +QMAKE_LIBDIR_OPENGL_ES1 = $$QMAKE_LIBDIR_OPENGL +QMAKE_INCDIR_OPENGL_ES1CL = $$QMAKE_INCDIR_OPENGL +QMAKE_LIBDIR_OPENGL_ES1CL = $$QMAKE_LIBDIR_OPENGL +QMAKE_INCDIR_OPENGL_ES2 = $$QMAKE_INCDIR_OPENGL +QMAKE_LIBDIR_OPENGL_ES2 = $$QMAKE_LIBDIR_OPENGL +QMAKE_INCDIR_EGL = +QMAKE_LIBDIR_EGL = +QMAKE_INCDIR_OPENVG = +QMAKE_LIBDIR_OPENVG = + +QMAKE_LIBS = +QMAKE_LIBS_DYNLOAD = -ldl +QMAKE_LIBS_X11 = -lXext -lX11 -lm +QMAKE_LIBS_X11SM = -lSM -lICE +QMAKE_LIBS_NIS = -lnsl +QMAKE_LIBS_EGL = -lEGL +QMAKE_LIBS_OPENGL = -lGLU -lGL +QMAKE_LIBS_OPENGL_QT = -lGL +QMAKE_LIBS_OPENGL_ES1 = -lGLES_CM +QMAKE_LIBS_OPENGL_ES1CL = -lGLES_CL +QMAKE_LIBS_OPENGL_ES2 = -lGLESv2 +QMAKE_LIBS_OPENVG = -lOpenVG +QMAKE_LIBS_THREAD = -lpthread + +QMAKE_MOC = $$[QT_INSTALL_BINS]/moc +QMAKE_UIC = $$[QT_INSTALL_BINS]/uic + +QMAKE_AR = host-ar cqs +QMAKE_OBJCOPY = host-objcopy +QMAKE_RANLIB = + +QMAKE_TAR = tar -cf +QMAKE_GZIP = gzip -9f + +QMAKE_COPY = cp -f +QMAKE_COPY_FILE = $(COPY) +QMAKE_COPY_DIR = $(COPY) -r +QMAKE_MOVE = mv -f +QMAKE_DEL_FILE = rm -f +QMAKE_DEL_DIR = rmdir +QMAKE_STRIP = host-strip +QMAKE_STRIPFLAGS_LIB += --strip-unneeded +QMAKE_CHK_DIR_EXISTS = test -d +QMAKE_MKDIR = mkdir -p +QMAKE_INSTALL_FILE = install -m 644 -p +QMAKE_INSTALL_PROGRAM = install -m 755 -p + +include(../common/unix.conf) +load(qt_config) diff --git a/mkspecs/unsupported/linux-host-g++/qplatformdefs.h b/mkspecs/unsupported/linux-host-g++/qplatformdefs.h new file mode 100644 index 0000000..60e0f5e --- /dev/null +++ b/mkspecs/unsupported/linux-host-g++/qplatformdefs.h @@ -0,0 +1,42 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the qmake spec of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "../../linux-g++/qplatformdefs.h" -- cgit v0.12 From 62fac968df5fb3632e458aeacfe5a8ef5cfd32bf Mon Sep 17 00:00:00 2001 From: Janne Anttila Date: Fri, 4 Dec 2009 14:23:24 +0200 Subject: Switched S60 QDesktopServices implementation to CDocumentHandler based. RApaLsSession based implementation did not succeed to start music player in some S60 devices to playing mode. The only found solution to this problem was to start using CDocumentHandler based implementation. CDocumentHandler adds a new S60 dependency, but it is needed to make QDesktopServices APIs fully fuonctional. However if Qt is comfigured without S60 we still fallback to RApaLsSession implementation. With CDocumentHandler the files are also opened as embedded, due to the fact that swicthing files in stand-alone mode would require SwEvent capability. Task-number: QTBUG-4699 Reviewed-by: Miikka Heikkinen --- src/gui/util/qdesktopservices_s60.cpp | 72 +++++++++++++++------- .../auto/qdesktopservices/tst_qdesktopservices.cpp | 16 ++++- 2 files changed, 64 insertions(+), 24 deletions(-) diff --git a/src/gui/util/qdesktopservices_s60.cpp b/src/gui/util/qdesktopservices_s60.cpp index 1890d56..c6932de 100644 --- a/src/gui/util/qdesktopservices_s60.cpp +++ b/src/gui/util/qdesktopservices_s60.cpp @@ -41,7 +41,7 @@ // This flag changes the implementation to use S60 CDcoumentHandler // instead of apparch when opening the files -#undef USE_DOCUMENTHANDLER +#define USE_DOCUMENTHANDLER #include #include @@ -58,12 +58,14 @@ #include // RSendAsMessage #ifdef Q_WS_S60 -# include // PathInfo +# include // PathInfo # ifdef USE_DOCUMENTHANDLER -# include // CDocumentHandler +# include // CDocumentHandler +# include # endif -#elif defined(USE_DOCUMENTHANDLER) -# error CDocumentHandler requires support for S60 +#else +# warning CDocumentHandler requires support for S60 +# undef USE_DOCUMENTHANDLER // Fallback to RApaLsSession based implementation #endif QT_BEGIN_NAMESPACE @@ -95,6 +97,42 @@ private: R* mPtr; }; +#ifdef USE_DOCUMENTHANDLER +class QS60DocumentHandler : public MAknServerAppExitObserver +{ +public: + QS60DocumentHandler() :docHandler(0) {} + + ~QS60DocumentHandler() { + delete docHandler; + } + + CDocumentHandler& documentHandler() { + // In case user calls openUrl twice subsequently, before the first embedded app is closed + // we use the same CDocumentHandler instance. Using same instance makes sure the first + // launched embedded app is closed and latter one gets embedded to our app. + // Using different instance would help only theoretically since user cannot interact with + // several embedded apps at the same time. + if(!docHandler) { + QT_TRAP_THROWING(docHandler = CDocumentHandler::NewL()); + docHandler->SetExitObserver(this); + } + return *docHandler; + } + +private: // From MAknServerAppExitObserver + void HandleServerAppExit(TInt /*aReason*/) { + delete docHandler; + docHandler = 0; + } + +private: + CDocumentHandler* docHandler; +}; +Q_GLOBAL_STATIC(QS60DocumentHandler, qt_s60_documenthandler); +#endif + + static void handleMailtoSchemeLX(const QUrl &url) { // this function has many intermingled leaves and throws. Qt and Symbian objects do not have @@ -264,21 +302,9 @@ static void openDocumentL(const TDesC& aUrl) CleanupStack::PopAndDestroy(); // appArcSession #else // This is an alternative way to launch app associated to MIME type - // CDocumentHandler would support opening apps in embedded mode, - // but our Qt application window group seems to always get switched on top of embedded one - // -> Cannot use menus etc of embedded app -> used - - CDocumentHandler* docHandler = CDocumentHandler::NewLC(); + // CDocumentHandler also supports opening apps in embedded mode. TDataType temp; - //Standalone file opening fails for some file-types at least in S60 3.1 emulator - //For example .txt file fails with KErrAlreadyInUse and music files with KERN-EXEC 0 - //Workaround is to use OpenFileEmbeddedL - //docHandler->OpenFileL(aUrl, temp); - - // Opening file with CDocumentHandler will leave if file does not exist - // Leave is trapped in openDocument and false returned to user. - docHandler->OpenFileEmbeddedL(aUrl, temp); - CleanupStack::PopAndDestroy(docHandler); + qt_s60_documenthandler()->documentHandler().OpenFileEmbeddedL(aUrl, temp); #endif } @@ -349,7 +375,7 @@ QString QDesktopServices::storageLocation(StandardLocation type) case DesktopLocation: qWarning("No desktop concept in Symbian OS"); // But lets still use some feasible default - path.Append(writableDataRoot()); + path.Append(writableDataRoot()); break; case DocumentsLocation: path.Append(writableDataRoot()); @@ -380,7 +406,7 @@ QString QDesktopServices::storageLocation(StandardLocation type) #endif break; case TempLocation: - return QDir::tempPath(); + return QDir::tempPath(); break; case HomeLocation: path.Append(writableDataRoot()); @@ -394,10 +420,10 @@ QString QDesktopServices::storageLocation(StandardLocation type) CEikonEnv::Static()->FsSession().PrivatePath(path); path.Insert(0, writableExeDrive().Name()); path.Append(KCacheSubDir); - break; + break; default: // Lets use feasible default - path.Append(writableDataRoot()); + path.Append(writableDataRoot()); break; } diff --git a/tests/auto/qdesktopservices/tst_qdesktopservices.cpp b/tests/auto/qdesktopservices/tst_qdesktopservices.cpp index 2d9e5dc..c105a97 100644 --- a/tests/auto/qdesktopservices/tst_qdesktopservices.cpp +++ b/tests/auto/qdesktopservices/tst_qdesktopservices.cpp @@ -70,6 +70,7 @@ private slots: void openMailtoUrl(); void openFileUrl_data(); void openFileUrl(); + void openMultipleFileUrls(); #endif void handlers(); void storageLocation_data(); @@ -197,6 +198,7 @@ void tst_qdesktopservices::openMailtoUrl() QFETCH(QUrl, url); QFETCH(bool, result); QCOMPARE(QDesktopServices::openUrl(url), result); + QTest::qWait(5000); } void tst_qdesktopservices::openFileUrl_data() @@ -239,7 +241,19 @@ void tst_qdesktopservices::openFileUrl() QFETCH(QUrl, url); QFETCH(bool, result); QCOMPARE(QDesktopServices::openUrl(url), result); - QTest::qWait(15000); + QTest::qWait(5000); +} + +void tst_qdesktopservices::openMultipleFileUrls() +{ +#ifndef RUN_MANUAL_TESTS + QSKIP("Test disabled -- only for manual purposes", SkipAll); +#endif + + QCOMPARE(QDesktopServices::openUrl(QUrl("file:///c:/data/images/image.bmp")), true); + QCOMPARE(QDesktopServices::openUrl(QUrl("file:///c:/data/images/image.png")), true); + QCOMPARE(QDesktopServices::openUrl(QUrl("file:///c:/data/others/noendofline.txt")), true); + QCOMPARE(QDesktopServices::openUrl(QUrl("file:///c:/data/installs/ErrRd.sisx")), true); } #endif -- cgit v0.12 From fe785ec5fa818b3b31777d22b434621522a532b4 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Fri, 4 Dec 2009 15:07:41 +0200 Subject: MMP_RULES overriding qmake variables now warns user Added warning to qmake when it detects MMP_RULES that override MMP statements created by qmake variables. Also harmonized the way << operator is used with #defined strings in symmake.cpp. Task-number: QTBUG-5407 Reviewed-by: Janne Anttila --- qmake/generators/symbian/symmake.cpp | 152 ++++++++++++++++++++++++----------- qmake/generators/symbian/symmake.h | 9 ++- 2 files changed, 111 insertions(+), 50 deletions(-) diff --git a/qmake/generators/symbian/symmake.cpp b/qmake/generators/symbian/symmake.cpp index afaf338..8379ed9 100644 --- a/qmake/generators/symbian/symmake.cpp +++ b/qmake/generators/symbian/symmake.cpp @@ -77,6 +77,15 @@ #define MMP_LINKEROPTION_CW "LINKEROPTION CW" #define MMP_LINKEROPTION_ARMCC "LINKEROPTION ARMCC" #define MMP_LINKEROPTION_GCCE "LINKEROPTION GCCE" +#define MMP_CAPABILITY "CAPABILITY" +#define MMP_EPOCALLOWDLLDATA "EPOCALLOWDLLDATA" +#define MMP_EPOCHEAPSIZE "EPOCHEAPSIZE" +#define MMP_EPOCSTACKSIZE "EPOCSTACKSIZE" +#define MMP_UID "UID" +#define MMP_VENDORID "VENDORID" +#define MMP_VERSION "VERSION" +#define MMP_START_RESOURCE "START RESOURCE" +#define MMP_END_RESOURCE "END" #define SIS_TARGET "sis" #define OK_SIS_TARGET "ok_sis" @@ -155,7 +164,7 @@ void SymbianMakefileGenerator::writeHeader(QTextStream &t) { t << "// ============================================================================" << endl; t << "// * Makefile for building: " << escapeFilePath(var("TARGET")) << endl; - t << "// * Generated by qmake (" << qmake_version() << ") (Qt " << QT_VERSION_STR << ") on: "; + t << "// * Generated by qmake (" << qmake_version() << ") (Qt " QT_VERSION_STR ") on: "; t << QDateTime::currentDateTime().toString(Qt::ISODate) << endl; t << "// * This file is generated by qmake and should not be modified by the" << endl; t << "// * user." << endl; @@ -444,7 +453,7 @@ void SymbianMakefileGenerator::writeCustomDefFile() QTextStream t(&ft); t << "; ==============================================================================" << endl; - t << "; Generated by qmake (" << qmake_version() << ") (Qt " << QT_VERSION_STR << ") on: "; + t << "; Generated by qmake (" << qmake_version() << ") (Qt " QT_VERSION_STR ") on: "; t << QDateTime::currentDateTime().toString(Qt::ISODate) << endl; t << "; This file is generated by qmake and should not be modified by the" << endl; t << "; user." << endl; @@ -646,30 +655,76 @@ void SymbianMakefileGenerator::initMmpVariables() // Check MMP_RULES for singleton keywords that are overridden QStringList overridableMmpKeywords; + QStringList restrictableMmpKeywords; + QStringList restrictedMmpKeywords; + bool inResourceBlock = false; + overridableMmpKeywords << QLatin1String(MMP_TARGETTYPE); + restrictableMmpKeywords << QLatin1String(MMP_TARGET) << QLatin1String(MMP_SECUREID) + << QLatin1String(MMP_OPTION_CW) << QLatin1String(MMP_OPTION_ARMCC) + << QLatin1String(MMP_OPTION_GCCE) << QLatin1String(MMP_LINKEROPTION_CW) + << QLatin1String(MMP_LINKEROPTION_ARMCC) << QLatin1String(MMP_LINKEROPTION_GCCE) + << QLatin1String(MMP_CAPABILITY) << QLatin1String(MMP_EPOCALLOWDLLDATA) + << QLatin1String(MMP_EPOCHEAPSIZE) << QLatin1String(MMP_EPOCSTACKSIZE) + << QLatin1String(MMP_UID) << QLatin1String(MMP_VENDORID) + << QLatin1String(MMP_VERSION); foreach (QString item, project->values("MMP_RULES")) { if (project->values(item).isEmpty()) { - checkOverridability(overridableMmpKeywords, item); + handleMmpRulesOverrides(item, inResourceBlock, restrictedMmpKeywords, + restrictableMmpKeywords, overridableMmpKeywords); } else { foreach (QString itemRow, project->values(item)) { - checkOverridability(overridableMmpKeywords, itemRow); + handleMmpRulesOverrides(itemRow, inResourceBlock, restrictedMmpKeywords, + restrictableMmpKeywords, overridableMmpKeywords); } } } + + if (restrictedMmpKeywords.size()) { + fprintf(stderr, "Warning: Restricted statements detected in MMP_RULES:\n" + " (%s)\n" + " Use corresponding qmake variable(s) instead.\n", + qPrintable(restrictedMmpKeywords.join(", "))); + } } -void SymbianMakefileGenerator::checkOverridability(QStringList &overridableKeywords, QString &checkString) +void SymbianMakefileGenerator::handleMmpRulesOverrides(QString &checkString, + bool &inResourceBlock, + QStringList &restrictedMmpKeywords, + const QStringList &restrictableMmpKeywords, + const QStringList &overridableMmpKeywords) { - // Check if checkString contains overridable keyword and - // add the keyword to overridden keywords list if so. QString simplifiedString = checkString.simplified(); - foreach (QString item, overridableKeywords) { - if (simplifiedString.startsWith(item)) - appendIfnotExist(overriddenMmpKeywords, item); + + if (!inResourceBlock && simplifiedString.startsWith(MMP_START_RESOURCE, Qt::CaseInsensitive)) + inResourceBlock = true; + else if (inResourceBlock && simplifiedString.startsWith(MMP_END_RESOURCE, Qt::CaseInsensitive)) + inResourceBlock = false; + + // Allow restricted and overridable items in RESOURCE blocks as those do not actually + // override anything. + if (!inResourceBlock) { + appendKeywordIfMatchFound(overriddenMmpKeywords, overridableMmpKeywords, simplifiedString); + appendKeywordIfMatchFound(restrictedMmpKeywords, restrictableMmpKeywords, simplifiedString); + } +} + +void SymbianMakefileGenerator::appendKeywordIfMatchFound(QStringList &list, + const QStringList &keywordList, + QString &checkString) +{ + // Check if checkString starts with any supplied keyword and + // add the found keyword to list if it does. + foreach (QString item, keywordList) { + if (checkString.startsWith(QString(item).append(" "), Qt::CaseInsensitive) + || checkString.compare(item, Qt::CaseInsensitive) == 0) { + appendIfnotExist(list, item); + } } } + bool SymbianMakefileGenerator::removeDuplicatedStrings(QStringList &stringList) { QStringList tmpStringList; @@ -690,7 +745,7 @@ bool SymbianMakefileGenerator::removeDuplicatedStrings(QStringList &stringList) void SymbianMakefileGenerator::writeMmpFileHeader(QTextStream &t) { t << "// ==============================================================================" << endl; - t << "// Generated by qmake (" << qmake_version() << ") (Qt " << QT_VERSION_STR << ") on: "; + t << "// Generated by qmake (" << qmake_version() << ") (Qt " QT_VERSION_STR ") on: "; t << QDateTime::currentDateTime().toString(Qt::ISODate) << endl; t << "// This file is generated by qmake and should not be modified by the" << endl; t << "// user." << endl; @@ -775,7 +830,7 @@ void SymbianMakefileGenerator::writeMmpFileMacrosPart(QTextStream& t) void SymbianMakefileGenerator::addMacro(QTextStream& t, const QString& value) { - t << "MACRO" << "\t\t" << value << endl; + t << "MACRO\t\t" << value << endl; } @@ -784,28 +839,28 @@ void SymbianMakefileGenerator::writeMmpFileTargetPart(QTextStream& t) bool skipTargetType = overriddenMmpKeywords.contains(MMP_TARGETTYPE); if (targetType == TypeExe) { - t << MMP_TARGET << "\t\t" << fixedTarget << ".exe" << endl; + t << MMP_TARGET "\t\t" << fixedTarget << ".exe" << endl; if (!skipTargetType) { if (project->values("CONFIG").contains("stdbinary", Qt::CaseInsensitive)) - t << MMP_TARGETTYPE << "\t\t" << "STDEXE" << endl; + t << MMP_TARGETTYPE "\t\tSTDEXE" << endl; else - t << MMP_TARGETTYPE << "\t\t" << "EXE" << endl; + t << MMP_TARGETTYPE "\t\tEXE" << endl; } } else if (targetType == TypeDll || targetType == TypePlugin) { - t << MMP_TARGET << "\t\t" << fixedTarget << ".dll" << endl; + t << MMP_TARGET "\t\t" << fixedTarget << ".dll" << endl; if (!skipTargetType) { if (project->values("CONFIG").contains("stdbinary", Qt::CaseInsensitive)) - t << MMP_TARGETTYPE << "\t\t" << "STDDLL" << endl; + t << MMP_TARGETTYPE "\t\tSTDDLL" << endl; else - t << MMP_TARGETTYPE << "\t\t" << "DLL" << endl; + t << MMP_TARGETTYPE "\t\tDLL" << endl; } } else if (targetType == TypeLib) { - t << MMP_TARGET << "\t\t" << fixedTarget << ".lib" << endl; + t << MMP_TARGET "\t\t" << fixedTarget << ".lib" << endl; if (!skipTargetType) { if (project->values("CONFIG").contains("stdbinary", Qt::CaseInsensitive)) - t << MMP_TARGETTYPE << "\t\t" << "STDLIB" << endl; + t << MMP_TARGETTYPE "\t\tSTDLIB" << endl; else - t << MMP_TARGETTYPE << "\t\t" << "LIB" << endl; + t << MMP_TARGETTYPE "\t\tLIB" << endl; } } else { fprintf(stderr, "Error: Unexpected targettype (%d) in SymbianMakefileGenerator::writeMmpFileTargetPart\n", targetType); @@ -813,30 +868,30 @@ void SymbianMakefileGenerator::writeMmpFileTargetPart(QTextStream& t) t << endl; - t << "UID" << "\t\t" << uid2 << " " << uid3 << endl; + t << MMP_UID "\t\t" << uid2 << " " << uid3 << endl; if (0 != project->values("TARGET.SID").size()) { - t << MMP_SECUREID << "\t\t" << project->values("TARGET.SID").join(" ") << endl; + t << MMP_SECUREID "\t\t" << project->values("TARGET.SID").join(" ") << endl; } else { if (0 == uid3.size()) - t << MMP_SECUREID << "\t\t" << "0" << endl; + t << MMP_SECUREID "\t\t0" << endl; else - t << MMP_SECUREID << "\t\t" << uid3 << endl; + t << MMP_SECUREID "\t\t" << uid3 << endl; } // default value used from mkspecs is 0 if (0 != project->values("TARGET.VID").size()) { - t << "VENDORID" << "\t\t" << project->values("TARGET.VID").join(" ") << endl; + t << MMP_VENDORID "\t\t" << project->values("TARGET.VID").join(" ") << endl; } t << endl; if (0 != project->first("TARGET.EPOCSTACKSIZE").size()) - t << "EPOCSTACKSIZE" << "\t\t" << project->first("TARGET.EPOCSTACKSIZE") << endl; + t << MMP_EPOCSTACKSIZE "\t\t" << project->first("TARGET.EPOCSTACKSIZE") << endl; if (0 != project->values("TARGET.EPOCHEAPSIZE").size()) - t << "EPOCHEAPSIZE" << "\t\t" << project->values("TARGET.EPOCHEAPSIZE").join(" ") << endl; + t << MMP_EPOCHEAPSIZE "\t\t" << project->values("TARGET.EPOCHEAPSIZE").join(" ") << endl; if (0 != project->values("TARGET.EPOCALLOWDLLDATA").size()) - t << "EPOCALLOWDLLDATA" << endl; + t << MMP_EPOCALLOWDLLDATA << endl; if (targetType == TypePlugin && !project->values("CONFIG").contains("stdbinary", Qt::CaseInsensitive)) { // Use custom def file for Qt plugins @@ -865,20 +920,20 @@ void SymbianMakefileGenerator::writeMmpFileResourcePart(QTextStream& t, QStringL t << lang << " "; // no endl } t << endl; - t << "START RESOURCE\t\t" << locTarget << endl; + t << MMP_START_RESOURCE "\t\t" << locTarget << endl; t << "HEADER" << endl; t << "TARGETPATH\t\t\t" RESOURCE_DIRECTORY_MMP << endl; - t << "END" << endl << endl; + t << MMP_END_RESOURCE << endl << endl; QString regTarget = fixedTarget; regTarget.append("_reg.rss"); t << "SOURCEPATH\t\t\t." << endl; - t << "START RESOURCE\t\t" << regTarget << endl; + t << MMP_START_RESOURCE "\t\t" << regTarget << endl; if (isForSymbianSbsv2()) t << "DEPENDS " << fixedTarget << ".rsg" << endl; t << "TARGETPATH\t\t" REGISTRATION_RESOURCE_DIRECTORY_HW << endl; - t << "END" << endl << endl; + t << MMP_END_RESOURCE << endl << endl; } } @@ -890,7 +945,7 @@ void SymbianMakefileGenerator::writeMmpFileSystemIncludePart(QTextStream& t) QStringList values = it.value(); for (int i = 0; i < values.size(); ++i) { QString handledPath = values.at(i); - t << "SYSTEMINCLUDE" << "\t\t" << fixPathForMmp(handledPath, current) << endl; + t << "SYSTEMINCLUDE\t\t" << fixPathForMmp(handledPath, current) << endl; } } @@ -946,14 +1001,14 @@ void SymbianMakefileGenerator::writeMmpFileCapabilityPart(QTextStream& t) { if (0 != project->first("TARGET.CAPABILITY").size()) { QStringList &capabilities = project->values("TARGET.CAPABILITY"); - t << "CAPABILITY" << "\t\t"; + t << MMP_CAPABILITY "\t\t"; for (int i = 0; i < capabilities.size(); ++i) { QString cap = capabilities.at(i); t << cap << " "; } } else { - t << "CAPABILITY" << "\t\t" << "None"; + t << MMP_CAPABILITY "\t\tNone"; } t << endl << endl; } @@ -1048,21 +1103,21 @@ void SymbianMakefileGenerator::writeMmpFileCompilerOptionPart(QTextStream& t) if (!gccelink.isEmpty() && gccelink[gccelink.size()-1] == ' ') gccelink.chop(1); - if (!cw.isEmpty() && !overriddenMmpKeywords.contains(MMP_OPTION_CW)) + if (!cw.isEmpty()) t << MMP_OPTION_CW " " << cw << endl; - if (!armcc.isEmpty() && !overriddenMmpKeywords.contains(MMP_OPTION_ARMCC)) + if (!armcc.isEmpty()) t << MMP_OPTION_ARMCC " " << armcc << endl; - if (!gcce.isEmpty() && !overriddenMmpKeywords.contains(MMP_OPTION_GCCE)) + if (!gcce.isEmpty()) t << MMP_OPTION_GCCE " " << gcce << endl; - if (!cwlink.isEmpty() && !overriddenMmpKeywords.contains(MMP_LINKEROPTION_CW)) + if (!cwlink.isEmpty()) t << MMP_LINKEROPTION_CW " " << cwlink << endl; - if (!armlink.isEmpty() && !overriddenMmpKeywords.contains(MMP_LINKEROPTION_ARMCC)) + if (!armlink.isEmpty()) t << MMP_LINKEROPTION_ARMCC " " << armlink << endl; - if (!gccelink.isEmpty() && !overriddenMmpKeywords.contains(MMP_LINKEROPTION_GCCE)) + if (!gccelink.isEmpty()) t << MMP_LINKEROPTION_GCCE " " << gccelink << endl; - t << endl; + t << endl; } void SymbianMakefileGenerator::writeMmpFileBinaryVersionPart(QTextStream& t) @@ -1098,7 +1153,7 @@ void SymbianMakefileGenerator::writeMmpFileBinaryVersionPart(QTextStream& t) mmpVersion = "10.0"; // Default binary version for symbian is 10.0 } - t << "VERSION " << mmpVersion << endl; + t << MMP_VERSION " " << mmpVersion << endl; } void SymbianMakefileGenerator::writeMmpFileRulesPart(QTextStream& t) @@ -1265,7 +1320,7 @@ void SymbianMakefileGenerator::writeRegRssFile(QStringList &userItems) generatedFiles << ft.fileName(); QTextStream t(&ft); t << "// ============================================================================" << endl; - t << "// * Generated by qmake (" << qmake_version() << ") (Qt " << QT_VERSION_STR << ") on: "; + t << "// * Generated by qmake (" << qmake_version() << ") (Qt " QT_VERSION_STR ") on: "; t << QDateTime::currentDateTime().toString(Qt::ISODate) << endl; t << "// * This file is generated by qmake and should not be modified by the" << endl; t << "// * user." << endl; @@ -1274,8 +1329,7 @@ void SymbianMakefileGenerator::writeRegRssFile(QStringList &userItems) t << "#include <" << fixedTarget << ".rsg>" << endl; t << "#include " << endl; t << endl; - //t << "#include " << "\n" << endl; - t << "UID2 " << "KUidAppRegistrationResourceFile" << endl; + t << "UID2 KUidAppRegistrationResourceFile" << endl; t << "UID3 " << uid3 << endl << endl; t << "RESOURCE APP_REGISTRATION_INFO" << endl; t << "\t{" << endl; @@ -1300,7 +1354,7 @@ void SymbianMakefileGenerator::writeRssFile(QString &numberOfIcons, QString &ico generatedFiles << ft.fileName(); QTextStream t(&ft); t << "// ============================================================================" << endl; - t << "// * Generated by qmake (" << qmake_version() << ") (Qt " << QT_VERSION_STR << ") on: "; + t << "// * Generated by qmake (" << qmake_version() << ") (Qt " QT_VERSION_STR ") on: "; t << QDateTime::currentDateTime().toString(Qt::ISODate) << endl; t << "// * This file is generated by qmake and should not be modified by the" << endl; t << "// * user." << endl; @@ -1346,7 +1400,7 @@ void SymbianMakefileGenerator::writeLocFile(QStringList &symbianLangCodes) generatedFiles << ft.fileName(); QTextStream t(&ft); t << "// ============================================================================" << endl; - t << "// * Generated by qmake (" << qmake_version() << ") (Qt " << QT_VERSION_STR << ") on: "; + t << "// * Generated by qmake (" << qmake_version() << ") (Qt " QT_VERSION_STR ") on: "; t << QDateTime::currentDateTime().toString(Qt::ISODate) << endl; t << "// * This file is generated by qmake and should not be modified by the" << endl; t << "// * user." << endl; diff --git a/qmake/generators/symbian/symmake.h b/qmake/generators/symbian/symmake.h index 2e78c46..1a20e64 100644 --- a/qmake/generators/symbian/symmake.h +++ b/qmake/generators/symbian/symmake.h @@ -96,7 +96,14 @@ protected: QString generateUID3(); void initMmpVariables(); - void checkOverridability(QStringList &overridableKeywords, QString &checkString); + void handleMmpRulesOverrides(QString &checkString, + bool &inResourceBlock, + QStringList &restrictedMmpKeywords, + const QStringList &restrictableMmpKeywords, + const QStringList &overridableMmpKeywords); + void appendKeywordIfMatchFound(QStringList &list, + const QStringList &keywordList, + QString &checkString); void writeHeader(QTextStream &t); void writeBldInfContent(QTextStream& t, bool addDeploymentExtension, const QString &iconFile); -- cgit v0.12 From 91921c880ea53a096237435ffac571a193f9c5f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Meril=C3=A4?= Date: Fri, 4 Dec 2009 15:34:35 +0200 Subject: QS60Style: Overwrites correct stylehint color values QS60Style overwrites correct theme colors with QCommonStyle values in QS60Style::styleHint(). In that method returned value is initialized as -1 and then if the value is still -1 after switch statement for different stylehints, the stylehint is queried from common style. Problem is that it is also getting RGB values set into return value. White color as HEX is FFFFFF and -1 as HEX is FFFFFF. So, if theme color is white for Group Text title, or for Grid lines, color is asked from QCommonStyle instead. As a fix, in 'default' case ask from QCommonStyle. Also, use RGBA instead of RGB values. Reviewed-by: Alessandro Portale --- src/gui/styles/qs60style.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index 5f7ec69..aece73c 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -2343,10 +2343,10 @@ int QS60Style::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w int retValue = -1; switch (sh) { case SH_Table_GridLineColor: - retValue = QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors,2,0).rgb(); + retValue = int(QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnLineColors,2,0).rgba()); break; case SH_GroupBox_TextLabelColor: - retValue = QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors,6,0).rgb(); + retValue = int(QS60StylePrivate::s60Color(QS60StyleEnums::CL_QsnTextColors,6,0).rgba()); break; case SH_ScrollBar_ScrollWhenPointerLeavesControl: retValue = true; @@ -2402,10 +2402,9 @@ int QS60Style::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w retValue = QFormLayout::WrapLongRows; break; default: + retValue = QCommonStyle::styleHint(sh, opt, widget, hret); break; } - if (retValue == -1) - retValue = QCommonStyle::styleHint(sh, opt, widget, hret); return retValue; } -- cgit v0.12 From 63318f834671552add4fd584e5aae80523b5f007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Meril=C3=A4?= Date: Fri, 4 Dec 2009 16:05:34 +0200 Subject: Button and LineEdit/TextEdit theme colors are incorrect QS60Style fetches incorrect color values from theme when using buttons and lineEdits/TextEdits. New values are the same as in native widgets (verified from native widget code). Task-number: QTBUG-6364 Reviewed-by: Alessandro Portale --- src/gui/styles/qs60style.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gui/styles/qs60style.cpp b/src/gui/styles/qs60style.cpp index aece73c..be4f15a 100644 --- a/src/gui/styles/qs60style.cpp +++ b/src/gui/styles/qs60style.cpp @@ -654,7 +654,7 @@ void QS60StylePrivate::setThemePalette(QPalette *palette) const palette->setColor(QPalette::WindowText, s60Color(QS60StyleEnums::CL_QsnTextColors, 6, 0)); palette->setColor(QPalette::ButtonText, - s60Color(QS60StyleEnums::CL_QsnTextColors, 6, 0)); + s60Color(QS60StyleEnums::CL_QsnTextColors, 20, 0)); palette->setColor(QPalette::Text, s60Color(QS60StyleEnums::CL_QsnTextColors, 6, 0)); palette->setColor(QPalette::ToolTipText, @@ -753,13 +753,15 @@ void QS60StylePrivate::setThemePaletteHash(QPalette *palette) const QApplication::setPalette(widgetPalette, "QTableView"); widgetPalette = *palette; + widgetPalette.setColor(QPalette::Text, + s60Color(QS60StyleEnums::CL_QsnTextColors, 27, 0)); widgetPalette.setColor(QPalette::HighlightedText, s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0)); QApplication::setPalette(widgetPalette, "QLineEdit"); widgetPalette = *palette; widgetPalette.setColor(QPalette::Text, - s60Color(QS60StyleEnums::CL_QsnTextColors, 34, 0)); + s60Color(QS60StyleEnums::CL_QsnTextColors, 27, 0)); widgetPalette.setColor(QPalette::HighlightedText, s60Color(QS60StyleEnums::CL_QsnTextColors, 24, 0)); QApplication::setPalette(widgetPalette, "QTextEdit"); -- cgit v0.12 From ac83e69ffbabff8a5e674d38f0bc90ff5f188f6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Fri, 4 Dec 2009 11:24:27 +0100 Subject: Made sure that we didn't reference dangling parallel anchors. We cannot delete the parallel anchors before we do the actual vertex restoration, since the parallel anchors created by vertex simplification will always be connected to some of the AnchorVertexPair found in simplifiedVertices that we iterate over later. Thus, we must delete the parallel anchors created by vertex simplification after we have done the restoration of the vertices. (the parallel anchor will be properly dealt with (i.e. taken out of the graph as we do the restoration)), so not deleting it won't cause it to be revisited later if that is a worry. Reviewed-by: Eduardo M. Fleury --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index b33e228..03ed63d 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -1317,9 +1317,7 @@ void QGraphicsAnchorLayoutPrivate::restoreVertices(Orientation orientation) for (int i = parallelAnchors.count() - 1; i >= 0; --i) { ParallelAnchorData *parallel = static_cast(parallelAnchors.at(i)); restoreSimplifiedConstraints(parallel); - delete parallel; } - parallelAnchors.clear(); // Then, we will restore the vertices in the inverse order of creation, this way we ensure that // the vertex being restored was not wrapped by another simplification. @@ -1365,6 +1363,8 @@ void QGraphicsAnchorLayoutPrivate::restoreVertices(Orientation orientation) delete pair; } + qDeleteAll(parallelAnchors); + parallelAnchors.clear(); toRestore.clear(); } -- cgit v0.12 From 39392326c8c843a6f46b864c6595a5241a47af10 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Fri, 4 Dec 2009 15:57:18 +0100 Subject: Fixes clipping bug in the embedded dialogs demo. The problem was that when using DeviceCoordinateCache for items in a scene, newly exposed areas were wrongly painted over the Pixmap in the cache, instead of blending into it. Autotest included. Task-number: QTBUG-657 Reviewed-by: Andreas Reviewed-by: bnilsen --- src/gui/graphicsview/qgraphicsscene.cpp | 1 - tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp | 39 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/gui/graphicsview/qgraphicsscene.cpp b/src/gui/graphicsview/qgraphicsscene.cpp index 8777cdc..27ebb79 100644 --- a/src/gui/graphicsview/qgraphicsscene.cpp +++ b/src/gui/graphicsview/qgraphicsscene.cpp @@ -4233,7 +4233,6 @@ static void _q_paintIntoCache(QPixmap *pix, QGraphicsItem *item, const QRegion & if (!subPix.isNull()) { // Blit the subpixmap into the main pixmap. pixmapPainter.begin(pix); - pixmapPainter.setCompositionMode(QPainter::CompositionMode_Source); pixmapPainter.setClipRegion(pixmapExposed); pixmapPainter.drawPixmap(br.topLeft(), subPix); pixmapPainter.end(); diff --git a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp index 32206db..c5e57f7 100644 --- a/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/qgraphicsscene/tst_qgraphicsscene.cpp @@ -280,6 +280,7 @@ private slots: void task160653_selectionChanged(); void task250680_childClip(); void taskQTBUG_5904_crashWithDeviceCoordinateCache(); + void taskQT657_paintIntoCacheWithTransparentParts(); }; void tst_QGraphicsScene::initTestCase() @@ -4270,5 +4271,43 @@ void tst_QGraphicsScene::taskQTBUG_5904_crashWithDeviceCoordinateCache() // No crash, then it passed! } +void tst_QGraphicsScene::taskQT657_paintIntoCacheWithTransparentParts() +{ + QWidget *w = new QWidget(); + w->setPalette(Qt::blue); + w->setGeometry(0, 0, 50, 50); + + QGraphicsScene *scene = new QGraphicsScene(); + QGraphicsView *view = new QGraphicsView(scene); + + QGraphicsProxyWidget *proxy = scene->addWidget(w); + proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache); + proxy->rotate(15); + + view->show(); + QTest::qWaitForWindowShown(view); + w->update(10,10,10,10); + QTest::qWait(50); + + QPixmap pix; + QGraphicsItemPrivate* itemp = QGraphicsItemPrivate::get(proxy); + QPixmapCache::Key key = itemp->extraItemCache()->deviceData.value(view->viewport()).key; + QVERIFY(QPixmapCache::find(key, &pix)); + + QTransform t = proxy->sceneTransform(); + // Map from scene coordinates to pixmap coordinates. + // X origin in the pixmap is the most-left point + // of the item's boundingRect in the scene. + qreal adjust = t.mapRect(proxy->boundingRect().toRect()).left(); + QRect rect = t.mapRect(QRect(10, 10, 10, 10)).adjusted(-adjust, 0, -adjust + 1, 1); + QPixmap subpix = pix.copy(rect); + + QImage im = subpix.toImage(); + for(int i = 0; i < im.width(); i++) { + for(int j = 0; j < im.height(); j++) + QCOMPARE(qAlpha(im.pixel(i, j)), 255); + } +} + QTEST_MAIN(tst_QGraphicsScene) #include "tst_qgraphicsscene.moc" -- cgit v0.12 From 2e3ecbb0b401aa29d4bbc2fe5df8cfb9f541a693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Fri, 4 Dec 2009 16:16:49 +0100 Subject: Make sure that QtGui links with QtCore for the win32-icc mkspec. Fix it by exporting QObjectData. Since this is a compiler bug we will only export it for the compiler that has this problem. (Intel Compiler on Windows) The Intel compiler seems to inline the destructor of QObject (or at least parts of it) even if it is declared virtual. Thus, it seems that the destruction of the QScopedPointer member is inlined into QtGui, and that code will eventually call the destructor of QObjectData, and since QObjectData was not exported from QtCore it would crash. Reviewed-by: Olivier Goffart --- src/corelib/kernel/qobject.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index 340498f..68475e5 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -91,7 +91,11 @@ template inline QList qFindChildren(const QObject *, const QRegEx # endif #endif +#if defined(__INTEL_COMPILER) && defined(Q_OS_WIN) +class Q_CORE_EXPORT QObjectData { +#else class QObjectData { +#endif public: virtual ~QObjectData() = 0; QObject *q_ptr; -- cgit v0.12 From b00b1c660beeb861ed3ce618ee30a3c46c95cfa2 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Fri, 4 Dec 2009 17:34:14 +0100 Subject: Fix toolbar animation when restoring from expanded state Task-number: QTBUG-6529 Reviewed-by: Gabi --- src/gui/widgets/qtoolbar.cpp | 2 +- src/gui/widgets/qtoolbarlayout.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/widgets/qtoolbar.cpp b/src/gui/widgets/qtoolbar.cpp index 58a3d28..c0ca015 100644 --- a/src/gui/widgets/qtoolbar.cpp +++ b/src/gui/widgets/qtoolbar.cpp @@ -396,10 +396,10 @@ bool QToolBarPrivate::mouseMoveEvent(QMouseEvent *event) void QToolBarPrivate::unplug(const QRect &_r) { Q_Q(QToolBar); - layout->setExpanded(false); QRect r = _r; r.moveTopLeft(q->mapToGlobal(QPoint(0, 0))); setWindowState(true, true, r); + layout->setExpanded(false); } void QToolBarPrivate::plug(const QRect &r) diff --git a/src/gui/widgets/qtoolbarlayout.cpp b/src/gui/widgets/qtoolbarlayout.cpp index 0afe5d8..93429e4 100644 --- a/src/gui/widgets/qtoolbarlayout.cpp +++ b/src/gui/widgets/qtoolbarlayout.cpp @@ -654,6 +654,7 @@ void QToolBarLayout::setExpanded(bool exp) if (!tb) return; if (QMainWindow *win = qobject_cast(tb->parentWidget())) { + animating = !tb->isWindow() && win->isAnimated(); QMainWindowLayout *layout = qobject_cast(win->layout()); if (expanded) { tb->raise(); @@ -664,7 +665,7 @@ void QToolBarLayout::setExpanded(bool exp) layoutActions(rect.size()); } } - layout->layoutState.toolBarAreaLayout.apply(win->isAnimated()); + layout->layoutState.toolBarAreaLayout.apply(animating); } } -- cgit v0.12 From bed10148f651cca2a7376a637267a31ef7c87064 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Fri, 4 Dec 2009 17:54:12 +0100 Subject: Made qobject.h "syncqt compliant". The previous patch to this file made syncqt confused (maybe because of the brackets), and caused it to not generate the QObject header file. This made of course a lot of stuff not compile. With this patch syncqt behaves. Reviewed-by: Olivier Goffart --- src/corelib/kernel/qobject.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/kernel/qobject.h b/src/corelib/kernel/qobject.h index 68475e5..1a178e2 100644 --- a/src/corelib/kernel/qobject.h +++ b/src/corelib/kernel/qobject.h @@ -91,11 +91,11 @@ template inline QList qFindChildren(const QObject *, const QRegEx # endif #endif +class #if defined(__INTEL_COMPILER) && defined(Q_OS_WIN) -class Q_CORE_EXPORT QObjectData { -#else -class QObjectData { +Q_CORE_EXPORT #endif +QObjectData { public: virtual ~QObjectData() = 0; QObject *q_ptr; -- cgit v0.12 From 60be72310c0f9469b3201b250b257473184ccf2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 3 Dec 2009 11:53:31 +0100 Subject: Fixed OpenGL graphicssystem issues for OpenGL ES 2.0 platforms. The format and internal_format parameters to glTexImage2D need to always match on OpenGL ES 2.0. Reviewed-by: Tom Cooksey --- src/opengl/qgl_p.h | 3 ++- src/opengl/qpixmapdata_gl.cpp | 38 ++++++++++++++++++++++++++++++-------- src/opengl/qwindowsurface_gl.cpp | 9 ++++----- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index ab72c9c..b2407ba 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -518,7 +518,8 @@ bool qt_gl_preferGL2Engine(); inline GLenum qt_gl_preferredTextureFormat() { - return QSysInfo::ByteOrder == QSysInfo::BigEndian ? GL_RGBA : GL_BGRA; + return (QGLExtensions::glExtensions & QGLExtensions::BGRATextureFormat) && QSysInfo::ByteOrder == QSysInfo::LittleEndian + ? GL_BGRA : GL_RGBA; } inline GLenum qt_gl_preferredTextureTarget() diff --git a/src/opengl/qpixmapdata_gl.cpp b/src/opengl/qpixmapdata_gl.cpp index fb55097..ab17789 100644 --- a/src/opengl/qpixmapdata_gl.cpp +++ b/src/opengl/qpixmapdata_gl.cpp @@ -321,25 +321,47 @@ void QGLPixmapData::ensureCreated() const QGLShareContextScope ctx(qt_gl_share_widget()->context()); m_ctx = ctx; - const GLenum format = qt_gl_preferredTextureFormat(); + const GLenum internal_format = m_hasAlpha ? GL_RGBA : GL_RGB; +#ifdef QT_OPENGL_ES_2 + const GLenum external_format = internal_format; +#else + const GLenum external_format = qt_gl_preferredTextureFormat(); +#endif const GLenum target = GL_TEXTURE_2D; if (!m_texture.id) { glGenTextures(1, &m_texture.id); glBindTexture(target, m_texture.id); - GLenum format = m_hasAlpha ? GL_RGBA : GL_RGB; - glTexImage2D(target, 0, format, w, h, 0, - GL_RGBA, GL_UNSIGNED_BYTE, 0); + glTexImage2D(target, 0, internal_format, w, h, 0, external_format, GL_UNSIGNED_BYTE, 0); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } if (!m_source.isNull()) { - const QImage tx = ctx->d_func()->convertToGLFormat(m_source, true, format); + if (external_format == GL_RGB) { + QImage tx = m_source.convertToFormat(QImage::Format_RGB32); + + QVector pixelData(w * h * 3); + uchar *p = &pixelData[0]; + QRgb *src = (QRgb *)tx.bits(); + + for (int i = 0; i < w * h; ++i) { + *p++ = qRed(*src); + *p++ = qGreen(*src); + *p++ = qBlue(*src); + ++src; + } - glBindTexture(target, m_texture.id); - glTexSubImage2D(target, 0, 0, 0, w, h, format, - GL_UNSIGNED_BYTE, tx.bits()); + glBindTexture(target, m_texture.id); + glTexSubImage2D(target, 0, 0, 0, w, h, external_format, + GL_UNSIGNED_BYTE, &pixelData[0]); + } else { + const QImage tx = ctx->d_func()->convertToGLFormat(m_source, true, external_format); + + glBindTexture(target, m_texture.id); + glTexSubImage2D(target, 0, 0, 0, w, h, external_format, + GL_UNSIGNED_BYTE, tx.bits()); + } if (useFramebufferObjects()) m_source = QImage(); diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp index e353f5d..7194f9d 100644 --- a/src/opengl/qwindowsurface_gl.cpp +++ b/src/opengl/qwindowsurface_gl.cpp @@ -493,7 +493,6 @@ void QGLWindowSurface::flush(QWidget *widget, const QRegion &rgn, const QPoint & } #endif d_ptr->paintedRegion = QRegion(); - context()->swapBuffers(); } else { glFlush(); @@ -688,11 +687,13 @@ void QGLWindowSurface::updateGeometry() { d_ptr->size = rect.size(); if (d_ptr->ctx) { +#ifndef QT_OPENGL_ES_2 if (d_ptr->destructive_swap_buffers) { glBindTexture(target, d_ptr->tex_id); glTexImage2D(target, 0, GL_RGBA, rect.width(), rect.height(), 0, GL_RGB, GL_UNSIGNED_BYTE, 0); glBindTexture(target, 0); } +#endif return; } @@ -756,11 +757,7 @@ void QGLWindowSurface::updateGeometry() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); -#ifndef QT_OPENGL_ES glOrtho(0, d_ptr->pb->width(), d_ptr->pb->height(), 0, -999999, 999999); -#else - glOrthof(0, d_ptr->pb->width(), d_ptr->pb->height(), 0, -999999, 999999); -#endif d_ptr->pb->d_ptr->qctx->d_func()->internal_context = true; return; @@ -774,6 +771,7 @@ void QGLWindowSurface::updateGeometry() { ctx->makeCurrent(); +#ifndef QT_OPENGL_ES_2 if (d_ptr->destructive_swap_buffers) { glGenTextures(1, &d_ptr->tex_id); glBindTexture(target, d_ptr->tex_id); @@ -783,6 +781,7 @@ void QGLWindowSurface::updateGeometry() { glTexParameterf(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBindTexture(target, 0); } +#endif qDebug() << "QGLWindowSurface: Using plain widget as window surface" << this;; d_ptr->ctx = ctx; -- cgit v0.12 From 8529a8cbb0c6404c758b5efc650186d740b0e09f Mon Sep 17 00:00:00 2001 From: Pierre Rossi Date: Fri, 4 Dec 2009 00:04:09 +0100 Subject: Fixes problem with QMenu when it's populated on the aboutToShow When the menu is populated that late, if the menu is to go off-screen, then it is moved and ends up covering its originating button. Includes some code cleanup thanks to Thierry's tips. Reviewed-by: Gabriel Reviewed-by: Thierry --- src/gui/widgets/qmenu.cpp | 35 +++++++++++++---------------------- src/gui/widgets/qmenu_p.h | 1 + src/gui/widgets/qpushbutton.cpp | 33 ++++++++++++++++++++++++--------- src/gui/widgets/qpushbutton_p.h | 4 ++++ tests/auto/qmenu/tst_qmenu.cpp | 36 +++++++++++++++++++++++++++++++++++- 5 files changed, 77 insertions(+), 32 deletions(-) diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index 2e27226..ec9683d 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -65,6 +65,8 @@ #include "qmenubar_p.h" #include "qwidgetaction.h" #include "qtoolbutton.h" +#include "qpushbutton.h" +#include #include #include #ifdef QT3_SUPPORT @@ -417,12 +419,7 @@ void QMenuPrivate::hideUpToMenuBar() hideMenu(m, fadeMenus); if (!fadeMenus) // Mac doesn't clear the action until after hidden. m->d_func()->setCurrentAction(0); - } else { -#ifndef QT_NO_TOOLBUTTON - if (qobject_cast(caused) == 0) -#endif - qWarning("QMenu: Internal error"); - caused = 0; + } else { caused = 0; } } #if defined(Q_WS_MAC) @@ -1825,8 +1822,15 @@ void QMenu::popup(const QPoint &p, QAction *atAction) ensurePolished(); // Get the right font emit aboutToShow(); + const bool actionListChanged = d->itemsDirty; d->updateActionRects(); - QPoint pos = p; + QPoint pos; + QPushButton *causedButton = qobject_cast(d->causedPopup.widget); + if (actionListChanged && causedButton) + pos = QPushButtonPrivate::get(causedButton)->adjustedMenuPosition(); + else + pos = p; + QSize size = sizeHint(); QRect screen; #ifndef QT_NO_GRAPHICSVIEW @@ -2302,22 +2306,9 @@ void QMenu::mouseReleaseEvent(QMouseEvent *e) if (action->menu()) action->menu()->d_func()->setFirstActionActive(); else { -#if defined(Q_WS_WIN) && !defined(QT_NO_MENUBAR) +#if defined(Q_WS_WIN) //On Windows only context menus can be activated with the right button - bool isContextMenu = true; - const QWidget *cause = d->causedPopup.widget; - while (cause) { - //if the popup was caused by either QMenuBar or a QToolButton, it is not a context menu - if (qobject_cast(cause) || qobject_cast(cause)) { - isContextMenu = false; - break; - } else if (const QMenu *menu = qobject_cast(cause)) { - cause = menu->d_func()->causedPopup.widget; - } else { - break; - } - } - if (e->button() == Qt::LeftButton || isContextMenu) + if (e->button() == Qt::LeftButton || d->topCausedWidget() == 0) #endif d->activateAction(action, QAction::Trigger); } diff --git a/src/gui/widgets/qmenu_p.h b/src/gui/widgets/qmenu_p.h index 5757885..93017f5 100644 --- a/src/gui/widgets/qmenu_p.h +++ b/src/gui/widgets/qmenu_p.h @@ -182,6 +182,7 @@ public: } void init(); + static QMenuPrivate *get(QMenu *m) { return m->d_func(); } int scrollerHeight() const; //item calculations diff --git a/src/gui/widgets/qpushbutton.cpp b/src/gui/widgets/qpushbutton.cpp index eb34336..849bc43 100644 --- a/src/gui/widgets/qpushbutton.cpp +++ b/src/gui/widgets/qpushbutton.cpp @@ -63,6 +63,7 @@ #include "qaccessible.h" #endif +#include "private/qmenu_p.h" #include "private/qpushbutton_p.h" QT_BEGIN_NAMESPACE @@ -575,12 +576,33 @@ void QPushButtonPrivate::_q_popupPressed() return; menu->setNoReplayFor(q); + + QPoint menuPos = adjustedMenuPosition(); + + QPointer guard(q); + QMenuPrivate::get(menu)->causedPopup.widget = guard; + + //Because of a delay in menu effects, we must keep track of the + //menu visibility to avoid flicker on button release + menuOpen = true; + menu->exec(menuPos); + if (guard) { + menuOpen = false; + q->setDown(false); + } +} + +QPoint QPushButtonPrivate::adjustedMenuPosition() +{ + Q_Q(QPushButton); + bool horizontal = true; #if !defined(QT_NO_TOOLBAR) QToolBar *tb = qobject_cast(parent); if (tb && tb->orientation() == Qt::Vertical) horizontal = false; #endif + QWidgetItem item(q); QRect rect = item.geometry(); rect.setRect(rect.x() - q->x(), rect.y() - q->y(), rect.width(), rect.height()); @@ -603,17 +625,10 @@ void QPushButtonPrivate::_q_popupPressed() else x -= menuSize.width(); } - QPointer guard(q); - //Because of a delay in menu effects, we must keep track of the - //menu visibility to avoid flicker on button release - menuOpen = true; - menu->exec(QPoint(x, y)); - if (guard) { - menuOpen = false; - q->setDown(false); - } + return QPoint(x,y); } + #endif // QT_NO_MENU void QPushButtonPrivate::resetLayoutItemMargins() diff --git a/src/gui/widgets/qpushbutton_p.h b/src/gui/widgets/qpushbutton_p.h index f448027..2510e05 100644 --- a/src/gui/widgets/qpushbutton_p.h +++ b/src/gui/widgets/qpushbutton_p.h @@ -68,6 +68,10 @@ public: defaultButton(false), flat(false), menuOpen(false), lastAutoDefault(false) {} inline void init() { resetLayoutItemMargins(); } + static QPushButtonPrivate* get(QPushButton *b) { return b->d_func(); } +#ifndef QT_NO_MENU + QPoint adjustedMenuPosition(); +#endif void resetLayoutItemMargins(); void _q_popupPressed(); QDialog *dialogParent() const; diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp index 7cdfe46..6079189 100644 --- a/tests/auto/qmenu/tst_qmenu.cpp +++ b/tests/auto/qmenu/tst_qmenu.cpp @@ -82,7 +82,7 @@ private slots: void keyboardNavigation_data(); void keyboardNavigation(); void focus(); - void overrideMenuAction(); + void overrideMenuAction(); void statusTip(); void widgetActionFocus(); void mouseActivation(); @@ -103,12 +103,14 @@ private slots: void task258920_mouseBorder(); void setFixedWidth(); void deleteActionInTriggered(); + void pushButtonPopulateOnAboutToShow(); protected slots: void onActivated(QAction*); void onHighlighted(QAction*); void onStatusMessageChanged(const QString &); void onStatusTipTimer(); void deleteAction(QAction *a) { delete a; } + void populateMenu(); private: void createActions(); QMenu *menus[2], *lastMenu; @@ -258,6 +260,15 @@ void tst_QMenu::onStatusMessageChanged(const QString &s) statustip=s; } +void tst_QMenu::populateMenu(){ + //just adds 3 dummy actions and a separator. + lastMenu->addAction("Foo"); + lastMenu->addAction("Bar"); + lastMenu->addAction("FooBar"); + lastMenu->addSeparator(); + +} + //actual tests void @@ -896,7 +907,30 @@ void tst_QMenu::deleteActionInTriggered() QVERIFY(!a); } +void tst_QMenu::pushButtonPopulateOnAboutToShow() +{ + QPushButton b("Test PushButton"); + b.setWindowFlags(Qt::FramelessWindowHint); + b.setWindowFlags(Qt::X11BypassWindowManagerHint); + lastMenu = new QMenu; + b.setMenu(lastMenu); + const int scrNumber = QApplication::desktop()->screenNumber(&b); + connect(lastMenu, SIGNAL(aboutToShow()), this, SLOT(populateMenu())); + b.show(); + const QRect screen = QApplication::desktop()->screenGeometry(scrNumber); + b.move(10, screen.bottom()-b.height()-5); + QTest::qWaitForWindowShown(&b); + QTimer::singleShot(300,lastMenu, SLOT(hide())); + QTest::mouseClick(&b, Qt::LeftButton, Qt::NoModifier, b.rect().center()); + QVERIFY(!lastMenu->geometry().intersects(b.geometry())); + + b.move(10, screen.bottom()-lastMenu->height()-5); + QTimer::singleShot(300,lastMenu, SLOT(hide())); + QTest::mouseClick(&b, Qt::LeftButton, Qt::NoModifier, b.rect().center()); + QVERIFY(!lastMenu->geometry().intersects(b.geometry())); + +} QTEST_MAIN(tst_QMenu) -- cgit v0.12 From 92e9fcc25c62870c383c8558d576abc509a8c683 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Fri, 4 Dec 2009 19:42:07 +0100 Subject: Add EGL_BUFFER_SIZE to QEglProperties::reduceConfiguration() Reviewed-by: Trustme --- src/gui/egl/qeglproperties.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/gui/egl/qeglproperties.cpp b/src/gui/egl/qeglproperties.cpp index 2d37edb..4d4410a 100644 --- a/src/gui/egl/qeglproperties.cpp +++ b/src/gui/egl/qeglproperties.cpp @@ -229,6 +229,15 @@ void QEglProperties::setRenderableType(QEgl::API api) // reductions in complexity are possible. bool QEglProperties::reduceConfiguration() { + // EGL chooses configs with the highest color depth over + // those with smaller (but faster) lower color depths. One + // way around this is to set EGL_BUFFER_SIZE to 16, which + // trumps the others. Of course, there may not be a 16-bit + // config avaliable, so it's the first restraint we remove. + if (value(EGL_BUFFER_SIZE) == 16) { + removeValue(EGL_BUFFER_SIZE); + return true; + } if (removeValue(EGL_SAMPLE_BUFFERS)) { removeValue(EGL_SAMPLES); return true; -- cgit v0.12 From 76c415b586991d978d46a888fb40c631513407dc Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Fri, 4 Dec 2009 20:48:53 +0100 Subject: Fix WA_TranslucentBackground for QGLWidgets on X11/EGL Also check for existing QEglContext before creating a new one and leaking a context. Reviewed-by: TrustMe --- src/opengl/qgl_x11egl.cpp | 118 ++++++++++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 45 deletions(-) diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp index b51c239..a868e83 100644 --- a/src/opengl/qgl_x11egl.cpp +++ b/src/opengl/qgl_x11egl.cpp @@ -63,6 +63,7 @@ void qt_egl_add_platform_config(QEglProperties& props, QPaintDevice *device) props.setPixelFormat(static_cast(device)->format()); } +// Chooses the EGL config and creates the EGL context bool QGLContext::chooseContext(const QGLContext* shareContext) { Q_D(QGLContext); @@ -73,56 +74,74 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) int devType = device()->devType(); // Get the display and initialize it. - d->eglContext = new QEglContext(); - d->eglContext->setApi(QEgl::OpenGL); - if (!d->eglContext->openDisplay(device())) { - delete d->eglContext; - d->eglContext = 0; - return false; - } + if (d->eglContext == 0) { + d->eglContext = new QEglContext(); + d->eglContext->setApi(QEgl::OpenGL); + if (!d->eglContext->openDisplay(device())) { + delete d->eglContext; + d->eglContext = 0; + return false; + } - // Construct the configuration we need for this surface. - QEglProperties configProps; - qt_egl_set_format(configProps, devType, d->glFormat); - qt_egl_add_platform_config(configProps, device()); - configProps.setRenderableType(QEgl::OpenGL); - - QEgl::PixelFormatMatch matchType = QEgl::BestPixelFormat; - if (device()->depth() == 16) { - configProps.setValue(EGL_RED_SIZE, 5); - configProps.setValue(EGL_GREEN_SIZE, 6); - configProps.setValue(EGL_BLUE_SIZE, 5); - configProps.setValue(EGL_ALPHA_SIZE, 0); - matchType = QEgl::ExactPixelFormat; - } - configProps.setRenderableType(QEgl::OpenGL); + // Construct the configuration we need for this surface. + QEglProperties configProps; + qt_egl_set_format(configProps, devType, d->glFormat); + qt_egl_add_platform_config(configProps, device()); + configProps.setRenderableType(QEgl::OpenGL); + +#if We_have_an_EGL_library_which_bothers_to_check_EGL_BUFFER_SIZE + if (device()->depth() == 16 && configProps.value(EGL_ALPHA_SIZE) <= 0) { + qDebug("Setting EGL_BUFFER_SIZE to 16"); + configProps.setValue(EGL_BUFFER_SIZE, 16); + configProps.setValue(EGL_ALPHA_SIZE, 0); + } - // Search for a matching configuration, reducing the complexity - // each time until we get something that matches. - if (!d->eglContext->chooseConfig(configProps, matchType)) { - delete d->eglContext; - d->eglContext = 0; - return false; - } + if (!d->eglContext->chooseConfig(configProps, QEgl::BestPixelFormat)) { + delete d->eglContext; + d->eglContext = 0; + return false; + } +#else + QEgl::PixelFormatMatch matchType = QEgl::BestPixelFormat; + if ((device()->depth() == 16) && configProps.value(EGL_ALPHA_SIZE) == 0) { + configProps.setValue(EGL_RED_SIZE, 5); + configProps.setValue(EGL_GREEN_SIZE, 6); + configProps.setValue(EGL_BLUE_SIZE, 5); + configProps.setValue(EGL_ALPHA_SIZE, 0); + matchType = QEgl::ExactPixelFormat; + } - // Inform the higher layers about the actual format properties. - qt_egl_update_format(*(d->eglContext), d->glFormat); + // Search for a matching configuration, reducing the complexity + // each time until we get something that matches. + if (!d->eglContext->chooseConfig(configProps, matchType)) { + delete d->eglContext; + d->eglContext = 0; + return false; + } +#endif - // Create a new context for the configuration. - if (!d->eglContext->createContext - (shareContext ? shareContext->d_func()->eglContext : 0)) { - delete d->eglContext; - d->eglContext = 0; - return false; - } - d->sharing = d->eglContext->isSharing(); - if (d->sharing && shareContext) - const_cast(shareContext)->d_func()->sharing = true; +// qDebug("QGLContext::chooseContext() - using EGL config %d:", d->eglContext->config()); +// qDebug() << QEglProperties(d->eglContext->config()).toString(); + + // Create a new context for the configuration. + if (!d->eglContext->createContext + (shareContext ? shareContext->d_func()->eglContext : 0)) { + delete d->eglContext; + d->eglContext = 0; + return false; + } + d->sharing = d->eglContext->isSharing(); + if (d->sharing && shareContext) + const_cast(shareContext)->d_func()->sharing = true; #if defined(EGL_VERSION_1_1) - if (d->glFormat.swapInterval() != -1 && devType == QInternal::Widget) - eglSwapInterval(d->eglContext->display(), d->glFormat.swapInterval()); + if (d->glFormat.swapInterval() != -1 && devType == QInternal::Widget) + eglSwapInterval(d->eglContext->display(), d->glFormat.swapInterval()); #endif + } + + // Inform the higher layers about the actual format properties. + qt_egl_update_format(*(d->eglContext), d->glFormat); return true; } @@ -160,6 +179,9 @@ bool qt_egl_setup_x11_visual(XVisualInfo &vi, EGLDisplay display, EGLConfig conf memset(&vi, 0, sizeof(XVisualInfo)); + EGLint eglConfigColorSize; + eglGetConfigAttrib(display, config, EGL_BUFFER_SIZE, &eglConfigColorSize); + // Check to see if EGL is suggesting an appropriate visual id: EGLint nativeVisualId; eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &nativeVisualId); @@ -189,8 +211,12 @@ bool qt_egl_setup_x11_visual(XVisualInfo &vi, EGLDisplay display, EGLConfig conf } else #endif { -// qDebug("Using opaque X Visual ID (%d) provided by EGL", (int)vi.visualid); - vi = *chosenVisualInfo; + if (eglConfigColorSize == chosenVisualInfo->depth) { +// qDebug("Using opaque X Visual ID (%d) provided by EGL", (int)vi.visualid); + vi = *chosenVisualInfo; + } else + qWarning("Warning: EGL suggested using X visual ID %d (%d bpp) for config %d (%d bpp), but the depths do not match!", + nativeVisualId, chosenVisualInfo->depth, (int)config, eglConfigColorSize); } XFree(chosenVisualInfo); } @@ -300,6 +326,8 @@ void QGLWidget::setContext(QGLContext *context, const QGLContext* shareContext, bool createFailed = false; if (!d->glcx->isValid()) { + // Create the QGLContext here, which in turn chooses the EGL config + // and creates the EGL context: if (!d->glcx->create(shareContext ? shareContext : oldcx)) createFailed = true; } -- cgit v0.12 From 147195bccfdf90924a1525398e9c7b3119c1e278 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Thu, 3 Dec 2009 10:07:22 +1000 Subject: Compressed texture binding for QtOpenGL: ETC1 and PVRTC The QGLContext::bindTexture(QString) function has been augmented with support for ETC1, PVRTC2, and PVRTC4 compressed textures, in addition to the existing DDS support. The QGLPixmapData class has also been modified to recognize compressed texture formats in fromFile() and fromData(). This change also fixes a bug in bindTexture() that prevented the same compressed texture file from being bound in multiple contexts. There is now a separate file cache for each context group. Task-number: QT-2547 Reviewed-by: Trond --- src/opengl/qgl.cpp | 485 ++++++++++++++++++++++++++++++++---------- src/opengl/qgl_p.h | 16 +- src/opengl/qglextensions_p.h | 17 ++ src/opengl/qpixmapdata_gl.cpp | 57 +++++ src/opengl/qpixmapdata_gl_p.h | 4 + 5 files changed, 461 insertions(+), 118 deletions(-) diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 94b8aa5..b376901 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -127,18 +127,6 @@ Q_GLOBAL_STATIC(QGLDefaultOverlayFormat, defaultOverlayFormatInstance) QGLExtensions::Extensions QGLExtensions::glExtensions = 0; bool QGLExtensions::nvidiaFboNeedsFinish = false; -#ifndef APIENTRY -# define APIENTRY -#endif -typedef void (APIENTRY *pfn_glCompressedTexImage2DARB) (GLenum, GLint, GLenum, GLsizei, - GLsizei, GLint, GLsizei, const GLvoid *); -static pfn_glCompressedTexImage2DARB qt_glCompressedTexImage2DARB = 0; - - -#ifndef APIENTRY -#define APIENTRY -#endif - Q_GLOBAL_STATIC(QGLSignalProxy, theSignalProxy) QGLSignalProxy *QGLSignalProxy::instance() { @@ -1887,118 +1875,42 @@ void QGLContextPrivate::cleanup() { } -typedef QHash QGLDDSCache; -Q_GLOBAL_STATIC(QGLDDSCache, qgl_dds_cache) - /*! \overload - Reads the DirectDrawSurface (DDS) compressed file \a fileName and - generates a 2D GL texture from it. + Reads the compressed texture file \a fileName and generates a 2D GL + texture from it. - Only the DXT1, DXT3 and DXT5 DDS formats are supported. + This function can load DirectDrawSurface (DDS) textures in the + DXT1, DXT3 and DXT5 DDS formats if the \c GL_ARB_texture_compression + and \c GL_EXT_texture_compression_s3tc extensions are supported. - Note that this will only work if the implementation supports the - \c GL_ARB_texture_compression and \c GL_EXT_texture_compression_s3tc - extensions. + Since 4.6.1, textures in the ETC1 format can be loaded if the + \c GL_OES_compressed_ETC1_RGB8_texture extension is supported + and the ETC1 texture has been encapsulated in the PVR container format. + Also, textures in the PVRTC2 and PVRTC4 formats can be loaded + if the \c GL_IMG_texture_compression_pvrtc extension is supported. \sa deleteTexture() */ GLuint QGLContext::bindTexture(const QString &fileName) { - if (!qt_glCompressedTexImage2DARB) { - qWarning("QGLContext::bindTexture(): The GL implementation does not support texture" - "compression extensions."); - return 0; - } - - QGLDDSCache::const_iterator it = qgl_dds_cache()->constFind(fileName); - if (it != qgl_dds_cache()->constEnd()) { + Q_D(QGLContext); + QGLDDSCache *dds_cache = &(d->group->m_dds_cache); + QGLDDSCache::const_iterator it = dds_cache->constFind(fileName); + if (it != dds_cache->constEnd()) { glBindTexture(GL_TEXTURE_2D, it.value()); return it.value(); } - QFile f(fileName); - f.open(QIODevice::ReadOnly); - - char tag[4]; - f.read(&tag[0], 4); - if (strncmp(tag,"DDS ", 4) != 0) { - qWarning("QGLContext::bindTexture(): not a DDS image file."); - return 0; - } - - DDSFormat ddsHeader; - f.read((char *) &ddsHeader, sizeof(DDSFormat)); - - if (!ddsHeader.dwLinearSize) { - qWarning("QGLContext::bindTexture() DDS image size is not valid."); - return 0; - } - - int factor = 4; - int bufferSize = 0; - int blockSize = 16; - GLenum format; - - switch(ddsHeader.ddsPixelFormat.dwFourCC) { - case FOURCC_DXT1: - format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; - factor = 2; - blockSize = 8; - break; - case FOURCC_DXT3: - format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; - break; - case FOURCC_DXT5: - format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; - break; - default: - qWarning("QGLContext::bindTexture() DDS image format not supported."); + QGLTexture texture(this); + QSize size = texture.bindCompressedTexture(fileName); + if (!size.isValid()) return 0; - } - - if (ddsHeader.dwMipMapCount > 1) - bufferSize = ddsHeader.dwLinearSize * factor; - else - bufferSize = ddsHeader.dwLinearSize; - - GLubyte *pixels = (GLubyte *) malloc(bufferSize*sizeof(GLubyte)); - f.seek(ddsHeader.dwSize + 4); - f.read((char *) pixels, bufferSize); - f.close(); - - GLuint tx_id; - glGenTextures(1, &tx_id); - glBindTexture(GL_TEXTURE_2D, tx_id); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - - int size; - int offset = 0; - int w = ddsHeader.dwWidth; - int h = ddsHeader.dwHeight; - // load mip-maps - for(int i = 0; i < (int) ddsHeader.dwMipMapCount; ++i) { - if (w == 0) w = 1; - if (h == 0) h = 1; - - size = ((w+3)/4) * ((h+3)/4) * blockSize; - qt_glCompressedTexImage2DARB(GL_TEXTURE_2D, i, format, w, h, 0, - size, pixels + offset); - offset += size; - - // half size for each mip-map level - w = w/2; - h = h/2; - } - - free(pixels); - - qgl_dds_cache()->insert(fileName, tx_id); - return tx_id; + dds_cache->insert(fileName, texture.id); + return texture.id; } static inline QRgb qt_gl_convertToGLFormatHelper(QRgb src_pixel, GLenum texture_format) @@ -2593,17 +2505,20 @@ GLuint QGLContext::bindTexture(const QPixmap &pixmap, QMacCompatGLenum target, Q */ void QGLContext::deleteTexture(GLuint id) { + Q_D(QGLContext); + if (QGLTextureCache::instance()->remove(this, id)) return; // check the DDS cache if the texture wasn't found in the pixmap/image // cache - QList ddsKeys = qgl_dds_cache()->keys(); + QGLDDSCache *dds_cache = &(d->group->m_dds_cache); + QList ddsKeys = dds_cache->keys(); for (int i = 0; i < ddsKeys.size(); ++i) { - GLuint texture = qgl_dds_cache()->value(ddsKeys.at(i)); + GLuint texture = dds_cache->value(ddsKeys.at(i)); if (id == texture) { glDeleteTextures(1, &texture); - qgl_dds_cache()->remove(ddsKeys.at(i)); + dds_cache->remove(ddsKeys.at(i)); return; } } @@ -4907,8 +4822,14 @@ void QGLExtensions::init_extensions() glExtensions |= SampleBuffers; if (extensions.contains("GL_SGIS_generate_mipmap")) glExtensions |= GenerateMipmap; - if (extensions.contains("GL_EXT_texture_compression_s3tc")) + if (extensions.contains("GL_ARB_texture_compression")) glExtensions |= TextureCompression; + if (extensions.contains("GL_EXT_texture_compression_s3tc")) + glExtensions |= DDSTextureCompression; + if (extensions.contains("GL_OES_compressed_ETC1_RGB8_texture")) + glExtensions |= ETC1TextureCompression; + if (extensions.contains("GL_IMG_texture_compression_pvrtc")) + glExtensions |= PVRTCTextureCompression; if (extensions.contains("GL_ARB_fragment_program")) glExtensions |= FragmentProgram; if (extensions.contains("GL_ARB_texture_mirrored_repeat")) @@ -4951,12 +4872,6 @@ void QGLExtensions::init_extensions() if (extensions.contains("GL_EXT_bgra")) glExtensions |= BGRATextureFormat; - - - QGLContext cx(QGLFormat::defaultFormat()); - if (glExtensions & TextureCompression) { - qt_glCompressedTexImage2DARB = (pfn_glCompressedTexImage2DARB) cx.getProcAddress(QLatin1String("glCompressedTexImage2DARB")); - } } /* @@ -5112,4 +5027,340 @@ void QGLSharedResourceGuard::setContext(const QGLContext *context) } } +QSize QGLTexture::bindCompressedTexture + (const QString& fileName, const char *format) +{ + QFile file(fileName); + if (!file.open(QIODevice::ReadOnly)) + return QSize(); + QByteArray contents = file.readAll(); + file.close(); + return bindCompressedTexture + (contents.constData(), contents.size(), format); +} + +// PVR header format for container files that store textures compressed +// with the ETC1, PVRTC2, and PVRTC4 encodings. Format information from the +// PowerVR SDK at http://www.imgtec.com/powervr/insider/powervr-sdk.asp +// "PVRTexTool Reference Manual, version 1.11f". +struct PvrHeader +{ + quint32 headerSize; + quint32 height; + quint32 width; + quint32 mipMapCount; + quint32 flags; + quint32 dataSize; + quint32 bitsPerPixel; + quint32 redMask; + quint32 greenMask; + quint32 blueMask; + quint32 alphaMask; + quint32 magic; + quint32 surfaceCount; +}; + +#define PVR_MAGIC 0x21525650 // "PVR!" in little-endian + +#define PVR_FORMAT_MASK 0x000000FF +#define PVR_FORMAT_PVRTC2 0x00000018 +#define PVR_FORMAT_PVRTC4 0x00000019 +#define PVR_FORMAT_ETC1 0x00000036 + +#define PVR_HAS_MIPMAPS 0x00000100 +#define PVR_TWIDDLED 0x00000200 +#define PVR_NORMAL_MAP 0x00000400 +#define PVR_BORDER_ADDED 0x00000800 +#define PVR_CUBE_MAP 0x00001000 +#define PVR_FALSE_COLOR_MIPMAPS 0x00002000 +#define PVR_VOLUME_TEXTURE 0x00004000 +#define PVR_ALPHA_IN_TEXTURE 0x00008000 +#define PVR_VERTICAL_FLIP 0x00010000 + +#ifndef GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG +#define GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG 0x8C00 +#define GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG 0x8C01 +#define GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG 0x8C02 +#define GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG 0x8C03 +#endif + +#ifndef GL_ETC1_RGB8_OES +#define GL_ETC1_RGB8_OES 0x8D64 +#endif + +bool QGLTexture::canBindCompressedTexture + (const char *buf, int len, const char *format, bool *hasAlpha) +{ + if (QSysInfo::ByteOrder != QSysInfo::LittleEndian) { + // Compressed texture loading only supported on little-endian + // systems such as x86 and ARM at the moment. + return false; + } + if (!format) { + // Auto-detect the format from the header. + if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) { + *hasAlpha = true; + return true; + } else if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) { + const PvrHeader *pvrHeader = + reinterpret_cast(buf); + *hasAlpha = (pvrHeader->alphaMask != 0); + return true; + } + } else { + // Validate the format against the header. + if (!qstricmp(format, "DDS")) { + if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) { + *hasAlpha = true; + return true; + } + } else if (!qstricmp(format, "PVR") || !qstricmp(format, "ETC1")) { + if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) { + const PvrHeader *pvrHeader = + reinterpret_cast(buf); + *hasAlpha = (pvrHeader->alphaMask != 0); + return true; + } + } + } + return false; +} + +#define ctx QGLContext::currentContext() + +QSize QGLTexture::bindCompressedTexture + (const char *buf, int len, const char *format) +{ + if (QSysInfo::ByteOrder != QSysInfo::LittleEndian) { + // Compressed texture loading only supported on little-endian + // systems such as x86 and ARM at the moment. + return QSize(); + } +#if !defined(QT_OPENGL_ES) + if (!glCompressedTexImage2D) { + if (!(QGLExtensions::glExtensions & QGLExtensions::TextureCompression)) { + qWarning("QGLContext::bindTexture(): The GL implementation does " + "not support texture compression extensions."); + return QSize(); + } + glCompressedTexImage2D = (_glCompressedTexImage2DARB) ctx->getProcAddress(QLatin1String("glCompressedTexImage2DARB")); + if (!glCompressedTexImage2D) { + qWarning("QGLContext::bindTexture(): could not resolve " + "glCompressedTexImage2DARB."); + return QSize(); + } + } +#endif + if (!format) { + // Auto-detect the format from the header. + if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) + return bindCompressedTextureDDS(buf, len); + else if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) + return bindCompressedTexturePVR(buf, len); + } else { + // Validate the format against the header. + if (!qstricmp(format, "DDS")) { + if (len >= 4 && !qstrncmp(buf, "DDS ", 4)) + return bindCompressedTextureDDS(buf, len); + } else if (!qstricmp(format, "PVR") || !qstricmp(format, "ETC1")) { + if (len >= 52 && !qstrncmp(buf + 44, "PVR!", 4)) + return bindCompressedTexturePVR(buf, len); + } + } + return QSize(); +} + +QSize QGLTexture::bindCompressedTextureDDS(const char *buf, int len) +{ + // We only support 2D texture loading at present. + if (target != GL_TEXTURE_2D) + return QSize(); + + // Bail out if the necessary extension is not present. + if (!(QGLExtensions::glExtensions & QGLExtensions::DDSTextureCompression)) { + qWarning("QGLContext::bindTexture(): DDS texture compression is not supported."); + return QSize(); + } + + const DDSFormat *ddsHeader = reinterpret_cast(buf + 4); + if (!ddsHeader->dwLinearSize) { + qWarning("QGLContext::bindTexture(): DDS image size is not valid."); + return QSize(); + } + + int blockSize = 16; + GLenum format; + + switch(ddsHeader->ddsPixelFormat.dwFourCC) { + case FOURCC_DXT1: + format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; + blockSize = 8; + break; + case FOURCC_DXT3: + format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; + break; + case FOURCC_DXT5: + format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; + break; + default: + qWarning("QGLContext::bindTexture(): DDS image format not supported."); + return QSize(); + } + + const GLubyte *pixels = + reinterpret_cast(buf + ddsHeader->dwSize + 4); + + glGenTextures(1, &id); + glBindTexture(GL_TEXTURE_2D, id); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + int size; + int offset = 0; + int available = len - int(ddsHeader->dwSize + 4); + int w = ddsHeader->dwWidth; + int h = ddsHeader->dwHeight; + + // load mip-maps + for(int i = 0; i < (int) ddsHeader->dwMipMapCount; ++i) { + if (w == 0) w = 1; + if (h == 0) h = 1; + + size = ((w+3)/4) * ((h+3)/4) * blockSize; + if (size > available) + break; + glCompressedTexImage2D(GL_TEXTURE_2D, i, format, w, h, 0, + size, pixels + offset); + offset += size; + available -= size; + + // half size for each mip-map level + w = w/2; + h = h/2; + } + + // DDS images are not inverted. + options &= ~QGLContext::InvertedYBindOption; + + return QSize(ddsHeader->dwWidth, ddsHeader->dwHeight); +} + +QSize QGLTexture::bindCompressedTexturePVR(const char *buf, int len) +{ + // We only support 2D texture loading at present. Cube maps later. + if (target != GL_TEXTURE_2D) + return QSize(); + + // Determine which texture format we will be loading. + const PvrHeader *pvrHeader = reinterpret_cast(buf); + GLenum textureFormat; + quint32 minWidth, minHeight; + switch (pvrHeader->flags & PVR_FORMAT_MASK) { + case PVR_FORMAT_PVRTC2: + if (pvrHeader->alphaMask) + textureFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; + else + textureFormat = GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; + minWidth = 16; + minHeight = 8; + break; + + case PVR_FORMAT_PVRTC4: + if (pvrHeader->alphaMask) + textureFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; + else + textureFormat = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; + minWidth = 8; + minHeight = 8; + break; + + case PVR_FORMAT_ETC1: + textureFormat = GL_ETC1_RGB8_OES; + minWidth = 4; + minHeight = 4; + break; + + default: + qWarning("QGLContext::bindTexture(): PVR image format 0x%x not supported.", int(pvrHeader->flags & PVR_FORMAT_MASK)); + return QSize(); + } + + // Bail out if the necessary extension is not present. + if (textureFormat == GL_ETC1_RGB8_OES) { + if (!(QGLExtensions::glExtensions & + QGLExtensions::ETC1TextureCompression)) { + qWarning("QGLContext::bindTexture(): ETC1 texture compression is not supported."); + return QSize(); + } + } else { + if (!(QGLExtensions::glExtensions & + QGLExtensions::PVRTCTextureCompression)) { + qWarning("QGLContext::bindTexture(): PVRTC texture compression is not supported."); + return QSize(); + } + } + + // Boundary check on the buffer size. + quint32 bufferSize = pvrHeader->headerSize + pvrHeader->dataSize; + if (bufferSize > quint32(len)) { + qWarning("QGLContext::bindTexture(): PVR image size is not valid."); + return QSize(); + } + + // Create the texture. + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glGenTextures(1, &id); + glBindTexture(GL_TEXTURE_2D, id); + if (pvrHeader->mipMapCount) { + if ((options & QGLContext::LinearFilteringBindOption) != 0) { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + } else { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + } + } else if ((options & QGLContext::LinearFilteringBindOption) != 0) { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + } else { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + } + + // Load the compressed mipmap levels. + const GLubyte *buffer = + reinterpret_cast(buf + pvrHeader->headerSize); + bufferSize = pvrHeader->dataSize; + quint32 level = 0; + quint32 width = pvrHeader->width; + quint32 height = pvrHeader->height; + while (bufferSize > 0 && level < pvrHeader->mipMapCount) { + quint32 size = + (qMax(width, minWidth) * qMax(height, minHeight) * + pvrHeader->bitsPerPixel) / 8; + if (size > bufferSize) + break; + glCompressedTexImage2D(GL_TEXTURE_2D, GLint(level), textureFormat, + GLsizei(width), GLsizei(height), 0, + GLsizei(size), buffer); + width /= 2; + height /= 2; + buffer += size; + ++level; + } + + // Restore the default pixel alignment for later texture uploads. + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + + // Set the invert flag for the texture. + if ((pvrHeader->flags & PVR_VERTICAL_FLIP) != 0) + options |= QGLContext::InvertedYBindOption; + else + options &= ~QGLContext::InvertedYBindOption; + + return QSize(pvrHeader->width, pvrHeader->height); +} + +#undef ctx + QT_END_NAMESPACE diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index b2407ba..0f785a5 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -222,6 +222,8 @@ public: class QGLContextResource; class QGLSharedResourceGuard; +typedef QHash QGLDDSCache; + // QGLContextPrivate has the responsibility of creating context groups. // QGLContextPrivate and QGLShareRegister will both maintain the reference counter and destroy // context groups when needed. @@ -246,6 +248,7 @@ private: QHash m_resources; QGLSharedResourceGuard *m_guards; // double-linked list of active guards. QAtomicInt m_refs; + QGLDDSCache m_dds_cache; void cleanupResources(const QGLContext *ctx); @@ -377,7 +380,10 @@ public: PixelBufferObject = 0x00000800, FramebufferBlit = 0x00001000, NPOTTextures = 0x00002000, - BGRATextureFormat = 0x00004000 + BGRATextureFormat = 0x00004000, + DDSTextureCompression = 0x00008000, + ETC1TextureCompression = 0x00010000, + PVRTCTextureCompression = 0x00020000 }; Q_DECLARE_FLAGS(Extensions, Extension) @@ -482,6 +488,14 @@ public: QPixmapData* boundPixmap; #endif + bool canBindCompressedTexture + (const char *buf, int len, const char *format, bool *hasAlpha); + QSize bindCompressedTexture + (const QString& fileName, const char *format = 0); + QSize bindCompressedTexture + (const char *buf, int len, const char *format = 0); + QSize bindCompressedTextureDDS(const char *buf, int len); + QSize bindCompressedTexturePVR(const char *buf, int len); }; class QGLTextureCache { diff --git a/src/opengl/qglextensions_p.h b/src/opengl/qglextensions_p.h index 3510765..62e216c 100644 --- a/src/opengl/qglextensions_p.h +++ b/src/opengl/qglextensions_p.h @@ -184,6 +184,10 @@ typedef void (APIENTRY *_glBlitFramebufferEXT) (int srcX0, int srcY0, int srcX1, typedef void (APIENTRY *_glRenderbufferStorageMultisampleEXT) (GLenum target, GLsizei samples, GLenum internalformat, GLsizei width, GLsizei height); +// ARB_texture_compression +typedef void (APIENTRY *_glCompressedTexImage2DARB) (GLenum, GLint, GLenum, GLsizei, + GLsizei, GLint, GLsizei, const GLvoid *); + QT_BEGIN_NAMESPACE struct QGLExtensionFuncs @@ -289,6 +293,11 @@ struct QGLExtensionFuncs #endif qt_glMapBufferARB = 0; qt_glUnmapBufferARB = 0; + +#if !defined(QT_OPENGL_ES) + // Texture compression + qt_glCompressedTexImage2DARB = 0; +#endif } @@ -397,6 +406,10 @@ struct QGLExtensionFuncs _glMapBufferARB qt_glMapBufferARB; _glUnmapBufferARB qt_glUnmapBufferARB; +#if !defined(QT_OPENGL_ES) + // Texture compression + _glCompressedTexImage2DARB qt_glCompressedTexImage2DARB; +#endif }; @@ -732,6 +745,10 @@ struct QGLExtensionFuncs #define glClearDepth glClearDepthf #endif +#if !defined(QT_OPENGL_ES) +#define glCompressedTexImage2D QGLContextPrivate::extensionFuncs(ctx).qt_glCompressedTexImage2DARB +#endif + extern bool qt_resolve_framebufferobject_extensions(QGLContext *ctx); bool qt_resolve_buffer_extensions(QGLContext *ctx); diff --git a/src/opengl/qpixmapdata_gl.cpp b/src/opengl/qpixmapdata_gl.cpp index ab17789..0299cea 100644 --- a/src/opengl/qpixmapdata_gl.cpp +++ b/src/opengl/qpixmapdata_gl.cpp @@ -53,6 +53,8 @@ #include #include +#include +#include QT_BEGIN_NAMESPACE @@ -407,6 +409,61 @@ void QGLPixmapData::fromImage(const QImage &image, } } +bool QGLPixmapData::fromFile(const QString &filename, const char *format, + Qt::ImageConversionFlags flags) +{ + if (pixelType() == QPixmapData::BitmapType) + return QPixmapData::fromFile(filename, format, flags); + QFile file(filename); + if (!file.open(QIODevice::ReadOnly)) + return false; + QByteArray data = file.peek(64); + bool alpha; + if (m_texture.canBindCompressedTexture + (data.constData(), data.size(), format, &alpha)) { + resize(0, 0); + data = file.readAll(); + file.close(); + QSize size = m_texture.bindCompressedTexture + (data.constData(), data.size(), format); + if (!size.isEmpty()) { + w = size.width(); + h = size.height(); + is_null = false; + d = 32; + m_hasAlpha = alpha; + m_source = QImage(); + m_dirty = isValid(); + return true; + } + return false; + } + fromImage(QImageReader(&file, format).read(), flags); + return !isNull(); +} + +bool QGLPixmapData::fromData(const uchar *buffer, uint len, const char *format, + Qt::ImageConversionFlags flags) +{ + bool alpha; + const char *buf = reinterpret_cast(buffer); + if (m_texture.canBindCompressedTexture(buf, int(len), format, &alpha)) { + resize(0, 0); + QSize size = m_texture.bindCompressedTexture(buf, int(len), format); + if (!size.isEmpty()) { + w = size.width(); + h = size.height(); + is_null = false; + d = 32; + m_hasAlpha = alpha; + m_source = QImage(); + m_dirty = isValid(); + return true; + } + } + return QPixmapData::fromData(buffer, len, format, flags); +} + bool QGLPixmapData::scroll(int dx, int dy, const QRect &rect) { Q_UNUSED(dx); diff --git a/src/opengl/qpixmapdata_gl_p.h b/src/opengl/qpixmapdata_gl_p.h index 8a13e03..007c52a 100644 --- a/src/opengl/qpixmapdata_gl_p.h +++ b/src/opengl/qpixmapdata_gl_p.h @@ -106,6 +106,10 @@ public: // Re-implemented from QPixmapData: void resize(int width, int height); void fromImage(const QImage &image, Qt::ImageConversionFlags flags); + bool fromFile(const QString &filename, const char *format, + Qt::ImageConversionFlags flags); + bool fromData(const uchar *buffer, uint len, const char *format, + Qt::ImageConversionFlags flags); void copy(const QPixmapData *data, const QRect &rect); bool scroll(int dx, int dy, const QRect &rect); void fill(const QColor &color); -- cgit v0.12 From 28206b2ec077396bc1fafffa4d85cab505f4409a Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Mon, 7 Dec 2009 08:13:47 +1000 Subject: Change file update for compressed texture support. --- dist/changes-4.6.1 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/dist/changes-4.6.1 b/dist/changes-4.6.1 index 6896358..5efa0e2 100644 --- a/dist/changes-4.6.1 +++ b/dist/changes-4.6.1 @@ -46,8 +46,11 @@ QtCore QtGui ----- - - foo - * bar + - QPixmap + * load() and loadFromData() can now support compressed GL textures + in the DDS, ETC1, PVRTC2, and PVRTC4 formats if the OpenGL graphics + system is active and the appropriate extensions are present in the + GL implementation. QtDBus ------ @@ -64,8 +67,10 @@ QtNetwork QtOpenGL -------- - - foo - * bar + - QGLContext + * bindTexture(QString) now supports DDS, ETC1, PVRTC2, and PVRTC4 + compressed textures if the appropriate extensions are present + in the GL implementation. QtScript -------- -- cgit v0.12 From 8f27913d0558c96a781b81834396374318b70fd6 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Mon, 7 Dec 2009 08:32:53 +1000 Subject: Automatically destroy VG pixmaps when the last window surface goes away Under S60, Qt will destroy the window surfaces of an application that goes into the background, which frees up EGL surface objects. But the VGImage's for pixmaps, and the EGLContext, were still using GPU memory. This change keeps track of the number of widgets / window surfaces that are in use and then calls hibernate() on all QVGPixmapData objects when it goes to zero. Once all the VGImage's are destroyed, the EGLContext should also be destroyed. Task-number: QT-2555 Reviewed-by: Sarah Smith --- src/openvg/qpixmapdata_vg.cpp | 33 ++++++++-- src/openvg/qpixmapdata_vg_p.h | 31 ++++++++- src/openvg/qvg_p.h | 10 ++- src/openvg/qwindowsurface_vgegl.cpp | 124 ++++++++++++++++++++++++++++++------ 4 files changed, 169 insertions(+), 29 deletions(-) diff --git a/src/openvg/qpixmapdata_vg.cpp b/src/openvg/qpixmapdata_vg.cpp index 19c90ed..5d5fcbf 100644 --- a/src/openvg/qpixmapdata_vg.cpp +++ b/src/openvg/qpixmapdata_vg.cpp @@ -65,12 +65,21 @@ QVGPixmapData::QVGPixmapData(PixelType type) recreate = true; #if !defined(QT_NO_EGL) context = 0; + qt_vg_register_pixmap(this); #endif setSerialNumber(++qt_vg_pixmap_serial); } QVGPixmapData::~QVGPixmapData() { + destroyImageAndContext(); +#if !defined(QT_NO_EGL) + qt_vg_unregister_pixmap(this); +#endif +} + +void QVGPixmapData::destroyImageAndContext() +{ if (vgImage != VG_INVALID_HANDLE) { // We need to have a context current to destroy the image. #if !defined(QT_NO_EGL) @@ -93,11 +102,16 @@ QVGPixmapData::~QVGPixmapData() if (vgImageOpacity != VG_INVALID_HANDLE) vgDestroyImage(vgImageOpacity); #endif + vgImage = VG_INVALID_HANDLE; + vgImageOpacity = VG_INVALID_HANDLE; } #if !defined(QT_NO_EGL) - if (context) - qt_vg_destroy_context(context); + if (context) { + qt_vg_destroy_context(context, QInternal::Pixmap); + context = 0; + } #endif + recreate = true; } QPixmapData *QVGPixmapData::createCompatiblePixmapData() const @@ -217,7 +231,7 @@ VGImage QVGPixmapData::toVGImage() #if !defined(QT_NO_EGL) // Increase the reference count on the shared context. if (!context) - context = qt_vg_create_context(0); + context = qt_vg_create_context(0, QInternal::Pixmap); #endif if (recreate && prevSize != QSize(w, h)) { @@ -286,6 +300,17 @@ VGImage QVGPixmapData::toVGImage(qreal opacity) #endif } +void QVGPixmapData::hibernate() +{ + // If the image was imported (e.g, from an SgImage under Symbian), + // then we cannot copy it back to main memory for storage. + if (vgImage != VG_INVALID_HANDLE && source.isNull()) + return; + + forceToImage(); + destroyImageAndContext(); +} + extern int qt_defaultDpiX(); extern int qt_defaultDpiY(); @@ -376,7 +401,7 @@ void QVGPixmapData::fromNativeType(void* pixmap, NativeType type) // when "0" used as argument then // default display, context are used if (!context) - context = qt_vg_create_context(0); + context = qt_vg_create_context(0, QInternal::Pixmap); if (vgImage != VG_INVALID_HANDLE) { vgDestroyImage(vgImage); diff --git a/src/openvg/qpixmapdata_vg_p.h b/src/openvg/qpixmapdata_vg_p.h index fe19f35..c0bb098 100644 --- a/src/openvg/qpixmapdata_vg_p.h +++ b/src/openvg/qpixmapdata_vg_p.h @@ -55,8 +55,6 @@ #include #include -#if !defined(QT_NO_EGL) -#endif #if defined(Q_OS_SYMBIAN) class RSGImage; @@ -66,6 +64,15 @@ QT_BEGIN_NAMESPACE class QEglContext; +#if !defined(QT_NO_EGL) +class QVGPixmapData; +class QVGSharedContext; + +void qt_vg_register_pixmap(QVGPixmapData *pd); +void qt_vg_unregister_pixmap(QVGPixmapData *pd); +void qt_vg_hibernate_pixmaps(QVGSharedContext *context); +#endif + class Q_OPENVG_EXPORT QVGPixmapData : public QPixmapData { public: @@ -94,6 +101,14 @@ public: // Return the VGImage form for a specific opacity setting. virtual VGImage toVGImage(qreal opacity); + // Release the VG resources associated with this pixmap and copy + // the pixmap's contents out of the GPU back into main memory. + // The VG resource will be automatically recreated the next time + // toVGImage() is called. Does nothing if the pixmap cannot be + // hibernated for some reason (e.g. VGImage is shared with another + // process via a SgImage). + virtual void hibernate(); + QSize size() const { return QSize(w, h); } #if defined(Q_OS_SYMBIAN) @@ -108,6 +123,16 @@ protected: void cleanup(); #endif +#if !defined(QT_NO_EGL) +private: + QVGPixmapData *next; + QVGPixmapData *prev; + + friend void qt_vg_register_pixmap(QVGPixmapData *pd); + friend void qt_vg_unregister_pixmap(QVGPixmapData *pd); + friend void qt_vg_hibernate_pixmaps(QVGSharedContext *context); +#endif + protected: QSize prevSize; VGImage vgImage; @@ -121,6 +146,8 @@ protected: void forceToImage(); QImage::Format sourceFormat() const; + + void destroyImageAndContext(); }; QT_END_NAMESPACE diff --git a/src/openvg/qvg_p.h b/src/openvg/qvg_p.h index 04e2bab..3577013 100644 --- a/src/openvg/qvg_p.h +++ b/src/openvg/qvg_p.h @@ -71,11 +71,17 @@ class QEglContext; // Create an EGL context, but don't bind it to a surface. If single-context // mode is enabled, this will return the previously-created context. -Q_OPENVG_EXPORT QEglContext *qt_vg_create_context(QPaintDevice *device); +// "devType" indicates the type of device using the context, usually +// QInternal::Widget or QInternal::Pixmap. +Q_OPENVG_EXPORT QEglContext *qt_vg_create_context + (QPaintDevice *device, int devType); // Destroy an EGL context that was created by qt_vg_create_context(). // If single-context mode is enabled, this will decrease the reference count. -Q_OPENVG_EXPORT void qt_vg_destroy_context(QEglContext *context); +// "devType" indicates the type of device destroying the context, usually +// QInternal::Widget or QInternal::Pixmap. +Q_OPENVG_EXPORT void qt_vg_destroy_context + (QEglContext *context, int devType); // Return the shared pbuffer surface that can be made current to // destroy VGImage objects when there is no other surface available. diff --git a/src/openvg/qwindowsurface_vgegl.cpp b/src/openvg/qwindowsurface_vgegl.cpp index 62871cf..1571083 100644 --- a/src/openvg/qwindowsurface_vgegl.cpp +++ b/src/openvg/qwindowsurface_vgegl.cpp @@ -111,15 +111,19 @@ public: QEglContext *context; int refCount; + int widgetRefCount; QVGPaintEngine *engine; EGLSurface surface; + QVGPixmapData *firstPixmap; }; QVGSharedContext::QVGSharedContext() : context(0) , refCount(0) + , widgetRefCount(0) , engine(0) , surface(EGL_NO_SURFACE) + , firstPixmap(0) { } @@ -154,6 +158,28 @@ void qt_vg_destroy_paint_engine(QVGPaintEngine *engine) Q_UNUSED(engine); } +void qt_vg_register_pixmap(QVGPixmapData *pd) +{ + QVGSharedContext *shared = sharedContext(); + pd->next = shared->firstPixmap; + pd->prev = 0; + if (shared->firstPixmap) + shared->firstPixmap->prev = pd; + shared->firstPixmap = pd; +} + +void qt_vg_unregister_pixmap(QVGPixmapData *pd) +{ + if (pd->next) + pd->next->prev = pd->prev; + if (pd->prev) { + pd->prev->next = pd->next; + } else { + QVGSharedContext *shared = sharedContext(); + shared->firstPixmap = pd->next; + } +} + #else QVGPaintEngine *qt_vg_create_paint_engine(void) @@ -166,6 +192,16 @@ void qt_vg_destroy_paint_engine(QVGPaintEngine *engine) delete engine; } +void qt_vg_register_pixmap(QVGPixmapData *pd) +{ + Q_UNUSED(pd); +} + +void qt_vg_unregister_pixmap(QVGPixmapData *pd) +{ + Q_UNUSED(pd); +} + #endif #ifdef EGL_VG_ALPHA_FORMAT_PRE_BIT @@ -278,9 +314,11 @@ static QEglContext *createContext(QPaintDevice *device) #if !defined(QVG_NO_SINGLE_CONTEXT) -QEglContext *qt_vg_create_context(QPaintDevice *device) +QEglContext *qt_vg_create_context(QPaintDevice *device, int devType) { QVGSharedContext *shared = sharedContext(); + if (devType == QInternal::Widget) + ++(shared->widgetRefCount); if (shared->context) { ++(shared->refCount); return shared->context; @@ -291,23 +329,65 @@ QEglContext *qt_vg_create_context(QPaintDevice *device) } } -void qt_vg_destroy_context(QEglContext *context) +static void qt_vg_destroy_shared_context(QVGSharedContext *shared) +{ + shared->context->makeCurrent(qt_vg_shared_surface()); + delete shared->engine; + shared->engine = 0; + shared->context->doneCurrent(); + if (shared->surface != EGL_NO_SURFACE) { + eglDestroySurface(shared->context->display(), shared->surface); + shared->surface = EGL_NO_SURFACE; + } + delete shared->context; + shared->context = 0; +} + +void qt_vg_hibernate_pixmaps(QVGSharedContext *shared) +{ + // Artificially increase the reference count to prevent the + // context from being destroyed until after we have finished + // the hibernation process. + ++(shared->refCount); + + // We need a context current to hibernate the VGImage objects. + shared->context->makeCurrent(qt_vg_shared_surface()); + + // Scan all QVGPixmapData objects in the system and hibernate them. + QVGPixmapData *pd = shared->firstPixmap; + while (pd != 0) { + pd->hibernate(); + pd = pd->next; + } + + // Don't need the current context any more. + shared->context->lazyDoneCurrent(); + + // Decrease the reference count and destroy the context if necessary. + if (--(shared->refCount) <= 0) + qt_vg_destroy_shared_context(shared); +} + +void qt_vg_destroy_context(QEglContext *context, int devType) { QVGSharedContext *shared = sharedContext(); if (shared->context != context) { // This is not the shared context. Shouldn't happen! delete context; - } else if (--(shared->refCount) <= 0) { - shared->context->makeCurrent(qt_vg_shared_surface()); - delete shared->engine; - shared->engine = 0; - shared->context->doneCurrent(); - if (shared->surface != EGL_NO_SURFACE) { - eglDestroySurface(shared->context->display(), shared->surface); - shared->surface = EGL_NO_SURFACE; - } - delete shared->context; - shared->context = 0; + return; + } + if (devType == QInternal::Widget) + --(shared->widgetRefCount); + if (--(shared->refCount) <= 0) { + qt_vg_destroy_shared_context(shared); + } else if (shared->widgetRefCount <= 0 && devType == QInternal::Widget) { + // All of the widget window surfaces have been destroyed + // but we still have VG pixmaps active. Ask them to hibernate + // to free up GPU resources until a widget is shown again. + // This may eventually cause the EGLContext to be destroyed + // because nothing in the system needs a context, which will + // free up even more GPU resources. + qt_vg_hibernate_pixmaps(shared); } } @@ -338,13 +418,15 @@ EGLSurface qt_vg_shared_surface(void) #else -QEglContext *qt_vg_create_context(QPaintDevice *device) +QEglContext *qt_vg_create_context(QPaintDevice *device, int devType) { + Q_UNUSED(devType); return createContext(device); } -void qt_vg_destroy_context(QEglContext *context) +void qt_vg_destroy_context(QEglContext *context, int devType) { + Q_UNUSED(devType); delete context; } @@ -434,7 +516,7 @@ QVGEGLWindowSurfaceVGImage::~QVGEGLWindowSurfaceVGImage() } if (windowSurface != EGL_NO_SURFACE) context->destroySurface(windowSurface); - qt_vg_destroy_context(context); + qt_vg_destroy_context(context, QInternal::Widget); } } @@ -453,7 +535,7 @@ QEglContext *QVGEGLWindowSurfaceVGImage::ensureContext(QWidget *widget) if (!context) { // Create a new EGL context. We create the surface in beginPaint(). size = newSize; - context = qt_vg_create_context(widget); + context = qt_vg_create_context(widget, QInternal::Widget); if (!context) return 0; isPaintingActive = false; @@ -548,7 +630,7 @@ QVGEGLWindowSurfaceDirect::~QVGEGLWindowSurfaceDirect() if (context) { if (windowSurface != EGL_NO_SURFACE) context->destroySurface(windowSurface); - qt_vg_destroy_context(context); + qt_vg_destroy_context(context, QInternal::Widget); } } @@ -587,7 +669,7 @@ QEglContext *QVGEGLWindowSurfaceDirect::ensureContext(QWidget *widget) qt_vg_destroy_paint_engine(engine); engine = 0; context->destroySurface(windowSurface); - qt_vg_destroy_context(context); + qt_vg_destroy_context(context, QInternal::Widget); context = 0; windowSurface = EGL_NO_SURFACE; } @@ -596,7 +678,7 @@ QEglContext *QVGEGLWindowSurfaceDirect::ensureContext(QWidget *widget) if (!context) { // Create a new EGL context and bind it to the widget surface. size = newSize; - context = qt_vg_create_context(widget); + context = qt_vg_create_context(widget, QInternal::Widget); if (!context) return 0; // We want a direct to window rendering surface if possible. @@ -613,7 +695,7 @@ QEglContext *QVGEGLWindowSurfaceDirect::ensureContext(QWidget *widget) #endif EGLSurface surface = context->createSurface(widget, &surfaceProps); if (surface == EGL_NO_SURFACE) { - qt_vg_destroy_context(context); + qt_vg_destroy_context(context, QInternal::Widget); context = 0; return 0; } -- cgit v0.12 From 8fea31ca0ab98ef6fed7bb2d87d97f4f425b2078 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Mon, 7 Dec 2009 10:07:13 +1000 Subject: Detect GL2 paint engine based on fragment shaders, not programs The auto-detect logic was looking for fragment programs to check for OpenGL2 support. It should have been looking for fragment shaders. Task-number: QTBUG-5638 Reviewed-by: Sarah Smith --- src/opengl/qgl.cpp | 7 +++++-- src/opengl/qgl_p.h | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index b376901..1ff102f 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -173,12 +173,12 @@ public: #else // We can't do this in the constructor for this object because it // needs to be called *before* the QApplication constructor. - // Also check for the FragmentProgram extension in conjunction with + // Also check for the FragmentShader extension in conjunction with // the 2.0 version flag, to cover the case where we export the display // from an old GL 1.1 server to a GL 2.x client. In that case we can't // use GL 2.0. if ((QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_2_0) - && (QGLExtensions::glExtensions & QGLExtensions::FragmentProgram) + && (QGLExtensions::glExtensions & QGLExtensions::FragmentShader) && qgetenv("QT_GL_USE_OPENGL1ENGINE").isEmpty()) engineType = QPaintEngine::OpenGL2; else @@ -4832,6 +4832,8 @@ void QGLExtensions::init_extensions() glExtensions |= PVRTCTextureCompression; if (extensions.contains("GL_ARB_fragment_program")) glExtensions |= FragmentProgram; + if (extensions.contains("GL_ARB_fragment_shader")) + glExtensions |= FragmentShader; if (extensions.contains("GL_ARB_texture_mirrored_repeat")) glExtensions |= MirroredRepeat; if (extensions.contains("GL_EXT_framebuffer_object")) @@ -4849,6 +4851,7 @@ void QGLExtensions::init_extensions() #if defined(QT_OPENGL_ES_2) glExtensions |= FramebufferObject; glExtensions |= GenerateMipmap; + glExtensions |= FragmentShader; #endif #if defined(QT_OPENGL_ES_1) || defined(QT_OPENGL_ES_1_CL) if (extensions.contains("GL_OES_framebuffer_object")) diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index 0f785a5..179d69a 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -383,7 +383,8 @@ public: BGRATextureFormat = 0x00004000, DDSTextureCompression = 0x00008000, ETC1TextureCompression = 0x00010000, - PVRTCTextureCompression = 0x00020000 + PVRTCTextureCompression = 0x00020000, + FragmentShader = 0x00040000 }; Q_DECLARE_FLAGS(Extensions, Extension) -- cgit v0.12 From 91b4a40bd3cc9d004baddd9c19ced07ed37afef2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Meril=C3=A4?= Date: Mon, 7 Dec 2009 11:44:03 +0200 Subject: Remove compilation warning from S60pixelMetrics on ARM Compiling s60pixelMetrics utility for ARMV5 urel gives two warnings: a) unused variable - Solution: removed b) transfer of control bypasses initialization (missing brackets within a switch-case) - Solution: brackets added. Reviewed-by: TrustMe --- util/s60pixelmetrics/pixel_metrics.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/util/s60pixelmetrics/pixel_metrics.cpp b/util/s60pixelmetrics/pixel_metrics.cpp index 9507c67..9ba6c8b 100644 --- a/util/s60pixelmetrics/pixel_metrics.cpp +++ b/util/s60pixelmetrics/pixel_metrics.cpp @@ -812,13 +812,12 @@ TInt PixelMetrics::PixelMetricValue(QStyle::PixelMetric metric) value = PixelMetricMenuValue(metric, mainPaneRect); break; case QStyle::PM_ButtonIconSize: + { //lets use voice recorder icons as a base //Unfortunately S60 graphics don't separate button bevel graphics from the actual icon. //Se we have no means to query the margin from bevel border to "central icon" border. //So, we need to make a estimate... - const TInt varietyForButtons = !landscape ? 0 : 1; - TAknLayoutRect vRMainRect; vRMainRect.LayoutRect( mainPaneRect, AknLayoutScalable_Apps::main_vorec_pane() ); @@ -833,7 +832,7 @@ TInt PixelMetrics::PixelMetricValue(QStyle::PixelMetric metric) // 0.32 is the estimate how much the icon occupies of the button bevel area value = vRButtonCellGraphicsRect.Rect().Width() * 0.32; - + } break; case QStyle::PM_SmallIconSize: { -- cgit v0.12 From cfd98763a1d051238382b77975567da0c0562ade Mon Sep 17 00:00:00 2001 From: Paul Olav Tvete Date: Mon, 7 Dec 2009 10:58:58 +0100 Subject: Fix programming error in autotest commit 8529a8cbb setWindowFlags() resets the flags, so the previous version only worked on X11. --- tests/auto/qmenu/tst_qmenu.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/auto/qmenu/tst_qmenu.cpp b/tests/auto/qmenu/tst_qmenu.cpp index 6079189..af10ad1 100644 --- a/tests/auto/qmenu/tst_qmenu.cpp +++ b/tests/auto/qmenu/tst_qmenu.cpp @@ -910,8 +910,7 @@ void tst_QMenu::deleteActionInTriggered() void tst_QMenu::pushButtonPopulateOnAboutToShow() { QPushButton b("Test PushButton"); - b.setWindowFlags(Qt::FramelessWindowHint); - b.setWindowFlags(Qt::X11BypassWindowManagerHint); + b.setWindowFlags(Qt::FramelessWindowHint | Qt::X11BypassWindowManagerHint); lastMenu = new QMenu; b.setMenu(lastMenu); const int scrNumber = QApplication::desktop()->screenNumber(&b); -- cgit v0.12 From 245c9cc07ff1581dd126f213985c3557b2667aca Mon Sep 17 00:00:00 2001 From: Janne Anttila Date: Mon, 7 Dec 2009 14:05:01 +0200 Subject: Added dimming support for disabled softkeys in Symbian. If QAction::setEnabled(false) is called, the CBA buttons are dimmed to have visual indication about disabled state. Since enabled/disabled state of buttons in QDialogButtonBox is controlled via QPushButton::setEnabled API, and because button box content in Symbian is mapped to sofkkeys we also need to have proxy for button enabled state to forward the information for underlying QAction. Reviewed-by: Sami Merila --- src/gui/kernel/qsoftkeymanager.cpp | 5 ++++- src/gui/widgets/qdialogbuttonbox.cpp | 28 +++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/gui/kernel/qsoftkeymanager.cpp b/src/gui/kernel/qsoftkeymanager.cpp index 30c67f4..464a250 100644 --- a/src/gui/kernel/qsoftkeymanager.cpp +++ b/src/gui/kernel/qsoftkeymanager.cpp @@ -254,7 +254,10 @@ void QSoftKeyManagerPrivate::updateSoftKeys_sys(const QList &softkeys) const int underlineShortCut = QApplication::style()->styleHint(QStyle::SH_UnderlineShortcut); QString iconText = softKeyAction->iconText(); TPtrC text = qt_QString2TPtrC( underlineShortCut ? softKeyAction->text() : iconText); - QT_TRAP_THROWING(nativeContainer->SetCommandL(position, command, text)); + QT_TRAP_THROWING( + nativeContainer->SetCommandL(position, command, text); + nativeContainer->DimCommand(command, !softKeyAction->isEnabled()); + ); } } diff --git a/src/gui/widgets/qdialogbuttonbox.cpp b/src/gui/widgets/qdialogbuttonbox.cpp index 0e859f1..56cf545 100644 --- a/src/gui/widgets/qdialogbuttonbox.cpp +++ b/src/gui/widgets/qdialogbuttonbox.cpp @@ -259,6 +259,30 @@ static const int layouts[2][5][14] = } }; +class QDialogButtonEnabledProxy : public QObject +{ +public: + QDialogButtonEnabledProxy(QObject *parent, QWidget *src, QAction *trg) : QObject(parent), source(src), target(trg) + { + source->installEventFilter(this); + } + ~QDialogButtonEnabledProxy() + { + source->removeEventFilter(this); + } + bool eventFilter(QObject *object, QEvent *event) + { + if (object == source && event->type() == QEvent::EnabledChange) { + target->setEnabled(source->isEnabled()); + } + return false; + }; +private: + QWidget *source; + QAction *target; +}; + + class QDialogButtonBoxPrivate : public QWidgetPrivate { Q_DECLARE_PUBLIC(QDialogButtonBox) @@ -548,7 +572,9 @@ void QDialogButtonBoxPrivate::addButton(QAbstractButton *button, QDialogButtonBo QObject::connect(button, SIGNAL(destroyed()), q, SLOT(_q_handleButtonDestroyed())); buttonLists[role].append(button); #ifdef QT_SOFTKEYS_ENABLED - softKeyActions.insert(button, createSoftKey(button, role)); + QAction *action = createSoftKey(button, role); + softKeyActions.insert(button, action); + new QDialogButtonEnabledProxy(action, button, action); #endif if (doLayout) layoutButtons(); -- cgit v0.12 From 41754fdb11a4d78b7b756b82d4ead235b6618687 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sami=20Meril=C3=A4?= Date: Mon, 7 Dec 2009 14:59:07 +0200 Subject: FEP returns the wrong foreground color in GetFormatOfFepInlineText When using T9, FEP is always using black text color. This is due to that we use default parameters for TFontPresentation. If we change the text color according to style, before calling GetFormatOfFepInlineText, it uses color value from style. Task-number: QTBUG-4072 Reviewed-by: axis --- src/gui/inputmethod/qcoefepinputcontext_s60.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp index bdff5e7..a295d66 100644 --- a/src/gui/inputmethod/qcoefepinputcontext_s60.cpp +++ b/src/gui/inputmethod/qcoefepinputcontext_s60.cpp @@ -437,6 +437,10 @@ void QCoeFepInputContext::applyHints(Qt::InputMethodHints hints) void QCoeFepInputContext::applyFormat(QList *attributes) { TCharFormat cFormat; + QColor styleTextColor = QApplication::palette("QLineEdit").text().color(); + TLogicalRgb tontColor(TRgb(styleTextColor.red(), styleTextColor.green(), styleTextColor.blue(), styleTextColor.alpha())); + cFormat.iFontPresentation.iTextColor = tontColor; + TInt numChars = 0; TInt charPos = 0; int oldSize = attributes->size(); -- cgit v0.12 From 7ad244cad155f32f22e82e1458eb1c42f759a620 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Mon, 7 Dec 2009 14:01:54 +0100 Subject: Fix the toolbars docking The gap could be inserted even if the toolbar is very far away. This is due to the fact that we were only considering the distance as 1-directional. Now we also check that mouse position is inside the main window. Reviewed-by: gabi --- src/gui/widgets/qtoolbararealayout.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/gui/widgets/qtoolbararealayout.cpp b/src/gui/widgets/qtoolbararealayout.cpp index c329305..b83026b 100644 --- a/src/gui/widgets/qtoolbararealayout.cpp +++ b/src/gui/widgets/qtoolbararealayout.cpp @@ -598,16 +598,21 @@ int QToolBarAreaLayoutInfo::distance(const QPoint &pos) const { switch (dockPos) { case QInternal::LeftDock: - return pos.x() - rect.right(); + if (pos.y() < rect.bottom()) + return pos.x() - rect.right(); case QInternal::RightDock: - return rect.left() - pos.x(); + if (pos.y() < rect.bottom()) + return rect.left() - pos.x(); case QInternal::TopDock: - return pos.y() - rect.bottom(); + if (pos.x() < rect.right()) + return pos.y() - rect.bottom(); case QInternal::BottomDock: - return rect.top() - pos.y(); + if (pos.x() < rect.right()) + return rect.top() - pos.y(); default: - return -1; + break; } + return -1; } /****************************************************************************** -- cgit v0.12 From fb78a402b512b017c850e7410745c4d20da04a7c Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Mon, 7 Dec 2009 15:04:42 +0100 Subject: Fixed memory leaks when removing a QGraphicsEffect from a QGraphicsItem or QWidget with setGraphicsEffect(0). The effect was not deleted in that case, problem solved for both QGraphicsItem and QWidget. Autotest included. Task-number: QTBUG-5917 Reviewed-by: bnilsen --- src/gui/graphicsview/qgraphicsitem.cpp | 19 +++---------------- src/gui/graphicsview/qgraphicsitem_p.h | 5 ++++- src/gui/kernel/qwidget.cpp | 14 ++++---------- src/gui/kernel/qwidget.h | 1 + src/gui/kernel/qwidget_p.h | 2 +- tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 16 ++++++++++++++++ tests/auto/qwidget/tst_qwidget.cpp | 16 ++++++++++++++++ 7 files changed, 45 insertions(+), 28 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index f93ffdf..9e8d587 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -2563,32 +2563,19 @@ void QGraphicsItem::setGraphicsEffect(QGraphicsEffect *effect) if (d_ptr->graphicsEffect == effect) return; - if (d_ptr->graphicsEffect && effect) { + if (d_ptr->graphicsEffect) { delete d_ptr->graphicsEffect; d_ptr->graphicsEffect = 0; } - if (!effect) { - // Unset current effect. - QGraphicsEffectPrivate *oldEffectPrivate = d_ptr->graphicsEffect->d_func(); - d_ptr->graphicsEffect = 0; - if (oldEffectPrivate) { - oldEffectPrivate->setGraphicsEffectSource(0); // deletes the current source. - if (d_ptr->scene) { // Update the views directly. - d_ptr->scene->d_func()->markDirty(this, QRectF(), /*invalidateChildren=*/false, - /*force=*/false, /*ignoreOpacity=*/false, - /*removeItemFromScene=*/true); - } - } - } else { + if (effect) { // Set new effect. QGraphicsEffectSourcePrivate *sourced = new QGraphicsItemEffectSourcePrivate(this); QGraphicsEffectSource *source = new QGraphicsEffectSource(*sourced); d_ptr->graphicsEffect = effect; effect->d_func()->setGraphicsEffectSource(source); + prepareGeometryChange(); } - - prepareGeometryChange(); } #endif //QT_NO_GRAPHICSEFFECT diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index d6ffb1a..8f9fe54 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -562,7 +562,10 @@ public: {} inline void detach() - { item->setGraphicsEffect(0); } + { + item->d_ptr->graphicsEffect = 0; + item->prepareGeometryChange(); + } inline const QGraphicsItem *graphicsItem() const { return item; } diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index d19c574..00c7dc0 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -5059,28 +5059,22 @@ void QWidget::setGraphicsEffect(QGraphicsEffect *effect) if (d->graphicsEffect == effect) return; - if (d->graphicsEffect && effect) { + if (d->graphicsEffect) { + d->invalidateBuffer(rect()); delete d->graphicsEffect; d->graphicsEffect = 0; } - if (!effect) { - // Unset current effect. - QGraphicsEffectPrivate *oldEffectPrivate = d->graphicsEffect->d_func(); - d->graphicsEffect = 0; - if (oldEffectPrivate) { - oldEffectPrivate->setGraphicsEffectSource(0); // deletes the current source. - } - } else { + if (effect) { // Set new effect. QGraphicsEffectSourcePrivate *sourced = new QWidgetEffectSourcePrivate(this); QGraphicsEffectSource *source = new QGraphicsEffectSource(*sourced); d->graphicsEffect = effect; effect->d_func()->setGraphicsEffectSource(source); + update(); } d->updateIsOpaque(); - update(); } #endif //QT_NO_GRAPHICSEFFECT diff --git a/src/gui/kernel/qwidget.h b/src/gui/kernel/qwidget.h index 5ba1d23..0824db3 100644 --- a/src/gui/kernel/qwidget.h +++ b/src/gui/kernel/qwidget.h @@ -744,6 +744,7 @@ private: friend struct QWidgetExceptionCleaner; friend class QGestureManager; friend class QWinNativePanGestureRecognizer; + friend class QWidgetEffectSourcePrivate; #ifdef Q_WS_MAC friend class QCoreGraphicsPaintEnginePrivate; diff --git a/src/gui/kernel/qwidget_p.h b/src/gui/kernel/qwidget_p.h index 04cf4bb..5d73951 100644 --- a/src/gui/kernel/qwidget_p.h +++ b/src/gui/kernel/qwidget_p.h @@ -823,7 +823,7 @@ public: {} inline void detach() - { m_widget->setGraphicsEffect(0); } + { m_widget->d_func()->graphicsEffect = 0; } inline const QGraphicsItem *graphicsItem() const { return 0; } diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index 565a3e7..6266933 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -7962,6 +7962,22 @@ void tst_QGraphicsItem::setGraphicsEffect() delete item; QVERIFY(!blurEffect); delete anotherItem; + + // Ensure the effect is uninstalled when deleting it + item = new QGraphicsRectItem(0, 0, 10, 10); + blurEffect = new QGraphicsBlurEffect; + item->setGraphicsEffect(blurEffect); + delete blurEffect; + QVERIFY(!item->graphicsEffect()); + + // Ensure the existing effect is uninstalled and deleted when setting a null effect + blurEffect = new QGraphicsBlurEffect; + item->setGraphicsEffect(blurEffect); + item->setGraphicsEffect(0); + QVERIFY(!item->graphicsEffect()); + QVERIFY(!blurEffect); + + delete item; } void tst_QGraphicsItem::panel() diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp index 9960f47..3e14b56 100644 --- a/tests/auto/qwidget/tst_qwidget.cpp +++ b/tests/auto/qwidget/tst_qwidget.cpp @@ -9549,6 +9549,22 @@ void tst_QWidget::setGraphicsEffect() delete widget; QVERIFY(!blurEffect); delete anotherWidget; + + // Ensure the effect is uninstalled when deleting it + widget = new QWidget; + blurEffect = new QGraphicsBlurEffect; + widget->setGraphicsEffect(blurEffect); + delete blurEffect; + QVERIFY(!widget->graphicsEffect()); + + // Ensure the existing effect is uninstalled and deleted when setting a null effect + blurEffect = new QGraphicsBlurEffect; + widget->setGraphicsEffect(blurEffect); + widget->setGraphicsEffect(0); + QVERIFY(!widget->graphicsEffect()); + QVERIFY(!blurEffect); + + delete widget; } void tst_QWidget::activateWindow() -- cgit v0.12 From 9a45e1853374c735dc08bf2e23b9d820900b1ccb Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Mon, 7 Dec 2009 13:40:14 +0100 Subject: Assert in designer while drag & dropping items from a QListWidget Did not honour returned value from beginMoveRows(). Auto-test included. Reviewed-by: leo Task-number: QTBUG-6532 --- src/gui/itemviews/qlistwidget.cpp | 3 ++- tests/auto/qlistwidget/tst_qlistwidget.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/itemviews/qlistwidget.cpp b/src/gui/itemviews/qlistwidget.cpp index 5dd1d76..929d688 100644 --- a/src/gui/itemviews/qlistwidget.cpp +++ b/src/gui/itemviews/qlistwidget.cpp @@ -176,7 +176,8 @@ void QListModel::move(int srcRow, int dstRow) || dstRow < 0 || dstRow >= items.count()) return; - beginMoveRows(QModelIndex(), srcRow, srcRow, QModelIndex(), dstRow); + if (!beginMoveRows(QModelIndex(), srcRow, srcRow, QModelIndex(), dstRow)) + return; if (srcRow < dstRow) --dstRow; items.move(srcRow, dstRow); diff --git a/tests/auto/qlistwidget/tst_qlistwidget.cpp b/tests/auto/qlistwidget/tst_qlistwidget.cpp index cb8f1e9..863c308 100644 --- a/tests/auto/qlistwidget/tst_qlistwidget.cpp +++ b/tests/auto/qlistwidget/tst_qlistwidget.cpp @@ -867,6 +867,7 @@ void tst_QListWidget::moveItemsPriv_data() QTest::newRow("Same place") << 5 << 2 << 2 << false; QTest::newRow("Up") << 5 << 4 << 2 << true; QTest::newRow("Down") << 5 << 2 << 4 << true; + QTest::newRow("QTBUG-6532 assert") << 5 << 0 << 1 << false; } void tst_QListWidget::moveItemsPriv() -- cgit v0.12 From ac90a37e5bec3c5b6cdc01a836f8e562395a3863 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Mon, 7 Dec 2009 16:48:04 +0100 Subject: Compilation fix --- src/gui/widgets/qdialogbuttonbox.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/gui/widgets/qdialogbuttonbox.cpp b/src/gui/widgets/qdialogbuttonbox.cpp index 56cf545..47ddc52 100644 --- a/src/gui/widgets/qdialogbuttonbox.cpp +++ b/src/gui/widgets/qdialogbuttonbox.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include "qdialogbuttonbox.h" -- cgit v0.12 From 05d4b4c72a5089885c1515833e34177607c2c511 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Tue, 8 Dec 2009 11:02:46 +1000 Subject: Fix GL_BGRA formats under OpenGL/ES systems OpenGL/ES requires that the internal and external formats be the same when calling glTexImage2D(). This caused problems with devices that had the GL_EXT_bgra extension. This change makes the formats the same just before the upload and also makes sure that the pixel type is GL_UNSIGNED_BYTE when GL_BGRA is used. No change for desktop systems. Reviewed-by: Donald Carr --- src/opengl/qgl.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 1ff102f..967ba48 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -2234,6 +2234,14 @@ QGLTexture* QGLContextPrivate::bindTexture(const QImage &image, GLenum target, G } } } +#ifdef QT_OPENGL_ES + // OpenGL/ES requires that the internal and external formats be identical. + // This is typically used to convert GL_RGBA into GL_BGRA. + // Also, we need to use GL_UNSIGNED_BYTE when the format is GL_BGRA. + internalFormat = externalFormat; + if (pixel_type == GL_UNSIGNED_INT_8_8_8_8_REV) + pixel_type = GL_UNSIGNED_BYTE; +#endif #ifdef QGL_BIND_TEXTURE_DEBUG printf(" - uploading, image.format=%d, externalFormat=0x%x, internalFormat=0x%x, pixel_type=0x%x\n", img.format(), externalFormat, internalFormat, pixel_type); -- cgit v0.12 From 854d8960b98a691094ac51ad69b60d6a3a798ac2 Mon Sep 17 00:00:00 2001 From: Janne Anttila Date: Tue, 8 Dec 2009 09:57:08 +0200 Subject: Minor fixes to softkey dimming support (commit 245c9cc0). In Qt invisible actions are disabled by default, and our "Options" softkey is set to invisible in order that it is not show in context menu. Thus we need don't want to dim in softkey even it is disabled. Additionally, QDialogButtonEnabledProxy need to set the initial enabled state for proxy action from button. Fixes bugs in commit: 245c9cc0 Reviewed-by: TrustMe --- src/gui/kernel/qsoftkeymanager.cpp | 6 +++++- src/gui/widgets/qdialogbuttonbox.cpp | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qsoftkeymanager.cpp b/src/gui/kernel/qsoftkeymanager.cpp index 464a250..0e98f39 100644 --- a/src/gui/kernel/qsoftkeymanager.cpp +++ b/src/gui/kernel/qsoftkeymanager.cpp @@ -250,13 +250,17 @@ void QSoftKeyManagerPrivate::updateSoftKeys_sys(const QList &softkeys) ? EAknSoftkeyOptions : s60CommandStart + index; + // _q_menuSoftKeyAction action is set to "invisible" and all invisible actions are by default + // disabled. However we never want to dim options softkey, even it is set to "invisible" + bool dimmed = (command == EAknSoftkeyOptions) ? false : !softKeyAction->isEnabled(); + if (position != -1) { const int underlineShortCut = QApplication::style()->styleHint(QStyle::SH_UnderlineShortcut); QString iconText = softKeyAction->iconText(); TPtrC text = qt_QString2TPtrC( underlineShortCut ? softKeyAction->text() : iconText); QT_TRAP_THROWING( nativeContainer->SetCommandL(position, command, text); - nativeContainer->DimCommand(command, !softKeyAction->isEnabled()); + nativeContainer->DimCommand(command, dimmed); ); } } diff --git a/src/gui/widgets/qdialogbuttonbox.cpp b/src/gui/widgets/qdialogbuttonbox.cpp index 56cf545..9512785 100644 --- a/src/gui/widgets/qdialogbuttonbox.cpp +++ b/src/gui/widgets/qdialogbuttonbox.cpp @@ -265,6 +265,7 @@ public: QDialogButtonEnabledProxy(QObject *parent, QWidget *src, QAction *trg) : QObject(parent), source(src), target(trg) { source->installEventFilter(this); + target->setEnabled(source->isEnabled()); } ~QDialogButtonEnabledProxy() { -- cgit v0.12 From 2e110daa8fb3889036db330837884a6aa61a92a1 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 8 Dec 2009 09:32:49 +0100 Subject: Remove id property from QGraphicsObject It is not actually useful (exact same READ/WRITE as objectName) and is confusing when used in QML. Task-number: QTBUG-6580 Reviewed-by: andreas Reviewed-by: alexis Reviewed-by: ogoffart --- src/gui/graphicsview/qgraphicsitem.cpp | 7 ------- src/gui/graphicsview/qgraphicsitem.h | 1 - 2 files changed, 8 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 9e8d587..9846dbb 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -7292,13 +7292,6 @@ void QGraphicsObject::ungrabGesture(Qt::GestureType gesture) */ /*! - \property QGraphicsObject::id - \brief the id of of the item - - \sa QObject::objectName(), QObject::setObjectName() -*/ - -/*! \property QGraphicsObject::opacity \brief the opacity of the item diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index 8bbe9f1..8818a0b 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -537,7 +537,6 @@ class Q_GUI_EXPORT QGraphicsObject : public QObject, public QGraphicsItem { Q_OBJECT Q_PROPERTY(QGraphicsObject * parent READ parentObject WRITE setParentItem NOTIFY parentChanged DESIGNABLE false) - Q_PROPERTY(QString id READ objectName WRITE setObjectName) Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL) -- cgit v0.12 From 4f6dc78fb05026608ffb03dfae905c23a48aac43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Tue, 8 Dec 2009 11:39:31 +0100 Subject: Doc: Explicitly mention that QWidget/QGraphicsItem takes ownership of effects. --- src/gui/graphicsview/qgraphicsitem.cpp | 2 ++ src/gui/kernel/qwidget.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 9846dbb..90cc132 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -2554,6 +2554,8 @@ QGraphicsEffect *QGraphicsItem::graphicsEffect() const If \a effect is the installed on a different item, setGraphicsEffect() will remove the effect from the item and install it on this item. + QGraphicsItem takes ownership of \a effect. + \note This function will apply the effect on itself and all its children. \since 4.6 diff --git a/src/gui/kernel/qwidget.cpp b/src/gui/kernel/qwidget.cpp index 00c7dc0..21aae3e 100644 --- a/src/gui/kernel/qwidget.cpp +++ b/src/gui/kernel/qwidget.cpp @@ -5046,6 +5046,8 @@ QGraphicsEffect *QWidget::graphicsEffect() const If \a effect is the installed on a different widget, setGraphicsEffect() will remove the effect from the widget and install it on this widget. + QWidget takes ownership of \a effect. + \note This function will apply the effect on itself and all its children. \since 4.6 -- cgit v0.12 From 85cd6e646376af5828e66d9df1812759fcf55f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Nilsen?= Date: Tue, 8 Dec 2009 11:52:20 +0100 Subject: Fixes broken graphics effect auto tests. This broke after commit: fb78a402b512b017c850e7410745c4d20da04a7c Effects and auto-tests are now in line with the documentation. --- tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp index d216924..259df4d 100644 --- a/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp +++ b/tests/auto/qgraphicseffect/tst_qgraphicseffect.cpp @@ -196,8 +196,8 @@ void tst_QGraphicsEffect::source() // Uninstall effect on QGraphicsItem. effect->reset(); item->setGraphicsEffect(0); - QVERIFY(!effect->source()); - QVERIFY(effect->m_sourceChangedFlags & QGraphicsEffect::SourceDetached); + QVERIFY(!effect); + effect = new CustomEffect; // The item takes ownership and should delete the effect when destroyed. item->setGraphicsEffect(effect); @@ -249,10 +249,10 @@ void tst_QGraphicsEffect::boundingRect() QCOMPARE(effect->boundingRect(), effect->boundingRectFor(itemRect)); // Uninstall effect on QGraphicsItem. + QPointer ptr = effect; item->setGraphicsEffect(0); - QCOMPARE(effect->boundingRect(), QRectF()); + QVERIFY(!ptr); - delete effect; delete item; } @@ -343,11 +343,11 @@ void tst_QGraphicsEffect::draw() QCOMPARE(item->numRepaints, 0); // Make sure uninstalling an effect triggers a repaint. + QPointer ptr = effect; item->setGraphicsEffect(0); + QVERIFY(!ptr); QTest::qWait(50); - QCOMPARE(effect->numRepaints, 0); QCOMPARE(item->numRepaints, 1); - delete effect; } void tst_QGraphicsEffect::opacity() -- cgit v0.12 From 1de8a5bc428a53158028f5a71319d88538c19c54 Mon Sep 17 00:00:00 2001 From: Eskil Abrahamsen Blomfeldt Date: Tue, 8 Dec 2009 15:07:02 +0100 Subject: Fix possible off-by-one inconsistency against system look and feel when drawing vertically aligned text When text is drawn in a font which has an odd-numbered height and it's vertically aligned in a rectangle which has an even-numbered height (or vice versa) we have to round the y-position, as the backend cannot position the text in subpixels. The y-position in this case will be at half a pixel and we can either round it up or down without increasing the size of the error. In Qt 4.5, the font height would be reported as one higher than what it actually was. Therefore, in many widgets such as comboboxes, we would appear to round the y-position down when faced with this issue. This is apparently also what Windows does, probably because most latin fonts have more glyphs extending into the maximum descent than the ascent. In Qt 4.6, the font height bug was fixed, and since we use qRound() we now round half-pixels up, thus moving all the text faced with this issue one pixel down. This looks odd and inconsistent, both with the platform look and feel and with older versions of Qt. The patch reverts to the old look and feel by rounding the half pixels down rather than up for the particular case in question. Task-number: QTBUG-6578 Reviewed-by: Samuel --- src/gui/painting/qpainter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp index 30f8c9e..66bf4f7 100644 --- a/src/gui/painting/qpainter.cpp +++ b/src/gui/painting/qpainter.cpp @@ -7630,7 +7630,7 @@ start_lengthVariant: // in the paint engines when drawing on floating point offsets const qreal scale = painter->transform().m22(); if (scale != 0) - yoff = qRound(yoff * scale) / scale; + yoff = -qRound(-yoff * scale) / scale; } } } -- cgit v0.12