26 #include "hbcombodropdown_p.h" |
26 #include "hbcombodropdown_p.h" |
27 #include "hbcombobox_p.h" |
27 #include "hbcombobox_p.h" |
28 #include "hbwidget_p.h" |
28 #include "hbwidget_p.h" |
29 #include <hblistview.h> |
29 #include <hblistview.h> |
30 #include <hbwidgetfeedback.h> |
30 #include <hbwidgetfeedback.h> |
|
31 #include <hbinputvirtualkeyboard.h> |
31 |
32 |
32 #include <hbtapgesture.h> |
33 #include <hbtapgesture.h> |
33 #include <hbpangesture.h> |
34 #include <hbpangesture.h> |
34 #include <QGestureEvent> |
35 #include <QGestureEvent> |
|
36 #include <QGraphicsSceneMouseEvent> |
|
37 |
|
38 #include <hbeffect.h> |
35 |
39 |
36 class HbComboDropDownPrivate : public HbWidgetPrivate |
40 class HbComboDropDownPrivate : public HbWidgetPrivate |
37 { |
41 { |
38 }; |
42 }; |
39 HbComboDropDown::HbComboDropDown( HbComboBoxPrivate *comboBoxPrivate, QGraphicsItem *parent ) |
43 HbComboDropDown::HbComboDropDown( HbComboBoxPrivate *comboBoxPrivate, QGraphicsItem *parent ) |
42 comboPrivate( comboBoxPrivate ), |
46 comboPrivate( comboBoxPrivate ), |
43 vkbOpened( false ), |
47 vkbOpened( false ), |
44 backgroundPressed( false ) |
48 backgroundPressed( false ) |
45 { |
49 { |
46 Q_D(HbComboDropDown); |
50 Q_D(HbComboDropDown); |
47 d->setBackgroundItem(HbStyle::P_ComboBoxPopup_background); |
51 d->setBackgroundItem(HbStylePrivate::P_ComboBoxPopup_background); |
48 #if QT_VERSION >= 0x040600 |
52 #if QT_VERSION >= 0x040600 |
49 //this is to keep the focus in the previous widget. |
53 //this is to keep the focus in the previous widget. |
50 setFlag( QGraphicsItem::ItemIsPanel, true ); |
54 setFlag( QGraphicsItem::ItemIsPanel, true ); |
51 setActive( false ); |
55 setActive( false ); |
|
56 setAcceptTouchEvents( true ); |
52 #endif |
57 #endif |
53 } |
58 } |
54 |
59 |
55 HbComboDropDown::~HbComboDropDown( ) |
60 HbComboDropDown::~HbComboDropDown( ) |
56 { |
61 { |
57 |
|
58 } |
62 } |
59 |
63 |
60 void HbComboDropDown::createList( ) |
64 void HbComboDropDown::createList( ) |
61 { |
65 { |
62 mList = new HbListView( this ); |
66 mList = new HbListView( this ); |
63 mList->setLongPressEnabled( false ); |
|
64 HbComboListViewItem *protoType = new HbComboListViewItem( this ); |
67 HbComboListViewItem *protoType = new HbComboListViewItem( this ); |
65 mList->setItemPrototype( protoType ); |
68 mList->setItemPrototype( protoType ); |
66 HbStyle::setItemName( mList, "list" ); |
69 HbStyle::setItemName( mList, "list" ); |
67 mList->setUniformItemSizes( true ); |
70 mList->setUniformItemSizes( true ); |
68 mList->setSelectionMode( HbAbstractItemView::SingleSelection ); |
71 mList->setSelectionMode( HbAbstractItemView::SingleSelection ); |
78 { |
81 { |
79 vkbOpened = false; |
82 vkbOpened = false; |
80 comboPrivate->vkbClosed( ); |
83 comboPrivate->vkbClosed( ); |
81 } |
84 } |
82 |
85 |
|
86 #ifdef HB_EFFECTS |
|
87 void HbComboDropDown::dismissEffectFinished( HbEffect::EffectStatus status ) |
|
88 { |
|
89 Q_UNUSED( status ); |
|
90 |
|
91 setVisible( false ); |
|
92 } |
|
93 #endif |
|
94 |
83 bool HbComboDropDown::eventFilter( QObject *obj, QEvent *event ) |
95 bool HbComboDropDown::eventFilter( QObject *obj, QEvent *event ) |
84 { |
96 { |
85 Q_UNUSED( obj ); |
97 Q_UNUSED( obj ); |
86 bool accepted = false; |
98 bool accepted = false; |
87 |
99 |
88 if ( isVisible( ) && !vkbOpened ) { |
100 if ( isVisible( ) ) { |
89 switch( event->type( ) ) |
101 switch( event->type( ) ) |
90 { |
102 { |
91 case QEvent::GraphicsSceneMousePress: |
|
92 case QEvent::GraphicsSceneMouseDoubleClick: |
|
93 { |
|
94 if( !( this->isUnderMouse( ) ) ) { |
|
95 HbWidgetFeedback::triggered( this, Hb::InstantPopupClosed ); |
|
96 setVisible( false ); |
|
97 comboPrivate->q_ptr->setProperty("state","normal"); |
|
98 backgroundPressed = true; |
|
99 accepted = true; |
|
100 } |
|
101 } |
|
102 break; |
|
103 case QEvent::Gesture: |
103 case QEvent::Gesture: |
104 { |
104 { |
105 if( !this->isUnderMouse( ) ) { |
105 if( QGestureEvent *gestureEvent = static_cast<QGestureEvent *>( event ) ) { |
106 //if its a pan gesture then don't accept the event so that list can be scrolled |
106 HbTapGesture *tapGesture = qobject_cast<HbTapGesture *>(gestureEvent->gesture(Qt::TapGesture)); |
107 //even if mouse is outside drop down area. Also tap might finish outside the |
107 if( tapGesture && tapGesture->state() == Qt::GestureStarted ) { |
108 //dropdown area |
108 QRectF dropDownSceneRect = mapToScene(boundingRect( )).boundingRect(); |
109 if( QGestureEvent *gestureEvent = static_cast<QGestureEvent *>( event ) ) { |
109 if(!dropDownSceneRect.contains(tapGesture->sceneStartPos())) { |
110 HbTapGesture *tapGesture = qobject_cast<HbTapGesture *>(gestureEvent->gesture(Qt::TapGesture)); |
110 if( !vkbOpened ) { |
|
111 HbWidgetFeedback::triggered( this, Hb::InstantPopupClosed ); |
|
112 comboPrivate->showDismissEffect( ); |
|
113 comboPrivate->q_ptr->setProperty("state","normal"); |
|
114 backgroundPressed = true; |
|
115 accepted = true; |
|
116 } else { |
|
117 //if vkb is opened then dismiss drop down only if click happened outside drop down and |
|
118 //vkb area |
|
119 if( comboPrivate->mEditable ) { |
|
120 HbEditorInterface editorInterface( comboPrivate->q_ptr ); |
|
121 HbVkbHost *host = editorInterface.vkbHost( ); |
|
122 if( host ) { |
|
123 //get the scene rect of vkb |
|
124 QGraphicsWidget *vkbWidget = host->activeKeypad( )->asGraphicsWidget( ); |
|
125 QRectF tmp = host->applicationArea( ); |
|
126 QRectF vkbArea = vkbWidget->mapToScene( tmp ).boundingRect( ); |
|
127 if( !vkbArea.contains( tapGesture->sceneStartPos() ) ) { |
|
128 comboPrivate->showDismissEffect( ); |
|
129 HbWidgetFeedback::triggered( this, Hb::InstantPopupClosed ); |
|
130 comboPrivate->q_ptr->setProperty( "state", "normal" ); |
|
131 backgroundPressed = true; |
|
132 accepted = true; |
|
133 } |
|
134 } |
|
135 } |
|
136 } |
|
137 } |
|
138 } else { |
|
139 //if its a pan gesture then don't accept the event so that list can be scrolled |
|
140 //even if mouse is outside drop down area. Also tap might finish outside the |
|
141 //dropdown area |
111 if( !qobject_cast<HbPanGesture *>( |
142 if( !qobject_cast<HbPanGesture *>( |
112 gestureEvent->gesture( Qt::PanGesture ) ) && |
143 gestureEvent->gesture( Qt::PanGesture ) ) && |
113 !(tapGesture && tapGesture->state() != Qt::GestureStarted)) { |
144 !(tapGesture && tapGesture->state() != Qt::GestureStarted)) { |
114 accepted = true; |
145 accepted = true; |
115 } |
146 } |
116 } |
147 } |
117 } |
148 } |
118 } |
149 } |
119 break; |
150 break; |
|
151 case QEvent::GraphicsSceneMousePress: |
|
152 //dont accept the mouse press event if vkb is pressed, so that vkb can take events |
|
153 if( vkbOpened ) { |
|
154 if( comboPrivate->mEditable ) { |
|
155 HbEditorInterface editorInterface( comboPrivate->q_ptr ); |
|
156 HbVkbHost *host = editorInterface.vkbHost( ); |
|
157 if( host ) { |
|
158 //get the scene rect of vkb |
|
159 QGraphicsWidget *vkbWidget = host->activeKeypad( )->asGraphicsWidget( ); |
|
160 QRectF tmp = host->applicationArea( ); |
|
161 QRectF vkbArea = vkbWidget->mapToScene( tmp ).boundingRect( ); |
|
162 |
|
163 QGraphicsSceneMouseEvent *mouseEvent = |
|
164 static_cast< QGraphicsSceneMouseEvent * >( event ); |
|
165 if( vkbArea.contains( mouseEvent->scenePos( ) ) ) { |
|
166 break; |
|
167 } |
|
168 } |
|
169 } |
|
170 } |
|
171 case QEvent::TouchBegin: |
|
172 accepted = true; |
|
173 break; |
120 default: |
174 default: |
121 break; |
175 break; |
122 } |
176 } |
123 } |
177 } |
124 return accepted; |
178 return accepted; |
125 } |
179 } |
126 |
180 |
|
181 QVariant HbComboDropDown::itemChange( GraphicsItemChange change, const QVariant & value ) |
|
182 { |
|
183 switch( change ) { |
|
184 case QGraphicsItem::ItemVisibleHasChanged: |
|
185 if( !value.toBool( ) ) { |
|
186 comboPrivate->resetGeometryChangeFlag( ); |
|
187 } |
|
188 break; |
|
189 default: |
|
190 break; |
|
191 } |
|
192 return HbWidget::itemChange( change, value ); |
|
193 } |
|
194 |
127 #include "moc_hbcombodropdown_p.cpp" |
195 #include "moc_hbcombodropdown_p.cpp" |
128 |
196 |