homescreenapp/hsdomainmodel/src/hsgui.cpp
changeset 77 4b195f3bea29
parent 60 30f14686fb04
child 85 35368b604b28
equal deleted inserted replaced
61:2b1b11a301d2 77:4b195f3bea29
    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     bool animate  = !mImpl->mWindow->isObscured();
       
   111     mImpl->mWindow->setCurrentView(mImpl->mIdleView, animate);    
       
   112 }
       
   113 
       
   114 void HsGui::cleanupIdleUi()
       
   115 {
       
   116     if (mImpl->mIdleView) {
       
   117         mImpl->mIdleView->setNavigationAction(0);
       
   118         delete mImpl->mNavigationAction;
       
   119         mImpl->mNavigationAction = 0;
       
   120         
       
   121         mImpl->mWindow->removeView(mImpl->mIdleView);
       
   122         delete mImpl->mIdleView;
       
   123         mImpl->mIdleView = 0;
       
   124 
       
   125         delete mImpl->mPageChangeAnimation;
       
   126         mImpl->mPageChangeAnimation = 0;
       
   127         
       
   128         delete mImpl->mPageCrawlingAnimation;
       
   129         mImpl->mPageCrawlingAnimation = 0;
       
   130     }
       
   131     
       
   132 }
       
   133 
       
   134 void HsGui::setOrientation(Qt::Orientation orientation)
       
   135 {
       
   136     mImpl->mWindow->setOrientation(orientation);
       
   137 }
       
   138 
       
   139 Qt::Orientation HsGui::orientation()
       
   140 {
       
   141     return mImpl->mWindow->orientation();
       
   142 }
       
   143 
       
   144 HbView *HsGui::idleView() const
       
   145 {
       
   146     return mImpl->mIdleView;
       
   147 }
       
   148 
       
   149 HsIdleWidget *HsGui::idleWidget() const
       
   150 {
       
   151     return mImpl->mIdleWidget;
       
   152 }
       
   153 
       
   154 QRectF HsGui::layoutRect() const
       
   155 {
       
   156     return mImpl->mWindow->layoutRect();
       
   157 }
       
   158 
       
   159 void HsGui::show()
       
   160 {
       
   161     mImpl->mWindow->raise();
       
   162     mImpl->mWindow->show();
       
   163 }
       
   164 
       
   165 HsPropertyAnimationWrapper *HsGui::pageChangeAnimation()
       
   166 {
       
   167     if (!mImpl->mPageChangeAnimation) {
       
   168         mImpl->mPageChangeAnimation = new HsPropertyAnimationWrapper;
       
   169         mImpl->mPageChangeAnimation->setTargetObject(mImpl->mIdleWidget);
       
   170         mImpl->mPageChangeAnimation->setPropertyName("sceneX"); 
       
   171     }
       
   172     return mImpl->mPageChangeAnimation;
       
   173 }
       
   174 HsPropertyAnimationWrapper *HsGui::pageCrawlingAnimation()
       
   175 {
       
   176     if (!mImpl->mPageCrawlingAnimation) {
       
   177         mImpl->mPageCrawlingAnimation = new HsPropertyAnimationWrapper;
       
   178         mImpl->mPageCrawlingAnimation->setTargetObject(mImpl->mIdleWidget);
       
   179         mImpl->mPageCrawlingAnimation->setPropertyName("sceneX"); 
       
   180     }
       
   181     return mImpl->mPageCrawlingAnimation;
       
   182 }
       
   183 
       
   184 HsGui::HsGui(QObject *parent):
       
   185     QObject(parent),mImpl(new HsGuiImpl)
       
   186 {
       
   187     mImpl->mIdleView = 0;
       
   188     mImpl->mIdleWidget = 0;
       
   189     mImpl->mNavigationAction = 0;
       
   190     mImpl->mPageChangeAnimation = 0;
       
   191     mImpl->mPageCrawlingAnimation = 0;
       
   192 
       
   193     mImpl->mWindow = hbInstance->allMainWindows().first();
       
   194     connect(mImpl->mWindow, SIGNAL(orientationChanged(Qt::Orientation)),
       
   195         SIGNAL(orientationChanged(Qt::Orientation)));
       
   196 }