void Ut_MWidget::testShowHideSimple()
{
    QGraphicsScene scene;
    QGraphicsView view(&scene);

    view.resize(500, 500);
    view.show();

    scene.addItem(widget);

    widget->setGeometry(10, 10, 50, 50);

    widget->hide();
    m_dummySlotCalled = false;
    connect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot()));
    widget->show();
    QVERIFY(m_dummySlotCalled == true);
    disconnect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot()));

    m_dummySlotCalled = false;
    connect(widget, SIGNAL(displayExited()), this, SLOT(dummySlot()));
    widget->hide();
    QVERIFY(m_dummySlotCalled == true);
    disconnect(widget, SIGNAL(displayExited()), this, SLOT(dummySlot()));

    /* displayEntered() should not be emitted when show() is called
       for an off-view widget */
    widget->setGeometry(-500, -500, 50, 50);
    m_dummySlotCalled = false;
    connect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot()));
    widget->show();
    QVERIFY(m_dummySlotCalled == false);
    disconnect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot()));
}
void Ut_MWidget::testShowHidePropagation()
{
    QGraphicsScene scene;
    QGraphicsView view(&scene);

    view.resize(500, 500);
    view.show();

    MWidget* topLevel = new MWidget;
    MLayout *layout = new MLayout(topLevel);
    MLinearLayoutPolicy *policy = new MLinearLayoutPolicy(layout, Qt::Vertical);
    policy->addItem(widget);

    scene.addItem(topLevel);
    topLevel->setGeometry(10, 10, 50, 50);

    topLevel->hide();
    m_dummySlotCalled = false;
    connect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot()));
    topLevel->show();
    QVERIFY(m_dummySlotCalled == true);
    disconnect(widget, SIGNAL(displayEntered()), this, SLOT(dummySlot()));

    m_dummySlotCalled = false;
    connect(widget, SIGNAL(displayExited()), this, SLOT(dummySlot()));
    topLevel->hide();
    QVERIFY(m_dummySlotCalled == true);
    disconnect(widget, SIGNAL(displayExited()), this, SLOT(dummySlot()));
}
bool MSheetPrivate::canDisappear(bool dismissing)
{
    Q_Q(MSheet);

    if (standAloneWindow && standAloneWindow->scene() == q->scene()
        && standAloneWindow->isOnDisplay()) {

        // we are being shown systemwide. In this situations we let
        // the window manager handle our closing animation.

        if (dismissing) {
            q->connect(standAloneWindow, SIGNAL(displayExited()), SLOT(_q_makeSystemSheetDisappear()));
        } else {
            q->connect(standAloneWindow, SIGNAL(displayExited()), SLOT(_q_dismissSystemSheet()));
        }

        standAloneWindow->close();

        // FIXME: FINISH THIS IMPLEMENTATION HERE
        // let it disappear once standAloneWindow emits displayExited()
        return false;

    } else {
        return true;
    }
}
void Ut_MWidget::testExitedDisplay()
{
    m_dummySlotCalled = false;

    QRectF viewRect(0, 0, 864, 480);
    {
        MOnDisplayChangeEvent ev(MOnDisplayChangeEvent::FullyOnDisplay,
                                   viewRect);
        widget->event(&ev);
    }

    QVERIFY(m_dummySlotCalled == false);

    connect(widget, SIGNAL(displayExited()), this, SLOT(dummySlot()));

    {
        MOnDisplayChangeEvent ev(MOnDisplayChangeEvent::FullyOffDisplay,
                                   viewRect);
        widget->event(&ev);
    }

    QVERIFY(m_dummySlotCalled == true);

    disconnect(widget, SIGNAL(displayExited()), this, SLOT(dummySlot()));
}
void Ut_StatusIndicatorMenuWindow::testWhenFullScreenWindowComesOnTopStatusMenuIsClosed()
{
    statusIndicatorMenuWindow->displayActive();

    connect(this, SIGNAL(displayExited()), statusIndicatorMenuWindow, SLOT(displayInActive()));
    emit displayExited();
    QVERIFY(mWindowSetVisible.first == statusIndicatorMenuWindow && !mWindowSetVisible.second);

    QCOMPARE(statusIndicatorMenuWindow->menuWidget->sceneWindowState(), MSceneWindow::Disappeared);
}
void Ut_MPositionIndicatorView::testNoActivityInSwitcher()
{
    QFETCH(QRectF, range);
    m_controller->setRange(range);

    MWindow window;
    MScene *scene = new MScene;
    window.setScene(scene);
    window.show();

    scene->addItem(m_controller);
    window.showMinimized();
    QVERIFY(window.isInSwitcher());
    QVERIFY(m_controller->isOnDisplay());

    MOnDisplayChangeEvent displayExited(false, QRectF());
    qApp->sendEvent(m_controller, &displayExited);
    QVERIFY(!m_subject->d_func()->hideTimer->isActive());
    QCOMPARE(m_subject->d_func()->fadeAnimation->state(), QAbstractAnimation::Stopped);
    QCOMPARE(m_subject->contentOpacity(), qreal(0.0));

    MOnDisplayChangeEvent displayEntered(true, QRectF());
    qApp->sendEvent(m_controller, &displayEntered);
    QVERIFY(!m_subject->d_func()->hideTimer->isActive());
    QCOMPARE(m_subject->d_func()->fadeAnimation->state(), QAbstractAnimation::Stopped);
    QCOMPARE(m_subject->contentOpacity(), qreal(0.0));

    scene->removeItem(m_controller);

    delete scene;
}
void MSheetPrivate::_q_makeSystemSheetDisappear()
{
    Q_Q(MSheet);

    QObject::disconnect(standAloneWindow, SIGNAL(displayExited()),
                        q, SLOT(_q_makeSystemSheetDisappear()));

    Q_ASSERT(standAloneWindow->scene() == q->scene());
    q->sceneManager()->disappearSceneWindowNow(q);
}
void Ut_MPositionIndicatorView::testIndicatorDisappearsWhenItGetsOffDisplay()
{
    QFETCH(QRectF, range);
    m_controller->setRange(range);

    MOnDisplayChangeEvent displayExited(false, QRectF());
    qApp->sendEvent(m_controller, &displayExited);

    QVERIFY(!m_subject->d_func()->hideTimer->isActive());
    QCOMPARE(m_subject->d_func()->fadeAnimation->state(), QAbstractAnimation::Stopped);
    QCOMPARE(m_subject->contentOpacity(), qreal(0.0));
}
void MPositionIndicatorViewPrivate::init(MPositionIndicator *controller)
{
    Q_Q(MPositionIndicatorView);

    this->controller = controller;
    hideTimer->setSingleShot(true);
    fadeAnimation = new QPropertyAnimation(controller, "opacity", q);

    q->connect(hideTimer, SIGNAL(timeout()), SLOT(hide()));
    q->connect(controller, SIGNAL(displayEntered()), SLOT(_q_displayEntered()));
    q->connect(controller, SIGNAL(displayExited()), SLOT(_q_displayExited()));
}
bool
QmlApplicationViewer::event(QEvent* event)
{
    if (event->type() == QEvent::WindowStateChange) {
        QWindowStateChangeEvent* change = static_cast<QWindowStateChangeEvent*>(event);
        if (!(change->oldState() & Qt::WindowMinimized) && isMinimized())
            Q_EMIT(d->view, displayExited());
        if ((change->oldState() & Qt::WindowMinimized) && !isMinimized())
            Q_EMIT(d->view, displayEntered());
    }

    return QDeclarativeView::event(event);
}
void Ut_StatusIndicatorMenuWindow::testInitialization()
{
    QVERIFY(statusIndicatorMenuWindow->menuWidget);

    QVERIFY(disconnect(statusIndicatorMenuWindow, SIGNAL(displayExited()), statusIndicatorMenuWindow, SLOT(displayInActive())));
    QVERIFY(disconnect(statusIndicatorMenuWindow, SIGNAL(displayEntered()), statusIndicatorMenuWindow, SLOT(displayActive())));

    QVERIFY(disconnect(statusIndicatorMenuWindow->menuWidget, SIGNAL(showRequested()), statusIndicatorMenuWindow, SLOT(makeVisible())));
    QVERIFY(disconnect(statusIndicatorMenuWindow->menuWidget, SIGNAL(hideRequested()), statusIndicatorMenuWindow->menuWidget, SLOT(disappear())));
    QVERIFY(disconnect(statusIndicatorMenuWindow->menuWidget, SIGNAL(disappeared()), statusIndicatorMenuWindow, SLOT(hideWindow())));

    QVERIFY(gSceneWindowStateMap.contains(statusIndicatorMenuWindow->menuWidget));
    QCOMPARE(gSceneWindowStateMap[statusIndicatorMenuWindow->menuWidget], MSceneWindow::Disappeared);
}
StatusIndicatorMenuWindow::StatusIndicatorMenuWindow(QWidget *parent) :
    MWindow(parent),
    statusBar(new MStatusBar),
    menuWidget(NULL)
{
    QDBusConnection bus = QDBusConnection::sessionBus();
    bus.registerService(SERVICE_NAME);
    bus.registerObject(OBJECT_NAME, this, QDBusConnection::ExportScriptableSlots);

    // Show status bar
    setSceneManager(new MSceneManager);
    sceneManager()->appearSceneWindowNow(statusBar);
    currentLanguage = MLocale().language();

    statusBar->setStyleName("StatusIndicatorMenuWindowStatusBar");

    // Set the X window type, so that the window does not appear in the switcher and
    // home screen can provide the correct UI flow
    setAttribute(Qt::WA_X11NetWmWindowTypeMenu);
    setTranslucentBackground(true);
    setWindowTitle("Status Indicator Menu");
    setProperty("followsCurrentApplicationWindowOrientation", true);
    connect(this, SIGNAL(displayEntered()), this, SLOT(displayActive()));
    connect(this, SIGNAL(displayExited()), this, SLOT(displayInActive()));

#ifdef HAVE_QMSYSTEM
    /*
     * We need to receive updates when device lock state changes
     * to prevent status indicator menu opening when device lock is on
     */
    connect (&qmLocks, SIGNAL(stateChanged (MeeGo::QmLocks::Lock, MeeGo::QmLocks::State)), this,
                                   SLOT(setWindowStateAccordingToDeviceLockState(MeeGo::QmLocks::Lock, MeeGo::QmLocks::State)));
    if (qmLocks.getState(MeeGo::QmLocks::Device) != MeeGo::QmLocks::Locked) {
        deviceLocked = false;
    } else {
        deviceLocked = true;
    }
#endif

    resetMenuWidget();
}