phoneplugins/infowidgetplugin/infowidget/src/infowidget.cpp
changeset 56 5bcb308bd24d
parent 46 bc5a64e5bc3c
equal deleted inserted replaced
46:bc5a64e5bc3c 56:5bcb308bd24d
    25 #include <hbcolorscheme.h>
    25 #include <hbcolorscheme.h>
    26 #include <hbdialog.h>
    26 #include <hbdialog.h>
    27 #include <hbmessagebox.h>
    27 #include <hbmessagebox.h>
    28 #include <hbframedrawer.h>
    28 #include <hbframedrawer.h>
    29 #include <hbframeitem.h>
    29 #include <hbframeitem.h>
       
    30 #include <hbtapgesture.h>
    30 #include <QPainter>
    31 #include <QPainter>
    31 #include <QPainterPath>
    32 #include <QPainterPath>
    32 #include <QBrush>
    33 #include <QBrush>
    33 #include <QGraphicsLinearLayout>
    34 #include <QGraphicsLinearLayout>
    34 #include <QApplication>
    35 #include <QApplication>
    35 #include <QLocale>
    36 #include <QLocale>
    36 #include <QTranslator>
       
    37 #include <QScopedPointer>
    37 #include <QScopedPointer>
       
    38 #include <QGesture>
    38 #include "infowidgetlogging.h"
    39 #include "infowidgetlogging.h"
    39 #include "infowidgetengine.h"
    40 #include "infowidgetengine.h"
    40 #include "infowidgetlayoutmanager.h"
    41 #include "infowidgetlayoutmanager.h"
    41 #include "infowidgetpreferences.h"
    42 #include "infowidgetpreferences.h"
    42 
    43 
    45   \brief Operator info widget main class. 
    46   \brief Operator info widget main class. 
    46 
    47 
    47    Implements HomeScreen specific slots and 
    48    Implements HomeScreen specific slots and 
    48    graphical representation of the 
    49    graphical representation of the 
    49    Operator Info widget. 
    50    Operator Info widget. 
    50 
       
    51    Derived from HbWidget.
       
    52     
    51     
    53 */
    52 */
    54 
    53 
    55 // Local constants 
    54 // Local constants 
    56 const int INFOWIDGET_DEFAULT_HEIGHT = 100;
    55 const int INFOWIDGET_DEFAULT_HEIGHT = 100;
    57 const int INFOWIDGET_DEFAULT_WIDTH = 200;
    56 const int INFOWIDGET_DEFAULT_WIDTH = 200;
    58 const int INFOWIDGET_MARQUEE_START_DELAY = 5000; 
    57 const int INFOWIDGET_MARQUEE_START_DELAY = 5000; 
    59 const char *TS_FILE_OPERATOR_WIDGET = "operator_widget"; 
       
    60 const char *TS_FILE_COMMON = "common";
       
    61 const char *BACKGROUND_FRAME_NAME = "qtg_fr_hswidget_normal"; 
    58 const char *BACKGROUND_FRAME_NAME = "qtg_fr_hswidget_normal"; 
    62 
    59 
    63 /*!
    60 /*!
    64     Constructor.  
    61     Constructor.  
    65 */
    62 */
    71     m_layoutManager(NULL),
    68     m_layoutManager(NULL),
    72     m_layout(NULL),
    69     m_layout(NULL),
    73     m_backgroundFrameItem(NULL),
    70     m_backgroundFrameItem(NULL),
    74     m_timerId(0),
    71     m_timerId(0),
    75     m_layoutChanging(false),
    72     m_layoutChanging(false),
    76     m_dragEvent(false), 
       
    77     m_initialized(false)
    73     m_initialized(false)
    78 {
    74 {
    79     INSTALL_TRACE_MSG_HANDLER; 
    75     INSTALL_TRACE_MSG_HANDLER; 
    80     DPRINT;
    76     DPRINT;
    81     
    77  
    82     // Localization file loading
       
    83     installTranslator(TS_FILE_OPERATOR_WIDGET);
       
    84     installTranslator(TS_FILE_COMMON);
       
    85 
       
    86     // Create layout & child-widget manager 
    78     // Create layout & child-widget manager 
    87     m_layoutManager.reset(new InfoWidgetLayoutManager);
    79     m_layoutManager.reset(new InfoWidgetLayoutManager);
    88     
    80     
    89     // Create widget engine 
    81     // Create widget engine 
    90     m_engine.reset(new InfoWidgetEngine);
    82     m_engine.reset(new InfoWidgetEngine);
   117     // Ownership of frame drawer is 
   109     // Ownership of frame drawer is 
   118     // transferred for frame item
   110     // transferred for frame item
   119     m_backgroundFrameItem = new HbFrameItem(
   111     m_backgroundFrameItem = new HbFrameItem(
   120             backgroundFrameDrawer.take(), this);  
   112             backgroundFrameDrawer.take(), this);  
   121     
   113     
   122     setBackgroundItem(m_backgroundFrameItem); 
   114     setBackgroundItem(m_backgroundFrameItem);
       
   115     
       
   116     // Listen for tap events 
       
   117     grabGesture(Qt::TapGesture);
   123 }
   118 }
   124 
   119 
   125 /*!
   120 /*!
   126     Destructor.  
   121     Destructor.  
   127 */
   122 */
   129 {
   124 {
   130     DPRINT;
   125     DPRINT;
   131     // Force layout manager to delete widgets 
   126     // Force layout manager to delete widgets 
   132     // before InfoWidget is destroyed   
   127     // before InfoWidget is destroyed   
   133     m_layoutManager->destroyWidgets(); 
   128     m_layoutManager->destroyWidgets(); 
   134     
       
   135     // Remove and delete language translators 
       
   136     removeTranslators(); 
       
   137     UNINSTALL_TRACE_MSG_HANDLER;
   129     UNINSTALL_TRACE_MSG_HANDLER;
   138 }
   130 }
   139 
   131 
   140 /*!
   132 /*!
   141     Called by HS framework, saved preference data
   133     Called by HS framework, saved preference data
   146 {
   138 {
   147     DPRINT; 
   139     DPRINT; 
   148     m_initialized = true; 
   140     m_initialized = true; 
   149     // Initialize preferences from meta-object data
   141     // Initialize preferences from meta-object data
   150     if (!readPersistentPreferences()) {
   142     if (!readPersistentPreferences()) {
   151 
       
   152         // Reading failed, initialize default values  
   143         // Reading failed, initialize default values  
   153         m_preferences->setPreference(InfoWidgetPreferences::DisplaySpn, 
   144         m_preferences->setPreference(InfoWidgetPreferences::DisplaySpn, 
   154                 DISPLAY_SETTING_ON);
   145                 DISPLAY_SETTING_ON);
   155         m_preferences->setPreference(InfoWidgetPreferences::DisplayMcn, 
   146         m_preferences->setPreference(InfoWidgetPreferences::DisplayMcn, 
   156                 DISPLAY_SETTING_ON);
   147                 DISPLAY_SETTING_ON);
   212     Handles timer events.  
   203     Handles timer events.  
   213 */
   204 */
   214 void InfoWidget::timerEvent(QTimerEvent *event)
   205 void InfoWidget::timerEvent(QTimerEvent *event)
   215 {
   206 {
   216     Q_UNUSED(event); 
   207     Q_UNUSED(event); 
   217     
       
   218     if (m_animationState == AnimationStarting) {
   208     if (m_animationState == AnimationStarting) {
   219         // Execute delayed start of marquee animation 
   209         // Execute delayed start of marquee animation 
   220         if (m_animatingItem) {
   210         if (m_animatingItem) {
   221             m_animationState = AnimationOngoing;
   211             m_animationState = AnimationOngoing;
   222             m_animatingItem->startAnimation(); 
   212             m_animatingItem->startAnimation(); 
   228         m_timerId = 0;
   218         m_timerId = 0;
   229     }
   219     }
   230 }
   220 }
   231 
   221 
   232 /*!
   222 /*!
   233     Install widget translator for given translation file.  
       
   234 */
       
   235 bool InfoWidget::installTranslator(QString translationFile)
       
   236 {
       
   237     DPRINT;
       
   238     QString lang = QLocale::system().name();
       
   239     QString path = "z:/resource/qt/translations/";
       
   240     bool translatorLoaded(false);  
       
   241     
       
   242     QScopedPointer<QTranslator> widgetTranslator; 
       
   243     widgetTranslator.reset(new QTranslator);
       
   244     translatorLoaded = widgetTranslator->load(
       
   245             path + translationFile + "_" + lang);
       
   246     if (translatorLoaded) {
       
   247         qApp->installTranslator(widgetTranslator.data());
       
   248         m_translators.append(widgetTranslator.take()); 
       
   249         DPRINT << ": translator installed: " << translationFile; 
       
   250     }
       
   251     return translatorLoaded;
       
   252 }
       
   253 
       
   254 /*!
       
   255     Remove translators. No need to call 
       
   256     QApplication::removeTranslator, 
       
   257     QTranslator object removes itself before deletion.  
       
   258 */
       
   259 void InfoWidget::removeTranslators()
       
   260 {
       
   261     DPRINT;
       
   262     qDeleteAll(m_translators);
       
   263     m_translators.clear();
       
   264 }
       
   265 
       
   266 /*!
       
   267     Returns bounding rect. 
   223     Returns bounding rect. 
   268 */
   224 */
   269 QRectF InfoWidget::boundingRect() const
   225 QRectF InfoWidget::boundingRect() const
   270 {   
   226 {   
   271     return rect();
   227     return rect();
   272 }
   228 }
   273 
   229 
   274 /*!
   230 /*!
   275     Calculate widget size hint based on visible row count.  
   231     Calculate widget size hint based on visible row count.  
   276 */
   232 */
   277 QSizeF InfoWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const   
   233 QSizeF InfoWidget::sizeHint(Qt::SizeHint which, 
       
   234         const QSizeF & constraint) const   
   278 {
   235 {
   279     Q_UNUSED(which);
   236     Q_UNUSED(which);
   280     Q_UNUSED(constraint); 
   237     Q_UNUSED(constraint); 
   281     
   238     
   282     QSizeF requiredSize(
   239     QSizeF requiredSize(
   297         // if widget size is changing
   254         // if widget size is changing
   298         if (size() != requiredSize) {
   255         if (size() != requiredSize) {
   299             m_backgroundFrameItem->resize(requiredSize);
   256             m_backgroundFrameItem->resize(requiredSize);
   300         }
   257         }
   301     }
   258     }
   302     
       
   303     DPRINT << ": returning size: " << requiredSize;
       
   304     return requiredSize; 
   259     return requiredSize; 
   305 }
   260 }
   306 
   261 
   307 /*!
   262 /*!
   308     Returns size polizy for the widget.   
   263     Returns size polizy for the widget.   
   319     Update item visibility based on display preferences.   
   274     Update item visibility based on display preferences.   
   320 */
   275 */
   321 void InfoWidget::updateItemsVisibility()
   276 void InfoWidget::updateItemsVisibility()
   322 {
   277 {
   323     DPRINT; 
   278     DPRINT; 
   324     int layoutRows = 0; 
       
   325     
       
   326     // Update layout according to item visibility settings
       
   327     if (m_preferences->preference(InfoWidgetPreferences::DisplaySpn).compare(
   279     if (m_preferences->preference(InfoWidgetPreferences::DisplaySpn).compare(
   328             DISPLAY_SETTING_ON) == 0) {
   280             DISPLAY_SETTING_OFF) == 0) {
   329         layoutRows++;
       
   330     } else {
       
   331         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSpnMarqueeItem); 
   281         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSpnMarqueeItem); 
   332         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSpnIcon); 
   282         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSpnIcon); 
   333     }
   283     }
   334 
   284     
   335     if (m_preferences->preference(InfoWidgetPreferences::DisplayMcn).compare(
   285     if (m_preferences->preference(InfoWidgetPreferences::DisplayMcn).compare(
   336             DISPLAY_SETTING_ON) == 0) {
   286             DISPLAY_SETTING_OFF) == 0) {
   337         layoutRows++;
       
   338     } else {
       
   339         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleMcnMarqueeItem); 
   287         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleMcnMarqueeItem); 
   340         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleMcnIcon); 
   288         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleMcnIcon); 
   341     }
   289     }
   342     
   290     
   343     if (m_preferences->preference(InfoWidgetPreferences::DisplaySatText).compare(
   291     if (m_preferences->preference(InfoWidgetPreferences::DisplaySatText).compare(
   344             DISPLAY_SETTING_ON) == 0) {
   292             DISPLAY_SETTING_OFF) == 0) {
   345         layoutRows++;
       
   346     } else {
       
   347         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSatMarqueeItem); 
   293         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSatMarqueeItem); 
   348         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSatTextIcon); 
   294         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSatTextIcon); 
   349     }
   295     }
   350     
       
   351     if (m_animatingItems.count() == 0) {
       
   352         m_animatingItem = NULL; 
       
   353     }
       
   354     
       
   355     m_layoutManager->setLayoutRows(layoutRows);
       
   356 }
   296 }
   357 
   297 
   358 /*!
   298 /*!
   359     Layout info display.    
   299     Layout info display.    
   360 */
   300 */
   361 void InfoWidget::layoutInfoDisplay()
   301 void InfoWidget::layoutInfoDisplay()
   362 {  
   302 {  
   363     DPRINT;
   303     DPRINT;
   364     QGraphicsLayout *infoDisplayLayout = 
   304     QGraphicsWidget *infoDisplay = 
   365         m_layoutManager->layoutInfoDisplay(); 
   305         m_layoutManager->layoutInfoDisplay(); 
   366     
   306     if ((!m_layout->count()) && infoDisplay) {
   367     if (!m_layout->count()) {
   307             m_layout->addItem(infoDisplay);
   368         QGraphicsWidget *contentWidget = 
   308         }
   369                 m_layoutManager->contentWidget();
   309 
   370         if (contentWidget) {
       
   371             // Add content widget to main layout 
       
   372             m_layout->addItem(contentWidget);
       
   373         }
       
   374     }
       
   375     updateItemsVisibility(); 
   310     updateItemsVisibility(); 
   376     endChanges();
   311     endChanges();
   377 }
   312 }
   378 
   313 
   379 /*!
   314 /*!
   381 */
   316 */
   382 void InfoWidget::layoutSettingsDialog()
   317 void InfoWidget::layoutSettingsDialog()
   383 {  
   318 {  
   384     DPRINT;
   319     DPRINT;
   385     startChanges();
   320     startChanges();
   386     
   321     HbDialog *settingsDialog =
   387     m_layoutManager->reloadWidgets(InfoWidgetLayoutManager::SettingsDialog); 
   322             qobject_cast<HbDialog *>(
   388     QGraphicsLayout *settingDialogLayout =
   323                     m_layoutManager->layoutSettingsDialog()); 
   389             m_layoutManager->layoutSettingsDialog(); 
   324 
   390     
   325     if (settingsDialog) {
   391     if (settingDialogLayout) {
   326         initializeSettingsDialogItems();
   392         HbDialog *settingsDialog = qobject_cast<HbDialog *>(
   327         settingsDialog->setDismissPolicy(HbDialog::NoDismiss); 
   393                 m_layoutManager->getWidget(InfoWidgetLayoutManager::
   328         settingsDialog->setTimeout(HbDialog::NoTimeout);
   394                 RoleSettingsDialog)); 
   329         settingsDialog->open(this, 
   395 
   330                 SLOT(settingsDialogClosed(HbAction *))); 
   396         if (settingsDialog) {
   331         }
   397             initializeSettingsDialogItems();
       
   398             settingsDialog->setDismissPolicy(HbDialog::NoDismiss); 
       
   399             settingsDialog->setTimeout(HbDialog::NoTimeout);
       
   400             settingsDialog->open(this, 
       
   401                     SLOT(settingsDialogClosed(HbAction *))); 
       
   402             }
       
   403     }    
       
   404 }
   332 }
   405 
   333 
   406 /*!
   334 /*!
   407     Set up initial check box states 
   335     Set up initial check box states 
   408     and connect signals to local slots.  
   336     and connect signals to local slots.  
   457         QString text)
   385         QString text)
   458 {
   386 {
   459     DPRINT; 
   387     DPRINT; 
   460     HbMarqueeItem *marqueeItem = qobject_cast<HbMarqueeItem *>(
   388     HbMarqueeItem *marqueeItem = qobject_cast<HbMarqueeItem *>(
   461             m_layoutManager->getWidget(itemRole));
   389             m_layoutManager->getWidget(itemRole));
   462     
       
   463     if (marqueeItem) {
   390     if (marqueeItem) {
   464         marqueeItem->setText(text);
   391         marqueeItem->setText(text);
   465         marqueeItem->setTextColor( HbColorScheme::color(
   392         marqueeItem->setTextColor( HbColorScheme::color(
   466                 "qtc_hs_list_item_title_normal"));
   393                 "qtc_hs_list_item_title_normal"));
   467         
   394         
   535     DWARNING << ": operation: " << operation << 
   462     DWARNING << ": operation: " << operation << 
   536                 " error: " << errorCode; 
   463                 " error: " << errorCode; 
   537 }
   464 }
   538 
   465 
   539 /*!
   466 /*!
   540     Mouse press handler. 
   467     Tap gesture handler.   
   541 */
   468 */
   542 void InfoWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
   469 void InfoWidget::gestureEvent(QGestureEvent *event)
   543 {
   470 {
   544     Q_UNUSED(event);
   471 HbTapGesture *gesture = qobject_cast<HbTapGesture *>(
   545     // Clear flag 
   472         event->gesture(Qt::TapGesture));
   546     m_dragEvent = false; 
   473 
   547 }
   474 if(!gesture)return;
   548 
   475 switch (gesture->state()) {
   549 /*!
   476     case Qt::GestureFinished:
   550     Mouse release handler.  
   477         if (gesture->tapStyleHint() == HbTapGesture::Tap) {
   551 */
   478             if (m_layoutManager->currentDisplayRole() == 
   552 void InfoWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   479                             InfoWidgetLayoutManager::InfoDisplay) {
   553 {
   480                   DPRINT << ": layout and display settings dialog";
   554     Q_UNUSED(event);
   481                   layoutSettingsDialog();
   555     // If widget wasn't dragged 
   482               } 
   556     // layout and open settings dialog
   483         }
   557     if ((!m_dragEvent) && 
   484     break;
   558           m_layoutManager->currentDisplayRole() == 
   485     
   559                   InfoWidgetLayoutManager::InfoDisplay) {
   486     default: 
   560         DPRINT << ": layout and display settings dialog";
   487         break;
   561         layoutSettingsDialog();
   488     }
   562     } 
       
   563     
       
   564     // Clear flag 
       
   565     m_dragEvent = false; 
       
   566 }
       
   567 
       
   568 /*!
       
   569     Mouse move handler.  
       
   570 */
       
   571 void InfoWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
       
   572 {
       
   573     Q_UNUSED(event);
       
   574     // Mouse is moving 
       
   575     // after mouse press event
       
   576     m_dragEvent = true; 
       
   577 }
   489 }
   578 
   490 
   579 /*!
   491 /*!
   580     Slot for handling Spn display setting change.  
   492     Slot for handling Spn display setting change.  
   581 */
   493 */
   795     when the settings dialog is closed with Ok action.   
   707     when the settings dialog is closed with Ok action.   
   796 */
   708 */
   797 void InfoWidget::settingsEditingFinished()
   709 void InfoWidget::settingsEditingFinished()
   798 {
   710 {
   799     DPRINT;
   711     DPRINT;
   800      
       
   801     if (m_preferences->validate()) {
   712     if (m_preferences->validate()) {
   802 
   713 
   803         // Signal HS framework to store Meta-object 
   714         // Signal HS framework to store Meta-object 
   804         // preferences if preferences have changed. 
   715         // preferences if preferences have changed. 
   805         if (m_preferences->storePreferences()) {
   716         if (m_preferences->storePreferences()) {
   807                     m_preferences->preferenceNames());
   718                     m_preferences->preferenceNames());
   808             }
   719             }
   809         
   720         
   810         // Visible item configuration changed, reload 
   721         // Visible item configuration changed, reload 
   811         // widgets. Restores deleted items.  
   722         // widgets. Restores deleted items.  
   812         m_layoutManager->reloadWidgets(
   723         m_layoutManager->loadWidgets(
   813                 InfoWidgetLayoutManager::InfoDisplay);
   724                 InfoWidgetLayoutManager::InfoDisplay);
   814         m_layoutManager->removeWidget(
   725         m_layoutManager->removeWidget(
   815                 InfoWidgetLayoutManager::RoleSettingsDialog,
   726                 InfoWidgetLayoutManager::RoleSettingsDialog,
   816                 true);
   727                 true);
   817         
   728         
   832 void InfoWidget::settingsEditingCancelled()
   743 void InfoWidget::settingsEditingCancelled()
   833 {
   744 {
   834     DPRINT;
   745     DPRINT;
   835     m_preferences->restorePreferences(); 
   746     m_preferences->restorePreferences(); 
   836     
   747     
   837     m_layoutManager->reloadWidgets(
   748     m_layoutManager->loadWidgets(
   838             InfoWidgetLayoutManager::InfoDisplay);
   749             InfoWidgetLayoutManager::InfoDisplay);
   839     m_layoutManager->removeWidget(
   750     m_layoutManager->removeWidget(
   840             InfoWidgetLayoutManager::RoleSettingsDialog,
   751             InfoWidgetLayoutManager::RoleSettingsDialog,
   841             true); 
   752             true); 
   842 }
   753 }
   885     updateInfoDisplay();
   796     updateInfoDisplay();
   886     m_layoutChanging = false;
   797     m_layoutChanging = false;
   887 }
   798 }
   888 
   799 
   889 /*!
   800 /*!
   890    \reimp
   801    Listen for theme change event. 
   891 */
   802 */
   892 void InfoWidget::changeEvent(QEvent *event)
   803 void InfoWidget::changeEvent(QEvent *event)
   893 {
   804 {
   894    DPRINT;
   805    DPRINT;
   895    if (event->type() == HbEvent::ThemeChanged) {
   806    if (event->type() == HbEvent::ThemeChanged) {
   911    }
   822    }
   912 }
   823 }
   913 
   824 
   914 /*!
   825 /*!
   915    Start marquee animations. 
   826    Start marquee animations. 
   916    First find existing marquee items and 
       
   917    enable marquee sequence. 
       
   918 */
   827 */
   919 bool InfoWidget::startMarquees()
   828 bool InfoWidget::startMarquees()
   920 {  
   829 {  
   921     DPRINT;
   830     DPRINT;
   922     bool started(true); 
   831     bool started(true); 
   990     m_animatingItem = NULL; 
   899     m_animatingItem = NULL; 
   991 }
   900 }
   992 
   901 
   993 /*!
   902 /*!
   994    Starts marquee animation for 
   903    Starts marquee animation for 
   995    next item in sequence.  
   904    next item in sequence. Called if there are 
       
   905    multiple text items needing marquee and animation 
       
   906    start/stop logic is needed.    
   996 */
   907 */
   997 void InfoWidget::marqueeNext()
   908 void InfoWidget::marqueeNext()
   998 {  
   909 {  
   999     DPRINT;
   910     DPRINT;
  1000     if (m_animationState == AnimationOngoing) {
   911     if (m_animationState == AnimationOngoing) {