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