homescreenapp/hsdomainmodel/src/hsgui.cpp
changeset 69 87476091b3f5
parent 62 341166945d65
child 71 1db7cc813a4e
equal deleted inserted replaced
67:474929a40a0f 69:87476091b3f5
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include <HbInstance>
    18 #include <HbInstance>
       
    19 #include <HbMainWindow>
    19 #include <HbView>
    20 #include <HbView>
       
    21 #include <HbMenu>
       
    22 #include <HbAction>
    20 
    23 
    21 #include "hsgui.h"
    24 #include "hsgui.h"
       
    25 #include "hsidlewidget.h"
       
    26 #include "hsscene.h"
       
    27 #include "hsconfiguration.h"
       
    28 #include "hspropertyanimationwrapper.h"
       
    29 namespace {
       
    30       const char gApplicationLibraryIconName[] = "qtg_mono_applications_all";
       
    31 }
    22 
    32 
    23 /*!
    33 /*!
    24     \class HsGui
    34     \class HsGui
    25     \ingroup group_hsdomainmodel
    35     \ingroup group_hsdomainmodel
    26     \brief Represents a view in the framework.
    36     \brief Represents a view in the framework.
    27     HsGui includes common UI components for Home screen.
    37     HsGui includes common UI components for Home screen.
    28 */
    38 */
    29 
    39 
    30 /*!
    40 HsGui *HsGui::mInstance(0);
    31     Returns the idle view. 
    41 
    32 */
    42 struct HsGuiImpl
    33 HbView *HsGui::idleView()
       
    34 {
    43 {
    35     return mIdleView;    
    44     HsIdleWidget *mIdleWidget;
       
    45     HbView *mIdleView;
       
    46     HbMainWindow *mWindow;
       
    47     HbAction *mNavigationAction;
       
    48     HsPropertyAnimationWrapper *mPageChangeAnimation;
       
    49     HsPropertyAnimationWrapper *mPageCrawlingAnimation;
       
    50 };
       
    51 
       
    52 
       
    53 
       
    54 HsGui::~HsGui()
       
    55 {
       
    56     if (mImpl->mNavigationAction) {
       
    57         delete mImpl->mNavigationAction;
       
    58     }
       
    59 
       
    60     if (mImpl->mPageChangeAnimation) {
       
    61         mImpl->mPageChangeAnimation->stop();
       
    62         delete mImpl->mPageChangeAnimation;
       
    63     }
       
    64     if (mImpl->mPageCrawlingAnimation) {
       
    65         mImpl->mPageCrawlingAnimation->stop();
       
    66         delete mImpl->mPageCrawlingAnimation;
       
    67     }
       
    68     delete mImpl;
    36 }
    69 }
    37 
    70 
    38 /*!
    71 HsGui *HsGui::setInstance(HsGui *instance)
    39     Returns the current idle view instance. Callers of this 
    72 {
    40     function take ownership of the instance. The current 
    73     HsGui *old = mInstance;
    41     view instance will be reset to null.    
    74     if (mInstance != instance) {
    42 */
    75         mInstance = instance;
    43 HbView *HsGui::takeIdleView()
    76     }
    44 {	
    77     return old;
    45     HbView *idleView = mIdleView;
       
    46     mIdleView = 0;
       
    47     return idleView;
       
    48 }
    78 }
    49 
    79 
    50 /*!
    80 HsGui *HsGui::instance()
    51     Sets the idle view instance. The existing instance
       
    52     will be deleted.
       
    53 */
       
    54 void HsGui::setIdleView(HbView *idleView)
       
    55 {
    81 {
    56     if (mIdleView != idleView) {
    82     if (!mInstance) {
    57         delete mIdleView;
    83         mInstance = new HsGui(QCoreApplication::instance());
    58         mIdleView = idleView;
       
    59     }
    84     }
       
    85     return mInstance;
    60 }
    86 }
    61 
    87 
    62 /*!
    88 HsGui *HsGui::takeInstance()
    63     Returns the main window.
       
    64 */
       
    65 HbMainWindow *HsGui::mainWindow()
       
    66 {
    89 {
    67     return hbInstance->allMainWindows().first();
    90     HsGui *instance = mInstance;
       
    91     mInstance = 0;
       
    92     return instance;
    68 }
    93 }
    69 
    94 
    70 /*!
    95 void HsGui::setupIdleUi()
    71     Points to the idle view instance.
    96 {
    72 */
    97     if (!mImpl->mIdleWidget) {
    73 QPointer<HbView> HsGui::mIdleView(0);
    98         mImpl->mIdleWidget = new HsIdleWidget;
       
    99         mImpl->mIdleView = mImpl->mWindow->addView(mImpl->mIdleWidget);
       
   100         mImpl->mIdleView->setContentFullScreen();
       
   101 
       
   102         delete mImpl->mNavigationAction;
       
   103         mImpl->mNavigationAction = 0;
       
   104         mImpl->mNavigationAction = new HbAction;
       
   105         mImpl->mNavigationAction->setIcon(HbIcon(gApplicationLibraryIconName));
       
   106         mImpl->mNavigationAction->setObjectName("applib_navigation_action");
       
   107         connect(mImpl->mNavigationAction, SIGNAL(triggered()), SIGNAL(navigateToApplibrary()));
       
   108         mImpl->mIdleView->setNavigationAction(mImpl->mNavigationAction);
       
   109     }
       
   110     mImpl->mWindow->setCurrentView(mImpl->mIdleView);    
       
   111 }
       
   112 
       
   113 void HsGui::cleanupIdleUi()
       
   114 {
       
   115     if (mImpl->mIdleView) {
       
   116         mImpl->mIdleView->setNavigationAction(0);
       
   117         delete mImpl->mNavigationAction;
       
   118         mImpl->mNavigationAction = 0;
       
   119         
       
   120         mImpl->mWindow->removeView(mImpl->mIdleView);
       
   121         delete mImpl->mIdleView;
       
   122         mImpl->mIdleView = 0;
       
   123 
       
   124         delete mImpl->mPageChangeAnimation;
       
   125         mImpl->mPageChangeAnimation = 0;
       
   126         
       
   127         delete mImpl->mPageCrawlingAnimation;
       
   128         mImpl->mPageCrawlingAnimation = 0;
       
   129     }
       
   130     
       
   131 }
       
   132 
       
   133 void HsGui::setOrientation(Qt::Orientation orientation)
       
   134 {
       
   135     mImpl->mWindow->setOrientation(orientation);
       
   136 }
       
   137 
       
   138 Qt::Orientation HsGui::orientation()
       
   139 {
       
   140     return mImpl->mWindow->orientation();
       
   141 }
       
   142 
       
   143 HbView *HsGui::idleView() const
       
   144 {
       
   145     return mImpl->mIdleView;
       
   146 }
       
   147 
       
   148 HsIdleWidget *HsGui::idleWidget() const
       
   149 {
       
   150     return mImpl->mIdleWidget;
       
   151 }
       
   152 
       
   153 QRectF HsGui::layoutRect() const
       
   154 {
       
   155     return mImpl->mWindow->layoutRect();
       
   156 }
       
   157 
       
   158 void HsGui::show()
       
   159 {
       
   160     mImpl->mWindow->raise();
       
   161     mImpl->mWindow->show();
       
   162 }
       
   163 
       
   164 HsPropertyAnimationWrapper *HsGui::pageChangeAnimation()
       
   165 {
       
   166     if (!mImpl->mPageChangeAnimation) {
       
   167         mImpl->mPageChangeAnimation = new HsPropertyAnimationWrapper;
       
   168         mImpl->mPageChangeAnimation->setTargetObject(mImpl->mIdleWidget);
       
   169         mImpl->mPageChangeAnimation->setPropertyName("sceneX"); 
       
   170     }
       
   171     return mImpl->mPageChangeAnimation;
       
   172 }
       
   173 HsPropertyAnimationWrapper *HsGui::pageCrawlingAnimation()
       
   174 {
       
   175     if (!mImpl->mPageCrawlingAnimation) {
       
   176         mImpl->mPageCrawlingAnimation = new HsPropertyAnimationWrapper;
       
   177         mImpl->mPageCrawlingAnimation->setTargetObject(mImpl->mIdleWidget);
       
   178         mImpl->mPageCrawlingAnimation->setPropertyName("sceneX"); 
       
   179     }
       
   180     return mImpl->mPageCrawlingAnimation;
       
   181 }
       
   182 
       
   183 HsGui::HsGui(QObject *parent):
       
   184     QObject(parent),mImpl(new HsGuiImpl)
       
   185 {
       
   186     mImpl->mIdleView = 0;
       
   187     mImpl->mIdleWidget = 0;
       
   188     mImpl->mNavigationAction = 0;
       
   189     mImpl->mPageChangeAnimation = 0;
       
   190     mImpl->mPageCrawlingAnimation = 0;
       
   191 
       
   192     mImpl->mWindow = hbInstance->allMainWindows().first();
       
   193     connect(mImpl->mWindow, SIGNAL(orientationChanged(Qt::Orientation)),
       
   194         SIGNAL(orientationChanged(Qt::Orientation)));
       
   195 }