From 445e8af844ef6f120a5e406271dbeabad34ed47a Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Mon, 9 Nov 2009 13:46:37 +0100 Subject: Fix warnings Reviewed-by: Trust Me --- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 2 +- src/gui/kernel/qgesturemanager.cpp | 1 + src/gui/painting/qbrush.cpp | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 182594e..594a205 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -903,7 +903,7 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP QStack > stack; stack.push(qMakePair(static_cast(0), layoutFirstVertex[orientation])); QVector candidates; - bool candidatesForward; + bool candidatesForward = true; // Walk depth-first, in the stack we store start of the candidate sequence (beforeSequence) // and the vertex to be visited. diff --git a/src/gui/kernel/qgesturemanager.cpp b/src/gui/kernel/qgesturemanager.cpp index abd2128..dfa5e52 100644 --- a/src/gui/kernel/qgesturemanager.cpp +++ b/src/gui/kernel/qgesturemanager.cpp @@ -599,6 +599,7 @@ void QGestureManager::deliverEvents(const QSet &gestures, Qt::GestureType gestureType = gesture->gestureType(); Q_ASSERT(gestureType != Qt::CustomGesture); + Q_UNUSED(gestureType); if (target) { if (gesture->state() == Qt::GestureStarted) { diff --git a/src/gui/painting/qbrush.cpp b/src/gui/painting/qbrush.cpp index 6f5d892..7273c35 100644 --- a/src/gui/painting/qbrush.cpp +++ b/src/gui/painting/qbrush.cpp @@ -970,7 +970,7 @@ bool QBrush::operator==(const QBrush &b) const QDebug operator<<(QDebug dbg, const QBrush &b) { #ifndef Q_BROKEN_DEBUG_STREAM - char *BRUSH_STYLES[] = { + static const char *BRUSH_STYLES[] = { "NoBrush", "SolidPattern", "Dense1Pattern", -- cgit v0.12 From 0d2f1562d63cf51d254a5761bf37ce36120cfcfd Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 9 Nov 2009 15:26:45 +0100 Subject: QPlastiqueStyle: Fix painting QTreeView with gradient When setting a gradian brush as a base for a QTreeWidget (with stylesheet), the branch decoration would be plain black. This is because the color() of a gradient brush is always black. Fix it by using the base brush itself to paint the decoration if the brush is not solid color. Task-number: QTBUG-3816 Reviewed-by: Thierry --- src/gui/styles/qplastiquestyle.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/gui/styles/qplastiquestyle.cpp b/src/gui/styles/qplastiquestyle.cpp index f880351..be4fff2 100644 --- a/src/gui/styles/qplastiquestyle.cpp +++ b/src/gui/styles/qplastiquestyle.cpp @@ -1094,8 +1094,6 @@ void QPlastiqueStyle::drawPrimitive(PrimitiveElement element, const QStyleOption QColor borderColor = option->palette.background().color().darker(178); QColor gradientStartColor = option->palette.button().color().lighter(104); QColor gradientStopColor = option->palette.button().color().darker(105); - QColor baseGradientStartColor = option->palette.base().color().darker(101); - QColor baseGradientStopColor = option->palette.base().color().darker(106); QColor highlightedGradientStartColor = option->palette.button().color().lighter(101); QColor highlightedGradientStopColor = mergedColors(option->palette.button().color(), option->palette.highlight().color(), 85); QColor highlightedBaseGradientStartColor = option->palette.base().color(); @@ -1978,7 +1976,13 @@ void QPlastiqueStyle::drawPrimitive(PrimitiveElement element, const QStyleOption QRect gradientRect(adjustedRect.left() + 1, adjustedRect.top() + 1, adjustedRect.right() - adjustedRect.left() - 1, adjustedRect.bottom() - adjustedRect.top() - 1); - qt_plastique_draw_gradient(painter, gradientRect, baseGradientStartColor, baseGradientStopColor); + if (option->palette.base().style() == Qt::SolidPattern) { + QColor baseGradientStartColor = option->palette.base().color().darker(101); + QColor baseGradientStopColor = option->palette.base().color().darker(106); + qt_plastique_draw_gradient(painter, gradientRect, baseGradientStartColor, baseGradientStopColor); + } else { + painter->fillRect(gradientRect, option->palette.base()); + } // draw "+" or "-" painter->setPen(alphaTextColor); painter->drawLine(center.x() - 2, center.y(), center.x() + 2, center.y()); -- cgit v0.12 From 0b7a5ebb7c4a65a931d2c69b9d3780cdc6ece893 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Mon, 9 Nov 2009 16:41:18 +0100 Subject: Now looking for the closer dock area for toolbutton Previously, we were looking for the 1st one that fit or was not too far (ie 80px) away. Now we really take the closest one. Task-number: QTBUG-2598 Reviewed-by: ogoffart --- src/gui/widgets/qtoolbararealayout.cpp | 50 ++++++++++++++++------------------ src/gui/widgets/qtoolbararealayout_p.h | 6 ++-- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/gui/widgets/qtoolbararealayout.cpp b/src/gui/widgets/qtoolbararealayout.cpp index de11625..39d5c66 100644 --- a/src/gui/widgets/qtoolbararealayout.cpp +++ b/src/gui/widgets/qtoolbararealayout.cpp @@ -480,7 +480,7 @@ void QToolBarAreaLayoutInfo::moveToolBar(QToolBar *toolbar, int pos) } -QList QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos) const +QList QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos, int *minDistance) const { int p = pick(o, pos); @@ -509,12 +509,19 @@ QList QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos) const QList result; result << j << k; + *minDistance = 0; //we found a perfect match + return result; + } + } else { + const int dist = distance(pos); + //it will only return a path if the minDistance is higher than the current distance + if (*minDistance > dist) { + *minDistance = dist; + + QList result; + result << lines.count() << 0; return result; } - } else if (appendLineDropRect().contains(pos)) { - QList result; - result << lines.count() << 0; - return result; } return QList(); @@ -587,32 +594,20 @@ QRect QToolBarAreaLayoutInfo::itemRect(const QList &path) const return result; } -QRect QToolBarAreaLayoutInfo::appendLineDropRect() const +int QToolBarAreaLayoutInfo::distance(const QPoint &pos) const { - QRect result; - switch (dockPos) { case QInternal::LeftDock: - result = QRect(rect.right(), rect.top(), - EmptyDockAreaSize, rect.height()); - break; + return pos.x() - rect.right(); case QInternal::RightDock: - result = QRect(rect.left() - EmptyDockAreaSize, rect.top(), - EmptyDockAreaSize, rect.height()); - break; + return rect.left() - pos.x(); case QInternal::TopDock: - result = QRect(rect.left(), rect.bottom() + 1, - rect.width(), EmptyDockAreaSize); - break; + return pos.y() - rect.bottom(); case QInternal::BottomDock: - result = QRect(rect.left(), rect.top() - EmptyDockAreaSize, - rect.width(), EmptyDockAreaSize); - break; + return rect.top() - pos.y(); default: - break; + return -1; } - - return result; } /****************************************************************************** @@ -1022,21 +1017,24 @@ QList QToolBarAreaLayout::indexOf(QWidget *toolBar) const return result; } +//this functions returns the path to the possible gapindex for the position pos QList QToolBarAreaLayout::gapIndex(const QPoint &pos) const { Qt::LayoutDirection dir = mainWindow->layoutDirection(); + int minDistance = 80; // when a dock area is empty, how "wide" is it? + QList ret; //return value for (int i = 0; i < QInternal::DockCount; ++i) { QPoint p = pos; if (docks[i].o == Qt::Horizontal) p = QStyle::visualPos(dir, docks[i].rect, p); - QList result = docks[i].gapIndex(p); + QList result = docks[i].gapIndex(p, &minDistance); if (!result.isEmpty()) { result.prepend(i); - return result; + ret = result; } } - return QList(); + return ret; } QList QToolBarAreaLayout::currentGapIndex() const diff --git a/src/gui/widgets/qtoolbararealayout_p.h b/src/gui/widgets/qtoolbararealayout_p.h index 1e113b7..f0ab80c 100644 --- a/src/gui/widgets/qtoolbararealayout_p.h +++ b/src/gui/widgets/qtoolbararealayout_p.h @@ -155,8 +155,6 @@ public: class QToolBarAreaLayoutInfo { public: - enum { EmptyDockAreaSize = 80 }; // when a dock area is empty, how "wide" is it? - QToolBarAreaLayoutInfo(QInternal::DockPosition pos = QInternal::TopDock); QList lines; @@ -173,11 +171,11 @@ public: void removeToolBarBreak(QToolBar *before); void moveToolBar(QToolBar *toolbar, int pos); - QList gapIndex(const QPoint &pos) const; + QList gapIndex(const QPoint &pos, int *maxDistance) const; bool insertGap(const QList &path, QLayoutItem *item); void clear(); QRect itemRect(const QList &path) const; - QRect appendLineDropRect() const; + int distance(const QPoint &pos) const; QRect rect; Qt::Orientation o; -- cgit v0.12 From 963d42fbf1fb68c2bd09b12dedbad000d8001b94 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Mon, 9 Nov 2009 17:25:49 +0100 Subject: Make sure the dock widget is updated when changing closable property Task-number: QTBUG-1665 Reviewed-by: ogoffart --- src/gui/widgets/qdockwidget.cpp | 5 +++++ tests/auto/qdockwidget/tst_qdockwidget.cpp | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/gui/widgets/qdockwidget.cpp b/src/gui/widgets/qdockwidget.cpp index a8e2a37..9cf6af1 100644 --- a/src/gui/widgets/qdockwidget.cpp +++ b/src/gui/widgets/qdockwidget.cpp @@ -1225,6 +1225,7 @@ void QDockWidget::setFeatures(QDockWidget::DockWidgetFeatures features) features &= DockWidgetFeatureMask; if (d->features == features) return; + const bool closableChanged = (d->features ^ features) & DockWidgetClosable; d->features = features; QDockWidgetLayout *layout = qobject_cast(this->layout()); @@ -1233,6 +1234,10 @@ void QDockWidget::setFeatures(QDockWidget::DockWidgetFeatures features) d->toggleViewAction->setEnabled((d->features & DockWidgetClosable) == DockWidgetClosable); emit featuresChanged(d->features); update(); + if (closableChanged && layout->nativeWindowDeco()) { + //this ensures the native decoration is drawn + d->setWindowState(true /*floating*/, true /*unplug*/); + } } QDockWidget::DockWidgetFeatures QDockWidget::features() const diff --git a/tests/auto/qdockwidget/tst_qdockwidget.cpp b/tests/auto/qdockwidget/tst_qdockwidget.cpp index e62ba8c..eb3f641 100644 --- a/tests/auto/qdockwidget/tst_qdockwidget.cpp +++ b/tests/auto/qdockwidget/tst_qdockwidget.cpp @@ -93,6 +93,7 @@ private slots: void task237438_setFloatingCrash(); void task248604_infiniteResize(); void task258459_visibilityChanged(); + void taskQTBUG_1665_closableChanged(); }; // Testing get/set functions @@ -834,5 +835,22 @@ void tst_QDockWidget::task258459_visibilityChanged() QCOMPARE(spy2.first().first().toBool(), true); //dock1 is visible } +void tst_QDockWidget::taskQTBUG_1665_closableChanged() +{ + QDockWidget dock; + dock.show(); + QTest::qWaitForWindowShown(&dock); + + if (dock.windowFlags() & Qt::FramelessWindowHint) + QSKIP("this machine doesn't support native dock widget", SkipAll); + + QVERIFY(dock.windowFlags() & Qt::WindowCloseButtonHint); + + //now let's remove the closable attribute + dock.setFeatures(dock.features() ^ QDockWidget::DockWidgetClosable); + QVERIFY(!(dock.windowFlags() & Qt::WindowCloseButtonHint)); +} + + QTEST_MAIN(tst_QDockWidget) #include "tst_qdockwidget.moc" -- cgit v0.12 From ecdecf7a628aa1c9eb953984c89fc65ffa767a24 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Mon, 9 Nov 2009 17:44:54 +0100 Subject: Fix docs for animation api All animation api code snippets should use references instead of local variables. Task-number: QTBUG-5616 Reviewed-by: thierry --- src/corelib/animation/qpropertyanimation.cpp | 10 +++++----- src/corelib/animation/qsequentialanimationgroup.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/corelib/animation/qpropertyanimation.cpp b/src/corelib/animation/qpropertyanimation.cpp index 3065083..013ff7f 100644 --- a/src/corelib/animation/qpropertyanimation.cpp +++ b/src/corelib/animation/qpropertyanimation.cpp @@ -58,12 +58,12 @@ an example: \code - QPropertyAnimation animation(myWidget, "geometry"); - animation.setDuration(10000); - animation.setStartValue(QRect(0, 0, 100, 30)); - animation.setEndValue(QRect(250, 250, 100, 30)); + QPropertyAnimation *animation = new QPropertyAnimation(myWidget, "geometry"); + animation->setDuration(10000); + animation->setStartValue(QRect(0, 0, 100, 30)); + animation->setEndValue(QRect(250, 250, 100, 30)); - animation.start(); + animation->start(); \endcode The property name and the QObject instance of which property diff --git a/src/corelib/animation/qsequentialanimationgroup.cpp b/src/corelib/animation/qsequentialanimationgroup.cpp index 861e26e..5dbb8c3 100644 --- a/src/corelib/animation/qsequentialanimationgroup.cpp +++ b/src/corelib/animation/qsequentialanimationgroup.cpp @@ -63,12 +63,12 @@ pause to a sequential animation group. \code - QSequentialAnimationGroup group; + QSequentialAnimationGroup *group = new QSequentialAnimationGroup; - group.addAnimation(anim1); - group.addAnimation(anim2); + group->addAnimation(anim1); + group->addAnimation(anim2); - group.start(); + group->start(); \endcode In this example, \c anim1 and \c anim2 are two already set up -- cgit v0.12 From 327ef9127aba3aa6bf2238c0aa779613f8edf0b1 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 9 Nov 2009 18:20:51 +0100 Subject: QGraphicsTextItem: update when changing the color. Task-number: QTBUG-5418 Reviewed-by: Gabriel --- src/gui/graphicsview/qgraphicsitem.cpp | 1 + tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp | 58 ++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 723e496..87ed5b7 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -9606,6 +9606,7 @@ void QGraphicsTextItem::setDefaultTextColor(const QColor &col) QPalette pal = c->palette(); pal.setColor(QPalette::Text, col); c->setPalette(pal); + update(); } /*! diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp index d65c6ec..27c6809 100644 --- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp @@ -413,6 +413,7 @@ private slots: void task243707_addChildBeforeParent(); void task197802_childrenVisibility(); void QTBUG_4233_updateCachedWithSceneRect(); + void QTBUG_5418_textItemSetDefaultColor(); private: QList paintedItems; @@ -9751,5 +9752,62 @@ void tst_QGraphicsItem::scenePosChange() QCOMPARE(child2->changes.count(QGraphicsItem::ItemScenePositionHasChanged), 0); } +void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() +{ + struct Item : public QGraphicsTextItem + { + bool painted; + void paint(QPainter *painter, const QStyleOptionGraphicsItem *opt, QWidget *wid) + { + painted = true; + QGraphicsTextItem::paint(painter, opt, wid); + } + }; + + Item *i = new Item; + i->painted = false; + i->setPlainText("I AM A TROLL"); + + QGraphicsScene scene; + QGraphicsView view(&scene); + view.show(); + QTest::qWaitForWindowShown(&view); + scene.addItem(i); + QApplication::processEvents(); + QTRY_VERIFY(i->painted); + QApplication::processEvents(); + + i->painted = false; + QColor col(Qt::red); + i->setDefaultTextColor(col); + QApplication::processEvents(); + QTRY_VERIFY(i->painted); //check that changing the color force an update + + i->painted = false; + QImage image(400, 200, QImage::Format_RGB32); + image.fill(0); + QPainter painter(&image); + scene.render(&painter); + painter.end(); + QVERIFY(i->painted); + + int numRedPixel = 0; + QRgb rgb = col.rgb(); + for (int y = 0; y < image.height(); ++y) { + for (int x = 0; x < image.width(); ++x) { + // Because of antialiasing we allow a certain range of errors here. + QRgb pixel = image.pixel(x, y); + if (qAbs((int)(pixel & 0xff) - (int)(rgb & 0xff)) + + qAbs((int)((pixel & 0xff00) >> 8) - (int)((rgb & 0xff00) >> 8)) + + qAbs((int)((pixel & 0xff0000) >> 16) - (int)((rgb & 0xff0000) >> 16)) <= 50) { + if (++numRedPixel >= 10) { + return; + } + } + } + } + QCOMPARE(numRedPixel, -1); //color not found, FAIL! +} + QTEST_MAIN(tst_QGraphicsItem) #include "tst_qgraphicsitem.moc" -- cgit v0.12 From d845505fd57ad4b06499b5b125703e80bbae692a Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Tue, 10 Nov 2009 10:48:11 +0100 Subject: Avoid XSync-related runtime crashes on HP-UX due to C++ mangling. HP-UX is missing the extern "C" wrapper for its XSync function declarations. This caused applications to _build_ but not _run_ (i.e., all GUI apps crashed). Adding the wrapper should be harmless on all X11 platforms. Task-number: QTBUG-5524 Reviewed-by: Thiago --- config.tests/x11/xsync/xsync.cpp | 6 +++++- src/gui/kernel/qt_x11_p.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config.tests/x11/xsync/xsync.cpp b/config.tests/x11/xsync/xsync.cpp index a7175de..8eea850 100644 --- a/config.tests/x11/xsync/xsync.cpp +++ b/config.tests/x11/xsync/xsync.cpp @@ -41,12 +41,16 @@ #include #include +extern "C" { #include +} int main(int, char **) { XSyncValue value; (void*)&XSyncIntToValue; (void*)&XSyncCreateCounter; - return 0; + int a, b; + Status ret = XSyncInitialize(NULL, &a, &b); + return ret; } diff --git a/src/gui/kernel/qt_x11_p.h b/src/gui/kernel/qt_x11_p.h index 9f08dc6..9e4cf60 100644 --- a/src/gui/kernel/qt_x11_p.h +++ b/src/gui/kernel/qt_x11_p.h @@ -163,7 +163,9 @@ extern "C" { #endif // QT_NO_XRENDER #ifndef QT_NO_XSYNC +extern "C" { # include "X11/extensions/sync.h" +} #endif // #define QT_NO_XKB -- cgit v0.12 From 6d4acbe94c71f7c0049cd08944855c23a716bee3 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Tue, 10 Nov 2009 12:05:36 +0100 Subject: Make the new examples for effects use the Qt Animation Framework Task-number: QTBUG-5640 Reviewed-by: Leo --- examples/effects/blurpicker/blurpicker.cpp | 53 ++++++++++++++++------------ examples/effects/blurpicker/blurpicker.h | 12 +++---- examples/effects/customshader/blurpicker.cpp | 53 ++++++++++++++++------------ examples/effects/customshader/blurpicker.h | 12 +++---- examples/effects/fademessage/fademessage.cpp | 18 +++++----- examples/effects/fademessage/fademessage.h | 5 ++- 6 files changed, 84 insertions(+), 69 deletions(-) diff --git a/examples/effects/blurpicker/blurpicker.cpp b/examples/effects/blurpicker/blurpicker.cpp index 1f46444..4911c73 100644 --- a/examples/effects/blurpicker/blurpicker.cpp +++ b/examples/effects/blurpicker/blurpicker.cpp @@ -49,24 +49,29 @@ #define M_PI 3.14159265358979323846 #endif -BlurPicker::BlurPicker(QWidget *parent): QGraphicsView(parent), m_index(0.0) +BlurPicker::BlurPicker(QWidget *parent): QGraphicsView(parent), m_index(0.0), m_animation(this, "index") { setBackgroundBrush(QPixmap(":/images/background.jpg")); - setScene(&m_scene); + setScene(new QGraphicsScene(this)); setupScene(); - updateIconPositions(); + setIndex(0); - connect(&m_timeLine, SIGNAL(valueChanged(qreal)), SLOT(updateIconPositions())); - m_timeLine.setDuration(400); + m_animation.setDuration(400); + m_animation.setEasingCurve(QEasingCurve::InOutSine); setRenderHint(QPainter::Antialiasing, true); setFrameStyle(QFrame::NoFrame); } -void BlurPicker::updateIconPositions() +qreal BlurPicker::index() const { - m_index = m_timeLine.currentFrame() / 1000.0; + return m_index; +} + +void BlurPicker::setIndex(qreal index) +{ + m_index = index; qreal baseline = 0; for (int i = 0; i < m_icons.count(); ++i) { @@ -82,12 +87,12 @@ void BlurPicker::updateIconPositions() static_cast(icon->graphicsEffect())->setBaseLine(baseline); } - m_scene.update(); + scene()->update(); } void BlurPicker::setupScene() { - m_scene.setSceneRect(-200, -120, 400, 240); + scene()->setSceneRect(-200, -120, 400, 240); QStringList names; names << ":/images/accessories-calculator.png"; @@ -101,32 +106,34 @@ void BlurPicker::setupScene() for (int i = 0; i < names.count(); i++) { QPixmap pixmap(names[i]); - QGraphicsPixmapItem *icon = m_scene.addPixmap(pixmap); + QGraphicsPixmapItem *icon = scene()->addPixmap(pixmap); icon->setZValue(1); icon->setGraphicsEffect(new BlurEffect(icon)); m_icons << icon; } - QGraphicsPixmapItem *bg = m_scene.addPixmap(QPixmap(":/images/background.jpg")); + QGraphicsPixmapItem *bg = scene()->addPixmap(QPixmap(":/images/background.jpg")); bg->setZValue(0); bg->setPos(-200, -150); } void BlurPicker::keyPressEvent(QKeyEvent *event) { - if (event->key() == Qt::Key_Left) { - if (m_timeLine.state() == QTimeLine::NotRunning) { - m_timeLine.setFrameRange(m_index * 1000, m_index * 1000 - 1000); - m_timeLine.start(); - event->accept(); - } + int delta = 0; + switch (event->key()) + { + case Qt::Key_Left: + delta = -1; + break; + case Qt::Key_Right: + delta = 1; + break; + default: + break; } - - if (event->key() == Qt::Key_Right) { - if (m_timeLine.state() == QTimeLine::NotRunning) { - m_timeLine.setFrameRange(m_index * 1000, m_index * 1000 + 1000); - m_timeLine.start(); + if (m_animation.state() == QAbstractAnimation::Stopped && delta) { + m_animation.setEndValue(m_index + delta); + m_animation.start(); event->accept(); - } } } diff --git a/examples/effects/blurpicker/blurpicker.h b/examples/effects/blurpicker/blurpicker.h index b460df4..b302db4 100644 --- a/examples/effects/blurpicker/blurpicker.h +++ b/examples/effects/blurpicker/blurpicker.h @@ -44,31 +44,31 @@ #include #include -#include +#include #include "blureffect.h" class BlurPicker: public QGraphicsView { Q_OBJECT + Q_PROPERTY(qreal index READ index WRITE setIndex); public: BlurPicker(QWidget *parent = 0); + qreal index() const; + void setIndex(qreal); + protected: void keyPressEvent(QKeyEvent *event); -private slots: - void updateIconPositions(); - private: void setupScene(); private: qreal m_index; - QGraphicsScene m_scene; QList m_icons; - QTimeLine m_timeLine; + QPropertyAnimation m_animation; }; #endif // BLURPICKER_H diff --git a/examples/effects/customshader/blurpicker.cpp b/examples/effects/customshader/blurpicker.cpp index 6cda711..d38d99b 100644 --- a/examples/effects/customshader/blurpicker.cpp +++ b/examples/effects/customshader/blurpicker.cpp @@ -50,24 +50,29 @@ #define M_PI 3.14159265358979323846 #endif -BlurPicker::BlurPicker(QWidget *parent): QGraphicsView(parent), m_index(0.0) +BlurPicker::BlurPicker(QWidget *parent): QGraphicsView(parent), m_index(0.0), m_animation(this, "index") { setBackgroundBrush(QPixmap(":/images/background.jpg")); - setScene(&m_scene); + setScene(new QGraphicsScene(this)); setupScene(); - updateIconPositions(); + setIndex(0); - connect(&m_timeLine, SIGNAL(valueChanged(qreal)), SLOT(updateIconPositions())); - m_timeLine.setDuration(400); + m_animation.setDuration(400); + m_animation.setEasingCurve(QEasingCurve::InOutSine); setRenderHint(QPainter::Antialiasing, true); setFrameStyle(QFrame::NoFrame); } -void BlurPicker::updateIconPositions() +qreal BlurPicker::index() const { - m_index = m_timeLine.currentFrame() / 1000.0; + return m_index; +} + +void BlurPicker::setIndex(qreal index) +{ + m_index = index; qreal baseline = 0; for (int i = 0; i < m_icons.count(); ++i) { @@ -84,12 +89,12 @@ void BlurPicker::updateIconPositions() static_cast(icon->graphicsEffect())->setBaseLine(baseline); } - m_scene.update(); + scene()->update(); } void BlurPicker::setupScene() { - m_scene.setSceneRect(-200, -120, 400, 240); + scene()->setSceneRect(-200, -120, 400, 240); QStringList names; names << ":/images/accessories-calculator.png"; @@ -103,7 +108,7 @@ void BlurPicker::setupScene() for (int i = 0; i < names.count(); i++) { QPixmap pixmap(names[i]); - QGraphicsPixmapItem *icon = m_scene.addPixmap(pixmap); + QGraphicsPixmapItem *icon = scene()->addPixmap(pixmap); icon->setZValue(1); if (i == 3) icon->setGraphicsEffect(new CustomShaderEffect()); @@ -112,26 +117,28 @@ void BlurPicker::setupScene() m_icons << icon; } - QGraphicsPixmapItem *bg = m_scene.addPixmap(QPixmap(":/images/background.jpg")); + QGraphicsPixmapItem *bg = scene()->addPixmap(QPixmap(":/images/background.jpg")); bg->setZValue(0); bg->setPos(-200, -150); } void BlurPicker::keyPressEvent(QKeyEvent *event) { - if (event->key() == Qt::Key_Left) { - if (m_timeLine.state() == QTimeLine::NotRunning) { - m_timeLine.setFrameRange(m_index * 1000, m_index * 1000 - 1000); - m_timeLine.start(); - event->accept(); - } + int delta = 0; + switch (event->key()) + { + case Qt::Key_Left: + delta = -1; + break; + case Qt::Key_Right: + delta = 1; + break; + default: + break; } - - if (event->key() == Qt::Key_Right) { - if (m_timeLine.state() == QTimeLine::NotRunning) { - m_timeLine.setFrameRange(m_index * 1000, m_index * 1000 + 1000); - m_timeLine.start(); + if (m_animation.state() == QAbstractAnimation::Stopped && delta) { + m_animation.setEndValue(m_index + delta); + m_animation.start(); event->accept(); - } } } diff --git a/examples/effects/customshader/blurpicker.h b/examples/effects/customshader/blurpicker.h index b460df4..b302db4 100644 --- a/examples/effects/customshader/blurpicker.h +++ b/examples/effects/customshader/blurpicker.h @@ -44,31 +44,31 @@ #include #include -#include +#include #include "blureffect.h" class BlurPicker: public QGraphicsView { Q_OBJECT + Q_PROPERTY(qreal index READ index WRITE setIndex); public: BlurPicker(QWidget *parent = 0); + qreal index() const; + void setIndex(qreal); + protected: void keyPressEvent(QKeyEvent *event); -private slots: - void updateIconPositions(); - private: void setupScene(); private: qreal m_index; - QGraphicsScene m_scene; QList m_icons; - QTimeLine m_timeLine; + QPropertyAnimation m_animation; }; #endif // BLURPICKER_H diff --git a/examples/effects/fademessage/fademessage.cpp b/examples/effects/fademessage/fademessage.cpp index 818d00f..a65c748 100644 --- a/examples/effects/fademessage/fademessage.cpp +++ b/examples/effects/fademessage/fademessage.cpp @@ -43,7 +43,7 @@ #include -FadeMessage::FadeMessage(QWidget *parent): QGraphicsView(parent), m_index(0.0) +FadeMessage::FadeMessage(QWidget *parent): QGraphicsView(parent) { setScene(&m_scene); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); @@ -51,9 +51,12 @@ FadeMessage::FadeMessage(QWidget *parent): QGraphicsView(parent), m_index(0.0) setupScene(); - m_timeLine = new QTimeLine(500, this); - m_timeLine->setCurveShape(QTimeLine::EaseInOutCurve); - connect(m_timeLine, SIGNAL(valueChanged(qreal)), m_effect, SLOT(setStrength(qreal))); + m_animation = new QPropertyAnimation(m_effect, "strength", this); + m_animation->setDuration(500); + m_animation->setEasingCurve(QEasingCurve::InOutSine); + m_animation->setStartValue(0); + m_animation->setEndValue(1); + setRenderHint(QPainter::Antialiasing, true); setFrameStyle(QFrame::NoFrame); @@ -63,13 +66,12 @@ void FadeMessage::togglePopup() { if (m_message->isVisible()) { m_message->setVisible(false); - m_timeLine->setDirection(QTimeLine::Backward); - m_timeLine->start(); + m_animation->setDirection(QAbstractAnimation::Backward); } else { m_message->setVisible(true); - m_timeLine->setDirection(QTimeLine::Forward); - m_timeLine->start(); + m_animation->setDirection(QAbstractAnimation::Forward); } + m_animation->start(); } void FadeMessage::setupScene() diff --git a/examples/effects/fademessage/fademessage.h b/examples/effects/fademessage/fademessage.h index 34e2fb8..e73ef6b 100644 --- a/examples/effects/fademessage/fademessage.h +++ b/examples/effects/fademessage/fademessage.h @@ -44,7 +44,7 @@ #include #include -#include +#include #include "fademessage.h" @@ -62,11 +62,10 @@ private slots: void togglePopup(); private: - qreal m_index; QGraphicsScene m_scene; QGraphicsColorizeEffect *m_effect; QGraphicsItem *m_message; - QTimeLine *m_timeLine; + QPropertyAnimation *m_animation; }; #endif // FADEMESSAGE_H -- cgit v0.12 From 7429ff911e05c05fbdd986a5932545571ee4beef Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Tue, 10 Nov 2009 13:17:29 +0100 Subject: Make the toolbar extension animated according to the main window Previously it would be always animated. Task-number: QTBUG-5623 Reviewed-by: Gabriel --- src/gui/widgets/qtoolbar.cpp | 2 +- src/gui/widgets/qtoolbarlayout.cpp | 5 ++--- src/gui/widgets/qtoolbarlayout_p.h | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/gui/widgets/qtoolbar.cpp b/src/gui/widgets/qtoolbar.cpp index 5596ca4..58a3d28 100644 --- a/src/gui/widgets/qtoolbar.cpp +++ b/src/gui/widgets/qtoolbar.cpp @@ -396,7 +396,7 @@ bool QToolBarPrivate::mouseMoveEvent(QMouseEvent *event) void QToolBarPrivate::unplug(const QRect &_r) { Q_Q(QToolBar); - layout->setExpanded(false, false); + layout->setExpanded(false); QRect r = _r; r.moveTopLeft(q->mapToGlobal(QPoint(0, 0))); setWindowState(true, true, r); diff --git a/src/gui/widgets/qtoolbarlayout.cpp b/src/gui/widgets/qtoolbarlayout.cpp index 7dc1e01..0afe5d8 100644 --- a/src/gui/widgets/qtoolbarlayout.cpp +++ b/src/gui/widgets/qtoolbarlayout.cpp @@ -642,7 +642,7 @@ QSize QToolBarLayout::expandedSize(const QSize &size) const return result; } -void QToolBarLayout::setExpanded(bool exp, bool animated) +void QToolBarLayout::setExpanded(bool exp) { if (exp == expanded) return; @@ -654,7 +654,6 @@ void QToolBarLayout::setExpanded(bool exp, bool animated) if (!tb) return; if (QMainWindow *win = qobject_cast(tb->parentWidget())) { - animating = true; QMainWindowLayout *layout = qobject_cast(win->layout()); if (expanded) { tb->raise(); @@ -665,7 +664,7 @@ void QToolBarLayout::setExpanded(bool exp, bool animated) layoutActions(rect.size()); } } - layout->layoutState.toolBarAreaLayout.apply(animated); + layout->layoutState.toolBarAreaLayout.apply(win->isAnimated()); } } diff --git a/src/gui/widgets/qtoolbarlayout_p.h b/src/gui/widgets/qtoolbarlayout_p.h index d49a5df..afd0227 100644 --- a/src/gui/widgets/qtoolbarlayout_p.h +++ b/src/gui/widgets/qtoolbarlayout_p.h @@ -112,7 +112,7 @@ public: bool hasExpandFlag() const; public Q_SLOTS: - void setExpanded(bool b, bool animated = true); + void setExpanded(bool b); private: QList items; -- cgit v0.12 From 2a0c11e13ff1cba30f3be324dadd14f8d0a1baa6 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 10 Nov 2009 12:56:23 +0100 Subject: PlatformPlugin: Do not load the plugin if there is no GUI Otherwise valgrind might complain we use uninitialized value (when using the X11 structure) Reviewed-by: Gabriel --- src/gui/kernel/qapplication.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/kernel/qapplication.cpp b/src/gui/kernel/qapplication.cpp index 987aa26..4b8f6a0 100644 --- a/src/gui/kernel/qapplication.cpp +++ b/src/gui/kernel/qapplication.cpp @@ -791,7 +791,8 @@ void QApplicationPrivate::construct( } //make sure the plugin is loaded - qt_guiPlatformPlugin(); + if (qt_is_gui_used) + qt_guiPlatformPlugin(); #endif } -- cgit v0.12 From b7ae1d97301dcb42997e09f996b103f3701b2139 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Tue, 10 Nov 2009 13:44:28 +0100 Subject: Make sure that the toolbar is in the mainwinow rect for docking Task-number: QTBUG-2598 Reviewed-by: ogoffart --- src/gui/widgets/qtoolbararealayout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/widgets/qtoolbararealayout.cpp b/src/gui/widgets/qtoolbararealayout.cpp index 39d5c66..b7e985c 100644 --- a/src/gui/widgets/qtoolbararealayout.cpp +++ b/src/gui/widgets/qtoolbararealayout.cpp @@ -515,7 +515,7 @@ QList QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos, int *minDistance) } else { const int dist = distance(pos); //it will only return a path if the minDistance is higher than the current distance - if (*minDistance > dist) { + if (dist >= 0 && *minDistance > dist) { *minDistance = dist; QList result; -- cgit v0.12 From 479e183a2c56eaf65a9734dcd134c534ce5e6642 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Tue, 10 Nov 2009 14:04:52 +0100 Subject: Fixes sub-attaq demo, unfreeze boat after launching new game when on pause Task-number: QTBUG-5526 Reviewed-by: thierry --- demos/sub-attaq/boat.cpp | 6 +++--- demos/sub-attaq/graphicsscene.cpp | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/demos/sub-attaq/boat.cpp b/demos/sub-attaq/boat.cpp index 0ad31b1..6fed9a9 100644 --- a/demos/sub-attaq/boat.cpp +++ b/demos/sub-attaq/boat.cpp @@ -62,7 +62,7 @@ static QAbstractAnimation *setupDestroyAnimation(Boat *boat) for (int i = 1; i <= 4; i++) { PixmapItem *step = new PixmapItem(QString("explosion/boat/step%1").arg(i),GraphicsScene::Big, boat); step->setZValue(6); - step->setOpacity(0); + step->setOpacity(0); //fade-in QPropertyAnimation *anim = new QPropertyAnimation(step, "opacity"); @@ -92,10 +92,10 @@ Boat::Boat() : PixmapItem(QString("boat"), GraphicsScene::Big), //The movement animation used to animate the boat movementAnimation = new QPropertyAnimation(this, "pos"); - //The movement animation used to animate the boat + //The destroy animation used to explode the boat destroyAnimation = setupDestroyAnimation(this); - //We setup the state machien of the boat + //We setup the state machine of the boat machine = new QStateMachine(this); QState *moving = new QState(machine); StopState *stopState = new StopState(this, moving); diff --git a/demos/sub-attaq/graphicsscene.cpp b/demos/sub-attaq/graphicsscene.cpp index e29095e..71d4fe7 100644 --- a/demos/sub-attaq/graphicsscene.cpp +++ b/demos/sub-attaq/graphicsscene.cpp @@ -278,4 +278,5 @@ void GraphicsScene::clearScene() boat->stop(); boat->hide(); + boat->setEnabled(true); } -- cgit v0.12 From 75f264cc6c47493f26ee81c783d1f9b64310c1d6 Mon Sep 17 00:00:00 2001 From: Leonardo Sobral Cunha Date: Tue, 10 Nov 2009 14:12:59 +0100 Subject: Fixes sub-attaq segfault when pausing The sub-attaq's animation manager was accessing a deleted animation. Task-number: QTBUG-5646 Reviewed-by: thierry --- demos/sub-attaq/animationmanager.cpp | 7 +++++++ demos/sub-attaq/animationmanager.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/demos/sub-attaq/animationmanager.cpp b/demos/sub-attaq/animationmanager.cpp index eb5a125..b3fc8e1 100644 --- a/demos/sub-attaq/animationmanager.cpp +++ b/demos/sub-attaq/animationmanager.cpp @@ -62,11 +62,18 @@ AnimationManager *AnimationManager::self() void AnimationManager::registerAnimation(QAbstractAnimation *anim) { + QObject::connect(anim, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterAnimation_helper(QObject*))); animations.append(anim); } +void AnimationManager::unregisterAnimation_helper(QObject *obj) +{ + unregisterAnimation(static_cast(obj)); +} + void AnimationManager::unregisterAnimation(QAbstractAnimation *anim) { + QObject::disconnect(anim, SIGNAL(destroyed(QObject*)), this, SLOT(unregisterAnimation_helper(QObject*))); animations.removeAll(anim); } diff --git a/demos/sub-attaq/animationmanager.h b/demos/sub-attaq/animationmanager.h index 8db13eb..48d84d1 100644 --- a/demos/sub-attaq/animationmanager.h +++ b/demos/sub-attaq/animationmanager.h @@ -62,6 +62,9 @@ public slots: void pauseAll(); void resumeAll(); +private slots: + void unregisterAnimation_helper(QObject *obj); + private: static AnimationManager *instance; QList animations; -- cgit v0.12 From b6be1c595fa67ec034f04c8a93e57e593ceb97aa Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Tue, 10 Nov 2009 14:43:19 +0100 Subject: Make sure the context menus also clear the status tip when needed Task-number: QTBUG-2700 Reviewed-by: ogoffart --- src/gui/kernel/qaction.cpp | 26 ++++++++++++++++---------- src/gui/kernel/qaction_p.h | 2 ++ src/gui/widgets/qmenu.cpp | 44 ++++++++++++++++++-------------------------- src/gui/widgets/qmenu_p.h | 1 + 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/gui/kernel/qaction.cpp b/src/gui/kernel/qaction.cpp index 6f3cbaf..3eaf2e1 100644 --- a/src/gui/kernel/qaction.cpp +++ b/src/gui/kernel/qaction.cpp @@ -100,6 +100,21 @@ QActionPrivate::~QActionPrivate() { } +bool QActionPrivate::showStatusText(QWidget *widget, const QString &str) +{ +#ifdef QT_NO_STATUSTIP + Q_UNUSED(widget); + Q_UNUSED(str); +#else + if(QObject *object = widget ? widget : parent) { + QStatusTipEvent tip(str); + QApplication::sendEvent(object, &tip); + return true; + } +#endif + return false; +} + void QActionPrivate::sendDataChanged() { Q_Q(QAction); @@ -1206,16 +1221,7 @@ QAction::setData(const QVariant &data) bool QAction::showStatusText(QWidget *widget) { -#ifdef QT_NO_STATUSTIP - Q_UNUSED(widget); -#else - if(QObject *object = widget ? widget : parent()) { - QStatusTipEvent tip(statusTip()); - QApplication::sendEvent(object, &tip); - return true; - } -#endif - return false; + return d_func()->showStatusText(widget, statusTip()); } /*! diff --git a/src/gui/kernel/qaction_p.h b/src/gui/kernel/qaction_p.h index 2527a02..f7b035b 100644 --- a/src/gui/kernel/qaction_p.h +++ b/src/gui/kernel/qaction_p.h @@ -75,6 +75,8 @@ public: QActionPrivate(); ~QActionPrivate(); + bool showStatusText(QWidget *w, const QString &str); + QPointer group; QString text; QString iconText; diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index cc39b7f..54d1612 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -602,14 +602,7 @@ void QMenuPrivate::setCurrentAction(QAction *action, int popup, SelectionReason } #ifndef QT_NO_STATUSTIP } else if (previousAction) { - QWidget *w = causedPopup.widget; - while (QMenu *m = qobject_cast(w)) - w = m->d_func()->causedPopup.widget; - if (w) { - QString empty; - QStatusTipEvent tip(empty); - QApplication::sendEvent(w, &tip); - } + previousAction->d_func()->showStatusText(topCausedWidget(), QString()); #endif } if (hideActiveMenu) { @@ -623,6 +616,15 @@ void QMenuPrivate::setCurrentAction(QAction *action, int popup, SelectionReason } } +//return the top causedPopup.widget that is not a QMenu +QWidget *QMenuPrivate::topCausedWidget() const +{ + QWidget* top = causedPopup.widget; + while (QMenu* m = qobject_cast(top)) + top = m->d_func()->causedPopup.widget; + return top; +} + QAction *QMenuPrivate::actionAt(QPoint p) const { if (!q_func()->rect().contains(p)) //sanity check @@ -1094,10 +1096,7 @@ void QMenuPrivate::activateAction(QAction *action, QAction::ActionEvent action_e QAccessible::updateAccessibility(q, actionIndex, QAccessible::Selection); } #endif - QWidget *w = causedPopup.widget; - while (QMenu *m = qobject_cast(w)) - w = m->d_func()->causedPopup.widget; - action->showStatusText(w); + action->showStatusText(topCausedWidget()); } else { actionAboutToTrigger = 0; } @@ -1801,10 +1800,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction) #ifndef QT_NO_MENUBAR // if this menu is part of a chain attached to a QMenuBar, set the // _NET_WM_WINDOW_TYPE_DROPDOWN_MENU X11 window type - QWidget* top = this; - while (QMenu* m = qobject_cast(top)) - top = m->d_func()->causedPopup.widget; - setAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu, qobject_cast(top) != 0); + setAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu, qobject_cast(d->topCausedWidget()) != 0); #endif ensurePolished(); // Get the right font @@ -2752,18 +2748,14 @@ void QMenu::keyPressEvent(QKeyEvent *e) } } if (!key_consumed) { - if (QWidget *caused = d->causedPopup.widget) { - while(QMenu *m = qobject_cast(caused)) - caused = m->d_func()->causedPopup.widget; #ifndef QT_NO_MENUBAR - if (QMenuBar *mb = qobject_cast(caused)) { - QAction *oldAct = mb->d_func()->currentAction; - QApplication::sendEvent(mb, e); - if (mb->d_func()->currentAction != oldAct) - key_consumed = true; - } -#endif + if (QMenuBar *mb = qobject_cast(d->topCausedWidget())) { + QAction *oldAct = mb->d_func()->currentAction; + QApplication::sendEvent(mb, e); + if (mb->d_func()->currentAction != oldAct) + key_consumed = true; } +#endif } #ifdef Q_OS_WIN32 diff --git a/src/gui/widgets/qmenu_p.h b/src/gui/widgets/qmenu_p.h index a5bde7c..c021063 100644 --- a/src/gui/widgets/qmenu_p.h +++ b/src/gui/widgets/qmenu_p.h @@ -215,6 +215,7 @@ public: SelectedFromKeyboard, SelectedFromElsewhere }; + QWidget *topCausedWidget() const; QAction *actionAt(QPoint p) const; void setFirstActionActive(); void setCurrentAction(QAction *, int popup = -1, SelectionReason reason = SelectedFromElsewhere, bool activateFirst = false); -- cgit v0.12 From 56077c71a771e0e92ead2244df51a85669529274 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Tue, 10 Nov 2009 14:45:23 +0100 Subject: processEvents() does not always process *all* events in the queue. This was a small behaviour change introduced by Brad that caused the autotest to fail (not every time). Our workaround is to call sendPostedEvents(). --- tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp b/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp index 546f92d..d3087dc 100644 --- a/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp +++ b/tests/auto/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp @@ -664,16 +664,16 @@ void tst_QGraphicsLinearLayout::invalidate() widget->show(); layout.setContentsMargins(1, 2, 3, 4); - qApp->processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(layout.layoutRequest, 1); layout.setOrientation(Qt::Vertical); - qApp->processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(layout.layoutRequest, 2); for (int i = 0; i < count; ++i) layout.invalidate(); // Event is compressed, should only get one layoutrequest - qApp->processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(layout.layoutRequest, count ? 3 : 2); delete widget; } -- cgit v0.12 From 9792ee15c60a4b8a849d5a098047482d192185ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Tue, 10 Nov 2009 15:10:27 +0100 Subject: Replace most processEvents() with sendPostedEvents(). After a change Brad did to the event dispatcher we are no longer guaranteed that processEvents will process *all* events in the event queue. (most of the time _it_will_ process all events) I only replaced processEvents for the tests that fail. --- tests/auto/qgridlayout/tst_qgridlayout.cpp | 36 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/auto/qgridlayout/tst_qgridlayout.cpp b/tests/auto/qgridlayout/tst_qgridlayout.cpp index 46e2a03..313dc95 100644 --- a/tests/auto/qgridlayout/tst_qgridlayout.cpp +++ b/tests/auto/qgridlayout/tst_qgridlayout.cpp @@ -268,7 +268,7 @@ void tst_QGridLayout::setMinAndMaxSize() leftChild.setMinimumSize(100, 100); leftChild.setMaximumSize(200, 200); layout.addWidget(&leftChild, 0, 0); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(widget.minimumSize(), leftChild.minimumSize()); QCOMPARE(widget.maximumSize(), leftChild.maximumSize()); @@ -277,7 +277,7 @@ void tst_QGridLayout::setMinAndMaxSize() rightChild.setMinimumSize(100, 100); rightChild.setMaximumSize(200, 200); layout.addWidget(&rightChild, 0, 2); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(widget.minimumWidth(), leftChild.minimumWidth() + rightChild.minimumWidth()); @@ -293,7 +293,7 @@ void tst_QGridLayout::setMinAndMaxSize() layout.setColumnMinimumWidth(1, colMin); QCOMPARE(layout.columnMinimumWidth(1), colMin); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(widget.minimumWidth(), leftChild.minimumWidth() + rightChild.minimumWidth() + colMin); QCOMPARE(widget.maximumWidth(), @@ -306,7 +306,7 @@ void tst_QGridLayout::setMinAndMaxSize() layout.setColumnStretch(1,1); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(widget.minimumWidth(), leftChild.minimumWidth() + rightChild.minimumWidth() + colMin); QCOMPARE(widget.maximumWidth(), QLAYOUTSIZE_MAX); @@ -318,7 +318,7 @@ void tst_QGridLayout::setMinAndMaxSize() layout.setColumnStretch(1,0); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(widget.minimumWidth(), leftChild.minimumWidth() + rightChild.minimumWidth() + colMin); QCOMPARE(widget.maximumWidth(), @@ -335,7 +335,7 @@ void tst_QGridLayout::setMinAndMaxSize() static const int spacerS = 250; QSpacerItem *spacer = new QSpacerItem(spacerS, spacerS); layout.addItem(spacer, 0, 1); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(widget.minimumWidth(), leftChild.minimumWidth() + rightChild.minimumWidth() + spacerS); @@ -348,7 +348,7 @@ void tst_QGridLayout::setMinAndMaxSize() spacer->changeSize(spacerS, spacerS, QSizePolicy::Fixed, QSizePolicy::Minimum); layout.invalidate(); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(widget.minimumWidth(), leftChild.minimumWidth() + rightChild.minimumWidth() + spacerS); QCOMPARE(widget.maximumWidth(), @@ -358,13 +358,13 @@ void tst_QGridLayout::setMinAndMaxSize() layout.removeItem(spacer); rightChild.hide(); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(widget.minimumSize(), leftChild.minimumSize()); QCOMPARE(widget.maximumSize(), leftChild.maximumSize()); rightChild.show(); layout.removeWidget(&rightChild); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(widget.minimumSize(), leftChild.minimumSize()); QCOMPARE(widget.maximumSize(), leftChild.maximumSize()); @@ -373,7 +373,7 @@ void tst_QGridLayout::setMinAndMaxSize() bottomChild.setMinimumSize(100, 100); bottomChild.setMaximumSize(200, 200); layout.addWidget(&bottomChild, 1, 0); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(widget.minimumHeight(), leftChild.minimumHeight() + bottomChild.minimumHeight()); @@ -385,13 +385,13 @@ void tst_QGridLayout::setMinAndMaxSize() qMax(leftChild.maximumWidth(), bottomChild.maximumWidth())); bottomChild.hide(); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(widget.minimumSize(), leftChild.minimumSize()); QCOMPARE(widget.maximumSize(), leftChild.maximumSize()); bottomChild.show(); layout.removeWidget(&bottomChild); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(widget.minimumSize(), leftChild.minimumSize()); QCOMPARE(widget.maximumSize(), leftChild.maximumSize()); } @@ -423,7 +423,7 @@ void tst_QGridLayout::spacingAndSpacers() SizeHinter leftChild(100,100); leftChild.setPalette(QPalette(Qt::red)); layout.addWidget(&leftChild, 0, 0); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); expectedSizeHint = leftChild.sizeHint(); QCOMPARE(widget.sizeHint(), expectedSizeHint); @@ -431,7 +431,7 @@ void tst_QGridLayout::spacingAndSpacers() SizeHinter rightChild(200,100); rightChild.setPalette(QPalette(Qt::green)); layout.addWidget(&rightChild, 0, 2); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(rightChild.sizeHint(), QSize(200,100)); expectedSizeHint += QSize(rightChild.sizeHint().width(), 0); @@ -440,11 +440,11 @@ void tst_QGridLayout::spacingAndSpacers() layout.setColumnMinimumWidth(1, 100); widget.adjustSize(); expectedSizeHint += QSize(100,0); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(widget.sizeHint(), expectedSizeHint); rightChild.hide(); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); expectedSizeHint -= QSize(rightChild.sizeHint().width(), 0); QCOMPARE(widget.sizeHint(), expectedSizeHint); @@ -459,12 +459,12 @@ void tst_QGridLayout::spacingAndSpacers() leftChild.setMaximumWidth(200); rightChild.setMaximumWidth(200); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(widget.maximumWidth(), leftChild.maximumWidth() + rightChild.maximumWidth()); #endif layout.removeWidget(&rightChild); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); QCOMPARE(widget.sizeHint(), expectedSizeHint); -- cgit v0.12 From 6789c06291febb20987d669d0e0e58913eeb9bfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Tue, 10 Nov 2009 15:30:24 +0100 Subject: Replace most processEvents() with sendPostedEvents(). After a change Brad did to the event dispatcher we are no longer guaranteed that processEvents will process *all* events in the event queue. (most of the time _it_will_ process all events) I only replaced processEvents for the tests that failed. --- .../auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp index e33c7b6..cd1eedd 100644 --- a/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp +++ b/tests/auto/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp @@ -399,7 +399,7 @@ void tst_QGraphicsGridLayout::columnAlignment() widget->resize(widget->effectiveSizeHint(Qt::MaximumSize)); view.show(); widget->show(); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); // Check default QCOMPARE(layout->columnAlignment(0), 0); QCOMPARE(layout->columnAlignment(1), 0); @@ -414,7 +414,7 @@ void tst_QGraphicsGridLayout::columnAlignment() layout->setAlignment(layout->itemAt(1,1), Qt::AlignRight); layout->setAlignment(layout->itemAt(1,2), Qt::AlignLeft); - QApplication::processEvents(); // process LayoutRequest + QApplication::sendPostedEvents(0, 0); // process LayoutRequest /* +----------+------------+---------+ | Left | HCenter | Right | @@ -846,7 +846,7 @@ void tst_QGraphicsGridLayout::rowAlignment() widget->resize(300, 400); view.show(); widget->show(); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); // Check default QCOMPARE(layout->rowAlignment(0), 0); QCOMPARE(layout->rowAlignment(1), 0); @@ -869,7 +869,7 @@ void tst_QGraphicsGridLayout::rowAlignment() layout->setAlignment(layout->itemAt(1,0), Qt::AlignTop); layout->setAlignment(layout->itemAt(2,0), Qt::AlignHCenter); - QApplication::processEvents(); // process LayoutRequest + QApplication::sendPostedEvents(0, 0); // process LayoutRequest QCOMPARE(layout->alignment(layout->itemAt(0,0)), Qt::AlignRight); //Qt::AlignRight | Qt::AlignBottom QCOMPARE(layout->itemAt(0,0)->geometry(), QRectF(50, 50, 50, 50)); @@ -1834,7 +1834,7 @@ void tst_QGraphicsGridLayout::defaultStretchFactors() desc.apply(layout, item); } - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); widget->show(); view.show(); @@ -1842,7 +1842,7 @@ void tst_QGraphicsGridLayout::defaultStretchFactors() if (newSize.isValid()) widget->resize(newSize); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); for (i = 0; i < expectedSizes.count(); ++i) { QSizeF itemSize = layout->itemAt(i)->geometry().size(); QCOMPARE(itemSize, expectedSizes.at(i)); @@ -1994,7 +1994,7 @@ void tst_QGraphicsGridLayout::alignment2() desc.apply(layout, item); } - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); widget->show(); view.resize(400,300); @@ -2002,7 +2002,7 @@ void tst_QGraphicsGridLayout::alignment2() if (newSize.isValid()) widget->resize(newSize); - QApplication::processEvents(); + QApplication::sendPostedEvents(0, 0); for (i = 0; i < expectedGeometries.count(); ++i) { QRectF itemRect = layout->itemAt(i)->geometry(); QCOMPARE(itemRect, expectedGeometries.at(i)); -- cgit v0.12 From 642b0f063df1339bcef6e8f23d84536230131573 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Tue, 10 Nov 2009 16:21:36 +0100 Subject: Menubars in dual screen mode now popup the menus on the correct screen If an item is split then its menu appears on the screen which contains most of it. Task-number: QTBUG-773 Reviewed-by: ogoffart --- src/gui/widgets/qmenubar.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index 689d2e1..b1ff662 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -332,7 +332,9 @@ void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst) QPoint pos(q->mapToGlobal(QPoint(adjustedActionRect.left(), adjustedActionRect.bottom() + 1))); QSize popup_size = activeMenu->sizeHint(); - QRect screenRect = QApplication::desktop()->screenGeometry(pos); + //we put the popup menu on the screen containing the bottom-center of the action rect + QRect screenRect = QApplication::desktop()->screenGeometry(pos + QPoint(adjustedActionRect.width() / 2, 0)); + pos = QPoint(qMax(pos.x(), screenRect.x()), qMax(pos.y(), screenRect.y())); const bool fitUp = (q->mapToGlobal(adjustedActionRect.topLeft()).y() >= popup_size.height()); const bool fitDown = (pos.y() + popup_size.height() <= screenRect.bottom()); -- cgit v0.12 From 6e6803540d50f14a2c4a6e1ee551310fa96d0cb6 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 10 Nov 2009 17:17:44 +0100 Subject: Fixed: Stylesheet and background image issue in ScrollArea When using background-image and background-attachement: scroll and background-repeat: no-repeat The rectangle used to draw the image was not correctly computed. Reviewed-by: Thierry Task-number: QTBUG-3783 --- src/gui/styles/qstylesheetstyle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/styles/qstylesheetstyle.cpp b/src/gui/styles/qstylesheetstyle.cpp index ce73fd8..59210c3 100644 --- a/src/gui/styles/qstylesheetstyle.cpp +++ b/src/gui/styles/qstylesheetstyle.cpp @@ -1180,7 +1180,7 @@ void QRenderRule::drawBackgroundImage(QPainter *p, const QRect &rect, QPoint off QRect r = originRect(rect, background()->origin); QRect aligned = QStyle::alignedRect(Qt::LeftToRight, background()->position, bgp.size(), r); - QRect inter = aligned.intersected(r); + QRect inter = aligned.translated(-off).intersected(r); switch (background()->repeat) { case Repeat_Y: -- cgit v0.12 From 2321e8636d7436b70a8afcde16828f00c4b8590e Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Tue, 10 Nov 2009 17:55:14 +0100 Subject: Make it possible for QMainWindow to restore the geom of undocked widget Task-number: QTBUG-5663 Reviewed-by: ogoffart --- src/gui/widgets/qdockarealayout.cpp | 6 +++--- tests/auto/qdockwidget/tst_qdockwidget.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/gui/widgets/qdockarealayout.cpp b/src/gui/widgets/qdockarealayout.cpp index dffec11..27e145f 100644 --- a/src/gui/widgets/qdockarealayout.cpp +++ b/src/gui/widgets/qdockarealayout.cpp @@ -1933,6 +1933,9 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList item_list.append(item); } else { QDockAreaLayoutItem item(new QDockWidgetItem(widget)); + if (!testing) { + item_list.append(item); + } if (flags & StateFlagFloating) { bool drawer = false; #ifdef Q_WS_MAC // drawer support @@ -1980,9 +1983,6 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList } } - if (!testing) { - item_list.append(item); - } } } else if (nextMarker == SequenceMarker) { int dummy; diff --git a/tests/auto/qdockwidget/tst_qdockwidget.cpp b/tests/auto/qdockwidget/tst_qdockwidget.cpp index eb3f641..e04ed18 100644 --- a/tests/auto/qdockwidget/tst_qdockwidget.cpp +++ b/tests/auto/qdockwidget/tst_qdockwidget.cpp @@ -87,6 +87,7 @@ private slots: void dockLocationChanged(); void setTitleBarWidget(); void titleBarDoubleClick(); + void restoreStateOfFloating(); // task specific tests: void task165177_deleteFocusWidget(); void task169808_setFloating(); @@ -715,6 +716,21 @@ void tst_QDockWidget::titleBarDoubleClick() QCOMPARE(win.dockWidgetArea(&dock), Qt::TopDockWidgetArea); } +void tst_QDockWidget::restoreStateOfFloating() +{ + QMainWindow mw; + QDockWidget dock; + dock.setObjectName("dock1"); + mw.addDockWidget(Qt::TopDockWidgetArea, &dock); + QVERIFY(!dock.isFloating()); + QByteArray ba = mw.saveState(); + dock.setFloating(true); + QVERIFY(dock.isFloating()); + QVERIFY(mw.restoreState(ba)); + QVERIFY(!dock.isFloating()); +} + + void tst_QDockWidget::task165177_deleteFocusWidget() { QMainWindow mw; -- cgit v0.12 From ba5fea372219000050715ecfac8fba9a6fd1b638 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Tue, 10 Nov 2009 18:01:27 +0100 Subject: QDockWidget also emits dockLocationChanged when the state is restored ...on the main window. Task-number: QTBUG-1304 Reviewed-by: ogoffart --- src/gui/widgets/qdockarealayout.cpp | 3 +-- tests/auto/qdockwidget/tst_qdockwidget.cpp | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gui/widgets/qdockarealayout.cpp b/src/gui/widgets/qdockarealayout.cpp index 27e145f..953edab 100644 --- a/src/gui/widgets/qdockarealayout.cpp +++ b/src/gui/widgets/qdockarealayout.cpp @@ -1841,7 +1841,6 @@ void QDockAreaLayoutInfo::saveState(QDataStream &stream) const } } -#ifdef Q_WS_MAC static Qt::DockWidgetArea toDockWidgetArea(QInternal::DockPosition pos) { switch (pos) { @@ -1853,7 +1852,6 @@ static Qt::DockWidgetArea toDockWidgetArea(QInternal::DockPosition pos) } return Qt::NoDockWidgetArea; } -#endif static QRect constrainedRect(QRect rect, const QRect &desktop) { @@ -1980,6 +1978,7 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList if (!testing) { widget->setFloating(false); widget->setVisible(flags & StateFlagVisible); + emit widget->dockLocationChanged(toDockWidgetArea(dockPos)); } } diff --git a/tests/auto/qdockwidget/tst_qdockwidget.cpp b/tests/auto/qdockwidget/tst_qdockwidget.cpp index e04ed18..c9a7f1c 100644 --- a/tests/auto/qdockwidget/tst_qdockwidget.cpp +++ b/tests/auto/qdockwidget/tst_qdockwidget.cpp @@ -614,6 +614,7 @@ void tst_QDockWidget::dockLocationChanged() QMainWindow mw; QDockWidget dw; + dw.setObjectName("dock1"); QSignalSpy spy(&dw, SIGNAL(dockLocationChanged(Qt::DockWidgetArea))); mw.addDockWidget(Qt::LeftDockWidgetArea, &dw); @@ -638,6 +639,7 @@ void tst_QDockWidget::dockLocationChanged() QCOMPARE(spy.count(), 0); QDockWidget dw2; + dw2.setObjectName("dock2"); mw.addDockWidget(Qt::TopDockWidgetArea, &dw2); mw.tabifyDockWidget(&dw2, &dw); QCOMPARE(spy.count(), 1); @@ -659,6 +661,12 @@ void tst_QDockWidget::dockLocationChanged() QCOMPARE(qvariant_cast(spy.at(0).at(0)), Qt::TopDockWidgetArea); spy.clear(); + + QByteArray ba = mw.saveState(); + mw.restoreState(ba); + QCOMPARE(spy.count(), 1); + QCOMPARE(qvariant_cast(spy.at(0).at(0)), + Qt::TopDockWidgetArea); } void tst_QDockWidget::featuresChanged() -- cgit v0.12 From 5e3f81237aae96181c9315b8e7c6c5368629a000 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Wed, 11 Nov 2009 07:09:07 +0100 Subject: Revert "Always set a clip on the painter in QGraphicsView." This reverts commit 4bf7f90a27377f439e86d6175e5e3cdebd131be0. The change is already reverted in kinetic-declarativeui. Reviewed-by: Warwick Allison Reviewed-by: bnilsen --- src/gui/graphicsview/qgraphicsview.cpp | 3 -- tests/auto/qgraphicsview/tst_qgraphicsview.cpp | 72 -------------------------- 2 files changed, 75 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsview.cpp b/src/gui/graphicsview/qgraphicsview.cpp index 27fd09e..3ef311c 100644 --- a/src/gui/graphicsview/qgraphicsview.cpp +++ b/src/gui/graphicsview/qgraphicsview.cpp @@ -3275,13 +3275,10 @@ void QGraphicsView::paintEvent(QPaintEvent *event) // Determine the exposed region d->exposedRegion = event->region(); - if (d->exposedRegion.isEmpty()) - d->exposedRegion = viewport()->rect(); QRectF exposedSceneRect = mapToScene(d->exposedRegion.boundingRect()).boundingRect(); // Set up the painter QPainter painter(viewport()); - painter.setClipRect(event->rect(), Qt::IntersectClip); #ifndef QT_NO_RUBBERBAND if (d->rubberBanding && !d->rubberBandRect.isEmpty()) painter.save(); diff --git a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp index 9c6aa39..f07453c 100644 --- a/tests/auto/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/auto/qgraphicsview/tst_qgraphicsview.cpp @@ -217,7 +217,6 @@ private slots: void update(); void inputMethodSensitivity(); void inputContextReset(); - void defaultClipIntersectToView(); // task specific tests below me void task172231_untransformableItems(); @@ -3693,77 +3692,6 @@ void tst_QGraphicsView::inputContextReset() QCOMPARE(inputContext.resets, 0); } -class ViewClipTester : public QGraphicsView -{ -public: - ViewClipTester(QGraphicsScene *scene = 0) - : QGraphicsView(scene) - { } - QRegion clipRegion; - -protected: - void drawBackground(QPainter *painter, const QRectF &rect) - { - clipRegion = painter->clipRegion(); - } -}; - -class ItemClipTester : public QGraphicsRectItem -{ -public: - ItemClipTester() : QGraphicsRectItem(0, 0, 20, 20) - { - setBrush(Qt::blue); - } - QRegion clipRegion; - - void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) - { - clipRegion = painter->clipRegion(); - QGraphicsRectItem::paint(painter, option, widget); - } -}; - -void tst_QGraphicsView::defaultClipIntersectToView() -{ - QGraphicsScene scene; - ItemClipTester *tester = new ItemClipTester; - scene.addItem(tester); - - ViewClipTester view(&scene); - view.setAlignment(Qt::AlignTop | Qt::AlignLeft); - view.setFrameStyle(0); - view.resize(200, 200); - view.show(); - QTRY_COMPARE(QApplication::activeWindow(), (QWidget *)&view); - - QRect viewRect(0, 0, 200, 200); - QCOMPARE(view.clipRegion, QRegion(viewRect)); - QCOMPARE(tester->clipRegion, QRegion(viewRect)); - - view.viewport()->update(0, 0, 5, 5); - view.viewport()->update(10, 10, 5, 5); - qApp->processEvents(); - viewRect = QRect(0, 0, 15, 15); - QCOMPARE(view.clipRegion, QRegion(viewRect)); - QCOMPARE(tester->clipRegion, QRegion(viewRect)); - - view.scale(2, 2); - qApp->processEvents(); - - viewRect.moveTop(-viewRect.height()); - viewRect = QRect(0, 0, 100, 100); - QCOMPARE(view.clipRegion, QRegion(viewRect)); - QCOMPARE(tester->clipRegion, QRegion(viewRect)); - - view.viewport()->update(0, 0, 5, 5); - view.viewport()->update(10, 10, 5, 5); - qApp->processEvents(); - viewRect = QRect(0, 0, 8, 8); - QCOMPARE(view.clipRegion, QRegion(viewRect)); - QCOMPARE(tester->clipRegion, QRegion(viewRect)); -} - void tst_QGraphicsView::task253415_reconnectUpdateSceneOnSceneChanged() { QGraphicsView view; -- cgit v0.12 From 2d97f299f5f25888656696c6dad0924b243ce4fd Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 11 Nov 2009 11:42:27 +0100 Subject: QKeySequence::mnemonic: add a warning if the text contains severals '&' Task-number: QTBUG-5667 Reviewed-by: Gabriel --- src/gui/kernel/qkeysequence.cpp | 20 ++++++++++--- tests/auto/qkeysequence/tst_qkeysequence.cpp | 45 ++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 9 deletions(-) diff --git a/src/gui/kernel/qkeysequence.cpp b/src/gui/kernel/qkeysequence.cpp index 1a76083..89c18fb 100644 --- a/src/gui/kernel/qkeysequence.cpp +++ b/src/gui/kernel/qkeysequence.cpp @@ -1014,9 +1014,12 @@ bool QKeySequence::isEmpty() const */ QKeySequence QKeySequence::mnemonic(const QString &text) { + QKeySequence ret; + if(qt_sequence_no_mnemonics) - return QKeySequence(); + return ret; + bool found = false; int p = 0; while (p >= 0) { p = text.indexOf(QLatin1Char('&'), p) + 1; @@ -1025,13 +1028,22 @@ QKeySequence QKeySequence::mnemonic(const QString &text) if (text.at(p) != QLatin1Char('&')) { QChar c = text.at(p); if (c.isPrint()) { - c = c.toUpper(); - return QKeySequence(c.unicode() + Qt::ALT); + if (!found) { + c = c.toUpper(); + ret = QKeySequence(c.unicode() + Qt::ALT); +#ifdef QT_NO_DEBUG + return ret; +#else + found = true; + } else { + qWarning(qPrintable(QString::fromLatin1("QKeySequence::mnemonic: \"%1\" contains multiple occurences of '&'").arg(text))); +#endif + } } } p++; } - return QKeySequence(); + return ret; } /*! diff --git a/tests/auto/qkeysequence/tst_qkeysequence.cpp b/tests/auto/qkeysequence/tst_qkeysequence.cpp index 1c257bf..bc9ae6c 100644 --- a/tests/auto/qkeysequence/tst_qkeysequence.cpp +++ b/tests/auto/qkeysequence/tst_qkeysequence.cpp @@ -119,6 +119,7 @@ private slots: void symetricConstructors_data(); void symetricConstructors(); void checkMultipleNames(); + void mnemonic_data(); void mnemonic(); void toString_data(); void toString(); @@ -133,6 +134,7 @@ private slots: void translated_data(); void translated(); + void initTestCase(); private: QTranslator *ourTranslator; @@ -299,7 +301,7 @@ void tst_QKeySequence::standardKeys_data() QTest::newRow("findNext") << (int)QKeySequence::FindNext<< QString("F3"); QTest::newRow("findPrevious") << (int)QKeySequence::FindPrevious << QString("SHIFT+F3"); QTest::newRow("close") << (int)QKeySequence::Close<< QString("CTRL+F4"); - QTest::newRow("replace") << (int)QKeySequence::Replace<< QString("CTRL+H"); + QTest::newRow("replace") << (int)QKeySequence::Replace<< QString("CTRL+H"); #endif QTest::newRow("bold") << (int)QKeySequence::Bold << QString("CTRL+B"); QTest::newRow("italic") << (int)QKeySequence::Italic << QString("CTRL+I"); @@ -357,17 +359,50 @@ void tst_QKeySequence::keyBindings() } + +void tst_QKeySequence::mnemonic_data() +{ + QTest::addColumn("string"); + QTest::addColumn("key"); + QTest::addColumn("warning"); + + QTest::newRow("1") << QString::fromLatin1("&bonjour") << QString::fromLatin1("ALT+B") << false; + QTest::newRow("2") << QString::fromLatin1("&&bonjour") << QString() << false; + QTest::newRow("3") << QString::fromLatin1("&&bon&jour") << QString::fromLatin1("ALT+J") << false; + QTest::newRow("4") << QString::fromLatin1("&&bon&jo&ur") << QString::fromLatin1("ALT+J") << true; + QTest::newRow("5") << QString::fromLatin1("b&on&&jour") << QString::fromLatin1("ALT+O") << false; + QTest::newRow("6") << QString::fromLatin1("bonjour") << QString() << false; + QTest::newRow("7") << QString::fromLatin1("&&&bonjour") << QString::fromLatin1("ALT+B") << false; + QTest::newRow("8") << QString::fromLatin1("bonjour&&&") << QString() << false; + QTest::newRow("9") << QString::fromLatin1("bo&&nj&o&&u&r") << QString::fromLatin1("ALT+O") << true; + QTest::newRow("10") << QString::fromLatin1("BON&JOUR") << QString::fromLatin1("ALT+J") << false; + QTest::newRow("11") << QString::fromUtf8("bonjour") << QString() << false; +} + void tst_QKeySequence::mnemonic() { #ifdef Q_WS_MAC QSKIP("mnemonics are not used on Mac OS X", SkipAll); #endif - QKeySequence k = QKeySequence::mnemonic("&Foo"); - QVERIFY(k == QKeySequence("ALT+F")); - k = QKeySequence::mnemonic("&& &x"); - QVERIFY(k == QKeySequence("ALT+X")); + QFETCH(QString, string); + QFETCH(QString, key); + QFETCH(bool, warning); + +#ifndef QT_NO_DEBUG + if (warning) { + QString str = QString::fromLatin1("QKeySequence::mnemonic: \"%1\" contains multiple occurences of '&'").arg(string); + QTest::ignoreMessage(QtWarningMsg, qPrintable(str)); + // qWarning(qPrintable(str)); + } +#endif + QKeySequence seq = QKeySequence::mnemonic(string); + QKeySequence res = QKeySequence(key); + + QCOMPARE(seq, res); } + + void tst_QKeySequence::toString_data() { QTest::addColumn("strSequence"); -- cgit v0.12 From ad5f41c02daa0278902d0e8273c8cd34efd2d6da Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Wed, 11 Nov 2009 12:43:46 +0100 Subject: Fix Font combobox: one can set the current font without it being changed Task-number: QTBUG-5693 Reviewed-by: ogoffart --- src/gui/widgets/qfontcombobox.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gui/widgets/qfontcombobox.cpp b/src/gui/widgets/qfontcombobox.cpp index 806db59..a66657d 100644 --- a/src/gui/widgets/qfontcombobox.cpp +++ b/src/gui/widgets/qfontcombobox.cpp @@ -247,7 +247,14 @@ void QFontComboBoxPrivate::_q_updateModel() } list = result; + //we need to block the signals so that the model doesn't emit reset + //this prevents the current index from changing + //it will be updated just after this + ///TODO: we should finda way to avoid blocking signals and have a real update of the model + const bool old = m->blockSignals(true); m->setStringList(list); + m->blockSignals(old); + if (list.isEmpty()) { if (currentFont != QFont()) { currentFont = QFont(); -- cgit v0.12 From 2b6fd0a7bdac686a41d7fbbe47ad3ded9e1d77b5 Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Wed, 11 Nov 2009 15:57:11 +0100 Subject: Small caps font variant wouldn't be used when defined through style sheets The font comparison (operator==) didn't check the capital attribute, which is the one responsible for this variant. Now it does. Auto-test updated. Reviewed-by: Samuel Reviewed-by: Olivier --- src/gui/text/qfont.cpp | 4 +++- tests/auto/qfont/tst_qfont.cpp | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 447087c..f1cd6bb 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -1613,7 +1613,8 @@ bool QFont::operator==(const QFont &f) const && f.d->underline == d->underline && f.d->overline == d->overline && f.d->strikeOut == d->strikeOut - && f.d->kerning == d->kerning)); + && f.d->kerning == d->kerning + && f.d->capital == d->capital)); } @@ -1645,6 +1646,7 @@ bool QFont::operator<(const QFont &f) const #ifdef Q_WS_X11 if (r1.addStyle != r2.addStyle) return r1.addStyle < r2.addStyle; #endif // Q_WS_X11 + if (f.d->capital != d->capital) return f.d->capital < d->capital; int f1attrs = (f.d->underline << 3) + (f.d->overline << 2) + (f.d->strikeOut<<1) + f.d->kerning; int f2attrs = (d->underline << 3) + (d->overline << 2) + (d->strikeOut<<1) + d->kerning; diff --git a/tests/auto/qfont/tst_qfont.cpp b/tests/auto/qfont/tst_qfont.cpp index fa76e44..5622e10 100644 --- a/tests/auto/qfont/tst_qfont.cpp +++ b/tests/auto/qfont/tst_qfont.cpp @@ -395,6 +395,13 @@ void tst_QFont::compare() font.setOverline(false); QVERIFY( font == font2 ); QVERIFY(!(font < font2)); + + font.setCapitalization(QFont::SmallCaps); + QVERIFY( font != font2 ); + QCOMPARE(font < font2,!(font2 < font)); + font.setCapitalization(QFont::MixedCase); + QVERIFY( font == font2 ); + QVERIFY(!(font < font2)); } #if defined(Q_WS_X11) -- cgit v0.12 From 46a3e518b3070cf7cb4cbbb2cb58254454cf169d Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 11 Nov 2009 16:28:24 +0100 Subject: QAbstractScrollArea: Wheel over a scrollarea that has only one horizontal scrollbar If the vertical scrollbar is hidden, scroll using the other scrollbar. Reviewed-by: Thierry Task-number: QTBUG-1760 --- src/gui/widgets/qabstractscrollarea.cpp | 11 ++- src/gui/widgets/qabstractslider.cpp | 2 - .../tst_qabstractscrollarea.cpp | 97 +++++++++++++++++++++- 3 files changed, 102 insertions(+), 8 deletions(-) diff --git a/src/gui/widgets/qabstractscrollarea.cpp b/src/gui/widgets/qabstractscrollarea.cpp index 48099ef..c186645 100644 --- a/src/gui/widgets/qabstractscrollarea.cpp +++ b/src/gui/widgets/qabstractscrollarea.cpp @@ -1130,10 +1130,13 @@ void QAbstractScrollArea::mouseMoveEvent(QMouseEvent *e) void QAbstractScrollArea::wheelEvent(QWheelEvent *e) { Q_D(QAbstractScrollArea); - if (static_cast(e)->orientation() == Qt::Horizontal) - QApplication::sendEvent(d->hbar, e); - else - QApplication::sendEvent(d->vbar, e); + QScrollBar *const bars[2] = { d->hbar, d->vbar }; + int idx = (e->orientation() == Qt::Vertical) ? 1 : 0; + int other = (idx + 1) % 2; + if (!bars[idx]->isVisible() && bars[other]->isVisible()) + idx = other; // If the scrollbar of the event orientation is hidden, fallback to the other. + + QApplication::sendEvent(bars[idx], e); } #endif diff --git a/src/gui/widgets/qabstractslider.cpp b/src/gui/widgets/qabstractslider.cpp index fec9fab..e0db9c2 100644 --- a/src/gui/widgets/qabstractslider.cpp +++ b/src/gui/widgets/qabstractslider.cpp @@ -690,8 +690,6 @@ void QAbstractSlider::wheelEvent(QWheelEvent * e) { Q_D(QAbstractSlider); e->ignore(); - if (e->orientation() != d->orientation && !rect().contains(e->pos())) - return; int stepsToScroll = 0; qreal offset = qreal(e->delta()) / 120; diff --git a/tests/auto/qabstractscrollarea/tst_qabstractscrollarea.cpp b/tests/auto/qabstractscrollarea/tst_qabstractscrollarea.cpp index 5033a50..99a263b 100644 --- a/tests/auto/qabstractscrollarea/tst_qabstractscrollarea.cpp +++ b/tests/auto/qabstractscrollarea/tst_qabstractscrollarea.cpp @@ -71,6 +71,8 @@ private slots: void viewportCrash(); void task214488_layoutDirection_data(); void task214488_layoutDirection(); + void wheelEvent_data(); + void wheelEvent(); }; tst_QAbstractScrollArea::tst_QAbstractScrollArea() @@ -296,10 +298,10 @@ public: setAttribute(Qt::WA_DropSiteRegistered, true); - startTimer(2000); + startTimer(200); } - void timerEvent(QTimerEvent *event) + void timerEvent(QTimerEvent *) { // should not crash. (void)new QScrollArea(this); @@ -385,5 +387,96 @@ void tst_QAbstractScrollArea::patternBackground() QCOMPARE(image.pixel(QPoint(20,20)) , QColor(Qt::red).rgb()); } +Q_DECLARE_METATYPE(QWheelEvent *); + +void tst_QAbstractScrollArea::wheelEvent_data() +{ + QTest::addColumn("widgetSize"); + QTest::addColumn("initialOffset"); + QTest::addColumn("event"); + QTest::addColumn("movedX"); // -1 , 0 , or 1 + QTest::addColumn("movedY"); + + QPoint pos(100,100); + int delta =-120; + + QTest::newRow("1") << QSize(600,600) << QPoint(50,50) + << new QWheelEvent(pos, delta, 0, 0, Qt::Horizontal) << 1 << 0; + + QTest::newRow("2") << QSize(600,600) << QPoint(50,50) + << new QWheelEvent(pos, delta, 0, 0, Qt::Vertical) << 0 << 1; + + QTest::newRow("3") << QSize(600,600) << QPoint(50,50) + << new QWheelEvent(pos, -delta, 0, 0, Qt::Horizontal) << -1 << 0; + + QTest::newRow("4") << QSize(600,600) << QPoint(50,50) + << new QWheelEvent(pos, -delta, 0, 0, Qt::Vertical) << 0 << -1; + + QTest::newRow("5") << QSize(20,600) << QPoint(0,50) + << new QWheelEvent(pos, delta, 0, 0, Qt::Horizontal) << 0 << 1; + + QTest::newRow("6") << QSize(20,600) << QPoint(0,50) + << new QWheelEvent(pos, delta, 0, 0, Qt::Vertical) << 0 << 1; + + QTest::newRow("7") << QSize(20,600) << QPoint(0,50) + << new QWheelEvent(pos, -delta, 0, 0, Qt::Horizontal) << 0 << -1; + + QTest::newRow("8") << QSize(20,600) << QPoint(0,50) + << new QWheelEvent(pos, -delta, 0, 0, Qt::Vertical) << 0 << -1; + + QTest::newRow("9") << QSize(600,20) << QPoint(50,0) + << new QWheelEvent(pos, delta, 0, 0, Qt::Horizontal) << 1 << 0; + + QTest::newRow("a") << QSize(600,20) << QPoint(50,0) + << new QWheelEvent(pos, delta, 0, 0, Qt::Vertical) << 1 << 0; + + QTest::newRow("b") << QSize(600,20) << QPoint(50,0) + << new QWheelEvent(pos, -delta, 0, 0, Qt::Horizontal) << -1 << 0; + + QTest::newRow("c") << QSize(600,20) << QPoint(50,0) + << new QWheelEvent(pos, -delta, 0, 0, Qt::Vertical) << -1 << 0; +} + + + + +void tst_QAbstractScrollArea::wheelEvent() +{ + QFETCH(QSize, widgetSize); + QFETCH(QPoint, initialOffset); + QFETCH(QWheelEvent *, event); + QFETCH(int, movedX); + QFETCH(int, movedY); + + QScrollArea scrollArea; + scrollArea.resize(200, 200); + QLabel widget("H e l l o"); + widget.resize(widgetSize); + scrollArea.setWidget(&widget); + scrollArea.show(); + QTest::qWait(20); + + scrollArea.verticalScrollBar()->setValue(initialOffset.y()); + scrollArea.horizontalScrollBar()->setValue(initialOffset.x()); + + QCOMPARE(scrollArea.verticalScrollBar()->value(), initialOffset.y()); + QCOMPARE(scrollArea.horizontalScrollBar()->value(), initialOffset.x()); + + QApplication::sendEvent(scrollArea.viewport(), event); + + if(movedX == 0) + QCOMPARE(scrollArea.horizontalScrollBar()->value(), initialOffset.x()); + else + QVERIFY(movedX * scrollArea.horizontalScrollBar()->value() > movedX * initialOffset.x()); + + if(movedY == 0) + QCOMPARE(scrollArea.verticalScrollBar()->value(), initialOffset.y()); + else + QVERIFY(movedY * scrollArea.verticalScrollBar()->value() > movedY * initialOffset.y()); + + delete event; +} + + QTEST_MAIN(tst_QAbstractScrollArea) #include "tst_qabstractscrollarea.moc" -- cgit v0.12 From 2d63f8fe5b77747014e1c5807c9d457611bd9304 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 11 Nov 2009 17:30:54 +0100 Subject: Fixed: QFontComboBox emits the currentFontChanged() signal twice Task-number: QTBUG-2438 Reviewed-by: Thierry --- src/gui/widgets/qfontcombobox.cpp | 4 +++- tests/auto/qfontcombobox/tst_qfontcombobox.cpp | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/gui/widgets/qfontcombobox.cpp b/src/gui/widgets/qfontcombobox.cpp index a66657d..d601f81 100644 --- a/src/gui/widgets/qfontcombobox.cpp +++ b/src/gui/widgets/qfontcombobox.cpp @@ -427,8 +427,10 @@ void QFontComboBox::setCurrentFont(const QFont &font) Q_D(QFontComboBox); if (font != d->currentFont) { d->currentFont = font; - emit currentFontChanged(d->currentFont); d->_q_updateModel(); + if (d->currentFont == font) { //else the signal has already be emitted by _q_updateModel + emit currentFontChanged(d->currentFont); + } } } diff --git a/tests/auto/qfontcombobox/tst_qfontcombobox.cpp b/tests/auto/qfontcombobox/tst_qfontcombobox.cpp index 7045c19..b974ecab 100644 --- a/tests/auto/qfontcombobox/tst_qfontcombobox.cpp +++ b/tests/auto/qfontcombobox/tst_qfontcombobox.cpp @@ -153,7 +153,7 @@ void tst_QFontComboBox::currentFont() if (oldCurrentFont != box.currentFont()) { //the signal may be emit twice if there is a foundry into brackets - QVERIFY(spy0.count() >= 1); + QCOMPARE(spy0.count(),1); } } @@ -286,6 +286,10 @@ void tst_QFontComboBox::currentFontChanged() if (box.model()->rowCount() > 2) { QTest::keyPress(&box, Qt::Key_Down); QCOMPARE(spy0.count(), 1); + + QFont f( "Sans Serif" ); + box.setCurrentFont(f); + QCOMPARE(spy0.count(), 2); } else qWarning("Not enough fonts installed on test system. Consider adding some"); } -- cgit v0.12 From 4f2dcef95299f2da628b30607021e8deb1d868b6 Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Thu, 12 Nov 2009 11:47:11 +0100 Subject: Fixed a crash when configuring an audio effect with the Phonon dialog Task-number: QTBUG-5731 Reviewed-by: jan-arve --- src/3rdparty/phonon/phonon/effectwidget.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/3rdparty/phonon/phonon/effectwidget.cpp b/src/3rdparty/phonon/phonon/effectwidget.cpp index fb9cf6e..f8341e5 100644 --- a/src/3rdparty/phonon/phonon/effectwidget.cpp +++ b/src/3rdparty/phonon/phonon/effectwidget.cpp @@ -97,8 +97,9 @@ void EffectWidgetPrivate::autogenerateUi() Q_Q(EffectWidget); QVBoxLayout *mainLayout = new QVBoxLayout(q); mainLayout->setMargin(0); - for (int i = 0; i < effect->parameters().count(); ++i) { - const EffectParameter ¶ = effect->parameters().at(i); + const QList parameters = effect->parameters(); + for (int i = 0; i < parameters.count(); ++i) { + const EffectParameter ¶ = parameters.at(i); QVariant value = effect->parameterValue(para); QHBoxLayout *pLayout = new QHBoxLayout; mainLayout->addLayout(pLayout); -- cgit v0.12