userguide/src/HelpKeywordView.cpp
branchRCL_3
changeset 18 cbffe13eac63
parent 17 12f60d9a73b3
equal deleted inserted replaced
17:12f60d9a73b3 18:cbffe13eac63
     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: 
       
    15 *
       
    16 */
       
    17 
       
    18 #include <QStandardItemModel>
       
    19 #include <QDebug>
       
    20 
       
    21 #include <hbmainwindow.h>
       
    22 #include <hbapplication.h>
       
    23 #include <hbaction.h>
       
    24 #include <hbtoolbar.h>
       
    25 #include <hblabel.h>
       
    26 
       
    27 #include <hbtreeview.h>
       
    28 #include <hblistview.h>
       
    29 #include <hbsearchpanel.h>
       
    30 #include <hbscrollbar.h>
       
    31 #include <hblineedit.h>
       
    32 #include <hbmenu.h>
       
    33 #include <hbstaticvkbhost.h>
       
    34 
       
    35 #include "HelpDataProvider.h"
       
    36 #include "HelpProxyModel.h"
       
    37 
       
    38 #include "HelpKeywordView.h"
       
    39 
       
    40 
       
    41 //////////////////////////////////////////////////////////////////////////////////////////////
       
    42 
       
    43 HelpKeywordView::HelpKeywordView() : 
       
    44 mListSearch(NULL), 
       
    45 mSearchPanel(NULL)
       
    46 {
       
    47 }
       
    48 
       
    49 HelpKeywordView::~HelpKeywordView()
       
    50 {
       
    51 }
       
    52 
       
    53 
       
    54 ////////////////////////////////////////////////////////////////////////////////////////////
       
    55 
       
    56 void HelpKeywordView::init()
       
    57 {
       
    58 	initDocMl();
       
    59     initBackAction();
       
    60     initSearchList();
       
    61     initSearchPanel();
       
    62 	initVirtualKeyboard();
       
    63     
       
    64     connect(mainWindow(), SIGNAL(viewReady()), this, SLOT(onViewReady()));
       
    65 }
       
    66 
       
    67 void HelpKeywordView::initDocMl()
       
    68 {
       
    69 	initBaseDocMl(); 
       
    70 	mBuilder.load(QRC_DOCML_KEYWORD);
       
    71 }
       
    72 
       
    73 void HelpKeywordView::initBackAction()
       
    74 {
       
    75     mSoftKeyAction = new HbAction(Hb::BackNaviAction);
       
    76     connect(mSoftKeyAction, SIGNAL(triggered()), this, SLOT(onBackAction()));
       
    77 }
       
    78 
       
    79 void HelpKeywordView::initSearchList()
       
    80 {
       
    81     mListSearch = mBuilder.findWidget<HbListView*>(DOCML_LIST_SEARCH);
       
    82     mListSearch->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
       
    83     mListSearch->setModel(HelpDataProvider::instance()->getSearchData());
       
    84     connect(mListSearch, SIGNAL(activated(const QModelIndex&)), this, SLOT(onSearchListActivated(const QModelIndex&)));
       
    85 }
       
    86 void HelpKeywordView::initSearchPanel()
       
    87 {
       
    88     mSearchPanel = mBuilder.findWidget<HbSearchPanel*>(DOCML_SEARCH_PANEL);
       
    89     connect(mSearchPanel, SIGNAL(exitClicked()), this, SLOT(onSearchPanelExitClicked()));
       
    90     connect(mSearchPanel, SIGNAL(criteriaChanged(const QString&)), this, SLOT(onSearchPanelCriteriaChanged(const QString&)));
       
    91 }
       
    92 
       
    93 void HelpKeywordView::initVirtualKeyboard()
       
    94 {
       
    95 	mVirtualKeyboard = new HbStaticVkbHost(this);
       
    96     connect(mVirtualKeyboard, SIGNAL(keypadOpened()), this, SLOT(onHandleKeypadOpen()));
       
    97     connect(mVirtualKeyboard, SIGNAL(keypadClosed()), this, SLOT(onHandleKeypadClose()));
       
    98 }
       
    99 
       
   100 HbLabel* HelpKeywordView::label()
       
   101 {
       
   102 	return mBuilder.findWidget<HbLabel*>(DOCML_NO_MATCH_LABEL);
       
   103 }
       
   104 
       
   105 void HelpKeywordView::loadAllContent()
       
   106 {
       
   107 	showToolBar(false);
       
   108 	mBuilder.load(QRC_DOCML_KEYWORD, DOCML_LAYOUT_SEARCH);
       
   109 	ResetSearchPanel();
       
   110 	
       
   111 }
       
   112 
       
   113 ////////////////////////////////////////////////////////////////////////////////////////////
       
   114 
       
   115 void HelpKeywordView::updateVisibleItems(bool visible)
       
   116 {
       
   117 	static Hb::SceneItems items = Hb::TitleBarItem | Hb::StatusBarItem;
       
   118 	if(visible)
       
   119 	{
       
   120 		showItems(items);
       
   121 	}
       
   122 	else
       
   123 	{
       
   124 		hideItems(items);
       
   125 	}
       
   126 }
       
   127 
       
   128 void HelpKeywordView::ResetSearchPanel()
       
   129 {
       
   130     foreach(QGraphicsItem *obj, mSearchPanel->childItems())
       
   131     {
       
   132         QGraphicsWidget *const widget = static_cast<QGraphicsWidget*>(obj);
       
   133         if(widget != NULL)
       
   134         {
       
   135             HbLineEdit *const lineEdit = qobject_cast<HbLineEdit*>(widget);
       
   136             if(lineEdit != NULL)
       
   137             {
       
   138                 lineEdit->setText("");
       
   139 				lineEdit->setFocus();
       
   140                 break;
       
   141             }
       
   142         }
       
   143     }
       
   144 }
       
   145 
       
   146 void HelpKeywordView::updateLabelPos()
       
   147 {
       
   148 	HbDeviceProfile profile = HbDeviceProfile::profile(mainWindow());
       
   149 	qreal unValue = profile.unitValue();
       
   150 	if(mainWindow()->orientation() == Qt::Vertical)
       
   151 	{
       
   152 		if(mVirtualKeyboard->keypadStatus() == HbVkbHost::HbVkbStatusClosed)
       
   153 		{
       
   154 			label()->setContentsMargins(0,30 * unValue,0,0);
       
   155 		}
       
   156 		else
       
   157 		{
       
   158 			label()->setContentsMargins(0,10 * unValue,0,0);
       
   159 		}
       
   160 	}
       
   161 	else
       
   162 	{
       
   163 		if(mVirtualKeyboard->keypadStatus() == HbVkbHost::HbVkbStatusClosed)
       
   164 		{
       
   165 			label()->setContentsMargins(0,10 * unValue,0,0);
       
   166 		}
       
   167 		else
       
   168 		{
       
   169             label()->setContentsMargins(0,0,0,0);
       
   170 			label()->setAlignment(label()->alignment() | Qt::AlignVCenter);
       
   171 		}
       
   172 	}
       
   173 }
       
   174 
       
   175 void HelpKeywordView::showToolBar(bool visible)
       
   176 {
       
   177 	Hb::SceneItems items = Hb::ToolBarItem;
       
   178 	if(visible)
       
   179 	{
       
   180 		showItems(items);
       
   181 	}
       
   182 	else
       
   183 	{
       
   184 		hideItems(items);
       
   185 	}
       
   186 }
       
   187 
       
   188 ////////////////////////////////////////////////////////////////////////////////////////////
       
   189 // handle system event
       
   190 
       
   191 void HelpKeywordView::onViewReady()
       
   192 {
       
   193 	if(isVisible())
       
   194 	{
       
   195 		setNavigationAction(mSoftKeyAction);  
       
   196 	}
       
   197 }
       
   198 
       
   199 ///////////////////////////////////////////////////////////////////////////////////////
       
   200 // handle button back action
       
   201 
       
   202 void HelpKeywordView::onBackAction()
       
   203 {
       
   204 	emit activateView(HelpViewCategory);
       
   205 }
       
   206 
       
   207 
       
   208 ////////////////////////////////////////////////////////////////////////////////////////////
       
   209 // handle list event
       
   210 
       
   211 void HelpKeywordView::onSearchListActivated(const QModelIndex& index)
       
   212 {
       
   213     if(!index.isValid() ||          // invalid
       
   214        index.child(0,0).isValid())  // this is a node
       
   215     {
       
   216         return;
       
   217     }
       
   218     
       
   219     QString uid = mListSearch->model()->data(index, UidRole).toString();
       
   220     QString href = mListSearch->model()->data(index, HrefRole).toString();
       
   221     HelpDataProvider::instance()->setHelpContentUrl(uid, href);
       
   222     emit activateView(HelpViewContents);
       
   223 }
       
   224 
       
   225 
       
   226 ////////////////////////////////////////////////////////////////////////////////////////////
       
   227 // handle search panel event
       
   228 
       
   229 void HelpKeywordView::onSearchPanelExitClicked()
       
   230 {
       
   231 	if(mListSearch->model()->rowCount() == 0)
       
   232 	{
       
   233 		mBuilder.load(QRC_DOCML_KEYWORD, DOCML_LAYOUT_SEARCH_NO_SRHPAL_NO_MATCH);
       
   234 	}
       
   235 	else
       
   236 	{
       
   237 		mBuilder.load(QRC_DOCML_KEYWORD, DOCML_LAYOUT_SEARCH_NO_SRHPAL);
       
   238 	}	
       
   239 	showToolBar(true);
       
   240 }
       
   241 
       
   242 void HelpKeywordView::onSearchPanelCriteriaChanged(const QString &criteria)
       
   243 {
       
   244     HelpDataProvider::instance()->getSearchData(criteria);
       
   245 	if(mListSearch->model()->rowCount() == 0)
       
   246 	{
       
   247 		mBuilder.load(QRC_DOCML_KEYWORD, DOCML_LAYOUT_SEARCH_NO_MATCH);
       
   248 	}
       
   249 	else
       
   250 	{
       
   251 		mBuilder.load(QRC_DOCML_KEYWORD, DOCML_LAYOUT_SEARCH);
       
   252 	}
       
   253 	showToolBar(false);
       
   254 }
       
   255 
       
   256 ////////////////////////////////////////////////////////////////////////////////////////////
       
   257 // handle virtual keyboard event
       
   258 
       
   259 void HelpKeywordView::onHandleKeypadOpen()
       
   260 {
       
   261 	updateVisibleItems(false);
       
   262     qreal heightToSet = mainWindow()->layoutRect().height() - mVirtualKeyboard->keyboardArea().height();
       
   263     this->setMaximumHeight(heightToSet);
       
   264 	updateLabelPos();
       
   265 }
       
   266 
       
   267 void HelpKeywordView::onHandleKeypadClose()
       
   268 {	
       
   269 	updateVisibleItems(true);
       
   270 	qreal mainHeight  = mainWindow()->layoutRect().height();
       
   271 	qreal toolbarHeight = toolBar()->size().height();
       
   272 	qreal height = mainHeight - ( toolBar()->isVisible() ? toolbarHeight : 0);
       
   273 	this->setMaximumHeight(height);
       
   274 	updateLabelPos();
       
   275 }
       
   276 
       
   277 void HelpKeywordView::onOrientationChanged(Qt::Orientation orientation)
       
   278 {
       
   279 	Q_UNUSED(orientation);
       
   280 	updateLabelPos();
       
   281 }
       
   282 
       
   283 // end of file