homescreenapp/hsdomainmodel/src/hsgui.cpp
author hgs
Wed, 18 Aug 2010 10:33:57 +0300
changeset 81 7dd137878ff8
parent 71 1db7cc813a4e
child 86 e4f038c420f7
permissions -rw-r--r--
201033
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     8
*
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    11
*
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    12
* Contributors:
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    13
*
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    14
* Description:
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
*
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    16
*/
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    18
#include <HbInstance>
69
hgs
parents: 62
diff changeset
    19
#include <HbMainWindow>
51
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    20
#include <HbView>
69
hgs
parents: 62
diff changeset
    21
#include <HbMenu>
hgs
parents: 62
diff changeset
    22
#include <HbAction>
55
03646e8da489 Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 51
diff changeset
    23
51
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    24
#include "hsgui.h"
69
hgs
parents: 62
diff changeset
    25
#include "hsidlewidget.h"
hgs
parents: 62
diff changeset
    26
#include "hsscene.h"
hgs
parents: 62
diff changeset
    27
#include "hsconfiguration.h"
hgs
parents: 62
diff changeset
    28
#include "hspropertyanimationwrapper.h"
hgs
parents: 62
diff changeset
    29
namespace {
hgs
parents: 62
diff changeset
    30
      const char gApplicationLibraryIconName[] = "qtg_mono_applications_all";
hgs
parents: 62
diff changeset
    31
}
51
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    32
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    33
/*!
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    34
    \class HsGui
62
hgs
parents: 55
diff changeset
    35
    \ingroup group_hsdomainmodel
51
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    36
    \brief Represents a view in the framework.
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    37
    HsGui includes common UI components for Home screen.
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    38
*/
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    39
69
hgs
parents: 62
diff changeset
    40
HsGui *HsGui::mInstance(0);
hgs
parents: 62
diff changeset
    41
hgs
parents: 62
diff changeset
    42
struct HsGuiImpl
51
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    43
{
69
hgs
parents: 62
diff changeset
    44
    HsIdleWidget *mIdleWidget;
hgs
parents: 62
diff changeset
    45
    HbView *mIdleView;
hgs
parents: 62
diff changeset
    46
    HbMainWindow *mWindow;
hgs
parents: 62
diff changeset
    47
    HbAction *mNavigationAction;
hgs
parents: 62
diff changeset
    48
    HsPropertyAnimationWrapper *mPageChangeAnimation;
hgs
parents: 62
diff changeset
    49
    HsPropertyAnimationWrapper *mPageCrawlingAnimation;
hgs
parents: 62
diff changeset
    50
};
hgs
parents: 62
diff changeset
    51
hgs
parents: 62
diff changeset
    52
hgs
parents: 62
diff changeset
    53
hgs
parents: 62
diff changeset
    54
HsGui::~HsGui()
hgs
parents: 62
diff changeset
    55
{
hgs
parents: 62
diff changeset
    56
    if (mImpl->mNavigationAction) {
hgs
parents: 62
diff changeset
    57
        delete mImpl->mNavigationAction;
hgs
parents: 62
diff changeset
    58
    }
hgs
parents: 62
diff changeset
    59
hgs
parents: 62
diff changeset
    60
    if (mImpl->mPageChangeAnimation) {
hgs
parents: 62
diff changeset
    61
        mImpl->mPageChangeAnimation->stop();
hgs
parents: 62
diff changeset
    62
        delete mImpl->mPageChangeAnimation;
hgs
parents: 62
diff changeset
    63
    }
hgs
parents: 62
diff changeset
    64
    if (mImpl->mPageCrawlingAnimation) {
hgs
parents: 62
diff changeset
    65
        mImpl->mPageCrawlingAnimation->stop();
hgs
parents: 62
diff changeset
    66
        delete mImpl->mPageCrawlingAnimation;
hgs
parents: 62
diff changeset
    67
    }
hgs
parents: 62
diff changeset
    68
    delete mImpl;
51
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    69
}
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    70
69
hgs
parents: 62
diff changeset
    71
HsGui *HsGui::setInstance(HsGui *instance)
hgs
parents: 62
diff changeset
    72
{
hgs
parents: 62
diff changeset
    73
    HsGui *old = mInstance;
hgs
parents: 62
diff changeset
    74
    if (mInstance != instance) {
hgs
parents: 62
diff changeset
    75
        mInstance = instance;
hgs
parents: 62
diff changeset
    76
    }
hgs
parents: 62
diff changeset
    77
    return old;
hgs
parents: 62
diff changeset
    78
}
hgs
parents: 62
diff changeset
    79
hgs
parents: 62
diff changeset
    80
HsGui *HsGui::instance()
hgs
parents: 62
diff changeset
    81
{
hgs
parents: 62
diff changeset
    82
    if (!mInstance) {
hgs
parents: 62
diff changeset
    83
        mInstance = new HsGui(QCoreApplication::instance());
hgs
parents: 62
diff changeset
    84
    }
hgs
parents: 62
diff changeset
    85
    return mInstance;
hgs
parents: 62
diff changeset
    86
}
hgs
parents: 62
diff changeset
    87
hgs
parents: 62
diff changeset
    88
HsGui *HsGui::takeInstance()
hgs
parents: 62
diff changeset
    89
{
hgs
parents: 62
diff changeset
    90
    HsGui *instance = mInstance;
hgs
parents: 62
diff changeset
    91
    mInstance = 0;
hgs
parents: 62
diff changeset
    92
    return instance;
hgs
parents: 62
diff changeset
    93
}
hgs
parents: 62
diff changeset
    94
hgs
parents: 62
diff changeset
    95
void HsGui::setupIdleUi()
hgs
parents: 62
diff changeset
    96
{
hgs
parents: 62
diff changeset
    97
    if (!mImpl->mIdleWidget) {
hgs
parents: 62
diff changeset
    98
        mImpl->mIdleWidget = new HsIdleWidget;
hgs
parents: 62
diff changeset
    99
        mImpl->mIdleView = mImpl->mWindow->addView(mImpl->mIdleWidget);
hgs
parents: 62
diff changeset
   100
        mImpl->mIdleView->setContentFullScreen();
hgs
parents: 62
diff changeset
   101
hgs
parents: 62
diff changeset
   102
        delete mImpl->mNavigationAction;
hgs
parents: 62
diff changeset
   103
        mImpl->mNavigationAction = 0;
hgs
parents: 62
diff changeset
   104
        mImpl->mNavigationAction = new HbAction;
hgs
parents: 62
diff changeset
   105
        mImpl->mNavigationAction->setIcon(HbIcon(gApplicationLibraryIconName));
hgs
parents: 62
diff changeset
   106
        mImpl->mNavigationAction->setObjectName("applib_navigation_action");
hgs
parents: 62
diff changeset
   107
        connect(mImpl->mNavigationAction, SIGNAL(triggered()), SIGNAL(navigateToApplibrary()));
hgs
parents: 62
diff changeset
   108
        mImpl->mIdleView->setNavigationAction(mImpl->mNavigationAction);
hgs
parents: 62
diff changeset
   109
    }
71
hgs
parents: 69
diff changeset
   110
    bool animate  = !mImpl->mWindow->isObscured();
hgs
parents: 69
diff changeset
   111
    mImpl->mWindow->setCurrentView(mImpl->mIdleView, animate);    
51
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   112
}
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   113
69
hgs
parents: 62
diff changeset
   114
void HsGui::cleanupIdleUi()
51
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   115
{
69
hgs
parents: 62
diff changeset
   116
    if (mImpl->mIdleView) {
hgs
parents: 62
diff changeset
   117
        mImpl->mIdleView->setNavigationAction(0);
hgs
parents: 62
diff changeset
   118
        delete mImpl->mNavigationAction;
hgs
parents: 62
diff changeset
   119
        mImpl->mNavigationAction = 0;
hgs
parents: 62
diff changeset
   120
        
hgs
parents: 62
diff changeset
   121
        mImpl->mWindow->removeView(mImpl->mIdleView);
hgs
parents: 62
diff changeset
   122
        delete mImpl->mIdleView;
hgs
parents: 62
diff changeset
   123
        mImpl->mIdleView = 0;
hgs
parents: 62
diff changeset
   124
hgs
parents: 62
diff changeset
   125
        delete mImpl->mPageChangeAnimation;
hgs
parents: 62
diff changeset
   126
        mImpl->mPageChangeAnimation = 0;
hgs
parents: 62
diff changeset
   127
        
hgs
parents: 62
diff changeset
   128
        delete mImpl->mPageCrawlingAnimation;
hgs
parents: 62
diff changeset
   129
        mImpl->mPageCrawlingAnimation = 0;
81
hgs
parents: 71
diff changeset
   130
        // This gets deleted when mImpl->mIdleView is deleted
hgs
parents: 71
diff changeset
   131
        // so just nullify.
hgs
parents: 71
diff changeset
   132
        mImpl->mIdleWidget = 0;
51
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   133
    }
69
hgs
parents: 62
diff changeset
   134
    
hgs
parents: 62
diff changeset
   135
}
hgs
parents: 62
diff changeset
   136
hgs
parents: 62
diff changeset
   137
void HsGui::setOrientation(Qt::Orientation orientation)
hgs
parents: 62
diff changeset
   138
{
hgs
parents: 62
diff changeset
   139
    mImpl->mWindow->setOrientation(orientation);
hgs
parents: 62
diff changeset
   140
}
hgs
parents: 62
diff changeset
   141
hgs
parents: 62
diff changeset
   142
Qt::Orientation HsGui::orientation()
hgs
parents: 62
diff changeset
   143
{
hgs
parents: 62
diff changeset
   144
    return mImpl->mWindow->orientation();
hgs
parents: 62
diff changeset
   145
}
hgs
parents: 62
diff changeset
   146
hgs
parents: 62
diff changeset
   147
HbView *HsGui::idleView() const
hgs
parents: 62
diff changeset
   148
{
hgs
parents: 62
diff changeset
   149
    return mImpl->mIdleView;
hgs
parents: 62
diff changeset
   150
}
hgs
parents: 62
diff changeset
   151
hgs
parents: 62
diff changeset
   152
HsIdleWidget *HsGui::idleWidget() const
hgs
parents: 62
diff changeset
   153
{
hgs
parents: 62
diff changeset
   154
    return mImpl->mIdleWidget;
51
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   155
}
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   156
69
hgs
parents: 62
diff changeset
   157
QRectF HsGui::layoutRect() const
51
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   158
{
69
hgs
parents: 62
diff changeset
   159
    return mImpl->mWindow->layoutRect();
hgs
parents: 62
diff changeset
   160
}
hgs
parents: 62
diff changeset
   161
hgs
parents: 62
diff changeset
   162
void HsGui::show()
hgs
parents: 62
diff changeset
   163
{
hgs
parents: 62
diff changeset
   164
    mImpl->mWindow->raise();
hgs
parents: 62
diff changeset
   165
    mImpl->mWindow->show();
51
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   166
}
4785f57bf3d4 Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   167
69
hgs
parents: 62
diff changeset
   168
HsPropertyAnimationWrapper *HsGui::pageChangeAnimation()
hgs
parents: 62
diff changeset
   169
{
hgs
parents: 62
diff changeset
   170
    if (!mImpl->mPageChangeAnimation) {
hgs
parents: 62
diff changeset
   171
        mImpl->mPageChangeAnimation = new HsPropertyAnimationWrapper;
hgs
parents: 62
diff changeset
   172
        mImpl->mPageChangeAnimation->setTargetObject(mImpl->mIdleWidget);
hgs
parents: 62
diff changeset
   173
        mImpl->mPageChangeAnimation->setPropertyName("sceneX"); 
hgs
parents: 62
diff changeset
   174
    }
hgs
parents: 62
diff changeset
   175
    return mImpl->mPageChangeAnimation;
hgs
parents: 62
diff changeset
   176
}
hgs
parents: 62
diff changeset
   177
HsPropertyAnimationWrapper *HsGui::pageCrawlingAnimation()
hgs
parents: 62
diff changeset
   178
{
hgs
parents: 62
diff changeset
   179
    if (!mImpl->mPageCrawlingAnimation) {
hgs
parents: 62
diff changeset
   180
        mImpl->mPageCrawlingAnimation = new HsPropertyAnimationWrapper;
hgs
parents: 62
diff changeset
   181
        mImpl->mPageCrawlingAnimation->setTargetObject(mImpl->mIdleWidget);
hgs
parents: 62
diff changeset
   182
        mImpl->mPageCrawlingAnimation->setPropertyName("sceneX"); 
hgs
parents: 62
diff changeset
   183
    }
hgs
parents: 62
diff changeset
   184
    return mImpl->mPageCrawlingAnimation;
hgs
parents: 62
diff changeset
   185
}
hgs
parents: 62
diff changeset
   186
hgs
parents: 62
diff changeset
   187
HsGui::HsGui(QObject *parent):
hgs
parents: 62
diff changeset
   188
    QObject(parent),mImpl(new HsGuiImpl)
hgs
parents: 62
diff changeset
   189
{
hgs
parents: 62
diff changeset
   190
    mImpl->mIdleView = 0;
hgs
parents: 62
diff changeset
   191
    mImpl->mIdleWidget = 0;
hgs
parents: 62
diff changeset
   192
    mImpl->mNavigationAction = 0;
hgs
parents: 62
diff changeset
   193
    mImpl->mPageChangeAnimation = 0;
hgs
parents: 62
diff changeset
   194
    mImpl->mPageCrawlingAnimation = 0;
hgs
parents: 62
diff changeset
   195
hgs
parents: 62
diff changeset
   196
    mImpl->mWindow = hbInstance->allMainWindows().first();
hgs
parents: 62
diff changeset
   197
    connect(mImpl->mWindow, SIGNAL(orientationChanged(Qt::Orientation)),
hgs
parents: 62
diff changeset
   198
        SIGNAL(orientationChanged(Qt::Orientation)));
hgs
parents: 62
diff changeset
   199
}