phoneplugins/infowidgetplugin/infowidget/src/infowidget.cpp
changeset 45 6b911d05207e
child 46 bc5a64e5bc3c
equal deleted inserted replaced
37:ba76fc04e6c2 45:6b911d05207e
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  *
       
    16  */
       
    17 
       
    18 #include "infowidget.h"
       
    19 #include <hbiconitem.h>
       
    20 #include <hbmarqueeitem.h>
       
    21 #include <hbfontspec.h>
       
    22 #include <hbaction.h>
       
    23 #include <hbcheckbox.h>
       
    24 #include <hbevent.h>
       
    25 #include <hbcolorscheme.h>
       
    26 #include <hbdialog.h>
       
    27 #include <hbmessagebox.h>
       
    28 #include <hbframedrawer.h>
       
    29 #include <hbframeitem.h>
       
    30 #include <QPainter>
       
    31 #include <QPainterPath>
       
    32 #include <QBrush>
       
    33 #include <QGraphicsLinearLayout>
       
    34 #include <QApplication>
       
    35 #include <QLocale>
       
    36 #include <QTranslator>
       
    37 #include <QScopedPointer>
       
    38 #include "infowidgetlogging.h"
       
    39 #include "infowidgetengine.h"
       
    40 #include "infowidgetlayoutmanager.h"
       
    41 #include "infowidgetpreferences.h"
       
    42 
       
    43 /*!
       
    44   \class InfoWidget
       
    45   \brief Operator info widget main class. 
       
    46 
       
    47    Implements HomeScreen specific slots and 
       
    48    graphical representation of the 
       
    49    Operator Info widget. 
       
    50 
       
    51    Derived from HbWidget.
       
    52     
       
    53 */
       
    54 
       
    55 // Local constants 
       
    56 const int INFOWIDGET_DEFAULT_HEIGHT = 100;
       
    57 const int INFOWIDGET_DEFAULT_WIDTH = 200;
       
    58 const char *TS_FILE_OPERATOR_WIDGET = "operator_widget"; 
       
    59 const char *TS_FILE_COMMON = "common";
       
    60 const char *BACKGROUND_FRAME_NAME = "qtg_fr_hswidget_normal"; 
       
    61 
       
    62 /*!
       
    63     InfoWidget::InfoWidget() 
       
    64 */
       
    65 InfoWidget::InfoWidget(QGraphicsItem* parent, Qt::WindowFlags flags)
       
    66     : HbWidget(parent, flags),
       
    67     m_animationState(AnimationIdle), 
       
    68     m_engine(NULL), 
       
    69     m_preferences(NULL),
       
    70     m_layoutManager(NULL),
       
    71     m_layout(NULL),
       
    72     m_backgroundFrameItem(NULL),
       
    73     m_timerId(0),
       
    74     m_layoutChanging(false),
       
    75     m_dragEvent(false), 
       
    76     m_initialized(false)
       
    77 {
       
    78     INSTALL_TRACE_MSG_HANDLER; 
       
    79     
       
    80     DPRINT << ": IN";
       
    81     
       
    82     // Localization file loading
       
    83     installTranslator(TS_FILE_OPERATOR_WIDGET);
       
    84     installTranslator(TS_FILE_COMMON);
       
    85 
       
    86     // Create layout & child-widget manager 
       
    87     m_layoutManager.reset(new InfoWidgetLayoutManager);
       
    88     
       
    89     // Create widget engine 
       
    90     m_engine.reset(new InfoWidgetEngine);
       
    91     
       
    92     // Create preference store and start listening signal(s) 
       
    93     m_preferences.reset(new InfoWidgetPreferences);
       
    94     QObject::connect(m_preferences.data(), 
       
    95             SIGNAL(preferencesChanged(InfoWidgetPreferences::Options)),
       
    96                 m_engine.data(), 
       
    97             SLOT(handlePreferencesChanged(
       
    98                 InfoWidgetPreferences::Options)));
       
    99 
       
   100     // Setup widget main layout 
       
   101     m_layout = new QGraphicsLinearLayout;    
       
   102     m_layout->setSpacing(0); 
       
   103     m_layout->setContentsMargins(0,0,0,0); 
       
   104     setLayout(m_layout);
       
   105   
       
   106     // Create and set background frame drawer
       
   107     QScopedPointer<HbFrameDrawer> backgroundFrameDrawer(
       
   108             new HbFrameDrawer(
       
   109                     BACKGROUND_FRAME_NAME, 
       
   110                     HbFrameDrawer::NinePieces));
       
   111     Q_ASSERT(!backgroundFrameDrawer.isNull()); 
       
   112     
       
   113     // Set widget initial size
       
   114     resize(INFOWIDGET_DEFAULT_WIDTH,
       
   115            INFOWIDGET_DEFAULT_HEIGHT); 
       
   116 
       
   117     // Ownership of frame drawer is 
       
   118     // transferred for frame item
       
   119     m_backgroundFrameItem = new HbFrameItem(
       
   120             backgroundFrameDrawer.take(), this);  
       
   121     
       
   122     setBackgroundItem(m_backgroundFrameItem); 
       
   123 
       
   124     DPRINT << ": OUT";
       
   125 }
       
   126 
       
   127 /*!
       
   128     InfoWidget::~InfoWidget() 
       
   129 */
       
   130 InfoWidget::~InfoWidget()
       
   131 {
       
   132     DPRINT << ": IN";
       
   133     
       
   134     // Force layout manager to delete widgets 
       
   135     // before InfoWidget is destroyed   
       
   136     m_layoutManager->destroyWidgets(); 
       
   137     
       
   138     // Remove and delete language translators 
       
   139     removeTranslators(); 
       
   140     
       
   141     DPRINT << ": OUT"; 
       
   142     UNINSTALL_TRACE_MSG_HANDLER;
       
   143 }
       
   144 
       
   145 /*!
       
   146     InfoWidget::onInitialize()
       
   147     
       
   148     Called by HS framework, saved preference data
       
   149     is available when onInitialize() is called and 
       
   150     meta-object data reading should be done here      
       
   151 */
       
   152 void InfoWidget::onInitialize()
       
   153 {
       
   154     DPRINT << ": IN";
       
   155     
       
   156     m_initialized = true; 
       
   157     
       
   158     // Initialize preferences from meta-object data
       
   159     if (!readPersistentPreferences()) {
       
   160 
       
   161         // Reading failed, initialize default values  
       
   162         m_preferences->setPreference(InfoWidgetPreferences::DisplaySpn, 
       
   163                 DISPLAY_SETTING_ON);
       
   164         m_preferences->setPreference(InfoWidgetPreferences::DisplayMcn, 
       
   165                 DISPLAY_SETTING_ON);
       
   166         m_preferences->setPreference(InfoWidgetPreferences::DisplaySatText, 
       
   167                 DISPLAY_SETTING_ON);
       
   168     } 
       
   169     m_preferences->storePreferences(); 
       
   170     
       
   171     // Layout components 
       
   172     layoutInfoDisplay();
       
   173     
       
   174     // Update background frame size  
       
   175     m_backgroundFrameItem->resize(size());
       
   176     
       
   177     // Listen for model changes 
       
   178     QObject::connect(m_engine.data(), SIGNAL(modelChanged()), 
       
   179             this, SLOT(readModel()), Qt::UniqueConnection); 
       
   180     
       
   181     DPRINT << ": OUT";
       
   182 }
       
   183 
       
   184 /*!
       
   185     InfoWidget::onUninitialize() 
       
   186 */
       
   187 void InfoWidget::onUninitialize()
       
   188 {
       
   189     DPRINT << ": IN";
       
   190     stopMarquees();
       
   191     m_initialized = false; 
       
   192     m_engine->suspend();
       
   193     DPRINT << ": OUT";
       
   194 }
       
   195 
       
   196 /*!
       
   197     InfoWidget::onShow() 
       
   198 */
       
   199 void InfoWidget::onShow()
       
   200 {
       
   201     DPRINT;
       
   202     if (m_initialized) { 
       
   203         m_engine->resume();
       
   204         updateInfoDisplay(); 
       
   205     }
       
   206 }
       
   207 
       
   208 /*!
       
   209     InfoWidget::onHide() 
       
   210 */
       
   211 void InfoWidget::onHide()
       
   212 {
       
   213     DPRINT;
       
   214     if (m_initialized) { 
       
   215         m_engine->suspend();
       
   216         stopMarquees(); 
       
   217     }
       
   218 }
       
   219 
       
   220 /*!
       
   221     InfoWidget::timerEvent() 
       
   222 */
       
   223 void InfoWidget::timerEvent(QTimerEvent *event)
       
   224 {
       
   225     Q_UNUSED(event); 
       
   226     
       
   227     if (m_animationState == AnimationStarting) {
       
   228         // Execute delayed start of marquee animation 
       
   229         if (m_animatingItem) {
       
   230             m_animationState = AnimationOngoing;
       
   231             m_animatingItem->startAnimation(); 
       
   232         } 
       
   233     }
       
   234     
       
   235     if (m_timerId) {
       
   236         killTimer(m_timerId);
       
   237         m_timerId = 0;
       
   238     }
       
   239 }
       
   240 
       
   241 /*!
       
   242     InfoWidget::installTranslator() 
       
   243 */
       
   244 bool InfoWidget::installTranslator(QString translationFile)
       
   245 {
       
   246     DPRINT << ": IN";
       
   247 
       
   248     QString lang = QLocale::system().name();
       
   249     QString path = "z:/resource/qt/translations/";
       
   250     bool translatorLoaded(false);  
       
   251     
       
   252     QScopedPointer<QTranslator> widgetTranslator; 
       
   253     widgetTranslator.reset(new QTranslator);
       
   254     translatorLoaded = widgetTranslator->load(
       
   255             path + translationFile + "_" + lang);
       
   256     if (translatorLoaded) {
       
   257         qApp->installTranslator(widgetTranslator.data());
       
   258         m_translators.append(widgetTranslator.take()); 
       
   259         DPRINT << ": translator installed: " << translationFile; 
       
   260     }
       
   261     
       
   262     DPRINT << ": OUT";
       
   263     return translatorLoaded;
       
   264 }
       
   265 
       
   266 /*!
       
   267     InfoWidget::removeTranslators()
       
   268     
       
   269     Remove translators from qApp and delete objects 
       
   270 */
       
   271 void InfoWidget::removeTranslators()
       
   272 {
       
   273     DPRINT << ": IN";
       
   274 
       
   275     foreach (QTranslator *translator, m_translators) {
       
   276         qApp->removeTranslator(translator);
       
   277     }    
       
   278     qDeleteAll(m_translators);
       
   279     m_translators.clear();
       
   280     
       
   281     DPRINT << ": OUT";
       
   282 }
       
   283 
       
   284 /*!
       
   285     InfoWidget::boundingRect() 
       
   286 */
       
   287 QRectF InfoWidget::boundingRect() const
       
   288 {   
       
   289     return rect();
       
   290 }
       
   291 
       
   292 /*!
       
   293     InfoWidget::sizeHint() 
       
   294     
       
   295     Calculate size hint based on visible rows count 
       
   296 */
       
   297 QSizeF InfoWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const   
       
   298 {
       
   299     Q_UNUSED(which);
       
   300     Q_UNUSED(constraint); 
       
   301     
       
   302     QSizeF requiredSize(
       
   303             INFOWIDGET_DEFAULT_WIDTH,
       
   304             INFOWIDGET_DEFAULT_HEIGHT);
       
   305     
       
   306     if (m_initialized) { 
       
   307         // Read size hint from docml content
       
   308         requiredSize = m_layoutManager->contentWidget()->minimumSize();
       
   309         // Height according number of rows, if 0 or 1 row use minimum size
       
   310         int rowCount = m_preferences->visibleItemCount();
       
   311         if (1 < rowCount) {
       
   312                 requiredSize.rheight() += (rowCount-1)*
       
   313                         m_layoutManager->layoutRowHeight();
       
   314         }
       
   315         
       
   316         // Update background frame size 
       
   317         // if widget size is changing
       
   318         if (size() != requiredSize) {
       
   319             m_backgroundFrameItem->resize(requiredSize);
       
   320         }
       
   321     }
       
   322     
       
   323     DPRINT << ": returning size: " << requiredSize;
       
   324     return requiredSize; 
       
   325 }
       
   326 
       
   327 /*!
       
   328     InfoWidget::sizePolicy() 
       
   329 */
       
   330 QSizePolicy InfoWidget::sizePolicy () const 
       
   331 {
       
   332     DPRINT;
       
   333     return QSizePolicy(
       
   334             QSizePolicy::Fixed, 
       
   335             QSizePolicy::Fixed); 
       
   336 }
       
   337 
       
   338 /*!
       
   339     InfoWidget::updateItemsVisibility() 
       
   340 */
       
   341 void InfoWidget::updateItemsVisibility()
       
   342 {
       
   343     DPRINT <<": IN"; 
       
   344     int layoutRows = 0; 
       
   345     QList<QGraphicsWidget *> widgetsToHide; 
       
   346     
       
   347     // Update layout according to item visibility settings
       
   348     if (m_preferences->preference(InfoWidgetPreferences::DisplaySpn).compare(
       
   349             DISPLAY_SETTING_ON) == 0) {
       
   350         layoutRows++;
       
   351     } else {
       
   352         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSpnMarqueeItem); 
       
   353         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSpnIcon); 
       
   354     }
       
   355 
       
   356     if (m_preferences->preference(InfoWidgetPreferences::DisplayMcn).compare(
       
   357             DISPLAY_SETTING_ON) == 0) {
       
   358         layoutRows++;
       
   359     } else {
       
   360         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleMcnMarqueeItem); 
       
   361         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleMcnIcon); 
       
   362     }
       
   363     
       
   364     if (m_preferences->preference(InfoWidgetPreferences::DisplaySatText).compare(
       
   365             DISPLAY_SETTING_ON) == 0) {
       
   366         layoutRows++;
       
   367     } else {
       
   368         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSatMarqueeItem); 
       
   369         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSatTextIcon); 
       
   370     }
       
   371     
       
   372     DPRINT << ": visible layout rows count: " << layoutRows;
       
   373     m_layoutManager->setLayoutRows(layoutRows);
       
   374 }
       
   375 
       
   376 /*!
       
   377     InfoWidget::layoutInfoDisplay()
       
   378     
       
   379     Layout info display    
       
   380 */
       
   381 void InfoWidget::layoutInfoDisplay()
       
   382 {  
       
   383     DPRINT << ": IN";
       
   384     
       
   385     QGraphicsLayout *infoDisplayLayout = 
       
   386         m_layoutManager->layoutInfoDisplay(); 
       
   387     
       
   388     if (!m_layout->count()) {
       
   389         QGraphicsWidget *contentWidget = 
       
   390                 m_layoutManager->contentWidget();
       
   391         if (contentWidget) {
       
   392             // Add content widget to main layout 
       
   393             m_layout->addItem(contentWidget);
       
   394         }
       
   395     }
       
   396 
       
   397     updateItemsVisibility(); 
       
   398     
       
   399     endChanges();
       
   400     DPRINT << ": OUT";
       
   401 }
       
   402 
       
   403 /*!
       
   404     InfoWidget::layoutSettingsDialog()
       
   405     
       
   406     Layout and display settings dialog    
       
   407 */
       
   408 void InfoWidget::layoutSettingsDialog()
       
   409 {  
       
   410     DPRINT << ": IN";
       
   411     startChanges();
       
   412     
       
   413     m_layoutManager->reloadWidgets(InfoWidgetLayoutManager::SettingsDialog); 
       
   414     QGraphicsLayout *settingDialogLayout =
       
   415             m_layoutManager->layoutSettingsDialog(); 
       
   416     
       
   417     if (settingDialogLayout) {
       
   418         HbDialog *settingsDialog = qobject_cast<HbDialog *>(
       
   419                 m_layoutManager->getWidget(InfoWidgetLayoutManager::
       
   420                 RoleSettingsDialog)); 
       
   421 
       
   422         if (settingsDialog) {
       
   423             DPRINT << ": settingsDialog has been returned from layout manager";
       
   424             initializeSettingsDialogItems();
       
   425             
       
   426             settingsDialog->setDismissPolicy(HbDialog::NoDismiss); 
       
   427             settingsDialog->setTimeout(HbDialog::NoTimeout);
       
   428             settingsDialog->open(this, 
       
   429                     SLOT(settingsDialogClosed(HbAction *))); 
       
   430             }
       
   431     }    
       
   432     DPRINT << ": OUT";
       
   433 }
       
   434 
       
   435 /*!
       
   436     InfoWidget::initializeSettingsDialogItems()
       
   437     
       
   438     Set up initial check box states 
       
   439     and connect signals to local slots  
       
   440 */
       
   441 void InfoWidget::initializeSettingsDialogItems()
       
   442 {  
       
   443     DPRINT << ": IN";
       
   444 
       
   445     // Connect display setting check boxes
       
   446     HbCheckBox *spnCheckBox = 
       
   447             qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   448                     InfoWidgetLayoutManager::RoleSpnCheckBox));
       
   449     if (spnCheckBox) {
       
   450         spnCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   451                 InfoWidgetPreferences::DisplaySpn));
       
   452         
       
   453         QObject::connect(spnCheckBox, SIGNAL(stateChanged(int)), 
       
   454                 this, SLOT(spnDisplaySettingChanged(int)), 
       
   455                 Qt::UniqueConnection); 
       
   456     }
       
   457     
       
   458     HbCheckBox *mcnCheckBox = 
       
   459             qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   460                     InfoWidgetLayoutManager::RoleMcnCheckBox));
       
   461     if (mcnCheckBox) {
       
   462         mcnCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   463                 InfoWidgetPreferences::DisplayMcn));
       
   464         
       
   465         QObject::connect(mcnCheckBox, SIGNAL(stateChanged(int)), 
       
   466                 this, SLOT(mcnDisplaySettingChanged(int)), 
       
   467                 Qt::UniqueConnection); 
       
   468     }
       
   469     
       
   470     HbCheckBox *satTextCheckBox = 
       
   471             qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   472                     InfoWidgetLayoutManager::RoleSatTextCheckBox));
       
   473     if (satTextCheckBox) {
       
   474         satTextCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   475                 InfoWidgetPreferences::DisplaySatText));
       
   476         
       
   477         QObject::connect(satTextCheckBox, SIGNAL(stateChanged(int)), 
       
   478                 this, SLOT(satDisplaySettingChanged(int)), 
       
   479                 Qt::UniqueConnection); 
       
   480     }
       
   481     
       
   482     DPRINT << ": OUT";
       
   483 }
       
   484 
       
   485 /*!
       
   486     InfoWidget::updateInfoDisplayItem() 
       
   487     
       
   488     Fetch widget based on item role and update 
       
   489     item specific data. 
       
   490 */
       
   491 void InfoWidget::updateInfoDisplayItem(
       
   492         InfoWidgetLayoutManager::LayoutItemRole itemRole, 
       
   493         QString text)
       
   494 {
       
   495     DPRINT; 
       
   496     HbMarqueeItem *marqueeItem = qobject_cast<HbMarqueeItem *>(
       
   497             m_layoutManager->getWidget(itemRole));
       
   498     
       
   499     if (marqueeItem) {
       
   500         marqueeItem->setText(text);
       
   501         marqueeItem->setTextColor( HbColorScheme::color(
       
   502                 "qtc_hs_list_item_title_normal"));
       
   503         
       
   504         // Update widget effective size if not already set  
       
   505         marqueeItem->adjustSize(); 
       
   506         if (!m_layoutManager->textFitsToRect(
       
   507                 text,
       
   508                 marqueeItem->font(), 
       
   509                 marqueeItem->rect())) {
       
   510             DPRINT << ": enable marquee animation";
       
   511             m_animatingItems.append(marqueeItem);
       
   512         }
       
   513     }
       
   514 }
       
   515 
       
   516 /*!
       
   517     InfoWidget::updateInfoDisplay() 
       
   518     
       
   519     Model or visibility data has changed, 
       
   520     update info display widgets accordingly. 
       
   521 */
       
   522 void InfoWidget::updateInfoDisplay()
       
   523 {
       
   524     DPRINT << ": IN"; 
       
   525     
       
   526     if (m_initialized) {
       
   527         stopMarquees();
       
   528         
       
   529         if (m_layoutManager->currentDisplayRole() == 
       
   530                 InfoWidgetLayoutManager::InfoDisplay )
       
   531             {
       
   532             QString text;
       
   533             InfoWidgetEngine::ModelData modelData = m_engine->modelData(); 
       
   534         
       
   535             // Update service provider name item
       
   536             text = modelData.serviceProviderName();
       
   537             updateInfoDisplayItem(InfoWidgetLayoutManager::RoleSpnMarqueeItem, text); 
       
   538 
       
   539             // Update MCN name item
       
   540             text = modelData.mcnName();
       
   541             updateInfoDisplayItem(InfoWidgetLayoutManager::RoleMcnMarqueeItem, text); 
       
   542             
       
   543             // Update SAT display text item
       
   544             text = modelData.satDisplayText();
       
   545             updateInfoDisplayItem(InfoWidgetLayoutManager::RoleSatMarqueeItem, text); 
       
   546         }
       
   547         
       
   548         if (m_animatingItems.count() > 0) {
       
   549             startMarquees(StartDelayed); 
       
   550         }
       
   551     }
       
   552 }
       
   553 
       
   554 /*!
       
   555     InfoWidget::readModel() 
       
   556     
       
   557     Read model data. Model's modelChanged - signal is connected to this slot.  
       
   558 */
       
   559 void InfoWidget::readModel()
       
   560 {
       
   561     DPRINT << ": IN"; 
       
   562 
       
   563     if (m_layoutManager->currentDisplayRole() == 
       
   564             InfoWidgetLayoutManager::InfoDisplay) { 
       
   565         updateInfoDisplay(); 
       
   566     }
       
   567     DPRINT << ": OUT";
       
   568 }
       
   569 
       
   570 /*!
       
   571     InfoWidget::handleModelError() 
       
   572     
       
   573     Model error signal is connected to this slot 
       
   574 */
       
   575 void InfoWidget::handleModelError(int operation,int errorCode)
       
   576 {
       
   577     DWARNING << ": operation: " << operation << " error: " << errorCode; 
       
   578 }
       
   579 
       
   580 /*!
       
   581     InfoWidget::mousePressEvent() 
       
   582 */
       
   583 void InfoWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
       
   584 {
       
   585     Q_UNUSED(event);
       
   586     
       
   587     // Clear flag 
       
   588     m_dragEvent = false; 
       
   589 }
       
   590 
       
   591 /*!
       
   592     InfoWidget::mouseReleaseEvent() 
       
   593 */
       
   594 void InfoWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
       
   595 {
       
   596     Q_UNUSED(event);
       
   597 
       
   598     // If in info display and widget wasn't dragged 
       
   599     // layout and open settings dialog
       
   600     if ((!m_dragEvent) && 
       
   601           m_layoutManager->currentDisplayRole() == 
       
   602                   InfoWidgetLayoutManager::InfoDisplay) {
       
   603         DPRINT << ": layout and display settings dialog";
       
   604         layoutSettingsDialog();
       
   605     } 
       
   606     
       
   607     // Clear flag 
       
   608     m_dragEvent = false; 
       
   609 
       
   610 }
       
   611 
       
   612 /*!
       
   613     InfoWidget::mouseMoveEvent() 
       
   614 */
       
   615 void InfoWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
       
   616 {
       
   617     Q_UNUSED(event);
       
   618     
       
   619     // Mouse is moving 
       
   620     // after mouse press event
       
   621     m_dragEvent = true; 
       
   622 }
       
   623 
       
   624 /*!
       
   625     InfoWidget::spnDisplaySettingChanged() 
       
   626 */
       
   627 void InfoWidget::spnDisplaySettingChanged(int state)
       
   628 {
       
   629     DPRINT << ": state: " << state;
       
   630     if (state == Qt::Checked){
       
   631         m_preferences->setPreference(
       
   632                 InfoWidgetPreferences::DisplaySpn, DISPLAY_SETTING_ON);
       
   633     } else {
       
   634         m_preferences->setPreference(
       
   635                 InfoWidgetPreferences::DisplaySpn, DISPLAY_SETTING_OFF);
       
   636     }
       
   637 }
       
   638 
       
   639 /*!
       
   640     InfoWidget::mcnDisplaySettingChanged() 
       
   641 */
       
   642 void InfoWidget::mcnDisplaySettingChanged(int state)
       
   643 {
       
   644     DPRINT << ": state: " << state; 
       
   645     if (state == Qt::Checked){
       
   646         m_preferences->setPreference(
       
   647                 InfoWidgetPreferences::DisplayMcn, DISPLAY_SETTING_ON);
       
   648     } else {
       
   649         m_preferences->setPreference(
       
   650                 InfoWidgetPreferences::DisplayMcn, DISPLAY_SETTING_OFF);
       
   651     }
       
   652 }
       
   653 
       
   654 /*!
       
   655     InfoWidget::satDisplaySettingChanged() 
       
   656 */
       
   657 void InfoWidget::satDisplaySettingChanged(int state)
       
   658 {
       
   659     DPRINT << ": state: " << state; 
       
   660     if (state == Qt::Checked){
       
   661         m_preferences->setPreference(
       
   662                 InfoWidgetPreferences::DisplaySatText, DISPLAY_SETTING_ON);
       
   663     } else {
       
   664         m_preferences->setPreference(
       
   665                 InfoWidgetPreferences::DisplaySatText, DISPLAY_SETTING_OFF);
       
   666     }
       
   667 }
       
   668 
       
   669 /*!
       
   670     InfoWidget::mcnDisplay() 
       
   671     
       
   672     Getter function for Meta-object property "mcnDisplay"
       
   673 */
       
   674 QString InfoWidget::mcnDisplay()
       
   675 {
       
   676     DPRINT; 
       
   677     return m_preferences->preference(
       
   678             InfoWidgetPreferences::DisplayMcn); 
       
   679 }
       
   680 
       
   681 /*!
       
   682     InfoWidget::setMcnDisplay() 
       
   683     
       
   684     Setter function for Meta-object property "mcnDisplay"
       
   685 */
       
   686 void InfoWidget::setMcnDisplay(QString value)
       
   687 {
       
   688     DPRINT;
       
   689     m_preferences->setPreference(
       
   690             InfoWidgetPreferences::DisplayMcn, value);
       
   691     }
       
   692 
       
   693 /*!
       
   694     InfoWidget::homeZoneDisplay() 
       
   695     
       
   696     Getter function for Meta-object property "homeZoneDisplay"
       
   697 */
       
   698 QString InfoWidget::homeZoneDisplay()
       
   699 {
       
   700     DPRINT; 
       
   701     return m_preferences->preference(
       
   702             InfoWidgetPreferences::DisplayHomeZone); 
       
   703 }
       
   704 
       
   705 /*!
       
   706     InfoWidget::setHomeZoneDisplay()
       
   707     
       
   708     Setter function for Meta-object property "homeZoneDisplay" 
       
   709 */
       
   710 void InfoWidget::setHomeZoneDisplay(QString value)
       
   711 {
       
   712     DPRINT; 
       
   713     m_preferences->setPreference(
       
   714             InfoWidgetPreferences::DisplayHomeZone, value);
       
   715 }
       
   716 
       
   717 /*!
       
   718     InfoWidget::activeLineDisplay() 
       
   719     
       
   720     Getter function for Meta-object property "activeLineDisplay"
       
   721 */
       
   722 QString InfoWidget::activeLineDisplay()
       
   723 {
       
   724     DPRINT; 
       
   725     return m_preferences->preference(
       
   726             InfoWidgetPreferences::DisplayActiveLine);
       
   727 }
       
   728 
       
   729 /*!
       
   730     InfoWidget::setActiveLineDisplay() 
       
   731     
       
   732     Setter function for Meta-object property "activeLineDisplay"
       
   733 */
       
   734 void InfoWidget::setActiveLineDisplay(QString value)
       
   735 {
       
   736     DPRINT; 
       
   737     m_preferences->setPreference(
       
   738             InfoWidgetPreferences::DisplayActiveLine, value);
       
   739 }
       
   740 
       
   741 /*!
       
   742     InfoWidget::satDisplay()
       
   743     
       
   744     Getter function for Meta-object property "satDisplay" 
       
   745 */
       
   746 QString InfoWidget::satDisplay()
       
   747 {
       
   748     DPRINT; 
       
   749     return m_preferences->preference(
       
   750             InfoWidgetPreferences::DisplaySatText);
       
   751 }
       
   752 
       
   753 /*!
       
   754     InfoWidget::setSatDisplay()
       
   755     
       
   756     Setter function for Meta-object property "satDisplay" 
       
   757 */
       
   758 void InfoWidget::setSatDisplay(QString value)
       
   759 {
       
   760     DPRINT;
       
   761     m_preferences->setPreference(
       
   762             InfoWidgetPreferences::DisplaySatText, value);
       
   763 }
       
   764 
       
   765 /*!
       
   766     InfoWidget::spnDisplay()
       
   767     
       
   768     Getter function for Meta-object property "spnDisplay" 
       
   769 */
       
   770 QString InfoWidget::spnDisplay()
       
   771 {
       
   772     DPRINT; 
       
   773     return m_preferences->preference(
       
   774             InfoWidgetPreferences::DisplaySpn);
       
   775 }
       
   776 
       
   777 /*!
       
   778     InfoWidget::setSpnDisplay()
       
   779     
       
   780     Setter function for Meta-object property "spnDisplay" 
       
   781 */
       
   782 void InfoWidget::setSpnDisplay(QString value)
       
   783 {
       
   784     DPRINT;
       
   785     m_preferences->setPreference(
       
   786             InfoWidgetPreferences::DisplaySpn, value);
       
   787 }
       
   788 
       
   789 /*!
       
   790     InfoWidget::readPersistentPreferences()
       
   791     
       
   792     Read Meta-object properties and store to preference handler. 
       
   793     Restores preferences from previous session.   
       
   794 */
       
   795 bool InfoWidget::readPersistentPreferences()
       
   796 {
       
   797     DPRINT;
       
   798     bool changed(false);
       
   799 
       
   800     QString propertyValue = QObject::property("homeZoneDisplay").toString();
       
   801     m_preferences->setPreference(InfoWidgetPreferences::DisplayHomeZone, 
       
   802             propertyValue);
       
   803     
       
   804     propertyValue = QObject::property("mcnDisplay").toString();
       
   805     m_preferences->setPreference(InfoWidgetPreferences::DisplayMcn, 
       
   806             propertyValue);
       
   807     
       
   808     propertyValue = QObject::property("activeLineDisplay").toString();
       
   809     m_preferences->setPreference(InfoWidgetPreferences::DisplayActiveLine, 
       
   810             propertyValue);
       
   811     
       
   812     propertyValue = QObject::property("satDisplay").toString();
       
   813     m_preferences->setPreference(InfoWidgetPreferences::DisplaySatText, 
       
   814             propertyValue);
       
   815 
       
   816     propertyValue = QObject::property("spnDisplay").toString();
       
   817     m_preferences->setPreference(InfoWidgetPreferences::DisplaySpn, 
       
   818             propertyValue);
       
   819 
       
   820     // Check that at least one item is set visible and  
       
   821     // store preferences if true 
       
   822     if (m_preferences->validate()) {
       
   823         changed = m_preferences->storePreferences(); 
       
   824     } 
       
   825         
       
   826     return changed; 
       
   827 }
       
   828 
       
   829 /*!
       
   830     InfoWidget::initializeCheckBoxStates()
       
   831     
       
   832     Read display settings from preference store 
       
   833     and set check box initial states accordingly. 
       
   834 */
       
   835 void InfoWidget::initializeCheckBoxStates()
       
   836 {
       
   837     DPRINT;
       
   838     HbCheckBox *spnCheckBox = qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   839             InfoWidgetLayoutManager::RoleSpnCheckBox));
       
   840     if (spnCheckBox) {
       
   841     spnCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   842                 InfoWidgetPreferences::DisplaySpn));
       
   843     }
       
   844     
       
   845     HbCheckBox *mcnCheckBox = qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   846             InfoWidgetLayoutManager::RoleMcnCheckBox));
       
   847     if (mcnCheckBox) {
       
   848         mcnCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   849                 InfoWidgetPreferences::DisplayMcn));
       
   850     }
       
   851     
       
   852     HbCheckBox *satTextCheckBox = qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   853             InfoWidgetLayoutManager::RoleSatTextCheckBox));
       
   854     if (satTextCheckBox) {
       
   855         satTextCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   856                 InfoWidgetPreferences::DisplaySatText));
       
   857     }
       
   858 }
       
   859 
       
   860 /*!
       
   861     InfoWidget::settingsEditingFinished()
       
   862 */
       
   863 void InfoWidget::settingsEditingFinished()
       
   864 {
       
   865     DPRINT << ": IN";
       
   866     
       
   867     // Save settings data if validation succeeds 
       
   868     if (m_preferences->validate()) {
       
   869         DPRINT << ": switching to info display";
       
   870         
       
   871         // Signal HS framework to store Meta-object 
       
   872         // preferences if changed 
       
   873         if (m_preferences->storePreferences()) {
       
   874             emit setPreferences(
       
   875                     m_preferences->preferenceNames());
       
   876             }
       
   877         
       
   878         // Visible item configuration changed, reload 
       
   879         // widgets. Restores deleted items.  
       
   880         m_layoutManager->reloadWidgets(
       
   881                 InfoWidgetLayoutManager::InfoDisplay);
       
   882         m_layoutManager->removeWidget(
       
   883                 InfoWidgetLayoutManager::RoleSettingsDialog,
       
   884                 true);
       
   885         
       
   886     } else {
       
   887         DPRINT << ": settings validation failed";
       
   888         // Cancel edit mode 
       
   889         settingsEditingCancelled();
       
   890         
       
   891         // Display warning note
       
   892         settingsValidationFailed();
       
   893     }
       
   894     
       
   895     DPRINT << ": OUT";
       
   896 }
       
   897 
       
   898 /*!
       
   899     InfoWidget::settingsEditingCancelled()
       
   900     
       
   901     Slot to be called when settings editing 
       
   902     shouldn't cause change set of visible items. 
       
   903     Restores previous state.  
       
   904 */
       
   905 void InfoWidget::settingsEditingCancelled()
       
   906 {
       
   907     DPRINT;
       
   908     m_preferences->restorePreferences(); 
       
   909     
       
   910     m_layoutManager->reloadWidgets(
       
   911             InfoWidgetLayoutManager::InfoDisplay);
       
   912     m_layoutManager->removeWidget(
       
   913             InfoWidgetLayoutManager::RoleSettingsDialog,
       
   914             true); 
       
   915 }
       
   916 
       
   917 /*!
       
   918     InfoWidget::settingsDialogClosed()
       
   919     
       
   920     Slot to be called when settings dialog is about to close
       
   921 */
       
   922 void InfoWidget::settingsDialogClosed(HbAction* action)
       
   923 {
       
   924     DPRINT << ": IN";
       
   925     if (action) {
       
   926         if (action->text() == hbTrId("txt_common_button_ok")) {
       
   927             settingsEditingFinished(); 
       
   928         } else if (action->text() == hbTrId("txt_common_button_cancel") ) {
       
   929             settingsEditingCancelled(); 
       
   930         }       
       
   931     } else {
       
   932         DPRINT << ": null action";
       
   933         settingsEditingCancelled(); 
       
   934     }
       
   935      
       
   936     // Switch to info display 
       
   937     layoutInfoDisplay();
       
   938     DPRINT << ": OUT";
       
   939 }
       
   940 
       
   941 /*!
       
   942     InfoWidget::startChanges()
       
   943 */
       
   944 void InfoWidget::startChanges()
       
   945 {
       
   946     DPRINT;
       
   947     m_layoutChanging = true;
       
   948     if (m_animationState != AnimationIdle) {
       
   949             stopMarquees(); 
       
   950     }
       
   951 }
       
   952 
       
   953 /*!
       
   954     InfoWidget::endChanges()
       
   955 */
       
   956 void InfoWidget::endChanges()
       
   957 {
       
   958     DPRINT;
       
   959     updateGeometry();
       
   960     updateInfoDisplay();
       
   961     
       
   962     m_layoutChanging = false;
       
   963 }
       
   964 
       
   965 /*!
       
   966    \reimp
       
   967 */
       
   968 void InfoWidget::changeEvent(QEvent *event)
       
   969 {
       
   970    DPRINT;
       
   971    if (event->type() == HbEvent::ThemeChanged) {
       
   972        DPRINT << ": HbEvent::ThemeChanged";
       
   973        updateInfoDisplay(); 
       
   974    }
       
   975    HbWidget::changeEvent(event);
       
   976 }
       
   977 
       
   978 /*!
       
   979    InfoWidget::settingsValidationFailed()
       
   980    
       
   981    Slot to be called when preference validation has failed. 
       
   982    Displays warning message box
       
   983 */
       
   984 void InfoWidget::settingsValidationFailed()
       
   985 {
       
   986    DPRINT;
       
   987    if (m_initialized) {
       
   988        HbMessageBox::warning(
       
   989                hbTrId("txt_operatorwidget_info_select_one"));
       
   990    }
       
   991 }
       
   992 
       
   993 /*!
       
   994    InfoWidget::startMarquees()
       
   995    
       
   996    Start marquee animations. 
       
   997    First find existing marquee items and 
       
   998    enable marquee sequence
       
   999 */
       
  1000 bool InfoWidget::startMarquees(AnimationStartDelay delay)
       
  1001 {  
       
  1002     DPRINT;
       
  1003     bool started(true); 
       
  1004     
       
  1005     if (m_animationState == AnimationOngoing || 
       
  1006         m_animationState == AnimationStarting) {
       
  1007         return false; 
       
  1008         }
       
  1009       
       
  1010     int animatingItemsCount = m_animatingItems.count();  
       
  1011     if (animatingItemsCount > 0) {
       
  1012         HbMarqueeItem *marqueeItem(NULL);  
       
  1013         foreach (marqueeItem, m_animatingItems) {
       
  1014             if (animatingItemsCount > 1) {
       
  1015                 // Multiple items, connect to marqueeNext() 
       
  1016                 // sequence logic
       
  1017                 QObject::connect(
       
  1018                         marqueeItem,SIGNAL(animationStopped()),
       
  1019                         this, SLOT(marqueeNext()), 
       
  1020                         Qt::UniqueConnection);
       
  1021                 marqueeItem->setLoopCount(1); 
       
  1022             } else if (animatingItemsCount ==1 ){
       
  1023                 // Single item, set continuous marquee mode 
       
  1024                 marqueeItem->setLoopCount(-1); 
       
  1025             }
       
  1026         }
       
  1027         
       
  1028         // Store marquee sequence start item 
       
  1029         m_animatingItem = m_animatingItems.first();
       
  1030         
       
  1031         if (delay == StartNoDelay) {
       
  1032             m_animationState = AnimationOngoing; 
       
  1033             m_animatingItem->startAnimation();
       
  1034         } else if (delay == StartDelayed && !m_timerId) {
       
  1035             m_animationState = AnimationStarting;
       
  1036             m_timerId = startTimer(100);
       
  1037         } 
       
  1038         
       
  1039     } else {
       
  1040         // No animating items, not started
       
  1041         DWARNING << ": not done, no animating items";
       
  1042         m_animatingItem = NULL; 
       
  1043         started = false;
       
  1044     }
       
  1045     
       
  1046     return started; 
       
  1047 }
       
  1048 
       
  1049 /*!
       
  1050    InfoWidget::stopMarquees()
       
  1051    
       
  1052    Stop all marquee animations and reset 
       
  1053    animation state
       
  1054 */
       
  1055 void InfoWidget::stopMarquees()
       
  1056 {  
       
  1057     DPRINT;
       
  1058     if (m_animationState != AnimationIdle && 
       
  1059         m_animatingItems.count() > 0) {
       
  1060         HbMarqueeItem *marqueeItem(NULL);
       
  1061         
       
  1062         foreach (marqueeItem, m_animatingItems) {
       
  1063             
       
  1064             // Disconnect if more than one item, 
       
  1065             // single animator doesn't connect to animationStopped() 
       
  1066             if (m_animatingItems.count() > 1) {
       
  1067                 QObject::disconnect(
       
  1068                     marqueeItem, SIGNAL(animationStopped()),
       
  1069                     this, SLOT(marqueeNext()));
       
  1070             }
       
  1071             
       
  1072             if (marqueeItem->isAnimating()) {
       
  1073                 marqueeItem->stopAnimation();
       
  1074             }
       
  1075         }
       
  1076     }
       
  1077     
       
  1078     // Stop timer 
       
  1079     if (m_timerId) {
       
  1080         killTimer(m_timerId); 
       
  1081         m_timerId = 0; 
       
  1082     }
       
  1083     
       
  1084     m_animationState = AnimationIdle;
       
  1085     m_animatingItems.clear();
       
  1086     m_animatingItem = NULL; 
       
  1087 }
       
  1088 
       
  1089 /*!
       
  1090    InfoWidget::marqueeNext()
       
  1091    
       
  1092    Starts marquee animation for 
       
  1093    next item in sequence.  
       
  1094 */
       
  1095 void InfoWidget::marqueeNext()
       
  1096 {  
       
  1097     DPRINT;
       
  1098     if (m_animationState == AnimationOngoing) {
       
  1099         QListIterator<HbMarqueeItem *> i(m_animatingItems);
       
  1100         if (i.findNext(m_animatingItem)) {
       
  1101             if (i.hasNext()) {
       
  1102                 m_animatingItem = i.peekNext();
       
  1103             } else {
       
  1104                 // Was last item, loop back to first item
       
  1105                 i.toFront();
       
  1106                 m_animatingItem = i.peekNext();  
       
  1107             }
       
  1108         } else {
       
  1109             DWARNING << ": animating item not found from list"; 
       
  1110             m_animatingItem = NULL; 
       
  1111         }
       
  1112           
       
  1113         if (m_animatingItem) {
       
  1114             if (!m_animatingItem->isAnimating()) {
       
  1115                 m_animatingItem->setLoopCount(1); 
       
  1116                 m_animatingItem->startAnimation();
       
  1117             }
       
  1118         }
       
  1119     }
       
  1120     
       
  1121 }
       
  1122 
       
  1123 // End of File. 
       
  1124