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