1 /* |
1 /* |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
4 * |
9 * Initial Contributors: |
5 * This program is free software: you can redistribute it and/or modify |
10 * Nokia Corporation - initial contribution. |
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
11 * |
8 * |
12 * Contributors: |
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
13 * |
13 * |
14 * Description: |
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
15 * |
19 * |
16 */ |
20 */ |
17 |
|
18 |
21 |
19 #include "ActionButtonSnippet.h" |
22 #include "ActionButtonSnippet.h" |
20 #include "controllableviewimpl.h" |
23 #include "controllableviewimpl.h" |
21 |
24 |
22 namespace GVA { |
25 namespace GVA { |
23 |
26 |
24 ActionButtonSnippet::ActionButtonSnippet( const QString & elementId, ChromeWidget * chrome, QGraphicsWidget * widget, const QWebElement & element ) |
27 ActionButtonSnippet::ActionButtonSnippet( const QString & elementId, ChromeWidget * chrome, QGraphicsWidget * widget, const QWebElement & element ) |
25 : ChromeSnippet( elementId, chrome, widget, element ) |
28 : ChromeSnippet( elementId, chrome, widget, element ) |
26 { |
29 { |
27 connect(static_cast<ActionButton*>(m_widget), SIGNAL(activated()), this, SIGNAL(activated())); |
30 |
28 connect(static_cast<ActionButton*>(m_widget), SIGNAL(contextMenuEvent()), this, SIGNAL(contextMenuEvent())); |
|
29 } |
31 } |
30 |
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 |
|
40 QAction * ActionButtonSnippet::getDefaultAction() |
|
41 { |
|
42 return (static_cast<ActionButton*>(m_widget)->defaultAction()); |
|
43 } |
|
44 |
|
45 //void ActionButtonSnippet::setDefaultAction( QAction * action, QEvent::Type triggerOn ) |
|
46 void ActionButtonSnippet::setDefaultAction( QAction * action, bool triggerOnDown, bool triggerOnUp) |
|
47 { |
|
48 static_cast<ActionButton*>(m_widget)->setAction(action,triggerOnDown, triggerOnUp); |
|
49 } |
|
50 |
|
51 QIcon ActionButtonSnippet::icon( ) |
|
52 { |
|
53 return static_cast<ActionButton*>(m_widget)->icon(); |
|
54 } |
|
55 |
31 void ActionButtonSnippet::setIcon( const QString & icon ) |
56 void ActionButtonSnippet::setIcon( const QString & icon ) |
32 { |
57 { |
33 static_cast<ActionButton*>(m_widget)->addIcon(icon); |
58 static_cast<ActionButton*>(m_widget)->addIcon(icon); |
34 } |
59 } |
35 |
60 |
36 void ActionButtonSnippet::setDisabledIcon( const QString & icon ) |
61 void ActionButtonSnippet::setDisabledIcon( const QString & icon ) |
37 { |
62 { |
38 static_cast<ActionButton*>(m_widget)->addIcon(icon, QIcon::Disabled); |
63 static_cast<ActionButton*>(m_widget)->addIcon(icon, QIcon::Disabled); |
39 |
64 |
40 } |
|
41 |
|
42 void ActionButtonSnippet::setSelectedIcon( const QString & icon ) |
|
43 { |
|
44 static_cast<ActionButton*>(m_widget)->addIcon(icon, QIcon::Selected); |
|
45 } |
65 } |
46 |
66 |
47 void ActionButtonSnippet::setActiveIcon( const QString & icon ) |
67 void ActionButtonSnippet::setActiveIcon( const QString & icon ) |
48 { |
68 { |
49 static_cast<ActionButton*>(m_widget)->addIcon(icon, QIcon::Active); |
69 static_cast<ActionButton*>(m_widget)->addIcon(icon, QIcon::Active); |
50 } |
70 } |
51 |
71 |
52 // 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 |
53 |
73 |
54 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) |
55 { |
75 { |
56 ControllableViewBase *viewBase = m_chrome->getView( view ); |
76 ControllableViewBase *viewBase = m_chrome->getView( view ); |
57 if(viewBase){ |
77 |
|
78 if (viewBase){ |
58 QAction * viewAction = viewBase->getAction(action); |
79 QAction * viewAction = viewBase->getAction(action); |
59 if(viewAction) |
80 if (viewAction) |
60 static_cast<ActionButton*>(m_widget)->setAction(viewAction, |
81 static_cast<ActionButton*>(m_widget)->setAction(viewAction, onDown, onUp); |
61 (inputEvent == "Down") ? QEvent::GraphicsSceneMousePress : QEvent::GraphicsSceneMouseRelease); |
|
62 return; |
82 return; |
63 } |
83 } |
64 } |
84 } |
65 |
85 |
66 //NB: setEnabled and setLatched only affect button behavior when no action |
86 bool ActionButtonSnippet::isChecked( ) |
67 //is currently set. These methods are intended to be used when the button |
87 { |
68 //is controlled by javascript. When an action has been set, button behavior and |
88 return (static_cast<ActionButton*>(m_widget)->isChecked()); |
69 //rendering is instead controlled by the action. |
89 } |
70 |
90 |
71 void ActionButtonSnippet::setEnabled( bool enabled ) |
91 void ActionButtonSnippet::setEnabled( bool enabled ) |
72 { |
92 { |
73 static_cast<ActionButton*>(m_widget)->setEnabled(enabled); |
93 static_cast<ActionButton*>(m_widget)->setEnabled(enabled); |
74 } |
94 } |
75 |
95 |
76 void ActionButtonSnippet::setLatched( bool latched ) |
96 void ActionButtonSnippet::setActive( bool enabled ) |
77 { |
97 { |
78 static_cast<ActionButton*>(m_widget)->setChecked(latched); |
98 static_cast<ActionButton*>(m_widget)->setActive(enabled); |
79 } |
99 } |
80 |
100 |
81 void ActionButtonSnippet::setInputEvent( const QString & inputEvent ) |
101 void ActionButtonSnippet::setActiveOnPress( bool active ) |
82 { |
102 { |
83 static_cast<ActionButton*>(m_widget)->setInputEvent((inputEvent=="Down") ? QEvent::GraphicsSceneMousePress : QEvent::GraphicsSceneMouseRelease); |
103 static_cast<ActionButton*>(m_widget)->setActiveOnPress(active); |
84 } |
104 } |
85 |
105 |
|
106 void ActionButtonSnippet::updateButtonState(bool state) { |
|
107 if (state ) { |
|
108 static_cast<ActionButton*>(m_widget)->onShown(); |
|
109 } |
|
110 else { |
|
111 static_cast<ActionButton*>(m_widget)->onHidden(); |
|
112 } |
|
113 } |
86 |
114 |
87 } |
115 } |