calendarui/views/dayview/src/calendayview.cpp
author hgs
Tue, 05 Oct 2010 13:57:00 +0530
changeset 81 ce92091cbd61
parent 75 7ac58b2aae6f
child 83 5aadd1120515
permissions -rw-r--r--
201039
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
 * All rights reserved.
hgs
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
 *
hgs
parents:
diff changeset
     9
 * Initial Contributors:
hgs
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
 *
hgs
parents:
diff changeset
    12
 * Contributors:
hgs
parents:
diff changeset
    13
 *
hgs
parents:
diff changeset
    14
 * Description: CalenDayView class definition.
hgs
parents:
diff changeset
    15
 *
hgs
parents:
diff changeset
    16
 */
hgs
parents:
diff changeset
    17
55
hgs
parents: 45
diff changeset
    18
// System includes
45
hgs
parents:
diff changeset
    19
#include <QDateTime>
hgs
parents:
diff changeset
    20
#include <QGraphicsLinearLayout>
hgs
parents:
diff changeset
    21
#include <xqsettingsmanager.h>
55
hgs
parents: 45
diff changeset
    22
#include <HbWidget>
63
hgs
parents: 57
diff changeset
    23
#include <HbFrameItem>
hgs
parents: 57
diff changeset
    24
#include <HbInstance>
hgs
parents: 57
diff changeset
    25
#include <HbAction>
hgs
parents: 57
diff changeset
    26
#include <HbMenu>
hgs
parents: 57
diff changeset
    27
#include <HbMainWindow>
hgs
parents: 57
diff changeset
    28
#include <HbModelIterator>
hgs
parents: 57
diff changeset
    29
#include <HbStyleLoader>
hgs
parents: 57
diff changeset
    30
#include <HbGroupBox>
hgs
parents: 57
diff changeset
    31
#include <HbExtendedLocale>
75
hgs
parents: 70
diff changeset
    32
#include <HbModelIterator>
45
hgs
parents:
diff changeset
    33
#include <agendautil.h>
55
hgs
parents: 45
diff changeset
    34
hgs
parents: 45
diff changeset
    35
// User includes
45
hgs
parents:
diff changeset
    36
#include "calendayview.h"
55
hgs
parents: 45
diff changeset
    37
#include "calencommon.h"
45
hgs
parents:
diff changeset
    38
#include "calencontext.h"
hgs
parents:
diff changeset
    39
#include "calenservices.h"
hgs
parents:
diff changeset
    40
#include "calendocloader.h"
hgs
parents:
diff changeset
    41
#include "calendateutils.h" //useful date/time utils
hgs
parents:
diff changeset
    42
#include "calendaycontentscrollarea.h"
hgs
parents:
diff changeset
    43
#include "calendaycontentwidget.h"
hgs
parents:
diff changeset
    44
#include "calendayhourscrollarea.h"
75
hgs
parents: 70
diff changeset
    45
#include "calendayitemview.h"
45
hgs
parents:
diff changeset
    46
#include "calendaymodelmanager.h"
hgs
parents:
diff changeset
    47
#include "CalenUid.h"
hgs
parents:
diff changeset
    48
#include "CalendarPrivateCRKeys.h"
hgs
parents:
diff changeset
    49
#include "calenpluginlabel.h"
hgs
parents:
diff changeset
    50
#include "calendaymodel.h"
63
hgs
parents: 57
diff changeset
    51
#include "calendayutils.h"
45
hgs
parents:
diff changeset
    52
hgs
parents:
diff changeset
    53
//constants
hgs
parents:
diff changeset
    54
57
hgs
parents: 55
diff changeset
    55
hgs
parents: 55
diff changeset
    56
/*!
hgs
parents: 55
diff changeset
    57
 \brief Constructor
hgs
parents: 55
diff changeset
    58
*/
45
hgs
parents:
diff changeset
    59
CalenDayView::CalenDayView(MCalenServices &services) :
hgs
parents:
diff changeset
    60
    CalenNativeView(services), mContentScrollArea(NULL), mContentWidget(NULL),
63
hgs
parents: 57
diff changeset
    61
        mHourScrollArea(NULL), mVLayout(NULL), mMainContainer(NULL),
hgs
parents: 57
diff changeset
    62
        mDocLoader(NULL), mIsLaunching(true), mSettingsManager(NULL),
hgs
parents: 57
diff changeset
    63
        mRegionalInfoKey(XQSettingsKey::TargetCentralRepository,
hgs
parents: 57
diff changeset
    64
            KCRUidCalendar, KCalendarShowRegionalInfo), mServices(services),
70
hgs
parents: 64
diff changeset
    65
        mRegionalInfoGroupBox(NULL), mGoToTodayMenuAction(NULL), mBg(NULL),
hgs
parents: 64
diff changeset
    66
        mGesturesAbsorber(NULL)
45
hgs
parents:
diff changeset
    67
{
hgs
parents:
diff changeset
    68
    setupMenu();
55
hgs
parents: 45
diff changeset
    69
45
hgs
parents:
diff changeset
    70
    // Create model manager
55
hgs
parents: 45
diff changeset
    71
    mModelManager = new CalenDayModelManager(mServices, true, this);
45
hgs
parents:
diff changeset
    72
    mSettingsManager = new XQSettingsManager(this);
63
hgs
parents: 57
diff changeset
    73
    mSettingsManager->startMonitoring(mRegionalInfoKey);
45
hgs
parents:
diff changeset
    74
75
hgs
parents: 70
diff changeset
    75
    //setup Back functionality, launch the month view only when it is
hgs
parents: 70
diff changeset
    76
	// the first view
hgs
parents: 70
diff changeset
    77
    if (ECalenMonthView == mServices.getFirstView()) {
45
hgs
parents:
diff changeset
    78
        HbAction* action = new HbAction(Hb::BackNaviAction, this);
hgs
parents:
diff changeset
    79
        setNavigationAction(action);
hgs
parents:
diff changeset
    80
        // Connect to the signal triggered by clicking on back button.
hgs
parents:
diff changeset
    81
        connect(action, SIGNAL(triggered()), this, SLOT(onBack()));
hgs
parents:
diff changeset
    82
    }
hgs
parents:
diff changeset
    83
hgs
parents:
diff changeset
    84
    HbStyleLoader::registerFilePath(":/calendayhourelement.css");
hgs
parents:
diff changeset
    85
    HbStyleLoader::registerFilePath(":/calendayhourelement.widgetml");
hgs
parents:
diff changeset
    86
    HbStyleLoader::registerFilePath(":/calendayitem.css");
hgs
parents:
diff changeset
    87
    HbStyleLoader::registerFilePath(":/calendayitem.widgetml");
55
hgs
parents: 45
diff changeset
    88
    HbStyleLoader::registerFilePath(":/calendayeventspane.css");
57
hgs
parents: 55
diff changeset
    89
    HbStyleLoader::registerFilePath(":/calendayhourscrollarea.css");
45
hgs
parents:
diff changeset
    90
}
hgs
parents:
diff changeset
    91
57
hgs
parents: 55
diff changeset
    92
/*!
hgs
parents: 55
diff changeset
    93
 \brief Destructor
hgs
parents: 55
diff changeset
    94
*/
45
hgs
parents:
diff changeset
    95
CalenDayView::~CalenDayView()
hgs
parents:
diff changeset
    96
{
63
hgs
parents: 57
diff changeset
    97
    mSettingsManager->stopMonitoring(mRegionalInfoKey);
hgs
parents: 57
diff changeset
    98
    
hgs
parents: 57
diff changeset
    99
    if (mRegionalInfoGroupBox) {
hgs
parents: 57
diff changeset
   100
        delete mRegionalInfoGroupBox;
hgs
parents: 57
diff changeset
   101
        mRegionalInfoGroupBox = NULL;
hgs
parents: 57
diff changeset
   102
    }
hgs
parents: 57
diff changeset
   103
    
55
hgs
parents: 45
diff changeset
   104
    if (mDocLoader) {
hgs
parents: 45
diff changeset
   105
        delete mDocLoader;
hgs
parents: 45
diff changeset
   106
        mDocLoader = NULL;
hgs
parents: 45
diff changeset
   107
    }
45
hgs
parents:
diff changeset
   108
}
hgs
parents:
diff changeset
   109
57
hgs
parents: 55
diff changeset
   110
/*!
hgs
parents: 55
diff changeset
   111
 \brief Handles locale change.
hgs
parents: 55
diff changeset
   112
 
hgs
parents: 55
diff changeset
   113
 \param reason the reason of a change
hgs
parents: 55
diff changeset
   114
*/
45
hgs
parents:
diff changeset
   115
void CalenDayView::onLocaleChanged(int reason)
hgs
parents:
diff changeset
   116
{
hgs
parents:
diff changeset
   117
    Q_UNUSED( reason )
81
hgs
parents: 75
diff changeset
   118
    if ((reason & EChangesSystemTime) || (reason & EChangesMidnightCrossover)) {
hgs
parents: 75
diff changeset
   119
        mDate = CalenDateUtils::today();
hgs
parents: 75
diff changeset
   120
    }
hgs
parents: 75
diff changeset
   121
    
hgs
parents: 75
diff changeset
   122
    if ((reason & EChangesLocale)) {
hgs
parents: 75
diff changeset
   123
        mHourScrollArea->localeChanged();
hgs
parents: 75
diff changeset
   124
    }
45
hgs
parents:
diff changeset
   125
}
hgs
parents:
diff changeset
   126
57
hgs
parents: 55
diff changeset
   127
/*!
hgs
parents: 55
diff changeset
   128
 \brief Reimplemented from CalenView. Handles view (re)population
hgs
parents: 55
diff changeset
   129
*/
45
hgs
parents:
diff changeset
   130
void CalenDayView::doPopulation()
hgs
parents:
diff changeset
   131
{
hgs
parents:
diff changeset
   132
    // Triggers fading effect for heading label
hgs
parents:
diff changeset
   133
    getCurrentDate();
hgs
parents:
diff changeset
   134
    HbEffect::start(mHeadingLabel, "fadeOut", this, "setHeadingText");
hgs
parents:
diff changeset
   135
    
hgs
parents:
diff changeset
   136
    mModelManager->refreshAllModels();
hgs
parents:
diff changeset
   137
    //Set date and time for hour scroll area. 
hgs
parents:
diff changeset
   138
    //It's later used by hour element to display timeline
hgs
parents:
diff changeset
   139
    mHourScrollArea->setDateTime(mDate);
hgs
parents:
diff changeset
   140
    
81
hgs
parents: 75
diff changeset
   141
    isDateValid();
hgs
parents: 75
diff changeset
   142
    
45
hgs
parents:
diff changeset
   143
    //set in menu go to today visible
hgs
parents:
diff changeset
   144
    QDateTime currentDateTime = QDateTime::currentDateTime();
hgs
parents:
diff changeset
   145
    if (mGoToTodayMenuAction and currentDateTime.date() == mDate.date()) {
hgs
parents:
diff changeset
   146
        mGoToTodayMenuAction->setVisible(false);
hgs
parents:
diff changeset
   147
    }
hgs
parents:
diff changeset
   148
    else if(mGoToTodayMenuAction) {
hgs
parents:
diff changeset
   149
        mGoToTodayMenuAction->setVisible(true);
hgs
parents:
diff changeset
   150
    }
hgs
parents:
diff changeset
   151
    
55
hgs
parents: 45
diff changeset
   152
    // Call async. if the view is loaded first time (fix to ou1cimx1#482516)
hgs
parents: 45
diff changeset
   153
    if (mIsLaunching) {
hgs
parents: 45
diff changeset
   154
        mIsLaunching = false;
hgs
parents: 45
diff changeset
   155
        QMetaObject::invokeMethod(this, "setupViewport", Qt::QueuedConnection);
hgs
parents: 45
diff changeset
   156
    } else {
hgs
parents: 45
diff changeset
   157
        setupViewport();
hgs
parents: 45
diff changeset
   158
    }
70
hgs
parents: 64
diff changeset
   159
    
hgs
parents: 64
diff changeset
   160
    //Set gestures absorber
hgs
parents: 64
diff changeset
   161
    if (!mGesturesAbsorber) {
hgs
parents: 64
diff changeset
   162
        mGesturesAbsorber = new HbWidget(this);
hgs
parents: 64
diff changeset
   163
        mGesturesAbsorber->setZValue(100);
hgs
parents: 64
diff changeset
   164
        mGesturesAbsorber->grabGesture(Qt::SwipeGesture);
hgs
parents: 64
diff changeset
   165
        mGesturesAbsorber->grabGesture(Qt::PanGesture);
hgs
parents: 64
diff changeset
   166
        mGesturesAbsorber->setGeometry(rect());
hgs
parents: 64
diff changeset
   167
        mGesturesAbsorber->installEventFilter(mContentScrollArea);
hgs
parents: 64
diff changeset
   168
    }
45
hgs
parents:
diff changeset
   169
	
hgs
parents:
diff changeset
   170
    populationComplete();
hgs
parents:
diff changeset
   171
}
hgs
parents:
diff changeset
   172
57
hgs
parents: 55
diff changeset
   173
/*!
hgs
parents: 55
diff changeset
   174
 \brief Reimplemented from CalenView. Informs the organizer that the view's population is complete.
hgs
parents: 55
diff changeset
   175
*/
45
hgs
parents:
diff changeset
   176
void CalenDayView::populationComplete()
hgs
parents:
diff changeset
   177
{
hgs
parents:
diff changeset
   178
    CalenNativeView::populationComplete();
hgs
parents:
diff changeset
   179
}
hgs
parents:
diff changeset
   180
57
hgs
parents: 55
diff changeset
   181
/*!
hgs
parents: 55
diff changeset
   182
 \brief Sets up the view accroding to the 'xml'
hgs
parents: 55
diff changeset
   183
 
hgs
parents: 55
diff changeset
   184
 \param docLoader Pointer to document loader
hgs
parents: 55
diff changeset
   185
*/
45
hgs
parents:
diff changeset
   186
void CalenDayView::setupView(CalenDocLoader* docLoader)
hgs
parents:
diff changeset
   187
{
55
hgs
parents: 45
diff changeset
   188
    // Store document loader for further use
hgs
parents: 45
diff changeset
   189
    mDocLoader = docLoader;
hgs
parents: 45
diff changeset
   190
hgs
parents: 45
diff changeset
   191
    // Get vertical layout from day view
hgs
parents: 45
diff changeset
   192
    mVLayout = static_cast<QGraphicsLinearLayout *> (this->layout());
hgs
parents: 45
diff changeset
   193
hgs
parents: 45
diff changeset
   194
    // Set up day info
hgs
parents: 45
diff changeset
   195
    mHeadingLabel = qobject_cast<HbGroupBox *> (mDocLoader->findWidget(
hgs
parents: 45
diff changeset
   196
        CALEN_DAYVIEW_DAYINFO));
hgs
parents: 45
diff changeset
   197
    HbEffect::add(mHeadingLabel, ":/fade_out.fxml", "fadeOut");
hgs
parents: 45
diff changeset
   198
    HbEffect::add(mHeadingLabel, ":/fade_in.fxml", "fadeIn");
63
hgs
parents: 57
diff changeset
   199
    
hgs
parents: 57
diff changeset
   200
    // Set up main container for hour elements/content area
hgs
parents: 57
diff changeset
   201
    mMainContainer = qobject_cast<HbWidget *> (mDocLoader->findWidget(
hgs
parents: 57
diff changeset
   202
        CALEN_DAYVIEW_CONTENTWIDGET));
hgs
parents: 57
diff changeset
   203
    if (Qt::Vertical == CalenDayUtils::instance()->orientation()) {
hgs
parents: 57
diff changeset
   204
        mBg = new HbFrameItem(KCalenBackgroundColorPortrait,
hgs
parents: 57
diff changeset
   205
            HbFrameDrawer::OnePiece, this);
hgs
parents: 57
diff changeset
   206
    }
hgs
parents: 57
diff changeset
   207
    else {
hgs
parents: 57
diff changeset
   208
        mBg = new HbFrameItem(KCalenBackgroundColorLandscape,
hgs
parents: 57
diff changeset
   209
            HbFrameDrawer::OnePiece, this);
hgs
parents: 57
diff changeset
   210
    }
hgs
parents: 57
diff changeset
   211
    mMainContainer->setBackgroundItem(mBg);
55
hgs
parents: 45
diff changeset
   212
hgs
parents: 45
diff changeset
   213
    // Set up hour scroll area
hgs
parents: 45
diff changeset
   214
    mHourScrollArea
hgs
parents: 45
diff changeset
   215
        = static_cast<CalenDayHourScrollArea *> (mDocLoader->findWidget(
hgs
parents: 45
diff changeset
   216
            CALEN_DAYVIEW_HOURSCROLLAREA));
hgs
parents: 45
diff changeset
   217
hgs
parents: 45
diff changeset
   218
    // Set up content scroll area
hgs
parents: 45
diff changeset
   219
    mContentScrollArea
hgs
parents: 45
diff changeset
   220
        = static_cast<CalenDayContentScrollArea *> (mDocLoader->findWidget(
hgs
parents: 45
diff changeset
   221
            CALEN_DAYVIEW_CONTENTSCROLLAREA));
63
hgs
parents: 57
diff changeset
   222
    // Pass parent object to mContentWidget to install event filters on parent
75
hgs
parents: 70
diff changeset
   223
    mContentWidget = new CalenDayContentWidget(mContentScrollArea);
55
hgs
parents: 45
diff changeset
   224
    mContentScrollArea->setContentWidget(mContentWidget);
75
hgs
parents: 70
diff changeset
   225
    
hgs
parents: 70
diff changeset
   226
    initializeViews();
63
hgs
parents: 57
diff changeset
   227
    setupSlots();
hgs
parents: 57
diff changeset
   228
    
55
hgs
parents: 45
diff changeset
   229
    // Set up regional info if variant is correct
hgs
parents: 45
diff changeset
   230
    showRegionalInformationFadeIn();
45
hgs
parents:
diff changeset
   231
}
hgs
parents:
diff changeset
   232
hgs
parents:
diff changeset
   233
//private slots
hgs
parents:
diff changeset
   234
57
hgs
parents: 55
diff changeset
   235
/*!
hgs
parents: 55
diff changeset
   236
 \brief Handles 'back' functionality
hgs
parents: 55
diff changeset
   237
*/
45
hgs
parents:
diff changeset
   238
void CalenDayView::onBack()
hgs
parents:
diff changeset
   239
{
hgs
parents:
diff changeset
   240
    TRAP_IGNORE(mServices.IssueCommandL(ECalenMonthView));
hgs
parents:
diff changeset
   241
}
hgs
parents:
diff changeset
   242
57
hgs
parents: 55
diff changeset
   243
/*!
hgs
parents: 55
diff changeset
   244
 \brief Slot that handles first phase of day change
hgs
parents: 55
diff changeset
   245
 
hgs
parents: 55
diff changeset
   246
 \param direction indicates to which day view needs to be scrolled (previous or next day)
hgs
parents: 55
diff changeset
   247
*/
45
hgs
parents:
diff changeset
   248
void CalenDayView::dayChangeStarted(CalenScrollDirection direction)
hgs
parents:
diff changeset
   249
{
81
hgs
parents: 75
diff changeset
   250
    switch (direction) {
hgs
parents: 75
diff changeset
   251
        case ECalenScrollToNext:
hgs
parents: 75
diff changeset
   252
            mDate = mDate.addDays(1);
hgs
parents: 75
diff changeset
   253
            break;
hgs
parents: 75
diff changeset
   254
        case ECalenScrollToPrev:
hgs
parents: 75
diff changeset
   255
            mDate = mDate.addDays(-1);
hgs
parents: 75
diff changeset
   256
            break;
hgs
parents: 75
diff changeset
   257
        default:
hgs
parents: 75
diff changeset
   258
            break;
45
hgs
parents:
diff changeset
   259
    }
hgs
parents:
diff changeset
   260
    
81
hgs
parents: 75
diff changeset
   261
    // Update the visibility of 'Go to today' option in menu
hgs
parents: 75
diff changeset
   262
	QDateTime currentDateTime = QDateTime::currentDateTime();
45
hgs
parents:
diff changeset
   263
    if (mGoToTodayMenuAction and currentDateTime.date() == mDate.date()) {
hgs
parents:
diff changeset
   264
        mGoToTodayMenuAction->setVisible(false);
hgs
parents:
diff changeset
   265
    }
hgs
parents:
diff changeset
   266
    else if(mGoToTodayMenuAction) {
hgs
parents:
diff changeset
   267
        mGoToTodayMenuAction->setVisible(true);
hgs
parents:
diff changeset
   268
    }
hgs
parents:
diff changeset
   269
    
hgs
parents:
diff changeset
   270
    // Triggers fading effect for heading label.
hgs
parents:
diff changeset
   271
    HbEffect::start(mHeadingLabel, "fadeOut", this, "setHeadingText");
63
hgs
parents: 57
diff changeset
   272
    if (mRegionalInfoGroupBox) {
hgs
parents: 57
diff changeset
   273
        HbEffect::start(mRegionalInfoGroupBox, "fadeOut", this,
hgs
parents: 57
diff changeset
   274
            "showRegionalInformation");
hgs
parents: 57
diff changeset
   275
    }
45
hgs
parents:
diff changeset
   276
    
hgs
parents:
diff changeset
   277
    mServices.Context().setFocusDate(mDate);
hgs
parents:
diff changeset
   278
}
hgs
parents:
diff changeset
   279
57
hgs
parents: 55
diff changeset
   280
/*!
hgs
parents: 55
diff changeset
   281
 \brief Slot that is triggered when operation of day change is completed
hgs
parents: 55
diff changeset
   282
 
hgs
parents: 55
diff changeset
   283
 \param direction ndicates to which day view was scrolled (previous or next day)
hgs
parents: 55
diff changeset
   284
*/
45
hgs
parents:
diff changeset
   285
void CalenDayView::dayChanged(CalenScrollDirection direction)
hgs
parents:
diff changeset
   286
{
hgs
parents:
diff changeset
   287
    mModelManager->viewsScrollingFinished(direction);
hgs
parents:
diff changeset
   288
	mHourScrollArea->setDateTime(mDate);
81
hgs
parents: 75
diff changeset
   289
	mHourScrollArea->updateTimeIndicator();
hgs
parents: 75
diff changeset
   290
	isDateValid();
45
hgs
parents:
diff changeset
   291
}
hgs
parents:
diff changeset
   292
57
hgs
parents: 55
diff changeset
   293
/*!
hgs
parents: 55
diff changeset
   294
 \brief Gets current date from context
hgs
parents: 55
diff changeset
   295
*/
45
hgs
parents:
diff changeset
   296
void CalenDayView::getCurrentDate()
hgs
parents:
diff changeset
   297
{
hgs
parents:
diff changeset
   298
    mDate = CalenNativeView::mServices.Context().focusDateAndTime();
hgs
parents:
diff changeset
   299
}
hgs
parents:
diff changeset
   300
57
hgs
parents: 55
diff changeset
   301
/*!
hgs
parents: 55
diff changeset
   302
 \brief Sets the menu for day view
hgs
parents: 55
diff changeset
   303
*/
45
hgs
parents:
diff changeset
   304
void CalenDayView::setupMenu()
hgs
parents:
diff changeset
   305
{
70
hgs
parents: 64
diff changeset
   306
	menu()->addAction(hbTrId("txt_calendar_opt_new_event"), this, SLOT(runNewMeeting()));
hgs
parents: 64
diff changeset
   307
	//get pointer to this position, because need to change visibility
hgs
parents: 64
diff changeset
   308
	mGoToTodayMenuAction = menu()->addAction(hbTrId("txt_calendar_opt_go_to_today"), this, SLOT(runGoToToday()));
hgs
parents: 64
diff changeset
   309
	menu()->addAction(hbTrId("txt_calendar_opt_go_to_date"), this, SLOT(goToDate()));
hgs
parents: 64
diff changeset
   310
	//TODO: Add id for this text
hgs
parents: 64
diff changeset
   311
	//"Switch to Agenda view"
hgs
parents: 64
diff changeset
   312
	menu()->addAction(hbTrId("txt_calendar_opt_switch_to_agenda_view"), this, SLOT(runChangeToAgendaView()));
hgs
parents: 64
diff changeset
   313
	//TODO: Add id for this text (lunar data)
hgs
parents: 64
diff changeset
   314
	//"Show lunar data"
hgs
parents: 64
diff changeset
   315
	if (pluginEnabled())
hgs
parents: 64
diff changeset
   316
	{
45
hgs
parents:
diff changeset
   317
		menu()->addAction(hbTrId("txt_calendar_opt_show_lunar_data"), this, SLOT(runLunarData()));
70
hgs
parents: 64
diff changeset
   318
	}
hgs
parents: 64
diff changeset
   319
	menu()->addAction(hbTrId("txt_calendar_opt_settings"), this, SLOT(launchSettingsView()));
hgs
parents: 64
diff changeset
   320
	
hgs
parents: 64
diff changeset
   321
	// Close the menu once closeDialogs() is received
hgs
parents: 64
diff changeset
   322
	connect(this, SIGNAL(closeDialogs()), menu(), SLOT(close()));
45
hgs
parents:
diff changeset
   323
}
hgs
parents:
diff changeset
   324
hgs
parents:
diff changeset
   325
/*!
57
hgs
parents: 55
diff changeset
   326
   \brief To change Day view to Agenda View
45
hgs
parents:
diff changeset
   327
 */
hgs
parents:
diff changeset
   328
void CalenDayView::runChangeToAgendaView()
hgs
parents:
diff changeset
   329
{
hgs
parents:
diff changeset
   330
    changeView(ECalenAgendaView);
hgs
parents:
diff changeset
   331
}
hgs
parents:
diff changeset
   332
hgs
parents:
diff changeset
   333
/*!
hgs
parents:
diff changeset
   334
   \brief Shows lunar data in popup box
hgs
parents:
diff changeset
   335
 */
hgs
parents:
diff changeset
   336
void CalenDayView::runLunarData()
hgs
parents:
diff changeset
   337
{
hgs
parents:
diff changeset
   338
	TRAP_IGNORE(mServices.IssueCommandL(ECalenRegionalPluginTapEvent));
hgs
parents:
diff changeset
   339
}
hgs
parents:
diff changeset
   340
57
hgs
parents: 55
diff changeset
   341
/*!
hgs
parents: 55
diff changeset
   342
   \brief This is a helper function to established connections between signals and slots
hgs
parents: 55
diff changeset
   343
*/
45
hgs
parents:
diff changeset
   344
void CalenDayView::setupSlots()
hgs
parents:
diff changeset
   345
{
hgs
parents:
diff changeset
   346
    // Connecting other view-related signals/slots
hgs
parents:
diff changeset
   347
    connect(mContentScrollArea,
hgs
parents:
diff changeset
   348
        SIGNAL(scrollAreaMoveStarted(CalenScrollDirection)), this,
hgs
parents:
diff changeset
   349
        SLOT(dayChangeStarted(CalenScrollDirection)));
hgs
parents:
diff changeset
   350
hgs
parents:
diff changeset
   351
    connect(mContentScrollArea,
hgs
parents:
diff changeset
   352
        SIGNAL(scrollAreaMoveFinished(CalenScrollDirection)), mContentWidget,
hgs
parents:
diff changeset
   353
        SLOT(relayoutWidgets(CalenScrollDirection)));
hgs
parents:
diff changeset
   354
hgs
parents:
diff changeset
   355
    connect(mContentWidget, SIGNAL(
hgs
parents:
diff changeset
   356
        widgetsRelayoutFinished(CalenScrollDirection)), mContentScrollArea,
hgs
parents:
diff changeset
   357
        SLOT(scrollToMiddleWidget()));
hgs
parents:
diff changeset
   358
hgs
parents:
diff changeset
   359
    connect(mContentWidget,
hgs
parents:
diff changeset
   360
        SIGNAL(widgetsRelayoutFinished(CalenScrollDirection)), this,
hgs
parents:
diff changeset
   361
        SLOT(dayChanged(CalenScrollDirection)));
hgs
parents:
diff changeset
   362
hgs
parents:
diff changeset
   363
    connect(mContentWidget, SIGNAL(scrollPositionChanged(const QPointF &)),
hgs
parents:
diff changeset
   364
        mHourScrollArea, SLOT(scrollVertically(const QPointF &)));
63
hgs
parents: 57
diff changeset
   365
45
hgs
parents:
diff changeset
   366
    connect(mHourScrollArea, SIGNAL(scrollPositionChanged(const QPointF &)),
hgs
parents:
diff changeset
   367
        mContentWidget, SLOT(widgetScrolled(const QPointF &)));
63
hgs
parents: 57
diff changeset
   368
hgs
parents: 57
diff changeset
   369
    connect(CalenDayUtils::instance()->mainWindow(),
hgs
parents: 57
diff changeset
   370
        SIGNAL(orientationChanged(Qt::Orientation)), this,
hgs
parents: 57
diff changeset
   371
        SLOT(orientationChanged(Qt::Orientation)));
hgs
parents: 57
diff changeset
   372
45
hgs
parents:
diff changeset
   373
    connect(mSettingsManager, SIGNAL(valueChanged(XQSettingsKey, QVariant)),
hgs
parents:
diff changeset
   374
        this, SLOT(showHideRegionalInformationChanged(XQSettingsKey, QVariant)));
hgs
parents:
diff changeset
   375
}
hgs
parents:
diff changeset
   376
57
hgs
parents: 55
diff changeset
   377
/*!
75
hgs
parents: 70
diff changeset
   378
   \brief Initializes internal views.
hgs
parents: 70
diff changeset
   379
   
hgs
parents: 70
diff changeset
   380
   CalenDayView uses 3 child views which represent previous, current and next days.
hgs
parents: 70
diff changeset
   381
   This assures that swiping to prev/next day works smoothly, because population
hgs
parents: 70
diff changeset
   382
   of data is done earlier.
hgs
parents: 70
diff changeset
   383
*/
hgs
parents: 70
diff changeset
   384
void CalenDayView::initializeViews()
hgs
parents: 70
diff changeset
   385
{
hgs
parents: 70
diff changeset
   386
    // Create item views
hgs
parents: 70
diff changeset
   387
    HbModelIterator *iterator(0);
hgs
parents: 70
diff changeset
   388
hgs
parents: 70
diff changeset
   389
    iterator = new HbModelIterator(&mModelManager->getModel(
hgs
parents: 70
diff changeset
   390
        CalenDayModelManager::PreviousDay));
hgs
parents: 70
diff changeset
   391
    CalenDayItemView *prevItemView = new CalenDayItemView(
hgs
parents: 70
diff changeset
   392
        mModelManager->getServices(), iterator, 0);
hgs
parents: 70
diff changeset
   393
hgs
parents: 70
diff changeset
   394
    iterator = new HbModelIterator(&mModelManager->getModel(
hgs
parents: 70
diff changeset
   395
        CalenDayModelManager::CurrentDay));
hgs
parents: 70
diff changeset
   396
    CalenDayItemView *currItemView = new CalenDayItemView(
hgs
parents: 70
diff changeset
   397
        mModelManager->getServices(), iterator, 0);
hgs
parents: 70
diff changeset
   398
hgs
parents: 70
diff changeset
   399
    iterator = new HbModelIterator(&mModelManager->getModel(
hgs
parents: 70
diff changeset
   400
        CalenDayModelManager::NextDay));
hgs
parents: 70
diff changeset
   401
    CalenDayItemView *nextItemView = new CalenDayItemView(
hgs
parents: 70
diff changeset
   402
        mModelManager->getServices(), iterator, 0);
hgs
parents: 70
diff changeset
   403
hgs
parents: 70
diff changeset
   404
    // Connect views with widgetScrolled SLOT to support simultanous vertical scrolling
hgs
parents: 70
diff changeset
   405
    connect(prevItemView, SIGNAL(scrollPositionChanged(const QPointF&)), mContentWidget,
hgs
parents: 70
diff changeset
   406
        SLOT(widgetScrolled(const QPointF&)));
hgs
parents: 70
diff changeset
   407
    connect(currItemView, SIGNAL(scrollPositionChanged(const QPointF&)), mContentWidget,
hgs
parents: 70
diff changeset
   408
        SLOT(widgetScrolled(const QPointF&)));
hgs
parents: 70
diff changeset
   409
    connect(nextItemView, SIGNAL(scrollPositionChanged(const QPointF&)), mContentWidget,
hgs
parents: 70
diff changeset
   410
        SLOT(widgetScrolled(const QPointF&)));
hgs
parents: 70
diff changeset
   411
    
hgs
parents: 70
diff changeset
   412
    // Close menu once closeDialogs() is received
hgs
parents: 70
diff changeset
   413
    connect(this, SIGNAL(closeDialogs()), prevItemView->contextMenu(), SLOT(close()));
hgs
parents: 70
diff changeset
   414
    connect(this, SIGNAL(closeDialogs()), currItemView->contextMenu(), SLOT(close()));
hgs
parents: 70
diff changeset
   415
    connect(this, SIGNAL(closeDialogs()), nextItemView->contextMenu(), SLOT(close()));
hgs
parents: 70
diff changeset
   416
hgs
parents: 70
diff changeset
   417
    // Install event filters to receive events necessary for gesture handling
hgs
parents: 70
diff changeset
   418
    prevItemView->installEventFilter(mContentScrollArea);
hgs
parents: 70
diff changeset
   419
    currItemView->installEventFilter(mContentScrollArea);
hgs
parents: 70
diff changeset
   420
    nextItemView->installEventFilter(mContentScrollArea);
hgs
parents: 70
diff changeset
   421
hgs
parents: 70
diff changeset
   422
    // Add views to layout
hgs
parents: 70
diff changeset
   423
    mContentWidget->add(prevItemView);
hgs
parents: 70
diff changeset
   424
    mContentWidget->add(currItemView);
hgs
parents: 70
diff changeset
   425
    mContentWidget->add(nextItemView);
hgs
parents: 70
diff changeset
   426
}
hgs
parents: 70
diff changeset
   427
hgs
parents: 70
diff changeset
   428
/*!
81
hgs
parents: 75
diff changeset
   429
 \brief Checks current date and if previous/next days are valid.
hgs
parents: 75
diff changeset
   430
 
hgs
parents: 75
diff changeset
   431
 Checks if previous/next day is in range of supported dates: 1900-01-01 - 2100-12-30
hgs
parents: 75
diff changeset
   432
 */
hgs
parents: 75
diff changeset
   433
void CalenDayView::isDateValid()
hgs
parents: 75
diff changeset
   434
{
hgs
parents: 75
diff changeset
   435
    // Fix to ou1cimx1#583805: user shouldnot be able to scroll 
hgs
parents: 75
diff changeset
   436
    // before 01/01/1900 and after 30/12/2100
hgs
parents: 75
diff changeset
   437
    mContentScrollArea->setDisallowedScrollDirection(ECalenScrollNoDayChange);
hgs
parents: 75
diff changeset
   438
    if (!CalenDateUtils::isValidDay(mDate.addDays(-1))) {
hgs
parents: 75
diff changeset
   439
        mContentScrollArea->setDisallowedScrollDirection(ECalenScrollToPrev);
hgs
parents: 75
diff changeset
   440
    }
hgs
parents: 75
diff changeset
   441
    else
hgs
parents: 75
diff changeset
   442
        if (!CalenDateUtils::isValidDay(mDate.addDays(1))) {
hgs
parents: 75
diff changeset
   443
            mContentScrollArea->setDisallowedScrollDirection(ECalenScrollToNext);
hgs
parents: 75
diff changeset
   444
        }
hgs
parents: 75
diff changeset
   445
}
hgs
parents: 75
diff changeset
   446
hgs
parents: 75
diff changeset
   447
/*!
57
hgs
parents: 55
diff changeset
   448
   \brief This slot triggers new meeting creation view
hgs
parents: 55
diff changeset
   449
*/
45
hgs
parents:
diff changeset
   450
void CalenDayView::runNewMeeting()
hgs
parents:
diff changeset
   451
{
hgs
parents:
diff changeset
   452
    QDateTime dateTime(mDate);
hgs
parents:
diff changeset
   453
    TRAP_IGNORE(
hgs
parents:
diff changeset
   454
        dateTime.setTime(mServices.Context().defaultCalTimeForViewsL().time());
hgs
parents:
diff changeset
   455
        mServices.Context().setFocusDateAndTime(dateTime);
hgs
parents:
diff changeset
   456
        mServices.IssueCommandL(ECalenNewMeeting)
55
hgs
parents: 45
diff changeset
   457
    );
45
hgs
parents:
diff changeset
   458
}
hgs
parents:
diff changeset
   459
57
hgs
parents: 55
diff changeset
   460
/*!
hgs
parents: 55
diff changeset
   461
   \brief This slot switches current view to today
hgs
parents: 55
diff changeset
   462
*/
45
hgs
parents:
diff changeset
   463
void CalenDayView::runGoToToday()
hgs
parents:
diff changeset
   464
{
hgs
parents:
diff changeset
   465
    mServices.Context().setFocusDateAndTime(CalenDateUtils::today());
hgs
parents:
diff changeset
   466
    TRAP_IGNORE(mServices.IssueCommandL(ECalenGotoToday));
hgs
parents:
diff changeset
   467
    refreshViewOnGoToDate();
hgs
parents:
diff changeset
   468
}
hgs
parents:
diff changeset
   469
hgs
parents:
diff changeset
   470
57
hgs
parents: 55
diff changeset
   471
/*!
hgs
parents: 55
diff changeset
   472
   \brief This slot switches current view to the given by id
hgs
parents: 55
diff changeset
   473
   
hgs
parents: 55
diff changeset
   474
   \param viewId id of the view that needs to be displayed
hgs
parents: 55
diff changeset
   475
*/
45
hgs
parents:
diff changeset
   476
void CalenDayView::changeView(TCalenCommandId viewId)
hgs
parents:
diff changeset
   477
{
hgs
parents:
diff changeset
   478
    TRAP_IGNORE(mServices.IssueCommandL(viewId));
hgs
parents:
diff changeset
   479
}
hgs
parents:
diff changeset
   480
57
hgs
parents: 55
diff changeset
   481
/*!
hgs
parents: 55
diff changeset
   482
   \brief Sets heading text according to date from model and locale.
hgs
parents: 55
diff changeset
   483
          It's connected to modelReset signal.
hgs
parents: 55
diff changeset
   484
   
hgs
parents: 55
diff changeset
   485
   \param status Parameter required in order to call this slot autmatically
hgs
parents: 55
diff changeset
   486
                 when an effect is complete.
hgs
parents: 55
diff changeset
   487
*/
45
hgs
parents:
diff changeset
   488
void CalenDayView::setHeadingText(const HbEffect::EffectStatus &status)
hgs
parents:
diff changeset
   489
{   
hgs
parents:
diff changeset
   490
    Q_UNUSED(status)
hgs
parents:
diff changeset
   491
hgs
parents:
diff changeset
   492
    // Format the date as per the device locale settings
hgs
parents:
diff changeset
   493
    HbExtendedLocale systemLocale = HbExtendedLocale::system();
hgs
parents:
diff changeset
   494
hgs
parents:
diff changeset
   495
    // Get localised name of the day from locale
hgs
parents:
diff changeset
   496
    QString dayString = systemLocale.dayName(mDate.date().dayOfWeek());
hgs
parents:
diff changeset
   497
    // Append a single space
hgs
parents:
diff changeset
   498
    dayString.append(" ");
hgs
parents:
diff changeset
   499
    // Set the heading
hgs
parents:
diff changeset
   500
hgs
parents:
diff changeset
   501
    // Append the date which is formatted as per the locale   
64
1881ad52dc45 201033_03
hgs
parents: 63
diff changeset
   502
    mHeadingLabel->setHeading(QString("%1 %2").arg(dayString).arg(
45
hgs
parents:
diff changeset
   503
        systemLocale.format(mDate.date(), r_qtn_date_usual_with_zero)));
hgs
parents:
diff changeset
   504
hgs
parents:
diff changeset
   505
    HbEffect::start(mHeadingLabel, "fadeIn");
hgs
parents:
diff changeset
   506
}
hgs
parents:
diff changeset
   507
57
hgs
parents: 55
diff changeset
   508
/*!
hgs
parents: 55
diff changeset
   509
   \brief Displays regional information
hgs
parents: 55
diff changeset
   510
   
hgs
parents: 55
diff changeset
   511
   \param status Parameter required in order to call this slot autmatically
hgs
parents: 55
diff changeset
   512
                 when an effect is complete.
hgs
parents: 55
diff changeset
   513
*/
45
hgs
parents:
diff changeset
   514
void CalenDayView::showRegionalInformation(const HbEffect::EffectStatus &status)
hgs
parents:
diff changeset
   515
{
hgs
parents:
diff changeset
   516
	Q_UNUSED(status);
hgs
parents:
diff changeset
   517
	showRegionalInformationFadeIn();
hgs
parents:
diff changeset
   518
}
hgs
parents:
diff changeset
   519
57
hgs
parents: 55
diff changeset
   520
/*!
hgs
parents: 55
diff changeset
   521
   \brief Runs effect on lunar data label and change text according to date change.
hgs
parents: 55
diff changeset
   522
*/
45
hgs
parents:
diff changeset
   523
void CalenDayView::showRegionalInformationFadeIn()
57
hgs
parents: 55
diff changeset
   524
{
63
hgs
parents: 57
diff changeset
   525
	showHideRegionalInformationChanged(mRegionalInfoKey, 3);
hgs
parents: 57
diff changeset
   526
	if (mRegionalInfoGroupBox) {
hgs
parents: 57
diff changeset
   527
	    HbEffect::start(mRegionalInfoGroupBox, "fadeIn");
hgs
parents: 57
diff changeset
   528
	}
57
hgs
parents: 55
diff changeset
   529
}
45
hgs
parents:
diff changeset
   530
57
hgs
parents: 55
diff changeset
   531
/*!
hgs
parents: 55
diff changeset
   532
   \brief To Show and hide regional plugin label depends upon settings.
hgs
parents: 55
diff changeset
   533
*/
55
hgs
parents: 45
diff changeset
   534
void CalenDayView::showHideRegionalInformationChanged(
hgs
parents: 45
diff changeset
   535
    const XQSettingsKey& key,
hgs
parents: 45
diff changeset
   536
    const QVariant&)
hgs
parents: 45
diff changeset
   537
{
63
hgs
parents: 57
diff changeset
   538
    if ((key.key() == mRegionalInfoKey.key()) && pluginEnabled()) {
55
hgs
parents: 45
diff changeset
   539
        int showRegionalInfo =
63
hgs
parents: 57
diff changeset
   540
            mSettingsManager->readItemValue(mRegionalInfoKey).toUInt();
hgs
parents: 57
diff changeset
   541
        if (showRegionalInfo) {
hgs
parents: 57
diff changeset
   542
            if (!mRegionalInfoGroupBox) {
hgs
parents: 57
diff changeset
   543
                mRegionalInfoGroupBox = new HbGroupBox();
hgs
parents: 57
diff changeset
   544
                CalenPluginLabel *regionalInfo = new CalenPluginLabel(
hgs
parents: 57
diff changeset
   545
                    mServices, this);
hgs
parents: 57
diff changeset
   546
                regionalInfo->setFontSpec(HbFontSpec(HbFontSpec::Primary));
hgs
parents: 57
diff changeset
   547
                mRegionalInfoGroupBox->setContentWidget(regionalInfo);
hgs
parents: 57
diff changeset
   548
                mVLayout->insertItem(1, mRegionalInfoGroupBox);
hgs
parents: 57
diff changeset
   549
            }
55
hgs
parents: 45
diff changeset
   550
            QString *pluginString = pluginText();
63
hgs
parents: 57
diff changeset
   551
            HbLabel *pluginInfoLabel = qobject_cast<HbLabel *> (
hgs
parents: 57
diff changeset
   552
                mRegionalInfoGroupBox->contentWidget());
hgs
parents: 57
diff changeset
   553
            pluginInfoLabel->setPlainText(*pluginString);
55
hgs
parents: 45
diff changeset
   554
        }
hgs
parents: 45
diff changeset
   555
        else {
hgs
parents: 45
diff changeset
   556
            if (mRegionalInfoGroupBox) {
hgs
parents: 45
diff changeset
   557
                mVLayout->removeItem(mRegionalInfoGroupBox);
hgs
parents: 45
diff changeset
   558
                delete mRegionalInfoGroupBox;
hgs
parents: 45
diff changeset
   559
                mRegionalInfoGroupBox = NULL;
hgs
parents: 45
diff changeset
   560
            }
hgs
parents: 45
diff changeset
   561
        }
hgs
parents: 45
diff changeset
   562
    }
hgs
parents: 45
diff changeset
   563
}
45
hgs
parents:
diff changeset
   564
57
hgs
parents: 55
diff changeset
   565
/*!
hgs
parents: 55
diff changeset
   566
   \brief Scrolls view according to current day and events.
hgs
parents: 55
diff changeset
   567
*/
45
hgs
parents:
diff changeset
   568
void CalenDayView::setupViewport()
hgs
parents:
diff changeset
   569
{
hgs
parents:
diff changeset
   570
    QDateTime currentTime = QDateTime::currentDateTime();
55
hgs
parents: 45
diff changeset
   571
45
hgs
parents:
diff changeset
   572
    // If we have event in current day and hour, scroll to this event
55
hgs
parents: 45
diff changeset
   573
    if (mDate.date() == currentTime.date()){
hgs
parents: 45
diff changeset
   574
hgs
parents: 45
diff changeset
   575
        QDateTime midnight = currentTime;
hgs
parents: 45
diff changeset
   576
        midnight.setTime(QTime(23, 59));
hgs
parents: 45
diff changeset
   577
hgs
parents: 45
diff changeset
   578
        //Filter flags (only timed events)
hgs
parents: 45
diff changeset
   579
        AgendaUtil::FilterFlags filter = AgendaUtil::FilterFlags(AgendaUtil::IncludeAppointments);
hgs
parents: 45
diff changeset
   580
        QList<AgendaEntry> list;
hgs
parents: 45
diff changeset
   581
        // Fetch the instance list from the agenda interface
hgs
parents: 45
diff changeset
   582
        list = mServices.agendaInterface()->fetchEntriesInRange(currentTime, midnight, filter);
hgs
parents: 45
diff changeset
   583
hgs
parents: 45
diff changeset
   584
        if(!list.isEmpty()){
hgs
parents: 45
diff changeset
   585
            int hourToScrollTo(list.first().startTime().time().hour());
hgs
parents: 45
diff changeset
   586
            mHourScrollArea->scrollToHour(hourToScrollTo);           
hgs
parents: 45
diff changeset
   587
        }
hgs
parents: 45
diff changeset
   588
        else{
hgs
parents: 45
diff changeset
   589
            mHourScrollArea->scrollToHour(currentTime.time().hour());
hgs
parents: 45
diff changeset
   590
        }
45
hgs
parents:
diff changeset
   591
    }
55
hgs
parents: 45
diff changeset
   592
    else {
45
hgs
parents:
diff changeset
   593
        //Scroll view to 7am
hgs
parents:
diff changeset
   594
        mHourScrollArea->scrollToHour(7);
hgs
parents:
diff changeset
   595
    }
hgs
parents:
diff changeset
   596
}
hgs
parents:
diff changeset
   597
63
hgs
parents: 57
diff changeset
   598
/*!
hgs
parents: 57
diff changeset
   599
 \brief Slot which is called whenever the orientation of the device changes.
hgs
parents: 57
diff changeset
   600
 
hgs
parents: 57
diff changeset
   601
 Changes the backgroung graphic element when orientation chandes.
hgs
parents: 57
diff changeset
   602
 
hgs
parents: 57
diff changeset
   603
 \param orientation Current device orientation
hgs
parents: 57
diff changeset
   604
 */
hgs
parents: 57
diff changeset
   605
void CalenDayView::orientationChanged(Qt::Orientation orientation)
hgs
parents: 57
diff changeset
   606
{
hgs
parents: 57
diff changeset
   607
    if (Qt::Vertical == orientation) {
hgs
parents: 57
diff changeset
   608
        mBg = new HbFrameItem(KCalenBackgroundColorPortrait,
hgs
parents: 57
diff changeset
   609
            HbFrameDrawer::OnePiece, this);
hgs
parents: 57
diff changeset
   610
    }
hgs
parents: 57
diff changeset
   611
    else {
hgs
parents: 57
diff changeset
   612
        mBg = new HbFrameItem(KCalenBackgroundColorLandscape,
hgs
parents: 57
diff changeset
   613
            HbFrameDrawer::OnePiece, this);
hgs
parents: 57
diff changeset
   614
    }
hgs
parents: 57
diff changeset
   615
    mMainContainer->setBackgroundItem(mBg);
hgs
parents: 57
diff changeset
   616
}
hgs
parents: 57
diff changeset
   617
45
hgs
parents:
diff changeset
   618
//End of File