diff options
author | Matti Vuorela <ext-matti.2.vuorela@nokia.com> | 2011-01-10 16:58:50 +0200 |
---|---|---|
committer | Adrian Yanes <ext-adrian.yanes@nokia.com> | 2011-01-17 13:37:15 +0200 |
commit | 685a2f14526fe996fb5dbf7987724bd1ba03cc00 (patch) | |
tree | 0d751521183ec27ce9b19d315395da46000c244b | |
parent | 4e2b6d3051aee796ab6d5a13917f9a43b6d90753 (diff) |
Changes: Dim the status bar when pressed
RevBy: Armin Aberres, Adrián Yanes
-rw-r--r-- | src/views/mstatusbarview.cpp | 23 | ||||
-rw-r--r-- | src/views/mstatusbarview.h | 3 | ||||
-rw-r--r-- | src/views/style/mstatusbarstyle.h | 1 | ||||
-rw-r--r-- | tests/ut_mstatusbarview/ut_mstatusbarview.cpp | 79 | ||||
-rw-r--r-- | tests/ut_mstatusbarview/ut_mstatusbarview.h | 2 |
5 files changed, 107 insertions, 1 deletions
diff --git a/src/views/mstatusbarview.cpp b/src/views/mstatusbarview.cpp index acf3e992..55358b0b 100644 --- a/src/views/mstatusbarview.cpp +++ b/src/views/mstatusbarview.cpp @@ -56,7 +56,8 @@ const char * MStatusBarView::STATUS_INDICATOR_MENU_DBUS_INTERFACE = "com.meego. MStatusBarView::MStatusBarView(MStatusBar *controller) : MSceneWindowView(controller), - controller(controller) + controller(controller), + pressDown(false) #ifdef Q_WS_X11 , updatesEnabled(true) , isInSwitcher(false) @@ -133,6 +134,14 @@ void MStatusBarView::drawContents(QPainter *painter, const QStyleOptionGraphicsI sourceRect.setHeight(SharedPixmapHeight); painter->drawPixmap(QPointF(0.0, 0.0), sharedPixmap, sourceRect); + + if (pressDown) { + painter->save(); + painter->setOpacity(style()->pressDimFactor()); + painter->fillRect(QRectF(QPointF(0.0, 0.0), sourceRect.size()), Qt::black); + painter->restore(); + } + #else Q_UNUSED(painter); #endif // Q_WS_X11 @@ -142,6 +151,12 @@ void MStatusBarView::mousePressEvent(QGraphicsSceneMouseEvent *event) { firstPos = event->pos(); playHapticsFeedback(); + + if (pressDown) + return; + + pressDown = true; + update(); } void MStatusBarView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) @@ -157,6 +172,12 @@ void MStatusBarView::mouseMoveEvent(QGraphicsSceneMouseEvent *event) void MStatusBarView::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { + if (!pressDown) + return; + + pressDown = false; + update(); + if (style()->useSwipeGesture()) { return; } diff --git a/src/views/mstatusbarview.h b/src/views/mstatusbarview.h index 800f0fbe..915ab2b7 100644 --- a/src/views/mstatusbarview.h +++ b/src/views/mstatusbarview.h @@ -73,6 +73,9 @@ private: //! position of mouse button press(firstPos) and position of last point of mouse move(lastPos) QPointF firstPos, lastPos; + //! Used to track whether a mouse button is currently being pressed + bool pressDown; + #ifdef Q_WS_X11 bool updatesEnabled; bool isInSwitcher; diff --git a/src/views/style/mstatusbarstyle.h b/src/views/style/mstatusbarstyle.h index 44caad45..125a4333 100644 --- a/src/views/style/mstatusbarstyle.h +++ b/src/views/style/mstatusbarstyle.h @@ -29,6 +29,7 @@ class M_VIEWS_EXPORT MStatusBarStyle : public MSceneWindowStyle M_STYLE_ATTRIBUTE(bool, useSwipeGesture, UseSwipeGesture) M_STYLE_ATTRIBUTE(int, swipeThreshold, SwipeThreshold) + M_STYLE_ATTRIBUTE(qreal, pressDimFactor, PressDimFactor) }; class M_VIEWS_EXPORT MStatusBarStyleContainer : public MSceneWindowStyleContainer diff --git a/tests/ut_mstatusbarview/ut_mstatusbarview.cpp b/tests/ut_mstatusbarview/ut_mstatusbarview.cpp index c2df20e8..aa29e9a6 100644 --- a/tests/ut_mstatusbarview/ut_mstatusbarview.cpp +++ b/tests/ut_mstatusbarview/ut_mstatusbarview.cpp @@ -22,6 +22,8 @@ #include <QGraphicsSceneMouseEvent> #include <QDBusPendingReply> #include <MApplication> +#include <MSceneManager> +#include <MScene> #include <mstatusbar.h> #include "mstatusbar_p.h" @@ -106,6 +108,40 @@ void MFeedback::play() const hapticsDone = true; } +qreal gTestOpacity; +QRectF gFilledRect; +QColor gFillColor; +QRectF gPixmapTargetRect; +QRectF gPixmapSourceRect; + +void QPainter::setOpacity(qreal opacity) +{ + gTestOpacity = opacity; +} + +void QPainter::fillRect(const QRectF &rectangle, const QColor &color) +{ + gFilledRect = rectangle; + gFillColor = color; +} + +void QPainter::drawPixmap(const QRectF &target, const QPixmap &pixmap, const QRectF &source) +{ + Q_UNUSED(pixmap); + + gPixmapTargetRect = target; + gPixmapSourceRect = source; +} + +void QPainter::save() +{ +} + +void QPainter::restore() +{ +} + + Ut_MStatusBarView::Ut_MStatusBarView(): m_subject(0), m_statusbar(0), @@ -231,6 +267,49 @@ void Ut_MStatusBarView::testTapFunctionality() } +void Ut_MStatusBarView::testPressDimming() +{ + qreal styleDimCSS = m_subject->modifiableStyle()->pressDimFactor(); + QCOMPARE(styleDimCSS, m_subject->modifiableStyle()->pressDimFactor()); + + m_subject->modifiableStyle()->setPressDimFactor(0.6); + + m_subject->sharedPixmap = QPixmap(50, 50); + MSceneManager sceneManager; + m_statusbar->appear(sceneManager.scene()); + + QPainter painter; + + gTestOpacity = -1; + gFillColor = -1; + gFilledRect = QRectF(); + + // Check that the dimming rectangle isn't being drawn by default + m_subject->drawContents(&painter, NULL); + QVERIFY(gFilledRect.isNull()); + + mouseDownWorker(START_POINT); + // Now the dimmer should be drawn + m_subject->drawContents(&painter, NULL); + + QCOMPARE(gTestOpacity, m_subject->modifiableStyle()->pressDimFactor()); + QCOMPARE(gFillColor, QColor(Qt::black)); + QCOMPARE(gFilledRect.size(), gPixmapSourceRect.size()); + QCOMPARE(gFilledRect.topLeft(), gPixmapTargetRect.topLeft()); + + // Release the mouse button and verify that the dimmer disappers + mouseUpWorker(START_POINT); + + gFilledRect = QRectF(); + m_subject->drawContents(&painter, NULL); + QVERIFY(gFilledRect.isNull()); + + // These are owned by the scene now + m_statusbar = NULL; + m_subject = NULL; +} + + // Helpers void Ut_MStatusBarView::mouseDownWorker(QPointF downAt) diff --git a/tests/ut_mstatusbarview/ut_mstatusbarview.h b/tests/ut_mstatusbarview/ut_mstatusbarview.h index dd1d7f3e..270f1658 100644 --- a/tests/ut_mstatusbarview/ut_mstatusbarview.h +++ b/tests/ut_mstatusbarview/ut_mstatusbarview.h @@ -74,6 +74,8 @@ private slots: void testWhenUsingTapSwipeDoesNothing(); // Thest that the tap functionality works void testTapFunctionality(); + // Test that the status bar is dimmed when pressed + void testPressDimming(); private: void mouseDownWorker(QPointF downAt); |