35 |
35 |
36 //Localization |
36 //Localization |
37 #define LOC_PASTE hbTrId("txt_common_menu_paste") |
37 #define LOC_PASTE hbTrId("txt_common_menu_paste") |
38 |
38 |
39 MsgUnifiedEditorLineEdit::MsgUnifiedEditorLineEdit(const QString& label,QGraphicsItem *parent): |
39 MsgUnifiedEditorLineEdit::MsgUnifiedEditorLineEdit(const QString& label,QGraphicsItem *parent): |
40 HbLineEdit(parent), |
40 HbTextEdit(parent), |
41 mSelectionStart(-1), |
41 mSelectionStart(-1), |
42 mSelectionEnd(-1), |
42 mSelectionEnd(-1), |
43 mDefaultBehaviour(false) |
43 mDefaultBehaviour(false) |
44 { |
44 { |
45 QString labelStr = label.trimmed(); |
45 QString labelStr = label.trimmed(); |
100 QString str = event->commitString(); |
100 QString str = event->commitString(); |
101 str.replace(expr, replacementStr); |
101 str.replace(expr, replacementStr); |
102 |
102 |
103 event->setCommitString(str, event->replacementStart(), event->replacementLength()); |
103 event->setCommitString(str, event->replacementStart(), event->replacementLength()); |
104 } |
104 } |
105 else if(this->hasSelectedText()) |
105 else if(this->textCursor().hasSelection()) |
106 {// all user inputs get appended at the end |
106 {// all user inputs get appended at the end |
107 this->setCursorPosition(this->text().length()); |
107 this->setCursorPosition(this->text().length()); |
108 } |
108 } |
109 } |
109 } |
110 |
110 |
111 HbAbstractEdit::inputMethodEvent(event); |
111 HbTextEdit::inputMethodEvent(event); |
112 event->accept(); |
112 event->accept(); |
113 } |
113 } |
114 |
114 |
115 void MsgUnifiedEditorLineEdit::keyPressEvent(QKeyEvent *event) |
115 void MsgUnifiedEditorLineEdit::keyPressEvent(QKeyEvent *event) |
116 { |
116 { |
130 return; |
130 return; |
131 } |
131 } |
132 this->setCursorPosition(this->text().length()); |
132 this->setCursorPosition(this->text().length()); |
133 str = replacementStr; |
133 str = replacementStr; |
134 QKeyEvent eve(event->type(), Qt::Key_Any, event->modifiers(), str); |
134 QKeyEvent eve(event->type(), Qt::Key_Any, event->modifiers(), str); |
135 HbAbstractEdit::keyPressEvent(&eve); |
135 HbTextEdit::keyPressEvent(&eve); |
136 event->accept(); |
136 event->accept(); |
137 return; |
137 return; |
138 } |
138 } |
139 |
139 |
140 if(event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete ) |
140 if(event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete ) |
141 { |
141 { |
142 int pos = this->cursorPosition(); |
142 int pos = this->cursorPosition(); |
143 bool pbkContact = true; |
143 bool pbkContact = true; |
144 |
144 |
145 if(!this->hasSelectedText()) |
145 if(!this->textCursor().hasSelection()) |
146 { |
146 { |
147 this->setCursorPosition(pos-2); |
147 this->setCursorPosition(pos-2); |
148 pbkContact = this->textCursor().charFormat().fontUnderline(); |
148 pbkContact = this->textCursor().charFormat().fontUnderline(); |
149 this->setCursorPosition(pos); |
149 this->setCursorPosition(pos); |
150 } |
150 } |
159 } |
159 } |
160 |
160 |
161 if(pbkContact) |
161 if(pbkContact) |
162 { |
162 { |
163 //if already selected delete it. |
163 //if already selected delete it. |
164 if(this->hasSelectedText()) |
164 if(this->textCursor().hasSelection()) |
165 { |
165 { |
166 // deleting phbkContact is an atomic operation |
166 // deleting phbkContact is an atomic operation |
167 // ensure that the signal is emitted only once |
167 // ensure that the signal is emitted only once |
168 disconnect(this, SIGNAL(contentsChanged()), |
168 disconnect(this, SIGNAL(contentsChanged()), |
169 this, SLOT(onContentsChanged())); |
169 this, SLOT(onContentsChanged())); |
170 HbLineEdit::keyPressEvent(event); |
170 HbTextEdit::keyPressEvent(event); |
171 event->accept(); |
171 event->accept(); |
172 //delete seperator (i.e."; "). |
172 //delete seperator (i.e."; "). |
173 QKeyEvent eve(event->type(), Qt::Key_Delete, Qt::NoModifier); |
173 QKeyEvent eve(event->type(), Qt::Key_Delete, Qt::NoModifier); |
174 HbLineEdit::keyPressEvent(&eve); |
174 HbTextEdit::keyPressEvent(&eve); |
175 HbLineEdit::keyPressEvent(&eve); |
175 HbTextEdit::keyPressEvent(&eve); |
176 connect(this, SIGNAL(contentsChanged()), |
176 connect(this, SIGNAL(contentsChanged()), |
177 this, SLOT(onContentsChanged())); |
177 this, SLOT(onContentsChanged())); |
178 onContentsChanged(); |
178 onContentsChanged(); |
179 } |
179 } |
180 else //make it selected |
180 else //make it selected |
192 // ensure that the signal is emitted only once |
192 // ensure that the signal is emitted only once |
193 disconnect(this, SIGNAL(contentsChanged()), |
193 disconnect(this, SIGNAL(contentsChanged()), |
194 this, SLOT(onContentsChanged())); |
194 this, SLOT(onContentsChanged())); |
195 //delete seperator (i.e."; "). |
195 //delete seperator (i.e."; "). |
196 QKeyEvent eve(event->type(), Qt::Key_Backspace, Qt::NoModifier); |
196 QKeyEvent eve(event->type(), Qt::Key_Backspace, Qt::NoModifier); |
197 HbLineEdit::keyPressEvent(&eve); |
197 HbTextEdit::keyPressEvent(&eve); |
198 HbLineEdit::keyPressEvent(&eve); |
198 HbTextEdit::keyPressEvent(&eve); |
199 connect(this, SIGNAL(contentsChanged()), |
199 connect(this, SIGNAL(contentsChanged()), |
200 this, SLOT(onContentsChanged())); |
200 this, SLOT(onContentsChanged())); |
201 onContentsChanged(); |
201 onContentsChanged(); |
202 } |
202 } |
203 else |
203 else |
204 { |
204 { |
205 HbLineEdit::keyPressEvent(event); |
205 HbTextEdit::keyPressEvent(event); |
206 } |
206 } |
207 event->accept(); |
207 event->accept(); |
208 } |
208 } |
209 |
209 |
210 event->accept(); |
210 event->accept(); |
211 return; |
211 return; |
212 } |
212 } |
213 |
213 |
214 if (event->key() == Qt::Key_Left ) |
214 if (event->key() == Qt::Key_Left ) |
215 { |
215 { |
216 bool selectedText = this->hasSelectedText(); |
216 bool selectedText = this->textCursor().hasSelection(); |
217 |
217 |
218 //look ahead left. |
218 //look ahead left. |
219 int pos = this->cursorPosition(); |
219 int pos = this->cursorPosition(); |
220 |
220 |
221 QString text = this->text(); |
221 QString text = this->text(); |
264 if( (newPos > 0 && selectedText) || (pos-2 == newPos)) |
264 if( (newPos > 0 && selectedText) || (pos-2 == newPos)) |
265 { |
265 { |
266 this->setCursorPosition(newPos+1); |
266 this->setCursorPosition(newPos+1); |
267 } |
267 } |
268 |
268 |
269 HbLineEdit::keyPressEvent(event); |
269 HbTextEdit::keyPressEvent(event); |
270 |
270 |
271 } |
271 } |
272 event->accept(); |
272 event->accept(); |
273 return; |
273 return; |
274 } |
274 } |
275 |
275 |
276 if (event->key() == Qt::Key_Right) |
276 if (event->key() == Qt::Key_Right) |
277 { |
277 { |
278 bool selectedText = this->hasSelectedText(); |
278 bool selectedText = this->textCursor().hasSelection(); |
279 |
279 |
280 //look ahead. |
280 //look ahead. |
281 int pos = this->cursorPosition(); |
281 int pos = this->cursorPosition(); |
282 this->setCursorPosition(pos+3); |
282 this->setCursorPosition(pos+3); |
283 bool pbkContact = this->textCursor().charFormat().fontUnderline(); |
283 bool pbkContact = this->textCursor().charFormat().fontUnderline(); |
299 if(selectedText || seperatorPos == pos) |
299 if(selectedText || seperatorPos == pos) |
300 { |
300 { |
301 this->setCursorPosition(pos+1); |
301 this->setCursorPosition(pos+1); |
302 this->deselect(); |
302 this->deselect(); |
303 } |
303 } |
304 HbAbstractEdit::keyPressEvent(event); |
304 HbTextEdit::keyPressEvent(event); |
305 } |
305 } |
306 event->accept(); |
306 event->accept(); |
307 return; |
307 return; |
308 } |
308 } |
309 |
309 |
310 if(!str.isEmpty()) |
310 if(!str.isEmpty()) |
311 { |
311 { |
312 if(mDefaultBehaviour) |
312 if(mDefaultBehaviour) |
313 { |
313 { |
314 HbAbstractEdit::keyPressEvent(event); |
314 HbTextEdit::keyPressEvent(event); |
315 event->accept(); |
315 event->accept(); |
316 return; |
316 return; |
317 } |
317 } |
318 if (str.contains(expr)) |
318 if (str.contains(expr)) |
319 { |
319 { |
332 this->setCursorPosition(this->text().length()); |
332 this->setCursorPosition(this->text().length()); |
333 } |
333 } |
334 |
334 |
335 str.replace(expr, replacementStr); |
335 str.replace(expr, replacementStr); |
336 QKeyEvent eve(event->type(), event->key(), event->modifiers(), str); |
336 QKeyEvent eve(event->type(), event->key(), event->modifiers(), str); |
337 HbAbstractEdit::keyPressEvent(&eve); |
337 HbTextEdit::keyPressEvent(&eve); |
338 } |
338 } |
339 else |
339 else |
340 { |
340 { |
341 HbAbstractEdit::keyPressEvent(event); |
341 HbTextEdit::keyPressEvent(event); |
342 event->accept(); |
342 event->accept(); |
343 return; |
343 return; |
344 } |
344 } |
345 } |
345 } |
346 } |
346 } |
357 txt = txt.right(txt.length() - currentPos); |
357 txt = txt.right(txt.length() - currentPos); |
358 int labelPos = txt.indexOf(labelSeperator); |
358 int labelPos = txt.indexOf(labelSeperator); |
359 |
359 |
360 if(labelPos >= 0 )//pressed on label. |
360 if(labelPos >= 0 )//pressed on label. |
361 { |
361 { |
362 this->setCursorPosition(currentPos + labelPos + 2); |
362 HbTextEdit::setCursorPosition(currentPos + labelPos + 2); |
363 } |
363 } |
364 else if(seperatorPos == currentPos-1 || seperatorPos == currentPos)//pressed just on seperator. |
364 else if(seperatorPos == currentPos-1 || seperatorPos == currentPos)//pressed just on seperator. |
365 { |
365 { |
366 this->setCursorPosition(seperatorPos+2); |
366 HbTextEdit::setCursorPosition(seperatorPos+2); |
367 } |
367 } |
368 else |
368 else |
369 { |
369 { |
370 this->setCursorPosition(currentPos+1); |
370 HbTextEdit::setCursorPosition(currentPos); |
371 bool pbkContact = this->textCursor().charFormat().fontUnderline(); |
371 bool pbkContact = this->textCursor().charFormat().fontUnderline(); |
372 if(pbkContact) |
372 if(pbkContact) |
373 { |
373 { |
374 setHighlight(currentPos); |
374 setHighlight(currentPos); |
375 } |
375 } |
379 } |
379 } |
380 |
380 |
381 void MsgUnifiedEditorLineEdit::gestureEvent(QGestureEvent* event) |
381 void MsgUnifiedEditorLineEdit::gestureEvent(QGestureEvent* event) |
382 { |
382 { |
383 //passing gesture event to base class. |
383 //passing gesture event to base class. |
384 HbLineEdit::gestureEvent(event); |
384 HbTextEdit::gestureEvent(event); |
385 |
385 |
386 |
386 |
387 if(HbTapGesture *tap = qobject_cast<HbTapGesture*>(event->gesture(Qt::TapGesture))) |
387 if(HbTapGesture *tap = qobject_cast<HbTapGesture*>(event->gesture(Qt::TapGesture))) |
388 { |
388 { |
389 //capturing gesture position, and map to local co-ordinates. |
389 //capturing gesture position, and map to local co-ordinates. |
460 return list; |
460 return list; |
461 } |
461 } |
462 |
462 |
463 void MsgUnifiedEditorLineEdit::focusInEvent(QFocusEvent* event) |
463 void MsgUnifiedEditorLineEdit::focusInEvent(QFocusEvent* event) |
464 { |
464 { |
465 HbLineEdit::focusInEvent(event); |
465 HbTextEdit::focusInEvent(event); |
466 this->setCursorVisibility(Hb::TextCursorVisible); |
466 // this->setCursorVisibility(Hb::TextCursorVisible); |
467 } |
467 } |
468 |
468 |
469 void MsgUnifiedEditorLineEdit::focusOutEvent(QFocusEvent* event) |
469 void MsgUnifiedEditorLineEdit::focusOutEvent(QFocusEvent* event) |
470 { |
470 { |
471 HbLineEdit::focusOutEvent(event); |
471 HbTextEdit::focusOutEvent(event); |
472 this->setCursorVisibility(Hb::TextCursorHidden); |
472 // this->setCursorVisibility(Hb::TextCursorHidden); |
473 } |
473 } |
474 |
474 |
475 void MsgUnifiedEditorLineEdit::setHighlight(int currentPos) |
475 void MsgUnifiedEditorLineEdit::setHighlight(int currentPos) |
476 { |
476 { |
477 QString txt = this->text(); |
477 QString txt = this->text(); |
531 } |
531 } |
532 |
532 |
533 void MsgUnifiedEditorLineEdit::timerEvent(QTimerEvent *event) |
533 void MsgUnifiedEditorLineEdit::timerEvent(QTimerEvent *event) |
534 { |
534 { |
535 //passing event to base class. |
535 //passing event to base class. |
536 HbLineEdit::timerEvent(event); |
536 HbTextEdit::timerEvent(event); |
537 |
537 |
538 if (event->timerId() == mSelectionSnapTimer.timerId()) |
538 if (event->timerId() == mSelectionSnapTimer.timerId()) |
539 { |
539 { |
540 mSelectionSnapTimer.stop(); |
540 mSelectionSnapTimer.stop(); |
541 |
541 |
569 mDefaultBehaviour = defaultBehaviour; |
569 mDefaultBehaviour = defaultBehaviour; |
570 } |
570 } |
571 |
571 |
572 QString MsgUnifiedEditorLineEdit::text() const |
572 QString MsgUnifiedEditorLineEdit::text() const |
573 { |
573 { |
574 return HbLineEdit::text(); |
574 return this->toPlainText(); |
575 } |
575 } |
576 |
576 |
577 QString MsgUnifiedEditorLineEdit::content() const |
577 QString MsgUnifiedEditorLineEdit::content() const |
578 { |
578 { |
579 QString text = this->text(); |
579 QString text = this->text(); |
635 contextMenu->addAction(LOC_PASTE,this,SLOT(paste())); |
635 contextMenu->addAction(LOC_PASTE,this,SLOT(paste())); |
636 } |
636 } |
637 } |
637 } |
638 |
638 |
639 } |
639 } |
|
640 |
|
641 void MsgUnifiedEditorLineEdit::setSelection(int start, int length) |
|
642 { |
|
643 int textLength = text().count(); |
|
644 QString test = text(); |
|
645 Q_UNUSED(test) |
|
646 if (start < 0 || start > textLength) { |
|
647 return; |
|
648 } |
|
649 |
|
650 int end(start+length); |
|
651 if (end > textLength) { |
|
652 end = textLength; |
|
653 } else if (end < 0) { |
|
654 end = 0; |
|
655 } |
|
656 |
|
657 QTextCursor cursor = textCursor(); |
|
658 cursor.setPosition(start, QTextCursor::MoveAnchor); |
|
659 cursor.setPosition(end, QTextCursor::KeepAnchor); |
|
660 setTextCursor(cursor); |
|
661 |
|
662 } |
640 // eof |
663 // eof |