equal
deleted
inserted
replaced
28 |
28 |
29 #include "hbstyleoption_p.h" |
29 #include "hbstyleoption_p.h" |
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_p.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 } |
592 /*! |
610 /*! |
593 \reimp |
611 \reimp |
594 */ |
612 */ |
595 bool HbLineEdit::canInsertFromMimeData(const QMimeData *source) const |
613 bool HbLineEdit::canInsertFromMimeData(const QMimeData *source) const |
596 { |
614 { |
597 return source->hasText() && !source->text().isEmpty(); |
615 Q_D(const HbLineEdit); |
|
616 if(source->hasText() && !source->text().isEmpty()) { |
|
617 QString text(source->text()); |
|
618 d->filterInputText(text); |
|
619 return !text.isEmpty(); |
|
620 } else { |
|
621 return false; |
|
622 } |
598 } |
623 } |
599 |
624 |
600 /*! |
625 /*! |
601 \reimp |
626 \reimp |
602 */ |
627 */ |
626 /*! |
651 /*! |
627 \reimp |
652 \reimp |
628 */ |
653 */ |
629 void HbLineEdit::focusOutEvent(QFocusEvent * event) |
654 void HbLineEdit::focusOutEvent(QFocusEvent * event) |
630 { |
655 { |
631 Q_D(HbLineEdit); |
656 HbAbstractEdit::focusOutEvent(event); |
632 |
|
633 if(echoMode() == HbLineEdit::PasswordEchoOnEdit) { |
|
634 setPlainText(d->passwordString(d->passwordText)); |
|
635 } |
|
636 |
|
637 HbAbstractEdit::focusOutEvent(event); |
|
638 |
|
639 emit editingFinished(); |
|
640 } |
657 } |
641 |
658 |
642 /*! |
659 /*! |
643 \reimp |
660 \reimp |
644 */ |
661 */ |
645 void HbLineEdit::focusInEvent(QFocusEvent * event) |
662 void HbLineEdit::focusInEvent(QFocusEvent * event) |
646 { |
663 { |
647 Q_D(HbLineEdit); |
|
648 |
|
649 if(echoMode() == HbLineEdit::PasswordEchoOnEdit) { |
|
650 // we need to clear the editor when typing starts |
|
651 d->clearOnEdit = true; |
|
652 } |
|
653 |
|
654 HbAbstractEdit::focusInEvent(event); |
664 HbAbstractEdit::focusInEvent(event); |
655 } |
665 } |
656 |
666 |
657 /*! |
667 /*! |
658 @proto |
668 @proto |
681 updateGeometry(); |
691 updateGeometry(); |
682 } |
692 } |
683 } |
693 } |
684 |
694 |
685 /*! |
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 /*! |
686 @proto |
719 @proto |
687 |
720 |
688 Returns true if vertical font streach mode is active. |
721 Returns true if vertical font streach mode is active. |
689 See HbLineEdit::setAdjustFontSizeToFitHeight for details. |
722 See HbLineEdit::setAdjustFontSizeToFitHeight for details. |
690 |
723 |
706 document()->setTextWidth(d->scrollArea->size().width()); |
739 document()->setTextWidth(d->scrollArea->size().width()); |
707 d->onResizeFontChange(); |
740 d->onResizeFontChange(); |
708 } |
741 } |
709 return HbAbstractEdit::eventFilter(obj, event); |
742 return HbAbstractEdit::eventFilter(obj, event); |
710 } |
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 } |