|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
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 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "ActionButtonSnippet.h" |
|
20 #include "controllableviewimpl.h" |
|
21 |
|
22 namespace GVA { |
|
23 |
|
24 ActionButtonSnippet::ActionButtonSnippet( const QString & elementId, ChromeWidget * chrome, QGraphicsWidget * widget, const QWebElement & element ) |
|
25 : ChromeSnippet( elementId, chrome, widget, element ) |
|
26 { |
|
27 connect(static_cast<ActionButton*>(m_widget), SIGNAL(activated()), this, SIGNAL(activated())); |
|
28 connect(static_cast<ActionButton*>(m_widget), SIGNAL(contextMenuEvent()), this, SIGNAL(contextMenuEvent())); |
|
29 } |
|
30 |
|
31 void ActionButtonSnippet::setIcon( const QString & icon ) |
|
32 { |
|
33 static_cast<ActionButton*>(m_widget)->addIcon(icon); |
|
34 } |
|
35 |
|
36 void ActionButtonSnippet::setDisabledIcon( const QString & icon ) |
|
37 { |
|
38 static_cast<ActionButton*>(m_widget)->addIcon(icon, QIcon::Disabled); |
|
39 |
|
40 } |
|
41 |
|
42 void ActionButtonSnippet::setSelectedIcon( const QString & icon ) |
|
43 { |
|
44 static_cast<ActionButton*>(m_widget)->addIcon(icon, QIcon::Selected); |
|
45 } |
|
46 |
|
47 void ActionButtonSnippet::setActiveIcon( const QString & icon ) |
|
48 { |
|
49 static_cast<ActionButton*>(m_widget)->addIcon(icon, QIcon::Active); |
|
50 } |
|
51 |
|
52 // Scriptable method to directly connect an action button to a view action |
|
53 |
|
54 void ActionButtonSnippet::connectAction( const QString & action, const QString & view, const QString & inputEvent ) |
|
55 { |
|
56 ControllableViewBase *viewBase = m_chrome->getView( view ); |
|
57 if(viewBase){ |
|
58 QAction * viewAction = viewBase->getAction(action); |
|
59 if(viewAction) |
|
60 static_cast<ActionButton*>(m_widget)->setAction(viewAction, |
|
61 (inputEvent == "Down") ? QEvent::GraphicsSceneMousePress : QEvent::GraphicsSceneMouseRelease); |
|
62 return; |
|
63 } |
|
64 } |
|
65 |
|
66 //NB: setEnabled and setLatched only affect button behavior when no action |
|
67 //is currently set. These methods are intended to be used when the button |
|
68 //is controlled by javascript. When an action has been set, button behavior and |
|
69 //rendering is instead controlled by the action. |
|
70 |
|
71 void ActionButtonSnippet::setEnabled( bool enabled ) |
|
72 { |
|
73 static_cast<ActionButton*>(m_widget)->setEnabled(enabled); |
|
74 } |
|
75 |
|
76 void ActionButtonSnippet::setLatched( bool latched ) |
|
77 { |
|
78 static_cast<ActionButton*>(m_widget)->setChecked(latched); |
|
79 } |
|
80 |
|
81 void ActionButtonSnippet::setInputEvent( const QString & inputEvent ) |
|
82 { |
|
83 static_cast<ActionButton*>(m_widget)->setInputEvent((inputEvent=="Down") ? QEvent::GraphicsSceneMousePress : QEvent::GraphicsSceneMouseRelease); |
|
84 } |
|
85 |
|
86 |
|
87 } |