equal
deleted
inserted
replaced
30 #include "hbscrollarea.h" |
30 #include "hbscrollarea.h" |
31 #ifdef HB_TEXT_MEASUREMENT_UTILITY |
31 #ifdef HB_TEXT_MEASUREMENT_UTILITY |
32 #include "hbtextmeasurementutility_p.h" |
32 #include "hbtextmeasurementutility_p.h" |
33 #include "hbfeaturemanager_r.h" |
33 #include "hbfeaturemanager_r.h" |
34 #endif //HB_TEXT_MEASUREMENT_UTILITY |
34 #endif //HB_TEXT_MEASUREMENT_UTILITY |
|
35 #include "hbevent.h" |
35 |
36 |
36 #include <QFontMetrics> |
37 #include <QFontMetrics> |
37 #include <QPainter> |
38 #include <QPainter> |
38 #include <QTextBlock> |
39 #include <QTextBlock> |
39 #include <QTextDocument> |
40 #include <QTextDocument> |
40 #include <QGraphicsSceneResizeEvent> |
41 #include <QGraphicsSceneResizeEvent> |
|
42 #include <QGraphicsLinearLayout> |
41 |
43 |
42 /*! |
44 /*! |
43 \class HbLineEdit |
45 \class HbLineEdit |
44 \brief HbLineEdit is a one line text editor widget |
46 \brief HbLineEdit is a one line text editor widget |
45 @alpha |
47 @alpha |
281 */ |
283 */ |
282 void HbLineEdit::inputMethodEvent(QInputMethodEvent *e) |
284 void HbLineEdit::inputMethodEvent(QInputMethodEvent *e) |
283 { |
285 { |
284 Q_D(HbLineEdit); |
286 Q_D(HbLineEdit); |
285 |
287 |
286 if(d->echoMode == HbLineEdit::PasswordEchoOnEdit && d->clearOnEdit) { |
288 if((!e->commitString().isEmpty() || e->replacementLength()) && |
|
289 d->echoMode == HbLineEdit::PasswordEchoOnEdit && d->clearOnEdit) { |
287 d->doc->clear(); |
290 d->doc->clear(); |
288 d->passwordText.clear(); |
291 d->passwordText.clear(); |
289 d->clearOnEdit = false; |
292 d->clearOnEdit = false; |
290 } |
293 } |
291 |
294 |
309 } |
312 } |
310 } |
313 } |
311 HbAbstractEdit::inputMethodEvent(e); |
314 HbAbstractEdit::inputMethodEvent(e); |
312 } |
315 } |
313 |
316 |
|
317 |
|
318 /*! |
|
319 \reimp |
|
320 */ |
|
321 QVariant HbLineEdit::inputMethodQuery(Qt::InputMethodQuery property) const |
|
322 { |
|
323 switch(property) { |
|
324 case Qt::ImMaximumTextLength: |
|
325 return QVariant(maxLength()); |
|
326 default: |
|
327 return HbAbstractEdit::inputMethodQuery(property); |
|
328 } |
|
329 } |
|
330 |
|
331 |
314 /*! |
332 /*! |
315 \reimp |
333 \reimp |
316 */ |
334 */ |
317 |
335 |
318 void HbLineEdit::keyPressEvent (QKeyEvent *event) |
336 void HbLineEdit::keyPressEvent (QKeyEvent *event) |
355 void HbLineEdit::keyReleaseEvent (QKeyEvent *event) |
373 void HbLineEdit::keyReleaseEvent (QKeyEvent *event) |
356 { |
374 { |
357 Q_D(HbLineEdit); |
375 Q_D(HbLineEdit); |
358 |
376 |
359 if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { |
377 if (event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return) { |
360 emit editingFinished(); |
378 d->editingFinished(); |
361 } |
379 } |
362 |
380 |
363 if(d->forwardKeyEvent(event)) { |
381 if(d->forwardKeyEvent(event)) { |
364 HbAbstractEdit::keyReleaseEvent(event); |
382 HbAbstractEdit::keyReleaseEvent(event); |
365 } |
383 } |
633 /*! |
651 /*! |
634 \reimp |
652 \reimp |
635 */ |
653 */ |
636 void HbLineEdit::focusOutEvent(QFocusEvent * event) |
654 void HbLineEdit::focusOutEvent(QFocusEvent * event) |
637 { |
655 { |
638 Q_D(HbLineEdit); |
656 HbAbstractEdit::focusOutEvent(event); |
639 |
|
640 if(echoMode() == HbLineEdit::PasswordEchoOnEdit) { |
|
641 setPlainText(d->passwordString(d->passwordText)); |
|
642 } |
|
643 |
|
644 HbAbstractEdit::focusOutEvent(event); |
|
645 |
|
646 emit editingFinished(); |
|
647 } |
657 } |
648 |
658 |
649 /*! |
659 /*! |
650 \reimp |
660 \reimp |
651 */ |
661 */ |
652 void HbLineEdit::focusInEvent(QFocusEvent * event) |
662 void HbLineEdit::focusInEvent(QFocusEvent * event) |
653 { |
663 { |
654 Q_D(HbLineEdit); |
|
655 |
|
656 if(echoMode() == HbLineEdit::PasswordEchoOnEdit) { |
|
657 // we need to clear the editor when typing starts |
|
658 d->clearOnEdit = true; |
|
659 } |
|
660 |
|
661 HbAbstractEdit::focusInEvent(event); |
664 HbAbstractEdit::focusInEvent(event); |
662 } |
665 } |
663 |
666 |
664 /*! |
667 /*! |
665 @proto |
668 @proto |
688 updateGeometry(); |
691 updateGeometry(); |
689 } |
692 } |
690 } |
693 } |
691 |
694 |
692 /*! |
695 /*! |
|
696 \reimp |
|
697 */ |
|
698 bool HbLineEdit::event(QEvent* event) |
|
699 { |
|
700 Q_D(HbLineEdit); |
|
701 |
|
702 if (event->type() == HbEvent::InputMethodFocusIn) { |
|
703 if(echoMode() == HbLineEdit::PasswordEchoOnEdit) { |
|
704 // we need to clear the editor when typing starts |
|
705 d->clearOnEdit = true; |
|
706 } |
|
707 d->showCustomAutoCompPopup(); |
|
708 } else if (event->type() == HbEvent::InputMethodFocusOut) { |
|
709 d->hideCustomAutoCompPopup(); |
|
710 d->editingFinished(); |
|
711 } |
|
712 |
|
713 return HbAbstractEdit::event(event); |
|
714 } |
|
715 |
|
716 |
|
717 |
|
718 /*! |
693 @proto |
719 @proto |
694 |
720 |
695 Returns true if vertical font streach mode is active. |
721 Returns true if vertical font streach mode is active. |
696 See HbLineEdit::setAdjustFontSizeToFitHeight for details. |
722 See HbLineEdit::setAdjustFontSizeToFitHeight for details. |
697 |
723 |
713 document()->setTextWidth(d->scrollArea->size().width()); |
739 document()->setTextWidth(d->scrollArea->size().width()); |
714 d->onResizeFontChange(); |
740 d->onResizeFontChange(); |
715 } |
741 } |
716 return HbAbstractEdit::eventFilter(obj, event); |
742 return HbAbstractEdit::eventFilter(obj, event); |
717 } |
743 } |
|
744 |
|
745 /*! |
|
746 set content of custum auto-complate pupup. |
|
747 */ |
|
748 void HbLineEdit::setAutoCompleteContent(QGraphicsLayoutItem *content) |
|
749 { |
|
750 Q_D(HbLineEdit); |
|
751 |
|
752 if (!d->mCustomAutoCompPopup) { |
|
753 d->createCustomAutoCompPopup(); |
|
754 repolish(); |
|
755 } |
|
756 |
|
757 if (d->mCustomAutoCompContent!=content) { |
|
758 if (d->mCustomAutoCompContent) { |
|
759 delete d->mCustomAutoCompContent; |
|
760 } |
|
761 |
|
762 d->mCustomAutoCompContent = content; |
|
763 |
|
764 if (content->isLayout()) { |
|
765 d->mCustomAutoCompPopup->setLayout(static_cast<QGraphicsLayout *>(content)); |
|
766 } else { |
|
767 QGraphicsLinearLayout *linLayout = new QGraphicsLinearLayout(Qt::Horizontal, |
|
768 d->mCustomAutoCompPopup); |
|
769 linLayout->addItem(content); |
|
770 } |
|
771 if (hasFocus()) { |
|
772 d->showCustomAutoCompPopup(); |
|
773 } |
|
774 } |
|
775 } |