phoneplugins/infowidgetplugin/infowidgetprovider/infowidget/src/infowidget.cpp
branchGCC_SURGE
changeset 51 f39ed5e045e0
parent 40 bab96b7ed1a4
parent 46 bc5a64e5bc3c
equal deleted inserted replaced
40:bab96b7ed1a4 51:f39ed5e045e0
     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 
       
    20 #include <hbanchorlayout.h>
       
    21 #include <hbiconitem.h>
       
    22 #include <hbmarqueeitem.h>
       
    23 #include <hbfontspec.h>
       
    24 #include <hbdialog.h>
       
    25 #include <hblabel.h>
       
    26 #include <hbaction.h>
       
    27 #include <hbcheckbox.h>
       
    28 #include <hbpushbutton.h>
       
    29 #include <hbevent.h>
       
    30 #include <hbcolorscheme.h>
       
    31 #include <hbmessagebox.h>
       
    32 #include <hbframedrawer.h>
       
    33 #include <QPainter>
       
    34 #include <QPainterPath>
       
    35 #include <QBrush>
       
    36 #include <QGraphicsLinearLayout>
       
    37 #include <QApplication>
       
    38 #include <QLocale>
       
    39 #include <QTranslator>
       
    40 #include "infowidgetlogging.h"
       
    41 #include "infowidgetengine.h"
       
    42 #include "infowidgetlayoutmanager.h"
       
    43 #include "infowidgetpreferences.h"
       
    44 
       
    45 const int INFOWIDGET_ROUNDING = 15;
       
    46 const int INFOWIDGET_DEFAULT_HEIGHT = 100;
       
    47 const int INFOWIDGET_DEFAULT_WIDTH = 100;
       
    48 const char *TS_FILE_OPERATOR_WIDGET = "operator_widget"; 
       
    49 const char *TS_FILE_COMMON = "common";
       
    50 const char *BACKGROUND_COLOR_GROUP_ID = "qtc_default_popup_normal"; 
       
    51 const char *BACKGROUND_FRAME_NAME = "qtg_fr_hswidget_normal"; 
       
    52 
       
    53 /*!
       
    54   \class InfoWidget
       
    55   \brief Operator info widget main class. 
       
    56 
       
    57    Implements HomeScreen specific slots and 
       
    58    graphical representation of the 
       
    59    Operator Info widget. 
       
    60 
       
    61    Derived from HbWidget.
       
    62     
       
    63 */
       
    64 
       
    65 /*!
       
    66     InfoWidget::InfoWidget() 
       
    67 */
       
    68 InfoWidget::InfoWidget(QGraphicsItem* parent, Qt::WindowFlags flags)
       
    69     : HbWidget(parent, flags),
       
    70     m_engine(NULL), 
       
    71     m_preferences(NULL),
       
    72     m_layoutManager(NULL),
       
    73     m_layout(NULL),
       
    74     m_frameDrawer(NULL),
       
    75     m_layoutChanging(false),
       
    76     m_dragEvent(false), 
       
    77     m_initialized(false)
       
    78 {
       
    79     INSTALL_TRACE_MSG_HANDLER; 
       
    80     
       
    81     DPRINT << ": IN";
       
    82     
       
    83     // Localization file loading
       
    84     installTranslator(TS_FILE_OPERATOR_WIDGET);
       
    85     installTranslator(TS_FILE_COMMON);
       
    86     
       
    87     m_layoutManager = new InfoWidgetLayoutManager(this);
       
    88     Q_ASSERT(m_layoutManager); 
       
    89     
       
    90     m_engine = new InfoWidgetEngine(this); 
       
    91     Q_ASSERT(m_engine);
       
    92     
       
    93     m_preferences = new InfoWidgetPreferences(this);
       
    94     Q_ASSERT(m_preferences);
       
    95     
       
    96     QObject::connect( m_preferences, SIGNAL(prefChanged(int,int)),
       
    97                     m_engine, SLOT(preferenceChanged(int,int)));
       
    98     
       
    99     // Setup widget main layout 
       
   100     m_layout = new QGraphicsLinearLayout;    
       
   101     m_layout->setSpacing(0); 
       
   102     m_layout->setContentsMargins(0,0,0,0); 
       
   103     setLayout(m_layout);
       
   104 
       
   105     // Read color definitions 
       
   106     m_backGroundColor = HbColorScheme::color(
       
   107             BACKGROUND_COLOR_GROUP_ID);
       
   108     if (!m_backGroundColor.isValid()) {
       
   109         m_backGroundColor = Qt::black; 
       
   110     }
       
   111     
       
   112     // Create background frame drawer 
       
   113     m_frameDrawer = new HbFrameDrawer(
       
   114             BACKGROUND_FRAME_NAME, 
       
   115             HbFrameDrawer::NinePieces);
       
   116     Q_ASSERT(m_frameDrawer); 
       
   117     
       
   118     // Set widget initial size
       
   119     resize(INFOWIDGET_DEFAULT_WIDTH,
       
   120            INFOWIDGET_DEFAULT_HEIGHT); 
       
   121     
       
   122     DPRINT << ": OUT";
       
   123 }
       
   124 
       
   125 /*!
       
   126     InfoWidget::~InfoWidget() 
       
   127 */
       
   128 InfoWidget::~InfoWidget()
       
   129 {
       
   130     DPRINT << ": IN"; 
       
   131     
       
   132     // Layout manager item cleanup
       
   133     m_layoutManager->destroyObjects(); 
       
   134     
       
   135     if (m_frameDrawer) {
       
   136         delete m_frameDrawer;
       
   137         m_frameDrawer = NULL; 
       
   138     }
       
   139     
       
   140     // Remove and delete language translators 
       
   141     removeTranslators(); 
       
   142     
       
   143     DPRINT << ": OUT"; 
       
   144     UNINSTALL_TRACE_MSG_HANDLER;
       
   145 }
       
   146 
       
   147 /*!
       
   148     InfoWidget::onInitialize()
       
   149     
       
   150     Called by HS framework, saved preference data
       
   151     is available when onInitialize() is called and 
       
   152     meta-object data reading should be done here      
       
   153 */
       
   154 void InfoWidget::onInitialize()
       
   155 {
       
   156     DPRINT << ": IN";
       
   157     
       
   158     m_initialized = true; 
       
   159     
       
   160     // Initialize preferences from meta-object data
       
   161     if (!readPersistentPreferences()) {
       
   162 
       
   163         // Reading failed, initialize default values  
       
   164         m_preferences->setPreference(InfoWidgetPreferences::DisplaySpn, 
       
   165                 DISPLAY_SETTING_ON);
       
   166         m_preferences->setPreference(InfoWidgetPreferences::DisplayMcn, 
       
   167                 DISPLAY_SETTING_ON);
       
   168         m_preferences->setPreference(InfoWidgetPreferences::DisplaySatText, 
       
   169                 DISPLAY_SETTING_ON);
       
   170     } 
       
   171     m_preferences->storePreferences(); 
       
   172     
       
   173     // Layout components 
       
   174     layoutInfoDisplay();
       
   175     m_layout->activate(); 
       
   176     
       
   177     // Read initial data from model
       
   178     updateInfoDisplay(); 
       
   179     
       
   180     // Listen for model changes 
       
   181     QObject::connect(m_engine, SIGNAL(modelChanged()), 
       
   182             this, SLOT(readModel())); 
       
   183 
       
   184     DPRINT << ": OUT";
       
   185 }
       
   186 
       
   187 /*!
       
   188     InfoWidget::onUninitialize() 
       
   189 */
       
   190 void InfoWidget::onUninitialize()
       
   191 {
       
   192     DPRINT;
       
   193     m_initialized = false; 
       
   194     m_engine->suspend(); 
       
   195 }
       
   196 
       
   197 /*!
       
   198     InfoWidget::onShow() 
       
   199 */
       
   200 void InfoWidget::onShow()
       
   201 {
       
   202     DPRINT;
       
   203     m_engine->resume(); 
       
   204 }
       
   205 
       
   206 /*!
       
   207     InfoWidget::onHide() 
       
   208 */
       
   209 void InfoWidget::onHide()
       
   210 {
       
   211     DPRINT;
       
   212     m_engine->suspend(); 
       
   213 }
       
   214 
       
   215 /*!
       
   216     InfoWidget::installTranslator() const
       
   217 */
       
   218 bool InfoWidget::installTranslator(QString translationFile)
       
   219 {
       
   220     DPRINT << ": IN";
       
   221 
       
   222     QString lang = QLocale::system().name();
       
   223     QString path = "z:/resource/qt/translations/";
       
   224     bool translatorLoaded(false);  
       
   225     
       
   226     QTranslator* widgetTranslator = new QTranslator;
       
   227     translatorLoaded = widgetTranslator->load(
       
   228             path + translationFile + "_" + lang);
       
   229     if (translatorLoaded) {
       
   230         qApp->installTranslator(widgetTranslator);
       
   231         m_translators.append(widgetTranslator); 
       
   232         DPRINT << ": translator installed: " << translationFile; 
       
   233     } else {
       
   234         delete widgetTranslator; 
       
   235         widgetTranslator = NULL; 
       
   236     }
       
   237     
       
   238     DPRINT << ": OUT";
       
   239     return translatorLoaded;
       
   240 }
       
   241 
       
   242 /*!
       
   243     InfoWidget::removeTranslators() const
       
   244 */
       
   245 void InfoWidget::removeTranslators()
       
   246 {
       
   247     DPRINT << ": IN";
       
   248 
       
   249     foreach (QTranslator *translator, m_translators) {
       
   250         qApp->removeTranslator(translator);
       
   251     }    
       
   252     qDeleteAll(m_translators);
       
   253     m_translators.clear();
       
   254     
       
   255     DPRINT << ": OUT";
       
   256 }
       
   257 
       
   258 /*!
       
   259     InfoWidget::boundingRect() const
       
   260 */
       
   261 QRectF InfoWidget::boundingRect() const
       
   262 {   
       
   263     return rect();
       
   264 }
       
   265 
       
   266 /*!
       
   267     InfoWidget::shape() const
       
   268     
       
   269     Return Operator widget's shape 
       
   270     according to currect display 
       
   271 */
       
   272 QPainterPath InfoWidget::shape() const
       
   273 {
       
   274     DPRINT;    
       
   275     
       
   276     QPainterPath path;
       
   277     if (m_layoutManager->currentDisplayRole() == 
       
   278                     InfoWidgetLayoutManager::InfoDisplay) {
       
   279         path.addRoundRect(boundingRect(), 
       
   280                 INFOWIDGET_ROUNDING, 
       
   281                 INFOWIDGET_ROUNDING);
       
   282     } else {
       
   283         path.addRect(boundingRect()); 
       
   284     }
       
   285     return path;
       
   286 }
       
   287 
       
   288 /*!
       
   289     InfoWidget::sizeHint() 
       
   290 */
       
   291 QSizeF InfoWidget::sizeHint(Qt::SizeHint which, const QSizeF & constraint) const   
       
   292 {
       
   293     Q_UNUSED(which);
       
   294     Q_UNUSED(constraint); 
       
   295     
       
   296     QSizeF requiredSize(
       
   297             INFOWIDGET_DEFAULT_WIDTH,
       
   298             INFOWIDGET_DEFAULT_HEIGHT);
       
   299     
       
   300     if (m_initialized) { 
       
   301         // Read size hint from docml content
       
   302         if (m_layoutManager->currentDisplayRole() == 
       
   303                     InfoWidgetLayoutManager::InfoDisplay) {
       
   304             if (m_layoutManager->contentWidget()) {
       
   305                 requiredSize = m_layoutManager->contentWidget()->minimumSize();
       
   306                 // Height according number of rows, if 0 or 1 row use minimum size
       
   307                 int rowCount = m_preferences->visibleItemCount();
       
   308                 if (1 < rowCount) {
       
   309                         requiredSize.rheight() += (rowCount-1)*
       
   310                                 m_layoutManager->rowHeight();
       
   311                 }
       
   312             }
       
   313         }
       
   314         else if (m_layoutManager->currentDisplayRole() == 
       
   315                 InfoWidgetLayoutManager::SettingsDisplay) {
       
   316             if (m_layoutManager->contentWidget()) {
       
   317                 requiredSize= m_layoutManager->contentWidget()->size();
       
   318                 }
       
   319         } 
       
   320     } 
       
   321     
       
   322     DPRINT << ": returning size: " << requiredSize;
       
   323     return requiredSize; 
       
   324 }
       
   325 
       
   326 /*!
       
   327     InfoWidget::sizePolicy() 
       
   328 */
       
   329 QSizePolicy InfoWidget::sizePolicy () const 
       
   330 {
       
   331     DPRINT;
       
   332     return QSizePolicy(
       
   333             QSizePolicy::Fixed, 
       
   334             QSizePolicy::Fixed); 
       
   335 }
       
   336 
       
   337 /*!
       
   338     InfoWidget::updateItemsVisibility() 
       
   339 */
       
   340 void InfoWidget::updateItemsVisibility()
       
   341 {
       
   342     DPRINT <<": IN"; 
       
   343     int layoutRows = 0; 
       
   344     QList<QGraphicsWidget *> widgetsToHide; 
       
   345     
       
   346     // Update layout according to item visibility settings
       
   347     if (m_preferences->preference(InfoWidgetPreferences::DisplaySpn).compare(
       
   348             DISPLAY_SETTING_ON) == 0) {
       
   349         layoutRows++;
       
   350     } else if (m_layoutManager->currentDisplayRole() != InfoWidgetLayoutManager::SettingsDisplay) {
       
   351         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSpnLabel); 
       
   352         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSpnIcon); 
       
   353     }
       
   354 
       
   355     if (m_preferences->preference(InfoWidgetPreferences::DisplayMcn).compare(
       
   356             DISPLAY_SETTING_ON) == 0) {
       
   357         layoutRows++;
       
   358     } else if (m_layoutManager->currentDisplayRole() != InfoWidgetLayoutManager::SettingsDisplay) {
       
   359         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleMcnMarqueeItem); 
       
   360         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleMcnIcon); 
       
   361     }
       
   362     
       
   363     if (m_preferences->preference(InfoWidgetPreferences::DisplaySatText).compare(
       
   364             DISPLAY_SETTING_ON) == 0) {
       
   365         layoutRows++;
       
   366     } else if (m_layoutManager->currentDisplayRole() != InfoWidgetLayoutManager::SettingsDisplay) {
       
   367         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSatMarqueeItem); 
       
   368         m_layoutManager->removeWidget(InfoWidgetLayoutManager::RoleSatTextIcon); 
       
   369     }
       
   370     
       
   371     DPRINT << ": visible layout rows count: " << layoutRows;
       
   372     m_layoutManager->setLayoutRows(layoutRows);
       
   373 }
       
   374 
       
   375 /*!
       
   376     InfoWidget::layoutInfoDisplay()
       
   377     
       
   378     Layout info display    
       
   379 */
       
   380 void InfoWidget::layoutInfoDisplay()
       
   381 {  
       
   382     startChanges(); 
       
   383     
       
   384     QGraphicsLayout *infoDisplayLayout = 
       
   385         m_layoutManager->layoutInfoDisplay(); 
       
   386     
       
   387     DPRINT << ": IN";
       
   388     if (infoDisplayLayout) {
       
   389         DPRINT << ": infoDisplayLayout has been returned from layout manager";
       
   390 
       
   391         QGraphicsWidget *contentWidget = m_layoutManager->contentWidget();
       
   392         if (contentWidget) {
       
   393             DPRINT << ": contentWidget has been returned from layout manager";
       
   394             
       
   395             // Remove old data from layout. 
       
   396             for (int i=0; i < m_layout->count(); i++) {
       
   397                 DPRINT << ": item(" << i << ") removed from layout";
       
   398                 m_layout->removeAt(i);
       
   399                 } 
       
   400             
       
   401             // Add content widget to main layout 
       
   402             m_layout->addItem(contentWidget);
       
   403         }       
       
   404     }
       
   405     
       
   406     m_layoutManager->showAll(); 
       
   407     updateItemsVisibility(); 
       
   408     m_layout->activate(); 
       
   409 
       
   410     endChanges(); 
       
   411     
       
   412     DPRINT << ": OUT";
       
   413 }
       
   414 
       
   415 /*!
       
   416     InfoWidget::layoutSettingsDisplay()
       
   417     
       
   418     Switch to settings display layout   
       
   419 */
       
   420 void InfoWidget::layoutSettingsDisplay()
       
   421 {  
       
   422     startChanges(); 
       
   423     
       
   424     QGraphicsLayout *settingDisplayLayout = 
       
   425         m_layoutManager->layoutSettingsDisplay(); 
       
   426     
       
   427     DPRINT << ": IN";
       
   428     if (settingDisplayLayout) {
       
   429         DPRINT << ": settingDisplayLayout has been returned from layout manager";
       
   430 
       
   431         QGraphicsWidget *contentWidget = m_layoutManager->contentWidget();
       
   432         if (contentWidget) {
       
   433             DPRINT << ": contentWidget has been returned from layout manager";
       
   434                 
       
   435             // Remove old data from layout. 
       
   436             for (int i=0; i < m_layout->count(); i++) {
       
   437                 DPRINT << ": item(" << i << ") removed from layout";
       
   438                 m_layout->removeAt(i);
       
   439                 } 
       
   440             
       
   441             // Add content widget to main layout 
       
   442             m_layout->addItem(contentWidget); 
       
   443         }
       
   444         
       
   445         // Connect settings display widget signals 
       
   446         initializeSettingsDisplayItems(); 
       
   447     }
       
   448      
       
   449     m_layoutManager->showAll(); 
       
   450     endChanges(); 
       
   451     
       
   452     DPRINT << ": OUT";
       
   453 }
       
   454 
       
   455 /*!
       
   456     InfoWidget::initializeInfoDisplayItems()
       
   457 */
       
   458 void InfoWidget::initializeInfoDisplayItems()
       
   459 {  
       
   460     DPRINT;
       
   461 }
       
   462 
       
   463 /*!
       
   464     InfoWidget::initializeSettingsDisplayItems()
       
   465     
       
   466     Set up initial check box states, lock check boxes 
       
   467     if needed and connect signals to local slots  
       
   468 */
       
   469 void InfoWidget::initializeSettingsDisplayItems()
       
   470 {  
       
   471     DPRINT << ": IN";
       
   472     
       
   473     HbPushButton *okButton = qobject_cast<HbPushButton *>(m_layoutManager->getWidget(
       
   474             InfoWidgetLayoutManager::RoleOkButton));
       
   475     if (okButton) {
       
   476         QObject::connect(okButton, SIGNAL(clicked()), 
       
   477                 this, SLOT(settingsEditingFinished()), Qt::UniqueConnection); 
       
   478     }
       
   479 
       
   480     // Connect display setting check boxes
       
   481     HbCheckBox *spnCheckBox = qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   482             InfoWidgetLayoutManager::RoleSpnCheckBox));
       
   483     if (spnCheckBox) {
       
   484         spnCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   485                 InfoWidgetPreferences::DisplaySpn));
       
   486         
       
   487         QObject::connect(spnCheckBox, SIGNAL(stateChanged(int)), 
       
   488                 this, SLOT(spnDisplaySettingChanged(int)), Qt::UniqueConnection); 
       
   489     }
       
   490     
       
   491     HbCheckBox *mcnCheckBox = qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   492             InfoWidgetLayoutManager::RoleMcnCheckBox));
       
   493     if (mcnCheckBox) {
       
   494         mcnCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   495                 InfoWidgetPreferences::DisplayMcn));
       
   496         
       
   497         QObject::connect(mcnCheckBox, SIGNAL(stateChanged(int)), 
       
   498                 this, SLOT(mcnDisplaySettingChanged(int)), Qt::UniqueConnection); 
       
   499     }
       
   500     
       
   501     HbCheckBox *satTextCheckBox = qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   502             InfoWidgetLayoutManager::RoleSatTextCheckBox));
       
   503     if (satTextCheckBox) {
       
   504         satTextCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   505                 InfoWidgetPreferences::DisplaySatText));
       
   506         
       
   507         QObject::connect(satTextCheckBox, SIGNAL(stateChanged(int)), 
       
   508                 this, SLOT(satDisplaySettingChanged(int)), Qt::UniqueConnection); 
       
   509     }
       
   510     
       
   511     DPRINT << ": OUT";
       
   512 }
       
   513 
       
   514 /*!
       
   515     InfoWidget::updateInfoDisplay() 
       
   516 */
       
   517 void InfoWidget::updateInfoDisplay()
       
   518 {
       
   519     DPRINT << ": IN"; 
       
   520     
       
   521     if (m_layoutManager->currentDisplayRole() == 
       
   522             InfoWidgetLayoutManager::InfoDisplay )
       
   523         {
       
   524         QString text;
       
   525         InfoWidgetEngine::ModelData modelData = m_engine->modelData(); 
       
   526     
       
   527         HbLabel *spnLabel = qobject_cast<HbLabel *>(m_layoutManager->getWidget(
       
   528                 InfoWidgetLayoutManager::RoleSpnLabel));
       
   529         if (spnLabel) {
       
   530             if (m_engine->modelData().serviceProviderNameDisplayRequired()) {
       
   531                 text = modelData.serviceProviderName();  
       
   532                 spnLabel->setPlainText(text);
       
   533             }
       
   534         }        
       
   535         
       
   536         HbMarqueeItem *mcnMarqueeItem = qobject_cast<HbMarqueeItem *>(m_layoutManager->getWidget(
       
   537                 InfoWidgetLayoutManager::RoleMcnMarqueeItem));
       
   538         if (mcnMarqueeItem) {
       
   539             text = modelData.mcnName(); 
       
   540             mcnMarqueeItem->setText(text);
       
   541             
       
   542             // Set marquee animation looping mode to infinite
       
   543             mcnMarqueeItem->setLoopCount(-1); 
       
   544                 
       
   545             // Finally, start marquee animation
       
   546             DPRINT << ": mcnMarqueeItem->isAnimating()"; 
       
   547             if (!mcnMarqueeItem->isAnimating()) {
       
   548                 DPRINT << ": mcnMarqueeItem->startAnimation()";   
       
   549                 mcnMarqueeItem->startAnimation();
       
   550             }
       
   551         }
       
   552     
       
   553         HbMarqueeItem *satMarqueeItem = qobject_cast<HbMarqueeItem *>(m_layoutManager->getWidget(
       
   554                 InfoWidgetLayoutManager::RoleSatMarqueeItem));
       
   555         if (satMarqueeItem) {
       
   556             text = modelData.satDisplayText(); 
       
   557     
       
   558             satMarqueeItem->setText(text);
       
   559             
       
   560             // Set marquee animation looping mode to infinite
       
   561             satMarqueeItem->setLoopCount(-1); 
       
   562                         
       
   563             // Finally, start marquee animation
       
   564             DPRINT << ": satMarqueeItem->isAnimating()"; 
       
   565             if (!satMarqueeItem->isAnimating()) {
       
   566                 DPRINT << ": mcnMarqueeItem->startAnimation()";   
       
   567                 satMarqueeItem->startAnimation();
       
   568             }
       
   569         }
       
   570     }
       
   571 }
       
   572 
       
   573 /*!
       
   574     InfoWidget::readModel() 
       
   575     
       
   576     Read model data. Model's modelChanged - signal is connected to this slot.  
       
   577 */
       
   578 void InfoWidget::readModel()
       
   579 {
       
   580     DPRINT << ": IN"; 
       
   581 
       
   582     if (m_layoutManager->currentDisplayRole() == 
       
   583             InfoWidgetLayoutManager::InfoDisplay) { 
       
   584         updateInfoDisplay(); 
       
   585     }
       
   586     DPRINT << ": OUT";
       
   587 }
       
   588 
       
   589 /*!
       
   590     InfoWidget::handleModelError() 
       
   591     
       
   592     Model error signal is connected to this slot 
       
   593 */
       
   594 void InfoWidget::handleModelError(int operation,int errorCode)
       
   595 {
       
   596     Q_UNUSED(operation); 
       
   597     Q_UNUSED(errorCode); 
       
   598     DPRINT;
       
   599 }
       
   600 
       
   601 /*!
       
   602     InfoWidget::paint() 
       
   603 */
       
   604 void InfoWidget::paint(QPainter *painter, 
       
   605         const QStyleOptionGraphicsItem *option, 
       
   606         QWidget *widget)
       
   607 {
       
   608     Q_UNUSED(option); 
       
   609     Q_UNUSED(widget);
       
   610     DPRINT;
       
   611 
       
   612     if (!m_layoutChanging) {
       
   613         painter->save();
       
   614         
       
   615         if (m_layoutManager->currentDisplayRole() == 
       
   616                 InfoWidgetLayoutManager::InfoDisplay) { 
       
   617             if (m_frameDrawer) {
       
   618                 m_frameDrawer->paint(painter,boundingRect());
       
   619             }
       
   620         } else {            
       
   621             QBrush brush(Qt::black); 
       
   622             QPainterPath path;
       
   623             path.addRoundRect(boundingRect(), 
       
   624                     INFOWIDGET_ROUNDING, 
       
   625                     INFOWIDGET_ROUNDING);
       
   626             painter->fillPath(path, brush);
       
   627         }
       
   628         
       
   629         painter->restore();
       
   630     }
       
   631 }
       
   632 
       
   633 /*!
       
   634     InfoWidget::mousePressEvent() 
       
   635 */
       
   636 void InfoWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
       
   637 {
       
   638     Q_UNUSED(event);
       
   639     
       
   640     // Clear flag 
       
   641     m_dragEvent = false; 
       
   642 }
       
   643 
       
   644 /*!
       
   645     InfoWidget::mouseReleaseEvent() 
       
   646 */
       
   647 void InfoWidget::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
       
   648 {
       
   649     Q_UNUSED(event);
       
   650 
       
   651     // If in info display and widget wasn't dragged 
       
   652     // change to settings display
       
   653     if ((!m_dragEvent) && 
       
   654           m_layoutManager->currentDisplayRole() == 
       
   655                   InfoWidgetLayoutManager::InfoDisplay) {
       
   656         DPRINT << ": layout settings display";
       
   657         layoutSettingsDisplay(); 
       
   658     }
       
   659     
       
   660     // Clear flag 
       
   661     m_dragEvent = false; 
       
   662 }
       
   663 
       
   664 /*!
       
   665     InfoWidget::mouseMoveEvent() 
       
   666 */
       
   667 void InfoWidget::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
       
   668 {
       
   669     Q_UNUSED(event);
       
   670     
       
   671     // Mouse is moving 
       
   672     // after mouse press event
       
   673     m_dragEvent = true; 
       
   674 }
       
   675 
       
   676 /*!
       
   677     InfoWidget::spnDisplaySettingChanged() 
       
   678 */
       
   679 void InfoWidget::spnDisplaySettingChanged(int state)
       
   680 {
       
   681     DPRINT << ": state: " << state;
       
   682     if (state == Qt::Checked){
       
   683         m_preferences->setPreference(InfoWidgetPreferences::DisplaySpn, DISPLAY_SETTING_ON);
       
   684     } else {
       
   685         m_preferences->setPreference(InfoWidgetPreferences::DisplaySpn, DISPLAY_SETTING_OFF);
       
   686     }
       
   687 }
       
   688 
       
   689 /*!
       
   690     InfoWidget::mcnDisplaySettingChanged() 
       
   691 */
       
   692 void InfoWidget::mcnDisplaySettingChanged(int state)
       
   693 {
       
   694     DPRINT << ": state: " << state; 
       
   695     if (state == Qt::Checked){
       
   696         m_preferences->setPreference(InfoWidgetPreferences::DisplayMcn, DISPLAY_SETTING_ON);
       
   697     } else {
       
   698         m_preferences->setPreference(InfoWidgetPreferences::DisplayMcn, DISPLAY_SETTING_OFF);
       
   699     }
       
   700 }
       
   701 
       
   702 /*!
       
   703     InfoWidget::satDisplaySettingChanged() 
       
   704 */
       
   705 void InfoWidget::satDisplaySettingChanged(int state)
       
   706 {
       
   707     DPRINT << ": state: " << state; 
       
   708     if (state == Qt::Checked){
       
   709         m_preferences->setPreference(InfoWidgetPreferences::DisplaySatText, DISPLAY_SETTING_ON);
       
   710     } else {
       
   711         m_preferences->setPreference(InfoWidgetPreferences::DisplaySatText, DISPLAY_SETTING_OFF);
       
   712     }
       
   713 }
       
   714 
       
   715 /*!
       
   716     InfoWidget::mcnDisplay() 
       
   717     
       
   718     Getter function for Meta-object property "mcnDisplay"
       
   719 */
       
   720 QString InfoWidget::mcnDisplay()
       
   721 {
       
   722     DPRINT; 
       
   723     return m_preferences->preference(InfoWidgetPreferences::DisplayMcn); 
       
   724 }
       
   725 
       
   726 /*!
       
   727     InfoWidget::setMcnDisplay() 
       
   728     
       
   729     Setter function for Meta-object property "mcnDisplay"
       
   730 */
       
   731 void InfoWidget::setMcnDisplay(QString value)
       
   732 {
       
   733     DPRINT;
       
   734     m_preferences->setPreference(InfoWidgetPreferences::DisplayMcn, value);
       
   735     }
       
   736 
       
   737 /*!
       
   738     InfoWidget::homeZoneDisplay() 
       
   739     
       
   740     Getter function for Meta-object property "homeZoneDisplay"
       
   741 */
       
   742 QString InfoWidget::homeZoneDisplay()
       
   743 {
       
   744     DPRINT; 
       
   745     return m_preferences->preference(InfoWidgetPreferences::DisplayHomeZone); 
       
   746 }
       
   747 
       
   748 /*!
       
   749     InfoWidget::setHomeZoneDisplay()
       
   750     
       
   751     Setter function for Meta-object property "homeZoneDisplay" 
       
   752 */
       
   753 void InfoWidget::setHomeZoneDisplay(QString value)
       
   754 {
       
   755     DPRINT; 
       
   756     m_preferences->setPreference(InfoWidgetPreferences::DisplayHomeZone, value);
       
   757 }
       
   758 
       
   759 /*!
       
   760     InfoWidget::activeLineDisplay() 
       
   761     
       
   762     Getter function for Meta-object property "activeLineDisplay"
       
   763 */
       
   764 QString InfoWidget::activeLineDisplay()
       
   765 {
       
   766     DPRINT; 
       
   767     return m_preferences->preference(InfoWidgetPreferences::DisplayActiveLine);
       
   768 }
       
   769 
       
   770 /*!
       
   771     InfoWidget::setActiveLineDisplay() 
       
   772     
       
   773     Setter function for Meta-object property "activeLineDisplay"
       
   774 */
       
   775 void InfoWidget::setActiveLineDisplay(QString value)
       
   776 {
       
   777     DPRINT; 
       
   778     m_preferences->setPreference(InfoWidgetPreferences::DisplayActiveLine, value);
       
   779 }
       
   780 
       
   781 /*!
       
   782     InfoWidget::satDisplay()
       
   783     
       
   784     Getter function for Meta-object property "satDisplay" 
       
   785 */
       
   786 QString InfoWidget::satDisplay()
       
   787 {
       
   788     DPRINT; 
       
   789     return m_preferences->preference(InfoWidgetPreferences::DisplaySatText);
       
   790 }
       
   791 
       
   792 /*!
       
   793     InfoWidget::setSatDisplay()
       
   794     
       
   795     Setter function for Meta-object property "satDisplay" 
       
   796 */
       
   797 void InfoWidget::setSatDisplay(QString value)
       
   798 {
       
   799     DPRINT;
       
   800     m_preferences->setPreference(InfoWidgetPreferences::DisplaySatText, value);
       
   801 }
       
   802 
       
   803 /*!
       
   804     InfoWidget::spnDisplay()
       
   805     
       
   806     Getter function for Meta-object property "spnDisplay" 
       
   807 */
       
   808 QString InfoWidget::spnDisplay()
       
   809 {
       
   810     DPRINT; 
       
   811     return m_preferences->preference(InfoWidgetPreferences::DisplaySpn);
       
   812 }
       
   813 
       
   814 /*!
       
   815     InfoWidget::setSpnDisplay()
       
   816     
       
   817     Setter function for Meta-object property "spnDisplay" 
       
   818 */
       
   819 void InfoWidget::setSpnDisplay(QString value)
       
   820 {
       
   821     DPRINT;
       
   822     m_preferences->setPreference(InfoWidgetPreferences::DisplaySpn, value);
       
   823 }
       
   824 
       
   825 /*!
       
   826     InfoWidget::readPersistentPreferences()
       
   827     
       
   828     Read Meta-object properties and store to preference handler. 
       
   829     Restores preferences from previous session.   
       
   830 */
       
   831 bool InfoWidget::readPersistentPreferences()
       
   832 {
       
   833     DPRINT << ": IN";
       
   834     bool changed(false); 
       
   835     
       
   836     QString propertyValue;
       
   837     
       
   838     propertyValue = QObject::property("homeZoneDisplay").toString();
       
   839     m_preferences->setPreference(InfoWidgetPreferences::DisplayHomeZone, 
       
   840             propertyValue);
       
   841     
       
   842     propertyValue = QObject::property("mcnDisplay").toString();
       
   843     m_preferences->setPreference(InfoWidgetPreferences::DisplayMcn, 
       
   844             propertyValue);
       
   845     
       
   846     propertyValue = QObject::property("activeLineDisplay").toString();
       
   847     m_preferences->setPreference(InfoWidgetPreferences::DisplayActiveLine, 
       
   848             propertyValue);
       
   849     
       
   850     propertyValue = QObject::property("satDisplay").toString();
       
   851     m_preferences->setPreference(InfoWidgetPreferences::DisplaySatText, 
       
   852             propertyValue);
       
   853 
       
   854     propertyValue = QObject::property("spnDisplay").toString();
       
   855     m_preferences->setPreference(InfoWidgetPreferences::DisplaySpn, 
       
   856             propertyValue);
       
   857 
       
   858     // Check that at least one item is set visible and  
       
   859     // store preferences if true 
       
   860     if (m_preferences->validate()) {
       
   861         changed = m_preferences->storePreferences(); 
       
   862     } 
       
   863         
       
   864     DPRINT << ": OUT";
       
   865     return changed; 
       
   866 }
       
   867 
       
   868 /*!
       
   869     InfoWidget::initializeCheckBoxStates()
       
   870 */
       
   871 void InfoWidget::initializeCheckBoxStates()
       
   872 {
       
   873     DPRINT << ": IN";
       
   874 
       
   875     HbCheckBox *spnCheckBox = qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   876             InfoWidgetLayoutManager::RoleSpnCheckBox));
       
   877     if (spnCheckBox) {
       
   878     spnCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   879                 InfoWidgetPreferences::DisplaySpn));
       
   880     }
       
   881     
       
   882     HbCheckBox *mcnCheckBox = qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   883             InfoWidgetLayoutManager::RoleMcnCheckBox));
       
   884     if (mcnCheckBox) {
       
   885         mcnCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   886                 InfoWidgetPreferences::DisplayMcn));
       
   887     }
       
   888     
       
   889     HbCheckBox *satTextCheckBox = qobject_cast<HbCheckBox *>(m_layoutManager->getWidget(
       
   890             InfoWidgetLayoutManager::RoleSatTextCheckBox));
       
   891     if (satTextCheckBox) {
       
   892         satTextCheckBox->setChecked(m_preferences->isPreferenceSet(
       
   893                 InfoWidgetPreferences::DisplaySatText));
       
   894     }
       
   895         
       
   896     DPRINT << ": OUT"; 
       
   897 }
       
   898 
       
   899 /*!
       
   900     InfoWidget::settingsEditingFinished()
       
   901 */
       
   902 void InfoWidget::settingsEditingFinished()
       
   903 {
       
   904     DPRINT << ": IN";
       
   905     
       
   906     // Save settings data if validation succeeds 
       
   907     if (m_preferences->validate()) {
       
   908         DPRINT << ": switching to info display";
       
   909         
       
   910         // Store preferences if changed 
       
   911         if (m_preferences->storePreferences()) {
       
   912             // Signal Homescreen FW   
       
   913             emit setPreferences(
       
   914                     m_preferences->preferenceNames());
       
   915             }
       
   916         
       
   917         // ToDo: do only if settings have really changed 
       
   918         m_layoutManager->reloadWidgets(
       
   919                 InfoWidgetLayoutManager::InfoDisplay);
       
   920 
       
   921         // Switch to info display 
       
   922         layoutInfoDisplay();
       
   923         updateInfoDisplay();
       
   924         
       
   925     } else {
       
   926         DPRINT << ": staying in settings display";    
       
   927         // Display warning note
       
   928         settingsValidationFailed(); 
       
   929         
       
   930         // Restore check box states 
       
   931         initializeCheckBoxStates(); 
       
   932     }
       
   933     
       
   934     DPRINT << ": OUT";
       
   935 }
       
   936 
       
   937 /*!
       
   938     InfoWidget::startChanges()
       
   939 */
       
   940 void InfoWidget::startChanges()
       
   941 {
       
   942     DPRINT;
       
   943     m_layoutChanging = true; 
       
   944 }
       
   945 
       
   946 /*!
       
   947     InfoWidget::endChanges()
       
   948 */
       
   949 void InfoWidget::endChanges()
       
   950 {
       
   951     DPRINT;
       
   952     m_layoutChanging = false; 
       
   953 }
       
   954 
       
   955 /*!
       
   956    \reimp
       
   957 */
       
   958 void InfoWidget::changeEvent(QEvent *event)
       
   959 {
       
   960    DPRINT << ": IN";
       
   961    
       
   962    if (event->type() == HbEvent::ThemeChanged) {
       
   963        DPRINT << ": HbEvent::ThemeChanged";
       
   964        m_backGroundColor = HbColorScheme::color(
       
   965                BACKGROUND_COLOR_GROUP_ID);
       
   966        if (!m_backGroundColor.isValid()) {
       
   967            m_backGroundColor = Qt::black; 
       
   968        }
       
   969    }
       
   970    HbWidget::changeEvent(event);
       
   971    
       
   972    DPRINT << ": OUT";
       
   973 }
       
   974 
       
   975 /*!
       
   976    InfoWidget::settingsValidationFailed()
       
   977 */
       
   978 void InfoWidget::settingsValidationFailed()
       
   979 {
       
   980    DPRINT << ": IN";
       
   981    
       
   982    if (m_layoutManager->currentDisplayRole() == 
       
   983                   InfoWidgetLayoutManager::SettingsDisplay) {
       
   984        HbMessageBox::warning(
       
   985                hbTrId("txt_operatorwidget_info_select_one"));
       
   986    }
       
   987 
       
   988    DPRINT << ": OUT";
       
   989 }
       
   990 
       
   991 
       
   992 // End of File. 
       
   993