homescreenapp/stateplugins/hshomescreenstateplugin/src/hsidlewidget.cpp
changeset 36 cdae8c6c3876
parent 35 f9ce957a272c
child 51 4785f57bf3d4
equal deleted inserted replaced
35:f9ce957a272c 36:cdae8c6c3876
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 #include <QApplication>
    18 #include <QGraphicsSceneMouseEvent>
    19 #include <QGraphicsSceneMouseEvent>
    19 #include <QGraphicsLinearLayout>
    20 #include <QGraphicsLinearLayout>
    20 #include <QDir>
    21 #include <QDir>
    21 
    22 
    22 #include <HbMainWindow>
    23 #include <HbMainWindow>
    23 #include <HbInputMethod>
    24 #include <HbVkbHost>
    24 
    25 
    25 #include "hsidlewidget.h"
    26 #include "hsidlewidget.h"
    26 #include "hsscene.h"
    27 #include "hsscene.h"
    27 #include "hspage.h"
    28 #include "hspage.h"
    28 #include "hswidgethost.h"
    29 #include "hswidgethost.h"
    29 #include "hswallpaper.h"
    30 #include "hswallpaper.h"
    30 #include "hstrashbinwidget.h"
    31 #include "hstrashbinwidget.h"
    31 #include "hspageindicator.h"
    32 #include "hspageindicator.h"
    32 #include "hsdocumentloader.h"
    33 #include "hsdocumentloader.h"
       
    34 #include "hshomescreenstatecommon.h"
    33 
    35 
    34 namespace
    36 namespace
    35 {
    37 {
    36     const char CONTROL_LAYER_DOCML_FILE[] = "controllayer.docml";
    38     const char gControlLayerDocmlName[] = "controllayer.docml";
    37     const char CONTROL_LAYER[] = "controlLayer";
    39     const char gControlLayerName[]      = "controlLayer";
    38     const char TRASH_BIN[] = "trashBin";
    40     const char gTrashBinName[]          = "trashBin";
    39     const char PAGE_INDICATOR[] = "pageIndicator";
    41     const char gPageIndicatorName[]     = "pageIndicator";
    40 }
    42 }
    41 
    43 
    42 /*!
    44 /*!
    43     \class HsIdleWidget
    45     \class HsIdleWidget
    44     \ingroup group_hshomescreenstateplugin
    46     \ingroup group_hshomescreenstateplugin
   107 void HsIdleWidget::setGeometry(const QRectF &rect)
   109 void HsIdleWidget::setGeometry(const QRectF &rect)
   108 {
   110 {
   109     int n = HsScene::instance()->pages().count();
   111     int n = HsScene::instance()->pages().count();
   110     mControlLayer->resize(rect.size());
   112     mControlLayer->resize(rect.size());
   111     mPageLayer->resize(n * rect.width(), rect.height());
   113     mPageLayer->resize(n * rect.width(), rect.height());
   112     mSceneLayer->resize(2 * rect.width(), rect.height());
   114     mSceneLayer->resize(2 * rect.width() + HSBOUNDARYEFFECT, rect.height());
   113     HbWidget::setGeometry(rect);
   115     HbWidget::setGeometry(rect);
   114 }
   116 }
   115 
   117 
   116 /*!
   118 /*!
   117     Stores the given mouse press \a event.
   119     Stores the given mouse press \a event.
   151     Sets the active page \a index to the page 
   153     Sets the active page \a index to the page 
   152     indicator.
   154     indicator.
   153 */
   155 */
   154 void HsIdleWidget::setActivePage(int index)
   156 void HsIdleWidget::setActivePage(int index)
   155 {
   157 {
   156     mPageIndicator->setCurrentIndex(index);
   158     mPageIndicator->setActiveItemIndex(index);
   157 }
   159 }
   158 
   160 
   159 /*!
   161 /*!
   160     Inserts the given \a page at index position
   162     Inserts the given \a page at index position
   161     \a index in the page layer.
   163     \a index in the page layer.
   263 */
   265 */
   264 bool HsIdleWidget::eventFilter(QObject *object, QEvent *event)
   266 bool HsIdleWidget::eventFilter(QObject *object, QEvent *event)
   265 {
   267 {
   266     Q_UNUSED(object)
   268     Q_UNUSED(object)
   267 
   269 
   268     if (HbInputMethod::activeInputMethod() &&
   270     if (HbVkbHost::activeVkbHost()) {
   269         HbInputMethod::activeInputMethod()->focusObject()) {
       
   270         setFiltersChildEvents(false);
   271         setFiltersChildEvents(false);
   271         return false;
   272         return false;
   272     }
   273     }
   273 
   274 
   274     bool filtered = false;
   275     bool filtered = false;
   336 
   337 
   337     layout = static_cast<QGraphicsLinearLayout *>(mSceneLayer->layout());
   338     layout = static_cast<QGraphicsLinearLayout *>(mSceneLayer->layout());
   338     HsWallpaper *wallpaper = HsScene::instance()->wallpaper();
   339     HsWallpaper *wallpaper = HsScene::instance()->wallpaper();
   339     layout->addItem(wallpaper);
   340     layout->addItem(wallpaper);
   340            
   341            
   341     mPageIndicator->setItemCount(pages.count());
   342     mPageIndicator->initialize(pages.count(), scene->activePageIndex());    
   342     setActivePage(scene->activePageIndex());
       
   343     showPageIndicator();
   343     showPageIndicator();
   344 
   344 
   345     HsScene::mainWindow()->scene()->installEventFilter(this);
   345     HsScene::mainWindow()->scene()->installEventFilter(this);
   346 }
   346 }
   347 
   347 
   357     QString path = QDir::currentPath();
   357     QString path = QDir::currentPath();
   358 #else
   358 #else
   359     QString path = "c:";
   359     QString path = "c:";
   360 #endif
   360 #endif
   361 
   361 
   362     QString file = path + "/hsresources/" + CONTROL_LAYER_DOCML_FILE;
   362     QString file = path + "/hsresources/" + gControlLayerDocmlName;
   363     QString fallbackPath = QString(":/") + CONTROL_LAYER_DOCML_FILE;
   363     QString fallbackPath = QString(":/") + gControlLayerDocmlName;
   364 
   364 
   365     if (QFile::exists(file)) {
   365     if (QFile::exists(file)) {
   366         loader.load(file, &loaded);
   366         loader.load(file, &loaded);
   367         if (!loaded) {
   367         if (!loaded) {
   368             loader.load(fallbackPath, &loaded);
   368             loader.load(fallbackPath, &loaded);
   370     } else {
   370     } else {
   371         loader.load(fallbackPath, &loaded);       
   371         loader.load(fallbackPath, &loaded);       
   372     }
   372     }
   373 
   373 
   374     if (loaded) {
   374     if (loaded) {
   375         mControlLayer = qobject_cast<HbWidget *>(loader.findWidget(CONTROL_LAYER));
   375         mControlLayer = qobject_cast<HbWidget *>(loader.findWidget(gControlLayerName));
   376         mControlLayer->setZValue(2);
   376         mControlLayer->setZValue(2);
   377         mControlLayer->setParentItem(this);
   377         mControlLayer->setParentItem(this);
   378 
   378 
   379         mTrashBin = qobject_cast<HsTrashBinWidget *>(loader.findWidget(TRASH_BIN));
   379         mTrashBin = qobject_cast<HsTrashBinWidget *>(loader.findWidget(gTrashBinName));
   380         mTrashBin->setZValue(1e6);
   380         mTrashBin->setZValue(1e6);
   381 
   381 
   382         mPageIndicator = qobject_cast<HsPageIndicator *>(loader.findWidget(PAGE_INDICATOR));
   382         mPageIndicator = qobject_cast<HsPageIndicator *>(loader.findWidget(gPageIndicatorName));
   383         mPageIndicator->setZValue(1e6);
   383         mPageIndicator->setZValue(1e6);
   384     } else {
   384     } else {
   385         // TODO: Handle error.
   385         // TODO: Handle error.
   386     }
   386     }
   387 }
   387 }
   391     unfocusable and stores the items.
   391     unfocusable and stores the items.
   392 */
   392 */
   393 void HsIdleWidget::setItemsUnfocusable(QGraphicsSceneMouseEvent *event)
   393 void HsIdleWidget::setItemsUnfocusable(QGraphicsSceneMouseEvent *event)
   394 {
   394 {
   395     mFocusableItems.clear();
   395     mFocusableItems.clear();
   396     QList<QGraphicsItem *> items = 
   396 
   397         HsScene::mainWindow()->scene()->items(event->scenePos());
   397     if (!scene()) {
       
   398         return;
       
   399     }
       
   400 
       
   401     QList<QGraphicsItem *> items = scene()->items(event->scenePos());
       
   402     if (items.isEmpty()) {
       
   403         return;
       
   404     }
       
   405 
   398     int i = 0;
   406     int i = 0;
   399     while (!mPageLayer->isAncestorOf(items[i++])) {}
   407     for (; i < items.count(); ++i) {
       
   408         if (mPageLayer->isAncestorOf(items[i])) {
       
   409             ++i;
       
   410             break;
       
   411         }
       
   412     }
       
   413  
   400     HsPage *page = HsScene::instance()->activePage();
   414     HsPage *page = HsScene::instance()->activePage();
   401     QList<HsWidgetHost *> widgets = page->widgets();
   415     QList<HsWidgetHost *> widgets = page->widgets();
       
   416     
   402     for (; i < items.count(); ++i) {
   417     for (; i < items.count(); ++i) {
   403         QGraphicsItem *item = items.at(i);
   418         QGraphicsItem *item = items.at(i);
   404         if (page->isAncestorOf(item)) {
   419         if (page->isAncestorOf(item)) {
   405             foreach (HsWidgetHost *widget, widgets) {
   420             foreach (HsWidgetHost *widget, widgets) {
   406                 if ((item == widget || widget->isAncestorOf(item))&& item->isEnabled() && (item->flags() & QGraphicsItem::ItemIsFocusable)) {
   421                 if ((item == widget || widget->isAncestorOf(item))&& item->isEnabled() && (item->flags() & QGraphicsItem::ItemIsFocusable)) {
   407                     if (!item->isWidget() || static_cast<QGraphicsWidget*>(item)->focusPolicy() & Qt::ClickFocus) {
   422                     if (!item->isWidget() || static_cast<QGraphicsWidget *>(item)->focusPolicy() & Qt::ClickFocus) {
   408                         item->setFlag(QGraphicsItem::ItemIsFocusable, false);
   423                         item->setFlag(QGraphicsItem::ItemIsFocusable, false);
   409                         mFocusableItems.append(item);
   424                         mFocusableItems.append(item);
   410                     }
   425                     }
   411                 }
   426                 }
   412             }
   427             }