calendarui/views/dayview/src/calendayview.cpp
changeset 63 a3cb48f6c889
parent 57 bb2d3e476f29
child 64 1881ad52dc45
equal deleted inserted replaced
57:bb2d3e476f29 63:a3cb48f6c889
    18 // System includes
    18 // System includes
    19 #include <QDateTime>
    19 #include <QDateTime>
    20 #include <QGraphicsLinearLayout>
    20 #include <QGraphicsLinearLayout>
    21 #include <xqsettingsmanager.h>
    21 #include <xqsettingsmanager.h>
    22 #include <HbWidget>
    22 #include <HbWidget>
    23 #include <hbaction.h>
    23 #include <HbFrameItem>
    24 #include <hbmenu.h>
    24 #include <HbInstance>
    25 #include <hbmainwindow.h>
    25 #include <HbAction>
    26 #include <hbmodeliterator.h>
    26 #include <HbMenu>
    27 #include <hbstyleloader.h>
    27 #include <HbMainWindow>
    28 #include <hbgroupbox.h>
    28 #include <HbModelIterator>
    29 #include <hbextendedlocale.h>
    29 #include <HbStyleLoader>
       
    30 #include <HbGroupBox>
       
    31 #include <HbExtendedLocale>
    30 #include <agendautil.h>
    32 #include <agendautil.h>
    31 
    33 
    32 // User includes
    34 // User includes
    33 #include "calendayview.h"
    35 #include "calendayview.h"
    34 #include "calencommon.h"
    36 #include "calencommon.h"
    42 #include "calendaymodelmanager.h"
    44 #include "calendaymodelmanager.h"
    43 #include "CalenUid.h"
    45 #include "CalenUid.h"
    44 #include "CalendarPrivateCRKeys.h"
    46 #include "CalendarPrivateCRKeys.h"
    45 #include "calenpluginlabel.h"
    47 #include "calenpluginlabel.h"
    46 #include "calendaymodel.h"
    48 #include "calendaymodel.h"
       
    49 #include "calendayutils.h"
    47 
    50 
    48 //constants
    51 //constants
    49 
    52 
    50 
    53 
    51 /*!
    54 /*!
    52  \brief Constructor
    55  \brief Constructor
    53 */
    56 */
    54 CalenDayView::CalenDayView(MCalenServices &services) :
    57 CalenDayView::CalenDayView(MCalenServices &services) :
    55     CalenNativeView(services), mContentScrollArea(NULL), mContentWidget(NULL),
    58     CalenNativeView(services), mContentScrollArea(NULL), mContentWidget(NULL),
    56         mHourScrollArea(NULL), mVLayout(NULL), mDocLoader(NULL), mIsLaunching(
    59         mHourScrollArea(NULL), mVLayout(NULL), mMainContainer(NULL),
    57             true), mSettingsManager(NULL), mRegionalInfo(
    60         mDocLoader(NULL), mIsLaunching(true), mSettingsManager(NULL),
    58             XQSettingsKey::TargetCentralRepository, KCRUidCalendar,
    61         mRegionalInfoKey(XQSettingsKey::TargetCentralRepository,
    59             KCalendarShowRegionalInfo), mServices(services),
    62             KCRUidCalendar, KCalendarShowRegionalInfo), mServices(services),
    60         mRegionalInfoGroupBox(NULL), mGoToTodayMenuAction(NULL)
    63         mRegionalInfoGroupBox(NULL), mGoToTodayMenuAction(NULL), mBg(NULL)
    61 {
    64 {
    62     setupMenu();
    65     setupMenu();
    63 
    66 
    64     // Create model manager
    67     // Create model manager
    65     mModelManager = new CalenDayModelManager(mServices, true, this);
    68     mModelManager = new CalenDayModelManager(mServices, true, this);
    66     mSettingsManager = new XQSettingsManager(this);
    69     mSettingsManager = new XQSettingsManager(this);
    67     mSettingsManager->startMonitoring(mRegionalInfo);
    70     mSettingsManager->startMonitoring(mRegionalInfoKey);
    68 
    71 
    69     //setup Back functionality
    72     //setup Back functionality
    70     if (ECalenDayView != mServices.getFirstView()) {
    73     if (ECalenDayView != mServices.getFirstView()) {
    71         HbAction* action = new HbAction(Hb::BackNaviAction, this);
    74         HbAction* action = new HbAction(Hb::BackNaviAction, this);
    72         setNavigationAction(action);
    75         setNavigationAction(action);
    85 /*!
    88 /*!
    86  \brief Destructor
    89  \brief Destructor
    87 */
    90 */
    88 CalenDayView::~CalenDayView()
    91 CalenDayView::~CalenDayView()
    89 {
    92 {
    90     mSettingsManager->stopMonitoring(mRegionalInfo);
    93     mSettingsManager->stopMonitoring(mRegionalInfoKey);
       
    94     
       
    95     if (mRegionalInfoGroupBox) {
       
    96         delete mRegionalInfoGroupBox;
       
    97         mRegionalInfoGroupBox = NULL;
       
    98     }
       
    99     
    91     if (mDocLoader) {
   100     if (mDocLoader) {
    92         delete mDocLoader;
   101         delete mDocLoader;
    93         mDocLoader = NULL;
   102         mDocLoader = NULL;
    94     }
   103     }
    95 }
   104 }
   173     // Set up day info
   182     // Set up day info
   174     mHeadingLabel = qobject_cast<HbGroupBox *> (mDocLoader->findWidget(
   183     mHeadingLabel = qobject_cast<HbGroupBox *> (mDocLoader->findWidget(
   175         CALEN_DAYVIEW_DAYINFO));
   184         CALEN_DAYVIEW_DAYINFO));
   176     HbEffect::add(mHeadingLabel, ":/fade_out.fxml", "fadeOut");
   185     HbEffect::add(mHeadingLabel, ":/fade_out.fxml", "fadeOut");
   177     HbEffect::add(mHeadingLabel, ":/fade_in.fxml", "fadeIn");
   186     HbEffect::add(mHeadingLabel, ":/fade_in.fxml", "fadeIn");
       
   187     
       
   188     // Set up main container for hour elements/content area
       
   189     mMainContainer = qobject_cast<HbWidget *> (mDocLoader->findWidget(
       
   190         CALEN_DAYVIEW_CONTENTWIDGET));
       
   191     if (Qt::Vertical == CalenDayUtils::instance()->orientation()) {
       
   192         mBg = new HbFrameItem(KCalenBackgroundColorPortrait,
       
   193             HbFrameDrawer::OnePiece, this);
       
   194     }
       
   195     else {
       
   196         mBg = new HbFrameItem(KCalenBackgroundColorLandscape,
       
   197             HbFrameDrawer::OnePiece, this);
       
   198     }
       
   199     mMainContainer->setBackgroundItem(mBg);
   178 
   200 
   179     // Set up hour scroll area
   201     // Set up hour scroll area
   180     mHourScrollArea
   202     mHourScrollArea
   181         = static_cast<CalenDayHourScrollArea *> (mDocLoader->findWidget(
   203         = static_cast<CalenDayHourScrollArea *> (mDocLoader->findWidget(
   182             CALEN_DAYVIEW_HOURSCROLLAREA));
   204             CALEN_DAYVIEW_HOURSCROLLAREA));
   183 
   205 
   184     // Set up content scroll area
   206     // Set up content scroll area
   185     mContentScrollArea
   207     mContentScrollArea
   186         = static_cast<CalenDayContentScrollArea *> (mDocLoader->findWidget(
   208         = static_cast<CalenDayContentScrollArea *> (mDocLoader->findWidget(
   187             CALEN_DAYVIEW_CONTENTSCROLLAREA));
   209             CALEN_DAYVIEW_CONTENTSCROLLAREA));
   188     mContentWidget = new CalenDayContentWidget(*mModelManager, NULL);
   210     // Pass parent object to mContentWidget to install event filters on parent
       
   211     mContentWidget = new CalenDayContentWidget(*mModelManager, mContentScrollArea);
   189     mContentScrollArea->setContentWidget(mContentWidget);
   212     mContentScrollArea->setContentWidget(mContentWidget);
   190 
   213 
       
   214     setupSlots();
       
   215     
   191     // Set up regional info if variant is correct
   216     // Set up regional info if variant is correct
   192     showRegionalInformationFadeIn();
   217     showRegionalInformationFadeIn();
   193 
       
   194     setupSlots();
       
   195 }
   218 }
   196 
   219 
   197 //private slots
   220 //private slots
   198 
   221 
   199 /*!
   222 /*!
   227         mGoToTodayMenuAction->setVisible(true);
   250         mGoToTodayMenuAction->setVisible(true);
   228     }
   251     }
   229     
   252     
   230     // Triggers fading effect for heading label.
   253     // Triggers fading effect for heading label.
   231     HbEffect::start(mHeadingLabel, "fadeOut", this, "setHeadingText");
   254     HbEffect::start(mHeadingLabel, "fadeOut", this, "setHeadingText");
   232     HbEffect::start(mRegionalInfoGroupBox, "fadeOut", this, "showRegionalInformation");
   255     if (mRegionalInfoGroupBox) {
       
   256         HbEffect::start(mRegionalInfoGroupBox, "fadeOut", this,
       
   257             "showRegionalInformation");
       
   258     }
   233     
   259     
   234     mServices.Context().setFocusDate(mDate);
   260     mServices.Context().setFocusDate(mDate);
   235 }
   261 }
   236 
   262 
   237 /*!
   263 /*!
   312         SIGNAL(widgetsRelayoutFinished(CalenScrollDirection)), this,
   338         SIGNAL(widgetsRelayoutFinished(CalenScrollDirection)), this,
   313         SLOT(dayChanged(CalenScrollDirection)));
   339         SLOT(dayChanged(CalenScrollDirection)));
   314 
   340 
   315     connect(mContentWidget, SIGNAL(scrollPositionChanged(const QPointF &)),
   341     connect(mContentWidget, SIGNAL(scrollPositionChanged(const QPointF &)),
   316         mHourScrollArea, SLOT(scrollVertically(const QPointF &)));
   342         mHourScrollArea, SLOT(scrollVertically(const QPointF &)));
   317     
   343 
   318     connect(mHourScrollArea, SIGNAL(scrollPositionChanged(const QPointF &)),
   344     connect(mHourScrollArea, SIGNAL(scrollPositionChanged(const QPointF &)),
   319         mContentWidget, SLOT(widgetScrolled(const QPointF &)));
   345         mContentWidget, SLOT(widgetScrolled(const QPointF &)));
   320     
   346 
       
   347     connect(CalenDayUtils::instance()->mainWindow(),
       
   348         SIGNAL(orientationChanged(Qt::Orientation)), this,
       
   349         SLOT(orientationChanged(Qt::Orientation)));
       
   350 
   321     connect(mSettingsManager, SIGNAL(valueChanged(XQSettingsKey, QVariant)),
   351     connect(mSettingsManager, SIGNAL(valueChanged(XQSettingsKey, QVariant)),
   322         this, SLOT(showHideRegionalInformationChanged(XQSettingsKey, QVariant)));
   352         this, SLOT(showHideRegionalInformationChanged(XQSettingsKey, QVariant)));
   323 }
   353 }
   324 
   354 
   325 /*!
   355 /*!
   398 /*!
   428 /*!
   399    \brief Runs effect on lunar data label and change text according to date change.
   429    \brief Runs effect on lunar data label and change text according to date change.
   400 */
   430 */
   401 void CalenDayView::showRegionalInformationFadeIn()
   431 void CalenDayView::showRegionalInformationFadeIn()
   402 {
   432 {
   403 	showHideRegionalInformationChanged(mRegionalInfo, 3);
   433 	showHideRegionalInformationChanged(mRegionalInfoKey, 3);
   404 	HbEffect::start(mRegionalInfoGroupBox, "fadeIn");
   434 	if (mRegionalInfoGroupBox) {
       
   435 	    HbEffect::start(mRegionalInfoGroupBox, "fadeIn");
       
   436 	}
   405 }
   437 }
   406 
   438 
   407 /*!
   439 /*!
   408    \brief To Show and hide regional plugin label depends upon settings.
   440    \brief To Show and hide regional plugin label depends upon settings.
   409 */
   441 */
   410 void CalenDayView::showHideRegionalInformationChanged(
   442 void CalenDayView::showHideRegionalInformationChanged(
   411     const XQSettingsKey& key,
   443     const XQSettingsKey& key,
   412     const QVariant&)
   444     const QVariant&)
   413 {
   445 {
   414     if (key.key() == mRegionalInfo.key()) {
   446     if ((key.key() == mRegionalInfoKey.key()) && pluginEnabled()) {
   415         int showRegionalInfo =
   447         int showRegionalInfo =
   416             mSettingsManager->readItemValue(mRegionalInfo).toUInt();
   448             mSettingsManager->readItemValue(mRegionalInfoKey).toUInt();
   417 
       
   418         if (showRegionalInfo) {
   449         if (showRegionalInfo) {
       
   450             if (!mRegionalInfoGroupBox) {
       
   451                 mRegionalInfoGroupBox = new HbGroupBox();
       
   452                 CalenPluginLabel *regionalInfo = new CalenPluginLabel(
       
   453                     mServices, this);
       
   454                 regionalInfo->setFontSpec(HbFontSpec(HbFontSpec::Primary));
       
   455 
       
   456                 // Set margins in groupbox according to UI spec
       
   457                 HbStyle style;
       
   458                 HbDeviceProfile deviceProfile;
       
   459                 qreal leftMargin = 0.0;
       
   460                 qreal rightMargin = 0.0;
       
   461                 qreal topMargin = 0.0;
       
   462                 qreal bottomMargin = 0.0;
       
   463                 style.parameter(QString("hb-param-margin-gene-left"),
       
   464                     leftMargin, deviceProfile);
       
   465                 style.parameter(QString("hb-param-margin-gene-right"),
       
   466                     rightMargin, deviceProfile);
       
   467                 style.parameter(QString("hb-param-margin-gene-top"), topMargin,
       
   468                     deviceProfile);
       
   469                 style.parameter(QString("hb-param-margin-gene-bottom"),
       
   470                     bottomMargin, deviceProfile);
       
   471                 regionalInfo->setContentsMargins(leftMargin, topMargin,
       
   472                     rightMargin, bottomMargin);
       
   473                 mRegionalInfoGroupBox->setContentWidget(regionalInfo);
       
   474 
       
   475                 mVLayout->insertItem(1, mRegionalInfoGroupBox);
       
   476             }
   419             QString *pluginString = pluginText();
   477             QString *pluginString = pluginText();
   420             if (pluginString) {
   478             HbLabel *pluginInfoLabel = qobject_cast<HbLabel *> (
   421                 if (!mRegionalInfoGroupBox) {
   479                 mRegionalInfoGroupBox->contentWidget());
   422                     mRegionalInfoGroupBox = qobject_cast<HbGroupBox *> (
   480             pluginInfoLabel->setPlainText(*pluginString);
   423                         mDocLoader->findWidget(CALEN_DAYVIEW_REGIONALINFO));
       
   424                     CalenPluginLabel *regionalInfo = new CalenPluginLabel(
       
   425                         mServices, this);
       
   426                     HbEffect::add(mRegionalInfoGroupBox, ":/fade_out.fxml",
       
   427                         "fadeOut");
       
   428                     HbEffect::add(mRegionalInfoGroupBox, ":/fade_in.fxml",
       
   429                         "fadeIn");
       
   430                     regionalInfo->setContentsMargins(1, 1, 1, 1);
       
   431                     mRegionalInfoGroupBox->setContentWidget(regionalInfo);
       
   432                 }
       
   433 
       
   434                 if (pluginEnabled()) {
       
   435                     HbLabel *pluginInfoLabel = qobject_cast<HbLabel *> (
       
   436                         mRegionalInfoGroupBox->contentWidget());
       
   437 
       
   438                     pluginInfoLabel->setPlainText(*pluginString);
       
   439                     mVLayout->insertItem(1, mRegionalInfoGroupBox);
       
   440                 }
       
   441             }
       
   442         }
   481         }
   443         else {
   482         else {
   444             if (mRegionalInfoGroupBox) {
   483             if (mRegionalInfoGroupBox) {
   445                 mVLayout->removeItem(mRegionalInfoGroupBox);
   484                 mVLayout->removeItem(mRegionalInfoGroupBox);
   446                 delete mRegionalInfoGroupBox;
   485                 delete mRegionalInfoGroupBox;
   481         //Scroll view to 7am
   520         //Scroll view to 7am
   482         mHourScrollArea->scrollToHour(7);
   521         mHourScrollArea->scrollToHour(7);
   483     }
   522     }
   484 }
   523 }
   485 
   524 
       
   525 /*!
       
   526  \brief Slot which is called whenever the orientation of the device changes.
       
   527  
       
   528  Changes the backgroung graphic element when orientation chandes.
       
   529  
       
   530  \param orientation Current device orientation
       
   531  */
       
   532 void CalenDayView::orientationChanged(Qt::Orientation orientation)
       
   533 {
       
   534     if (Qt::Vertical == orientation) {
       
   535         mBg = new HbFrameItem(KCalenBackgroundColorPortrait,
       
   536             HbFrameDrawer::OnePiece, this);
       
   537     }
       
   538     else {
       
   539         mBg = new HbFrameItem(KCalenBackgroundColorLandscape,
       
   540             HbFrameDrawer::OnePiece, this);
       
   541     }
       
   542     mMainContainer->setBackgroundItem(mBg);
       
   543 }
       
   544 
   486 //End of File
   545 //End of File