59 insertPolicy ( HbComboBox::InsertAtBottom ), |
59 insertPolicy ( HbComboBox::InsertAtBottom ), |
60 mBackgroundItem ( 0 ), |
60 mBackgroundItem ( 0 ), |
61 mButtonTouchAreaItem ( 0 ), |
61 mButtonTouchAreaItem ( 0 ), |
62 mIsDown ( false ), |
62 mIsDown ( false ), |
63 mEditable ( false ), |
63 mEditable ( false ), |
64 mIsDorpdownCreated(false), |
64 mIsDorpdownCreated( false ), |
65 mIsDropwnToSceneAdded(false), |
65 mIsDropwnToSceneAdded( false ), |
66 mHasDownEffect ( false ), |
66 mHasDownEffect ( false ), |
67 mHasUpEffect (false ), |
67 mHasUpEffect ( false ), |
68 mListItemHeight( -1 ), |
68 mListItemHeight( -1 ), |
69 mDropDownRowsInPortrait( -1 ), |
69 mDropDownRowsInPortrait( -1 ), |
70 mDropDownRowsInLandscape( -1 ) |
70 mDropDownRowsInLandscape( -1 ) |
71 { |
71 { |
72 } |
72 } |
73 |
73 |
74 HbComboBoxPrivate::~HbComboBoxPrivate( ) |
74 HbComboBoxPrivate::~HbComboBoxPrivate( ) |
75 { |
75 { |
76 Q_Q(HbComboBox); |
76 Q_Q( HbComboBox ); |
77 if( mButtonTouchAreaItem ) { |
77 if( mButtonTouchAreaItem ) { |
78 static_cast<HbTouchArea*>( mButtonTouchAreaItem )->removeEventFilter( q ); |
78 static_cast<HbTouchArea*>( mButtonTouchAreaItem )->removeEventFilter( q ); |
79 } |
79 } |
80 if ( !q->scene() || !q->scene( )->property( "destructed" ).isValid( ) ) { |
80 if ( !q->scene( ) || !q->scene( )->property( "destructed" ).isValid( ) ) { |
81 if( mDropDown ) { |
81 if( mDropDown ) { |
82 delete mDropDown; |
82 delete mDropDown; |
83 mDropDown = 0; |
83 mDropDown = 0; |
84 } |
84 } |
85 } |
85 } |
101 HbStyle::setItemName( mBackgroundItem, "text_background" ); |
101 HbStyle::setItemName( mBackgroundItem, "text_background" ); |
102 |
102 |
103 mButton = q->style( )->createPrimitive( HbStyle::P_ComboBox_button, q ); |
103 mButton = q->style( )->createPrimitive( HbStyle::P_ComboBox_button, q ); |
104 HbStyle::setItemName( mButton, "combobox_button" ); |
104 HbStyle::setItemName( mButton, "combobox_button" ); |
105 |
105 |
106 mButtonTouchAreaItem = q->style( )->createPrimitive( |
106 mButtonTouchAreaItem = q->style( )->createPrimitive( HbStyle::P_ComboBoxButton_toucharea, q ); |
107 HbStyle::P_ComboBoxButton_toucharea, q ); |
107 static_cast<HbTouchArea*>( mButtonTouchAreaItem )->installEventFilter( q ); |
108 static_cast<HbTouchArea*>(mButtonTouchAreaItem)->installEventFilter( q ); |
108 q->setHandlesChildEvents( true ); |
109 q->setHandlesChildEvents(true); |
109 |
110 |
110 static_cast<HbTouchArea*>( mButtonTouchAreaItem )->grabGesture( Qt::TapGesture ); |
111 static_cast<HbTouchArea*>(mButtonTouchAreaItem)->grabGesture( Qt::TapGesture ); |
|
112 } |
111 } |
113 |
112 |
114 void HbComboBoxPrivate::touchAreaPressEvent( ) |
113 void HbComboBoxPrivate::touchAreaPressEvent( ) |
115 { |
114 { |
116 Q_Q( HbComboBox ); |
115 Q_Q( HbComboBox ); |
117 if (q->count() > 0) { |
116 if ( q->count( ) > 0 ) { |
118 HbWidgetFeedback::triggered( q, Hb::InstantPressed ); |
117 HbWidgetFeedback::triggered( q, Hb::InstantPressed ); |
119 } |
118 } |
120 mIsDown = true; |
119 mIsDown = true; |
121 q->updatePrimitives( ); |
120 q->updatePrimitives( ); |
122 q->setProperty( "state", "pressed" ); |
121 q->setProperty( "state", "pressed" ); |
123 } |
122 } |
124 |
123 |
125 void HbComboBoxPrivate::touchAreaReleaseEvent( ) |
124 void HbComboBoxPrivate::touchAreaReleaseEvent( ) |
126 { |
125 { |
127 Q_Q( HbComboBox ); |
126 Q_Q( HbComboBox ); |
128 mIsDown = false; |
127 mIsDown = false; |
129 touchAreaClicked( ); |
128 touchAreaClicked( ); |
130 q->updatePrimitives( ); |
129 q->updatePrimitives( ); |
131 if ( q->count() > 0 ) { |
130 if ( q->count( ) > 0 ) { |
132 HbWidgetFeedback::triggered( q, Hb::InstantReleased ); |
131 HbWidgetFeedback::triggered( q, Hb::InstantReleased ); |
133 } |
132 } |
134 |
133 |
135 q->setProperty( "state", "normal" ); |
134 q->setProperty( "state", "normal" ); |
136 } |
135 } |
156 } else { |
155 } else { |
157 if( mDropDown->mList->model( ) != mModel ) { |
156 if( mDropDown->mList->model( ) != mModel ) { |
158 mDropDown->mList->setModel( mModel ); |
157 mDropDown->mList->setModel( mModel ); |
159 } |
158 } |
160 mDropDown->mList->scrollTo( mModel->index( 0, 0 ) ); |
159 mDropDown->mList->scrollTo( mModel->index( 0, 0 ) ); |
161 mDropDown->mList->setCurrentIndex( mModel->index( 0, 0 ), QItemSelectionModel::Select ); |
160 mDropDown->mList->setCurrentIndex( |
|
161 mModel->index( 0, 0 ), QItemSelectionModel::Select ); |
162 } |
162 } |
163 #ifdef HB_EFFECTS |
163 #ifdef HB_EFFECTS |
164 HbEffect::start( mDropDown, HB_DROPD0WN_ITEM_TYPE, "appear" ); |
164 HbEffect::start( mDropDown, HB_DROPD0WN_ITEM_TYPE, "appear" ); |
165 #endif |
165 #endif |
166 positionDropDown( ); |
166 positionDropDown( ); |
167 } |
167 } |
168 } |
168 } |
169 |
169 |
170 void HbComboBoxPrivate::vkbOpened( ) |
170 void HbComboBoxPrivate::vkbOpened( ) |
171 { |
171 { |
172 |
172 |
173 } |
173 } |
174 |
174 |
175 void HbComboBoxPrivate::vkbClosed() |
175 void HbComboBoxPrivate::vkbClosed( ) |
176 { |
176 { |
177 if( mDropDown->isVisible( ) ) { |
177 if( mDropDown->isVisible( ) ) { |
178 positionDropDown( ); |
178 positionDropDown( ); |
179 } |
179 } |
180 } |
180 } |
181 |
181 |
182 void HbComboBoxPrivate::showPopup( QAbstractItemModel *aModel, QModelIndex aIndex ) |
182 void HbComboBoxPrivate::showPopup( QAbstractItemModel *aModel, QModelIndex aIndex ) |
183 { |
183 { |
184 Q_UNUSED( aModel ); |
|
185 Q_UNUSED( aIndex ); |
|
186 Q_Q( HbComboBox ); |
184 Q_Q( HbComboBox ); |
187 if ( aModel && aModel->rowCount( ) ) { |
185 if ( aModel && aModel->rowCount( ) ) { |
188 addDropDownToScene(); |
186 addDropDownToScene( ); |
189 if( !mDropDown->mList ) { |
187 if( !mDropDown->mList ) { |
190 mDropDown->createList(); |
188 mDropDown->createList( ); |
191 q->connect( mDropDown->mList, SIGNAL( activated( QModelIndex ) ), q, |
189 q->connect( mDropDown->mList, SIGNAL( activated( QModelIndex ) ), q, |
192 SLOT( _q_textChanged( QModelIndex ) ) ); |
190 SLOT( _q_textChanged( QModelIndex ) ) ); |
193 |
|
194 } |
191 } |
195 mDropDown->mList->setModel( aModel ); |
192 mDropDown->mList->setModel( aModel ); |
196 if ( aIndex.isValid( ) ) { |
193 if ( aIndex.isValid( ) ) { |
197 mDropDown->mList->scrollTo( aIndex, HbAbstractItemView::PositionAtTop ); |
194 mDropDown->mList->scrollTo( aIndex, HbAbstractItemView::PositionAtTop ); |
198 mDropDown->mList->setCurrentIndex( mCurrentIndex, QItemSelectionModel::Select ); |
195 mDropDown->mList->setCurrentIndex( mCurrentIndex, QItemSelectionModel::Select ); |
202 positionDropDown( ); |
199 positionDropDown( ); |
203 mDropDown->setVisible( true ); |
200 mDropDown->setVisible( true ); |
204 } |
201 } |
205 } |
202 } |
206 |
203 |
207 void HbComboBoxPrivate::createDropDown() |
204 void HbComboBoxPrivate::createDropDown( ) |
208 { |
205 { |
209 if( !mIsDorpdownCreated ) { |
206 if( !mIsDorpdownCreated ) { |
210 mDropDown = new HbComboDropDown( this ); |
207 mDropDown = new HbComboDropDown( this ); |
211 mIsDorpdownCreated = true; |
208 mIsDorpdownCreated = true; |
212 mDropDown->setVisible(false); |
209 mDropDown->setVisible( false ); |
213 } |
210 } |
214 } |
211 } |
215 |
212 |
216 void HbComboBoxPrivate::calculateListItemHeight() |
213 void HbComboBoxPrivate::calculateListItemHeight( ) |
217 { |
214 { |
218 QAbstractItemModel *model = mDropDown->mList->model( ); |
215 QAbstractItemModel *model = mDropDown->mList->model( ); |
219 if( mCurrentIndex.isValid( ) && mDropDown->mList->itemByIndex( mCurrentIndex ) ) { |
216 if( mCurrentIndex.isValid( ) && mDropDown->mList->itemByIndex( mCurrentIndex ) ) { |
220 mListItemHeight = mDropDown->mList->itemByIndex( mCurrentIndex )->geometry( ).height( ); |
217 mListItemHeight = mDropDown->mList->itemByIndex( mCurrentIndex )->geometry( ).height( ); |
221 } else if( model->index( 0, 0 ).isValid() && mDropDown->mList->itemByIndex( model->index( 0, 0 ) ) ) { |
218 } else if( model->index( 0, 0 ).isValid( ) && |
222 mListItemHeight = mDropDown->mList->itemByIndex( model->index( 0, 0 ) )->geometry( ).height( ); |
219 mDropDown->mList->itemByIndex( model->index( 0, 0 ) ) ) { |
|
220 |
|
221 mListItemHeight = |
|
222 mDropDown->mList->itemByIndex( model->index( 0, 0 ) )->geometry( ).height( ); |
223 } else { |
223 } else { |
224 HbListViewItem *proto = mDropDown->mList->listItemPrototype( ); |
224 HbListViewItem *proto = mDropDown->mList->listItemPrototype( ); |
225 HbListViewItem *temp = static_cast<HbListViewItem*>( proto->createItem( ) ); |
225 HbListViewItem *temp = static_cast<HbListViewItem*>( proto->createItem( ) ); |
226 mListItemHeight = temp->effectiveSizeHint( Qt::PreferredSize ).height( ); |
226 mListItemHeight = temp->effectiveSizeHint( Qt::PreferredSize ).height( ); |
227 delete temp; |
227 delete temp; |
236 QRectF sceneRect( QPointF( ), HbDeviceProfile::profile( q ).logicalSize( ) ); |
236 QRectF sceneRect( QPointF( ), HbDeviceProfile::profile( q ).logicalSize( ) ); |
237 QPointF widgetPos = q->scenePos( ); |
237 QPointF widgetPos = q->scenePos( ); |
238 QAbstractItemModel *model = mDropDown->mList->model( ); |
238 QAbstractItemModel *model = mDropDown->mList->model( ); |
239 calculateListItemHeight( ); |
239 calculateListItemHeight( ); |
240 qreal totalHeightRequd = model->rowCount( ) * mListItemHeight; |
240 qreal totalHeightRequd = model->rowCount( ) * mListItemHeight; |
241 |
|
242 qreal maxPopupHeight = 0.0; |
241 qreal maxPopupHeight = 0.0; |
|
242 |
243 //read the maximum rows in drop down for different orientation from css |
243 //read the maximum rows in drop down for different orientation from css |
244 if( q->mainWindow( )->orientation( ) == Qt::Horizontal ){ |
244 if( q->mainWindow( )->orientation( ) == Qt::Horizontal ) { |
245 if( mDropDownRowsInLandscape == -1 ) { |
245 if( mDropDownRowsInLandscape == -1 ) { |
246 HbStyleParameters params; |
246 HbStyleParameters params; |
247 q->style( )->parameters( params ); |
247 q->style( )->parameters( params ); |
248 params.addParameter( "max-rows-in-dropdown" ); |
248 params.addParameter( "max-rows-in-dropdown" ); |
249 q->polish( params ); |
249 q->polish( params ); |
250 mDropDownRowsInLandscape = params.value( "max-rows-in-dropdown" ).toInt( ); |
250 mDropDownRowsInLandscape = params.value( "max-rows-in-dropdown" ).toInt( ); |
251 } |
251 } |
252 maxPopupHeight = mDropDownRowsInLandscape * mListItemHeight; |
252 maxPopupHeight = mDropDownRowsInLandscape * mListItemHeight; |
253 } else if( q->mainWindow( )->orientation( ) == Qt::Vertical ){ |
253 } else if( q->mainWindow( )->orientation( ) == Qt::Vertical ) { |
254 if( mDropDownRowsInPortrait == -1 ) { |
254 if( mDropDownRowsInPortrait == -1 ) { |
255 HbStyleParameters params; |
255 HbStyleParameters params; |
256 q->style( )->parameters(params); |
256 q->style( )->parameters( params ); |
257 params.addParameter( "max-rows-in-dropdown" ); |
257 params.addParameter( "max-rows-in-dropdown" ); |
258 q->polish( params ); |
258 q->polish( params ); |
259 mDropDownRowsInPortrait = params.value("max-rows-in-dropdown").toInt(); |
259 mDropDownRowsInPortrait = params.value( "max-rows-in-dropdown" ).toInt( ); |
260 } |
260 } |
261 maxPopupHeight = mDropDownRowsInPortrait * mListItemHeight; |
261 maxPopupHeight = mDropDownRowsInPortrait * mListItemHeight; |
262 } |
262 } |
263 |
263 |
264 if ( totalHeightRequd < maxPopupHeight ) { |
264 if ( totalHeightRequd < maxPopupHeight ) { |
265 maxPopupHeight = totalHeightRequd; |
265 maxPopupHeight = totalHeightRequd; |
266 } |
266 } |
267 QSizeF popupSize = QSizeF( q->rect( ).width( ), maxPopupHeight ); |
267 QSizeF popupSize = QSizeF( q->rect( ).width( ), maxPopupHeight ); |
268 QPointF popupPos; |
268 QPointF popupPos; |
269 if( !mDropDown->vkbOpened ) { |
269 if( !mDropDown->vkbOpened ) { |
270 //position of drop down in both editable and non-editable combobox depends upon |
270 //position of drop down in both editable and non-editable combobox depends upon |
271 //the available space above and below combobox |
271 //the available space above and below combobox |
272 if( (widgetPos.y( ) + q->rect( ).height( ) + maxPopupHeight) < sceneRect.height( ) ) { |
272 if( ( widgetPos.y( ) + q->rect( ).height( ) + maxPopupHeight) < sceneRect.height( ) ) { |
273 popupPos = QPointF( widgetPos.x(), widgetPos.y( ) + q->rect( ).height( ) ); |
273 popupPos = QPointF( widgetPos.x( ), widgetPos.y( ) + q->rect( ).height( ) ); |
274 #ifdef HB_EFFECTS |
274 #ifdef HB_EFFECTS |
275 if ( !mHasDownEffect ) { |
275 if ( !mHasDownEffect ) { |
276 mHasDownEffect = true; |
276 mHasDownEffect = true; |
277 mHasUpEffect = false; |
277 mHasUpEffect = false; |
278 // this is temporary until proper effect theming comes. |
278 // this is temporary until proper effect theming comes. |
279 //this Effect will be shown when there is space in the view bottom. |
279 //this Effect will be shown when there is space in the view bottom. |
280 HbEffectInternal::add( mDropDown, "combo_appear_down", "appear" ); |
280 HbEffectInternal::add( mDropDown, "combo_appear_down", "appear" ); |
281 HbEffectInternal::add( mDropDown, "combo_disappear_downl", "disappear" ); |
281 HbEffectInternal::add( mDropDown, "combo_disappear_downl", "disappear" ); |
282 } |
282 } |
283 #endif |
283 #endif |
284 } else if( widgetPos.y( ) - maxPopupHeight > 0.0 ) { |
284 } else if( widgetPos.y( ) - maxPopupHeight > 0.0 ) { |
285 popupPos = QPointF( widgetPos.x( ), widgetPos.y( ) - maxPopupHeight ); |
285 popupPos = QPointF( widgetPos.x( ), widgetPos.y( ) - maxPopupHeight ); |
286 #ifdef HB_EFFECTS |
286 #ifdef HB_EFFECTS |
287 if ( !mHasUpEffect ) { |
287 if ( !mHasUpEffect ) { |
288 // this is temporary until proper effect theming comes. |
288 // this is temporary until proper effect theming comes. |
289 //this Effect will be shown when there is no space in the view bottom |
289 //this Effect will be shown when there is no space in the view bottom |
290 mHasUpEffect = true; |
290 mHasUpEffect = true; |
291 mHasDownEffect = false; |
291 mHasDownEffect = false; |
292 HbEffectInternal::add( mDropDown, "combo_appear_up", "appear" ); |
292 HbEffectInternal::add( mDropDown, "combo_appear_up", "appear" ); |
293 HbEffectInternal::add( mDropDown, "combo_disappear_up", "disappear" ); |
293 HbEffectInternal::add( mDropDown, "combo_disappear_up", "disappear" ); |
294 } |
294 } |
295 #endif |
295 #endif |
296 } else { |
296 } else { |
297 qreal topScreenHeight = sceneRect.height( ) - maxPopupHeight; |
297 qreal topScreenHeight = sceneRect.height( ) - maxPopupHeight; |
298 if( topScreenHeight > sceneRect.height( ) - topScreenHeight ) { |
298 if( topScreenHeight > sceneRect.height( ) - topScreenHeight ) { |
299 popupPos = QPointF( widgetPos.x( ), 0.0 ); |
299 popupPos = QPointF( widgetPos.x( ), 0.0 ); |
300 #ifdef HB_EFFECTS |
300 #ifdef HB_EFFECTS |
301 if ( !mHasDownEffect ) { |
301 if ( !mHasDownEffect ) { |
302 mHasDownEffect = true; |
302 mHasDownEffect = true; |
303 mHasUpEffect = false; |
303 mHasUpEffect = false; |
304 // this is temporary until proper effect theming comes. |
304 // this is temporary until proper effect theming comes. |
305 //this Effect will be shown when there is more space in the view bottom. |
305 //this Effect will be shown when there is more space in the view bottom. |
306 HbEffectInternal::add( mDropDown, "combo_appear_down", "appear" ); |
306 HbEffectInternal::add( mDropDown, "combo_appear_down", "appear" ); |
307 HbEffectInternal::add( mDropDown, "combo_disappear_down", "disappear" ); |
307 HbEffectInternal::add( mDropDown, "combo_disappear_down", "disappear" ); |
308 } |
308 } |
309 #endif |
309 #endif |
310 } else { |
310 } else { |
311 popupPos = QPointF( widgetPos.x( ), sceneRect.height( ) - maxPopupHeight ); |
311 popupPos = QPointF( widgetPos.x( ), sceneRect.height( ) - maxPopupHeight ); |
312 #ifdef HB_EFFECTS |
312 #ifdef HB_EFFECTS |
313 if ( !mHasUpEffect ) { |
313 if ( !mHasUpEffect ) { |
314 mHasUpEffect = true; |
314 mHasUpEffect = true; |
315 mHasDownEffect = false; |
315 mHasDownEffect = false; |
316 // this is temporary until proper effect theming comes. |
316 // this is temporary until proper effect theming comes. |
317 //this Effect will be shown when there is more space in the view bottom. |
317 //this Effect will be shown when there is more space in the view bottom. |
318 HbEffectInternal::add( mDropDown, "combo_appear_up", "appear" ); |
318 HbEffectInternal::add( mDropDown, "combo_appear_up", "appear" ); |
319 HbEffectInternal::add( mDropDown, "combo_disappear_up", "disappear" ); |
319 HbEffectInternal::add( mDropDown, "combo_disappear_up", "disappear" ); |
320 } |
320 } |
321 #endif |
321 #endif |
322 } |
322 } |
323 } |
323 } |
324 } else { |
324 } else { |
325 // positioning drop down when vkb is positioned |
325 // positioning drop down when vkb is positioned |
326 // drop down will come on top/below of combo based upon which side has more space |
326 // drop down will come on top/below of combo based upon which side has more space |
327 // available |
327 // available |
328 |
|
329 HbEditorInterface editorInterface( q ); |
328 HbEditorInterface editorInterface( q ); |
330 HbVkbHost *host = editorInterface.vkbHost( ); |
329 HbVkbHost *host = editorInterface.vkbHost( ); |
331 if ( host ) { |
330 if ( host ) { |
332 QSizeF keyBoardArea = host->keyboardArea( ); |
331 QSizeF keyBoardArea = host->keyboardArea( ); |
333 QSize screenSize = HbDeviceProfile::profile( q ).logicalSize( ); |
332 QSize screenSize = HbDeviceProfile::profile( q ).logicalSize( ); |
334 |
333 |
335 qreal heightDifference = screenSize.height( ) - keyBoardArea.height( ); |
334 qreal heightDifference = screenSize.height( ) - keyBoardArea.height( ); |
336 qreal topSpace = widgetPos.y( ); |
335 qreal topSpace = widgetPos.y( ); |
337 qreal bottomSpace = heightDifference - topSpace - q->boundingRect( ).height( ); |
336 qreal bottomSpace = heightDifference - topSpace - q->boundingRect( ).height( ); |
338 |
337 |
339 if( topSpace > bottomSpace ) { |
338 if( topSpace > bottomSpace ) { |
343 } else { |
342 } else { |
344 popupPos = QPointF( widgetPos.x( ), 0.0 ); |
343 popupPos = QPointF( widgetPos.x( ), 0.0 ); |
345 popupSize.setHeight( topSpace ); |
344 popupSize.setHeight( topSpace ); |
346 } |
345 } |
347 #ifdef HB_EFFECTS |
346 #ifdef HB_EFFECTS |
348 if ( !mHasUpEffect ) { |
347 if ( !mHasUpEffect ) { |
349 mHasUpEffect = true; |
348 mHasUpEffect = true; |
350 mHasDownEffect = false; |
349 mHasDownEffect = false; |
351 // this is temporary until proper effect theming comes. |
350 // this is temporary until proper effect theming comes. |
352 //this Effect will be shown when there is more space in the view bottom. |
351 //this Effect will be shown when there is more space in the view bottom. |
353 HbEffectInternal::add( mDropDown, "combo_appear_up", "appear" ); |
352 HbEffectInternal::add( mDropDown, "combo_appear_up", "appear" ); |
354 HbEffectInternal::add( mDropDown, "combo_disappear_up", "disappear" ); |
353 HbEffectInternal::add( mDropDown, "combo_disappear_up", "disappear" ); |
355 } |
354 } |
356 #endif |
355 #endif |
357 |
|
358 } else { |
356 } else { |
359 //display drop down at bottom |
357 //display drop down at bottom |
360 popupPos = QPointF( widgetPos.x( ), widgetPos.y( ) + q->rect( ).height( ) ); |
358 popupPos = QPointF( widgetPos.x( ), widgetPos.y( ) + q->rect( ).height( ) ); |
361 if( bottomSpace < maxPopupHeight ) { |
359 if( bottomSpace < maxPopupHeight ) { |
362 popupSize.setHeight( bottomSpace ); |
360 popupSize.setHeight( bottomSpace ); |
363 } |
361 } |
364 #ifdef HB_EFFECTS |
362 #ifdef HB_EFFECTS |
365 if ( !mHasDownEffect ) { |
363 if ( !mHasDownEffect ) { |
366 mHasDownEffect = true; |
364 mHasDownEffect = true; |
367 mHasUpEffect = false; |
365 mHasUpEffect = false; |
368 // this is temporary until proper effect theming comes. |
366 // this is temporary until proper effect theming comes. |
369 //this Effect will be shown when there is more space in the view bottom. |
367 //this Effect will be shown when there is more space in the view bottom. |
370 HbEffectInternal::add( mDropDown, "combo_appear_down", "appear" ); |
368 HbEffectInternal::add( mDropDown, "combo_appear_down", "appear" ); |
371 HbEffectInternal::add( mDropDown, "combo_disappear_down", "disappear" ); |
369 HbEffectInternal::add( mDropDown, "combo_disappear_down", "disappear" ); |
372 } |
370 } |
373 #endif |
371 #endif |
374 } |
372 } |
375 } |
373 } |
376 } |
374 } |
377 mDropDown->setPreferredSize( popupSize ); |
375 mDropDown->setPreferredSize( popupSize ); |
378 mDropDown->setMinimumSize( popupSize ); |
376 mDropDown->setMinimumSize( popupSize ); |
379 mDropDown->setMaximumSize( popupSize ); |
377 mDropDown->setMaximumSize( popupSize ); |
380 mDropDown->setPos(popupPos); |
378 mDropDown->setPos( popupPos ); |
381 QGraphicsWidget *p = q; |
379 QGraphicsWidget *p = q; |
382 while ( p->parentWidget( ) ) { |
380 while ( p->parentWidget( ) ) { |
383 p = p->parentWidget( ); |
381 p = p->parentWidget( ); |
384 } |
382 } |
385 mDropDown->setZValue( p->zValue( ) + 1 ); |
383 mDropDown->setZValue( p->zValue( ) + 1 ); |
388 void HbComboBoxPrivate::_q_textChanged( const QModelIndex & aIndex ) |
386 void HbComboBoxPrivate::_q_textChanged( const QModelIndex & aIndex ) |
389 { |
387 { |
390 Q_Q( HbComboBox ); |
388 Q_Q( HbComboBox ); |
391 QVariant data = mDropDown->mList->model( )->data( aIndex ); |
389 QVariant data = mDropDown->mList->model( )->data( aIndex ); |
392 mText = data.toString( ); |
390 mText = data.toString( ); |
393 if( !mEditable ) { |
391 if( !mEditable ) { |
394 if( mLineEdit ) { |
392 if( mLineEdit ) { |
395 mLineEdit->setText( mText ); |
393 mLineEdit->setText( mText ); |
396 } else { |
394 } else { |
397 HbStyleOptionComboBox comboBoxOption; |
395 HbStyleOptionComboBox comboBoxOption; |
398 q->initStyleOption( &comboBoxOption ); |
396 q->initStyleOption( &comboBoxOption ); |
399 q->style( )->updatePrimitive( mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption); |
397 q->style( )->updatePrimitive( mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption ); |
400 } |
398 } |
401 mCurrentIndex = aIndex; |
399 mCurrentIndex = aIndex; |
402 } else { |
400 } else { |
403 q->disconnect( mLineEdit, SIGNAL( textChanged ( QString ) ), q, |
401 q->disconnect( mLineEdit, SIGNAL( textChanged ( QString ) ), q, |
404 SLOT( _q_textChanged( QString ) ) ); |
402 SLOT( _q_textChanged( QString ) ) ); |
405 mLineEdit->setText( mText ); |
403 mLineEdit->setText( mText ); |
406 mCurrentIndex = findData( mText ); |
404 mCurrentIndex = findData( mText ); |
407 q->connect( mLineEdit, SIGNAL( textChanged ( QString ) ), q, |
405 q->connect( mLineEdit, SIGNAL( textChanged ( QString ) ), q, |
408 SLOT( _q_textChanged( QString ) ) ); |
406 SLOT( _q_textChanged( QString ) ) ); |
409 } |
407 } |
410 if ( mDropDown->isVisible( ) ) { |
408 if ( mDropDown->isVisible( ) ) { |
411 mDropDown->setVisible( false ); |
409 mDropDown->setVisible( false ); |
412 } |
410 } |
413 currentIndexChanged( mCurrentIndex ); |
411 currentIndexChanged( mCurrentIndex ); |
414 } |
412 } |
415 |
413 |
416 void HbComboBoxPrivate::_q_textCompleted( const QModelIndex & aIndex ) |
414 void HbComboBoxPrivate::_q_textCompleted( const QModelIndex & aIndex ) |
417 { |
415 { |
418 if( aIndex.isValid( ) ) { |
416 if( aIndex.isValid( ) ) { |
419 showPopup( mCompleter->completionModel( ) ); |
417 showPopup( mCompleter->completionModel( ) ); |
420 } |
418 } |
421 } |
419 } |
422 |
420 |
423 void HbComboBoxPrivate::_q_textChanged( const QString & aString ) |
421 void HbComboBoxPrivate::_q_textChanged( const QString & aString ) |
424 { |
422 { |
425 Q_Q(HbComboBox); |
423 Q_Q( HbComboBox ); |
426 |
424 |
427 if( !aString.isEmpty( ) ) { |
425 if( !aString.isEmpty( ) ) { |
428 if ( mCompleter ) { |
426 if ( mCompleter ) { |
429 mCompleter->setCompletionPrefix( aString ); |
427 mCompleter->setCompletionPrefix( aString ); |
430 mCompleter->complete( ); |
428 mCompleter->complete( ); |
431 if( mCompleter->currentRow() == -1 ) { |
429 if( mCompleter->currentRow( ) == -1 ) { |
432 if (( mDropDown ) && ( mDropDown->isVisible() )) { |
430 if ( ( mDropDown ) && ( mDropDown->isVisible( ) ) ) { |
433 mDropDown->setVisible(false); |
431 mDropDown->setVisible( false ); |
434 } |
432 } |
435 } |
433 } |
436 } |
434 } |
437 } else { |
435 } else { |
438 if( mDropDown ) { |
436 if( mDropDown ) { |
439 mDropDown->setVisible(false); |
437 mDropDown->setVisible( false ); |
440 } |
438 } |
441 //showPopup( mModel, mCurrentIndex); |
439 //showPopup( mModel, mCurrentIndex); |
442 } |
440 } |
443 emit q->editTextChanged( aString ); |
441 emit q->editTextChanged( aString ); |
444 } |
442 } |
575 { |
574 { |
576 Q_Q( HbComboBox ); |
575 Q_Q( HbComboBox ); |
577 bool indexChanged = ( mi != mCurrentIndex ); |
576 bool indexChanged = ( mi != mCurrentIndex ); |
578 if ( indexChanged ) { |
577 if ( indexChanged ) { |
579 mCurrentIndex = QModelIndex( mi ); |
578 mCurrentIndex = QModelIndex( mi ); |
580 mText = q->itemText( mCurrentIndex.row( ) ); |
579 mText = q->itemText( mCurrentIndex.row( ) ); |
581 if( mEditable ) { |
580 if( mEditable ) { |
582 q->disconnect( mLineEdit, SIGNAL( textChanged ( QString ) ), q, |
581 q->disconnect( mLineEdit, SIGNAL( textChanged ( QString ) ), q, |
583 SLOT( _q_textChanged( QString ) ) ); |
582 SLOT( _q_textChanged( QString ) ) ); |
584 mLineEdit->setText( mText ); |
583 mLineEdit->setText( mText ); |
585 q->connect( mLineEdit, SIGNAL( textChanged ( QString ) ), |
584 q->connect( mLineEdit, SIGNAL( textChanged ( QString ) ), |
586 q, SLOT( _q_textChanged( QString ) ) ); |
585 q, SLOT( _q_textChanged( QString ) ) ); |
587 } else { |
586 } else { |
588 if( mLineEdit ) { |
587 if( mLineEdit ) { |
589 mLineEdit->setText( mText ); |
588 mLineEdit->setText( mText ); |
590 } else { |
589 } else { |
591 HbStyleOptionComboBox comboBoxOption; |
590 HbStyleOptionComboBox comboBoxOption; |
592 q->initStyleOption(&comboBoxOption); |
591 q->initStyleOption(&comboBoxOption); |
593 q->style( )->updatePrimitive( mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption ); |
592 q->style( )->updatePrimitive( |
|
593 mTextItem, HbStyle::P_ComboBox_text, &comboBoxOption ); |
594 } |
594 } |
595 } |
595 } |
596 currentIndexChanged( mCurrentIndex ); |
596 currentIndexChanged( mCurrentIndex ); |
597 } |
597 } |
598 } |
598 } |
599 |
599 |
600 void HbComboBoxPrivate::currentIndexChanged( const QModelIndex &index ) |
600 void HbComboBoxPrivate::currentIndexChanged( const QModelIndex &index ) |
601 { |
601 { |
602 Q_Q( HbComboBox ); |
602 Q_Q( HbComboBox ); |
603 emit q->currentIndexChanged( index.row( ) ); |
603 emit q->currentIndexChanged( index.row( ) ); |
604 emit q->currentIndexChanged( q->itemText ( mCurrentIndex.row( ) ) ); |
604 emit q->currentIndexChanged( q->itemText ( mCurrentIndex.row( ) ) ); |
605 } |
605 } |
606 |
606 |
607 /* |
607 /* |
608 Returns the index of the item containing the given \a data for the |
608 Returns the index of the item containing the given \a data for the |