searchui/stateproviders/searchstateprovider/src/searchuiloader.cpp
changeset 15 df6898e696c6
child 16 e918432ddd92
equal deleted inserted replaced
13:0a2ec6860a93 15:df6898e696c6
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:  Implementation of the uicontroller.
       
    15  *
       
    16  */
       
    17 
       
    18 #include "searchuiloader.h"
       
    19 #include <hbdocumentloader.h>
       
    20 #include <hbview.h>
       
    21 #include <hblistwidget.h>
       
    22 #include <hbsearchpanel.h>
       
    23 #include <hbabstractviewitem.h>
       
    24 #include <hbframebackground.h>
       
    25 #include <hblistviewitem.h>
       
    26 #include <hbmainwindow.h>
       
    27 #include <hbaction.h>
       
    28 #include <hbinstance.h>
       
    29 #include <tstasksettings.h>
       
    30 #include <hbshrinkingvkbhost.h>
       
    31 const char *SEARCHSTATEPROVIDER_DOCML = ":/xml/searchstateprovider.docml";
       
    32 const char *TOC_VIEW = "tocView";
       
    33 const char *TUT_SEARCHPANEL_WIDGET = "searchPanel";
       
    34 const char *TUT_LIST_VIEW = "listView";
       
    35 
       
    36 SearchUiLoader *SearchUiLoader::m_instance = 0;
       
    37 int SearchUiLoader::m_instanceCounter = 0;
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // SearchUiLoader::SearchUiLoader
       
    41 // ---------------------------------------------------------------------------
       
    42 SearchUiLoader::SearchUiLoader() :
       
    43     mDocumentLoader(NULL), mView(NULL), mListWidget(NULL), mSearchPanel(NULL),mClient(NULL)
       
    44     {
       
    45     bool ok = false;
       
    46 
       
    47     mDocumentLoader = new HbDocumentLoader();
       
    48 
       
    49     mDocumentLoader->load(SEARCHSTATEPROVIDER_DOCML, &ok);
       
    50 
       
    51     QGraphicsWidget *widget = mDocumentLoader->findWidget(TOC_VIEW);
       
    52 
       
    53     Q_ASSERT_X(ok && (widget != 0), "TOC_VIEW", "invalid view");
       
    54 
       
    55     mView = qobject_cast<HbView*> (widget);
       
    56 
       
    57     if (mView)
       
    58         {
       
    59         mView->setTitle(hbTrId("txt_search_title_search"));
       
    60         }
       
    61 
       
    62     mListWidget = qobject_cast<HbListWidget *> (mDocumentLoader->findWidget(
       
    63             TUT_LIST_VIEW));
       
    64 
       
    65     Q_ASSERT_X(ok && (mListWidget != 0), "TUT_LIST_VIEW", "invalid viewocML file");
       
    66 
       
    67     if (mListWidget)
       
    68         {
       
    69         HbAbstractViewItem *prototype = mListWidget->itemPrototypes().first();
       
    70         HbFrameBackground frame;
       
    71         frame.setFrameGraphicsName("qtg_fr_list_normal");
       
    72         frame.setFrameType(HbFrameDrawer::NinePieces);
       
    73         prototype->setDefaultFrame(frame);
       
    74         HbListViewItem *prototypeListView = qobject_cast<HbListViewItem *> (
       
    75                 prototype);
       
    76         prototypeListView->setGraphicsSize(HbListViewItem::LargeIcon);
       
    77         if (prototypeListView)
       
    78             {
       
    79             prototypeListView->setTextFormat(Qt::RichText);
       
    80             }
       
    81         HbAbstractItemView::ItemAnimations noCreationAndRemovalAnimations =
       
    82                 HbAbstractItemView::All;
       
    83         noCreationAndRemovalAnimations ^= HbAbstractItemView::Appear;
       
    84         noCreationAndRemovalAnimations ^= HbAbstractItemView::Disappear;
       
    85         mListWidget->setEnabledAnimations(noCreationAndRemovalAnimations);
       
    86         }
       
    87 
       
    88     mSearchPanel = qobject_cast<HbSearchPanel *> (
       
    89             mDocumentLoader->findWidget(TUT_SEARCHPANEL_WIDGET));
       
    90     if (mSearchPanel)
       
    91         {
       
    92         Qt::InputMethodHints hints = mSearchPanel->inputMethodHints();
       
    93         hints |= Qt::ImhNoPredictiveText;
       
    94         mSearchPanel->setInputMethodHints(hints);
       
    95         mSearchPanel->setSearchOptionsEnabled(true);
       
    96         mSearchPanel->setCancelEnabled(false);
       
    97         }
       
    98 
       
    99     mMainWindow = hbInstance->allMainWindows().at(0);
       
   100     HbAction *action = new HbAction(Hb::DoneNaviAction);
       
   101     connect(action, SIGNAL(triggered()), this, SLOT(slotsendtobackground()));
       
   102     mView->setNavigationAction(action);
       
   103     mVirtualKeyboard = new HbShrinkingVkbHost(mView);
       
   104     QCoreApplication::instance()->installEventFilter(this);
       
   105     }
       
   106 // ---------------------------------------------------------------------------
       
   107 // SearchUiLoader::~SearchUiLoader
       
   108 // ---------------------------------------------------------------------------
       
   109 SearchUiLoader::~SearchUiLoader()
       
   110     {
       
   111     QCoreApplication::instance()->removeEventFilter(this);
       
   112 
       
   113     if (mDocumentLoader)
       
   114         {
       
   115         delete mDocumentLoader;
       
   116         }
       
   117     delete mClient;
       
   118     }
       
   119 // ---------------------------------------------------------------------------
       
   120 // SearchUiLoader::slotsendtobackground
       
   121 // ---------------------------------------------------------------------------
       
   122 void SearchUiLoader::slotsendtobackground()
       
   123     {
       
   124     if (!mClient)
       
   125         mClient = new TsTaskSettings;
       
   126     mClient->setVisibility(false);
       
   127     mListWidget->clear();
       
   128     mSearchPanel->setCriteria(QString());
       
   129     mMainWindow->lower();
       
   130     }
       
   131 // ---------------------------------------------------------------------------
       
   132 // SearchUiLoader::event
       
   133 // ---------------------------------------------------------------------------
       
   134 bool SearchUiLoader::eventFilter(QObject *obj, QEvent *event)
       
   135     {
       
   136     if (event->type() == QEvent::ApplicationActivate)
       
   137         {
       
   138         if (!mClient)
       
   139             mClient = new TsTaskSettings;
       
   140         mClient->setVisibility(true);
       
   141         if (!(mListWidget->count()))
       
   142             mSearchPanel->setFocus();
       
   143         return true;
       
   144         }
       
   145     return QObject::eventFilter(obj, event);
       
   146     }