28 : ChromeSnippet( elementId, chrome, widget, element ) |
28 : ChromeSnippet( elementId, chrome, widget, element ) |
29 { |
29 { |
30 |
30 |
31 } |
31 } |
32 |
32 |
|
33 ActionButtonSnippet * ActionButtonSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element) |
|
34 { |
|
35 ActionButtonSnippet* that = new ActionButtonSnippet(elementId, chrome, 0, element); |
|
36 that->setChromeWidget( new ActionButton( that ) ); |
|
37 return that; |
|
38 } |
|
39 |
33 QAction * ActionButtonSnippet::getDefaultAction() |
40 QAction * ActionButtonSnippet::getDefaultAction() |
34 { |
41 { |
35 return (static_cast<ActionButton*>(m_widget)->defaultAction()); |
42 return (static_cast<ActionButton*>(m_widget)->defaultAction()); |
36 } |
43 } |
37 |
44 |
38 void ActionButtonSnippet::setDefaultAction( QAction * action, QEvent::Type triggerOn ) |
45 //void ActionButtonSnippet::setDefaultAction( QAction * action, QEvent::Type triggerOn ) |
|
46 void ActionButtonSnippet::setDefaultAction( QAction * action, bool triggerOnDown, bool triggerOnUp) |
39 { |
47 { |
40 static_cast<ActionButton*>(m_widget)->setAction(action,triggerOn); |
48 static_cast<ActionButton*>(m_widget)->setAction(action,triggerOnDown, triggerOnUp); |
41 } |
49 } |
42 |
50 |
43 QIcon ActionButtonSnippet::icon( ) |
51 QIcon ActionButtonSnippet::icon( ) |
44 { |
52 { |
45 return static_cast<ActionButton*>(m_widget)->icon(); |
53 return static_cast<ActionButton*>(m_widget)->icon(); |
54 { |
62 { |
55 static_cast<ActionButton*>(m_widget)->addIcon(icon, QIcon::Disabled); |
63 static_cast<ActionButton*>(m_widget)->addIcon(icon, QIcon::Disabled); |
56 |
64 |
57 } |
65 } |
58 |
66 |
59 void ActionButtonSnippet::setSelectedIcon( const QString & icon ) |
|
60 { |
|
61 static_cast<ActionButton*>(m_widget)->addIcon(icon, QIcon::Selected); |
|
62 } |
|
63 |
|
64 void ActionButtonSnippet::setActiveIcon( const QString & icon ) |
67 void ActionButtonSnippet::setActiveIcon( const QString & icon ) |
65 { |
68 { |
66 static_cast<ActionButton*>(m_widget)->addIcon(icon, QIcon::Active); |
69 static_cast<ActionButton*>(m_widget)->addIcon(icon, QIcon::Active); |
67 } |
70 } |
68 |
71 |
69 // Scriptable method to directly connect an action button to a view action |
72 // Scriptable method to directly connect an action button to a view action |
70 |
73 |
71 void ActionButtonSnippet::connectAction( const QString & action, const QString & view, const QString & inputEvent ) |
74 void ActionButtonSnippet::connectAction( const QString & action, const QString & view, bool onDown, bool onUp) |
72 { |
75 { |
73 ControllableViewBase *viewBase = m_chrome->getView( view ); |
76 ControllableViewBase *viewBase = m_chrome->getView( view ); |
74 |
77 |
75 if (viewBase){ |
78 if (viewBase){ |
76 QAction * viewAction = viewBase->getAction(action); |
79 QAction * viewAction = viewBase->getAction(action); |
77 if (viewAction) |
80 if (viewAction) |
78 static_cast<ActionButton*>(m_widget)->setAction(viewAction, |
81 static_cast<ActionButton*>(m_widget)->setAction(viewAction, onDown, onUp); |
79 (inputEvent == "Down") ? QEvent::GraphicsSceneMousePress : QEvent::GraphicsSceneMouseRelease); |
|
80 return; |
82 return; |
81 } |
83 } |
82 } |
84 } |
83 |
85 |
84 bool ActionButtonSnippet::isChecked( ) |
86 bool ActionButtonSnippet::isChecked( ) |
89 void ActionButtonSnippet::setEnabled( bool enabled ) |
91 void ActionButtonSnippet::setEnabled( bool enabled ) |
90 { |
92 { |
91 static_cast<ActionButton*>(m_widget)->setEnabled(enabled); |
93 static_cast<ActionButton*>(m_widget)->setEnabled(enabled); |
92 } |
94 } |
93 |
95 |
94 void ActionButtonSnippet::setLatched( bool latched ) |
|
95 { |
|
96 static_cast<ActionButton*>(m_widget)->setChecked(latched); |
|
97 } |
|
98 |
|
99 void ActionButtonSnippet::setActive( bool enabled ) |
96 void ActionButtonSnippet::setActive( bool enabled ) |
100 { |
97 { |
101 static_cast<ActionButton*>(m_widget)->setActive(enabled); |
98 static_cast<ActionButton*>(m_widget)->setActive(enabled); |
102 } |
99 } |
103 |
100 |
104 void ActionButtonSnippet::setInputEvent( const QString & inputEvent ) |
101 void ActionButtonSnippet::setActiveOnPress( bool active ) |
105 { |
102 { |
106 static_cast<ActionButton*>(m_widget)->setInputEvent((inputEvent=="Down") ? QEvent::GraphicsSceneMousePress : QEvent::GraphicsSceneMouseRelease); |
103 static_cast<ActionButton*>(m_widget)->setActiveOnPress(active); |
107 } |
104 } |
108 |
105 |
109 void ActionButtonSnippet::updateButtonState(bool state) { |
106 void ActionButtonSnippet::updateButtonState(bool state) { |
110 if (state ) { |
107 if (state ) { |
111 static_cast<ActionButton*>(m_widget)->onShown(); |
108 static_cast<ActionButton*>(m_widget)->onShown(); |