calendarui/views/dayview/src/calendayitemview.cpp
author hgs
Mon, 20 Sep 2010 12:44:39 +0530
changeset 75 7ac58b2aae6f
parent 70 a5ed90760192
child 81 ce92091cbd61
permissions -rw-r--r--
201037
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
45
hgs
parents:
diff changeset
     1
/*
70
hgs
parents: 63
diff changeset
     2
 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents: 63
diff changeset
     3
 * All rights reserved.
hgs
parents: 63
diff changeset
     4
 * This component and the accompanying materials are made available
hgs
parents: 63
diff changeset
     5
 * under the terms of "Eclipse Public License v1.0"
hgs
parents: 63
diff changeset
     6
 * which accompanies this distribution, and is available
hgs
parents: 63
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents: 63
diff changeset
     8
 *
hgs
parents: 63
diff changeset
     9
 * Initial Contributors:
hgs
parents: 63
diff changeset
    10
 * Nokia Corporation - initial contribution.
hgs
parents: 63
diff changeset
    11
 *
hgs
parents: 63
diff changeset
    12
 * Contributors:
hgs
parents: 63
diff changeset
    13
 *
hgs
parents: 63
diff changeset
    14
 * Description:  Day view control of calendar
hgs
parents: 63
diff changeset
    15
 *
hgs
parents: 63
diff changeset
    16
 */
45
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
//System includes
hgs
parents:
diff changeset
    19
#include <QGesture>
hgs
parents:
diff changeset
    20
#include <QGraphicsLinearLayout>
63
hgs
parents: 57
diff changeset
    21
#include <HbAbstractViewItem>
hgs
parents: 57
diff changeset
    22
#include <HbInstance>
hgs
parents: 57
diff changeset
    23
#include <HbAction>
45
hgs
parents:
diff changeset
    24
hgs
parents:
diff changeset
    25
//User includes
hgs
parents:
diff changeset
    26
#include "calendayitemview.h"
hgs
parents:
diff changeset
    27
#include "calendayutils.h"
hgs
parents:
diff changeset
    28
#include "calendaycontainer.h"
75
hgs
parents: 70
diff changeset
    29
#include "calendayitemview.h"
45
hgs
parents:
diff changeset
    30
#include "calendayinfo.h"
hgs
parents:
diff changeset
    31
#include "calendaymodel.h"
hgs
parents:
diff changeset
    32
#include "calenservices.h"
hgs
parents:
diff changeset
    33
#include "calencontext.h"
57
hgs
parents: 55
diff changeset
    34
#include "calenagendautils.h"
45
hgs
parents:
diff changeset
    35
#include "CalenUid.h"
hgs
parents:
diff changeset
    36
70
hgs
parents: 63
diff changeset
    37
/*!
hgs
parents: 63
diff changeset
    38
 \brief Constructor
hgs
parents: 63
diff changeset
    39
 */
hgs
parents: 63
diff changeset
    40
CalenDayItemView::CalenDayItemView(
hgs
parents: 63
diff changeset
    41
    MCalenServices &services,
hgs
parents: 63
diff changeset
    42
    HbModelIterator *iterator,
hgs
parents: 63
diff changeset
    43
    QGraphicsItem *parent) :
hgs
parents: 63
diff changeset
    44
    HbAbstractItemView(mContainer = new CalenDayContainer(), iterator, parent),
hgs
parents: 63
diff changeset
    45
        mServices(services)
hgs
parents: 63
diff changeset
    46
{
hgs
parents: 63
diff changeset
    47
    mInfo = new CalenDayInfo(CalenDayInfo::EFour);
hgs
parents: 63
diff changeset
    48
    mContainer->setDayInfo(mInfo);
45
hgs
parents:
diff changeset
    49
hgs
parents:
diff changeset
    50
    //setup Selection Model
hgs
parents:
diff changeset
    51
    QItemSelectionModel* selModel = new QItemSelectionModel(this->model());
70
hgs
parents: 63
diff changeset
    52
    if (selModel) {
hgs
parents: 63
diff changeset
    53
        setSelectionMode(HbAbstractItemView::SingleSelection);
hgs
parents: 63
diff changeset
    54
        setSelectionModel(selModel);
45
hgs
parents:
diff changeset
    55
    }
70
hgs
parents: 63
diff changeset
    56
45
hgs
parents:
diff changeset
    57
    setScrollDirections(Qt::Vertical);
hgs
parents:
diff changeset
    58
    setScrollingStyle(HbScrollArea::PanWithFollowOn);
hgs
parents:
diff changeset
    59
    setVerticalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
70
hgs
parents: 63
diff changeset
    60
45
hgs
parents:
diff changeset
    61
    //TODO: KG: Animate item pressed?! HbAbstractItemView::TouchDown
70
hgs
parents: 63
diff changeset
    62
    setEnabledAnimations(HbAbstractItemView::None);
hgs
parents: 63
diff changeset
    63
45
hgs
parents:
diff changeset
    64
    // Get the width of content and fix its size
hgs
parents:
diff changeset
    65
    qreal contentWidth = CalenDayUtils::instance()->contentWidth();
hgs
parents:
diff changeset
    66
    setMinimumWidth(contentWidth);
hgs
parents:
diff changeset
    67
    setMaximumWidth(contentWidth);
70
hgs
parents: 63
diff changeset
    68
45
hgs
parents:
diff changeset
    69
    setupSlots();
hgs
parents:
diff changeset
    70
    setupContextMenu();
hgs
parents:
diff changeset
    71
}
hgs
parents:
diff changeset
    72
57
hgs
parents: 55
diff changeset
    73
/*!
70
hgs
parents: 63
diff changeset
    74
 \brief Destructor
hgs
parents: 63
diff changeset
    75
 */
45
hgs
parents:
diff changeset
    76
CalenDayItemView::~CalenDayItemView()
hgs
parents:
diff changeset
    77
{
hgs
parents:
diff changeset
    78
    delete mInfo;
hgs
parents:
diff changeset
    79
}
hgs
parents:
diff changeset
    80
57
hgs
parents: 55
diff changeset
    81
/*!
70
hgs
parents: 63
diff changeset
    82
 \brief Scrolls to given index
hgs
parents: 63
diff changeset
    83
 */
hgs
parents: 63
diff changeset
    84
void CalenDayItemView::scrollTo(
hgs
parents: 63
diff changeset
    85
    const QModelIndex &index,
hgs
parents: 63
diff changeset
    86
    HbAbstractItemView::ScrollHint hint)
45
hgs
parents:
diff changeset
    87
{
hgs
parents:
diff changeset
    88
    HbAbstractItemView::scrollTo(index, hint);
hgs
parents:
diff changeset
    89
}
hgs
parents:
diff changeset
    90
57
hgs
parents: 55
diff changeset
    91
/*!
75
hgs
parents: 70
diff changeset
    92
 \brief Gets context menu of ItemView
hgs
parents: 70
diff changeset
    93
 
hgs
parents: 70
diff changeset
    94
 \return Context menu
hgs
parents: 70
diff changeset
    95
 */
hgs
parents: 70
diff changeset
    96
HbMenu *CalenDayItemView::contextMenu() const
hgs
parents: 70
diff changeset
    97
{
hgs
parents: 70
diff changeset
    98
    return mContextMenu;
hgs
parents: 70
diff changeset
    99
}
hgs
parents: 70
diff changeset
   100
hgs
parents: 70
diff changeset
   101
/*!
hgs
parents: 70
diff changeset
   102
 \brief Sets context menu of ItemView
hgs
parents: 70
diff changeset
   103
 
hgs
parents: 70
diff changeset
   104
 \param contextMenu Context menu
hgs
parents: 70
diff changeset
   105
 */
hgs
parents: 70
diff changeset
   106
void CalenDayItemView::setContextMenu(HbMenu *contextMenu)
hgs
parents: 70
diff changeset
   107
{
hgs
parents: 70
diff changeset
   108
    mContextMenu = contextMenu;
hgs
parents: 70
diff changeset
   109
}
hgs
parents: 70
diff changeset
   110
hgs
parents: 70
diff changeset
   111
/*!
70
hgs
parents: 63
diff changeset
   112
 \brief Currently empty implementation.
hgs
parents: 63
diff changeset
   113
 */
45
hgs
parents:
diff changeset
   114
void CalenDayItemView::reset()
hgs
parents:
diff changeset
   115
{
57
hgs
parents: 55
diff changeset
   116
45
hgs
parents:
diff changeset
   117
}
hgs
parents:
diff changeset
   118
57
hgs
parents: 55
diff changeset
   119
/*!
70
hgs
parents: 63
diff changeset
   120
 \brief Handles signal that is emitted when reset() is called, before the model's
hgs
parents: 63
diff changeset
   121
 internal state (e.g. persistent model indexes) has been invalidated.
hgs
parents: 63
diff changeset
   122
 */
45
hgs
parents:
diff changeset
   123
void CalenDayItemView::modelAboutToBeReset()
hgs
parents:
diff changeset
   124
{
70
hgs
parents: 63
diff changeset
   125
45
hgs
parents:
diff changeset
   126
}
hgs
parents:
diff changeset
   127
57
hgs
parents: 55
diff changeset
   128
/*!
70
hgs
parents: 63
diff changeset
   129
 \brief Handles signal that is emitted when reset() is called, before the model's
hgs
parents: 63
diff changeset
   130
 internal state (e.g. persistent model indexes) has been invalidated.
hgs
parents: 63
diff changeset
   131
 */
45
hgs
parents:
diff changeset
   132
void CalenDayItemView::modelReset()
hgs
parents:
diff changeset
   133
{
70
hgs
parents: 63
diff changeset
   134
    if (!mInfo) {
45
hgs
parents:
diff changeset
   135
        return;
hgs
parents:
diff changeset
   136
    }
hgs
parents:
diff changeset
   137
    //reset day info
hgs
parents:
diff changeset
   138
    mInfo->Reset();
55
hgs
parents: 45
diff changeset
   139
45
hgs
parents:
diff changeset
   140
    CalenDayModel* model(0);
70
hgs
parents: 63
diff changeset
   141
    model = static_cast<CalenDayModel*> (this->model());
hgs
parents: 63
diff changeset
   142
    if (!model) {
45
hgs
parents:
diff changeset
   143
        return;
hgs
parents:
diff changeset
   144
    }
70
hgs
parents: 63
diff changeset
   145
55
hgs
parents: 45
diff changeset
   146
    mContainer->setDate(model->modelDate().date());
70
hgs
parents: 63
diff changeset
   147
    int rowCount = model->rowCount();
hgs
parents: 63
diff changeset
   148
    SCalenApptInfo apptInfo;
hgs
parents: 63
diff changeset
   149
    for (int row = 0; row < rowCount; row++) {
hgs
parents: 63
diff changeset
   150
        QModelIndex idx = model->index(row, 0);
hgs
parents: 63
diff changeset
   151
        QVariant variant = idx.data(CalenDayEntry);
hgs
parents: 63
diff changeset
   152
        AgendaEntry entry = variant.value<AgendaEntry> ();
45
hgs
parents:
diff changeset
   153
        apptInfo.iIndex = idx;
70
hgs
parents: 63
diff changeset
   154
45
hgs
parents:
diff changeset
   155
        QDateTime start;
hgs
parents:
diff changeset
   156
        QDateTime end;
70
hgs
parents: 63
diff changeset
   157
        QDateTime currDate(model->modelDate());
hgs
parents: 63
diff changeset
   158
        CalenDayUtils::instance()->getEventValidStartEndTime(start, end, entry,
hgs
parents: 63
diff changeset
   159
            currDate);
45
hgs
parents:
diff changeset
   160
hgs
parents:
diff changeset
   161
        apptInfo.iStartTime = start;
hgs
parents:
diff changeset
   162
        apptInfo.iEndTime = end;
70
hgs
parents: 63
diff changeset
   163
45
hgs
parents:
diff changeset
   164
        TCalenInstanceId id = TCalenInstanceId::nullInstanceId();//index.row() - temporary ID
hgs
parents:
diff changeset
   165
        id.mEntryLocalUid = row;
70
hgs
parents: 63
diff changeset
   166
        id.mInstanceTime = apptInfo.iStartTime;
45
hgs
parents:
diff changeset
   167
        apptInfo.iId = id;
hgs
parents:
diff changeset
   168
        apptInfo.iColor = 0xffff;
70
hgs
parents: 63
diff changeset
   169
hgs
parents: 63
diff changeset
   170
        if (entry.isTimedEntry() && !CalenAgendaUtils::isAlldayEvent(entry)) {
45
hgs
parents:
diff changeset
   171
            apptInfo.iAllDay = false;
70
hgs
parents: 63
diff changeset
   172
            mInfo->InsertTimedEvent(apptInfo);
hgs
parents: 63
diff changeset
   173
        }
hgs
parents: 63
diff changeset
   174
        else
hgs
parents: 63
diff changeset
   175
            if (CalenAgendaUtils::isAlldayEvent(entry)) //all-day event
hgs
parents: 63
diff changeset
   176
            {
hgs
parents: 63
diff changeset
   177
                apptInfo.iAllDay = true;
hgs
parents: 63
diff changeset
   178
                mInfo->InsertAlldayEvent(apptInfo);
hgs
parents: 63
diff changeset
   179
            }
45
hgs
parents:
diff changeset
   180
    }
70
hgs
parents: 63
diff changeset
   181
45
hgs
parents:
diff changeset
   182
    HbAbstractItemView::reset();
hgs
parents:
diff changeset
   183
}
hgs
parents:
diff changeset
   184
57
hgs
parents: 55
diff changeset
   185
/*!
70
hgs
parents: 63
diff changeset
   186
 \brief Scrolls view vertically to the given position.
hgs
parents: 63
diff changeset
   187
 
hgs
parents: 63
diff changeset
   188
 \param newPosition position to scroll to.
hgs
parents: 63
diff changeset
   189
 */
hgs
parents: 63
diff changeset
   190
void CalenDayItemView::scrollVertically(const QPointF &newPosition)
45
hgs
parents:
diff changeset
   191
{
hgs
parents:
diff changeset
   192
    QPointF currentPos = contentWidget()->pos();
hgs
parents:
diff changeset
   193
    if (abs(newPosition.y()) != abs(currentPos.y())) {
hgs
parents:
diff changeset
   194
        currentPos.setY(newPosition.y());
hgs
parents:
diff changeset
   195
        scrollContentsTo(currentPos, 0);
hgs
parents:
diff changeset
   196
    }
hgs
parents:
diff changeset
   197
}
hgs
parents:
diff changeset
   198
57
hgs
parents: 55
diff changeset
   199
/*!
70
hgs
parents: 63
diff changeset
   200
 \brief This function is called when a touch press event is received 
hgs
parents: 63
diff changeset
   201
 within Abstract view item that is representing index.
hgs
parents: 63
diff changeset
   202
 Currently it does nothing.
hgs
parents: 63
diff changeset
   203
 */
hgs
parents: 63
diff changeset
   204
void CalenDayItemView::itemPressed(const QModelIndex &index)
45
hgs
parents:
diff changeset
   205
{
70
hgs
parents: 63
diff changeset
   206
    Q_UNUSED( index )
45
hgs
parents:
diff changeset
   207
}
hgs
parents:
diff changeset
   208
57
hgs
parents: 55
diff changeset
   209
/*!
70
hgs
parents: 63
diff changeset
   210
 \brief This function is called when a touch release event is received 
hgs
parents: 63
diff changeset
   211
 within Abstract view item that is representing index.
hgs
parents: 63
diff changeset
   212
 Currently it does nothing.
hgs
parents: 63
diff changeset
   213
 */
hgs
parents: 63
diff changeset
   214
void CalenDayItemView::itemReleased(const QModelIndex &index)
45
hgs
parents:
diff changeset
   215
{
70
hgs
parents: 63
diff changeset
   216
    Q_UNUSED( index )
45
hgs
parents:
diff changeset
   217
}
hgs
parents:
diff changeset
   218
57
hgs
parents: 55
diff changeset
   219
/*!
70
hgs
parents: 63
diff changeset
   220
 \brief This function is called when the item specified by index is activated by the user.
hgs
parents: 63
diff changeset
   221
 
hgs
parents: 63
diff changeset
   222
 \param position Not used.
hgs
parents: 63
diff changeset
   223
 */
hgs
parents: 63
diff changeset
   224
void CalenDayItemView::itemActivated(const QModelIndex &index)
45
hgs
parents:
diff changeset
   225
{
70
hgs
parents: 63
diff changeset
   226
    QItemSelectionModel* selModel(selectionModel());
hgs
parents: 63
diff changeset
   227
    if (index.isValid() && selModel) {
hgs
parents: 63
diff changeset
   228
        selModel->select(index, QItemSelectionModel::Current
hgs
parents: 63
diff changeset
   229
            | QItemSelectionModel::Select);
45
hgs
parents:
diff changeset
   230
        openSelectedItem();
hgs
parents:
diff changeset
   231
    }
hgs
parents:
diff changeset
   232
}
hgs
parents:
diff changeset
   233
57
hgs
parents: 55
diff changeset
   234
/*!
70
hgs
parents: 63
diff changeset
   235
 \brief This function is called when long press event is received within Abstract view item viewItem.
57
hgs
parents: 55
diff changeset
   236
70
hgs
parents: 63
diff changeset
   237
 \param item Pointer to pressed item.
hgs
parents: 63
diff changeset
   238
 \param coord Position where item was pressed.
hgs
parents: 63
diff changeset
   239
 */
45
hgs
parents:
diff changeset
   240
void CalenDayItemView::itemLongPressed(HbAbstractViewItem* item, QPointF coords)
hgs
parents:
diff changeset
   241
{
hgs
parents:
diff changeset
   242
    QModelIndex index = item->modelIndex();
70
hgs
parents: 63
diff changeset
   243
    QItemSelectionModel* selModel(selectionModel());
hgs
parents: 63
diff changeset
   244
    if (index.isValid() && selModel && mContextMenu) {
hgs
parents: 63
diff changeset
   245
        selModel->select(index, QItemSelectionModel::Current
hgs
parents: 63
diff changeset
   246
            | QItemSelectionModel::Select);
hgs
parents: 63
diff changeset
   247
        mContextMenu->setPreferredPos(coords, HbPopup::BottomRightCorner);
45
hgs
parents:
diff changeset
   248
        mContextMenu->open();
hgs
parents:
diff changeset
   249
    }
hgs
parents:
diff changeset
   250
}
hgs
parents:
diff changeset
   251
57
hgs
parents: 55
diff changeset
   252
/*!
70
hgs
parents: 63
diff changeset
   253
 \brief Slot which is called whenever the orientation of the device changes.
57
hgs
parents: 55
diff changeset
   254
70
hgs
parents: 63
diff changeset
   255
 \param orientation New orientation.
hgs
parents: 63
diff changeset
   256
 */
hgs
parents: 63
diff changeset
   257
void CalenDayItemView::orientationChanged(Qt::Orientation orientation)
45
hgs
parents:
diff changeset
   258
{
hgs
parents:
diff changeset
   259
    // Update the width of screen
hgs
parents:
diff changeset
   260
    qreal contentWidth = CalenDayUtils::instance()->contentWidth();
hgs
parents:
diff changeset
   261
    setMinimumWidth(contentWidth);
hgs
parents:
diff changeset
   262
    setMaximumWidth(contentWidth);
70
hgs
parents: 63
diff changeset
   263
    if (mContainer) {
hgs
parents: 63
diff changeset
   264
        mContainer->orientationChanged(orientation);
45
hgs
parents:
diff changeset
   265
    }
hgs
parents:
diff changeset
   266
}
hgs
parents:
diff changeset
   267
57
hgs
parents: 55
diff changeset
   268
/*!
70
hgs
parents: 63
diff changeset
   269
 \brief Opens currently selected model item.
hgs
parents: 63
diff changeset
   270
 */
45
hgs
parents:
diff changeset
   271
void CalenDayItemView::openSelectedItem()
hgs
parents:
diff changeset
   272
{
70
hgs
parents: 63
diff changeset
   273
    issueCommandOnSelectedItem(ECalenEventView);
45
hgs
parents:
diff changeset
   274
}
hgs
parents:
diff changeset
   275
57
hgs
parents: 55
diff changeset
   276
/*!
70
hgs
parents: 63
diff changeset
   277
 \brief Edits currently selected model item.
hgs
parents: 63
diff changeset
   278
 */
45
hgs
parents:
diff changeset
   279
void CalenDayItemView::editSelectedItem()
hgs
parents:
diff changeset
   280
{
70
hgs
parents: 63
diff changeset
   281
    issueCommandOnSelectedItem(ECalenEditCurrentEntry);
45
hgs
parents:
diff changeset
   282
}
hgs
parents:
diff changeset
   283
57
hgs
parents: 55
diff changeset
   284
/*!
70
hgs
parents: 63
diff changeset
   285
 \brief Deletes currently selected model item.
hgs
parents: 63
diff changeset
   286
 */
45
hgs
parents:
diff changeset
   287
void CalenDayItemView::deleteSelectedItem()
hgs
parents:
diff changeset
   288
{
70
hgs
parents: 63
diff changeset
   289
    issueCommandOnSelectedItem(ECalenDeleteCurrentEntry);
45
hgs
parents:
diff changeset
   290
}
hgs
parents:
diff changeset
   291
57
hgs
parents: 55
diff changeset
   292
/*!
70
hgs
parents: 63
diff changeset
   293
 \brief Connects item view's slots.
hgs
parents: 63
diff changeset
   294
 */
45
hgs
parents:
diff changeset
   295
void CalenDayItemView::setupSlots()
hgs
parents:
diff changeset
   296
{
hgs
parents:
diff changeset
   297
    // Connect to main window's orientationChanged signal to handle orientation
hgs
parents:
diff changeset
   298
    // switching
70
hgs
parents: 63
diff changeset
   299
    QObject::connect(CalenDayUtils::instance()->mainWindow(),
45
hgs
parents:
diff changeset
   300
        SIGNAL(orientationChanged(Qt::Orientation)), this,
hgs
parents:
diff changeset
   301
        SLOT(orientationChanged(Qt::Orientation)));
hgs
parents:
diff changeset
   302
hgs
parents:
diff changeset
   303
    // Connect with model signals
hgs
parents:
diff changeset
   304
    if (this->model()) {
hgs
parents:
diff changeset
   305
        QObject::connect(this->model(), SIGNAL(modelAboutToBeReset()), this,
hgs
parents:
diff changeset
   306
            SLOT(modelAboutToBeReset()));
hgs
parents:
diff changeset
   307
        QObject::connect(this->model(), SIGNAL(modelReset()), this,
hgs
parents:
diff changeset
   308
            SLOT(modelReset()));
hgs
parents:
diff changeset
   309
    }
hgs
parents:
diff changeset
   310
    if (mContainer) {
hgs
parents:
diff changeset
   311
        // Connect with base class to enable handling item press by model index
hgs
parents:
diff changeset
   312
        QObject::connect(mContainer, SIGNAL(itemCreated(HbAbstractViewItem *)),
hgs
parents:
diff changeset
   313
            this, SLOT(itemCreated(HbAbstractViewItem*)));
hgs
parents:
diff changeset
   314
    }
70
hgs
parents: 63
diff changeset
   315
    QObject::connect(this, SIGNAL(pressed(const QModelIndex&)), this,
hgs
parents: 63
diff changeset
   316
        SLOT(itemPressed(const QModelIndex&)));
hgs
parents: 63
diff changeset
   317
    QObject::connect(this, SIGNAL(released(const QModelIndex&)), this,
hgs
parents: 63
diff changeset
   318
        SLOT(itemReleased(const QModelIndex&)));
hgs
parents: 63
diff changeset
   319
    QObject::connect(this, SIGNAL(activated(const QModelIndex&)), this,
hgs
parents: 63
diff changeset
   320
        SLOT(itemActivated(const QModelIndex&)));
45
hgs
parents:
diff changeset
   321
    QObject::connect(this, SIGNAL(longPressed(HbAbstractViewItem*, QPointF)),
hgs
parents:
diff changeset
   322
        this, SLOT(itemLongPressed(HbAbstractViewItem*, QPointF)));
hgs
parents:
diff changeset
   323
}
hgs
parents:
diff changeset
   324
57
hgs
parents: 55
diff changeset
   325
/*!
70
hgs
parents: 63
diff changeset
   326
 \brief Creates context menu.
hgs
parents: 63
diff changeset
   327
 */
45
hgs
parents:
diff changeset
   328
void CalenDayItemView::setupContextMenu()
hgs
parents:
diff changeset
   329
{
hgs
parents:
diff changeset
   330
    mContextMenu = new HbMenu();
70
hgs
parents: 63
diff changeset
   331
    HbAction *openAction = mContextMenu->addAction(hbTrId(
hgs
parents: 63
diff changeset
   332
        "txt_common_menu_open"));
45
hgs
parents:
diff changeset
   333
    if (openAction) {
hgs
parents:
diff changeset
   334
        connect(openAction, SIGNAL(triggered()), this, SLOT(openSelectedItem()));
hgs
parents:
diff changeset
   335
    }
70
hgs
parents: 63
diff changeset
   336
    HbAction *editAction = mContextMenu->addAction(hbTrId(
hgs
parents: 63
diff changeset
   337
        "txt_common_menu_edit"));
45
hgs
parents:
diff changeset
   338
    if (editAction) {
hgs
parents:
diff changeset
   339
        connect(editAction, SIGNAL(triggered()), this, SLOT(editSelectedItem()));
hgs
parents:
diff changeset
   340
    }
70
hgs
parents: 63
diff changeset
   341
    HbAction *deleteAction = mContextMenu->addAction(hbTrId(
hgs
parents: 63
diff changeset
   342
        "txt_common_menu_delete"));
45
hgs
parents:
diff changeset
   343
    if (deleteAction) {
hgs
parents:
diff changeset
   344
        connect(deleteAction, SIGNAL(triggered()), this,
hgs
parents:
diff changeset
   345
            SLOT(deleteSelectedItem()));
hgs
parents:
diff changeset
   346
    }
hgs
parents:
diff changeset
   347
}
hgs
parents:
diff changeset
   348
57
hgs
parents: 55
diff changeset
   349
/*!
70
hgs
parents: 63
diff changeset
   350
 \brief Sets context to currently selected model item and issues calendar command.
hgs
parents: 63
diff changeset
   351
 
hgs
parents: 63
diff changeset
   352
 \param command A command to be issued.
hgs
parents: 63
diff changeset
   353
 */
hgs
parents: 63
diff changeset
   354
bool CalenDayItemView::issueCommandOnSelectedItem(int command)
45
hgs
parents:
diff changeset
   355
{
hgs
parents:
diff changeset
   356
    bool retVal(false);
hgs
parents:
diff changeset
   357
    QItemSelectionModel* selModel(selectionModel());
70
hgs
parents: 63
diff changeset
   358
    if (!selModel) {
45
hgs
parents:
diff changeset
   359
        return retVal;
hgs
parents:
diff changeset
   360
    }
70
hgs
parents: 63
diff changeset
   361
    QModelIndex index(selModel->currentIndex());
hgs
parents: 63
diff changeset
   362
    if (index.isValid()) {
45
hgs
parents:
diff changeset
   363
        retVal = true;
70
hgs
parents: 63
diff changeset
   364
        QVariant variant = index.data(CalenDayEntry);
hgs
parents: 63
diff changeset
   365
        AgendaEntry entry = variant.value<AgendaEntry> ();
45
hgs
parents:
diff changeset
   366
        QDateTime start;
hgs
parents:
diff changeset
   367
        QDateTime end;
hgs
parents:
diff changeset
   368
        CalenDayModel* model(0);
70
hgs
parents: 63
diff changeset
   369
        model = static_cast<CalenDayModel*> (this->model());
hgs
parents: 63
diff changeset
   370
        QDateTime currDate(model->modelDate());
hgs
parents: 63
diff changeset
   371
        CalenDayUtils::instance()->getEventValidStartEndTime(start, end, entry,
hgs
parents: 63
diff changeset
   372
            currDate);
45
hgs
parents:
diff changeset
   373
        TRAPD(error,
70
hgs
parents: 63
diff changeset
   374
            mServices.Context().setFocusDateAndTimeAndInstance(start,
hgs
parents: 63
diff changeset
   375
                TCalenInstanceId::create(entry));
hgs
parents: 63
diff changeset
   376
            mServices.IssueCommandL( command );
hgs
parents: 63
diff changeset
   377
        );
hgs
parents: 63
diff changeset
   378
        if (error) {
45
hgs
parents:
diff changeset
   379
            retVal = false;
hgs
parents:
diff changeset
   380
        }
hgs
parents:
diff changeset
   381
        clearSelectionInModel();
hgs
parents:
diff changeset
   382
    }
hgs
parents:
diff changeset
   383
    return retVal;
hgs
parents:
diff changeset
   384
}
hgs
parents:
diff changeset
   385
57
hgs
parents: 55
diff changeset
   386
/*!
70
hgs
parents: 63
diff changeset
   387
 \brief Clears current selection in Selection Model.
hgs
parents: 63
diff changeset
   388
 */
45
hgs
parents:
diff changeset
   389
void CalenDayItemView::clearSelectionInModel()
hgs
parents:
diff changeset
   390
{
hgs
parents:
diff changeset
   391
    QItemSelectionModel* selModel(selectionModel());
hgs
parents:
diff changeset
   392
    if (selModel) {
hgs
parents:
diff changeset
   393
        selModel->clear();
hgs
parents:
diff changeset
   394
    }
hgs
parents:
diff changeset
   395
}
hgs
parents:
diff changeset
   396
hgs
parents:
diff changeset
   397
// End of File