calendarui/views/dayview/src/calendayutils.cpp
author hgs
Wed, 25 Aug 2010 14:02:13 +0530
changeset 63 a3cb48f6c889
parent 57 bb2d3e476f29
child 64 1881ad52dc45
permissions -rw-r--r--
201033
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:  CalenDayUtils utility class implementation.
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
// System includes
63
hgs
parents: 57
diff changeset
    19
#include <QDateTime>
hgs
parents: 57
diff changeset
    20
#include <HbDeviceProfile>
hgs
parents: 57
diff changeset
    21
#include <HbStyle>
hgs
parents: 57
diff changeset
    22
#include <HbInstance>
45
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
// User includes
hgs
parents:
diff changeset
    25
#include "calendayutils.h"
hgs
parents:
diff changeset
    26
#include "calendaycommonheaders.h"
hgs
parents:
diff changeset
    27
#include "agendaentry.h"
hgs
parents:
diff changeset
    28
#include "calendateutils.h"
hgs
parents:
diff changeset
    29
hgs
parents:
diff changeset
    30
// Initialization of static member
hgs
parents:
diff changeset
    31
CalenDayUtils* CalenDayUtils::mInstance = 0;
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
/*!
hgs
parents:
diff changeset
    34
 \class CalenDayUtils
hgs
parents:
diff changeset
    35
 \brief Singleton utility class.
hgs
parents:
diff changeset
    36
 
hgs
parents:
diff changeset
    37
 Class cannot be used in console applications.
hgs
parents:
diff changeset
    38
 
hgs
parents:
diff changeset
    39
 Provided functionalities (getters):
hgs
parents:
diff changeset
    40
 - screen width of device
hgs
parents:
diff changeset
    41
 - default width of hour element
hgs
parents:
diff changeset
    42
 - default height of hour element
hgs
parents:
diff changeset
    43
 - default width of content area
hgs
parents:
diff changeset
    44
 - current orientation of screen
hgs
parents:
diff changeset
    45
 - pointer to the main window of application
hgs
parents:
diff changeset
    46
 */
hgs
parents:
diff changeset
    47
hgs
parents:
diff changeset
    48
/*!
hgs
parents:
diff changeset
    49
 \brief Returns the instance of CalenDayUtils class
hgs
parents:
diff changeset
    50
 */
hgs
parents:
diff changeset
    51
CalenDayUtils *CalenDayUtils::instance()
hgs
parents:
diff changeset
    52
{
hgs
parents:
diff changeset
    53
    if (!mInstance) {
hgs
parents:
diff changeset
    54
        mInstance = new CalenDayUtils();
hgs
parents:
diff changeset
    55
    }
hgs
parents:
diff changeset
    56
    return mInstance;
hgs
parents:
diff changeset
    57
}
hgs
parents:
diff changeset
    58
hgs
parents:
diff changeset
    59
/*!
hgs
parents:
diff changeset
    60
 \brief Destructor
hgs
parents:
diff changeset
    61
 */
hgs
parents:
diff changeset
    62
CalenDayUtils::~CalenDayUtils()
hgs
parents:
diff changeset
    63
{
hgs
parents:
diff changeset
    64
    
hgs
parents:
diff changeset
    65
}
hgs
parents:
diff changeset
    66
hgs
parents:
diff changeset
    67
/*!
hgs
parents:
diff changeset
    68
 \brief screenWidth
hgs
parents:
diff changeset
    69
 
hgs
parents:
diff changeset
    70
 \return Width of main window's screen
hgs
parents:
diff changeset
    71
 */
hgs
parents:
diff changeset
    72
qreal CalenDayUtils::screenWidth() const
hgs
parents:
diff changeset
    73
{
hgs
parents:
diff changeset
    74
    ASSERT(mMainWindow);
hgs
parents:
diff changeset
    75
    
hgs
parents:
diff changeset
    76
    return mMainWindow->layoutRect().width();
hgs
parents:
diff changeset
    77
}
hgs
parents:
diff changeset
    78
hgs
parents:
diff changeset
    79
/*!
hgs
parents:
diff changeset
    80
 \brief hourElementWidth
hgs
parents:
diff changeset
    81
 
hgs
parents:
diff changeset
    82
 \return Width of hour element
hgs
parents:
diff changeset
    83
 */
hgs
parents:
diff changeset
    84
qreal CalenDayUtils::hourElementWidth() const
hgs
parents:
diff changeset
    85
{
hgs
parents:
diff changeset
    86
    return mHourElementWidth;
hgs
parents:
diff changeset
    87
}
hgs
parents:
diff changeset
    88
hgs
parents:
diff changeset
    89
/*!
hgs
parents:
diff changeset
    90
 \brief hourElementHeight
hgs
parents:
diff changeset
    91
 
hgs
parents:
diff changeset
    92
 \return Height of hour element
hgs
parents:
diff changeset
    93
 */
hgs
parents:
diff changeset
    94
qreal CalenDayUtils::hourElementHeight() const
hgs
parents:
diff changeset
    95
{
hgs
parents:
diff changeset
    96
    return mHourElementHeight;
hgs
parents:
diff changeset
    97
}
hgs
parents:
diff changeset
    98
hgs
parents:
diff changeset
    99
/*!
hgs
parents:
diff changeset
   100
 \brief contentWidth
hgs
parents:
diff changeset
   101
 
hgs
parents:
diff changeset
   102
 \return Width of content area
hgs
parents:
diff changeset
   103
 */
hgs
parents:
diff changeset
   104
qreal CalenDayUtils::contentWidth() const
hgs
parents:
diff changeset
   105
{
hgs
parents:
diff changeset
   106
    return (screenWidth() - mHourElementWidth);
hgs
parents:
diff changeset
   107
}
hgs
parents:
diff changeset
   108
hgs
parents:
diff changeset
   109
/*!
hgs
parents:
diff changeset
   110
 \brief orientation
hgs
parents:
diff changeset
   111
 
hgs
parents:
diff changeset
   112
 \return Orientation of main window
hgs
parents:
diff changeset
   113
 */
hgs
parents:
diff changeset
   114
Qt::Orientation CalenDayUtils::orientation() const
hgs
parents:
diff changeset
   115
{
hgs
parents:
diff changeset
   116
    ASSERT(mMainWindow);
hgs
parents:
diff changeset
   117
        
hgs
parents:
diff changeset
   118
    return mMainWindow->orientation();
hgs
parents:
diff changeset
   119
}
hgs
parents:
diff changeset
   120
hgs
parents:
diff changeset
   121
/*!
hgs
parents:
diff changeset
   122
 \brief mainWindow
hgs
parents:
diff changeset
   123
 
hgs
parents:
diff changeset
   124
 \return Pointer to main window of application
hgs
parents:
diff changeset
   125
 */
hgs
parents:
diff changeset
   126
HbMainWindow* CalenDayUtils::mainWindow()
hgs
parents:
diff changeset
   127
{
hgs
parents:
diff changeset
   128
    ASSERT(mMainWindow);
hgs
parents:
diff changeset
   129
    
hgs
parents:
diff changeset
   130
    return mMainWindow;
hgs
parents:
diff changeset
   131
}
hgs
parents:
diff changeset
   132
hgs
parents:
diff changeset
   133
/*!
hgs
parents:
diff changeset
   134
 \brief getEventValidStartEndTime
hgs
parents:
diff changeset
   135
 \brief Get event's valid start/end time from agenda entry.
hgs
parents:
diff changeset
   136
 */
hgs
parents:
diff changeset
   137
void CalenDayUtils::getEventValidStartEndTime( QDateTime& start, QDateTime& end, 
55
hgs
parents: 45
diff changeset
   138
                                    const AgendaEntry& entry, QDateTime& currentDate )
45
hgs
parents:
diff changeset
   139
{
hgs
parents:
diff changeset
   140
    start = entry.startTime();
hgs
parents:
diff changeset
   141
    end = entry.endTime();
hgs
parents:
diff changeset
   142
    
hgs
parents:
diff changeset
   143
    if ( !CalenDateUtils::onSameDay( start, currentDate ) ) {
hgs
parents:
diff changeset
   144
        start = CalenDateUtils::beginningOfDay( currentDate );
hgs
parents:
diff changeset
   145
    }
hgs
parents:
diff changeset
   146
    
hgs
parents:
diff changeset
   147
    if ( !CalenDateUtils::onSameDay( end, currentDate ) ) {
hgs
parents:
diff changeset
   148
       QDateTime tommorrow( currentDate.addDays( 1 ));
hgs
parents:
diff changeset
   149
       end = CalenDateUtils::beginningOfDay( tommorrow ).addSecs( -60 );
hgs
parents:
diff changeset
   150
    }
hgs
parents:
diff changeset
   151
}
hgs
parents:
diff changeset
   152
hgs
parents:
diff changeset
   153
/*!
hgs
parents:
diff changeset
   154
 \brief Constructor
hgs
parents:
diff changeset
   155
 */
hgs
parents:
diff changeset
   156
CalenDayUtils::CalenDayUtils() : mMainWindow(NULL)
hgs
parents:
diff changeset
   157
{
hgs
parents:
diff changeset
   158
    if (HbInstance::instance()->allMainWindows().count() > 0) {
hgs
parents:
diff changeset
   159
        mMainWindow = HbInstance::instance()->allMainWindows().first();
hgs
parents:
diff changeset
   160
    }
hgs
parents:
diff changeset
   161
    mHourElementWidth = calculateHourElementWidth();
hgs
parents:
diff changeset
   162
    mHourElementHeight = calculateHourElementHeight();
hgs
parents:
diff changeset
   163
}
hgs
parents:
diff changeset
   164
hgs
parents:
diff changeset
   165
/*!
hgs
parents:
diff changeset
   166
 \brief Calculates the width of hour element according to UI spec.
hgs
parents:
diff changeset
   167
 
hgs
parents:
diff changeset
   168
 \return Calculated width of hour element
hgs
parents:
diff changeset
   169
 */
hgs
parents:
diff changeset
   170
qreal CalenDayUtils::calculateHourElementWidth() const
hgs
parents:
diff changeset
   171
{
hgs
parents:
diff changeset
   172
    HbStyle style;
hgs
parents:
diff changeset
   173
    HbDeviceProfile deviceProfile;
hgs
parents:
diff changeset
   174
    qreal unitInPixels = deviceProfile.unitValue();
hgs
parents:
diff changeset
   175
hgs
parents:
diff changeset
   176
    // Calculate element's preferred width
hgs
parents:
diff changeset
   177
    qreal prefWidth = 0.0;
hgs
parents:
diff changeset
   178
    qreal textWidth = 0.0;
hgs
parents:
diff changeset
   179
    qreal horizontalSpacing = 0.0;
hgs
parents:
diff changeset
   180
    
hgs
parents:
diff changeset
   181
    textWidth = 8.04 * unitInPixels; // pix (according to UI spec)   
hgs
parents:
diff changeset
   182
    style.parameter(QString("hb-param-margin-gene-middle-horizontal"), 
hgs
parents:
diff changeset
   183
        horizontalSpacing, deviceProfile);
hgs
parents:
diff changeset
   184
    prefWidth = horizontalSpacing * 2 + textWidth;
hgs
parents:
diff changeset
   185
    
hgs
parents:
diff changeset
   186
    return prefWidth;
hgs
parents:
diff changeset
   187
}
hgs
parents:
diff changeset
   188
hgs
parents:
diff changeset
   189
/*!
hgs
parents:
diff changeset
   190
 \brief Calculates the height of hour element according to UI spec.
hgs
parents:
diff changeset
   191
 
hgs
parents:
diff changeset
   192
 \return Calculated height of hour element
hgs
parents:
diff changeset
   193
 */
hgs
parents:
diff changeset
   194
qreal CalenDayUtils::calculateHourElementHeight() const
hgs
parents:
diff changeset
   195
{
hgs
parents:
diff changeset
   196
    HbStyle style;
hgs
parents:
diff changeset
   197
    HbDeviceProfile deviceProfile;
hgs
parents:
diff changeset
   198
    
hgs
parents:
diff changeset
   199
    qreal unitInPixels = deviceProfile.unitValue();
hgs
parents:
diff changeset
   200
    
hgs
parents:
diff changeset
   201
    // Calculate element's preferred height
hgs
parents:
diff changeset
   202
    qreal prefHeight = 0.0;
hgs
parents:
diff changeset
   203
    qreal textHeight = 0.0;
hgs
parents:
diff changeset
   204
    qreal verticalSpacing = 0.0;
hgs
parents:
diff changeset
   205
        
hgs
parents:
diff changeset
   206
    qreal bottomSpacer = 3.0 * unitInPixels;
hgs
parents:
diff changeset
   207
    style.parameter(QString("hb-param-text-height-secondary"), textHeight, 
hgs
parents:
diff changeset
   208
        deviceProfile);
hgs
parents:
diff changeset
   209
    style.parameter(QString("hb-param-margin-gene-middle-vertical"), 
hgs
parents:
diff changeset
   210
        verticalSpacing, deviceProfile);
hgs
parents:
diff changeset
   211
hgs
parents:
diff changeset
   212
    prefHeight = textHeight * 2; //time + ampm
hgs
parents:
diff changeset
   213
    prefHeight += verticalSpacing * 2;
hgs
parents:
diff changeset
   214
    prefHeight += bottomSpacer;
hgs
parents:
diff changeset
   215
    
hgs
parents:
diff changeset
   216
    return prefHeight;
hgs
parents:
diff changeset
   217
}