|
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 #include "usbmainview.h" |
|
18 #include <QModelIndex> |
|
19 #include <QtGui/QGraphicsLinearLayout> |
|
20 #include <hblistwidget.h> |
|
21 #include <hblistwidgetitem.h> |
|
22 #include <hbradiobuttonlist.h> |
|
23 #include <hbtextedit.h> |
|
24 |
|
25 #include "usbuisettingmodel.h" |
|
26 #include "mydebug.h" |
|
27 /*! |
|
28 * default constructor |
|
29 */ |
|
30 UsbMainView::UsbMainView( QObject *parent ) |
|
31 : HbView(), mModel(NULL) |
|
32 { |
|
33 myDebug() << ">>> UsbMainView::UsbMainView"; |
|
34 setParent( parent ); |
|
35 setTitle( qtTrId("USB") ); |
|
36 mMainLayout = new QGraphicsLinearLayout( Qt::Vertical, this ); |
|
37 mModel = new UsbUiSettingModel(); |
|
38 createMainView(); |
|
39 setLayout( mMainLayout ); |
|
40 myDebug() << "<<< UsbMainView::UsbMainView"; |
|
41 } |
|
42 |
|
43 /*! |
|
44 * creates the main view |
|
45 */ |
|
46 void UsbMainView::createMainView() |
|
47 { |
|
48 myDebug() << ">>> UsbMainView::createMainView"; |
|
49 QGraphicsLinearLayout *mainViewLayout = new QGraphicsLinearLayout( Qt::Vertical, mMainLayout ); |
|
50 mListItem = NULL; |
|
51 mlist = NULL; |
|
52 mlabel = NULL; |
|
53 mradio = NULL; |
|
54 mIcon = NULL; |
|
55 createIconNameRow( mainViewLayout ); |
|
56 createDescriptionArea( mainViewLayout ); |
|
57 createRadioButtonArea( mainViewLayout ); |
|
58 mMainLayout->addItem( mainViewLayout ); |
|
59 bool connected = connect( mModel, SIGNAL( dataChanged( QModelIndex, QModelIndex ) ), |
|
60 this, SLOT( updateSettingItems( QModelIndex, QModelIndex ) ) ); |
|
61 myDebug() << "<<< UsbMainView::createMainView model connected=" << connected; |
|
62 connected = connect(mradio, SIGNAL( itemSelected( int ) ), |
|
63 this, SLOT( setPersonality( int ) ) ); |
|
64 myDebug() << "<<< UsbMainView::createMainView mradio connected=" << connected; |
|
65 myDebug() << "<<< UsbMainView::createMainView"; |
|
66 } |
|
67 /*! |
|
68 * creating the creates the first row in the view containing an icon and a mode name |
|
69 */ |
|
70 void UsbMainView::createIconNameRow( QGraphicsLinearLayout *aLocalPropertiesGroup ) |
|
71 { |
|
72 myDebug() << ">>> UsbMainView::createIconNameRow"; |
|
73 QGraphicsLinearLayout *listLayout = new QGraphicsLinearLayout( Qt::Vertical, mMainLayout ); |
|
74 mlist = new HbListWidget( this ); |
|
75 mlist->setMaximumSize( 300, 50 ); //todo |
|
76 mListItem= new HbListWidgetItem(); |
|
77 QModelIndex index = mModel->index( UsbUiSettingModel::DefaultMode, KDefaultColumn ); |
|
78 // QVariant iconName = mModel->data( index, Qt::DecorationRole ); |
|
79 mIcon = new HbIcon( mModel->data( index, Qt::DecorationRole ).toString() ); |
|
80 mListItem->setDecorationIcon( *mIcon ); |
|
81 mListItem->setText( mModel->data( index,Qt::DisplayRole ).toString() ); |
|
82 mListItem->setText( mModel->data( index,Qt::DisplayRole ).toString() ); |
|
83 mlist->insertItem( 1, mListItem ); |
|
84 listLayout->addItem( mlist ); |
|
85 aLocalPropertiesGroup->addItem( listLayout ); |
|
86 myDebug() << "<<< UsbMainView::createIconNameRow"; |
|
87 } |
|
88 /*! |
|
89 * creates the second row from the view containing the description of the selected mode |
|
90 */ |
|
91 void UsbMainView::createDescriptionArea( QGraphicsLinearLayout *aLocalPropertiesGroup ) |
|
92 { |
|
93 myDebug() << ">>> UsbMainView::createDescriptionArea"; |
|
94 QGraphicsLinearLayout *desLayout = new QGraphicsLinearLayout( Qt::Vertical, mMainLayout ); |
|
95 QModelIndex index = mModel->index( UsbUiSettingModel::Description, KDefaultColumn ); |
|
96 mlabel = new HbTextEdit( mModel->data( index, Qt::DisplayRole ).toString() ); |
|
97 mlabel->setReadOnly( true ); |
|
98 mlabel->setCursorVisibility( Hb::TextCursorHidden ); |
|
99 desLayout->addItem( mlabel ); |
|
100 desLayout->setAlignment( mlabel, Qt::AlignTop ); |
|
101 aLocalPropertiesGroup->addItem( desLayout ); |
|
102 myDebug() << "<<< UsbMainView::createDescriptionArea"; |
|
103 } |
|
104 |
|
105 /*! |
|
106 * creates the third row from the view containing the radio button list of the existing usb modes |
|
107 */ |
|
108 void UsbMainView::createRadioButtonArea(QGraphicsLinearLayout *aLocalPropertiesGroup) |
|
109 { |
|
110 myDebug() << ">>> UsbMainView::createRadioButtonArea"; |
|
111 QGraphicsLinearLayout *radioLayout = new QGraphicsLinearLayout( Qt::Vertical, mMainLayout ); |
|
112 QModelIndex index = mModel->index( UsbUiSettingModel::UsbModeList, KDefaultColumn ); |
|
113 QStringList radioList = mModel->data( index, UsbUiSettingModel::SettingsModeNameList ).toStringList(); |
|
114 int selectedIndex = mModel->data( index, Qt::EditRole ).toInt(); |
|
115 mradio = new HbRadioButtonList( radioList, selectedIndex ); |
|
116 radioLayout->addItem( mradio ); |
|
117 radioLayout->setAlignment( mradio, Qt::AlignBottom ); |
|
118 aLocalPropertiesGroup->addItem(radioLayout); |
|
119 myDebug() << "<<< UsbMainView::createRadioButtonArea"; |
|
120 } |
|
121 |
|
122 /*! |
|
123 Slot for receiving notification of data changes from the model. |
|
124 Identify the setting changed and update the corresponding UI item. |
|
125 */ |
|
126 void UsbMainView::updateSettingItems(const QModelIndex &topLeft, const QModelIndex &bottomRight) |
|
127 { |
|
128 myDebug() << ">>> UsbMainView::updateSettingItems"; |
|
129 // update only the part of the view specified by the model row(s) |
|
130 for ( int row = topLeft.row(); row <= bottomRight.row(); row++ ) { |
|
131 myDebug() << " UsbMainView::updateSettingItems row=" << row; |
|
132 QModelIndex index = mModel->index( row, KDefaultColumn ); |
|
133 // Distinguish which setting value is changed. |
|
134 switch ( row ) { |
|
135 case UsbUiSettingModel::DefaultMode : |
|
136 // set the selected personality icon and name |
|
137 mIcon->setIconName( mModel->data( index, Qt::DecorationRole ).toString() ); |
|
138 mListItem->setDecorationIcon( *mIcon ); |
|
139 mListItem->setText( mModel->data( index,Qt::DisplayRole ).toString() ); |
|
140 break; |
|
141 case UsbUiSettingModel::Description : |
|
142 // set the description of the selected personality. |
|
143 mlabel->setPlainText( mModel->data( index, Qt::DisplayRole ).toString() ); |
|
144 mlabel->setReadOnly( true ); |
|
145 mlabel->setCursorVisibility( Hb::TextCursorHidden ); |
|
146 break; |
|
147 case UsbUiSettingModel::UsbModeList : |
|
148 // only the selection can change, no changes in the list of personalities |
|
149 mradio->setSelected( mModel->data( index, Qt::EditRole ).toInt() ); |
|
150 break; |
|
151 default : |
|
152 myDebug() << " UsbMainView::updateSettingItems unknown row " << row; |
|
153 break; |
|
154 } |
|
155 } |
|
156 myDebug() << "<<< UsbMainView::updateSettingItems"; |
|
157 } |
|
158 |
|
159 /* |
|
160 * Slot for receiving notification from the change in radio button list |
|
161 */ |
|
162 void UsbMainView::setPersonality( int personalityIndex ) |
|
163 { |
|
164 myDebug() << ">>> UsbMainView::setPersonality"; |
|
165 QModelIndex index = mModel->index( UsbUiSettingModel::UsbModeList, KDefaultColumn ); |
|
166 mModel->setData( index, personalityIndex, Qt::EditRole ); |
|
167 myDebug() << "<<< UsbMainView::setPersonality"; |
|
168 } |
|
169 |
|
170 /*! |
|
171 * Destructor |
|
172 * destructs the items which are not owned by this class |
|
173 */ |
|
174 UsbMainView::~UsbMainView() |
|
175 { |
|
176 myDebug() << ">>> UsbMainView::~UsbMainView"; |
|
177 delete mModel; |
|
178 delete mIcon; |
|
179 myDebug() << "<<< UsbMainView::~UsbMainView"; |
|
180 } |