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