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