userguide/src/HelpCategoryView.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 
       
    25 #include <hbtreeview.h>
       
    26 #include <hbscrollbar.h>
       
    27 #include <hbmenu.h>
       
    28 #include <hbtoolbar.h>
       
    29 
       
    30 #include "HelpDataProvider.h"
       
    31 
       
    32 #include "HelpCategoryView.h"
       
    33 
       
    34 
       
    35 //////////////////////////////////////////////////////////////////////////////////////////////
       
    36 
       
    37 HelpCategoryView::HelpCategoryView() : 
       
    38 mListAll(NULL),
       
    39 mExpandCount(0)
       
    40 {
       
    41 }
       
    42 
       
    43 HelpCategoryView::~HelpCategoryView()
       
    44 {
       
    45 }
       
    46 
       
    47 
       
    48 ////////////////////////////////////////////////////////////////////////////////////////////
       
    49 
       
    50 void HelpCategoryView::init()
       
    51 {
       
    52 	initDocMl();
       
    53     initAllList();
       
    54 }
       
    55 
       
    56 void HelpCategoryView::initDocMl()
       
    57 {
       
    58 	initBaseDocMl();
       
    59     mBuilder.load(QRC_DOCML_CATEGORY);
       
    60 }
       
    61 
       
    62 void HelpCategoryView::initAllList()
       
    63 {
       
    64     mListAll = mBuilder.findWidget<HbTreeView*>(DOCML_LIST_CATEGORY_ALL);
       
    65     mListAll->setHorizontalScrollBarPolicy(HbScrollArea::ScrollBarAlwaysOff);
       
    66     mListAll->setModel(HelpDataProvider::instance()->getCategoryData());
       
    67     connect(mListAll, SIGNAL(activated(const QModelIndex&)), this, SLOT(onAllListActivated(const QModelIndex&)));
       
    68 }
       
    69 
       
    70 ////////////////////////////////////////////////////////////////////////////////////////////
       
    71 
       
    72 void HelpCategoryView::expandCollapseAllList(QStandardItem* item, bool expand)
       
    73 {
       
    74 	if(item->rowCount() <= 0)
       
    75 	{
       
    76 		return;
       
    77 	}
       
    78 	mListAll->setExpanded(item->index(),expand);
       
    79 	for(int i = 0; i < item->rowCount(); i++)
       
    80 	{		
       
    81 		expandCollapseAllList(item->child(i),expand);
       
    82 	}
       
    83 }
       
    84 
       
    85 void HelpCategoryView::updateExpandCollapseAction(bool expand)
       
    86 {
       
    87 	HbAction* allAction = mBuilder.findObject<HbAction*>(DOCML_ACTION_EXPAND_COLLAPSE_ALL);
       
    88 	allAction->setText(expand ? hbTrId(TXT_EXPAND_ALL) : hbTrId(TXT_COLLAPSE_ALL));
       
    89 }
       
    90 
       
    91 ////////////////////////////////////////////////////////////////////////////////////////////
       
    92 // handle list event
       
    93 
       
    94 void HelpCategoryView::onAllListActivated(const QModelIndex& index)
       
    95 {
       
    96     if(!index.isValid() ||          // invalid
       
    97        index.child(0,0).isValid())  // this is a node
       
    98     {
       
    99 		if(index.parent().isValid())
       
   100 		{
       
   101 			return;
       
   102 		}
       
   103 		
       
   104 		if(mListAll->isExpanded(index))
       
   105 		{
       
   106 			mExpandCount++;
       
   107 		}
       
   108 		else
       
   109 		{
       
   110 			mExpandCount--;
       
   111 		}
       
   112 		updateExpandCollapseAction(mExpandCount == 0);
       
   113         return;
       
   114     }
       
   115 
       
   116 	QString uid = mListAll->model()->data(index, UidRole).toString();
       
   117     QString href = mListAll->model()->data(index, HrefRole).toString();
       
   118     HelpDataProvider::instance()->setHelpContentUrl(uid, href);
       
   119     emit activateView(HelpViewContents);
       
   120 }
       
   121 
       
   122 ////////////////////////////////////////////////////////////////////////////////////////////
       
   123 // handle menu event
       
   124 void HelpCategoryView::onExpandOrCollapseAll()
       
   125 {
       
   126 	bool needExpand = (mExpandCount == 0);
       
   127 	QStandardItemModel* model = (QStandardItemModel*)(mListAll->model());
       
   128 	expandCollapseAllList(model->invisibleRootItem(),needExpand);
       
   129 	mExpandCount = needExpand ?  model->invisibleRootItem()->rowCount() : 0;
       
   130 	updateExpandCollapseAction(mExpandCount == 0);
       
   131 }
       
   132 
       
   133 // end of file