calendarui/views/dayview/src/calendayview.cpp
changeset 55 2c54b51f39c4
parent 45 b6db4fd4947b
child 57 bb2d3e476f29
equal deleted inserted replaced
51:0b38fc5b94c6 55:2c54b51f39c4
    13  *
    13  *
    14  * Description: CalenDayView class definition.
    14  * Description: CalenDayView class definition.
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    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 <hbaction.h>
    23 #include <hbaction.h>
    23 #include <hbmenu.h>
    24 #include <hbmenu.h>
    24 #include <hbmainwindow.h>
    25 #include <hbmainwindow.h>
    25 #include <hbmodeliterator.h>
    26 #include <hbmodeliterator.h>
    26 #include <hbstyleloader.h>
    27 #include <hbstyleloader.h>
    27 #include <hbgroupbox.h>
    28 #include <hbgroupbox.h>
    28 #include <hbextendedlocale.h>
    29 #include <hbextendedlocale.h>
    29 #include <agendautil.h>
    30 #include <agendautil.h>
    30 //user includes
    31 
       
    32 // User includes
    31 #include "calendayview.h"
    33 #include "calendayview.h"
       
    34 #include "calencommon.h"
    32 #include "calencontext.h"
    35 #include "calencontext.h"
    33 #include "calenservices.h"
    36 #include "calenservices.h"
    34 #include "calendocloader.h"
    37 #include "calendocloader.h"
    35 #include "calendateutils.h" //useful date/time utils
    38 #include "calendateutils.h" //useful date/time utils
    36 #include "calendaycontentscrollarea.h"
    39 #include "calendaycontentscrollarea.h"
    49 // Constructor.
    52 // Constructor.
    50 // -----------------------------------------------------------------------------
    53 // -----------------------------------------------------------------------------
    51 //
    54 //
    52 CalenDayView::CalenDayView(MCalenServices &services) :
    55 CalenDayView::CalenDayView(MCalenServices &services) :
    53     CalenNativeView(services), mContentScrollArea(NULL), mContentWidget(NULL),
    56     CalenNativeView(services), mContentScrollArea(NULL), mContentWidget(NULL),
    54     mHourScrollArea(NULL), mSettingsManager(NULL),
    57         mHourScrollArea(NULL), mVLayout(NULL), mDocLoader(NULL), mIsLaunching(
    55     mRegionalInfo(XQSettingsKey::TargetCentralRepository, KCRUidCalendar, 
    58             true), mSettingsManager(NULL), mRegionalInfo(
    56             KCalendarShowRegionalInfo), 
    59             XQSettingsKey::TargetCentralRepository, KCRUidCalendar,
    57     mServices(services), mRegionalInfoGroupBox(NULL), mGoToTodayMenuAction(NULL)
    60             KCalendarShowRegionalInfo), mServices(services),
       
    61         mRegionalInfoGroupBox(NULL), mGoToTodayMenuAction(NULL)
    58 {
    62 {
    59     setupMenu();
    63     setupMenu();
    60     
    64 
    61     // Create model manager
    65     // Create model manager
    62     mModelManager = new CalenDayModelManager(mServices, true, this);   
    66     mModelManager = new CalenDayModelManager(mServices, true, this);
    63     
       
    64     mVLayout = new QGraphicsLinearLayout(Qt::Vertical, NULL);
       
    65     mVLayout->setContentsMargins(0.0, 0.0, 0.0, 0.0);
       
    66     mVLayout->setSpacing(0.0);    
       
    67       
       
    68     // Create heading label and insert into layout
       
    69     mHeadingLabel = new HbGroupBox();
       
    70     HbEffect::add(mHeadingLabel, ":/fade_out.fxml", "fadeOut");
       
    71     HbEffect::add(mHeadingLabel, ":/fade_in.fxml", "fadeIn");
       
    72     
       
    73     mSettingsManager = new XQSettingsManager(this);
    67     mSettingsManager = new XQSettingsManager(this);
    74 
       
    75     // Add day info
       
    76     mVLayout->addItem(mHeadingLabel);
       
    77     
       
    78     //show regional info if set so
       
    79     showRegionalInformationFadeIn();
       
    80     mSettingsManager->startMonitoring(mRegionalInfo);
    68     mSettingsManager->startMonitoring(mRegionalInfo);
    81     
       
    82     // Put hour scroll area and content scroll area into horizontal layout
       
    83     QGraphicsLinearLayout *hLayout = new QGraphicsLinearLayout(Qt::Horizontal, NULL);
       
    84     hLayout->setContentsMargins(0.0, 0.0, 0.0, 0.0);
       
    85     hLayout->setSpacing(0.0);
       
    86     
       
    87     // Create scroll area for content (events)
       
    88     mContentScrollArea = new CalenDayContentScrollArea(this);
       
    89 
       
    90     // Create and apply central widget for scroll area
       
    91     mContentWidget = new CalenDayContentWidget(*mModelManager, mContentScrollArea);
       
    92     mContentScrollArea->setContentWidget(mContentWidget);
       
    93     
       
    94     // Create scroll area for hour elements
       
    95     mHourScrollArea = new CalenDayHourScrollArea(this);
       
    96         
       
    97     hLayout->addItem(mHourScrollArea);
       
    98     hLayout->addItem(mContentScrollArea);
       
    99     
       
   100     mVLayout->addItem(hLayout);
       
   101     setLayout(mVLayout);
       
   102     
       
   103     setupSlots();
       
   104 
    69 
   105     //setup Back functionality
    70     //setup Back functionality
   106     if (ECalenDayView != mServices.getFirstView()) {
    71     if (ECalenDayView != mServices.getFirstView()) {
   107         HbAction* action = new HbAction(Hb::BackNaviAction, this);
    72         HbAction* action = new HbAction(Hb::BackNaviAction, this);
   108         setNavigationAction(action);
    73         setNavigationAction(action);
   112 
    77 
   113     HbStyleLoader::registerFilePath(":/calendayhourelement.css");
    78     HbStyleLoader::registerFilePath(":/calendayhourelement.css");
   114     HbStyleLoader::registerFilePath(":/calendayhourelement.widgetml");
    79     HbStyleLoader::registerFilePath(":/calendayhourelement.widgetml");
   115     HbStyleLoader::registerFilePath(":/calendayitem.css");
    80     HbStyleLoader::registerFilePath(":/calendayitem.css");
   116     HbStyleLoader::registerFilePath(":/calendayitem.widgetml");
    81     HbStyleLoader::registerFilePath(":/calendayitem.widgetml");
       
    82     HbStyleLoader::registerFilePath(":/calendayeventspane.css");
   117 }
    83 }
   118 
    84 
   119 // -----------------------------------------------------------------------------
    85 // -----------------------------------------------------------------------------
   120 // ~CalenDayView()
    86 // ~CalenDayView()
   121 // Destructor.
    87 // Destructor.
   122 // -----------------------------------------------------------------------------
    88 // -----------------------------------------------------------------------------
   123 //
    89 //
   124 CalenDayView::~CalenDayView()
    90 CalenDayView::~CalenDayView()
   125 {
    91 {
   126 	mSettingsManager->stopMonitoring(mRegionalInfo);
    92     mSettingsManager->stopMonitoring(mRegionalInfo);
       
    93     if (mDocLoader) {
       
    94         delete mDocLoader;
       
    95         mDocLoader = NULL;
       
    96     }
   127 }
    97 }
   128 
    98 
   129 // -----------------------------------------------------------------------------
    99 // -----------------------------------------------------------------------------
   130 // onLocaleChanged()
   100 // onLocaleChanged()
   131 // Handles locale change.
   101 // Handles locale change.
   160     }
   130     }
   161     else if(mGoToTodayMenuAction) {
   131     else if(mGoToTodayMenuAction) {
   162         mGoToTodayMenuAction->setVisible(true);
   132         mGoToTodayMenuAction->setVisible(true);
   163     }
   133     }
   164     
   134     
   165 	setupViewport();
   135     // Call async. if the view is loaded first time (fix to ou1cimx1#482516)
       
   136     if (mIsLaunching) {
       
   137         mIsLaunching = false;
       
   138         QMetaObject::invokeMethod(this, "setupViewport", Qt::QueuedConnection);
       
   139     } else {
       
   140         setupViewport();
       
   141     }
   166 	
   142 	
   167     populationComplete();
   143     populationComplete();
   168 }
   144 }
   169 
   145 
   170 // -----------------------------------------------------------------------------
   146 // -----------------------------------------------------------------------------
   194 // Sets up the view accroding to the 'xml'
   170 // Sets up the view accroding to the 'xml'
   195 // -----------------------------------------------------------------------------
   171 // -----------------------------------------------------------------------------
   196 //
   172 //
   197 void CalenDayView::setupView(CalenDocLoader* docLoader)
   173 void CalenDayView::setupView(CalenDocLoader* docLoader)
   198 {
   174 {
   199     Q_UNUSED( docLoader )
   175     // Store document loader for further use
       
   176     mDocLoader = docLoader;
       
   177 
       
   178     // Get vertical layout from day view
       
   179     mVLayout = static_cast<QGraphicsLinearLayout *> (this->layout());
       
   180 
       
   181     // Set up day info
       
   182     mHeadingLabel = qobject_cast<HbGroupBox *> (mDocLoader->findWidget(
       
   183         CALEN_DAYVIEW_DAYINFO));
       
   184     HbEffect::add(mHeadingLabel, ":/fade_out.fxml", "fadeOut");
       
   185     HbEffect::add(mHeadingLabel, ":/fade_in.fxml", "fadeIn");
       
   186 
       
   187     // Set up hour scroll area
       
   188     mHourScrollArea
       
   189         = static_cast<CalenDayHourScrollArea *> (mDocLoader->findWidget(
       
   190             CALEN_DAYVIEW_HOURSCROLLAREA));
       
   191 
       
   192     // Set up content scroll area
       
   193     mContentScrollArea
       
   194         = static_cast<CalenDayContentScrollArea *> (mDocLoader->findWidget(
       
   195             CALEN_DAYVIEW_CONTENTSCROLLAREA));
       
   196     mContentWidget = new CalenDayContentWidget(*mModelManager, NULL);
       
   197     mContentScrollArea->setContentWidget(mContentWidget);
       
   198 
       
   199     // Set up regional info if variant is correct
       
   200     showRegionalInformationFadeIn();
       
   201 
       
   202     setupSlots();
   200 }
   203 }
   201 
   204 
   202 //private slots
   205 //private slots
   203 
   206 
   204 // -----------------------------------------------------------------------------
   207 // -----------------------------------------------------------------------------
   339     QDateTime dateTime(mDate);
   342     QDateTime dateTime(mDate);
   340     TRAP_IGNORE(
   343     TRAP_IGNORE(
   341         dateTime.setTime(mServices.Context().defaultCalTimeForViewsL().time());
   344         dateTime.setTime(mServices.Context().defaultCalTimeForViewsL().time());
   342         mServices.Context().setFocusDateAndTime(dateTime);
   345         mServices.Context().setFocusDateAndTime(dateTime);
   343         mServices.IssueCommandL(ECalenNewMeeting)
   346         mServices.IssueCommandL(ECalenNewMeeting)
   344             );
   347     );
   345 }
   348 }
   346 
   349 
   347 // -----------------------------------------------------------------------------
   350 // -----------------------------------------------------------------------------
   348 // runGoToToday()
   351 // runGoToToday()
   349 // -----------------------------------------------------------------------------
   352 // -----------------------------------------------------------------------------
   416 // ----------------------------------------------------------------------------
   419 // ----------------------------------------------------------------------------
   417 // CalenDayView::showHideRegionalInformationChanged
   420 // CalenDayView::showHideRegionalInformationChanged
   418 // To Show and hide regional plugin label depends upon settings
   421 // To Show and hide regional plugin label depends upon settings
   419 // ----------------------------------------------------------------------------
   422 // ----------------------------------------------------------------------------
   420 //
   423 //
   421 void CalenDayView::showHideRegionalInformationChanged(const XQSettingsKey& key, const QVariant&)
   424 void CalenDayView::showHideRegionalInformationChanged(
   422 	{
   425     const XQSettingsKey& key,
   423 	if (key.key() == mRegionalInfo.key())
   426     const QVariant&)
   424 		{
   427 {
   425 		int showRegionalInfo =
   428     if (key.key() == mRegionalInfo.key()) {
   426 				mSettingsManager->readItemValue(mRegionalInfo).toUInt();
   429         int showRegionalInfo =
   427 
   430             mSettingsManager->readItemValue(mRegionalInfo).toUInt();
   428 		if (showRegionalInfo)
   431 
   429 			{
   432         if (showRegionalInfo) {
   430 			QString *pluginString = pluginText();
   433             QString *pluginString = pluginText();
   431 			if (pluginString)
   434             if (pluginString) {
   432 				{
   435                 if (!mRegionalInfoGroupBox) {
   433 				if (!mRegionalInfoGroupBox)
   436                     mRegionalInfoGroupBox = qobject_cast<HbGroupBox *> (
   434 					{
   437                         mDocLoader->findWidget(CALEN_DAYVIEW_REGIONALINFO));
   435 					mRegionalInfoGroupBox = new HbGroupBox();
   438                     CalenPluginLabel *regionalInfo = new CalenPluginLabel(
   436 					CalenPluginLabel *regionalInfo = new CalenPluginLabel(
   439                         mServices, this);
   437 							mServices, this);
   440                     HbEffect::add(mRegionalInfoGroupBox, ":/fade_out.fxml",
   438 					HbEffect::add(mRegionalInfoGroupBox, ":/fade_out.fxml",
   441                         "fadeOut");
   439 							"fadeOut");
   442                     HbEffect::add(mRegionalInfoGroupBox, ":/fade_in.fxml",
   440 					HbEffect::add(mRegionalInfoGroupBox, ":/fade_in.fxml", "fadeIn");
   443                         "fadeIn");
   441 
   444                     regionalInfo->setContentsMargins(1, 1, 1, 1);
   442 					// add margins to calenpluginlabel
   445                     mRegionalInfoGroupBox->setContentWidget(regionalInfo);
   443 
   446                 }
   444 					HbStyle style;
   447 
   445 					HbDeviceProfile deviceProfile;
   448                 if (pluginEnabled()) {
   446 					qreal marginLeft = 0.0;
   449                     HbLabel *pluginInfoLabel = qobject_cast<HbLabel *> (
   447 					qreal marginRight = 0.0;
   450                         mRegionalInfoGroupBox->contentWidget());
   448 					qreal marginTop = 0.0;
   451 
   449 					qreal marginBottom = 0.0;
   452                     pluginInfoLabel->setPlainText(*pluginString);
   450 					style.parameter(QString("hb-param-margin-gene-left"), marginLeft, deviceProfile);
   453                     mVLayout->insertItem(1, mRegionalInfoGroupBox);
   451 					style.parameter(QString("hb-param-margin-gene-right"), marginRight, deviceProfile);
   454                 }
   452 					style.parameter(QString("hb-param-margin-gene-top"), marginTop, deviceProfile);
   455             }
   453 					style.parameter(QString("hb-param-margin-gene-bottom"), marginBottom, deviceProfile);
   456         }
   454 
   457         else {
   455 					regionalInfo->setContentsMargins(1, 1, 1, 1);
   458             if (mRegionalInfoGroupBox) {
   456 
   459                 mVLayout->removeItem(mRegionalInfoGroupBox);
   457 					//	qreal width = mRegionalInfoGroupBox->size().width();
   460                 delete mRegionalInfoGroupBox;
   458 					//	qreal height = mRegionalInfoGroupBox->size().height() + marginTop + marginBottom;
   461                 mRegionalInfoGroupBox = NULL;
   459 
   462             }
   460 					//	mRegionalInfoGroupBox->resize(width, height);
   463         }
   461 
   464     }
   462 					mRegionalInfoGroupBox->setContentWidget(regionalInfo);
   465 }
   463 					}
       
   464 
       
   465 				if (pluginEnabled())
       
   466 					{
       
   467 					HbLabel *pluginInfoLabel = qobject_cast<HbLabel *> (
       
   468 							mRegionalInfoGroupBox->contentWidget());
       
   469 
       
   470 					pluginInfoLabel->setPlainText(*pluginString);
       
   471 
       
   472 					mVLayout->insertItem(1, mRegionalInfoGroupBox);
       
   473 					}
       
   474 				}
       
   475 			}
       
   476 		else
       
   477 			{
       
   478 
       
   479 			if (mRegionalInfoGroupBox)
       
   480 				{
       
   481 				mVLayout->removeItem(mRegionalInfoGroupBox);
       
   482 				delete mRegionalInfoGroupBox;
       
   483 				mRegionalInfoGroupBox = NULL;
       
   484 				}
       
   485 			}
       
   486 		}
       
   487 	}
       
   488 
   466 
   489 // ----------------------------------------------------------------------------
   467 // ----------------------------------------------------------------------------
   490 // CalenDayView::setupViewport
   468 // CalenDayView::setupViewport
   491 // Scrolls view according to current day and events
   469 // Scrolls view according to current day and events
   492 // ----------------------------------------------------------------------------
   470 // ----------------------------------------------------------------------------
   493 //
   471 //
   494 void CalenDayView::setupViewport()
   472 void CalenDayView::setupViewport()
   495 {
   473 {
   496     QDateTime currentTime = QDateTime::currentDateTime();
   474     QDateTime currentTime = QDateTime::currentDateTime();
   497     
   475 
   498     //Filter flags (only timed events)
       
   499 	AgendaUtil::FilterFlags filter = AgendaUtil::FilterFlags(
       
   500 			AgendaUtil::IncludeAppointments );
       
   501 	QList<AgendaEntry> list;
       
   502 	// Fetch the instance list from the agenda interface
       
   503 	list = mServices.agendaInterface()->fetchEntriesInRange(currentTime, currentTime, filter);
       
   504     
       
   505     // If we have event in current day and hour, scroll to this event
   476     // If we have event in current day and hour, scroll to this event
   506     if(mDate.date() == currentTime.date() && !list.isEmpty()){
   477     if (mDate.date() == currentTime.date()){
   507     	int hourToScrollTo(list.first().startTime().time().hour());
   478 
   508         mHourScrollArea->scrollToHour(hourToScrollTo);
   479         QDateTime midnight = currentTime;
   509     }
   480         midnight.setTime(QTime(23, 59));
   510     else{
   481 
       
   482         //Filter flags (only timed events)
       
   483         AgendaUtil::FilterFlags filter = AgendaUtil::FilterFlags(AgendaUtil::IncludeAppointments);
       
   484         QList<AgendaEntry> list;
       
   485         // Fetch the instance list from the agenda interface
       
   486         list = mServices.agendaInterface()->fetchEntriesInRange(currentTime, midnight, filter);
       
   487 
       
   488         if(!list.isEmpty()){
       
   489             int hourToScrollTo(list.first().startTime().time().hour());
       
   490             mHourScrollArea->scrollToHour(hourToScrollTo);           
       
   491         }
       
   492         else{
       
   493             mHourScrollArea->scrollToHour(currentTime.time().hour());
       
   494         }
       
   495     }
       
   496     else {
   511         //Scroll view to 7am
   497         //Scroll view to 7am
   512         mHourScrollArea->scrollToHour(7);
   498         mHourScrollArea->scrollToHour(7);
   513     }
   499     }
   514 }
   500 }
   515 
   501