calendarui/views/dayview/src/calendayutils.cpp
author hgs
Tue, 05 Oct 2010 13:57:00 +0530
changeset 81 ce92091cbd61
parent 70 a5ed90760192
child 83 5aadd1120515
permissions -rw-r--r--
201039
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:  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
/*!
70
hgs
parents: 64
diff changeset
   100
 \brief minEventHeight
hgs
parents: 64
diff changeset
   101
 
hgs
parents: 64
diff changeset
   102
 \return Minimum height of event bubble
hgs
parents: 64
diff changeset
   103
 */
hgs
parents: 64
diff changeset
   104
qreal CalenDayUtils::minEventHeight() const
hgs
parents: 64
diff changeset
   105
{
hgs
parents: 64
diff changeset
   106
    return mMinEventHeight;
hgs
parents: 64
diff changeset
   107
}
hgs
parents: 64
diff changeset
   108
hgs
parents: 64
diff changeset
   109
/*!
45
hgs
parents:
diff changeset
   110
 \brief contentWidth
hgs
parents:
diff changeset
   111
 
hgs
parents:
diff changeset
   112
 \return Width of content area
hgs
parents:
diff changeset
   113
 */
hgs
parents:
diff changeset
   114
qreal CalenDayUtils::contentWidth() const
hgs
parents:
diff changeset
   115
{
hgs
parents:
diff changeset
   116
    return (screenWidth() - mHourElementWidth);
hgs
parents:
diff changeset
   117
}
hgs
parents:
diff changeset
   118
hgs
parents:
diff changeset
   119
/*!
hgs
parents:
diff changeset
   120
 \brief orientation
hgs
parents:
diff changeset
   121
 
hgs
parents:
diff changeset
   122
 \return Orientation of main window
hgs
parents:
diff changeset
   123
 */
hgs
parents:
diff changeset
   124
Qt::Orientation CalenDayUtils::orientation() const
hgs
parents:
diff changeset
   125
{
hgs
parents:
diff changeset
   126
    ASSERT(mMainWindow);
hgs
parents:
diff changeset
   127
        
hgs
parents:
diff changeset
   128
    return mMainWindow->orientation();
hgs
parents:
diff changeset
   129
}
hgs
parents:
diff changeset
   130
hgs
parents:
diff changeset
   131
/*!
hgs
parents:
diff changeset
   132
 \brief mainWindow
hgs
parents:
diff changeset
   133
 
hgs
parents:
diff changeset
   134
 \return Pointer to main window of application
hgs
parents:
diff changeset
   135
 */
hgs
parents:
diff changeset
   136
HbMainWindow* CalenDayUtils::mainWindow()
hgs
parents:
diff changeset
   137
{
hgs
parents:
diff changeset
   138
    ASSERT(mMainWindow);
hgs
parents:
diff changeset
   139
    
hgs
parents:
diff changeset
   140
    return mMainWindow;
hgs
parents:
diff changeset
   141
}
hgs
parents:
diff changeset
   142
81
hgs
parents: 70
diff changeset
   143
/*
hgs
parents: 70
diff changeset
   144
 * Get event's start/end time fromm agenda entry.
hgs
parents: 70
diff changeset
   145
 * Start/end time are validated to be within the current day (the case of
hgs
parents: 70
diff changeset
   146
 * multi-day events)
hgs
parents: 70
diff changeset
   147
 * @param start [out] valid start time
hgs
parents: 70
diff changeset
   148
 * @param end [out] valid end time
hgs
parents: 70
diff changeset
   149
 * @param entry [in] agenda entry asociated with the event.
hgs
parents: 70
diff changeset
   150
 * @param currentDate [in] current date
45
hgs
parents:
diff changeset
   151
 */
81
hgs
parents: 70
diff changeset
   152
void CalenDayUtils::getEventValidStartEndTime(
hgs
parents: 70
diff changeset
   153
    QDateTime& start,
hgs
parents: 70
diff changeset
   154
    QDateTime& end,
hgs
parents: 70
diff changeset
   155
    const AgendaEntry& entry,
hgs
parents: 70
diff changeset
   156
    QDateTime& currentDate)
45
hgs
parents:
diff changeset
   157
{
hgs
parents:
diff changeset
   158
    start = entry.startTime();
hgs
parents:
diff changeset
   159
    end = entry.endTime();
81
hgs
parents: 70
diff changeset
   160
hgs
parents: 70
diff changeset
   161
    if (!CalenDateUtils::onSameDay(start, currentDate)) {
hgs
parents: 70
diff changeset
   162
        start = CalenDateUtils::beginningOfDay(currentDate);
45
hgs
parents:
diff changeset
   163
    }
81
hgs
parents: 70
diff changeset
   164
hgs
parents: 70
diff changeset
   165
    if (!CalenDateUtils::onSameDay(end, currentDate)) {
hgs
parents: 70
diff changeset
   166
        QDateTime tommorrow(currentDate.addDays(1));
hgs
parents: 70
diff changeset
   167
        end = CalenDateUtils::beginningOfDay(tommorrow).addSecs(-60);
45
hgs
parents:
diff changeset
   168
    }
hgs
parents:
diff changeset
   169
}
hgs
parents:
diff changeset
   170
hgs
parents:
diff changeset
   171
/*!
hgs
parents:
diff changeset
   172
 \brief Constructor
hgs
parents:
diff changeset
   173
 */
hgs
parents:
diff changeset
   174
CalenDayUtils::CalenDayUtils() : mMainWindow(NULL)
hgs
parents:
diff changeset
   175
{
hgs
parents:
diff changeset
   176
    if (HbInstance::instance()->allMainWindows().count() > 0) {
hgs
parents:
diff changeset
   177
        mMainWindow = HbInstance::instance()->allMainWindows().first();
hgs
parents:
diff changeset
   178
    }
hgs
parents:
diff changeset
   179
    mHourElementWidth = calculateHourElementWidth();
hgs
parents:
diff changeset
   180
    mHourElementHeight = calculateHourElementHeight();
70
hgs
parents: 64
diff changeset
   181
    mMinEventHeight = calculateMinEventHeight();
45
hgs
parents:
diff changeset
   182
}
hgs
parents:
diff changeset
   183
hgs
parents:
diff changeset
   184
/*!
hgs
parents:
diff changeset
   185
 \brief Calculates the width of hour element according to UI spec.
hgs
parents:
diff changeset
   186
 
hgs
parents:
diff changeset
   187
 \return Calculated width of hour element
hgs
parents:
diff changeset
   188
 */
hgs
parents:
diff changeset
   189
qreal CalenDayUtils::calculateHourElementWidth() const
hgs
parents:
diff changeset
   190
{
hgs
parents:
diff changeset
   191
    HbStyle style;
hgs
parents:
diff changeset
   192
    HbDeviceProfile deviceProfile;
hgs
parents:
diff changeset
   193
    qreal unitInPixels = deviceProfile.unitValue();
hgs
parents:
diff changeset
   194
hgs
parents:
diff changeset
   195
    // Calculate element's preferred width
hgs
parents:
diff changeset
   196
    qreal prefWidth = 0.0;
hgs
parents:
diff changeset
   197
    qreal textWidth = 0.0;
hgs
parents:
diff changeset
   198
    qreal horizontalSpacing = 0.0;
hgs
parents:
diff changeset
   199
    
hgs
parents:
diff changeset
   200
    textWidth = 8.04 * unitInPixels; // pix (according to UI spec)   
hgs
parents:
diff changeset
   201
    style.parameter(QString("hb-param-margin-gene-middle-horizontal"), 
hgs
parents:
diff changeset
   202
        horizontalSpacing, deviceProfile);
hgs
parents:
diff changeset
   203
    prefWidth = horizontalSpacing * 2 + textWidth;
hgs
parents:
diff changeset
   204
    
hgs
parents:
diff changeset
   205
    return prefWidth;
hgs
parents:
diff changeset
   206
}
hgs
parents:
diff changeset
   207
hgs
parents:
diff changeset
   208
/*!
hgs
parents:
diff changeset
   209
 \brief Calculates the height of hour element according to UI spec.
hgs
parents:
diff changeset
   210
 
hgs
parents:
diff changeset
   211
 \return Calculated height of hour element
hgs
parents:
diff changeset
   212
 */
hgs
parents:
diff changeset
   213
qreal CalenDayUtils::calculateHourElementHeight() const
hgs
parents:
diff changeset
   214
{
hgs
parents:
diff changeset
   215
    HbStyle style;
hgs
parents:
diff changeset
   216
    HbDeviceProfile deviceProfile;
hgs
parents:
diff changeset
   217
    
hgs
parents:
diff changeset
   218
    qreal unitInPixels = deviceProfile.unitValue();
hgs
parents:
diff changeset
   219
    
hgs
parents:
diff changeset
   220
    // Calculate element's preferred height
hgs
parents:
diff changeset
   221
    qreal prefHeight = 0.0;
hgs
parents:
diff changeset
   222
    qreal textHeight = 0.0;
hgs
parents:
diff changeset
   223
    qreal verticalSpacing = 0.0;
hgs
parents:
diff changeset
   224
        
64
1881ad52dc45 201033_03
hgs
parents: 63
diff changeset
   225
    qreal bottomSpacer = 4.1 * unitInPixels;
45
hgs
parents:
diff changeset
   226
    style.parameter(QString("hb-param-text-height-secondary"), textHeight, 
hgs
parents:
diff changeset
   227
        deviceProfile);
hgs
parents:
diff changeset
   228
    style.parameter(QString("hb-param-margin-gene-middle-vertical"), 
hgs
parents:
diff changeset
   229
        verticalSpacing, deviceProfile);
hgs
parents:
diff changeset
   230
hgs
parents:
diff changeset
   231
    prefHeight = textHeight * 2; //time + ampm
hgs
parents:
diff changeset
   232
    prefHeight += verticalSpacing * 2;
hgs
parents:
diff changeset
   233
    prefHeight += bottomSpacer;
hgs
parents:
diff changeset
   234
    
hgs
parents:
diff changeset
   235
    return prefHeight;
hgs
parents:
diff changeset
   236
}
70
hgs
parents: 64
diff changeset
   237
hgs
parents: 64
diff changeset
   238
/*!
hgs
parents: 64
diff changeset
   239
 \brief Calculates the height of hour element according to UI spec.
hgs
parents: 64
diff changeset
   240
 
hgs
parents: 64
diff changeset
   241
 \return Calculated minimum height of event bubble
hgs
parents: 64
diff changeset
   242
 */
hgs
parents: 64
diff changeset
   243
qreal CalenDayUtils::calculateMinEventHeight() const
hgs
parents: 64
diff changeset
   244
{
hgs
parents: 64
diff changeset
   245
    HbStyle style;
hgs
parents: 64
diff changeset
   246
    HbDeviceProfile deviceProfile;
hgs
parents: 64
diff changeset
   247
hgs
parents: 64
diff changeset
   248
    // Calculate minimum height of event bubble
hgs
parents: 64
diff changeset
   249
    qreal textHeight = 0.0;
hgs
parents: 64
diff changeset
   250
    qreal topSpacing = 0.0;
hgs
parents: 64
diff changeset
   251
    qreal bottomSpacing = 0.0;
hgs
parents: 64
diff changeset
   252
    style.parameter(QString("hb-param-text-height-secondary"), textHeight,
hgs
parents: 64
diff changeset
   253
        deviceProfile);
hgs
parents: 64
diff changeset
   254
    style.parameter(QString("hb-param-margin-gene-top"), topSpacing, 
hgs
parents: 64
diff changeset
   255
        deviceProfile);
hgs
parents: 64
diff changeset
   256
    style.parameter(QString("hb-param-margin-gene-bottom"), bottomSpacing, 
hgs
parents: 64
diff changeset
   257
        deviceProfile);
hgs
parents: 64
diff changeset
   258
    
hgs
parents: 64
diff changeset
   259
    return (topSpacing + textHeight + bottomSpacing);
hgs
parents: 64
diff changeset
   260
}