phoneplugins/infowidgetplugin/infowidget/src/infowidget.cpp
changeset 56 5bcb308bd24d
parent 46 bc5a64e5bc3c
--- a/phoneplugins/infowidgetplugin/infowidget/src/infowidget.cpp	Tue Jul 06 14:15:47 2010 +0300
+++ b/phoneplugins/infowidgetplugin/infowidget/src/infowidget.cpp	Wed Aug 18 09:48:26 2010 +0300
@@ -27,14 +27,15 @@
 #include <hbmessagebox.h>
 #include <hbframedrawer.h>
 #include <hbframeitem.h>
+#include <hbtapgesture.h>
 #include <QPainter>
 #include <QPainterPath>
 #include <QBrush>
 #include <QGraphicsLinearLayout>
 #include <QApplication>
 #include <QLocale>
-#include <QTranslator>
 #include <QScopedPointer>
+#include <QGesture>
 #include "infowidgetlogging.h"
 #include "infowidgetengine.h"
 #include "infowidgetlayoutmanager.h"
@@ -47,8 +48,6 @@
    Implements HomeScreen specific slots and 
    graphical representation of the 
    Operator Info widget. 
-
-   Derived from HbWidget.
     
 */
 
@@ -56,8 +55,6 @@
 const int INFOWIDGET_DEFAULT_HEIGHT = 100;
 const int INFOWIDGET_DEFAULT_WIDTH = 200;
 const int INFOWIDGET_MARQUEE_START_DELAY = 5000; 
-const char *TS_FILE_OPERATOR_WIDGET = "operator_widget"; 
-const char *TS_FILE_COMMON = "common";
 const char *BACKGROUND_FRAME_NAME = "qtg_fr_hswidget_normal"; 
 
 /*!
@@ -73,16 +70,11 @@
     m_backgroundFrameItem(NULL),
     m_timerId(0),
     m_layoutChanging(false),
-    m_dragEvent(false), 
     m_initialized(false)
 {
     INSTALL_TRACE_MSG_HANDLER; 
     DPRINT;
-    
-    // Localization file loading
-    installTranslator(TS_FILE_OPERATOR_WIDGET);
-    installTranslator(TS_FILE_COMMON);
-
+ 
     // Create layout & child-widget manager 
     m_layoutManager.reset(new InfoWidgetLayoutManager);
     
@@ -119,7 +111,10 @@
     m_backgroundFrameItem = new HbFrameItem(
             backgroundFrameDrawer.take(), this);  
     
-    setBackgroundItem(m_backgroundFrameItem); 
+    setBackgroundItem(m_backgroundFrameItem);
+    
+    // Listen for tap events 
+    grabGesture(Qt::TapGesture);
 }
 
 /*!
@@ -131,9 +126,6 @@
     // Force layout manager to delete widgets 
     // before InfoWidget is destroyed   
     m_layoutManager->destroyWidgets(); 
-    
-    // Remove and delete language translators 
-    removeTranslators(); 
     UNINSTALL_TRACE_MSG_HANDLER;
 }
 
@@ -148,7 +140,6 @@
     m_initialized = true; 
     // Initialize preferences from meta-object data
     if (!readPersistentPreferences()) {
-
         // Reading failed, initialize default values  
         m_preferences->setPreference(InfoWidgetPreferences::DisplaySpn, 
                 DISPLAY_SETTING_ON);
@@ -214,7 +205,6 @@
 void InfoWidget::timerEvent(QTimerEvent *event)
 {
     Q_UNUSED(event); 
-    
     if (m_animationState == AnimationStarting) {
         // Execute delayed start of marquee animation 
         if (m_animatingItem) {
@@ -230,40 +220,6 @@
 }
 
 /*!
-    Install widget translator for given translation file.  
-*/
-bool InfoWidget::installTranslator(QString translationFile)
-{
-    DPRINT;
-    QString lang = QLocale::system().name();
-    QString path = "z:/resource/qt/translations/";
-    bool translatorLoaded(false);  
-    
-    QScopedPointer<QTranslator> widgetTranslator; 
-    widgetTranslator.reset(new QTranslator);
-    translatorLoaded = widgetTranslator->load(
-            path + translationFile + "_" + lang);
-    if (translatorLoaded) {
-        qApp->installTranslator(widgetTranslator.data());
-        m_translators.append(widgetTranslator.take()); 
-        DPRINT << ": translator installed: " << translationFile; 
-    }
-    return translatorLoaded;
-}
-
-/*!
-    Remove translators. No need to call 
-    QApplication::removeTranslator, 
-    QTranslator object removes itself before deletion.  
-*/
-void InfoWidget::removeTranslators()
-{
-    DPRINT;
-    qDeleteAll(m_translators);
-    m_translators.clear();
-}
-
-/*!
     Returns bounding rect. 
 */
 QRectF InfoWidget::boundingRect() const
@@ -274,7 +230,8 @@
 /*!
     Calculate widget size hint based on visible row count.  
 */
-QSizeF InfoWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const   
+QSizeF InfoWidget::sizeHint(Qt::SizeHint which, 
+        const QSizeF & constraint) const   
 {
     Q_UNUSED(which);
     Q_UNUSED(constraint); 
@@ -299,8 +256,6 @@
             m_backgroundFrameItem->resize(requiredSize);
         }
     }
-    
-    DPRINT << ": returning size: " << requiredSize;
     return requiredSize; 
 }
 
@@ -321,38 +276,23 @@
 void InfoWidget::updateItemsVisibility()
 {
     DPRINT; 
-    int layoutRows = 0; 
-    
-    // Update layout according to item visibility settings
     if (m_preferences->preference(InfoWidgetPreferences::DisplaySpn).compare(
-            DISPLAY_SETTING_ON) == 0) {
-        layoutRows++;
-    } else {
+            DISPLAY_SETTING_OFF) == 0) {
         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSpnMarqueeItem); 
         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSpnIcon); 
     }
-
+    
     if (m_preferences->preference(InfoWidgetPreferences::DisplayMcn).compare(
-            DISPLAY_SETTING_ON) == 0) {
-        layoutRows++;
-    } else {
+            DISPLAY_SETTING_OFF) == 0) {
         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleMcnMarqueeItem); 
         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleMcnIcon); 
     }
     
     if (m_preferences->preference(InfoWidgetPreferences::DisplaySatText).compare(
-            DISPLAY_SETTING_ON) == 0) {
-        layoutRows++;
-    } else {
+            DISPLAY_SETTING_OFF) == 0) {
         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSatMarqueeItem); 
         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSatTextIcon); 
     }
-    
-    if (m_animatingItems.count() == 0) {
-        m_animatingItem = NULL; 
-    }
-    
-    m_layoutManager->setLayoutRows(layoutRows);
 }
 
 /*!
@@ -361,17 +301,12 @@
 void InfoWidget::layoutInfoDisplay()
 {  
     DPRINT;
-    QGraphicsLayout *infoDisplayLayout = 
+    QGraphicsWidget *infoDisplay = 
         m_layoutManager->layoutInfoDisplay(); 
-    
-    if (!m_layout->count()) {
-        QGraphicsWidget *contentWidget = 
-                m_layoutManager->contentWidget();
-        if (contentWidget) {
-            // Add content widget to main layout 
-            m_layout->addItem(contentWidget);
+    if ((!m_layout->count()) && infoDisplay) {
+            m_layout->addItem(infoDisplay);
         }
-    }
+
     updateItemsVisibility(); 
     endChanges();
 }
@@ -383,24 +318,17 @@
 {  
     DPRINT;
     startChanges();
-    
-    m_layoutManager->reloadWidgets(InfoWidgetLayoutManager::SettingsDialog); 
-    QGraphicsLayout *settingDialogLayout =
-            m_layoutManager->layoutSettingsDialog(); 
-    
-    if (settingDialogLayout) {
-        HbDialog *settingsDialog = qobject_cast<HbDialog *>(
-                m_layoutManager->getWidget(InfoWidgetLayoutManager::
-                RoleSettingsDialog)); 
+    HbDialog *settingsDialog =
+            qobject_cast<HbDialog *>(
+                    m_layoutManager->layoutSettingsDialog()); 
 
-        if (settingsDialog) {
-            initializeSettingsDialogItems();
-            settingsDialog->setDismissPolicy(HbDialog::NoDismiss); 
-            settingsDialog->setTimeout(HbDialog::NoTimeout);
-            settingsDialog->open(this, 
-                    SLOT(settingsDialogClosed(HbAction *))); 
-            }
-    }    
+    if (settingsDialog) {
+        initializeSettingsDialogItems();
+        settingsDialog->setDismissPolicy(HbDialog::NoDismiss); 
+        settingsDialog->setTimeout(HbDialog::NoTimeout);
+        settingsDialog->open(this, 
+                SLOT(settingsDialogClosed(HbAction *))); 
+        }
 }
 
 /*!
@@ -459,7 +387,6 @@
     DPRINT; 
     HbMarqueeItem *marqueeItem = qobject_cast<HbMarqueeItem *>(
             m_layoutManager->getWidget(itemRole));
-    
     if (marqueeItem) {
         marqueeItem->setText(text);
         marqueeItem->setTextColor( HbColorScheme::color(
@@ -537,43 +464,28 @@
 }
 
 /*!
-    Mouse press handler. 
+    Tap gesture handler.   
 */
-void InfoWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
-{
-    Q_UNUSED(event);
-    // Clear flag 
-    m_dragEvent = false; 
-}
-
-/*!
-    Mouse release handler.  
-*/
-void InfoWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
+void InfoWidget::gestureEvent(QGestureEvent *event)
 {
-    Q_UNUSED(event);
-    // If widget wasn't dragged 
-    // layout and open settings dialog
-    if ((!m_dragEvent) && 
-          m_layoutManager->currentDisplayRole() == 
-                  InfoWidgetLayoutManager::InfoDisplay) {
-        DPRINT << ": layout and display settings dialog";
-        layoutSettingsDialog();
-    } 
+HbTapGesture *gesture = qobject_cast<HbTapGesture *>(
+        event->gesture(Qt::TapGesture));
+
+if(!gesture)return;
+switch (gesture->state()) {
+    case Qt::GestureFinished:
+        if (gesture->tapStyleHint() == HbTapGesture::Tap) {
+            if (m_layoutManager->currentDisplayRole() == 
+                            InfoWidgetLayoutManager::InfoDisplay) {
+                  DPRINT << ": layout and display settings dialog";
+                  layoutSettingsDialog();
+              } 
+        }
+    break;
     
-    // Clear flag 
-    m_dragEvent = false; 
-}
-
-/*!
-    Mouse move handler.  
-*/
-void InfoWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
-{
-    Q_UNUSED(event);
-    // Mouse is moving 
-    // after mouse press event
-    m_dragEvent = true; 
+    default: 
+        break;
+    }
 }
 
 /*!
@@ -797,7 +709,6 @@
 void InfoWidget::settingsEditingFinished()
 {
     DPRINT;
-     
     if (m_preferences->validate()) {
 
         // Signal HS framework to store Meta-object 
@@ -809,7 +720,7 @@
         
         // Visible item configuration changed, reload 
         // widgets. Restores deleted items.  
-        m_layoutManager->reloadWidgets(
+        m_layoutManager->loadWidgets(
                 InfoWidgetLayoutManager::InfoDisplay);
         m_layoutManager->removeWidget(
                 InfoWidgetLayoutManager::RoleSettingsDialog,
@@ -834,7 +745,7 @@
     DPRINT;
     m_preferences->restorePreferences(); 
     
-    m_layoutManager->reloadWidgets(
+    m_layoutManager->loadWidgets(
             InfoWidgetLayoutManager::InfoDisplay);
     m_layoutManager->removeWidget(
             InfoWidgetLayoutManager::RoleSettingsDialog,
@@ -887,7 +798,7 @@
 }
 
 /*!
-   \reimp
+   Listen for theme change event. 
 */
 void InfoWidget::changeEvent(QEvent *event)
 {
@@ -913,8 +824,6 @@
 
 /*!
    Start marquee animations. 
-   First find existing marquee items and 
-   enable marquee sequence. 
 */
 bool InfoWidget::startMarquees()
 {  
@@ -992,7 +901,9 @@
 
 /*!
    Starts marquee animation for 
-   next item in sequence.  
+   next item in sequence. Called if there are 
+   multiple text items needing marquee and animation 
+   start/stop logic is needed.    
 */
 void InfoWidget::marqueeNext()
 {