src/hbwidgets/editors/hbabstractedit.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 7 923ff622b8b9
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
9:730c025d4b77 15:f378acbc9cfb
    34 #include "hbevent.h"
    34 #include "hbevent.h"
    35 #include "hbwidgetfeedback.h"
    35 #include "hbwidgetfeedback.h"
    36 #include "hbmenu.h"
    36 #include "hbmenu.h"
    37 #include "hbaction.h"
    37 #include "hbaction.h"
    38 #include "hbselectioncontrol_p.h"
    38 #include "hbselectioncontrol_p.h"
    39 #include "hbmeshlayout_p.h"
       
    40 #include "hbsmileyengine_p.h"
    39 #include "hbsmileyengine_p.h"
    41 #include "hbinputeditorinterface.h"
    40 #include "hbinputeditorinterface.h"
    42 #include "hbfeaturemanager_p.h"
    41 #include "hbfeaturemanager_r.h"
    43 #include "hbtextmeasurementutility_p.h"
    42 #include "hbtextmeasurementutility_p.h"
    44 #include "hbtapgesture.h"
    43 #include "hbtapgesture.h"
    45 #include "hbpangesture.h"
    44 #include "hbpangesture.h"
       
    45 #include "hbnamespace_p.h"
    46 
    46 
    47 #include <QApplication>
    47 #include <QApplication>
    48 #include "hbpopup.h"
    48 #include "hbpopup.h"
    49 #include "hbformatdialog.h"
    49 #include "hbformatdialog.h"
    50 #include <QTextList>
    50 #include <QTextList>
    52 #include <QPainter>
    52 #include <QPainter>
    53 #include <QTextBlock>
    53 #include <QTextBlock>
    54 #include <QAbstractTextDocumentLayout>
    54 #include <QAbstractTextDocumentLayout>
    55 #include <QClipboard>
    55 #include <QClipboard>
    56 #include <QInputContext>
    56 #include <QInputContext>
       
    57 #include <QGraphicsScene>
    57 
    58 
    58 /*!
    59 /*!
    59     \class HbAbstractEdit
    60     \class HbAbstractEdit
    60     \brief HbAbstractEdit is a base class for all text editors.
    61     \brief HbAbstractEdit is a base class for all text editors.
    61     @proto
    62     @proto
   134 
   135 
   135     This signal is emitted when cursor position has been changed.
   136     This signal is emitted when cursor position has been changed.
   136 */
   137 */
   137 
   138 
   138 /*!
   139 /*!
       
   140   \fn void anchorTapped(const QString &anchor)
       
   141 
       
   142   This signal is emitted when a tap gesture happens on a word which has anchor attached.
       
   143 
       
   144 */
       
   145 
       
   146 /*!
   139     \fn QString HbAbstractEdit::toPlainText() const
   147     \fn QString HbAbstractEdit::toPlainText() const
   140 
   148 
   141     Returns the contents as plain text.
   149     Returns the contents as plain text.
   142 
   150 
   143     \sa QTextDocument::toPlainText()
   151     \sa QTextDocument::toPlainText()
   174 */
   182 */
   175 HbAbstractEdit::~HbAbstractEdit()
   183 HbAbstractEdit::~HbAbstractEdit()
   176 {
   184 {
   177     Q_D(HbAbstractEdit);
   185     Q_D(HbAbstractEdit);
   178     if (d->selectionControl) {
   186     if (d->selectionControl) {
   179         d->selectionControl->detachEditor();
   187         d->selectionControl->detachEditorFromDestructor();
   180     }
   188     }
   181 }
   189 }
   182 
   190 
   183 /*!
   191 /*!
   184     \reimp
   192     \reimp
   192 /*!
   200 /*!
   193     \reimp
   201     \reimp
   194 */
   202 */
   195 bool HbAbstractEdit::event(QEvent* event)
   203 bool HbAbstractEdit::event(QEvent* event)
   196 {
   204 {
       
   205     Q_D(HbAbstractEdit);
       
   206 
   197     if(event->type() ==  QEvent::DynamicPropertyChange) {
   207     if(event->type() ==  QEvent::DynamicPropertyChange) {
   198         const QString p = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName();
   208         const QString p = static_cast<QDynamicPropertyChangeEvent *>(event)->propertyName();
   199         if(p == "SmileyIcon") {
   209         if(p == "SmileyIcon") {
   200             Q_D(HbAbstractEdit);
   210             Q_D(HbAbstractEdit);
   201             QString iconName = property("SmileyIcon").toString();
   211             QString iconName = property("SmileyIcon").toString();
   214             matchCursor.setPosition(oldPos);
   224             matchCursor.setPosition(oldPos);
   215             d->smileyEngineInstance()->insertSmiley(matchCursor);
   225             d->smileyEngineInstance()->insertSmiley(matchCursor);
   216 
   226 
   217             d->cursorChanged(HbValidator::CursorChangeFromContentUpdate);
   227             d->cursorChanged(HbValidator::CursorChangeFromContentUpdate);
   218         }
   228         }
   219     }
   229     } else { //HbEvent handler
       
   230         if (event->type() == HbEvent::InputMethodFocusIn) {
       
   231             d->setInputFocusEnabled(true);
       
   232             
       
   233         } else if (event->type() == HbEvent::InputMethodFocusOut) {
       
   234             d->setInputFocusEnabled(false);
       
   235         }
       
   236     }
       
   237 
   220     return HbWidget::event(event);
   238     return HbWidget::event(event);
   221 }
   239 }
   222 
   240 
   223 QVariant HbAbstractEdit::inputMethodQuery (Qt::InputMethodQuery query) const
   241 QVariant HbAbstractEdit::inputMethodQuery (Qt::InputMethodQuery query) const
   224 {
   242 {
   234         return QVariant(d->cursor.position() - block.position());
   252         return QVariant(d->cursor.position() - block.position());
   235     case Qt::ImSurroundingText:
   253     case Qt::ImSurroundingText:
   236         return QVariant(block.text());
   254         return QVariant(block.text());
   237     case Qt::ImCurrentSelection:
   255     case Qt::ImCurrentSelection:
   238         return QVariant(d->cursor.selectedText());
   256         return QVariant(d->cursor.selectedText());
       
   257     case Qt::ImMaximumTextLength:
       
   258         return QVariant(); // No limit.
       
   259     case Qt::ImAnchorPosition:
       
   260         return QVariant(qBound(0, d->cursor.anchor() - block.position(), block.length()));
   239     default:
   261     default:
   240         return QVariant();
   262         return QVariant();
   241     }
   263     }
   242 }
   264 }
   243 
   265 
   321         d->imAdded = e->commitString().length();
   343         d->imAdded = e->commitString().length();
   322         d->imRemoved =  e->replacementLength();
   344         d->imRemoved =  e->replacementLength();
   323         d->_q_contentsChanged();
   345         d->_q_contentsChanged();
   324     }
   346     }
   325 
   347 
   326     if(hasFocus()) {
   348     if(d->hasInputFocus()) {
   327         d->cursorOn = true;
   349         d->cursorOn = true;
   328     }
   350     }
   329     d->ensureCursorVisible();
   351     d->ensureCursorVisible();
   330 }
   352 }
   331 
   353 
   362     if (d->interactionFlags & Qt::TextSelectableByKeyboard
   384     if (d->interactionFlags & Qt::TextSelectableByKeyboard
   363         && d->cursorMoveKeyEvent(event))
   385         && d->cursorMoveKeyEvent(event))
   364         d->acceptKeyPressEvent(event);
   386         d->acceptKeyPressEvent(event);
   365 
   387 
   366     if (!(d->interactionFlags & Qt::TextEditable)) {
   388     if (!(d->interactionFlags & Qt::TextEditable)) {
   367         d->repaintOldAndNewSelection(d->selectionCursor);
       
   368         d->cursorChanged(HbValidator::CursorChangeFromContentUpdate);
   389         d->cursorChanged(HbValidator::CursorChangeFromContentUpdate);
   369         //ensureCursorVisible();
       
   370         event->ignore();
   390         event->ignore();
   371         return;
   391         return;
   372     }
   392     }
   373 
   393 
   374     if (event->key() == Qt::Key_Direction_L || event->key() == Qt::Key_Direction_R) {
   394     if (event->key() == Qt::Key_Direction_L || event->key() == Qt::Key_Direction_R) {
   471     d->selectionControl = HbSelectionControl::attachEditor(this);
   491     d->selectionControl = HbSelectionControl::attachEditor(this);
   472 
   492 
   473     if (d->interactionFlags & Qt::NoTextInteraction)
   493     if (d->interactionFlags & Qt::NoTextInteraction)
   474         return;
   494         return;
   475 
   495 
   476     update(d->selectionRect());
   496     // It sets the cursor the focus item's depending on if
   477 
   497     // the input panel is connceted or not
   478     if (d->interactionFlags & Qt::TextEditable) {
   498     d->setInputFocusEnabled(d->hasInputFocus());
   479         d->setBlinkingCursorEnabled(true);
       
   480     } else {
       
   481         d->cursorOn = (d->interactionFlags & Qt::TextSelectableByKeyboard);
       
   482     }
       
   483 
       
   484     d->openInputPanel();        
       
   485 
   499 
   486     event->accept();
   500     event->accept();
   487 }
   501 }
   488 
   502 
   489 /*!
   503 /*!
   496     Q_D(HbAbstractEdit);
   510     Q_D(HbAbstractEdit);
   497 
   511 
   498     if (d->interactionFlags & Qt::NoTextInteraction)
   512     if (d->interactionFlags & Qt::NoTextInteraction)
   499         return;
   513         return;
   500 
   514 
   501     d->setBlinkingCursorEnabled(false);
   515     // It sets the cursor the focus item's depending on if
   502     d->repaintOldAndNewSelection(d->selectionCursor);
   516     // the input panel is connceted or not
       
   517     d->setInputFocusEnabled(d->hasInputFocus());
   503 
   518 
   504     event->accept();
   519     event->accept();
   505 }
   520 }
   506 
   521 
   507 /*!
   522 /*!
   549     Q_D(HbAbstractEdit);
   564     Q_D(HbAbstractEdit);
   550     HbWidget::hideEvent(event);
   565     HbWidget::hideEvent(event);
   551 
   566 
   552     deselect();
   567     deselect();
   553 
   568 
   554     if(hasFocus() && !isReadOnly() && !panel()) {
   569     if(d->hasInputFocus() && !isReadOnly() && !panel()) {
   555         d->closeInputPanel();
   570         d->closeInputPanel();
   556     }
   571     }
   557 }
   572 }
   558 
   573 
   559 
   574 
   650     f ^= Qt::TextEditable;
   665     f ^= Qt::TextEditable;
   651 
   666 
   652     d->setTextInteractionFlags(f);
   667     d->setTextInteractionFlags(f);
   653 
   668 
   654     setFlag(QGraphicsItem::ItemAcceptsInputMethod, !value);
   669     setFlag(QGraphicsItem::ItemAcceptsInputMethod, !value);
       
   670 
       
   671     if (value && d->hasInputFocus()) {
       
   672         d->closeInputPanel();
       
   673     }
   655 }
   674 }
   656 
   675 
   657 /*!
   676 /*!
   658 
   677 
   659     \deprecated HbAbstractEdit::primitive(HbStyle::Primitive)
   678     \deprecated HbAbstractEdit::primitive(HbStyle::Primitive)
   681     \reimp
   700     \reimp
   682 */
   701 */
   683 void HbAbstractEdit::updatePrimitives()
   702 void HbAbstractEdit::updatePrimitives()
   684 {
   703 {
   685     Q_D(HbAbstractEdit);
   704     Q_D(HbAbstractEdit);
   686     HbWidget::updatePrimitives();
   705 
   687 
   706     if (d->polished && !d->updatePrimitivesInProgress) {
   688     if (d->scrollArea) {
   707 
   689         d->doc->setTextWidth(d->scrollArea->size().width());
   708         d->updatePrimitivesInProgress = true;
   690         if(d->placeholderDoc) {
   709 
   691             d->placeholderDoc->setTextWidth(d->scrollArea->size().width());
   710         HbWidget::updatePrimitives();
   692         }
   711 
   693     }
   712         if (d->scrollArea) {
   694     QRectF canvasGeom(QRectF(QPointF(0,0),d->doc->size()));
   713             if(!qFuzzyCompare(d->doc->textWidth(), d->scrollArea->size().width())){
   695     if(d->scrollArea) {
   714                 d->doc->setTextWidth(d->scrollArea->size().width());
   696         canvasGeom.setHeight(qMax(d->scrollArea->size().height(), d->doc->size().height()));
   715                 if(d->placeholderDoc) {
   697     }
   716                     d->placeholderDoc->setTextWidth(d->scrollArea->size().width());
   698     //Changed from setGeometry() to setPreferredSize() because it causes
   717                 }
   699     //weird input behavior otherwise.
   718             }
   700     d->canvas->setPreferredSize(canvasGeom.size());
   719         }
   701     d->ensureCursorVisible();
   720         QRectF canvasGeom(QRectF(QPointF(0,0),d->doc->size()));
   702     if (d->selectionControl) {
   721         if(d->scrollArea) {
   703         d->selectionControl->updatePrimitives();
   722             canvasGeom.setHeight(qMax(d->scrollArea->size().height(), d->doc->size().height()));
   704     }
   723         }
   705 
   724 
       
   725         d->canvas->setGeometry(canvasGeom);
       
   726 
       
   727         d->ensureCursorVisible();
       
   728         if (d->selectionControl) {
       
   729             d->selectionControl->updatePrimitives();
       
   730         }
       
   731 
       
   732         d->updatePrimitivesInProgress=false;
       
   733     }
   706 }
   734 }
   707 
   735 
   708 /*!
   736 /*!
   709     Replaces editor content with \a text.
   737     Replaces editor content with \a text.
   710 
   738 
   785     \sa QTextDocument::documentSizeChanged(QSizeF size)
   813     \sa QTextDocument::documentSizeChanged(QSizeF size)
   786 */
   814 */
   787 void HbAbstractEdit::documentSizeChanged(const QSizeF &size)
   815 void HbAbstractEdit::documentSizeChanged(const QSizeF &size)
   788 {
   816 {
   789     Q_UNUSED(size)
   817     Q_UNUSED(size)
       
   818 
   790     updateGeometry();
   819     updateGeometry();
   791     updatePrimitives();
   820     updatePrimitives();
   792 }
   821 }
   793 
   822 
   794 /*!
   823 /*!
   821     Q_D(HbAbstractEdit);
   850     Q_D(HbAbstractEdit);
   822 
   851 
   823     // QTextCursor operator!= compares only position
   852     // QTextCursor operator!= compares only position
   824     if (    cursor.position() != d->cursor.position()
   853     if (    cursor.position() != d->cursor.position()
   825         ||  cursor.anchor() != d->cursor.anchor() ) {
   854         ||  cursor.anchor() != d->cursor.anchor() ) {
   826         const QTextCursor oldCursor = d->cursor;
       
   827         d->cursor = cursor;
   855         d->cursor = cursor;
   828 
   856 
   829         d->updateCurrentCharFormat();
   857         d->updateCurrentCharFormat();
   830 
   858 
   831         d->ensureCursorVisible();
   859         d->ensureCursorVisible();
   832         d->repaintOldAndNewSelection(oldCursor);
       
   833         d->cursorChanged(HbValidator::CursorChangeFromContentSet);
   860         d->cursorChanged(HbValidator::CursorChangeFromContentSet);
   834     }
   861     }
   835 }
   862 }
   836 
   863 
   837 /*!
   864 /*!
   917 
   944 
   918     if (cursorPos == -1)
   945     if (cursorPos == -1)
   919         return;
   946         return;
   920 
   947 
   921     setCursorPosition(cursorPos);
   948     setCursorPosition(cursorPos);
   922     const QTextCursor oldSelection = d->cursor;
       
   923     d->cursor.select(QTextCursor::WordUnderCursor);
   949     d->cursor.select(QTextCursor::WordUnderCursor);
   924     emit selectionChanged(oldSelection, d->cursor);
       
   925     d->repaintOldAndNewSelection(oldSelection);
       
   926     d->cursorChanged(HbValidator::CursorChangeFromMouse);
   950     d->cursorChanged(HbValidator::CursorChangeFromMouse);
   927     //TODO: focus is in VKB so needs to re-focus to editor
       
   928 //    setFocus();
       
   929 }
   951 }
   930 
   952 
   931 /*!
   953 /*!
   932     Selects all the text in the editor.
   954     Selects all the text in the editor.
   933     \sa selectClickedWord deselect
   955     \sa selectClickedWord deselect
   934  */
   956  */
   935 void HbAbstractEdit::selectAll()
   957 void HbAbstractEdit::selectAll()
   936 {
   958 {
   937     Q_D(HbAbstractEdit);
   959     Q_D(HbAbstractEdit);
   938     const QTextCursor oldSelection = d->cursor;
       
   939     d->cursor.select(QTextCursor::Document);
   960     d->cursor.select(QTextCursor::Document);
   940     emit selectionChanged(oldSelection, d->cursor);
       
   941     d->repaintOldAndNewSelection(oldSelection);
       
   942     d->cursorChanged(HbValidator::CursorChangeFromMouse);
   961     d->cursorChanged(HbValidator::CursorChangeFromMouse);
   943 }
   962 }
   944 
   963 
   945 /*!
   964 /*!
   946     Deselects the text in the editor if there is text selected.
   965     Deselects the text in the editor if there is text selected.
   947     \sa selectClickedWord selectAll
   966     \sa selectClickedWord selectAll
   948  */
   967  */
   949 void HbAbstractEdit::deselect()
   968 void HbAbstractEdit::deselect()
   950 {
   969 {
   951     Q_D(HbAbstractEdit);
   970     Q_D(HbAbstractEdit);
   952     const QTextCursor oldSelection = d->cursor;
       
   953     d->cursor.clearSelection();
   971     d->cursor.clearSelection();
   954     emit selectionChanged(oldSelection, d->cursor);
   972     d->cursorChanged(HbValidator::CursorChangeFromMouse);
   955 }
   973 }
   956 
   974 
   957 /*!
   975 /*!
   958     Launches the format user interface.
   976     Launches the format user interface.
   959  */
   977  */
  1011     QTextDocumentFragment fragment;
  1029     QTextDocumentFragment fragment;
  1012 #ifndef QT_NO_TEXTHTMLPARSER
  1030 #ifndef QT_NO_TEXTHTMLPARSER
  1013     if (source->hasFormat(QLatin1String("application/x-qrichtext"))) {
  1031     if (source->hasFormat(QLatin1String("application/x-qrichtext"))) {
  1014         QString richtext = QString::fromUtf8(source->data(QLatin1String("application/x-qrichtext")));
  1032         QString richtext = QString::fromUtf8(source->data(QLatin1String("application/x-qrichtext")));
  1015         richtext.prepend(QLatin1String("<meta name=\"qrichtext\" content=\"1\" />"));        
  1033         richtext.prepend(QLatin1String("<meta name=\"qrichtext\" content=\"1\" />"));        
  1016         fragment = QTextDocumentFragment::fromHtml(filterInputText(richtext), d->doc);
  1034         fragment = QTextDocumentFragment::fromHtml(richtext, d->doc);
  1017         hasData = true;
  1035         hasData = true;
  1018     } else if (source->hasHtml()) {
  1036     } else if (source->hasHtml()) {
  1019         fragment = QTextDocumentFragment::fromHtml(filterInputText(source->html()), d->doc);
  1037         fragment = QTextDocumentFragment::fromHtml(source->html(), d->doc);
  1020         hasData = true;
  1038         hasData = true;
  1021     } else
  1039     } else
  1022 #endif //QT_NO_TEXTHTMLPARSER
  1040 #endif //QT_NO_TEXTHTMLPARSER
  1023     {
  1041     {
  1024         QString text = source->text();
  1042         QString text = source->text();
  1090  */
  1108  */
  1091 void HbAbstractEdit::setValidator(HbValidator* validator)
  1109 void HbAbstractEdit::setValidator(HbValidator* validator)
  1092 {
  1110 {
  1093     Q_D(HbAbstractEdit);
  1111     Q_D(HbAbstractEdit);
  1094 
  1112 
  1095     if(d->validator) {
  1113     d->validator = validator;
  1096         delete d->validator;
  1114     d->initValidator();
  1097         d->validator = 0;
       
  1098     }
       
  1099 
       
  1100     if(validator) {
       
  1101         d->validator = validator;
       
  1102         d->initValidator();
       
  1103     }
       
  1104 }
  1115 }
  1105 
  1116 
  1106 /*!
  1117 /*!
  1107     \property QLineEdit::acceptableInput
  1118     \property QLineEdit::acceptableInput
  1108     This property holds whether the input satisfies the validator.
  1119     This property holds whether the input satisfies the validator.
  1122     \sa QTextCursor::movePosition()
  1133     \sa QTextCursor::movePosition()
  1123  */
  1134  */
  1124 void HbAbstractEdit::moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode)
  1135 void HbAbstractEdit::moveCursor(QTextCursor::MoveOperation op, QTextCursor::MoveMode mode)
  1125 {
  1136 {
  1126     Q_D(HbAbstractEdit);
  1137     Q_D(HbAbstractEdit);
  1127     //const QTextCursor oldCursor = d->cursor;
       
  1128     d->cursor.movePosition(op, mode);
  1138     d->cursor.movePosition(op, mode);
  1129 
  1139 
  1130     d->updateCurrentCharFormat();
  1140     d->updateCurrentCharFormat();
  1131 
  1141 
  1132     d->ensureCursorVisible();
  1142     d->ensureCursorVisible();
  1133     QTextCursor previousCursor(d->cursor);
  1143     QTextCursor previousCursor(d->cursor);
  1134     previousCursor.setPosition(d->previousCursorAnchor);
  1144     previousCursor.setPosition(d->previousCursorAnchor);
  1135     previousCursor.setPosition(d->previousCursorPosition, QTextCursor::KeepAnchor);
  1145     previousCursor.setPosition(d->previousCursorPosition, QTextCursor::KeepAnchor);
  1136     d->repaintOldAndNewSelection(previousCursor);
       
  1137     d->cursorChanged(HbValidator::CursorChangeFromOperation);
  1146     d->cursorChanged(HbValidator::CursorChangeFromOperation);
  1138 }
  1147 }
  1139 
  1148 
  1140 /*!
  1149 /*!
  1141     Returns the bounding rect for given text block.
  1150     Returns the bounding rect for given text block.
  1283 void HbAbstractEdit::showContextMenu(QPointF position)
  1292 void HbAbstractEdit::showContextMenu(QPointF position)
  1284 {
  1293 {
  1285     Q_D(HbAbstractEdit);
  1294     Q_D(HbAbstractEdit);
  1286     HbMenu *menu = createContextMenu();
  1295     HbMenu *menu = createContextMenu();
  1287 
  1296 
       
  1297     QTextBlock block = d->cursor.block();
       
  1298     QTextLayout *layout = block.layout();
       
  1299     if(layout && !layout->preeditAreaText().isEmpty())
       
  1300     {
       
  1301         // there's pre-edit text present, it needs to be commited 1st
       
  1302         if(qApp->inputContext()) {
       
  1303             qApp->inputContext()->reset();
       
  1304         }
       
  1305     }
       
  1306 
  1288     if (!menu) {
  1307     if (!menu) {
  1289         menu = new HbMenu();
  1308         menu = new HbMenu();
  1290     }
  1309     }
  1291 
  1310 
  1292     menu->setAttribute(Hb::InputMethodNeutral);
       
  1293 
       
  1294     if (d->cursor.hasSelection() && d->canCut()) {
  1311     if (d->cursor.hasSelection() && d->canCut()) {
  1295         connect(
  1312         connect(
  1296             menu->addAction("Cut"), SIGNAL(triggered()),
  1313             menu->addAction(hbTrId("txt_common_menu_cut")), SIGNAL(triggered()),
  1297             this, SLOT(cut()));       
  1314             this, SLOT(cut()));       
  1298     }
  1315     }
  1299     if (d->cursor.hasSelection() && d->canCopy()) {
  1316     if (d->cursor.hasSelection() && d->canCopy()) {
  1300         connect(
  1317         connect(
  1301             menu->addAction("Copy"), SIGNAL(triggered()),
  1318             menu->addAction(hbTrId("txt_common_menu_copy")), SIGNAL(triggered()),
  1302             this, SLOT(copy()));
  1319             this, SLOT(copy()));
  1303     }
  1320     }
  1304     if (!d->cursor.hasSelection() && !d->doc->isEmpty() && d->canCopy()){
  1321     if (!d->cursor.hasSelection() && !d->doc->isEmpty() && d->canCopy()){
  1305         connect(
  1322         connect(
  1306             menu->addAction("Select"), SIGNAL(triggered()),
  1323             menu->addAction(hbTrId("txt_common_menu_select")), SIGNAL(triggered()),
  1307             this, SLOT(selectClickedWord()));
  1324             this, SLOT(selectClickedWord()));
  1308         connect(
  1325         connect(
  1309             menu->addAction("Select all"), SIGNAL(triggered()),
  1326             menu->addAction(hbTrId("txt_common_menu_select_all_contents")), SIGNAL(triggered()),
  1310             this, SLOT(selectAll()));
  1327             this, SLOT(selectAll()));
  1311     }
  1328     }
  1312     if (d->canPaste()) {
  1329     if (d->canPaste()) {
  1313         connect(
  1330         connect(
  1314             menu->addAction("Paste"), SIGNAL(triggered()), 
  1331             menu->addAction(hbTrId("txt_common_menu_paste")), SIGNAL(triggered()),
  1315             this, SLOT(paste()));
  1332             this, SLOT(paste()));
  1316     }
  1333     }
  1317     if (d->cursor.hasSelection()) {
  1334     if (d->cursor.hasSelection()) {
  1318         connect(
  1335         connect(
  1319             menu->addAction("Deselect"), SIGNAL(triggered()), 
  1336             menu->addAction(hbTrId("txt_common_menu_deselect")), SIGNAL(triggered()),
  1320             this, SLOT(deselect()));
  1337             this, SLOT(deselect()));
  1321     }
  1338     }
  1322     if (d->canFormat()) {
  1339     if (d->canFormat()) {
  1323         connect(
  1340         connect(
  1324             menu->addAction("Format"), SIGNAL(triggered()), 
  1341             menu->addAction(hbTrId("txt_common_menu_format")), SIGNAL(triggered()),
  1325             this, SLOT(format()));
  1342             this, SLOT(format()));
  1326     }
  1343     }
  1327 
  1344 
  1328     emit aboutToShowContextMenu(menu, d->tapPosition);
  1345     emit aboutToShowContextMenu(menu, d->tapPosition);
  1329 
  1346 
  1330     if(menu->actions().count() > 0){
  1347     if(menu->actions().count() > 0){
  1331         d->minimizeInputPanel();
  1348 //        d->minimizeInputPanel();
  1332         menu->setPreferredPos(position);
  1349         menu->setPreferredPos(position);
  1333         menu->show();
  1350         menu->show();
  1334     }
  1351     }
  1335 }
  1352 }
  1336 
  1353 
  1679         // The QGestureEvent knows the viewport through which the gesture
  1696         // The QGestureEvent knows the viewport through which the gesture
  1680         // was triggered.
  1697         // was triggered.
  1681         QPointF pos = mapFromScene(event->mapToGraphicsScene(tap->position()));
  1698         QPointF pos = mapFromScene(event->mapToGraphicsScene(tap->position()));
  1682         switch(tap->state()) {
  1699         switch(tap->state()) {
  1683         case Qt::GestureStarted:
  1700         case Qt::GestureStarted:
       
  1701             scene()->setProperty(HbPrivate::OverridingGesture.latin1(),Qt::TapGesture);
       
  1702             if (!tap->property(HbPrivate::ThresholdRect.latin1()).toRect().isValid()) {
       
  1703                 tap->setProperty(HbPrivate::ThresholdRect.latin1(), mapRectToScene(boundingRect()).toRect());
       
  1704             }
       
  1705 
  1684             d->tapPosition = pos;
  1706             d->tapPosition = pos;
  1685             HbWidgetFeedback::triggered(this, Hb::InstantPressed);
  1707             HbWidgetFeedback::triggered(this, Hb::InstantPressed);
  1686             break;
  1708             break;
  1687         case Qt::GestureUpdated:
  1709         case Qt::GestureUpdated:
  1688             if(tap->tapStyleHint() == HbTapGesture::TapAndHold) {
  1710             if(tap->tapStyleHint() == HbTapGesture::TapAndHold) {
  1689                 d->longTapGesture(pos);
  1711                 d->openInputPanel();
       
  1712                 d->longTapGesture(pos);                
  1690             }
  1713             }
  1691             break;
  1714             break;
  1692       case Qt::GestureFinished:
  1715       case Qt::GestureFinished:
       
  1716             scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant());
       
  1717 
  1693             if(tap->tapStyleHint() == HbTapGesture::TapAndHold) {
  1718             if(tap->tapStyleHint() == HbTapGesture::TapAndHold) {
  1694             } else {
  1719             } else {
  1695                 d->tapGesture(pos);
  1720                 d->tapGesture(pos);
  1696             }
  1721             }
  1697 
  1722 
  1699 
  1724 
  1700             d->openInputPanel();
  1725             d->openInputPanel();
  1701             
  1726             
  1702             break;
  1727             break;
  1703       case Qt::GestureCanceled:
  1728       case Qt::GestureCanceled:
       
  1729             scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant());
       
  1730 
  1704             break;
  1731             break;
  1705       default:
  1732       default:
  1706             break;
  1733             break;
  1707         }
  1734         }
  1708         event->accept();
  1735         event->accept();
  1714 /*!
  1741 /*!
  1715   Returns the filtered text, or \a text if no input filter attached to editor.
  1742   Returns the filtered text, or \a text if no input filter attached to editor.
  1716 */
  1743 */
  1717 QString HbAbstractEdit::filterInputText(const QString &text)
  1744 QString HbAbstractEdit::filterInputText(const QString &text)
  1718 {
  1745 {
  1719     HbEditorInterface editorInterface(this);
  1746     Q_D(HbAbstractEdit);
  1720     HbInputFilter *inputFilter = editorInterface.filter();
  1747     QString filteredText(text);
  1721     if (!text.isEmpty() && inputFilter) {
  1748     d->filterInputText(filteredText);
  1722         QString filteredText;
  1749     return filteredText;
  1723         foreach(QChar c, text) {
  1750 }
  1724             if (inputFilter->filter(c)) {
       
  1725                 filteredText.append(c);
       
  1726             }
       
  1727         }
       
  1728         return filteredText;
       
  1729     }
       
  1730     return text;
       
  1731 }