calendarui/views/dayview/src/calendayview.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: CalenDayView class definition.
hgs
parents:
diff changeset
    15
 *
hgs
parents:
diff changeset
    16
 */
hgs
parents:
diff changeset
    17
55
hgs
parents: 45
diff changeset
    18
// System includes
45
hgs
parents:
diff changeset
    19
#include <QDateTime>
hgs
parents:
diff changeset
    20
#include <QGraphicsLinearLayout>
hgs
parents:
diff changeset
    21
#include <xqsettingsmanager.h>
55
hgs
parents: 45
diff changeset
    22
#include <HbWidget>
63
hgs
parents: 57
diff changeset
    23
#include <HbFrameItem>
hgs
parents: 57
diff changeset
    24
#include <HbInstance>
hgs
parents: 57
diff changeset
    25
#include <HbAction>
hgs
parents: 57
diff changeset
    26
#include <HbMenu>
hgs
parents: 57
diff changeset
    27
#include <HbMainWindow>
hgs
parents: 57
diff changeset
    28
#include <HbModelIterator>
hgs
parents: 57
diff changeset
    29
#include <HbStyleLoader>
hgs
parents: 57
diff changeset
    30
#include <HbGroupBox>
hgs
parents: 57
diff changeset
    31
#include <HbExtendedLocale>
45
hgs
parents:
diff changeset
    32
#include <agendautil.h>
55
hgs
parents: 45
diff changeset
    33
hgs
parents: 45
diff changeset
    34
// User includes
45
hgs
parents:
diff changeset
    35
#include "calendayview.h"
55
hgs
parents: 45
diff changeset
    36
#include "calencommon.h"
45
hgs
parents:
diff changeset
    37
#include "calencontext.h"
hgs
parents:
diff changeset
    38
#include "calenservices.h"
hgs
parents:
diff changeset
    39
#include "calendocloader.h"
hgs
parents:
diff changeset
    40
#include "calendateutils.h" //useful date/time utils
hgs
parents:
diff changeset
    41
#include "calendaycontentscrollarea.h"
hgs
parents:
diff changeset
    42
#include "calendaycontentwidget.h"
hgs
parents:
diff changeset
    43
#include "calendayhourscrollarea.h"
hgs
parents:
diff changeset
    44
#include "calendaymodelmanager.h"
hgs
parents:
diff changeset
    45
#include "CalenUid.h"
hgs
parents:
diff changeset
    46
#include "CalendarPrivateCRKeys.h"
hgs
parents:
diff changeset
    47
#include "calenpluginlabel.h"
hgs
parents:
diff changeset
    48
#include "calendaymodel.h"
63
hgs
parents: 57
diff changeset
    49
#include "calendayutils.h"
45
hgs
parents:
diff changeset
    50
hgs
parents:
diff changeset
    51
//constants
hgs
parents:
diff changeset
    52
57
hgs
parents: 55
diff changeset
    53
hgs
parents: 55
diff changeset
    54
/*!
hgs
parents: 55
diff changeset
    55
 \brief Constructor
hgs
parents: 55
diff changeset
    56
*/
45
hgs
parents:
diff changeset
    57
CalenDayView::CalenDayView(MCalenServices &services) :
hgs
parents:
diff changeset
    58
    CalenNativeView(services), mContentScrollArea(NULL), mContentWidget(NULL),
63
hgs
parents: 57
diff changeset
    59
        mHourScrollArea(NULL), mVLayout(NULL), mMainContainer(NULL),
hgs
parents: 57
diff changeset
    60
        mDocLoader(NULL), mIsLaunching(true), mSettingsManager(NULL),
hgs
parents: 57
diff changeset
    61
        mRegionalInfoKey(XQSettingsKey::TargetCentralRepository,
hgs
parents: 57
diff changeset
    62
            KCRUidCalendar, KCalendarShowRegionalInfo), mServices(services),
hgs
parents: 57
diff changeset
    63
        mRegionalInfoGroupBox(NULL), mGoToTodayMenuAction(NULL), mBg(NULL)
45
hgs
parents:
diff changeset
    64
{
hgs
parents:
diff changeset
    65
    setupMenu();
55
hgs
parents: 45
diff changeset
    66
45
hgs
parents:
diff changeset
    67
    // Create model manager
55
hgs
parents: 45
diff changeset
    68
    mModelManager = new CalenDayModelManager(mServices, true, this);
45
hgs
parents:
diff changeset
    69
    mSettingsManager = new XQSettingsManager(this);
63
hgs
parents: 57
diff changeset
    70
    mSettingsManager->startMonitoring(mRegionalInfoKey);
45
hgs
parents:
diff changeset
    71
hgs
parents:
diff changeset
    72
    //setup Back functionality
hgs
parents:
diff changeset
    73
    if (ECalenDayView != mServices.getFirstView()) {
hgs
parents:
diff changeset
    74
        HbAction* action = new HbAction(Hb::BackNaviAction, this);
hgs
parents:
diff changeset
    75
        setNavigationAction(action);
hgs
parents:
diff changeset
    76
        // Connect to the signal triggered by clicking on back button.
hgs
parents:
diff changeset
    77
        connect(action, SIGNAL(triggered()), this, SLOT(onBack()));
hgs
parents:
diff changeset
    78
    }
hgs
parents:
diff changeset
    79
hgs
parents:
diff changeset
    80
    HbStyleLoader::registerFilePath(":/calendayhourelement.css");
hgs
parents:
diff changeset
    81
    HbStyleLoader::registerFilePath(":/calendayhourelement.widgetml");
hgs
parents:
diff changeset
    82
    HbStyleLoader::registerFilePath(":/calendayitem.css");
hgs
parents:
diff changeset
    83
    HbStyleLoader::registerFilePath(":/calendayitem.widgetml");
55
hgs
parents: 45
diff changeset
    84
    HbStyleLoader::registerFilePath(":/calendayeventspane.css");
57
hgs
parents: 55
diff changeset
    85
    HbStyleLoader::registerFilePath(":/calendayhourscrollarea.css");
45
hgs
parents:
diff changeset
    86
}
hgs
parents:
diff changeset
    87
57
hgs
parents: 55
diff changeset
    88
/*!
hgs
parents: 55
diff changeset
    89
 \brief Destructor
hgs
parents: 55
diff changeset
    90
*/
45
hgs
parents:
diff changeset
    91
CalenDayView::~CalenDayView()
hgs
parents:
diff changeset
    92
{
63
hgs
parents: 57
diff changeset
    93
    mSettingsManager->stopMonitoring(mRegionalInfoKey);
hgs
parents: 57
diff changeset
    94
    
hgs
parents: 57
diff changeset
    95
    if (mRegionalInfoGroupBox) {
hgs
parents: 57
diff changeset
    96
        delete mRegionalInfoGroupBox;
hgs
parents: 57
diff changeset
    97
        mRegionalInfoGroupBox = NULL;
hgs
parents: 57
diff changeset
    98
    }
hgs
parents: 57
diff changeset
    99
    
55
hgs
parents: 45
diff changeset
   100
    if (mDocLoader) {
hgs
parents: 45
diff changeset
   101
        delete mDocLoader;
hgs
parents: 45
diff changeset
   102
        mDocLoader = NULL;
hgs
parents: 45
diff changeset
   103
    }
45
hgs
parents:
diff changeset
   104
}
hgs
parents:
diff changeset
   105
57
hgs
parents: 55
diff changeset
   106
/*!
hgs
parents: 55
diff changeset
   107
 \brief Handles locale change.
hgs
parents: 55
diff changeset
   108
 
hgs
parents: 55
diff changeset
   109
 \param reason the reason of a change
hgs
parents: 55
diff changeset
   110
*/
45
hgs
parents:
diff changeset
   111
void CalenDayView::onLocaleChanged(int reason)
hgs
parents:
diff changeset
   112
{
hgs
parents:
diff changeset
   113
    Q_UNUSED( reason )
hgs
parents:
diff changeset
   114
}
hgs
parents:
diff changeset
   115
57
hgs
parents: 55
diff changeset
   116
/*!
hgs
parents: 55
diff changeset
   117
 \brief Reimplemented from CalenView. Handles view (re)population
hgs
parents: 55
diff changeset
   118
*/
45
hgs
parents:
diff changeset
   119
void CalenDayView::doPopulation()
hgs
parents:
diff changeset
   120
{
hgs
parents:
diff changeset
   121
    // Triggers fading effect for heading label
hgs
parents:
diff changeset
   122
    getCurrentDate();
hgs
parents:
diff changeset
   123
    HbEffect::start(mHeadingLabel, "fadeOut", this, "setHeadingText");
hgs
parents:
diff changeset
   124
    
hgs
parents:
diff changeset
   125
    mModelManager->refreshAllModels();
hgs
parents:
diff changeset
   126
    //Set date and time for hour scroll area. 
hgs
parents:
diff changeset
   127
    //It's later used by hour element to display timeline
hgs
parents:
diff changeset
   128
    mHourScrollArea->setDateTime(mDate);
hgs
parents:
diff changeset
   129
    
hgs
parents:
diff changeset
   130
    //set in menu go to today visible
hgs
parents:
diff changeset
   131
    QDateTime currentDateTime = QDateTime::currentDateTime();
hgs
parents:
diff changeset
   132
    if (mGoToTodayMenuAction and currentDateTime.date() == mDate.date()) {
hgs
parents:
diff changeset
   133
        mGoToTodayMenuAction->setVisible(false);
hgs
parents:
diff changeset
   134
    }
hgs
parents:
diff changeset
   135
    else if(mGoToTodayMenuAction) {
hgs
parents:
diff changeset
   136
        mGoToTodayMenuAction->setVisible(true);
hgs
parents:
diff changeset
   137
    }
hgs
parents:
diff changeset
   138
    
55
hgs
parents: 45
diff changeset
   139
    // Call async. if the view is loaded first time (fix to ou1cimx1#482516)
hgs
parents: 45
diff changeset
   140
    if (mIsLaunching) {
hgs
parents: 45
diff changeset
   141
        mIsLaunching = false;
hgs
parents: 45
diff changeset
   142
        QMetaObject::invokeMethod(this, "setupViewport", Qt::QueuedConnection);
hgs
parents: 45
diff changeset
   143
    } else {
hgs
parents: 45
diff changeset
   144
        setupViewport();
hgs
parents: 45
diff changeset
   145
    }
45
hgs
parents:
diff changeset
   146
	
hgs
parents:
diff changeset
   147
    populationComplete();
hgs
parents:
diff changeset
   148
}
hgs
parents:
diff changeset
   149
57
hgs
parents: 55
diff changeset
   150
/*!
hgs
parents: 55
diff changeset
   151
 \brief Reimplemented from CalenView. Informs the organizer that the view's population is complete.
hgs
parents: 55
diff changeset
   152
*/
45
hgs
parents:
diff changeset
   153
void CalenDayView::populationComplete()
hgs
parents:
diff changeset
   154
{
hgs
parents:
diff changeset
   155
    CalenNativeView::populationComplete();
hgs
parents:
diff changeset
   156
}
hgs
parents:
diff changeset
   157
57
hgs
parents: 55
diff changeset
   158
/*!
hgs
parents: 55
diff changeset
   159
 \brief Reimplemented from MCalenNotificationHandler. The function handles calendar notifications
hgs
parents: 55
diff changeset
   160
 
hgs
parents: 55
diff changeset
   161
 \param notification notification type
hgs
parents: 55
diff changeset
   162
*/
45
hgs
parents:
diff changeset
   163
void CalenDayView::HandleNotification(const TCalenNotification notification)
hgs
parents:
diff changeset
   164
{
hgs
parents:
diff changeset
   165
    Q_UNUSED( notification )
hgs
parents:
diff changeset
   166
}
hgs
parents:
diff changeset
   167
57
hgs
parents: 55
diff changeset
   168
hgs
parents: 55
diff changeset
   169
/*!
hgs
parents: 55
diff changeset
   170
 \brief Sets up the view accroding to the 'xml'
hgs
parents: 55
diff changeset
   171
 
hgs
parents: 55
diff changeset
   172
 \param docLoader Pointer to document loader
hgs
parents: 55
diff changeset
   173
*/
45
hgs
parents:
diff changeset
   174
void CalenDayView::setupView(CalenDocLoader* docLoader)
hgs
parents:
diff changeset
   175
{
55
hgs
parents: 45
diff changeset
   176
    // Store document loader for further use
hgs
parents: 45
diff changeset
   177
    mDocLoader = docLoader;
hgs
parents: 45
diff changeset
   178
hgs
parents: 45
diff changeset
   179
    // Get vertical layout from day view
hgs
parents: 45
diff changeset
   180
    mVLayout = static_cast<QGraphicsLinearLayout *> (this->layout());
hgs
parents: 45
diff changeset
   181
hgs
parents: 45
diff changeset
   182
    // Set up day info
hgs
parents: 45
diff changeset
   183
    mHeadingLabel = qobject_cast<HbGroupBox *> (mDocLoader->findWidget(
hgs
parents: 45
diff changeset
   184
        CALEN_DAYVIEW_DAYINFO));
hgs
parents: 45
diff changeset
   185
    HbEffect::add(mHeadingLabel, ":/fade_out.fxml", "fadeOut");
hgs
parents: 45
diff changeset
   186
    HbEffect::add(mHeadingLabel, ":/fade_in.fxml", "fadeIn");
63
hgs
parents: 57
diff changeset
   187
    
hgs
parents: 57
diff changeset
   188
    // Set up main container for hour elements/content area
hgs
parents: 57
diff changeset
   189
    mMainContainer = qobject_cast<HbWidget *> (mDocLoader->findWidget(
hgs
parents: 57
diff changeset
   190
        CALEN_DAYVIEW_CONTENTWIDGET));
hgs
parents: 57
diff changeset
   191
    if (Qt::Vertical == CalenDayUtils::instance()->orientation()) {
hgs
parents: 57
diff changeset
   192
        mBg = new HbFrameItem(KCalenBackgroundColorPortrait,
hgs
parents: 57
diff changeset
   193
            HbFrameDrawer::OnePiece, this);
hgs
parents: 57
diff changeset
   194
    }
hgs
parents: 57
diff changeset
   195
    else {
hgs
parents: 57
diff changeset
   196
        mBg = new HbFrameItem(KCalenBackgroundColorLandscape,
hgs
parents: 57
diff changeset
   197
            HbFrameDrawer::OnePiece, this);
hgs
parents: 57
diff changeset
   198
    }
hgs
parents: 57
diff changeset
   199
    mMainContainer->setBackgroundItem(mBg);
55
hgs
parents: 45
diff changeset
   200
hgs
parents: 45
diff changeset
   201
    // Set up hour scroll area
hgs
parents: 45
diff changeset
   202
    mHourScrollArea
hgs
parents: 45
diff changeset
   203
        = static_cast<CalenDayHourScrollArea *> (mDocLoader->findWidget(
hgs
parents: 45
diff changeset
   204
            CALEN_DAYVIEW_HOURSCROLLAREA));
hgs
parents: 45
diff changeset
   205
hgs
parents: 45
diff changeset
   206
    // Set up content scroll area
hgs
parents: 45
diff changeset
   207
    mContentScrollArea
hgs
parents: 45
diff changeset
   208
        = static_cast<CalenDayContentScrollArea *> (mDocLoader->findWidget(
hgs
parents: 45
diff changeset
   209
            CALEN_DAYVIEW_CONTENTSCROLLAREA));
63
hgs
parents: 57
diff changeset
   210
    // Pass parent object to mContentWidget to install event filters on parent
hgs
parents: 57
diff changeset
   211
    mContentWidget = new CalenDayContentWidget(*mModelManager, mContentScrollArea);
55
hgs
parents: 45
diff changeset
   212
    mContentScrollArea->setContentWidget(mContentWidget);
hgs
parents: 45
diff changeset
   213
63
hgs
parents: 57
diff changeset
   214
    setupSlots();
hgs
parents: 57
diff changeset
   215
    
55
hgs
parents: 45
diff changeset
   216
    // Set up regional info if variant is correct
hgs
parents: 45
diff changeset
   217
    showRegionalInformationFadeIn();
45
hgs
parents:
diff changeset
   218
}
hgs
parents:
diff changeset
   219
hgs
parents:
diff changeset
   220
//private slots
hgs
parents:
diff changeset
   221
57
hgs
parents: 55
diff changeset
   222
/*!
hgs
parents: 55
diff changeset
   223
 \brief Handles 'back' functionality
hgs
parents: 55
diff changeset
   224
*/
45
hgs
parents:
diff changeset
   225
void CalenDayView::onBack()
hgs
parents:
diff changeset
   226
{
hgs
parents:
diff changeset
   227
    TRAP_IGNORE(mServices.IssueCommandL(ECalenMonthView));
hgs
parents:
diff changeset
   228
}
hgs
parents:
diff changeset
   229
57
hgs
parents: 55
diff changeset
   230
/*!
hgs
parents: 55
diff changeset
   231
 \brief Slot that handles first phase of day change
hgs
parents: 55
diff changeset
   232
 
hgs
parents: 55
diff changeset
   233
 \param direction indicates to which day view needs to be scrolled (previous or next day)
hgs
parents: 55
diff changeset
   234
*/
45
hgs
parents:
diff changeset
   235
void CalenDayView::dayChangeStarted(CalenScrollDirection direction)
hgs
parents:
diff changeset
   236
{
hgs
parents:
diff changeset
   237
    if (direction == ECalenScrollToNext) {
hgs
parents:
diff changeset
   238
        mDate = mDate.addDays(1);	
hgs
parents:
diff changeset
   239
    }
hgs
parents:
diff changeset
   240
    else {
hgs
parents:
diff changeset
   241
        mDate = mDate.addDays(-1);
hgs
parents:
diff changeset
   242
    }
hgs
parents:
diff changeset
   243
    
hgs
parents:
diff changeset
   244
    //set in menu go to today visible
hgs
parents:
diff changeset
   245
    QDateTime currentDateTime = QDateTime::currentDateTime();
hgs
parents:
diff changeset
   246
    if (mGoToTodayMenuAction and currentDateTime.date() == mDate.date()) {
hgs
parents:
diff changeset
   247
        mGoToTodayMenuAction->setVisible(false);
hgs
parents:
diff changeset
   248
    }
hgs
parents:
diff changeset
   249
    else if(mGoToTodayMenuAction) {
hgs
parents:
diff changeset
   250
        mGoToTodayMenuAction->setVisible(true);
hgs
parents:
diff changeset
   251
    }
hgs
parents:
diff changeset
   252
    
hgs
parents:
diff changeset
   253
    // Triggers fading effect for heading label.
hgs
parents:
diff changeset
   254
    HbEffect::start(mHeadingLabel, "fadeOut", this, "setHeadingText");
63
hgs
parents: 57
diff changeset
   255
    if (mRegionalInfoGroupBox) {
hgs
parents: 57
diff changeset
   256
        HbEffect::start(mRegionalInfoGroupBox, "fadeOut", this,
hgs
parents: 57
diff changeset
   257
            "showRegionalInformation");
hgs
parents: 57
diff changeset
   258
    }
45
hgs
parents:
diff changeset
   259
    
hgs
parents:
diff changeset
   260
    mServices.Context().setFocusDate(mDate);
hgs
parents:
diff changeset
   261
}
hgs
parents:
diff changeset
   262
57
hgs
parents: 55
diff changeset
   263
/*!
hgs
parents: 55
diff changeset
   264
 \brief Slot that is triggered when operation of day change is completed
hgs
parents: 55
diff changeset
   265
 
hgs
parents: 55
diff changeset
   266
 \param direction ndicates to which day view was scrolled (previous or next day)
hgs
parents: 55
diff changeset
   267
*/
45
hgs
parents:
diff changeset
   268
void CalenDayView::dayChanged(CalenScrollDirection direction)
hgs
parents:
diff changeset
   269
{
hgs
parents:
diff changeset
   270
    mModelManager->viewsScrollingFinished(direction);
hgs
parents:
diff changeset
   271
	mHourScrollArea->setDateTime(mDate);
hgs
parents:
diff changeset
   272
}
hgs
parents:
diff changeset
   273
57
hgs
parents: 55
diff changeset
   274
/*!
hgs
parents: 55
diff changeset
   275
 \brief Gets current date from context
hgs
parents: 55
diff changeset
   276
*/
45
hgs
parents:
diff changeset
   277
void CalenDayView::getCurrentDate()
hgs
parents:
diff changeset
   278
{
hgs
parents:
diff changeset
   279
    mDate = CalenNativeView::mServices.Context().focusDateAndTime();
hgs
parents:
diff changeset
   280
}
hgs
parents:
diff changeset
   281
57
hgs
parents: 55
diff changeset
   282
/*!
hgs
parents: 55
diff changeset
   283
 \brief Sets the menu for day view
hgs
parents: 55
diff changeset
   284
*/
45
hgs
parents:
diff changeset
   285
void CalenDayView::setupMenu()
hgs
parents:
diff changeset
   286
{
hgs
parents:
diff changeset
   287
    menu()->addAction(hbTrId("txt_calendar_opt_new_event"), this, SLOT(runNewMeeting()));
hgs
parents:
diff changeset
   288
    //get pointer to this position, because need to change visibility
hgs
parents:
diff changeset
   289
    mGoToTodayMenuAction = menu()->addAction(hbTrId("txt_calendar_opt_go_to_today"), this, SLOT(runGoToToday()));
hgs
parents:
diff changeset
   290
    menu()->addAction(hbTrId("txt_calendar_opt_go_to_date"), this, SLOT(goToDate()));
hgs
parents:
diff changeset
   291
    //TODO: Add id for this text
hgs
parents:
diff changeset
   292
    //"Switch to Agenda view"
hgs
parents:
diff changeset
   293
    menu()->addAction(hbTrId("txt_calendar_opt_switch_to_agenda_view"), this, SLOT(runChangeToAgendaView()));
hgs
parents:
diff changeset
   294
    //TODO: Add id for this text (lunar data)
hgs
parents:
diff changeset
   295
    //"Show lunar data"
hgs
parents:
diff changeset
   296
    if (pluginEnabled())
hgs
parents:
diff changeset
   297
    	{
hgs
parents:
diff changeset
   298
		menu()->addAction(hbTrId("txt_calendar_opt_show_lunar_data"), this, SLOT(runLunarData()));
hgs
parents:
diff changeset
   299
    	}
hgs
parents:
diff changeset
   300
    menu()->addAction(hbTrId("txt_calendar_opt_settings"), this, SLOT(launchSettingsView()));
hgs
parents:
diff changeset
   301
}
hgs
parents:
diff changeset
   302
hgs
parents:
diff changeset
   303
/*!
57
hgs
parents: 55
diff changeset
   304
   \brief To change Day view to Agenda View
45
hgs
parents:
diff changeset
   305
 */
hgs
parents:
diff changeset
   306
void CalenDayView::runChangeToAgendaView()
hgs
parents:
diff changeset
   307
{
hgs
parents:
diff changeset
   308
    changeView(ECalenAgendaView);
hgs
parents:
diff changeset
   309
}
hgs
parents:
diff changeset
   310
hgs
parents:
diff changeset
   311
/*!
hgs
parents:
diff changeset
   312
   \brief Shows lunar data in popup box
hgs
parents:
diff changeset
   313
 */
hgs
parents:
diff changeset
   314
void CalenDayView::runLunarData()
hgs
parents:
diff changeset
   315
{
hgs
parents:
diff changeset
   316
	TRAP_IGNORE(mServices.IssueCommandL(ECalenRegionalPluginTapEvent));
hgs
parents:
diff changeset
   317
}
hgs
parents:
diff changeset
   318
57
hgs
parents: 55
diff changeset
   319
/*!
hgs
parents: 55
diff changeset
   320
   \brief This is a helper function to established connections between signals and slots
hgs
parents: 55
diff changeset
   321
*/
45
hgs
parents:
diff changeset
   322
void CalenDayView::setupSlots()
hgs
parents:
diff changeset
   323
{
hgs
parents:
diff changeset
   324
    // Connecting other view-related signals/slots
hgs
parents:
diff changeset
   325
    connect(mContentScrollArea,
hgs
parents:
diff changeset
   326
        SIGNAL(scrollAreaMoveStarted(CalenScrollDirection)), this,
hgs
parents:
diff changeset
   327
        SLOT(dayChangeStarted(CalenScrollDirection)));
hgs
parents:
diff changeset
   328
hgs
parents:
diff changeset
   329
    connect(mContentScrollArea,
hgs
parents:
diff changeset
   330
        SIGNAL(scrollAreaMoveFinished(CalenScrollDirection)), mContentWidget,
hgs
parents:
diff changeset
   331
        SLOT(relayoutWidgets(CalenScrollDirection)));
hgs
parents:
diff changeset
   332
hgs
parents:
diff changeset
   333
    connect(mContentWidget, SIGNAL(
hgs
parents:
diff changeset
   334
        widgetsRelayoutFinished(CalenScrollDirection)), mContentScrollArea,
hgs
parents:
diff changeset
   335
        SLOT(scrollToMiddleWidget()));
hgs
parents:
diff changeset
   336
hgs
parents:
diff changeset
   337
    connect(mContentWidget,
hgs
parents:
diff changeset
   338
        SIGNAL(widgetsRelayoutFinished(CalenScrollDirection)), this,
hgs
parents:
diff changeset
   339
        SLOT(dayChanged(CalenScrollDirection)));
hgs
parents:
diff changeset
   340
hgs
parents:
diff changeset
   341
    connect(mContentWidget, SIGNAL(scrollPositionChanged(const QPointF &)),
hgs
parents:
diff changeset
   342
        mHourScrollArea, SLOT(scrollVertically(const QPointF &)));
63
hgs
parents: 57
diff changeset
   343
45
hgs
parents:
diff changeset
   344
    connect(mHourScrollArea, SIGNAL(scrollPositionChanged(const QPointF &)),
hgs
parents:
diff changeset
   345
        mContentWidget, SLOT(widgetScrolled(const QPointF &)));
63
hgs
parents: 57
diff changeset
   346
hgs
parents: 57
diff changeset
   347
    connect(CalenDayUtils::instance()->mainWindow(),
hgs
parents: 57
diff changeset
   348
        SIGNAL(orientationChanged(Qt::Orientation)), this,
hgs
parents: 57
diff changeset
   349
        SLOT(orientationChanged(Qt::Orientation)));
hgs
parents: 57
diff changeset
   350
45
hgs
parents:
diff changeset
   351
    connect(mSettingsManager, SIGNAL(valueChanged(XQSettingsKey, QVariant)),
hgs
parents:
diff changeset
   352
        this, SLOT(showHideRegionalInformationChanged(XQSettingsKey, QVariant)));
hgs
parents:
diff changeset
   353
}
hgs
parents:
diff changeset
   354
57
hgs
parents: 55
diff changeset
   355
/*!
hgs
parents: 55
diff changeset
   356
   \brief This slot triggers new meeting creation view
hgs
parents: 55
diff changeset
   357
*/
45
hgs
parents:
diff changeset
   358
void CalenDayView::runNewMeeting()
hgs
parents:
diff changeset
   359
{
hgs
parents:
diff changeset
   360
    QDateTime dateTime(mDate);
hgs
parents:
diff changeset
   361
    TRAP_IGNORE(
hgs
parents:
diff changeset
   362
        dateTime.setTime(mServices.Context().defaultCalTimeForViewsL().time());
hgs
parents:
diff changeset
   363
        mServices.Context().setFocusDateAndTime(dateTime);
hgs
parents:
diff changeset
   364
        mServices.IssueCommandL(ECalenNewMeeting)
55
hgs
parents: 45
diff changeset
   365
    );
45
hgs
parents:
diff changeset
   366
}
hgs
parents:
diff changeset
   367
57
hgs
parents: 55
diff changeset
   368
/*!
hgs
parents: 55
diff changeset
   369
   \brief This slot switches current view to today
hgs
parents: 55
diff changeset
   370
*/
45
hgs
parents:
diff changeset
   371
void CalenDayView::runGoToToday()
hgs
parents:
diff changeset
   372
{
hgs
parents:
diff changeset
   373
    mServices.Context().setFocusDateAndTime(CalenDateUtils::today());
hgs
parents:
diff changeset
   374
    TRAP_IGNORE(mServices.IssueCommandL(ECalenGotoToday));
hgs
parents:
diff changeset
   375
    refreshViewOnGoToDate();
hgs
parents:
diff changeset
   376
}
hgs
parents:
diff changeset
   377
hgs
parents:
diff changeset
   378
57
hgs
parents: 55
diff changeset
   379
/*!
hgs
parents: 55
diff changeset
   380
   \brief This slot switches current view to the given by id
hgs
parents: 55
diff changeset
   381
   
hgs
parents: 55
diff changeset
   382
   \param viewId id of the view that needs to be displayed
hgs
parents: 55
diff changeset
   383
*/
45
hgs
parents:
diff changeset
   384
void CalenDayView::changeView(TCalenCommandId viewId)
hgs
parents:
diff changeset
   385
{
hgs
parents:
diff changeset
   386
    TRAP_IGNORE(mServices.IssueCommandL(viewId));
hgs
parents:
diff changeset
   387
}
hgs
parents:
diff changeset
   388
57
hgs
parents: 55
diff changeset
   389
/*!
hgs
parents: 55
diff changeset
   390
   \brief Sets heading text according to date from model and locale.
hgs
parents: 55
diff changeset
   391
          It's connected to modelReset signal.
hgs
parents: 55
diff changeset
   392
   
hgs
parents: 55
diff changeset
   393
   \param status Parameter required in order to call this slot autmatically
hgs
parents: 55
diff changeset
   394
                 when an effect is complete.
hgs
parents: 55
diff changeset
   395
*/
45
hgs
parents:
diff changeset
   396
void CalenDayView::setHeadingText(const HbEffect::EffectStatus &status)
hgs
parents:
diff changeset
   397
{   
hgs
parents:
diff changeset
   398
    Q_UNUSED(status)
hgs
parents:
diff changeset
   399
hgs
parents:
diff changeset
   400
    // Format the date as per the device locale settings
hgs
parents:
diff changeset
   401
    HbExtendedLocale systemLocale = HbExtendedLocale::system();
hgs
parents:
diff changeset
   402
hgs
parents:
diff changeset
   403
    // Get localised name of the day from locale
hgs
parents:
diff changeset
   404
    QString dayString = systemLocale.dayName(mDate.date().dayOfWeek());
hgs
parents:
diff changeset
   405
    // Append a single space
hgs
parents:
diff changeset
   406
    dayString.append(" ");
hgs
parents:
diff changeset
   407
    // Set the heading
hgs
parents:
diff changeset
   408
hgs
parents:
diff changeset
   409
    // Append the date which is formatted as per the locale   
hgs
parents:
diff changeset
   410
    mHeadingLabel->setHeading(hbTrId("txt_calendar_subhead_1_2").arg(dayString).arg(
hgs
parents:
diff changeset
   411
        systemLocale.format(mDate.date(), r_qtn_date_usual_with_zero)));
hgs
parents:
diff changeset
   412
hgs
parents:
diff changeset
   413
    HbEffect::start(mHeadingLabel, "fadeIn");
hgs
parents:
diff changeset
   414
}
hgs
parents:
diff changeset
   415
57
hgs
parents: 55
diff changeset
   416
/*!
hgs
parents: 55
diff changeset
   417
   \brief Displays regional information
hgs
parents: 55
diff changeset
   418
   
hgs
parents: 55
diff changeset
   419
   \param status Parameter required in order to call this slot autmatically
hgs
parents: 55
diff changeset
   420
                 when an effect is complete.
hgs
parents: 55
diff changeset
   421
*/
45
hgs
parents:
diff changeset
   422
void CalenDayView::showRegionalInformation(const HbEffect::EffectStatus &status)
hgs
parents:
diff changeset
   423
{
hgs
parents:
diff changeset
   424
	Q_UNUSED(status);
hgs
parents:
diff changeset
   425
	showRegionalInformationFadeIn();
hgs
parents:
diff changeset
   426
}
hgs
parents:
diff changeset
   427
57
hgs
parents: 55
diff changeset
   428
/*!
hgs
parents: 55
diff changeset
   429
   \brief Runs effect on lunar data label and change text according to date change.
hgs
parents: 55
diff changeset
   430
*/
45
hgs
parents:
diff changeset
   431
void CalenDayView::showRegionalInformationFadeIn()
57
hgs
parents: 55
diff changeset
   432
{
63
hgs
parents: 57
diff changeset
   433
	showHideRegionalInformationChanged(mRegionalInfoKey, 3);
hgs
parents: 57
diff changeset
   434
	if (mRegionalInfoGroupBox) {
hgs
parents: 57
diff changeset
   435
	    HbEffect::start(mRegionalInfoGroupBox, "fadeIn");
hgs
parents: 57
diff changeset
   436
	}
57
hgs
parents: 55
diff changeset
   437
}
45
hgs
parents:
diff changeset
   438
57
hgs
parents: 55
diff changeset
   439
/*!
hgs
parents: 55
diff changeset
   440
   \brief To Show and hide regional plugin label depends upon settings.
hgs
parents: 55
diff changeset
   441
*/
55
hgs
parents: 45
diff changeset
   442
void CalenDayView::showHideRegionalInformationChanged(
hgs
parents: 45
diff changeset
   443
    const XQSettingsKey& key,
hgs
parents: 45
diff changeset
   444
    const QVariant&)
hgs
parents: 45
diff changeset
   445
{
63
hgs
parents: 57
diff changeset
   446
    if ((key.key() == mRegionalInfoKey.key()) && pluginEnabled()) {
55
hgs
parents: 45
diff changeset
   447
        int showRegionalInfo =
63
hgs
parents: 57
diff changeset
   448
            mSettingsManager->readItemValue(mRegionalInfoKey).toUInt();
hgs
parents: 57
diff changeset
   449
        if (showRegionalInfo) {
hgs
parents: 57
diff changeset
   450
            if (!mRegionalInfoGroupBox) {
hgs
parents: 57
diff changeset
   451
                mRegionalInfoGroupBox = new HbGroupBox();
hgs
parents: 57
diff changeset
   452
                CalenPluginLabel *regionalInfo = new CalenPluginLabel(
hgs
parents: 57
diff changeset
   453
                    mServices, this);
hgs
parents: 57
diff changeset
   454
                regionalInfo->setFontSpec(HbFontSpec(HbFontSpec::Primary));
45
hgs
parents:
diff changeset
   455
63
hgs
parents: 57
diff changeset
   456
                // Set margins in groupbox according to UI spec
hgs
parents: 57
diff changeset
   457
                HbStyle style;
hgs
parents: 57
diff changeset
   458
                HbDeviceProfile deviceProfile;
hgs
parents: 57
diff changeset
   459
                qreal leftMargin = 0.0;
hgs
parents: 57
diff changeset
   460
                qreal rightMargin = 0.0;
hgs
parents: 57
diff changeset
   461
                qreal topMargin = 0.0;
hgs
parents: 57
diff changeset
   462
                qreal bottomMargin = 0.0;
hgs
parents: 57
diff changeset
   463
                style.parameter(QString("hb-param-margin-gene-left"),
hgs
parents: 57
diff changeset
   464
                    leftMargin, deviceProfile);
hgs
parents: 57
diff changeset
   465
                style.parameter(QString("hb-param-margin-gene-right"),
hgs
parents: 57
diff changeset
   466
                    rightMargin, deviceProfile);
hgs
parents: 57
diff changeset
   467
                style.parameter(QString("hb-param-margin-gene-top"), topMargin,
hgs
parents: 57
diff changeset
   468
                    deviceProfile);
hgs
parents: 57
diff changeset
   469
                style.parameter(QString("hb-param-margin-gene-bottom"),
hgs
parents: 57
diff changeset
   470
                    bottomMargin, deviceProfile);
hgs
parents: 57
diff changeset
   471
                regionalInfo->setContentsMargins(leftMargin, topMargin,
hgs
parents: 57
diff changeset
   472
                    rightMargin, bottomMargin);
hgs
parents: 57
diff changeset
   473
                mRegionalInfoGroupBox->setContentWidget(regionalInfo);
hgs
parents: 57
diff changeset
   474
hgs
parents: 57
diff changeset
   475
                mVLayout->insertItem(1, mRegionalInfoGroupBox);
hgs
parents: 57
diff changeset
   476
            }
55
hgs
parents: 45
diff changeset
   477
            QString *pluginString = pluginText();
63
hgs
parents: 57
diff changeset
   478
            HbLabel *pluginInfoLabel = qobject_cast<HbLabel *> (
hgs
parents: 57
diff changeset
   479
                mRegionalInfoGroupBox->contentWidget());
hgs
parents: 57
diff changeset
   480
            pluginInfoLabel->setPlainText(*pluginString);
55
hgs
parents: 45
diff changeset
   481
        }
hgs
parents: 45
diff changeset
   482
        else {
hgs
parents: 45
diff changeset
   483
            if (mRegionalInfoGroupBox) {
hgs
parents: 45
diff changeset
   484
                mVLayout->removeItem(mRegionalInfoGroupBox);
hgs
parents: 45
diff changeset
   485
                delete mRegionalInfoGroupBox;
hgs
parents: 45
diff changeset
   486
                mRegionalInfoGroupBox = NULL;
hgs
parents: 45
diff changeset
   487
            }
hgs
parents: 45
diff changeset
   488
        }
hgs
parents: 45
diff changeset
   489
    }
hgs
parents: 45
diff changeset
   490
}
45
hgs
parents:
diff changeset
   491
57
hgs
parents: 55
diff changeset
   492
/*!
hgs
parents: 55
diff changeset
   493
   \brief Scrolls view according to current day and events.
hgs
parents: 55
diff changeset
   494
*/
45
hgs
parents:
diff changeset
   495
void CalenDayView::setupViewport()
hgs
parents:
diff changeset
   496
{
hgs
parents:
diff changeset
   497
    QDateTime currentTime = QDateTime::currentDateTime();
55
hgs
parents: 45
diff changeset
   498
45
hgs
parents:
diff changeset
   499
    // If we have event in current day and hour, scroll to this event
55
hgs
parents: 45
diff changeset
   500
    if (mDate.date() == currentTime.date()){
hgs
parents: 45
diff changeset
   501
hgs
parents: 45
diff changeset
   502
        QDateTime midnight = currentTime;
hgs
parents: 45
diff changeset
   503
        midnight.setTime(QTime(23, 59));
hgs
parents: 45
diff changeset
   504
hgs
parents: 45
diff changeset
   505
        //Filter flags (only timed events)
hgs
parents: 45
diff changeset
   506
        AgendaUtil::FilterFlags filter = AgendaUtil::FilterFlags(AgendaUtil::IncludeAppointments);
hgs
parents: 45
diff changeset
   507
        QList<AgendaEntry> list;
hgs
parents: 45
diff changeset
   508
        // Fetch the instance list from the agenda interface
hgs
parents: 45
diff changeset
   509
        list = mServices.agendaInterface()->fetchEntriesInRange(currentTime, midnight, filter);
hgs
parents: 45
diff changeset
   510
hgs
parents: 45
diff changeset
   511
        if(!list.isEmpty()){
hgs
parents: 45
diff changeset
   512
            int hourToScrollTo(list.first().startTime().time().hour());
hgs
parents: 45
diff changeset
   513
            mHourScrollArea->scrollToHour(hourToScrollTo);           
hgs
parents: 45
diff changeset
   514
        }
hgs
parents: 45
diff changeset
   515
        else{
hgs
parents: 45
diff changeset
   516
            mHourScrollArea->scrollToHour(currentTime.time().hour());
hgs
parents: 45
diff changeset
   517
        }
45
hgs
parents:
diff changeset
   518
    }
55
hgs
parents: 45
diff changeset
   519
    else {
45
hgs
parents:
diff changeset
   520
        //Scroll view to 7am
hgs
parents:
diff changeset
   521
        mHourScrollArea->scrollToHour(7);
hgs
parents:
diff changeset
   522
    }
hgs
parents:
diff changeset
   523
}
hgs
parents:
diff changeset
   524
63
hgs
parents: 57
diff changeset
   525
/*!
hgs
parents: 57
diff changeset
   526
 \brief Slot which is called whenever the orientation of the device changes.
hgs
parents: 57
diff changeset
   527
 
hgs
parents: 57
diff changeset
   528
 Changes the backgroung graphic element when orientation chandes.
hgs
parents: 57
diff changeset
   529
 
hgs
parents: 57
diff changeset
   530
 \param orientation Current device orientation
hgs
parents: 57
diff changeset
   531
 */
hgs
parents: 57
diff changeset
   532
void CalenDayView::orientationChanged(Qt::Orientation orientation)
hgs
parents: 57
diff changeset
   533
{
hgs
parents: 57
diff changeset
   534
    if (Qt::Vertical == orientation) {
hgs
parents: 57
diff changeset
   535
        mBg = new HbFrameItem(KCalenBackgroundColorPortrait,
hgs
parents: 57
diff changeset
   536
            HbFrameDrawer::OnePiece, this);
hgs
parents: 57
diff changeset
   537
    }
hgs
parents: 57
diff changeset
   538
    else {
hgs
parents: 57
diff changeset
   539
        mBg = new HbFrameItem(KCalenBackgroundColorLandscape,
hgs
parents: 57
diff changeset
   540
            HbFrameDrawer::OnePiece, this);
hgs
parents: 57
diff changeset
   541
    }
hgs
parents: 57
diff changeset
   542
    mMainContainer->setBackgroundItem(mBg);
hgs
parents: 57
diff changeset
   543
}
hgs
parents: 57
diff changeset
   544
45
hgs
parents:
diff changeset
   545
//End of File