|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * This program is free software: you can redistribute it and/or modify |
|
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. |
|
8 * |
|
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 * |
|
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: |
|
19 * |
|
20 */ |
|
21 |
|
22 #include "EditorSnippet.h" |
|
23 |
|
24 namespace GVA { |
|
25 |
|
26 EditorSnippet::EditorSnippet( const QString & elementId, ChromeWidget * chrome, QGraphicsWidget * widget, const QWebElement & element ) |
|
27 : ChromeSnippet( elementId, chrome, widget, element ) |
|
28 { |
|
29 connectAll(); |
|
30 } |
|
31 |
|
32 void EditorSnippet::setChromeWidget(QGraphicsWidget * widget){ |
|
33 ChromeSnippet::setChromeWidget(widget); |
|
34 connectAll(); |
|
35 } |
|
36 |
|
37 EditorSnippet * EditorSnippet::instance(const QString& elementId, ChromeWidget * chrome, const QWebElement & element) |
|
38 { |
|
39 EditorSnippet* that = new EditorSnippet(elementId, chrome, 0, element); |
|
40 that->setChromeWidget( new TextEditItem( that, chrome ) ); |
|
41 return that; |
|
42 } |
|
43 |
|
44 void EditorSnippet::connectAll(){ |
|
45 if(m_widget){ |
|
46 GTextEditor * editor = static_cast<TextEditItem*>(m_widget)->editor(); |
|
47 connect(editor, SIGNAL(textMayChanged()), this, SIGNAL(textChanged())); |
|
48 connect(editor, SIGNAL(activated()), this, SIGNAL(activated())); |
|
49 connect(editor, SIGNAL(focusChanged(bool)), this, SLOT(onFocusChanged(bool))); |
|
50 connect(editor, SIGNAL(tapped(QPointF&)), this, SLOT(onTapped(QPointF&))); |
|
51 } |
|
52 } |
|
53 |
|
54 void EditorSnippet::onFocusChanged(bool in) |
|
55 { |
|
56 if(in) |
|
57 emit gainedFocus(); |
|
58 else |
|
59 emit lostFocus(); |
|
60 } |
|
61 |
|
62 void EditorSnippet::onTapped(QPointF& pos){ |
|
63 emit gainedFocus(); |
|
64 } |
|
65 |
|
66 void EditorSnippet::setText( const QString & text ) |
|
67 { |
|
68 static_cast<TextEditItem*>(m_widget)->setText(text); |
|
69 } |
|
70 |
|
71 QString EditorSnippet::text() |
|
72 { |
|
73 return static_cast<TextEditItem*>(m_widget)->text(); |
|
74 } |
|
75 |
|
76 void EditorSnippet::setCursorPosition(int pos) |
|
77 { |
|
78 static_cast<TextEditItem*>(m_widget)->setCursorPosition(pos); |
|
79 } |
|
80 |
|
81 int EditorSnippet::charCount(){ |
|
82 return static_cast<TextEditItem*>(m_widget)->characterCount(); |
|
83 } |
|
84 |
|
85 void EditorSnippet::selectAll(){ |
|
86 return static_cast<TextEditItem*>(m_widget)->selectAll(); |
|
87 } |
|
88 |
|
89 void EditorSnippet::unselect(){ |
|
90 return static_cast<TextEditItem*>(m_widget)->unselect(); |
|
91 } |
|
92 |
|
93 int EditorSnippet::getTextOptions(){ |
|
94 return (int) static_cast<TextEditItem*>(m_widget)->getTextOptions(); |
|
95 } |
|
96 |
|
97 void EditorSnippet::setTextOptions(int flag){ |
|
98 return static_cast<TextEditItem*>(m_widget)->setTextOptions(flag); |
|
99 } |
|
100 |
|
101 void EditorSnippet::setMaxTextLength(int length){ |
|
102 return static_cast<TextEditItem*>(m_widget)->setMaxTextLength(length); |
|
103 } |
|
104 } |