homescreenapp/hsdomainmodel/src/hsscene.cpp
changeset 60 30f14686fb04
parent 55 03646e8da489
child 61 2b1b11a301d2
equal deleted inserted replaced
55:03646e8da489 60:30f14686fb04
    17 
    17 
    18 #include <QApplication>
    18 #include <QApplication>
    19 
    19 
    20 #include <HbInstance>
    20 #include <HbInstance>
    21 #include <HbMainWindow>
    21 #include <HbMainWindow>
    22 #include <HbDeviceProfile>
       
    23 
    22 
    24 #include "hsdomainmodeldatastructures.h"
    23 #include "hsdomainmodeldatastructures.h"
    25 #include "hsscene.h"
    24 #include "hsscene.h"
    26 #include "hspage.h"
    25 #include "hspage.h"
    27 #include "hswidgethost.h"
    26 #include "hswidgethost.h"
    28 #include "hsdatabase.h"
    27 #include "hsdatabase.h"
    29 #include "hswallpaper.h"
    28 #include "hswallpaper.h"
    30 #include "hsconfiguration.h"
    29 #include "hsconfiguration.h"
    31 
    30 
       
    31 
       
    32 /*!
       
    33     \class HsScene
       
    34     \ingroup group_hsdomainmodel
       
    35     \brief Represents a scene in the framework.
       
    36     HsScene can have a wallpaper.
       
    37 */
       
    38 
    32 /*!
    39 /*!
    33     Destructor.
    40     Destructor.
    34 */
    41 */
    35 HsScene::~HsScene()
    42 HsScene::~HsScene()
    36 {
    43 {
    56     HsSceneData sceneData;
    63     HsSceneData sceneData;
    57     if (!db->scene(sceneData)) {
    64     if (!db->scene(sceneData)) {
    58         return false;
    65         return false;
    59     }
    66     }
    60 
    67 
    61     mMaximumPageCount = HsConfiguration::maximumPageCount();
    68     mDatabaseId = sceneData.id;
    62 
       
    63     calculateWidgetSizeLimitations();
       
    64 
       
    65     if (sceneData.portraitWallpaper.isEmpty()) {
       
    66         mWallpaper->setImagesById();
       
    67     } else {
       
    68         mWallpaper->setImagesByPaths(
       
    69             sceneData.landscapeWallpaper, 
       
    70             sceneData.portraitWallpaper);
       
    71     }
       
    72 
    69 
    73     QList<HsPageData> pageDatas;
    70     QList<HsPageData> pageDatas;
    74     if (!db->pages(pageDatas) || pageDatas.empty()) {
    71     if (!db->pages(pageDatas) || pageDatas.empty()) {
    75         return false;
    72         return false;
    76     }
    73     }
    77     
    74     
       
    75     if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::SceneWallpaper) {
       
    76         mWallpaper = new HsSceneWallpaper(this);
       
    77     }
       
    78 
    78     foreach (HsPageData pageData, pageDatas) {
    79     foreach (HsPageData pageData, pageDatas) {
    79         HsPage *page = new HsPage;
    80         HsPage *page = new HsPage;
    80         page->setDatabaseId(pageData.id);
    81         page->setDatabaseId(pageData.id);
    81         if (page->load()) {
    82         if (page->load()) {
    82             mPages.append(page);
    83             mPages.append(page);
    83         } else {
    84         } else {
    84             delete page;
    85             delete page;
    85             continue;
    86             continue;
    86         }
    87         }
    87         if (pageData.id == HsConfiguration::defaultPageId()) {
    88         if (pageData.id == HSCONFIGURATION_GET(defaultPageId)) {
    88             mActivePage = page;
    89             mActivePage = page;
    89             mActivePage->setRemovable(false);
    90             mActivePage->setRemovable(false);
    90         }
    91         }
    91     }
    92     }
    92 
    93     
    93     QApplication::instance()->installEventFilter(this);
       
    94 
       
    95 	return true;
    94 	return true;
    96 }
    95 }
    97 
    96 
    98 /*!
    97 /*!
    99     Calculate maximum and minimum widget sizes 
    98     Return wallpaper.
   100 */
       
   101 void HsScene::calculateWidgetSizeLimitations()
       
   102 {
       
   103     // 1un = 6.7px = 2mm
       
   104     mMaximumWidgetSizeInUnits = QSizeF(HsConfiguration::maximumWidgetWidth(),
       
   105                                        HsConfiguration::maximumWidgetHeight());
       
   106     mMinimumWidgetSizeInUnits = QSizeF(HsConfiguration::minimumWidgetWidth(),
       
   107                                        HsConfiguration::minimumWidgetHeight());
       
   108     HbDeviceProfile profile;
       
   109     qreal unitToPixelFactor = profile.unitValue();
       
   110     mMaximumWidgetSizeInPixels = unitToPixelFactor * mMaximumWidgetSizeInUnits;
       
   111     mMinimumWidgetSizeInPixels = unitToPixelFactor * mMinimumWidgetSizeInUnits;
       
   112 }
       
   113 
       
   114 /*!
       
   115     Return wallpaper. 
       
   116 */
    99 */
   117 HsWallpaper *HsScene::wallpaper() const
   100 HsWallpaper *HsScene::wallpaper() const
   118 {
   101 {
   119     return mWallpaper;
   102     return mWallpaper;
   120 }
   103 }
   124 */
   107 */
   125 QList<HsPage *> HsScene::pages() const
   108 QList<HsPage *> HsScene::pages() const
   126 {
   109 {
   127     return mPages;
   110     return mPages;
   128 }
   111 }
   129     
   112 
   130 /*!
   113 /*!
   131     Add page \a page.
   114     Add page \a page.
   132 */
   115 */
   133 bool HsScene::addPage(HsPage *page)
   116 bool HsScene::addPage(HsPage *page)
   134 {
   117 {
   135     if (!page) {
   118     if (!page) {
   136         return false;
   119         return false;
   137     }
   120     }
   138    
   121 
   139     if (mPages.contains(page)) {
   122     if (mPages.contains(page)) {
   140         return true;
   123         return true;
   141     }
   124     }
   142 
   125 
   143     HsDatabase *db = HsDatabase::instance();
   126     HsDatabase *db = HsDatabase::instance();
   144     
   127 
   145     HsPageData data;
   128     HsPageData data;
   146     data.id = page->databaseId();
   129     data.id = page->databaseId();
   147     if (!db->page(data)) {
   130     if (!db->page(data)) {
   148         return false;
   131         return false;
   149     }
   132     }
   158         if (!db->updatePage(data)) {
   141         if (!db->updatePage(data)) {
   159             db->rollback();
   142             db->rollback();
   160             return false;
   143             return false;
   161         }
   144         }
   162     }
   145     }
   163     
   146 
   164     db->commit();
   147     db->commit();
   165     
   148 
   166     mPages.insert(addPosition, page);
   149     mPages.insert(addPosition, page);
   167     return true;
   150     return true;
   168 }
   151 }
   169     
   152 
   170 /*!
   153 /*!
   171     Removes page \a page.
   154     Removes page \a page.
   172 */
   155 */
   173 bool HsScene::removePage(HsPage *page)
   156 bool HsScene::removePage(HsPage *page)
   174 {
   157 {
   203     db->commit();
   186     db->commit();
   204 
   187 
   205     mPages.removeOne(page);
   188     mPages.removeOne(page);
   206     return true;
   189     return true;
   207 }
   190 }
   208  
   191 
   209 /*!
   192 /*!
   210     Set active page \a page.
   193     Set active page \a page.
   211 */
   194 */
   212 bool HsScene::setActivePage(HsPage *page)
   195 bool HsScene::setActivePage(HsPage *page)
   213 {
   196 {
   214     if (!page) {
   197     if (!page) {
   215         return false;
   198         return false;
   216     }
   199     }
   217    
   200 
   218     if (!mPages.contains(page)) {
   201     if (!mPages.contains(page)) {
   219         return false;
   202         return false;
   220     }
   203     }
   221 
   204 
   222     if (page == mActivePage) {
   205     if (page == mActivePage) {
   262 {
   245 {
   263     return mPages.indexOf(mActivePage);
   246     return mPages.indexOf(mActivePage);
   264 }
   247 }
   265 
   248 
   266 /*!
   249 /*!
   267     Return maximum number of pages.
       
   268 */
       
   269 int HsScene::maximumPageCount() const
       
   270 {
       
   271     return mMaximumPageCount;
       
   272 }
       
   273 
       
   274 /*!
       
   275     Return maximum widget size in pixels.
       
   276 */
       
   277 QSizeF HsScene::maximumWidgetSizeInPixels() const
       
   278 {
       
   279     return mMaximumWidgetSizeInPixels;
       
   280 }
       
   281 
       
   282 /*!
       
   283     Return minimum widget size in pixels.
       
   284 */
       
   285 QSizeF HsScene::minimumWidgetSizeInPixels() const
       
   286 {
       
   287     return mMinimumWidgetSizeInPixels;
       
   288 }
       
   289 
       
   290 /*!
       
   291     Return maximum widget size in units.
       
   292 */
       
   293 QSizeF HsScene::maximumWidgetSizeInUnits() const
       
   294 {
       
   295     return mMaximumWidgetSizeInUnits;
       
   296 }
       
   297 
       
   298 /*!
       
   299     Return minimum widget size in units.
       
   300 */
       
   301 QSizeF HsScene::minimumWidgetSizeInUnits() const
       
   302 {
       
   303     return mMinimumWidgetSizeInUnits;
       
   304 }
       
   305 
       
   306 /*!
       
   307     Set active widget \a widget.
   250     Set active widget \a widget.
   308 */
   251 */
   309 void HsScene::setActiveWidget(HsWidgetHost *widget)
   252 void HsScene::setActiveWidget(HsWidgetHost *widget)
   310 {
   253 {
   311     mActiveWidget = widget;
   254     mActiveWidget = widget;
   312 }
   255 }
   313  
   256 
   314 /*!
   257 /*!
   315    Return active widget.
   258    Return active widget.
   316 */
   259 */
   317 HsWidgetHost *HsScene::activeWidget() const
   260 HsWidgetHost *HsScene::activeWidget() const
   318 {
   261 {
   319     return mActiveWidget;
   262     return mActiveWidget;
   320 }
   263 }
   321 /*!
   264 /*!
   322     Toggle application online state. Defaults 
   265     Toggle application online state. Defaults
   323     to true.
   266     to true.
   324 */
   267 */
   325 void HsScene::setOnline(bool online)
   268 void HsScene::setOnline(bool online)
   326 {
   269 {
   327     mIsOnline = online;
   270     mIsOnline = online;
   337 {
   280 {
   338     return mIsOnline;
   281     return mIsOnline;
   339 }
   282 }
   340 
   283 
   341 /*!
   284 /*!
   342     Singleton. 
   285     Singleton.
   343 */
   286 */
   344 HsScene *HsScene::instance()
   287 HsScene *HsScene::instance()
   345 {
   288 {
   346     if (!mInstance) {
       
   347         mInstance = new HsScene;
       
   348         mInstance->setParent(HsScene::mainWindow());
       
   349     }
       
   350     return mInstance;
   289     return mInstance;
       
   290 }
       
   291 
       
   292 HsScene *HsScene::takeInstance()
       
   293 {
       
   294     HsScene *instance = mInstance;
       
   295     mInstance = 0;
       
   296     return instance;
       
   297 }
       
   298  
       
   299 void HsScene::setInstance(HsScene *instance)
       
   300 {
       
   301     if (mInstance != instance) {
       
   302         delete mInstance;
       
   303         mInstance = instance; 
       
   304     }    
   351 }
   305 }
   352 
   306 
   353 /*!
   307 /*!
   354     Return main window.
   308     Return main window.
   355 */
   309 */
   387 /*!
   341 /*!
   388     Constructor
   342     Constructor
   389 */
   343 */
   390 HsScene::HsScene(QObject *parent)
   344 HsScene::HsScene(QObject *parent)
   391   : QObject(parent),
   345   : QObject(parent),
   392     mDatabaseId(-1),    
   346     mDatabaseId(-1),
   393     mWallpaper(0),    
   347     mWallpaper(0),
   394     mActivePage(0),
   348     mActivePage(0),
   395     mActiveWidget(0),
   349     mActiveWidget(0),
   396     mIsOnline(true),
   350     mIsOnline(true)
   397     mMaximumPageCount(1),
   351 {
   398     mMaximumWidgetSizeInPixels(321.6, 261.3),
       
   399     mMinimumWidgetSizeInPixels(58.625, 58.625),
       
   400     mMaximumWidgetSizeInUnits(48, 39),
       
   401     mMinimumWidgetSizeInUnits(8.75, 8.75)
       
   402 {
       
   403     mWallpaper = new HsWallpaper;
       
   404 }
   352 }
   405 
   353 
   406 /*!
   354 /*!
   407     Points to the scene instance.
   355     Points to the scene instance.
   408 */
   356 */