40 mMutex.unlock(); |
41 mMutex.unlock(); |
41 } |
42 } |
42 |
43 |
43 bool HbEditorInterfacePrivate::hasInterface(HbEditorInterface *toBeChecked) const |
44 bool HbEditorInterfacePrivate::hasInterface(HbEditorInterface *toBeChecked) const |
44 { |
45 { |
45 foreach (HbEditorInterface *iFace, mAttachedInterfaces) { |
46 foreach(HbEditorInterface *iFace, mAttachedInterfaces) { |
46 if (iFace == toBeChecked) { |
47 if (iFace == toBeChecked) { |
47 return true; |
48 return true; |
48 } |
49 } |
49 } |
50 } |
50 |
51 |
51 return false; |
52 return false; |
52 } |
53 } |
53 |
54 |
54 void HbEditorInterfacePrivate::setInputMethodHints(Qt::InputMethodHints hints) |
55 void HbEditorInterfacePrivate::setInputMethodHints(Qt::InputMethodHints hints) |
55 { |
56 { |
56 if (mHostEditor) { |
57 if (mHostEditor) { |
57 QGraphicsWidget *graphicsWidget = qobject_cast<QGraphicsWidget*>(mHostEditor); |
58 QGraphicsWidget *graphicsWidget = qobject_cast<QGraphicsWidget *>(mHostEditor); |
58 if (graphicsWidget) { |
59 if (graphicsWidget) { |
59 graphicsWidget->setInputMethodHints(hints); |
60 graphicsWidget->setInputMethodHints(hints); |
60 } else { |
61 } else { |
61 QWidget *widget = qobject_cast<QWidget*>(mHostEditor); |
62 QWidget *widget = qobject_cast<QWidget *>(mHostEditor); |
62 if (widget) { |
63 if (widget) { |
63 widget->setInputMethodHints(hints); |
64 widget->setInputMethodHints(hints); |
64 } |
65 } |
65 } |
66 } |
66 } |
67 } |
67 } |
68 } |
68 |
69 |
69 Qt::InputMethodHints HbEditorInterfacePrivate::inputMethodHints() const |
70 Qt::InputMethodHints HbEditorInterfacePrivate::inputMethodHints() const |
70 { |
71 { |
71 if (mHostEditor) { |
72 if (mHostEditor) { |
72 QGraphicsWidget *graphicsWidget = qobject_cast<QGraphicsWidget*>(mHostEditor); |
73 QGraphicsWidget *graphicsWidget = qobject_cast<QGraphicsWidget *>(mHostEditor); |
73 if (graphicsWidget) { |
74 if (graphicsWidget) { |
74 return graphicsWidget->inputMethodHints(); |
75 return graphicsWidget->inputMethodHints(); |
75 } else { |
76 } else { |
76 QWidget *widget = qobject_cast<QWidget*>(mHostEditor); |
77 QWidget *widget = qobject_cast<QWidget *>(mHostEditor); |
77 if (widget) { |
78 if (widget) { |
78 return widget->inputMethodHints(); |
79 return widget->inputMethodHints(); |
79 } |
80 } |
80 } |
81 } |
81 } |
82 } |
82 |
83 |
83 return Qt::ImhNone; |
84 return Qt::ImhNone; |
84 } |
85 } |
85 |
86 |
86 void HbEditorInterfacePrivate::notifyCursorPositionChange(int oldPos, int newPos) |
87 void HbEditorInterfacePrivate::notifyCursorPositionChange(int oldPos, int newPos) |
87 { |
88 { |
88 emit cursorPositionChanged(oldPos, newPos); |
89 emit cursorPositionChanged(oldPos, newPos); |
112 for (int i = 0; i < mObjectCache.count(); i++) { |
113 for (int i = 0; i < mObjectCache.count(); i++) { |
113 delete mObjectCache[i]; |
114 delete mObjectCache[i]; |
114 } |
115 } |
115 } |
116 } |
116 |
117 |
117 HbEditorInterfacePrivate* HbEditorInterfacePrivateCache::attachEditor(QObject* editor, HbEditorInterface* interface) |
118 HbEditorInterfacePrivate *HbEditorInterfacePrivateCache::attachEditor(QObject *editor, HbEditorInterface *interface) |
118 { |
119 { |
119 if (editor) { |
120 if (editor) { |
120 for (int i = 0; i < mObjectCache.count(); i++) { |
121 for (int i = 0; i < mObjectCache.count(); i++) { |
121 if (mObjectCache[i]->mHostEditor == editor) { |
122 if (mObjectCache[i]->mHostEditor == editor) { |
122 if (!mObjectCache[i]->hasInterface(interface)) { |
123 if (!mObjectCache[i]->hasInterface(interface)) { |
123 mObjectCache[i]->mAttachedInterfaces.append(interface); |
124 mObjectCache[i]->mAttachedInterfaces.append(interface); |
124 connect(interface, SIGNAL(destroyed(QObject*)), this, SLOT(interfaceDestroyed(QObject*))); |
125 connect(interface, SIGNAL(destroyed(QObject *)), this, SLOT(interfaceDestroyed(QObject *))); |
125 connect(mObjectCache[i], SIGNAL(cursorPositionChanged(int, int)), interface, SIGNAL(cursorPositionChanged(int, int))); |
126 connect(mObjectCache[i], SIGNAL(cursorPositionChanged(int, int)), interface, SIGNAL(cursorPositionChanged(int, int))); |
126 } |
127 } |
127 return mObjectCache[i]; |
128 return mObjectCache[i]; |
128 } |
129 } |
129 } |
130 } |
130 |
131 |
131 HbEditorInterfacePrivate* newItem = new HbEditorInterfacePrivate(); |
132 HbEditorInterfacePrivate *newItem = new HbEditorInterfacePrivate(); |
132 newItem->mHostEditor = editor; |
133 newItem->mHostEditor = editor; |
133 newItem->mAttachedInterfaces.append(interface); |
134 newItem->mAttachedInterfaces.append(interface); |
134 mObjectCache.append(newItem); |
135 mObjectCache.append(newItem); |
135 |
136 |
136 connect(editor, SIGNAL(destroyed(QObject*)), this, SLOT(destroyed(QObject*))); |
137 connect(editor, SIGNAL(destroyed(QObject *)), this, SLOT(destroyed(QObject *))); |
137 connect(interface, SIGNAL(destroyed(QObject*)), this, SLOT(interfaceDestroyed(QObject*))); |
138 connect(interface, SIGNAL(destroyed(QObject *)), this, SLOT(interfaceDestroyed(QObject *))); |
138 connect(newItem, SIGNAL(cursorPositionChanged(int, int)), interface, SIGNAL(cursorPositionChanged(int, int))); |
139 connect(newItem, SIGNAL(cursorPositionChanged(int, int)), interface, SIGNAL(cursorPositionChanged(int, int))); |
139 |
140 |
140 // Check whether the connected object is a QLineEdit or QTextEdit, plain or wrapped in QGraphicsProxyWidget |
141 // Check whether the connected object is a QLineEdit or QTextEdit, plain or wrapped in QGraphicsProxyWidget |
141 // and if yes, connect its cursorPositionChanged() signal to this item's cursorPositionChanged() signal |
142 // and if yes, connect its cursorPositionChanged() signal to this item's cursorPositionChanged() signal |
142 if (editor->inherits("HbAbstractEdit")) { |
143 if (editor->inherits("HbAbstractEdit")) { |
143 connect(editor, SIGNAL(cursorPositionChanged(int, int)), newItem, SIGNAL(cursorPositionChanged(int, int))); |
144 connect(editor, SIGNAL(cursorPositionChanged(int, int)), newItem, SIGNAL(cursorPositionChanged(int, int))); |
144 } else { |
145 } else { |
145 QGraphicsProxyWidget* proxywidget = qobject_cast<QGraphicsProxyWidget*>(editor); |
146 QGraphicsProxyWidget *proxywidget = qobject_cast<QGraphicsProxyWidget *>(editor); |
146 if (proxywidget) { |
147 if (proxywidget) { |
147 QWidget* editorwidget = proxywidget->widget(); |
148 QWidget *editorwidget = proxywidget->widget(); |
148 QLineEdit* lineedit = qobject_cast<QLineEdit*>(editorwidget); |
149 QLineEdit *lineedit = qobject_cast<QLineEdit *>(editorwidget); |
149 if (lineedit) { |
150 if (lineedit) { |
150 connect(lineedit, SIGNAL(cursorPositionChanged(int, int)), newItem, SIGNAL(cursorPositionChanged(int, int))); |
151 connect(lineedit, SIGNAL(cursorPositionChanged(int, int)), newItem, SIGNAL(cursorPositionChanged(int, int))); |
151 } else { |
152 } else { |
152 QTextEdit* textedit = qobject_cast<QTextEdit*>(editorwidget); |
153 QTextEdit *textedit = qobject_cast<QTextEdit *>(editorwidget); |
153 if (textedit) { |
154 if (textedit) { |
154 connect(textedit, SIGNAL(cursorPositionChanged()), newItem, SLOT(cursorPositionChanged())); |
155 connect(textedit, SIGNAL(cursorPositionChanged()), newItem, SLOT(cursorPositionChanged())); |
155 } |
156 } |
156 } |
157 } |
157 } else { |
158 } else { |
158 QLineEdit* lineedit = qobject_cast<QLineEdit*>(editor); |
159 QLineEdit *lineedit = qobject_cast<QLineEdit *>(editor); |
159 if (lineedit) { |
160 if (lineedit) { |
160 connect(lineedit, SIGNAL(cursorPositionChanged(int, int)), newItem, SIGNAL(cursorPositionChanged(int, int))); |
161 connect(lineedit, SIGNAL(cursorPositionChanged(int, int)), newItem, SIGNAL(cursorPositionChanged(int, int))); |
161 } else { |
162 } else { |
162 QTextEdit* textedit = qobject_cast<QTextEdit*>(editor); |
163 QTextEdit *textedit = qobject_cast<QTextEdit *>(editor); |
163 if (textedit) { |
164 if (textedit) { |
164 connect(textedit, SIGNAL(cursorPositionChanged()), newItem, SLOT(cursorPositionChanged())); |
165 connect(textedit, SIGNAL(cursorPositionChanged()), newItem, SLOT(cursorPositionChanged())); |
165 } |
166 } |
166 } |
167 } |
167 } |
168 } |
168 } |
169 } |
169 |
170 |