1 /* |
|
2 * Copyright (c) 2010 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 #include "usbsettingsapp.h" |
|
18 #include <hblistviewitem.h> |
|
19 #include <QItemSelectionModel> |
|
20 #include <hbstyleloader.h> |
|
21 #include <hbdocumentloader.h> |
|
22 #include <hbview.h> |
|
23 #include <hblistview.h> |
|
24 #include <hbgroupbox.h> |
|
25 #include "usbuisettingmodel.h" |
|
26 #include "usbdebug.h" |
|
27 |
|
28 #define DOCML ":/xml/usbsettingsapp.docml" |
|
29 |
|
30 USBSettingsApp::USBSettingsApp(QWidget *parent) |
|
31 : HbMainWindow(parent), mView(NULL), mListViewItem(NULL) |
|
32 { |
|
33 myDebug() << ">>> USBSettingsApp::USBSettingsApp"; |
|
34 //Init the document loader and we load the view |
|
35 mModel = new UsbUiSettingModel(this); |
|
36 mSelectionModel = new QItemSelectionModel(mModel); |
|
37 mDocumentLoader = new HbDocumentLoader(); |
|
38 connect(this, SIGNAL(orientationChanged(Qt::Orientation)), |
|
39 this,SLOT(setOrientation(Qt::Orientation))); |
|
40 load(orientation()); |
|
41 myDebug() << "<<< USBSettingsApp::USBSettingsApp"; |
|
42 } |
|
43 |
|
44 USBSettingsApp::~USBSettingsApp() |
|
45 { |
|
46 myDebug() << ">>> USBSettingsApp::~USBSettingsApp"; |
|
47 delete mView; |
|
48 delete mModel; |
|
49 delete mDocumentLoader; |
|
50 myDebug() << "<<< USBSettingsApp::~USBSettingsApp"; |
|
51 } |
|
52 /*! |
|
53 loads the DOCML and build the view by finding the widgets from it |
|
54 */ |
|
55 void USBSettingsApp::load(Qt::Orientation orientation) |
|
56 { |
|
57 myDebug() << ">>> USBSettingsApp::load"; |
|
58 bool loaded = true; |
|
59 |
|
60 //Sets loader to initial state |
|
61 mDocumentLoader->reset(); |
|
62 //Load the common section |
|
63 mDocumentLoader->load(DOCML, &loaded); |
|
64 |
|
65 //Loads the view |
|
66 if ( loaded ) { |
|
67 myDebug() << " USBSettingsApp::load DOCML loaded"; |
|
68 QGraphicsWidget *widget = mDocumentLoader->findWidget(QString("view")); |
|
69 if (widget) { |
|
70 myDebug() << " USBSettingsApp::load view found"; |
|
71 mView = qobject_cast<HbView*>(widget); |
|
72 this->addView(mView); |
|
73 this->setCurrentView(mView); |
|
74 } |
|
75 QGraphicsWidget *listViewWidget = mDocumentLoader->findWidget(QString("listView")); |
|
76 if (listViewWidget) { |
|
77 myDebug() << " USBSettingsApp::load listView found"; |
|
78 HbListView *listView = qobject_cast<HbListView*>(listViewWidget); |
|
79 listView->setItemPixmapCacheEnabled(true); |
|
80 listView->setModel(mModel); |
|
81 listView->setSelectionMode(HbAbstractItemView::SingleSelection); |
|
82 listView->setSelectionModel(mSelectionModel); |
|
83 mModel -> setSelectionModel(mSelectionModel); |
|
84 HbStyleLoader::registerFilePath(":/"); |
|
85 listView->setLayoutName("usb"); |
|
86 //scroll to the selected index, if not hidden personality |
|
87 QModelIndexList indexList = mSelectionModel->selectedIndexes(); |
|
88 if ( !indexList.isEmpty() ) { |
|
89 myDebug() << " USBSettingsApp::load scrollTo " << indexList[0].row(); |
|
90 myDebug() << " USBSettingsApp::load scrollTo disabled"; |
|
91 //listView->scrollTo(indexList[0]); |
|
92 } |
|
93 } |
|
94 |
|
95 QGraphicsWidget *listViewItemWidget = mDocumentLoader->findWidget(QString("listItemPrototype")); |
|
96 if (listViewItemWidget) { |
|
97 myDebug() << " USBSettingsApp::load mListViewItem found"; |
|
98 mListViewItem = qobject_cast<HbListViewItem*>(listViewItemWidget); |
|
99 mListViewItem->setGraphicsSize(HbListViewItem::LargeIcon); |
|
100 setOrientation(orientation); |
|
101 } |
|
102 |
|
103 QGraphicsWidget *groupBoxWidget = mDocumentLoader->findWidget(QString("groupBox")); |
|
104 if (groupBoxWidget) { |
|
105 myDebug() << " USBSettingsApp::load groupBox found"; |
|
106 HbGroupBox *groupBox = qobject_cast<HbGroupBox*>(groupBoxWidget); |
|
107 groupBox->setHeading(QString(hbTrId("txt_usb_subhead_select_connection_type"))); |
|
108 } |
|
109 } |
|
110 myDebug() << "<<< USBSettingsApp::load"; |
|
111 } |
|
112 /*! |
|
113 Handles the orientation change |
|
114 */ |
|
115 void USBSettingsApp::setOrientation(Qt::Orientation orientation) |
|
116 { |
|
117 myDebug() << ">>> USBSettingsApp::setOrientation"; |
|
118 if (mListViewItem) { |
|
119 switch (orientation) { |
|
120 case Qt::Horizontal: |
|
121 mListViewItem->setSecondaryTextRowCount(KUSBLandscapeMinLine, KUSBLandscapeMaxLine); |
|
122 break; |
|
123 case Qt::Vertical: |
|
124 mListViewItem->setSecondaryTextRowCount(KUSBPortrateMinLine, KUSBPortrateMaxLine); |
|
125 break; |
|
126 default: |
|
127 break; |
|
128 } |
|
129 } |
|
130 myDebug() << "<<< USBSettingsApp::setOrientation"; |
|
131 } |
|
132 |
|