23 ** |
23 ** |
24 ****************************************************************************/ |
24 ****************************************************************************/ |
25 |
25 |
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 <hblistview.h> |
29 #include <hblistview.h> |
29 #include <hbwidgetfeedback.h> |
30 #include <hbwidgetfeedback.h> |
30 |
31 |
31 #ifdef HB_GESTURE_FW |
|
32 #include <hbtapgesture.h> |
32 #include <hbtapgesture.h> |
33 #include <hbpangesture.h> |
33 #include <hbpangesture.h> |
34 #endif |
34 #include <QGestureEvent> |
35 |
35 |
|
36 class HbComboDropDownPrivate : public HbWidgetPrivate |
|
37 { |
|
38 }; |
36 HbComboDropDown::HbComboDropDown( HbComboBoxPrivate *comboBoxPrivate, QGraphicsItem *parent ) |
39 HbComboDropDown::HbComboDropDown( HbComboBoxPrivate *comboBoxPrivate, QGraphicsItem *parent ) |
37 :HbWidget( parent ), |
40 :HbWidget( *new HbComboDropDownPrivate(), parent ), |
38 mList( 0 ), |
41 mList( 0 ), |
39 comboPrivate( comboBoxPrivate ), |
42 comboPrivate( comboBoxPrivate ), |
40 vkbOpened( false ), |
43 vkbOpened( false ), |
41 backgroundPressed( false ) |
44 backgroundPressed( false ) |
42 { |
45 { |
43 setBackgroundItem( HbStyle::P_ComboBoxPopup_background ); |
46 Q_D(HbComboDropDown); |
|
47 d->setBackgroundItem(HbStyle::P_ComboBoxPopup_background); |
44 #if QT_VERSION >= 0x040600 |
48 #if QT_VERSION >= 0x040600 |
45 //this is to keep the focus in the previous widget. |
49 //this is to keep the focus in the previous widget. |
46 setFlag( QGraphicsItem::ItemIsPanel, true ); |
50 setFlag( QGraphicsItem::ItemIsPanel, true ); |
47 setActive( false ); |
51 setActive( false ); |
48 #endif |
52 #endif |
49 //setFlag(QGraphicsItem::ItemIsPanel); |
|
50 //setPanelModality(PanelModal); |
|
51 } |
53 } |
52 |
54 |
53 HbComboDropDown::~HbComboDropDown( ) |
55 HbComboDropDown::~HbComboDropDown( ) |
54 { |
56 { |
55 |
57 |
56 } |
58 } |
57 |
59 |
58 void HbComboDropDown::createList( ) |
60 void HbComboDropDown::createList( ) |
59 { |
61 { |
60 mList = new HbListView( this ); |
62 mList = new HbListView( this ); |
61 mList->setLongPressEnabled(false); |
63 mList->setLongPressEnabled( false ); |
62 HbComboListViewItem *protoType = new HbComboListViewItem(this); |
64 HbComboListViewItem *protoType = new HbComboListViewItem( this ); |
63 mList->setItemPrototype( protoType ); |
65 mList->setItemPrototype( protoType ); |
64 HbStyle::setItemName( mList, "list" ); |
66 HbStyle::setItemName( mList, "list" ); |
65 mList->setUniformItemSizes( true ); |
67 mList->setUniformItemSizes( true ); |
66 mList->setSelectionMode( HbAbstractItemView::SingleSelection ); |
68 mList->setSelectionMode( HbAbstractItemView::SingleSelection ); |
67 } |
69 } |
68 |
70 |
69 void HbComboDropDown::keypadOpened( ) |
71 void HbComboDropDown::keypadOpened( ) |
70 { |
72 { |
71 vkbOpened = true; |
73 vkbOpened = true; |
72 comboPrivate->vkbOpened(); |
74 comboPrivate->vkbOpened( ); |
73 } |
75 } |
74 |
76 |
75 void HbComboDropDown::keypadClosed( ) |
77 void HbComboDropDown::keypadClosed( ) |
76 { |
78 { |
77 vkbOpened = false; |
79 vkbOpened = false; |
78 comboPrivate->vkbClosed(); |
80 comboPrivate->vkbClosed( ); |
79 } |
81 } |
80 |
82 |
81 bool HbComboDropDown::eventFilter( QObject *obj, QEvent *event ) |
83 bool HbComboDropDown::eventFilter( QObject *obj, QEvent *event ) |
82 { |
84 { |
83 Q_UNUSED( obj ); |
85 Q_UNUSED( obj ); |
88 { |
90 { |
89 case QEvent::GraphicsSceneMousePress: |
91 case QEvent::GraphicsSceneMousePress: |
90 case QEvent::GraphicsSceneMouseDoubleClick: |
92 case QEvent::GraphicsSceneMouseDoubleClick: |
91 { |
93 { |
92 if( !( this->isUnderMouse( ) ) ) { |
94 if( !( this->isUnderMouse( ) ) ) { |
93 backgroundPressed = true; |
|
94 accepted = true; |
|
95 } |
|
96 } |
|
97 break; |
|
98 case QEvent::GraphicsSceneMouseRelease: |
|
99 { |
|
100 if( !( this->isUnderMouse( ) ) && backgroundPressed ) { |
|
101 HbWidgetFeedback::triggered( this, Hb::InstantPopupClosed ); |
95 HbWidgetFeedback::triggered( this, Hb::InstantPopupClosed ); |
102 setVisible( false ); |
96 setVisible( false ); |
103 backgroundPressed = false; |
97 comboPrivate->q_ptr->setProperty("state","normal"); |
|
98 backgroundPressed = true; |
104 accepted = true; |
99 accepted = true; |
105 } |
100 } |
106 } |
101 } |
107 break; |
102 break; |
108 case QEvent::Gesture: |
103 case QEvent::Gesture: |
109 { |
104 { |
110 if( !this->isUnderMouse() ) { |
105 if( !this->isUnderMouse( ) ) { |
111 //if its a pan gesture then don't accept the event so that list can be scrolled |
106 //if its a pan gesture then don't accept the event so that list can be scrolled |
112 //even if mouse is outside drop down area |
107 //even if mouse is outside drop down area. Also tap might finish outside the |
113 if(QGestureEvent *gestureEvent = static_cast<QGestureEvent *>( event ) ) { |
108 //dropdown area |
114 if( !qobject_cast<HbPanGesture *>( gestureEvent->gesture( Qt::PanGesture ) ) ) { |
109 if( QGestureEvent *gestureEvent = static_cast<QGestureEvent *>( event ) ) { |
|
110 HbTapGesture *tapGesture = qobject_cast<HbTapGesture *>(gestureEvent->gesture(Qt::TapGesture)); |
|
111 if( !qobject_cast<HbPanGesture *>( |
|
112 gestureEvent->gesture( Qt::PanGesture ) ) && |
|
113 !(tapGesture && tapGesture->state() != Qt::GestureStarted)) { |
115 accepted = true; |
114 accepted = true; |
116 } |
115 } |
117 } |
116 } |
118 } |
117 } |
119 } |
118 } |
120 break; |
119 break; |
121 default: |
120 default: |
122 break; |
121 break; |
123 } |
122 } |
124 } |
123 } |
125 |
|
126 return accepted; |
124 return accepted; |
127 } |
125 } |
128 |
126 |
129 #include "moc_hbcombodropdown_p.cpp" |
127 #include "moc_hbcombodropdown_p.cpp" |
130 |
128 |