homescreenapp/stateplugins/hsapplibrarystateplugin/src/hssearchview.cpp
author hgs
Wed, 18 Aug 2010 10:33:57 +0300
changeset 81 7dd137878ff8
parent 71 1db7cc813a4e
child 90 3ac3aaebaee5
permissions -rw-r--r--
201033
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
69
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
 * Copyright (c) 2009 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: hssearchview.cpp
hgs
parents:
diff changeset
    15
 *
hgs
parents:
diff changeset
    16
 */
hgs
parents:
diff changeset
    17
71
hgs
parents: 69
diff changeset
    18
#include <QApplication>
69
hgs
parents:
diff changeset
    19
#include <QSortFilterProxyModel>
hgs
parents:
diff changeset
    20
#include <HbGroupBox>
hgs
parents:
diff changeset
    21
#include <HbLineEdit>
hgs
parents:
diff changeset
    22
#include <HbListView>
hgs
parents:
diff changeset
    23
#include <HbAbstractViewItem>
hgs
parents:
diff changeset
    24
#include <HbView>
hgs
parents:
diff changeset
    25
#include <HbSearchPanel>
hgs
parents:
diff changeset
    26
hgs
parents:
diff changeset
    27
#include <caitemmodel.h>
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
#include "hslistviewitem.h"
hgs
parents:
diff changeset
    30
#include "hsmainwindow.h"
hgs
parents:
diff changeset
    31
#include "hssearchview.h"
hgs
parents:
diff changeset
    32
hgs
parents:
diff changeset
    33
/*!
81
hgs
parents: 71
diff changeset
    34
 * \fn void activated(const QModelIndex &index)
hgs
parents: 71
diff changeset
    35
 * This signal is emitted when item is tapped.
hgs
parents: 71
diff changeset
    36
 * \param index of an item that was tapped.
hgs
parents: 71
diff changeset
    37
 */
hgs
parents: 71
diff changeset
    38
hgs
parents: 71
diff changeset
    39
 /*!
hgs
parents: 71
diff changeset
    40
 * \fn void longPressed(HbAbstractViewItem *item, const QPointF &coords)
hgs
parents: 71
diff changeset
    41
 * This singal is emitted when view is long pressed.
hgs
parents: 71
diff changeset
    42
 * \param item View item that was long pressed.
hgs
parents: 71
diff changeset
    43
 * \param coords View coordinates of the long press.
hgs
parents: 71
diff changeset
    44
 */
hgs
parents: 71
diff changeset
    45
 
hgs
parents: 71
diff changeset
    46
 /*!
hgs
parents: 71
diff changeset
    47
  * \fn void searchComplete(const QModelIndex &firstMatching)
hgs
parents: 71
diff changeset
    48
  * This signal is emitted when search action has been finished 
hgs
parents: 71
diff changeset
    49
  * and search view is about to quit.
hgs
parents: 71
diff changeset
    50
  * \param firstMatching of first item in search filtered view.
hgs
parents: 71
diff changeset
    51
  */
hgs
parents: 71
diff changeset
    52
    
hgs
parents: 71
diff changeset
    53
    
hgs
parents: 71
diff changeset
    54
/*!
69
hgs
parents:
diff changeset
    55
  Set up proxy model for search.
hgs
parents:
diff changeset
    56
  \param builder Retrieves UI widgets.
hgs
parents:
diff changeset
    57
  \param stateContext Identifies the state where search starts from.
hgs
parents:
diff changeset
    58
  \param mainWindow Enables switching between originating and search view.
hgs
parents:
diff changeset
    59
 */
hgs
parents:
diff changeset
    60
HsSearchView::HsSearchView(HsMenuViewBuilder &builder,
hgs
parents:
diff changeset
    61
        HsStateContext stateContext, HsMainWindow &mainWindow) :
71
hgs
parents: 69
diff changeset
    62
    mProxyModel(new QSortFilterProxyModel(this)), mSearchView(NULL),
69
hgs
parents:
diff changeset
    63
    mSearchListView(NULL), mSearchPanel(NULL), mStateContext(stateContext),
hgs
parents:
diff changeset
    64
    mBuilder(builder), mMainWindow(mainWindow), mListView(NULL),
71
hgs
parents: 69
diff changeset
    65
    mVkbHost(NULL), mSearchViewBuilder(), mEmptyResultText(true)
69
hgs
parents:
diff changeset
    66
{
hgs
parents:
diff changeset
    67
    mProxyModel->setFilterRole(CaItemModel::TextRole);
81
hgs
parents: 71
diff changeset
    68
    mProxyModel->setFilterKeyColumn(0);
69
hgs
parents:
diff changeset
    69
    mProxyModel->setSortRole(CaItemModel::TextRole);
81
hgs
parents: 71
diff changeset
    70
    mProxyModel->setDynamicSortFilter(true);
69
hgs
parents:
diff changeset
    71
}
hgs
parents:
diff changeset
    72
hgs
parents:
diff changeset
    73
/*!
hgs
parents:
diff changeset
    74
  Empty.
hgs
parents:
diff changeset
    75
 */
hgs
parents:
diff changeset
    76
HsSearchView::~HsSearchView()
hgs
parents:
diff changeset
    77
{
hgs
parents:
diff changeset
    78
}
hgs
parents:
diff changeset
    79
hgs
parents:
diff changeset
    80
/*!
hgs
parents:
diff changeset
    81
    Makes the UI to show or hide view search panel.
hgs
parents:
diff changeset
    82
    When search panel is shown the view toolbar and status pane
hgs
parents:
diff changeset
    83
    are hidden until search panel is hidden.
hgs
parents:
diff changeset
    84
    \param visible When true search panel will be shown,
hgs
parents:
diff changeset
    85
     otherwise it will be hidden.
hgs
parents:
diff changeset
    86
 */
hgs
parents:
diff changeset
    87
void HsSearchView::setSearchPanelVisible(bool visible)
hgs
parents:
diff changeset
    88
{
hgs
parents:
diff changeset
    89
    HSMENUTEST_FUNC_ENTRY("HsMenuView::setSearchPanelVisible");
hgs
parents:
diff changeset
    90
hgs
parents:
diff changeset
    91
    if (visible && !isActive()) {
hgs
parents:
diff changeset
    92
        searchBegins();
hgs
parents:
diff changeset
    93
        connectSearchItemViewsSignals();
hgs
parents:
diff changeset
    94
        connectSearchPanelSignals();
hgs
parents:
diff changeset
    95
    } else if (isActive()) {
hgs
parents:
diff changeset
    96
        disconnectSearchPanelSignals();
hgs
parents:
diff changeset
    97
        disconnectSearchItemViewsSignals();
hgs
parents:
diff changeset
    98
        searchFinished();
hgs
parents:
diff changeset
    99
    }
hgs
parents:
diff changeset
   100
    HSMENUTEST_FUNC_EXIT("HsMenuView::setSearchPanelVisible");
hgs
parents:
diff changeset
   101
}
hgs
parents:
diff changeset
   102
hgs
parents:
diff changeset
   103
/*!
hgs
parents:
diff changeset
   104
    \param view List view to operate on.
71
hgs
parents: 69
diff changeset
   105
    \return Index of F=first visible item of \a view if any
69
hgs
parents:
diff changeset
   106
    or default QModelIndex otherwise.
hgs
parents:
diff changeset
   107
 */
hgs
parents:
diff changeset
   108
QModelIndex HsSearchView::firstVisibleItemIndex(const HbListView *view) const
hgs
parents:
diff changeset
   109
{
71
hgs
parents: 69
diff changeset
   110
    const QList<HbAbstractViewItem *> array = view->visibleItems();
hgs
parents: 69
diff changeset
   111
    if (array.count()) {
hgs
parents: 69
diff changeset
   112
        return array[0]->modelIndex();
69
hgs
parents:
diff changeset
   113
    }
71
hgs
parents: 69
diff changeset
   114
    return QModelIndex();
69
hgs
parents:
diff changeset
   115
}
hgs
parents:
diff changeset
   116
hgs
parents:
diff changeset
   117
/*!
hgs
parents:
diff changeset
   118
 Displays search panel with view representing search results.
hgs
parents:
diff changeset
   119
 */
hgs
parents:
diff changeset
   120
void HsSearchView::searchBegins()
hgs
parents:
diff changeset
   121
{
hgs
parents:
diff changeset
   122
    HSMENUTEST_FUNC_ENTRY("HsSearchView::searchBegins");
hgs
parents:
diff changeset
   123
hgs
parents:
diff changeset
   124
    setOriginatingContext();
hgs
parents:
diff changeset
   125
hgs
parents:
diff changeset
   126
    mListView = mBuilder.currentListView();
hgs
parents:
diff changeset
   127
    mSearchViewInitialIndex = firstVisibleItemIndex(mListView);
hgs
parents:
diff changeset
   128
hgs
parents:
diff changeset
   129
    mProxyModel->invalidate();
hgs
parents:
diff changeset
   130
    mProxyModel->setSourceModel(mListView->model());
hgs
parents:
diff changeset
   131
    mProxyModel->setFilterRegExp(
hgs
parents:
diff changeset
   132
            QRegExp(QString(".*"), Qt::CaseInsensitive, QRegExp::RegExp));
hgs
parents:
diff changeset
   133
71
hgs
parents: 69
diff changeset
   134
    mSearchView = mSearchViewBuilder.searchView();
hgs
parents: 69
diff changeset
   135
    mSearchListView = mSearchViewBuilder.searchListView();
hgs
parents: 69
diff changeset
   136
    mSearchPanel = mSearchViewBuilder.searchPanel();
69
hgs
parents:
diff changeset
   137
    initSearchPanel(*mSearchPanel);
hgs
parents:
diff changeset
   138
    mVkbHost.reset(new HbShrinkingVkbHost(mSearchView));
hgs
parents:
diff changeset
   139
71
hgs
parents: 69
diff changeset
   140
    if (mBuilder.currentViewLabel()) {
hgs
parents: 69
diff changeset
   141
        mSearchViewBuilder.searchViewLabel()->setHeading(
hgs
parents: 69
diff changeset
   142
                mBuilder.currentViewLabel()->heading());
hgs
parents: 69
diff changeset
   143
        mSearchViewBuilder.setSearchLabledContext();
69
hgs
parents:
diff changeset
   144
    }
hgs
parents:
diff changeset
   145
hgs
parents:
diff changeset
   146
    mSearchView->hideItems(Hb::AllItems);
71
hgs
parents: 69
diff changeset
   147
    mSearchListView->setModel(mProxyModel, new HsListViewItem());
69
hgs
parents:
diff changeset
   148
hgs
parents:
diff changeset
   149
    mMainWindow.setCurrentView(mSearchView);
hgs
parents:
diff changeset
   150
81
hgs
parents: 71
diff changeset
   151
    openVkb();
hgs
parents: 71
diff changeset
   152
69
hgs
parents:
diff changeset
   153
    mSearchListView->scrollTo(
hgs
parents:
diff changeset
   154
        mProxyModel->mapFromSource(mSearchViewInitialIndex),
hgs
parents:
diff changeset
   155
        HbAbstractItemView::PositionAtTop);
71
hgs
parents: 69
diff changeset
   156
hgs
parents: 69
diff changeset
   157
    setNoResultsVisibility();
69
hgs
parents:
diff changeset
   158
    HSMENUTEST_FUNC_EXIT("HsSearchView::searchBegins");
hgs
parents:
diff changeset
   159
}
hgs
parents:
diff changeset
   160
71
hgs
parents: 69
diff changeset
   161
/*!
hgs
parents: 69
diff changeset
   162
 Handles button visibility.
hgs
parents: 69
diff changeset
   163
 \param visibility indicates whether show or not to show 'empty' label.
hgs
parents: 69
diff changeset
   164
 */
hgs
parents: 69
diff changeset
   165
void HsSearchView::setNoResultsVisibility()
hgs
parents: 69
diff changeset
   166
{
hgs
parents: 69
diff changeset
   167
    if (mProxyModel->rowCount() && mEmptyResultText) {
hgs
parents: 69
diff changeset
   168
        mSearchViewBuilder.loadViewListSection();
hgs
parents: 69
diff changeset
   169
        mEmptyResultText = false;
hgs
parents: 69
diff changeset
   170
    } else if (!mProxyModel->rowCount() && !mEmptyResultText) {
hgs
parents: 69
diff changeset
   171
        mSearchViewBuilder.loadViewEmptySection();
hgs
parents: 69
diff changeset
   172
        mEmptyResultText = true;
hgs
parents: 69
diff changeset
   173
    }
hgs
parents: 69
diff changeset
   174
}
69
hgs
parents:
diff changeset
   175
hgs
parents:
diff changeset
   176
/*
hgs
parents:
diff changeset
   177
 Connects \a activated and \a longPressed signals coming from search list
hgs
parents:
diff changeset
   178
 view to emit corresponding signal of this object with translated model index.
hgs
parents:
diff changeset
   179
*/
hgs
parents:
diff changeset
   180
void HsSearchView::connectSearchItemViewsSignals()
hgs
parents:
diff changeset
   181
{
81
hgs
parents: 71
diff changeset
   182
    connect(mSearchListView, SIGNAL(pressed(QModelIndex)),
hgs
parents: 71
diff changeset
   183
                this, SLOT(hideVkb()), Qt::UniqueConnection);
69
hgs
parents:
diff changeset
   184
    connect(mSearchListView, SIGNAL(activated(QModelIndex)),
81
hgs
parents: 71
diff changeset
   185
            this, SLOT(activatedProxySlot(QModelIndex)), Qt::UniqueConnection);
69
hgs
parents:
diff changeset
   186
    connect(mSearchListView, SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
81
hgs
parents: 71
diff changeset
   187
            this, SLOT(longPressedProxySlot(HbAbstractViewItem *, QPointF)), 
hgs
parents: 71
diff changeset
   188
			    Qt::UniqueConnection);
hgs
parents: 71
diff changeset
   189
69
hgs
parents:
diff changeset
   190
}
hgs
parents:
diff changeset
   191
hgs
parents:
diff changeset
   192
/*!
hgs
parents:
diff changeset
   193
 Disconnects \a activated and \a longPressed signals coming from list
hgs
parents:
diff changeset
   194
 view from to emit corresponding signal
hgs
parents:
diff changeset
   195
 of this object with translated model index.
hgs
parents:
diff changeset
   196
*/
hgs
parents:
diff changeset
   197
void HsSearchView::disconnectSearchItemViewsSignals()
hgs
parents:
diff changeset
   198
{
81
hgs
parents: 71
diff changeset
   199
    disconnect(mSearchListView, SIGNAL(pressed(QModelIndex)),
hgs
parents: 71
diff changeset
   200
            this, SLOT(hideVkb()));
69
hgs
parents:
diff changeset
   201
    disconnect(mSearchListView, SIGNAL(activated(QModelIndex)),
hgs
parents:
diff changeset
   202
            this, SLOT(activatedProxySlot(QModelIndex)));
hgs
parents:
diff changeset
   203
    disconnect(mSearchListView,
hgs
parents:
diff changeset
   204
            SIGNAL(longPressed(HbAbstractViewItem *, QPointF)),
hgs
parents:
diff changeset
   205
            this, SLOT(longPressedProxySlot(HbAbstractViewItem *, QPointF)));
hgs
parents:
diff changeset
   206
}
hgs
parents:
diff changeset
   207
hgs
parents:
diff changeset
   208
hgs
parents:
diff changeset
   209
/*!
hgs
parents:
diff changeset
   210
 Makes search panel invisible.
hgs
parents:
diff changeset
   211
 Equivalent to \a setSearchPanelVisible(false).
hgs
parents:
diff changeset
   212
 */
hgs
parents:
diff changeset
   213
void HsSearchView::hideSearchPanel()
hgs
parents:
diff changeset
   214
{
hgs
parents:
diff changeset
   215
    HSMENUTEST_FUNC_ENTRY("HsMenuView::hideSearchPanel");
hgs
parents:
diff changeset
   216
    setSearchPanelVisible(false);
hgs
parents:
diff changeset
   217
    HSMENUTEST_FUNC_EXIT("HsMenuView::hideSearchPanel");
hgs
parents:
diff changeset
   218
}
hgs
parents:
diff changeset
   219
hgs
parents:
diff changeset
   220
/*!
hgs
parents:
diff changeset
   221
 Connects signals \a exitClicked and \a criteriaChanged emitted
hgs
parents:
diff changeset
   222
 by search panel with handling slots of the object or its members.
hgs
parents:
diff changeset
   223
*/
hgs
parents:
diff changeset
   224
void HsSearchView::connectSearchPanelSignals()
hgs
parents:
diff changeset
   225
{
81
hgs
parents: 71
diff changeset
   226
    connect(mProxyModel, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
hgs
parents: 71
diff changeset
   227
            this, SLOT(setNoResultsVisibility()), Qt::UniqueConnection);
71
hgs
parents: 69
diff changeset
   228
    connect(mProxyModel, SIGNAL(rowsInserted(QModelIndex, int, int)),
hgs
parents: 69
diff changeset
   229
            this, SLOT(setNoResultsVisibility()));
hgs
parents: 69
diff changeset
   230
    connect(mProxyModel, SIGNAL(rowsRemoved(QModelIndex, int, int)),
hgs
parents: 69
diff changeset
   231
            this, SLOT(setNoResultsVisibility()));
69
hgs
parents:
diff changeset
   232
    connect(mSearchPanel, SIGNAL(exitClicked()),
hgs
parents:
diff changeset
   233
            this, SLOT(hideSearchPanel()));
hgs
parents:
diff changeset
   234
    connect(mSearchPanel, SIGNAL(criteriaChanged(QString)),
81
hgs
parents: 71
diff changeset
   235
            this, SLOT(findItem(QString)), Qt::UniqueConnection);
69
hgs
parents:
diff changeset
   236
}
hgs
parents:
diff changeset
   237
hgs
parents:
diff changeset
   238
/*!
hgs
parents:
diff changeset
   239
 Disconnects signals \a exitClicked and \a criteriaChanged emitted
hgs
parents:
diff changeset
   240
 by search panel from handling slots of the object or its members
hgs
parents:
diff changeset
   241
 Scrolls view to state before connections.
hgs
parents:
diff changeset
   242
*/
hgs
parents:
diff changeset
   243
void HsSearchView::disconnectSearchPanelSignals()
hgs
parents:
diff changeset
   244
{
71
hgs
parents: 69
diff changeset
   245
    mProxyModel->disconnect(this);
hgs
parents: 69
diff changeset
   246
    mSearchPanel->disconnect(this);
69
hgs
parents:
diff changeset
   247
}
hgs
parents:
diff changeset
   248
hgs
parents:
diff changeset
   249
/*!
hgs
parents:
diff changeset
   250
  Scrolls originating view to first item matching search criteria.
hgs
parents:
diff changeset
   251
 */
hgs
parents:
diff changeset
   252
void HsSearchView::searchFinished()
hgs
parents:
diff changeset
   253
{
hgs
parents:
diff changeset
   254
    HSMENUTEST_FUNC_ENTRY("HsSearchView::searchFinished");
hgs
parents:
diff changeset
   255
71
hgs
parents: 69
diff changeset
   256
    mIndexToScrollAfterSearchDone = firstVisibleItemIndex(mSearchListView);
69
hgs
parents:
diff changeset
   257
81
hgs
parents: 71
diff changeset
   258
    // emiting searchComplete must be done
hgs
parents: 71
diff changeset
   259
    // after this->isActive() returns false
hgs
parents: 71
diff changeset
   260
    mSearchListView = NULL;
hgs
parents: 71
diff changeset
   261
    mSearchPanel = NULL;
hgs
parents: 71
diff changeset
   262
    
hgs
parents: 71
diff changeset
   263
    emit searchComplete(mProxyModel->mapToSource(
hgs
parents: 71
diff changeset
   264
            mIndexToScrollAfterSearchDone));
69
hgs
parents:
diff changeset
   265
hgs
parents:
diff changeset
   266
    HbVkbHost::detachHost(mSearchView);
hgs
parents:
diff changeset
   267
    mVkbHost.reset(NULL);
81
hgs
parents: 71
diff changeset
   268
71
hgs
parents: 69
diff changeset
   269
    mProxyModel->setSourceModel(NULL);
69
hgs
parents:
diff changeset
   270
    HSMENUTEST_FUNC_EXIT("HsSearchView::searchFinished");
hgs
parents:
diff changeset
   271
}
hgs
parents:
diff changeset
   272
hgs
parents:
diff changeset
   273
/*!
hgs
parents:
diff changeset
   274
 Looks up for item and if found scrolls to it.
hgs
parents:
diff changeset
   275
 \param criteriaStr The item name to find.
hgs
parents:
diff changeset
   276
 */
hgs
parents:
diff changeset
   277
void HsSearchView::findItem(QString criteriaStr)
hgs
parents:
diff changeset
   278
{
hgs
parents:
diff changeset
   279
    qDebug() << "HsSearchView::findItem: " + criteriaStr;
hgs
parents:
diff changeset
   280
    HSMENUTEST_FUNC_ENTRY("HsSearchView::findItem");
hgs
parents:
diff changeset
   281
hgs
parents:
diff changeset
   282
    mProxyModel->setFilterRegExp(
hgs
parents:
diff changeset
   283
            QRegExp("(^|\\b)" + criteriaStr, Qt::CaseInsensitive));
hgs
parents:
diff changeset
   284
hgs
parents:
diff changeset
   285
    mSearchListView->scrollTo(
81
hgs
parents: 71
diff changeset
   286
            mProxyModel->index(0, 0), HbAbstractItemView::PositionAtTop);
69
hgs
parents:
diff changeset
   287
hgs
parents:
diff changeset
   288
    HSMENUTEST_FUNC_EXIT("HsSearchView::findItem");
hgs
parents:
diff changeset
   289
}
hgs
parents:
diff changeset
   290
hgs
parents:
diff changeset
   291
/*!
hgs
parents:
diff changeset
   292
 Slot used to translate activated signal from proxy model to normal model.
hgs
parents:
diff changeset
   293
 \param index Represents an item activated in search list view.
hgs
parents:
diff changeset
   294
 */
hgs
parents:
diff changeset
   295
void HsSearchView::activatedProxySlot(const QModelIndex &index)
hgs
parents:
diff changeset
   296
{
hgs
parents:
diff changeset
   297
    emit activated(mProxyModel->mapToSource(index));
hgs
parents:
diff changeset
   298
}
hgs
parents:
diff changeset
   299
hgs
parents:
diff changeset
   300
/*!
hgs
parents:
diff changeset
   301
 Slot used to forward 'long pressed' signal with item description transladed
hgs
parents:
diff changeset
   302
 from search view context to context of the view search was requested from.
hgs
parents:
diff changeset
   303
  \param item Long pressed item.
hgs
parents:
diff changeset
   304
  \param coords Coordinates of the long press action.
hgs
parents:
diff changeset
   305
 */
71
hgs
parents: 69
diff changeset
   306
void HsSearchView::longPressedProxySlot(
hgs
parents: 69
diff changeset
   307
        HbAbstractViewItem *item, const QPointF &coords)
69
hgs
parents:
diff changeset
   308
{
hgs
parents:
diff changeset
   309
    /*
hgs
parents:
diff changeset
   310
    this is a kind of hack, introduced for reasons:
hgs
parents:
diff changeset
   311
    item object should be reusable later, but orbit (or qt) prevents setting
hgs
parents:
diff changeset
   312
    its index model to previous state
hgs
parents:
diff changeset
   313
    */
71
hgs
parents: 69
diff changeset
   314
    mSearchViewLongPressedIndex = mProxyModel->mapToSource(
hgs
parents: 69
diff changeset
   315
            item->modelIndex());
69
hgs
parents:
diff changeset
   316
    QScopedPointer<HbAbstractViewItem> itemNew(item->createItem());
hgs
parents:
diff changeset
   317
    itemNew->setModelIndex(mSearchViewLongPressedIndex);
hgs
parents:
diff changeset
   318
    emit longPressed(itemNew.data(), coords);
hgs
parents:
diff changeset
   319
}
hgs
parents:
diff changeset
   320
hgs
parents:
diff changeset
   321
/*!
hgs
parents:
diff changeset
   322
  Sets up search panel.
hgs
parents:
diff changeset
   323
hgs
parents:
diff changeset
   324
 \param searchPanel Search panel to initialize.
hgs
parents:
diff changeset
   325
 */
hgs
parents:
diff changeset
   326
void HsSearchView::initSearchPanel(HbSearchPanel &searchPanel)
hgs
parents:
diff changeset
   327
{
hgs
parents:
diff changeset
   328
    HbLineEdit *const lineEdit(searchPanelLineEdit(searchPanel));
hgs
parents:
diff changeset
   329
hgs
parents:
diff changeset
   330
    lineEdit->setText("");
hgs
parents:
diff changeset
   331
    lineEdit->setFocus();
71
hgs
parents: 69
diff changeset
   332
    lineEdit->setInputMethodHints(
hgs
parents: 69
diff changeset
   333
            Qt::ImhNoPredictiveText | Qt::ImhNoAutoUppercase);
69
hgs
parents:
diff changeset
   334
}
hgs
parents:
diff changeset
   335
hgs
parents:
diff changeset
   336
/*!
hgs
parents:
diff changeset
   337
 \param searchPanel Search panel to operate on.
hgs
parents:
diff changeset
   338
 \return Line edit of the searchPanel on success, NULL otherwise.
hgs
parents:
diff changeset
   339
 */
hgs
parents:
diff changeset
   340
HbLineEdit *HsSearchView::searchPanelLineEdit(
hgs
parents:
diff changeset
   341
        HbSearchPanel &searchPanel) const
hgs
parents:
diff changeset
   342
{
hgs
parents:
diff changeset
   343
    HSMENUTEST_FUNC_ENTRY("HsSearchView::searchPanelLineEdit");
hgs
parents:
diff changeset
   344
hgs
parents:
diff changeset
   345
    HbLineEdit *result(0);
hgs
parents:
diff changeset
   346
    foreach(QGraphicsItem *obj, searchPanel.childItems()) {
hgs
parents:
diff changeset
   347
        QGraphicsWidget *const widget = static_cast<QGraphicsWidget *>(obj);
hgs
parents:
diff changeset
   348
        if (widget != NULL) {
hgs
parents:
diff changeset
   349
            HbLineEdit *const lineEdit = qobject_cast<HbLineEdit *>(widget);
hgs
parents:
diff changeset
   350
            if (lineEdit != NULL) {
hgs
parents:
diff changeset
   351
                result = lineEdit;
hgs
parents:
diff changeset
   352
                break;
hgs
parents:
diff changeset
   353
            }
hgs
parents:
diff changeset
   354
        }
hgs
parents:
diff changeset
   355
    }
hgs
parents:
diff changeset
   356
    HSMENUTEST_FUNC_EXIT("HsSearchView::searchPanelLineEdit");
hgs
parents:
diff changeset
   357
hgs
parents:
diff changeset
   358
    return result;
hgs
parents:
diff changeset
   359
}
hgs
parents:
diff changeset
   360
hgs
parents:
diff changeset
   361
/*!
hgs
parents:
diff changeset
   362
  Sets the builder context to the one determined by \a mStateContext and
hgs
parents:
diff changeset
   363
  \a HsItemViewContext.
hgs
parents:
diff changeset
   364
 */
hgs
parents:
diff changeset
   365
void HsSearchView::setOriginatingContext()
hgs
parents:
diff changeset
   366
{
hgs
parents:
diff changeset
   367
    mBuilder.setStateContext(mStateContext);
hgs
parents:
diff changeset
   368
    mBuilder.setOperationalContext(HsItemViewContext);
hgs
parents:
diff changeset
   369
}
hgs
parents:
diff changeset
   370
hgs
parents:
diff changeset
   371
/*!
81
hgs
parents: 71
diff changeset
   372
  \retval true when search view is actually responsible for view management, 
hgs
parents: 71
diff changeset
   373
  \a false otherwise.
69
hgs
parents:
diff changeset
   374
 */
hgs
parents:
diff changeset
   375
bool HsSearchView::isActive() const
hgs
parents:
diff changeset
   376
{
hgs
parents:
diff changeset
   377
    return mSearchListView != NULL;
hgs
parents:
diff changeset
   378
}
hgs
parents:
diff changeset
   379
81
hgs
parents: 71
diff changeset
   380
/*!
hgs
parents: 71
diff changeset
   381
  Slot to close virtual keyboard.
hgs
parents: 71
diff changeset
   382
 */
hgs
parents: 71
diff changeset
   383
void HsSearchView::hideVkb()
hgs
parents: 71
diff changeset
   384
{
hgs
parents: 71
diff changeset
   385
    sendEvent(QEvent::CloseSoftwareInputPanel);
hgs
parents: 71
diff changeset
   386
}
hgs
parents: 71
diff changeset
   387
hgs
parents: 71
diff changeset
   388
/*!
hgs
parents: 71
diff changeset
   389
 Makes Vkb open provided there is an editor visible in the graphics scene.
hgs
parents: 71
diff changeset
   390
 */
hgs
parents: 71
diff changeset
   391
void HsSearchView::openVkb()
hgs
parents: 71
diff changeset
   392
{
hgs
parents: 71
diff changeset
   393
    sendEvent(QEvent::RequestSoftwareInputPanel);
hgs
parents: 71
diff changeset
   394
}
hgs
parents: 71
diff changeset
   395
hgs
parents: 71
diff changeset
   396
/*!
hgs
parents: 71
diff changeset
   397
  Sends QEvent.
hgs
parents: 71
diff changeset
   398
  \param eventType Identifies event to be sent.
hgs
parents: 71
diff changeset
   399
 */
hgs
parents: 71
diff changeset
   400
void HsSearchView::sendEvent(const QEvent::Type eventType)
hgs
parents: 71
diff changeset
   401
{
hgs
parents: 71
diff changeset
   402
    QInputContext *const ic = qApp->inputContext();
hgs
parents: 71
diff changeset
   403
    if (ic != NULL) {
hgs
parents: 71
diff changeset
   404
        QScopedPointer<QEvent> event(
hgs
parents: 71
diff changeset
   405
            new QEvent(eventType));
hgs
parents: 71
diff changeset
   406
hgs
parents: 71
diff changeset
   407
        ic->filterEvent(event.data());
hgs
parents: 71
diff changeset
   408
    }
hgs
parents: 71
diff changeset
   409
hgs
parents: 71
diff changeset
   410
}
hgs
parents: 71
diff changeset
   411