calendarui/views/src/calenmonthgrid.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:
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
     1
/*
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
     3
 * All rights reserved.
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
     4
 * This component and the accompanying materials are made available
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
     6
 * which accompanies this distribution, and is available
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
     8
 *
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
     9
 * Initial Contributors:
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    10
 * Nokia Corporation - initial contribution.
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    11
 *
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    12
 * Contributors: 
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    13
 *
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    14
 * Description: Definition file for class CalenMonthGrid.
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    15
 *
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    16
 */
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    17
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    18
// System includes
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    19
#include <hbgridview.h>
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    20
#include <hbabstractviewitem.h>
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    21
#include <hbstyleloader.h>
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    22
#include <hbcolorscheme.h>
45
hgs
parents: 23
diff changeset
    23
#include <hbpangesture.h>
hgs
parents: 23
diff changeset
    24
#include <hbswipegesture.h>
51
hgs
parents: 45
diff changeset
    25
#include <hbtapgesture.h>
45
hgs
parents: 23
diff changeset
    26
#include <hbdeviceprofile.h>
55
hgs
parents: 51
diff changeset
    27
#include <hbinstance.h>
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    28
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    29
// User includes
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    30
#include "calenmonthgrid.h"
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    31
#include "calengriditemprototype.h"
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    32
#include "calenmonthdata.h"
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    33
#include "calenmonthview.h"
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    34
#include "calendateutils.h"
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    35
#include "calencommon.h"
45
hgs
parents: 23
diff changeset
    36
#include "calenconstants.h"
51
hgs
parents: 45
diff changeset
    37
#include "OstTraceDefinitions.h"
hgs
parents: 45
diff changeset
    38
#ifdef OST_TRACE_COMPILER_IN_USE
hgs
parents: 45
diff changeset
    39
#include "calenmonthgridTraces.h"
hgs
parents: 45
diff changeset
    40
#endif
hgs
parents: 45
diff changeset
    41
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    42
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    43
// Constants
45
hgs
parents: 23
diff changeset
    44
#define SCROLL_SPEEED 3000 
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    45
#define GRIDLINE_WIDTH 0.075 //units
45
hgs
parents: 23
diff changeset
    46
#define MAX_PAN_DIRECTION_THRESHOLD 50
hgs
parents: 23
diff changeset
    47
#define MIN_PAN_DIRECTION_THRESHOLD 20
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    48
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    49
/*!
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    50
 \class CalenMonthGrid
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    51
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    52
 Implements the month grid
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    53
 */
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
    54
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    55
/*!
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    56
 Default constructor.
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    57
 */
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    58
CalenMonthGrid::CalenMonthGrid(QGraphicsItem *parent):
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    59
	HbGridView(parent),
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    60
	mModel(0),
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    61
	mDirection(invalid),
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    62
	mIsPanGesture(false),
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    63
	mIsAtomicScroll(true),
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    64
	mView(NULL),
45
hgs
parents: 23
diff changeset
    65
	mCurrentRow(-100),
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    66
	mIsNonActiveDayFocused(false),
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    67
	mIgnoreItemActivated(false),
63
hgs
parents: 57
diff changeset
    68
	mGridLineColor(HbColorScheme::color("qtc_cal_grid_line")),
70
hgs
parents: 63
diff changeset
    69
    mActiveDatesSet(false),
75
hgs
parents: 70
diff changeset
    70
    mIsGridAdjusting(false),
hgs
parents: 70
diff changeset
    71
    mEventIndicatorNotSet(false)
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    72
{
51
hgs
parents: 45
diff changeset
    73
    OstTraceFunctionEntry0( CALENMONTHGRID_CALENMONTHGRID_ENTRY );
hgs
parents: 45
diff changeset
    74
    
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    75
	setScrollDirections(Qt::Vertical);
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    76
	setRowCount(KNumOfVisibleRows);
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    77
	setColumnCount(KCalenDaysInWeek);
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    78
	setItemRecycling(false);
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    79
	setSelectionMode(HbGridView::NoSelection);
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    80
	setUniformItemSizes(true);
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
    81
	setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
45
hgs
parents: 23
diff changeset
    82
	setClampingStyle(HbScrollArea::StrictClamping);
hgs
parents: 23
diff changeset
    83
	setEnabledAnimations(HbAbstractItemView::None);
hgs
parents: 23
diff changeset
    84
	setFrictionEnabled(false);
hgs
parents: 23
diff changeset
    85
	setFlag(QGraphicsItem::ItemHasNoContents, false);
63
hgs
parents: 57
diff changeset
    86
	
75
hgs
parents: 70
diff changeset
    87
	// Enable the pixmap cache for better scrolling performance
hgs
parents: 70
diff changeset
    88
	setItemPixmapCacheEnabled(true);
hgs
parents: 70
diff changeset
    89
	
63
hgs
parents: 57
diff changeset
    90
	// Disable the rows and columns swapping on orientation change
hgs
parents: 57
diff changeset
    91
	setSwapDimensionsOnOrientationChange(false);
hgs
parents: 57
diff changeset
    92
	
45
hgs
parents: 23
diff changeset
    93
	resetTransform();
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    94
	
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    95
	// Get the content widget of the scroll area to draw the grid lines
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
    96
	mContentWidget = contentWidget();
63
hgs
parents: 57
diff changeset
    97
45
hgs
parents: 23
diff changeset
    98
	// Get the localised dates well before
hgs
parents: 23
diff changeset
    99
	// TODO: Need to update the mLocalisedDates when user changes the
hgs
parents: 23
diff changeset
   100
	// phone language keeping calendar application in background
hgs
parents: 23
diff changeset
   101
	HbExtendedLocale locale = HbExtendedLocale::system();
hgs
parents: 23
diff changeset
   102
	for (int i = 1; i <= 31; i++) {
hgs
parents: 23
diff changeset
   103
		mLocalisedDates.append(locale.toString(i));
hgs
parents: 23
diff changeset
   104
	}
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   105
	
45
hgs
parents: 23
diff changeset
   106
	// Connect to scrolling finished signal
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   107
	connect(this, SIGNAL(scrollingEnded()), this,
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   108
			SLOT(scrollingFinished()));
63
hgs
parents: 57
diff changeset
   109
hgs
parents: 57
diff changeset
   110
    connect(
hgs
parents: 57
diff changeset
   111
                HbTheme::instance(), SIGNAL(changed()),
hgs
parents: 57
diff changeset
   112
                this, SLOT(handleThemeChange()));
hgs
parents: 57
diff changeset
   113
				
hgs
parents: 57
diff changeset
   114
	// Disable the haptic feedback for the month grid during scrolling
hgs
parents: 57
diff changeset
   115
    setAttribute(Hb::InteractionDisabled);
51
hgs
parents: 45
diff changeset
   116
	
hgs
parents: 45
diff changeset
   117
	OstTraceFunctionExit0( CALENMONTHGRID_CALENMONTHGRID_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   118
}
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   119
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   120
/*!
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   121
 Destructor
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   122
 */
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   123
CalenMonthGrid::~CalenMonthGrid()
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   124
{
51
hgs
parents: 45
diff changeset
   125
    OstTraceFunctionEntry0( DUP1_CALENMONTHGRID_CALENMONTHGRID_ENTRY );
hgs
parents: 45
diff changeset
   126
    
45
hgs
parents: 23
diff changeset
   127
	// Nothing Yet
51
hgs
parents: 45
diff changeset
   128
    
hgs
parents: 45
diff changeset
   129
    OstTraceFunctionExit0( DUP1_CALENMONTHGRID_CALENMONTHGRID_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   130
}
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   131
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   132
/*!
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   133
 Stores the view pointer
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   134
 */
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   135
void CalenMonthGrid::setView(CalenMonthView *view)
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   136
{
51
hgs
parents: 45
diff changeset
   137
    OstTraceFunctionEntry0( CALENMONTHGRID_SETVIEW_ENTRY );
hgs
parents: 45
diff changeset
   138
    
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   139
	mView = view;
51
hgs
parents: 45
diff changeset
   140
	
hgs
parents: 45
diff changeset
   141
	OstTraceFunctionExit0( CALENMONTHGRID_SETVIEW_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   142
}
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   143
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   144
/*!
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   145
 Updates the model with the proper dates and sets the required user roles
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   146
 */
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   147
void CalenMonthGrid::updateMonthGridModel(QList<CalenMonthData> &monthDataArray,
45
hgs
parents: 23
diff changeset
   148
                        int indexToBeScrolled, bool isFirstTime)
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   149
{
51
hgs
parents: 45
diff changeset
   150
    OstTraceFunctionEntry0( CALENMONTHGRID_UPDATEMONTHGRIDMODEL_ENTRY );
hgs
parents: 45
diff changeset
   151
    
45
hgs
parents: 23
diff changeset
   152
	int loopStart = 0;
hgs
parents: 23
diff changeset
   153
	int loopEnd = monthDataArray.count();
hgs
parents: 23
diff changeset
   154
	if (isFirstTime) {
hgs
parents: 23
diff changeset
   155
		// Create the model with only 42 items as visible to the user
hgs
parents: 23
diff changeset
   156
		mModel = new QStandardItemModel(KCalenDaysInWeek * KNumOfVisibleRows, 
hgs
parents: 23
diff changeset
   157
		                                1, this);
hgs
parents: 23
diff changeset
   158
		loopStart = (mView->rowsInPrevMonth()) * KCalenDaysInWeek;
hgs
parents: 23
diff changeset
   159
		loopEnd = loopStart + (KCalenDaysInWeek * KNumOfVisibleRows);
hgs
parents: 23
diff changeset
   160
	} else {
hgs
parents: 23
diff changeset
   161
		// Block the signals generated by model, this is being done as
hgs
parents: 23
diff changeset
   162
		// we want to avoid the overload of view listening to signals
hgs
parents: 23
diff changeset
   163
		mModel->blockSignals(true);
hgs
parents: 23
diff changeset
   164
		
hgs
parents: 23
diff changeset
   165
		// Check the counts
hgs
parents: 23
diff changeset
   166
		int dataCount = monthDataArray.count();
hgs
parents: 23
diff changeset
   167
		int rowCount = mModel->rowCount();
hgs
parents: 23
diff changeset
   168
		int countDiff = dataCount - rowCount;
hgs
parents: 23
diff changeset
   169
		if (countDiff < 0) {
hgs
parents: 23
diff changeset
   170
			// Delete extra rows in the model
hgs
parents: 23
diff changeset
   171
			mModel->removeRows(dataCount,abs(countDiff));
hgs
parents: 23
diff changeset
   172
		} else if (countDiff > 0) {
hgs
parents: 23
diff changeset
   173
			// Add the necessary number of rows
hgs
parents: 23
diff changeset
   174
			mModel->insertRows(rowCount,countDiff);
hgs
parents: 23
diff changeset
   175
		}
hgs
parents: 23
diff changeset
   176
		loopEnd = dataCount;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   177
	}
45
hgs
parents: 23
diff changeset
   178
	
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   179
	QDateTime activeDay = mView->getActiveDay();
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   180
	QDateTime activeDateTime = CalenDateUtils::beginningOfDay(activeDay);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   181
	
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   182
	QModelIndex currentIndex;
45
hgs
parents: 23
diff changeset
   183
	int modelIndex = 0;
hgs
parents: 23
diff changeset
   184
	for (int i = loopStart; i < loopEnd; i++) {
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   185
		QDateTime dateTime = monthDataArray[i].Day();
45
hgs
parents: 23
diff changeset
   186
		currentIndex = mModel->index(modelIndex++, 0);
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   187
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   188
		// Create the variant list to contain the date to depict a grid item
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   189
		QVariantList itemData;
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   190
		
45
hgs
parents: 23
diff changeset
   191
		// !!!NOTE!!!: Add the data in the order mentioned in the 
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   192
		// CalendarNamespace::DataRole enum. Dont change the order.
45
hgs
parents: 23
diff changeset
   193
		itemData << mLocalisedDates.at(dateTime.date().day()-1); 
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   194
		
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   195
		// Check for active day
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   196
		if (activeDateTime == CalenDateUtils::beginningOfDay(dateTime)) {
45
hgs
parents: 23
diff changeset
   197
			mCurrentRow = i;
hgs
parents: 23
diff changeset
   198
			// Set the focus attribute to true
hgs
parents: 23
diff changeset
   199
			itemData << true;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   200
		} else {
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   201
			// reset the highlight
45
hgs
parents: 23
diff changeset
   202
			itemData << false;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   203
		}
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   204
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   205
		// Check for current day
81
hgs
parents: 75
diff changeset
   206
		if (QDate::currentDate() == dateTime.date()) {
45
hgs
parents: 23
diff changeset
   207
			// Set the underline attribute to true
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   208
			itemData << true;
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   209
		} else {			
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   210
			itemData << false;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   211
		}
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   212
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   213
		// Check for events
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   214
		if (monthDataArray[i].HasEvents()) {
45
hgs
parents: 23
diff changeset
   215
			// Set the event indicator attribute
hgs
parents: 23
diff changeset
   216
			itemData << true;
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   217
		} else {
45
hgs
parents: 23
diff changeset
   218
			itemData << false;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   219
		}
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   220
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   221
		// Add default text color
45
hgs
parents: 23
diff changeset
   222
		if (monthDataArray[i].isActive()) {
hgs
parents: 23
diff changeset
   223
			itemData << true;
hgs
parents: 23
diff changeset
   224
		} else {
hgs
parents: 23
diff changeset
   225
			itemData << false;
hgs
parents: 23
diff changeset
   226
		}
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   227
		mModel->itemFromIndex(currentIndex)->setData(itemData);
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   228
	}
45
hgs
parents: 23
diff changeset
   229
	
hgs
parents: 23
diff changeset
   230
	if (isFirstTime) {
hgs
parents: 23
diff changeset
   231
		
hgs
parents: 23
diff changeset
   232
		// Create the prototype
63
hgs
parents: 57
diff changeset
   233
		CalenGridItemPrototype* gridItemPrototype = new CalenGridItemPrototype(this);
45
hgs
parents: 23
diff changeset
   234
		
63
hgs
parents: 57
diff changeset
   235
	    connect(
hgs
parents: 57
diff changeset
   236
	            HbTheme::instance(), SIGNAL(changed()),
hgs
parents: 57
diff changeset
   237
	            gridItemPrototype, SLOT(handleThemeChange()));
45
hgs
parents: 23
diff changeset
   238
		
hgs
parents: 23
diff changeset
   239
		// Register the widgetml and css files
hgs
parents: 23
diff changeset
   240
		HbStyleLoader::registerFilePath(":/");
hgs
parents: 23
diff changeset
   241
		
hgs
parents: 23
diff changeset
   242
		// Set the layout name
hgs
parents: 23
diff changeset
   243
		setLayoutName("calendarCustomGridItem");
75
hgs
parents: 70
diff changeset
   244
		
hgs
parents: 70
diff changeset
   245
		// Set the mode and the prototypec --> set it after setting layout name and 
hgs
parents: 70
diff changeset
   246
		// other things as it will avoid unnecessary polish calls
hgs
parents: 70
diff changeset
   247
        setModel(mModel,gridItemPrototype);
45
hgs
parents: 23
diff changeset
   248
	} else {
hgs
parents: 23
diff changeset
   249
		// Since, we have finished setData, Now unblock the signals
hgs
parents: 23
diff changeset
   250
		mModel->blockSignals(false);
hgs
parents: 23
diff changeset
   251
		
hgs
parents: 23
diff changeset
   252
		// Since till now, we had blocked signals being generated frm the mode
hgs
parents: 23
diff changeset
   253
		// view will be unaware of the items that we added. Hence, inform the view
hgs
parents: 23
diff changeset
   254
		// explicitly in one shot
hgs
parents: 23
diff changeset
   255
		QModelIndex leftIndex = mModel->index(0, 0);
hgs
parents: 23
diff changeset
   256
		QModelIndex rightIndex = mModel->index(loopEnd-1, 0);
hgs
parents: 23
diff changeset
   257
		dataChanged(leftIndex, rightIndex);
hgs
parents: 23
diff changeset
   258
		
hgs
parents: 23
diff changeset
   259
		// NOTE: To make sure that we always display proper month,
hgs
parents: 23
diff changeset
   260
		// two calls have been  made to scrollTo(), one with top
hgs
parents: 23
diff changeset
   261
		// visible item and other with bottom visible item
hgs
parents: 23
diff changeset
   262
		// Calculate the first visible item in the grid
hgs
parents: 23
diff changeset
   263
		
hgs
parents: 23
diff changeset
   264
		// Calculate the last visible item in the grid
hgs
parents: 23
diff changeset
   265
		QModelIndex lastVisibleIndex = mModel->index(indexToBeScrolled, 0);
81
hgs
parents: 75
diff changeset
   266
		scrollTo(lastVisibleIndex, HbAbstractItemView::PositionAtBottom);
45
hgs
parents: 23
diff changeset
   267
	}
51
hgs
parents: 45
diff changeset
   268
	
hgs
parents: 45
diff changeset
   269
	OstTraceFunctionExit0( CALENMONTHGRID_UPDATEMONTHGRIDMODEL_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   270
}
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   271
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   272
/*!
45
hgs
parents: 23
diff changeset
   273
	Updates the view with jprevious month dates when calendar is opened for the 
hgs
parents: 23
diff changeset
   274
	first time to improve the opening time
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   275
 */
45
hgs
parents: 23
diff changeset
   276
void CalenMonthGrid::updateMonthGridWithInActiveMonths(
hgs
parents: 23
diff changeset
   277
										QList<CalenMonthData> &monthDataArray)
hgs
parents: 23
diff changeset
   278
{	
51
hgs
parents: 45
diff changeset
   279
    OstTraceFunctionEntry0( CALENMONTHGRID_UPDATEMONTHGRIDWITHINACTIVEMONTHS_ENTRY );
45
hgs
parents: 23
diff changeset
   280
		
hgs
parents: 23
diff changeset
   281
	// Prepend the required rows
hgs
parents: 23
diff changeset
   282
	handlePrependingRows(monthDataArray);
hgs
parents: 23
diff changeset
   283
	
hgs
parents: 23
diff changeset
   284
	// Append the required rows
hgs
parents: 23
diff changeset
   285
	handleAppendingRows(monthDataArray);
hgs
parents: 23
diff changeset
   286
	
hgs
parents: 23
diff changeset
   287
	int rowsInPrevMonth = mView->rowsInPrevMonth();
hgs
parents: 23
diff changeset
   288
	
hgs
parents: 23
diff changeset
   289
	// Calculate the proper index to be scrolled to
81
hgs
parents: 75
diff changeset
   290
		
hgs
parents: 75
diff changeset
   291
	int itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * 
hgs
parents: 75
diff changeset
   292
								   KCalenDaysInWeek) - 1;
45
hgs
parents: 23
diff changeset
   293
	QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
hgs
parents: 23
diff changeset
   294
	mIsAtomicScroll = true;
81
hgs
parents: 75
diff changeset
   295
	scrollTo(indexToBeScrolled, HbAbstractItemView::PositionAtBottom);
45
hgs
parents: 23
diff changeset
   296
	
hgs
parents: 23
diff changeset
   297
	// Update the sart position of the content widget
hgs
parents: 23
diff changeset
   298
	mStartPos = mContentWidget->pos();
hgs
parents: 23
diff changeset
   299
	
hgs
parents: 23
diff changeset
   300
	// Now connect to the signal which gets emitted when any item on the grid 
hgs
parents: 23
diff changeset
   301
	// is tapped.
hgs
parents: 23
diff changeset
   302
	connect(this, SIGNAL(activated(const QModelIndex &)), this,
hgs
parents: 23
diff changeset
   303
						SLOT(itemActivated(const QModelIndex &)));
51
hgs
parents: 45
diff changeset
   304
	
75
hgs
parents: 70
diff changeset
   305
	// Check if we need to set the event indicators
hgs
parents: 70
diff changeset
   306
	if(mEventIndicatorNotSet) {
hgs
parents: 70
diff changeset
   307
	    mEventIndicatorNotSet = false;
hgs
parents: 70
diff changeset
   308
	    updateMonthGridWithEventIndicators(monthDataArray);
hgs
parents: 70
diff changeset
   309
	}
51
hgs
parents: 45
diff changeset
   310
	OstTraceFunctionExit0( CALENMONTHGRID_UPDATEMONTHGRIDWITHINACTIVEMONTHS_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   311
}
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   312
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   313
/*!
45
hgs
parents: 23
diff changeset
   314
	Updates the view with just event indicators
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   315
 */
45
hgs
parents: 23
diff changeset
   316
void CalenMonthGrid::updateMonthGridWithEventIndicators(
hgs
parents: 23
diff changeset
   317
										QList<CalenMonthData> &monthDataArray)
hgs
parents: 23
diff changeset
   318
{
51
hgs
parents: 45
diff changeset
   319
    OstTraceFunctionEntry0( CALENMONTHGRID_UPDATEMONTHGRIDWITHEVENTINDICATORS_ENTRY );
hgs
parents: 45
diff changeset
   320
    
hgs
parents: 45
diff changeset
   321
	int count(monthDataArray.count());
75
hgs
parents: 70
diff changeset
   322
	
hgs
parents: 70
diff changeset
   323
	// Check if model is updated with all the dates
hgs
parents: 70
diff changeset
   324
	// If not, return false for later updation
hgs
parents: 70
diff changeset
   325
	if(count == mModel->rowCount()) {
hgs
parents: 70
diff changeset
   326
        for(int i = 0; i < count; i++) {
hgs
parents: 70
diff changeset
   327
            // Check if the day has events
hgs
parents: 70
diff changeset
   328
            if (monthDataArray[i].HasEvents()) {
hgs
parents: 70
diff changeset
   329
                QModelIndex itemIndex = mModel->index(i,0);
hgs
parents: 70
diff changeset
   330
                QVariant itemData = itemIndex.data(Qt::UserRole + 1);
hgs
parents: 70
diff changeset
   331
                QVariantList list = itemData.toList();
81
hgs
parents: 75
diff changeset
   332
				if (list.count() > CalendarNamespace::CalendarMonthEventRole ) { 
hgs
parents: 75
diff changeset
   333
	                list.replace(CalendarNamespace::CalendarMonthEventRole, true);
hgs
parents: 75
diff changeset
   334
        	        mModel->itemFromIndex(itemIndex)->setData(list);
hgs
parents: 75
diff changeset
   335
				}
75
hgs
parents: 70
diff changeset
   336
            }
hgs
parents: 70
diff changeset
   337
        }
hgs
parents: 70
diff changeset
   338
	} else {
hgs
parents: 70
diff changeset
   339
	    mEventIndicatorNotSet = true;
45
hgs
parents: 23
diff changeset
   340
	}
51
hgs
parents: 45
diff changeset
   341
	
hgs
parents: 45
diff changeset
   342
	OstTraceFunctionExit0( CALENMONTHGRID_UPDATEMONTHGRIDWITHEVENTINDICATORS_EXIT );
45
hgs
parents: 23
diff changeset
   343
}
hgs
parents: 23
diff changeset
   344
hgs
parents: 23
diff changeset
   345
/*!
hgs
parents: 23
diff changeset
   346
 Scrolls the content dowmwards
hgs
parents: 23
diff changeset
   347
 */
hgs
parents: 23
diff changeset
   348
void CalenMonthGrid::downGesture()
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   349
{
51
hgs
parents: 45
diff changeset
   350
    OstTraceFunctionEntry0( CALENMONTHGRID_DOWNGESTURE_ENTRY );
70
hgs
parents: 63
diff changeset
   351
    mIsGridAdjusting = true;
45
hgs
parents: 23
diff changeset
   352
    // Make sure that content widget is properly placed
63
hgs
parents: 57
diff changeset
   353
    // We are doing this as tapping on inactive date of previous month is leading to
hgs
parents: 57
diff changeset
   354
    // position the grid at wrong place after scrolling down. Hence, set the grid
hgs
parents: 57
diff changeset
   355
    // at proper position before we start actual scrolling
45
hgs
parents: 23
diff changeset
   356
    if (mIsNonActiveDayFocused) {
hgs
parents: 23
diff changeset
   357
        mIsAtomicScroll = true;
hgs
parents: 23
diff changeset
   358
        int itemToBeScrolled = mView->rowsInPrevMonth() * KCalenDaysInWeek;
hgs
parents: 23
diff changeset
   359
        QModelIndex indexToBeScrolled  = mModel->index(itemToBeScrolled, 0);
hgs
parents: 23
diff changeset
   360
        scrollTo(indexToBeScrolled);
hgs
parents: 23
diff changeset
   361
    }
63
hgs
parents: 57
diff changeset
   362
   
hgs
parents: 57
diff changeset
   363
    // Set the required flags
45
hgs
parents: 23
diff changeset
   364
    mDirection = down;
hgs
parents: 23
diff changeset
   365
    mIsAtomicScroll = false;
63
hgs
parents: 57
diff changeset
   366
    
hgs
parents: 57
diff changeset
   367
    // Set the active and inactive dates
hgs
parents: 57
diff changeset
   368
    QDateTime activeMonth = mView->getActiveDay();
hgs
parents: 57
diff changeset
   369
    // For previous month, substract one month to the current month
hgs
parents: 57
diff changeset
   370
    setActiveDates(activeMonth.addMonths(-1).date());
hgs
parents: 57
diff changeset
   371
    mActiveDatesSet = true;
hgs
parents: 57
diff changeset
   372
    // Set the focus to proper date before scrolling to avoid somekind of
hgs
parents: 57
diff changeset
   373
    // jerkiness
hgs
parents: 57
diff changeset
   374
    if (!mIsNonActiveDayFocused) {
hgs
parents: 57
diff changeset
   375
        setFocusToProperDay();
hgs
parents: 57
diff changeset
   376
    }
hgs
parents: 57
diff changeset
   377
    
hgs
parents: 57
diff changeset
   378
    // Start the scrolling
45
hgs
parents: 23
diff changeset
   379
    QPointF targetPos(0.0, 0.0);
hgs
parents: 23
diff changeset
   380
    scrollContentsTo(targetPos,500);
51
hgs
parents: 45
diff changeset
   381
    
hgs
parents: 45
diff changeset
   382
    OstTraceFunctionExit0( CALENMONTHGRID_DOWNGESTURE_EXIT );
45
hgs
parents: 23
diff changeset
   383
}
hgs
parents: 23
diff changeset
   384
hgs
parents: 23
diff changeset
   385
/*!
hgs
parents: 23
diff changeset
   386
 Scrolls the content upwards
hgs
parents: 23
diff changeset
   387
 */
hgs
parents: 23
diff changeset
   388
void CalenMonthGrid::upGesture()
hgs
parents: 23
diff changeset
   389
{
51
hgs
parents: 45
diff changeset
   390
    OstTraceFunctionEntry0( CALENMONTHGRID_UPGESTURE_ENTRY );
70
hgs
parents: 63
diff changeset
   391
	
hgs
parents: 63
diff changeset
   392
    mIsGridAdjusting = true;
hgs
parents: 63
diff changeset
   393
63
hgs
parents: 57
diff changeset
   394
    // Set the required flags
45
hgs
parents: 23
diff changeset
   395
    mDirection = up;
hgs
parents: 23
diff changeset
   396
    mIsAtomicScroll = false;
63
hgs
parents: 57
diff changeset
   397
    
hgs
parents: 57
diff changeset
   398
    // Set the active and inactive dates
hgs
parents: 57
diff changeset
   399
    QDateTime activeMonth = mView->getActiveDay();
hgs
parents: 57
diff changeset
   400
    // For next month, add one month to the current month
hgs
parents: 57
diff changeset
   401
    setActiveDates(activeMonth.addMonths(1).date());
hgs
parents: 57
diff changeset
   402
    mActiveDatesSet = true;
hgs
parents: 57
diff changeset
   403
    // Set the focus to proper date before scrolling to avoid somekind of
hgs
parents: 57
diff changeset
   404
    // jerkiness
hgs
parents: 57
diff changeset
   405
    if (!mIsNonActiveDayFocused) {
hgs
parents: 57
diff changeset
   406
        setFocusToProperDay();
hgs
parents: 57
diff changeset
   407
    }
hgs
parents: 57
diff changeset
   408
    
hgs
parents: 57
diff changeset
   409
    // Start the scrolling
45
hgs
parents: 23
diff changeset
   410
    QPointF targetPos(0.0, mStartPos.y() - size().height());
hgs
parents: 23
diff changeset
   411
    scrollContentsTo(-targetPos,500);
hgs
parents: 23
diff changeset
   412
	
51
hgs
parents: 45
diff changeset
   413
    OstTraceFunctionExit0( CALENMONTHGRID_UPGESTURE_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   414
}
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   415
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   416
/*!
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   417
 Function to listen mouse press events
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   418
 */
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   419
void CalenMonthGrid::mousePressEvent(QGraphicsSceneMouseEvent* event)
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   420
{
51
hgs
parents: 45
diff changeset
   421
    OstTraceFunctionEntry0( CALENMONTHGRID_MOUSEPRESSEVENT_ENTRY );
hgs
parents: 45
diff changeset
   422
    
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   423
	// Pass it to parent
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   424
	HbGridView::mousePressEvent(event);
51
hgs
parents: 45
diff changeset
   425
	
hgs
parents: 45
diff changeset
   426
	OstTraceFunctionExit0( CALENMONTHGRID_MOUSEPRESSEVENT_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   427
}
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   428
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   429
/*!
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   430
 Function to listen mouse release events
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   431
 */
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   432
void CalenMonthGrid::mouseReleaseEvent(QGraphicsSceneMouseEvent* event)
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   433
{
51
hgs
parents: 45
diff changeset
   434
    OstTraceFunctionEntry0( CALENMONTHGRID_MOUSERELEASEEVENT_ENTRY );
hgs
parents: 45
diff changeset
   435
    
45
hgs
parents: 23
diff changeset
   436
	// Pass it grid view if pan gesture is not in progress else pass it to
hgs
parents: 23
diff changeset
   437
	// scrollarea. Problem here is, if we pass to gridview when panning, then 
hgs
parents: 23
diff changeset
   438
	// its emitting item activated signal simply becasue of which focus item
hgs
parents: 23
diff changeset
   439
	// is getting changed when you finish the pan / shake
hgs
parents: 23
diff changeset
   440
	if (!mIsPanGesture) {
hgs
parents: 23
diff changeset
   441
		HbGridView::mouseReleaseEvent(event);
hgs
parents: 23
diff changeset
   442
	} else {
hgs
parents: 23
diff changeset
   443
		HbScrollArea::mouseReleaseEvent(event);
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   444
	}
51
hgs
parents: 45
diff changeset
   445
	
hgs
parents: 45
diff changeset
   446
	OstTraceFunctionExit0( CALENMONTHGRID_MOUSERELEASEEVENT_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   447
}
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   448
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   449
/*!
45
hgs
parents: 23
diff changeset
   450
    Function to list for all the gesture events
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   451
 */
45
hgs
parents: 23
diff changeset
   452
void CalenMonthGrid::gestureEvent(QGestureEvent *event)
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   453
{
51
hgs
parents: 45
diff changeset
   454
    OstTraceFunctionEntry0( CALENMONTHGRID_GESTUREEVENT_ENTRY );
hgs
parents: 45
diff changeset
   455
    
75
hgs
parents: 70
diff changeset
   456
    // Dont listen for any gesture when grid is getting adjusted as listening to those was causing
70
hgs
parents: 63
diff changeset
   457
    // grid to stop abruptly i between
hgs
parents: 63
diff changeset
   458
    if (mIsGridAdjusting) {
hgs
parents: 63
diff changeset
   459
        // consume the event and return
hgs
parents: 63
diff changeset
   460
        qDebug()<<"RETURNING BACK";
hgs
parents: 63
diff changeset
   461
        event->ignore();
hgs
parents: 63
diff changeset
   462
        return;
hgs
parents: 63
diff changeset
   463
    }
hgs
parents: 63
diff changeset
   464
	
45
hgs
parents: 23
diff changeset
   465
   if(HbPanGesture *gesture = qobject_cast<HbPanGesture *>(event->gesture(Qt::PanGesture))) {
hgs
parents: 23
diff changeset
   466
        if (gesture->state() == Qt::GestureStarted) {
hgs
parents: 23
diff changeset
   467
            mIsAtomicScroll = false;
hgs
parents: 23
diff changeset
   468
            if (!mIsPanGesture) {
hgs
parents: 23
diff changeset
   469
                mDirection = invalid;
hgs
parents: 23
diff changeset
   470
                mStartPos = mContentWidget->pos();
63
hgs
parents: 57
diff changeset
   471
                // TODO: This work around till framework provides an api
45
hgs
parents: 23
diff changeset
   472
                // to know the direciton of the pan, until then we need
hgs
parents: 23
diff changeset
   473
                // calculate the direction explicitly
hgs
parents: 23
diff changeset
   474
                // Get to know the direction of the gesture
hgs
parents: 23
diff changeset
   475
                // Use our defined threshold temporarily till scrollarea 
hgs
parents: 23
diff changeset
   476
                // frm orbit side is made clever enough not to scroll in other direction
hgs
parents: 23
diff changeset
   477
                // apart frm the registered scroll direction
75
hgs
parents: 70
diff changeset
   478
                QPointF delta = gesture->sceneOffset();
hgs
parents: 70
diff changeset
   479
                qreal horizontalDiff = delta.x();
hgs
parents: 70
diff changeset
   480
                qreal verticalDiff = delta.y();
55
hgs
parents: 51
diff changeset
   481
                if (abs(horizontalDiff) > MAX_PAN_DIRECTION_THRESHOLD) {
45
hgs
parents: 23
diff changeset
   482
                    // Now see if y coord diff has crossed threshold
55
hgs
parents: 51
diff changeset
   483
                    if (verticalDiff > MAX_PAN_DIRECTION_THRESHOLD) {
45
hgs
parents: 23
diff changeset
   484
                        mIsPanGesture = true;
hgs
parents: 23
diff changeset
   485
                        mIgnoreItemActivated = true;
hgs
parents: 23
diff changeset
   486
                        mDirection = down;
55
hgs
parents: 51
diff changeset
   487
                    } else if (verticalDiff < -MAX_PAN_DIRECTION_THRESHOLD){
45
hgs
parents: 23
diff changeset
   488
                        mIsPanGesture = true;
hgs
parents: 23
diff changeset
   489
                        mIgnoreItemActivated = true;
hgs
parents: 23
diff changeset
   490
                        mDirection = up;
hgs
parents: 23
diff changeset
   491
                    } else {
hgs
parents: 23
diff changeset
   492
                        event->accept(Qt::PanGesture);
51
hgs
parents: 45
diff changeset
   493
                        OstTraceFunctionExit0( CALENMONTHGRID_GESTUREEVENT_EXIT );
45
hgs
parents: 23
diff changeset
   494
                        return;
hgs
parents: 23
diff changeset
   495
                    }
55
hgs
parents: 51
diff changeset
   496
                } else if (abs(horizontalDiff) < MAX_PAN_DIRECTION_THRESHOLD) {
hgs
parents: 51
diff changeset
   497
                   if (verticalDiff > MIN_PAN_DIRECTION_THRESHOLD) {
45
hgs
parents: 23
diff changeset
   498
                        mIsPanGesture = true;
hgs
parents: 23
diff changeset
   499
                        mIgnoreItemActivated = true;
hgs
parents: 23
diff changeset
   500
                        mDirection = down;
55
hgs
parents: 51
diff changeset
   501
                   } else if (verticalDiff < -MIN_PAN_DIRECTION_THRESHOLD){
45
hgs
parents: 23
diff changeset
   502
                        mIsPanGesture = true;
hgs
parents: 23
diff changeset
   503
                        mIgnoreItemActivated = true;
hgs
parents: 23
diff changeset
   504
                        mDirection = up;
hgs
parents: 23
diff changeset
   505
                   }else {
hgs
parents: 23
diff changeset
   506
                       event->accept(Qt::PanGesture);
51
hgs
parents: 45
diff changeset
   507
                       OstTraceFunctionExit0( DUP1_CALENMONTHGRID_GESTUREEVENT_EXIT );
45
hgs
parents: 23
diff changeset
   508
                       return;
hgs
parents: 23
diff changeset
   509
                   }
hgs
parents: 23
diff changeset
   510
                } 
hgs
parents: 23
diff changeset
   511
            }
hgs
parents: 23
diff changeset
   512
        }
hgs
parents: 23
diff changeset
   513
    } else if(HbSwipeGesture *gesture = qobject_cast<HbSwipeGesture *>(event->gesture(Qt::SwipeGesture))) {
hgs
parents: 23
diff changeset
   514
        if (gesture->state() == Qt::GestureStarted) {
hgs
parents: 23
diff changeset
   515
            mIsAtomicScroll = false;
hgs
parents: 23
diff changeset
   516
            mDirection = invalid;
hgs
parents: 23
diff changeset
   517
            if (gesture->sceneVerticalDirection() == QSwipeGesture::Down) {
hgs
parents: 23
diff changeset
   518
                mDirection = down;
hgs
parents: 23
diff changeset
   519
            } else if (gesture->sceneVerticalDirection() == QSwipeGesture::Up) {
hgs
parents: 23
diff changeset
   520
                mDirection = up;
hgs
parents: 23
diff changeset
   521
            } else {
hgs
parents: 23
diff changeset
   522
                event->accept(Qt::SwipeGesture);
51
hgs
parents: 45
diff changeset
   523
                OstTraceFunctionExit0( DUP2_CALENMONTHGRID_GESTUREEVENT_EXIT );
45
hgs
parents: 23
diff changeset
   524
                return;
hgs
parents: 23
diff changeset
   525
            }
hgs
parents: 23
diff changeset
   526
        }
51
hgs
parents: 45
diff changeset
   527
    } else if (HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
hgs
parents: 45
diff changeset
   528
        if(gesture->state() == Qt::GestureFinished) {
hgs
parents: 45
diff changeset
   529
            // Check if scrolling is in progress
hgs
parents: 45
diff changeset
   530
            if (mDirection != invalid) {
hgs
parents: 45
diff changeset
   531
                // Set the pan flag to true so that grid adjusts to nearest
hgs
parents: 45
diff changeset
   532
                // month after tapping
hgs
parents: 45
diff changeset
   533
                mIsPanGesture = true;
hgs
parents: 45
diff changeset
   534
                handlePanGestureFinished();
hgs
parents: 45
diff changeset
   535
            }
hgs
parents: 45
diff changeset
   536
        }
45
hgs
parents: 23
diff changeset
   537
    }
hgs
parents: 23
diff changeset
   538
   
75
hgs
parents: 70
diff changeset
   539
   // Check if we can scroll
hgs
parents: 70
diff changeset
   540
   if (!checkIfWeCanScroll(mDirection)) {
hgs
parents: 70
diff changeset
   541
       // We cannot scroll, return back
hgs
parents: 70
diff changeset
   542
       mIsPanGesture = false;
hgs
parents: 70
diff changeset
   543
       mIgnoreItemActivated = false;
hgs
parents: 70
diff changeset
   544
       mDirection = invalid;
hgs
parents: 70
diff changeset
   545
       event->accept(Qt::PanGesture);
hgs
parents: 70
diff changeset
   546
   }
hgs
parents: 70
diff changeset
   547
   
45
hgs
parents: 23
diff changeset
   548
   if (mDirection!= invalid) {
hgs
parents: 23
diff changeset
   549
        // Call the parent class to perform the pan gesture
hgs
parents: 23
diff changeset
   550
        // When scrolling finished, month grid will adjust to show the proper month
hgs
parents: 23
diff changeset
   551
        HbScrollArea::gestureEvent(event);
hgs
parents: 23
diff changeset
   552
   }
51
hgs
parents: 45
diff changeset
   553
   
hgs
parents: 45
diff changeset
   554
   OstTraceFunctionExit0( DUP3_CALENMONTHGRID_GESTUREEVENT_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   555
}
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   556
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   557
/*!
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   558
 Gets called when scrolling finishes to update the model
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   559
 */
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   560
void CalenMonthGrid::scrollingFinished()
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   561
{
51
hgs
parents: 45
diff changeset
   562
    OstTraceFunctionEntry0( CALENMONTHGRID_SCROLLINGFINISHED_ENTRY );
70
hgs
parents: 63
diff changeset
   563
hgs
parents: 63
diff changeset
   564
    mIsGridAdjusting = false;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   565
	if (mIsPanGesture) {
45
hgs
parents: 23
diff changeset
   566
		handlePanGestureFinished();
70
hgs
parents: 63
diff changeset
   567
		// Check if still request has been made for scrolling
hgs
parents: 63
diff changeset
   568
		// if yes, then simply return
hgs
parents: 63
diff changeset
   569
		if (mDirection != invalid) {
hgs
parents: 63
diff changeset
   570
            mIgnoreItemActivated = false;
hgs
parents: 63
diff changeset
   571
            return;
hgs
parents: 63
diff changeset
   572
		}
hgs
parents: 63
diff changeset
   573
	} 
hgs
parents: 63
diff changeset
   574
	
hgs
parents: 63
diff changeset
   575
	if(!mIsAtomicScroll) {
45
hgs
parents: 23
diff changeset
   576
		QDateTime activeDate = mView->getActiveDay();
hgs
parents: 23
diff changeset
   577
		if(mDirection == down) { // down gesture
63
hgs
parents: 57
diff changeset
   578
			if (!mActiveDatesSet) {
45
hgs
parents: 23
diff changeset
   579
				setActiveDates(activeDate.addMonths(-1).date());
63
hgs
parents: 57
diff changeset
   580
				setFocusToProperDay();
45
hgs
parents: 23
diff changeset
   581
			}
hgs
parents: 23
diff changeset
   582
			prependRows();
hgs
parents: 23
diff changeset
   583
		} else if (mDirection == up) { //up gesture
63
hgs
parents: 57
diff changeset
   584
			if (!mActiveDatesSet) {
45
hgs
parents: 23
diff changeset
   585
				setActiveDates(activeDate.addMonths(1).date());
63
hgs
parents: 57
diff changeset
   586
				setFocusToProperDay();
45
hgs
parents: 23
diff changeset
   587
			}
hgs
parents: 23
diff changeset
   588
			appendRows();
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   589
		}
45
hgs
parents: 23
diff changeset
   590
		mDirection = invalid;
63
hgs
parents: 57
diff changeset
   591
		mActiveDatesSet = false;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   592
	} else {
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   593
        mIsAtomicScroll = false;
45
hgs
parents: 23
diff changeset
   594
        mDirection = invalid;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   595
	}
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   596
	mIgnoreItemActivated = false;
51
hgs
parents: 45
diff changeset
   597
	
hgs
parents: 45
diff changeset
   598
	OstTraceFunctionExit0( CALENMONTHGRID_SCROLLINGFINISHED_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   599
}
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   600
45
hgs
parents: 23
diff changeset
   601
/*!
hgs
parents: 23
diff changeset
   602
 Function to handle completion of pan gesture
hgs
parents: 23
diff changeset
   603
 */
hgs
parents: 23
diff changeset
   604
void CalenMonthGrid::handlePanGestureFinished()
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   605
{
51
hgs
parents: 45
diff changeset
   606
    OstTraceFunctionEntry0( CALENMONTHGRID_HANDLEPANGESTUREFINISHED_ENTRY );
hgs
parents: 45
diff changeset
   607
    
45
hgs
parents: 23
diff changeset
   608
	mIsPanGesture = false;
70
hgs
parents: 63
diff changeset
   609
	// Reset the mDirection flag
hgs
parents: 63
diff changeset
   610
	mDirection = invalid;
45
hgs
parents: 23
diff changeset
   611
	// Get the first item that is visible
hgs
parents: 23
diff changeset
   612
	QList<HbAbstractViewItem *> list = visibleItems();
hgs
parents: 23
diff changeset
   613
	HbAbstractViewItem* item = list[0];
hgs
parents: 23
diff changeset
   614
	QModelIndex modelIndex = item->modelIndex();
hgs
parents: 23
diff changeset
   615
	
hgs
parents: 23
diff changeset
   616
	// Get the date which is visible at the above row
55
hgs
parents: 51
diff changeset
   617
	QList<CalenMonthData>& monthDataArray = mView->monthDataList();
hgs
parents: 51
diff changeset
   618
	QDateTime date = monthDataArray[modelIndex.row()].Day();
45
hgs
parents: 23
diff changeset
   619
	
hgs
parents: 23
diff changeset
   620
	// Check if this date belong to current active month or 
hgs
parents: 23
diff changeset
   621
	// previous month else future month
hgs
parents: 23
diff changeset
   622
	QDateTime activeMonth = mView->getActiveDay();
hgs
parents: 23
diff changeset
   623
	QDateTime prevMonth = activeMonth.addMonths(-1);
hgs
parents: 23
diff changeset
   624
	QDateTime nextMonth = activeMonth.addMonths(1);
hgs
parents: 23
diff changeset
   625
	int month = date.date().month();
hgs
parents: 23
diff changeset
   626
	if (month == activeMonth.date().month()) {
hgs
parents: 23
diff changeset
   627
		// Then pan is completed on current month
hgs
parents: 23
diff changeset
   628
		// Check if the date is more than half of the current month or it is
hgs
parents: 23
diff changeset
   629
		// more than or equal to half of the future month
hgs
parents: 23
diff changeset
   630
		if (date.date().day() > (activeMonth.date().daysInMonth()) / 2 ||
hgs
parents: 23
diff changeset
   631
				date.addDays(KNumOfVisibleRows*KCalenDaysInWeek).date().day() >=
hgs
parents: 23
diff changeset
   632
				(prevMonth.date().daysInMonth()) / 2) {
hgs
parents: 23
diff changeset
   633
			// up gesture to bring the next month
hgs
parents: 23
diff changeset
   634
			upGesture();
hgs
parents: 23
diff changeset
   635
		} else {
hgs
parents: 23
diff changeset
   636
			// we should again show the current month by scrolling downwards
hgs
parents: 23
diff changeset
   637
			mDirection = down;
hgs
parents: 23
diff changeset
   638
			mIsAtomicScroll = true;
hgs
parents: 23
diff changeset
   639
			scrollContentsTo(-mStartPos,500);
hgs
parents: 23
diff changeset
   640
		}
hgs
parents: 23
diff changeset
   641
	} else if (month == prevMonth.date().month()) {
hgs
parents: 23
diff changeset
   642
		// first visible item belongs to previous month
hgs
parents: 23
diff changeset
   643
		// Check if the date is more than half of the previous month
hgs
parents: 23
diff changeset
   644
		if (date.date().day() > (prevMonth.date().daysInMonth()) / 2) {
70
hgs
parents: 63
diff changeset
   645
			// we should again show the current month by scrolling downwards
hgs
parents: 63
diff changeset
   646
			mDirection = down;
45
hgs
parents: 23
diff changeset
   647
			mIsAtomicScroll = true;
hgs
parents: 23
diff changeset
   648
			scrollContentsTo(-mStartPos,500);
hgs
parents: 23
diff changeset
   649
		} else {
hgs
parents: 23
diff changeset
   650
			// down gesture to show the previous month
hgs
parents: 23
diff changeset
   651
			downGesture();
hgs
parents: 23
diff changeset
   652
		}
hgs
parents: 23
diff changeset
   653
	} else if (month == prevMonth.addMonths(-1).date().month()) {
hgs
parents: 23
diff changeset
   654
		// first visible date belong to previous to previous month
hgs
parents: 23
diff changeset
   655
		// hence, scroll down to bring the previous month
hgs
parents: 23
diff changeset
   656
		downGesture();
hgs
parents: 23
diff changeset
   657
	} else if (month == nextMonth.date().month()) {
hgs
parents: 23
diff changeset
   658
		// first visible item belongs to next month
hgs
parents: 23
diff changeset
   659
		// Check if the date is more than half of the next month
hgs
parents: 23
diff changeset
   660
		if (date.date().day() > (nextMonth.date().daysInMonth()) / 2) {
hgs
parents: 23
diff changeset
   661
			// up gesture to bring the next month
hgs
parents: 23
diff changeset
   662
			upGesture();
hgs
parents: 23
diff changeset
   663
		} else {
hgs
parents: 23
diff changeset
   664
			// we should again show the current month by scrolling upwards
63
hgs
parents: 57
diff changeset
   665
			mDirection = up;
70
hgs
parents: 63
diff changeset
   666
			mIsAtomicScroll = true;
45
hgs
parents: 23
diff changeset
   667
			scrollContentsTo(-mStartPos,500);
hgs
parents: 23
diff changeset
   668
		}
hgs
parents: 23
diff changeset
   669
	} else if (month == nextMonth.addMonths(1).date().month()) {
hgs
parents: 23
diff changeset
   670
		// first visible date belongs to next to next month
hgs
parents: 23
diff changeset
   671
		// hence, scroll up to show the next month
hgs
parents: 23
diff changeset
   672
		upGesture();
70
hgs
parents: 63
diff changeset
   673
	} else {
hgs
parents: 63
diff changeset
   674
        // User has panned so that exact month has been scrolled
hgs
parents: 63
diff changeset
   675
        // no need for any adjustment here, just append/prepend the rows
hgs
parents: 63
diff changeset
   676
        mIsAtomicScroll = false;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   677
	}
51
hgs
parents: 45
diff changeset
   678
	
hgs
parents: 45
diff changeset
   679
	OstTraceFunctionExit0( CALENMONTHGRID_HANDLEPANGESTUREFINISHED_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   680
}
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   681
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   682
/*!
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   683
 Called when down gesture is performed. Adds the new previous month details
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   684
 to the model
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   685
 */
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   686
void CalenMonthGrid::prependRows()
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   687
{
51
hgs
parents: 45
diff changeset
   688
    OstTraceFunctionEntry0( CALENMONTHGRID_PREPENDROWS_ENTRY );
45
hgs
parents: 23
diff changeset
   689
	
hgs
parents: 23
diff changeset
   690
	// Block the signals generated by model, this is being done as
hgs
parents: 23
diff changeset
   691
	// we want to avoid the overload of view listening to signals
hgs
parents: 23
diff changeset
   692
	mModel->blockSignals(true);
hgs
parents: 23
diff changeset
   693
		
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   694
	mIsNonActiveDayFocused = false;
45
hgs
parents: 23
diff changeset
   695
	
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   696
	int rowsInFutMonthEarlier = mView->rowsInFutMonth();
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   697
	int rowsInPrevMonthEarlier = mView->rowsInPrevMonth();
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   698
	
45
hgs
parents: 23
diff changeset
   699
	// remove the cells in the future month
hgs
parents: 23
diff changeset
   700
	int deleteFromIndex = (rowsInPrevMonthEarlier + KNumOfVisibleRows) * KCalenDaysInWeek;
hgs
parents: 23
diff changeset
   701
	int numOfIndices = rowsInFutMonthEarlier * KCalenDaysInWeek;
hgs
parents: 23
diff changeset
   702
	
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   703
	// Get the updated dates from the view
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   704
	mView->updateModelWithPrevMonth();
55
hgs
parents: 51
diff changeset
   705
	QList<CalenMonthData >& monthDataList = mView->monthDataList();
45
hgs
parents: 23
diff changeset
   706
	
hgs
parents: 23
diff changeset
   707
	// Prepend the required rows
hgs
parents: 23
diff changeset
   708
	handlePrependingRows(monthDataList);
hgs
parents: 23
diff changeset
   709
		
hgs
parents: 23
diff changeset
   710
	// Since, we have finished setData, Now unblock the signals
hgs
parents: 23
diff changeset
   711
	mModel->blockSignals(false);
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   712
	
45
hgs
parents: 23
diff changeset
   713
	int rowsInPrevMonth = mView->rowsInPrevMonth();
hgs
parents: 23
diff changeset
   714
	int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek;
hgs
parents: 23
diff changeset
   715
		
hgs
parents: 23
diff changeset
   716
	// Since till now, we had blocked signals being generated frm the model
hgs
parents: 23
diff changeset
   717
	// view will be unaware of the items that we added. Hence, inform the view
hgs
parents: 23
diff changeset
   718
	// explicitly in one shot
hgs
parents: 23
diff changeset
   719
	QModelIndex leftIndex = mModel->index(0, 0);
hgs
parents: 23
diff changeset
   720
	QModelIndex rightIndex = mModel->index(countToBeAdded-1, 0);
hgs
parents: 23
diff changeset
   721
	dataChanged(leftIndex, rightIndex);
hgs
parents: 23
diff changeset
   722
		
hgs
parents: 23
diff changeset
   723
	// Now remove the necessary items frm the model
hgs
parents: 23
diff changeset
   724
	mModel->removeRows(deleteFromIndex+countToBeAdded, numOfIndices);
hgs
parents: 23
diff changeset
   725
	mIsAtomicScroll = true;
hgs
parents: 23
diff changeset
   726
	int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek;
hgs
parents: 23
diff changeset
   727
	QModelIndex indexToBeScrolled  = mModel->index(itemToBeScrolled, 0);
hgs
parents: 23
diff changeset
   728
	scrollTo(indexToBeScrolled);
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   729
	
45
hgs
parents: 23
diff changeset
   730
	// Scroll to proper index
hgs
parents: 23
diff changeset
   731
	itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * 
hgs
parents: 23
diff changeset
   732
								   KCalenDaysInWeek) - 1;
hgs
parents: 23
diff changeset
   733
	indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
hgs
parents: 23
diff changeset
   734
	mIsAtomicScroll = true;
hgs
parents: 23
diff changeset
   735
	scrollTo(indexToBeScrolled);
hgs
parents: 23
diff changeset
   736
	// Update the mCurrentRow
hgs
parents: 23
diff changeset
   737
	mCurrentRow += countToBeAdded;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   738
	
45
hgs
parents: 23
diff changeset
   739
	// Update the sart position of the content widget
hgs
parents: 23
diff changeset
   740
	mStartPos = mContentWidget->pos();
51
hgs
parents: 45
diff changeset
   741
	
hgs
parents: 45
diff changeset
   742
	OstTraceFunctionExit0( CALENMONTHGRID_PREPENDROWS_EXIT );
45
hgs
parents: 23
diff changeset
   743
}
hgs
parents: 23
diff changeset
   744
hgs
parents: 23
diff changeset
   745
/*!
hgs
parents: 23
diff changeset
   746
	Helper function that prepends the required rows to the model
hgs
parents: 23
diff changeset
   747
 */
hgs
parents: 23
diff changeset
   748
void CalenMonthGrid::handlePrependingRows(QList<CalenMonthData > &monthDataList)
hgs
parents: 23
diff changeset
   749
{
51
hgs
parents: 45
diff changeset
   750
    OstTraceFunctionEntry0( CALENMONTHGRID_HANDLEPREPENDINGROWS_ENTRY );
hgs
parents: 45
diff changeset
   751
    
45
hgs
parents: 23
diff changeset
   752
	int rowsInPrevMonth = mView->rowsInPrevMonth();
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   753
	// Add the new days
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   754
	int countToBeAdded = rowsInPrevMonth * KCalenDaysInWeek;
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   755
	
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   756
	mModel->insertRows(0, countToBeAdded);
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   757
	
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   758
	for (int i = 0; i < countToBeAdded; i++) {
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   759
		QDateTime dateTime = monthDataList[i].Day();
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   760
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   761
		// Get the localised string for the day
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   762
		QModelIndex currentIndex = mModel->index(i, 0);
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   763
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   764
		// Create the variant list to contain the date to depict a grid item
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   765
		QVariantList itemData;
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   766
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   767
		// NOTE: Add the data in the order mentioned in the 
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   768
		// CalendarNamespace::DataRole enum. Dont change the order.
45
hgs
parents: 23
diff changeset
   769
		itemData << mLocalisedDates.at(dateTime.date().day()-1);;
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   770
				
45
hgs
parents: 23
diff changeset
   771
		// Disable the focus role
hgs
parents: 23
diff changeset
   772
		itemData << false;
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   773
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   774
		// Check for current day
81
hgs
parents: 75
diff changeset
   775
		if (QDate::currentDate() == dateTime.date()) {
45
hgs
parents: 23
diff changeset
   776
			// Set the underline icon attribute
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   777
			itemData << true;
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   778
		} else {
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   779
			itemData << false;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   780
		}
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   781
		
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   782
		// Update the event indicators
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   783
		if (monthDataList[i].HasEvents()) {
45
hgs
parents: 23
diff changeset
   784
			// Set the event indicator attribute
hgs
parents: 23
diff changeset
   785
			itemData << true;
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   786
		} else {
45
hgs
parents: 23
diff changeset
   787
			itemData << false;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   788
		}
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   789
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   790
		// Add default text color
45
hgs
parents: 23
diff changeset
   791
		itemData << false;
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   792
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   793
		// Set the data to model
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   794
		mModel->itemFromIndex(currentIndex)->setData(itemData);
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   795
	}
51
hgs
parents: 45
diff changeset
   796
	
hgs
parents: 45
diff changeset
   797
	OstTraceFunctionExit0( CALENMONTHGRID_HANDLEPREPENDINGROWS_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   798
}
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   799
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   800
/*!
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   801
 Called when Up gwsture is performed. Adds the new future month details
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   802
 to the model
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   803
 */
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   804
void CalenMonthGrid::appendRows()
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   805
{
51
hgs
parents: 45
diff changeset
   806
    OstTraceFunctionEntry0( CALENMONTHGRID_APPENDROWS_ENTRY );
45
hgs
parents: 23
diff changeset
   807
	
hgs
parents: 23
diff changeset
   808
	// Block the signals generated by model, this is being done as
hgs
parents: 23
diff changeset
   809
	// we want to avoid the overload of view listening to signals
hgs
parents: 23
diff changeset
   810
	mModel->blockSignals(true);
hgs
parents: 23
diff changeset
   811
	
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   812
	mIsNonActiveDayFocused = false;
45
hgs
parents: 23
diff changeset
   813
	
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   814
	int rowsInFutMonth = mView->rowsInFutMonth();
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   815
	int rowsInPrevMonth = mView->rowsInPrevMonth();
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   816
	// remove the cells in the previous month
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   817
	int countToBeDeleted = rowsInPrevMonth * KCalenDaysInWeek;
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   818
		
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   819
	// Get the updated dates from the view
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   820
	mView->updateModelWithFutureMonth();
55
hgs
parents: 51
diff changeset
   821
	QList<CalenMonthData >& monthDataList = mView->monthDataList();
45
hgs
parents: 23
diff changeset
   822
	
hgs
parents: 23
diff changeset
   823
	// Get the model count before we add any rows into the mode
hgs
parents: 23
diff changeset
   824
	int rowCount = mModel->rowCount();
hgs
parents: 23
diff changeset
   825
	// Append the required rows
hgs
parents: 23
diff changeset
   826
	handleAppendingRows(monthDataList);
hgs
parents: 23
diff changeset
   827
	
hgs
parents: 23
diff changeset
   828
	// Since, we have finished setData, Now unblock the signals
hgs
parents: 23
diff changeset
   829
	mModel->blockSignals(false);
hgs
parents: 23
diff changeset
   830
	
hgs
parents: 23
diff changeset
   831
	// Since till now, we had blocked signals being generated frm the mode
hgs
parents: 23
diff changeset
   832
	// view will be unaware of the items that we added. Hence, inform the view
hgs
parents: 23
diff changeset
   833
	// explicitly in one shot
hgs
parents: 23
diff changeset
   834
	QModelIndex leftIndex = mModel->index(rowCount-1, 0);
hgs
parents: 23
diff changeset
   835
	QModelIndex rightIndex = mModel->index(mModel->rowCount()-1, 0);
hgs
parents: 23
diff changeset
   836
	dataChanged(leftIndex, rightIndex);
hgs
parents: 23
diff changeset
   837
		
hgs
parents: 23
diff changeset
   838
	// Update the mCurrentRow
hgs
parents: 23
diff changeset
   839
	mCurrentRow -= (countToBeDeleted);
hgs
parents: 23
diff changeset
   840
	for (int i = 0; i < countToBeDeleted; i++) {
hgs
parents: 23
diff changeset
   841
		mModel->removeRow(0);
hgs
parents: 23
diff changeset
   842
	}
hgs
parents: 23
diff changeset
   843
	
hgs
parents: 23
diff changeset
   844
	mIsAtomicScroll = true;
hgs
parents: 23
diff changeset
   845
	
hgs
parents: 23
diff changeset
   846
	rowsInFutMonth = mView->rowsInFutMonth();
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   847
	rowsInPrevMonth = mView->rowsInPrevMonth();
45
hgs
parents: 23
diff changeset
   848
	
hgs
parents: 23
diff changeset
   849
	// Calculate the proper index to be scrolled to
hgs
parents: 23
diff changeset
   850
	int itemToBeScrolled = rowsInPrevMonth * KCalenDaysInWeek;
hgs
parents: 23
diff changeset
   851
	QModelIndex indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
hgs
parents: 23
diff changeset
   852
	scrollTo(indexToBeScrolled);
hgs
parents: 23
diff changeset
   853
	
hgs
parents: 23
diff changeset
   854
	itemToBeScrolled = ((rowsInPrevMonth + KNumOfVisibleRows) * 
hgs
parents: 23
diff changeset
   855
									   KCalenDaysInWeek) - 1;
hgs
parents: 23
diff changeset
   856
	indexToBeScrolled = mModel->index(itemToBeScrolled, 0);
hgs
parents: 23
diff changeset
   857
	mIsAtomicScroll = true;
hgs
parents: 23
diff changeset
   858
	scrollTo(indexToBeScrolled);
hgs
parents: 23
diff changeset
   859
	
hgs
parents: 23
diff changeset
   860
	// Update the sart position of the content widget
hgs
parents: 23
diff changeset
   861
    mStartPos = mContentWidget->pos();
51
hgs
parents: 45
diff changeset
   862
    
hgs
parents: 45
diff changeset
   863
    OstTraceFunctionExit0( CALENMONTHGRID_APPENDROWS_EXIT );
45
hgs
parents: 23
diff changeset
   864
}
hgs
parents: 23
diff changeset
   865
hgs
parents: 23
diff changeset
   866
/*!
hgs
parents: 23
diff changeset
   867
	Helper function that appends the required rows to the model
hgs
parents: 23
diff changeset
   868
 */
hgs
parents: 23
diff changeset
   869
void CalenMonthGrid::handleAppendingRows(QList<CalenMonthData > &monthDataList)
hgs
parents: 23
diff changeset
   870
{
51
hgs
parents: 45
diff changeset
   871
    OstTraceFunctionEntry0( CALENMONTHGRID_HANDLEAPPENDINGROWS_ENTRY );
hgs
parents: 45
diff changeset
   872
    
45
hgs
parents: 23
diff changeset
   873
	int rowsInFutMonth = mView->rowsInFutMonth();
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   874
	int countToBeAdded = rowsInFutMonth * KCalenDaysInWeek;
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   875
	int lastVisibleIndex = monthDataList.count() - countToBeAdded;
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   876
	
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   877
	int rowCount = mModel->rowCount();
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   878
	mModel->insertRows(rowCount, countToBeAdded);
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   879
	
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   880
	for (int i = 0; i < countToBeAdded; i++) {
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   881
		QModelIndex currentIndex = mModel->index(rowCount + i, 0);
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   882
				
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   883
		QDateTime dateTime = monthDataList[lastVisibleIndex + i].Day();
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   884
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   885
		// Create the variant list to contain the date to depict a grid item
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   886
		QVariantList itemData;
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   887
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   888
		// NOTE: Add the data in the order mentioned in the 
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   889
		// CalendarNamespace::DataRole enum. Dont change the order.
45
hgs
parents: 23
diff changeset
   890
		itemData << mLocalisedDates.at(dateTime.date().day()-1);;
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   891
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   892
		// Disable the focus role
45
hgs
parents: 23
diff changeset
   893
		itemData << false;
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   894
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   895
		// Check for current day
81
hgs
parents: 75
diff changeset
   896
		if (QDate::currentDate() == dateTime.date()) {
45
hgs
parents: 23
diff changeset
   897
			// Set the underline icon attribute
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   898
			itemData << true;
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   899
		} else {
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   900
			itemData << false;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   901
		}
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   902
		
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   903
		// Update the event indicators
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   904
		if (monthDataList[lastVisibleIndex + i].HasEvents()) {
45
hgs
parents: 23
diff changeset
   905
			// Set the event indicator attribute
hgs
parents: 23
diff changeset
   906
			itemData << true;
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   907
		} else {
45
hgs
parents: 23
diff changeset
   908
			itemData << false;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   909
		}
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   910
		
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   911
		// Add default text color
45
hgs
parents: 23
diff changeset
   912
		itemData << false;
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   913
				
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   914
		// Set the data to model
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   915
		mModel->itemFromIndex(currentIndex)->setData(itemData);
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   916
	}
51
hgs
parents: 45
diff changeset
   917
	
hgs
parents: 45
diff changeset
   918
	OstTraceFunctionExit0( CALENMONTHGRID_HANDLEAPPENDINGROWS_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   919
}
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   920
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   921
/*!
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   922
 Slot to handle when a particular grid item is tapped
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   923
 */
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   924
void CalenMonthGrid::itemActivated(const QModelIndex &index)
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   925
{
51
hgs
parents: 45
diff changeset
   926
    OstTraceFunctionEntry0( CALENMONTHGRID_ITEMACTIVATED_ENTRY );
hgs
parents: 45
diff changeset
   927
    
75
hgs
parents: 70
diff changeset
   928
    QList<CalenMonthData >& monthDataList = mView->monthDataList();
hgs
parents: 70
diff changeset
   929
    // Chekc if we need to ignore the event or the newly tapped date is
hgs
parents: 70
diff changeset
   930
    // not valid date
hgs
parents: 70
diff changeset
   931
	if (mIgnoreItemActivated || !(CalenDateUtils::isValidDay(monthDataList[index.row()].Day()))) {
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   932
		mIgnoreItemActivated = false;
51
hgs
parents: 45
diff changeset
   933
		OstTraceFunctionExit0( CALENMONTHGRID_ITEMACTIVATED_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   934
		return;
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   935
	}
75
hgs
parents: 70
diff changeset
   936
	
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   937
	mIsNonActiveDayFocused = false;
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   938
	// Check if the same item has been tapped twice
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   939
	if (mCurrentRow == index.row()) {
45
hgs
parents: 23
diff changeset
   940
		// Launch the Day view
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   941
		mView->launchDayView();
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   942
	} else {
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   943
		// Reset the focus attribute to this item		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   944
		QModelIndex itemIndex = mModel->index(mCurrentRow,0);
45
hgs
parents: 23
diff changeset
   945
		if(itemIndex.row() < 0 || itemIndex.row() >= mModel->rowCount() ||
hgs
parents: 23
diff changeset
   946
				itemIndex.column() < 0 || itemIndex.column() > mModel->columnCount()) {
51
hgs
parents: 45
diff changeset
   947
			OstTraceFunctionExit0( DUP1_CALENMONTHGRID_ITEMACTIVATED_EXIT );
45
hgs
parents: 23
diff changeset
   948
			return;
hgs
parents: 23
diff changeset
   949
		}
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   950
		QVariant itemData = itemIndex.data(Qt::UserRole + 1);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   951
		QVariantList list = itemData.toList();
45
hgs
parents: 23
diff changeset
   952
		list.replace(CalendarNamespace::CalendarMonthFocusRole, false);
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   953
		mModel->itemFromIndex(itemIndex)->setData(list);
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   954
		
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   955
		// Inform view to update the context and preview panes
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   956
		mCurrentRow = index.row();
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   957
		itemIndex = mModel->index(mCurrentRow,0);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   958
		itemData = itemIndex.data(Qt::UserRole + 1);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   959
		list = itemData.toList();
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   960
		list.replace(CalendarNamespace::CalendarMonthFocusRole, 
45
hgs
parents: 23
diff changeset
   961
								 true);
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   962
		mModel->itemFromIndex(itemIndex)->setData(list);
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   963
		// Check if inactive date is tapped
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   964
		QDateTime activeMonth = mView->getActiveDay();
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
   965
		int month = activeMonth.date().month();
55
hgs
parents: 51
diff changeset
   966
		if(month != monthDataList[mCurrentRow].Day().date().month()){
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   967
			// Set the flag
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   968
			mIsNonActiveDayFocused = true;
63
hgs
parents: 57
diff changeset
   969
			QDateTime nonActiveFocusedDay = monthDataList[mCurrentRow].Day();
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   970
			
45
hgs
parents: 23
diff changeset
   971
			// Add one month to active month
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   972
			activeMonth = activeMonth.addMonths(1);
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   973
			if (activeMonth.date().month() == 
63
hgs
parents: 57
diff changeset
   974
			        nonActiveFocusedDay.date().month()) {
45
hgs
parents: 23
diff changeset
   975
				mDirection = up;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   976
				// up gesture
45
hgs
parents: 23
diff changeset
   977
				upGesture();
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   978
			} else {
45
hgs
parents: 23
diff changeset
   979
				mDirection = down;
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   980
				// down gesture
45
hgs
parents: 23
diff changeset
   981
				downGesture();
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   982
			}
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   983
		} 
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   984
		mView->setContextForActiveDay(index.row());
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   985
	}
51
hgs
parents: 45
diff changeset
   986
	
hgs
parents: 45
diff changeset
   987
	OstTraceFunctionExit0( DUP2_CALENMONTHGRID_ITEMACTIVATED_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   988
}
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
   989
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   990
/*!
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   991
 Sets the focus to proper day after the flick scrollng
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   992
 */
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   993
void CalenMonthGrid::setFocusToProperDay()
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   994
{
51
hgs
parents: 45
diff changeset
   995
    OstTraceFunctionEntry0( CALENMONTHGRID_SETFOCUSTOPROPERDAY_ENTRY );
hgs
parents: 45
diff changeset
   996
    
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   997
	// Calculate the new item to be focussed
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   998
	QDateTime oldFocussedDate = mView->getActiveDay();
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
   999
	QList<CalenMonthData> monthDataList = mView->monthDataList();
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1000
	int listCount = monthDataList.count();
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1001
	int rowsInPrevMonth = mView->rowsInPrevMonth();
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1002
	QDateTime dateToBeFocussed;
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1003
	int indexStart = 0;
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1004
	int indexEnd = listCount - 1;
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1005
	if (mDirection == up) {
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1006
		dateToBeFocussed = oldFocussedDate.addMonths(1); // add the month 
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1007
		indexStart = (rowsInPrevMonth + 4) * KCalenDaysInWeek;
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1008
	} else if (mDirection == down) {
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1009
		dateToBeFocussed = oldFocussedDate.addMonths(-1); // substract the month
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1010
		indexEnd = (rowsInPrevMonth + 1) * KCalenDaysInWeek;
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1011
	}
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1012
	// Reset the focus attribute to earlier current item
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1013
	QModelIndex index = mModel->index(mCurrentRow,0);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1014
	QVariant itemData = index.data(Qt::UserRole + 1);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1015
	QVariantList list = itemData.toList();
45
hgs
parents: 23
diff changeset
  1016
	list.replace(CalendarNamespace::CalendarMonthFocusRole, false);
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1017
	mModel->itemFromIndex(index)->setData(list);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1018
	
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1019
	// Search for this date in the model
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1020
	for (int i = indexStart; i <= indexEnd; i++) {
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1021
		if (monthDataList[i].Day().date() == dateToBeFocussed.date()) {
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1022
			index = mModel->index(i,0);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1023
			itemData = index.data(Qt::UserRole + 1);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1024
			list = itemData.toList();
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1025
			list.replace(CalendarNamespace::CalendarMonthFocusRole,
45
hgs
parents: 23
diff changeset
  1026
										 true);
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1027
			mModel->itemFromIndex(index)->setData(list);
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1028
			mCurrentRow = i;
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1029
			mView->setContextForActiveDay(i);
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1030
			break;
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1031
		}
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1032
	}
51
hgs
parents: 45
diff changeset
  1033
	
hgs
parents: 45
diff changeset
  1034
	OstTraceFunctionExit0( CALENMONTHGRID_SETFOCUSTOPROPERDAY_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1035
}
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1036
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1037
/*!
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1038
 Sets the appropriate text color depending upon the active dates
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1039
 */
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1040
void CalenMonthGrid::setActiveDates(QDate activeDate)
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1041
{
51
hgs
parents: 45
diff changeset
  1042
    OstTraceFunctionEntry0( CALENMONTHGRID_SETACTIVEDATES_ENTRY );
hgs
parents: 45
diff changeset
  1043
    
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1044
	// By default, text color will be set as inactive date color
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1045
	// set active date color only for the dates that fall in current month
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1046
	// So, in the whole data array, start from where the current month starts
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1047
	// and stop the loop where it the current month ends
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1048
	
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1049
	int start = 0;
55
hgs
parents: 51
diff changeset
  1050
	QList<CalenMonthData >& monthDataList = mView->monthDataList();
hgs
parents: 51
diff changeset
  1051
	int end = monthDataList.count();
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1052
	
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1053
	// Calculate the start and end values
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1054
	QDate firstDateInGrid = mView->firstDayOfGrid().date();
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1055
	
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1056
	// Get the date where active month starts
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1057
	QDate startOfActiveMonth(activeDate.year(), activeDate.month(),1);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1058
	// Number of days frm start of the grid to start of the month
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1059
	start = firstDateInGrid.daysTo(startOfActiveMonth);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1060
	
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1061
	// Get the date where active month ends
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1062
	QDate endOfActiveMonth = startOfActiveMonth.addDays(
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1063
													activeDate.daysInMonth());
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1064
	// Number of days frm start of the grid to end of the month
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1065
	end = firstDateInGrid.daysTo(endOfActiveMonth);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1066
	
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1067
	// Set the active text color
63
hgs
parents: 57
diff changeset
  1068
	if (start >= 0 && end < monthDataList.count()) {
hgs
parents: 57
diff changeset
  1069
        for (int i = start; i < end; i++) {	
hgs
parents: 57
diff changeset
  1070
            QModelIndex index = mModel->index(i,0);
hgs
parents: 57
diff changeset
  1071
            QVariant itemData = index.data(Qt::UserRole + 1);
hgs
parents: 57
diff changeset
  1072
            QVariantList list = itemData.toList();
hgs
parents: 57
diff changeset
  1073
            list.replace(CalendarNamespace::CalendarMonthTextColorRole, true);
hgs
parents: 57
diff changeset
  1074
            mModel->itemFromIndex(index)->setData(list);
hgs
parents: 57
diff changeset
  1075
        }
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1076
	}
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1077
	
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1078
	// Now set the inactive text color to those which were active before the swipe
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1079
	if (mDirection == invalid) {
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1080
		// no need to do anything as other dates will be in inactive dates color
51
hgs
parents: 45
diff changeset
  1081
		OstTraceFunctionExit0( CALENMONTHGRID_SETACTIVEDATES_EXIT );
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1082
		return;
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1083
	}
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1084
	
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1085
	if (mDirection == up) {
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1086
		// Came here as user did up gesture
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1087
		// Get the activeDate that was set before the swipe
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1088
		activeDate = activeDate.addMonths(-1);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1089
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1090
		// Get the date where active month starts
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1091
		startOfActiveMonth = QDate(activeDate.year(), activeDate.month(),1);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1092
		// Number of days frm start of the grid to start of the month
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1093
		start = firstDateInGrid.daysTo(startOfActiveMonth);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1094
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1095
		// Get the date where active month ends
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1096
		QDate endOfActiveMonth = startOfActiveMonth.addDays(activeDate.daysInMonth());
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1097
		// Number of days frm start of the grid to end of the month
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1098
		end = firstDateInGrid.daysTo(endOfActiveMonth);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1099
	} else if (mDirection == down) {
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1100
		// Came here as user did down gesture
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1101
		// Get the activeDate that was set before the swipe
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1102
		activeDate = activeDate.addMonths(1);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1103
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1104
		// Get the activeDate that was set before the swipe
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1105
		startOfActiveMonth = QDate(activeDate.year(), activeDate.month(),1); 
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1106
		// Number of days frm start of the grid to start of the month
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1107
		start = firstDateInGrid.daysTo(startOfActiveMonth);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1108
		
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1109
		// Get the date where active month ends
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1110
		QDate endOfActiveMonth = startOfActiveMonth.addDays(activeDate.daysInMonth());
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1111
		// Number of days frm start of the grid to end of the month
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1112
		end = firstDateInGrid.daysTo(endOfActiveMonth);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1113
	}
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1114
	
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1115
	// Set the inactive text color
63
hgs
parents: 57
diff changeset
  1116
	if (start >= 0 && end < monthDataList.count()) {
hgs
parents: 57
diff changeset
  1117
        for (int i = start; i < end; i++) {		
hgs
parents: 57
diff changeset
  1118
            QModelIndex index = mModel->index(i,0);
hgs
parents: 57
diff changeset
  1119
            QVariant itemData = index.data(Qt::UserRole + 1);
hgs
parents: 57
diff changeset
  1120
            QVariantList list = itemData.toList();
hgs
parents: 57
diff changeset
  1121
            list.replace(CalendarNamespace::CalendarMonthTextColorRole, false);
hgs
parents: 57
diff changeset
  1122
            mModel->itemFromIndex(index)->setData(list);
hgs
parents: 57
diff changeset
  1123
        }
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1124
	}
51
hgs
parents: 45
diff changeset
  1125
	
hgs
parents: 45
diff changeset
  1126
	OstTraceFunctionExit0( DUP1_CALENMONTHGRID_SETACTIVEDATES_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1127
}
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1128
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1129
/*!
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1130
 To get current foucsed index of monthGrid
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1131
 */
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1132
int CalenMonthGrid::getCurrentIndex()
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1133
{
51
hgs
parents: 45
diff changeset
  1134
    OstTraceFunctionEntry0( CALENMONTHGRID_GETCURRENTINDEX_ENTRY );
hgs
parents: 45
diff changeset
  1135
    
hgs
parents: 45
diff changeset
  1136
	OstTraceFunctionExit0( CALENMONTHGRID_GETCURRENTINDEX_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1137
	return mCurrentRow;
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1138
}
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1139
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1140
/*!
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1141
 To set the focus to Index 
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1142
 */
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1143
void CalenMonthGrid::setCurrentIdex(int index)
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1144
{
51
hgs
parents: 45
diff changeset
  1145
    OstTraceFunctionEntry0( CALENMONTHGRID_SETCURRENTIDEX_ENTRY );
hgs
parents: 45
diff changeset
  1146
    
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1147
	itemActivated(mModel->index(index, 0));
51
hgs
parents: 45
diff changeset
  1148
	
hgs
parents: 45
diff changeset
  1149
	OstTraceFunctionExit0( CALENMONTHGRID_SETCURRENTIDEX_EXIT );
18
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1150
}
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1151
c198609911f9 Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 0
diff changeset
  1152
/*!
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1153
 Paint function to draw grid lines
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1154
 */
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1155
void CalenMonthGrid::paint(QPainter* painter,
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1156
                          const QStyleOptionGraphicsItem* option,
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1157
                          QWidget* widget)
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1158
{
51
hgs
parents: 45
diff changeset
  1159
    OstTraceFunctionEntry0( CALENMONTHGRID_PAINT_ENTRY );
hgs
parents: 45
diff changeset
  1160
    
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1161
	Q_UNUSED(option);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1162
	Q_UNUSED(widget);
45
hgs
parents: 23
diff changeset
  1163
	painter->setRenderHint(QPainter::NonCosmeticDefaultPen);
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1164
	
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1165
	// Set the required attributes to the pen
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1166
	QPen pen;
45
hgs
parents: 23
diff changeset
  1167
	HbDeviceProfile deviceProf;
hgs
parents: 23
diff changeset
  1168
	qreal unitValue = deviceProf.unitValue();
hgs
parents: 23
diff changeset
  1169
	qreal widthInPixels = GRIDLINE_WIDTH * unitValue;
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1170
	pen.setStyle(Qt::SolidLine);
45
hgs
parents: 23
diff changeset
  1171
	pen.setWidth(widthInPixels);
63
hgs
parents: 57
diff changeset
  1172
	pen.setBrush(mGridLineColor);
hgs
parents: 57
diff changeset
  1173
	
51
hgs
parents: 45
diff changeset
  1174
	// Store the old pen
hgs
parents: 45
diff changeset
  1175
	QPen oldPen = painter->pen();
hgs
parents: 45
diff changeset
  1176
	
45
hgs
parents: 23
diff changeset
  1177
	// Set the new pen to the painter
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1178
	painter->setPen(pen);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1179
	
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1180
	// Get the sizes of content widget
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1181
	qreal contentHeight = mContentWidget->size().height();
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1182
	qreal contentWidth = mContentWidget->size().width();
45
hgs
parents: 23
diff changeset
  1183
	qreal rowWidth = 0.0;
hgs
parents: 23
diff changeset
  1184
	int numOfRows = 0;
hgs
parents: 23
diff changeset
  1185
	QPointF startPoint = mContentWidget->pos();
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1186
	
45
hgs
parents: 23
diff changeset
  1187
	// NOTE!!!: There is a filcker when we blindly draw equally spaced lines
hgs
parents: 23
diff changeset
  1188
	// on complete content widget when scrolling is finished. This happens only
hgs
parents: 23
diff changeset
  1189
	// when content widget size is changed due to the change in total number
hgs
parents: 23
diff changeset
  1190
	// of rows when we append or prepend rows. Hence, to avoid this, we draw
hgs
parents: 23
diff changeset
  1191
	// lines on complete content widget only when it is scrolling.
hgs
parents: 23
diff changeset
  1192
	// That means, as soon as scrolling is finished, we will end up drawing 
hgs
parents: 23
diff changeset
  1193
	// only 6 lines that are visible to the user.
hgs
parents: 23
diff changeset
  1194
	if (mDirection == invalid) {
hgs
parents: 23
diff changeset
  1195
		// Start point is left most point on the screen
hgs
parents: 23
diff changeset
  1196
		startPoint = QPointF(0,0);
hgs
parents: 23
diff changeset
  1197
		rowWidth = size().height() / KNumOfVisibleRows;
hgs
parents: 23
diff changeset
  1198
		numOfRows = KNumOfVisibleRows;
hgs
parents: 23
diff changeset
  1199
	} else {
hgs
parents: 23
diff changeset
  1200
		// Get the num of rows
hgs
parents: 23
diff changeset
  1201
		numOfRows = mModel->rowCount() / KCalenDaysInWeek;
hgs
parents: 23
diff changeset
  1202
		// Draw horizontal lines
hgs
parents: 23
diff changeset
  1203
		rowWidth = contentHeight / numOfRows;
hgs
parents: 23
diff changeset
  1204
	}
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1205
	
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1206
	QPointF endPoint(startPoint.x() + contentWidth, 
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1207
	                 startPoint.y());
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1208
	
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1209
	// Create the list of points for which lines have to be drawn
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1210
	// List should have even number of points so that it draws all the lines
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1211
	// Painter draws the line for first two points in the list and then second 
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1212
	// line for next two points in the list like that. Hence, list should 
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1213
	// contain even number of points
57
hgs
parents: 55
diff changeset
  1214
	// Dont draw the first horizontal line as we have thick line seperator
hgs
parents: 55
diff changeset
  1215
	// coming between day names and the month grid
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1216
	QVector<QPointF> pointList;
57
hgs
parents: 55
diff changeset
  1217
	for (int i = 1; i < numOfRows; i++) {
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1218
		pointList.append(QPointF(startPoint.x(), 
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1219
		                         startPoint.y() + (i * rowWidth)));
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1220
		pointList.append(QPointF(endPoint.x(), endPoint.y() + (i * rowWidth)));
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1221
	}
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1222
	
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1223
	// Draw vertical lines
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1224
	qreal colWidth = contentWidth / KCalenDaysInWeek;
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1225
	endPoint = QPointF(startPoint.x(), 
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1226
	                   startPoint.y() + contentHeight);
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1227
	for (int i = 1; i < KCalenDaysInWeek; i++) {
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1228
		pointList.append(QPointF(startPoint.x() + (i * colWidth), 
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1229
		                         startPoint.y()));
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1230
		pointList.append(QPointF(endPoint.x() + (i * colWidth), endPoint.y()));
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1231
	}
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1232
	
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1233
	// Draw the lines for the points in the vector list
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1234
	painter->drawLines(pointList);
51
hgs
parents: 45
diff changeset
  1235
	
45
hgs
parents: 23
diff changeset
  1236
	// Set the old pen back
hgs
parents: 23
diff changeset
  1237
	painter->setPen(oldPen);
51
hgs
parents: 45
diff changeset
  1238
	
hgs
parents: 45
diff changeset
  1239
	OstTraceFunctionExit0( CALENMONTHGRID_PAINT_EXIT );
23
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1240
}
fd30d51f876b Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents: 18
diff changeset
  1241
63
hgs
parents: 57
diff changeset
  1242
/*!
75
hgs
parents: 70
diff changeset
  1243
 Function to check if scrolling is allowed. This function will make an effect
hgs
parents: 70
diff changeset
  1244
 only when you are going to month that is not supported by us.
hgs
parents: 70
diff changeset
  1245
 */
hgs
parents: 70
diff changeset
  1246
bool CalenMonthGrid::checkIfWeCanScroll(scrollDirection direction)
hgs
parents: 70
diff changeset
  1247
{
hgs
parents: 70
diff changeset
  1248
    OstTraceFunctionEntry0( CALENMONTHGRID_CHECKIFWECANSCROLL_ENTRY );
hgs
parents: 70
diff changeset
  1249
    
hgs
parents: 70
diff changeset
  1250
    bool value = true;
hgs
parents: 70
diff changeset
  1251
    
hgs
parents: 70
diff changeset
  1252
    // Get the current active Date
hgs
parents: 70
diff changeset
  1253
    QDateTime activeDate = mView->getActiveDay();
hgs
parents: 70
diff changeset
  1254
    // if direction is up, then check if the next month is
hgs
parents: 70
diff changeset
  1255
    // not January, 2101
hgs
parents: 70
diff changeset
  1256
    if (direction == up) {
hgs
parents: 70
diff changeset
  1257
        QDateTime nextMonth = activeDate.addMonths(1);
hgs
parents: 70
diff changeset
  1258
        value = CalenDateUtils::isValidDay(nextMonth);
hgs
parents: 70
diff changeset
  1259
    } else if (direction == down) { // if direction is up, then check if the next month is
hgs
parents: 70
diff changeset
  1260
        // not December, 1899
hgs
parents: 70
diff changeset
  1261
        QDateTime prevMonth = activeDate.addMonths(-1);
hgs
parents: 70
diff changeset
  1262
        value = CalenDateUtils::isValidDay(prevMonth);
hgs
parents: 70
diff changeset
  1263
    }
hgs
parents: 70
diff changeset
  1264
    
hgs
parents: 70
diff changeset
  1265
    OstTraceFunctionExit0( CALENMONTHGRID_CHECKIFWECANSCROLL_EXIT );
hgs
parents: 70
diff changeset
  1266
    
hgs
parents: 70
diff changeset
  1267
    return value;
hgs
parents: 70
diff changeset
  1268
}
hgs
parents: 70
diff changeset
  1269
hgs
parents: 70
diff changeset
  1270
/*!
63
hgs
parents: 57
diff changeset
  1271
 Slot to handle the change in theme
hgs
parents: 57
diff changeset
  1272
 */
hgs
parents: 57
diff changeset
  1273
void CalenMonthGrid::handleThemeChange()
hgs
parents: 57
diff changeset
  1274
{
hgs
parents: 57
diff changeset
  1275
    OstTraceFunctionEntry0(CALENMONTHGRID_HANDLETHEMECHANGE_ENTRY);
hgs
parents: 57
diff changeset
  1276
    
hgs
parents: 57
diff changeset
  1277
    mGridLineColor = HbColorScheme::color("qtc_cal_grid_line");
hgs
parents: 57
diff changeset
  1278
    
hgs
parents: 57
diff changeset
  1279
    OstTraceFunctionExit0(CALENMONTHGRID_HANDLETHEMECHANGE_EXIT);
hgs
parents: 57
diff changeset
  1280
}
hgs
parents: 57
diff changeset
  1281
0
f979ecb2b13e Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff changeset
  1282
// End of File