src/hbcore/inputfw/hbinputfocusobject.cpp
changeset 1 f7ac710697a9
parent 0 16d8024aca5e
child 2 06ff229162e9
equal deleted inserted replaced
0:16d8024aca5e 1:f7ac710697a9
    43 @hbcore
    43 @hbcore
    44 \class HbInputFocusObject
    44 \class HbInputFocusObject
    45 \brief A helper class for accessing editor widget in abstract way.
    45 \brief A helper class for accessing editor widget in abstract way.
    46 
    46 
    47 This class is input method side API for accessing editor widgets. It was added because
    47 This class is input method side API for accessing editor widgets. It was added because
    48 in some cases Qt's QInputMethodEvent/inputMethodQuery system is not enough for our purposes
    48 in some cases Qt's QInputMethodEvent/inputMethodQuery system is not enough and direct
    49 and direct access via type casting between QWidget and QGraphiscWidget based editors is needed.
    49 access via type casting between QWidget and QGraphiscWidget based editors is needed.
       
    50 Focus object hides those cases behind a convinience API.
    50 
    51 
    51 This class is purely a convenience or helper type of class in nature. Everything
    52 This class is purely a convenience or helper type of class in nature. Everything
    52 it does, can be done directly in input method code as well. It just wraps
    53 it does, can be done directly in input method code as well. It just wraps
    53 most commonly used operations behind one API to avoid duplicate code in input method implementations.
    54 most commonly used operations behind one API to avoid duplicate code.
    54 
    55 
    55 Application developers should never need to use this class, it is for input method developers only.
    56 Application developers should never need to use this class, it is for input method developers only.
    56 
    57 
    57 \sa HbEditorInterface
    58 \sa HbEditorInterface
    58 */
    59 */
    59 
       
    60 
       
    61 
    60 
    62 /// @cond
    61 /// @cond
    63 
    62 
    64 /*
    63 /*
    65 This function ensures cursor visibility for known editor types.
    64 This function ensures cursor visibility for known editor types.
   233 {
   232 {
   234     return d_ptr->mEditorInterface;
   233     return d_ptr->mEditorInterface;
   235 }
   234 }
   236 
   235 
   237 /*!
   236 /*!
       
   237 \deprecated HbInputFocusObject::cursorLeft(int)
       
   238   is deprecated. Use HbInputFocusObject::cursorLeft(Qt::KeyboardModifiers modifiers) instead.
   238 Sends left arrow key press to focused editor.
   239 Sends left arrow key press to focused editor.
   239 */
   240 */
   240 void HbInputFocusObject::cursorLeft(int modifiers)
   241 void HbInputFocusObject::cursorLeft(int modifiers)
   241 {
   242 {
   242     QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Left, (Qt::KeyboardModifiers)modifiers);
   243     cursorLeft(static_cast<Qt::KeyboardModifiers>(modifiers));
       
   244 }
       
   245 
       
   246 /*!
       
   247 \deprecated HbInputFocusObject::cursorRight(int)
       
   248   is deprecated. Use HbInputFocusObject::cursorRight(Qt::KeyboardModifiers modifiers) instead.
       
   249 Sends right arrow key press to focused editor.
       
   250 */
       
   251 void HbInputFocusObject::cursorRight(int modifiers)
       
   252 {
       
   253     cursorRight(static_cast<Qt::KeyboardModifiers>(modifiers));
       
   254 }
       
   255 
       
   256 /*!
       
   257 Sends left arrow key press to focused editor.
       
   258 */
       
   259 void HbInputFocusObject::cursorLeft(Qt::KeyboardModifiers modifiers)
       
   260 {
       
   261     QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Left, modifiers);
   243     sendEvent(keyEvent);
   262     sendEvent(keyEvent);
   244 }
   263 }
   245 
   264 
   246 /*!
   265 /*!
   247 Sends right arrow key press to focused editor.
   266 Sends right arrow key press to focused editor.
   248 */
   267 */
   249 void HbInputFocusObject::cursorRight(int modifiers)
   268 void HbInputFocusObject::cursorRight(Qt::KeyboardModifiers modifiers)
   250 {
   269 {
   251     QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Right, (Qt::KeyboardModifiers)modifiers);
   270     QKeyEvent keyEvent(QEvent::KeyPress, Qt::Key_Right, modifiers);
   252     sendEvent(keyEvent);
   271     sendEvent(keyEvent);
   253 }
   272 }
   254 
   273 
   255 /*!
   274 /*!
   256 Removes focus from the editor.
   275 Removes focus from the editor.
   278 
   297 
   279 /*!
   298 /*!
   280 Runs the given character through active input filter and commits it if it was accepted.
   299 Runs the given character through active input filter and commits it if it was accepted.
   281 Returns true if the character was accepted.
   300 Returns true if the character was accepted.
   282 */
   301 */
   283 bool HbInputFocusObject::filterAndCommitCharacter(QChar aChar)
   302 bool HbInputFocusObject::filterAndCommitCharacter(QChar character)
   284 {
   303 {
   285     // Two pass filtering because this may be a case constrained editor
   304     // Two pass filtering because this may be a case constrained editor
   286     // with a filter.
   305     // with a filter.
   287     Qt::InputMethodHints hints = inputMethodHints();
   306     Qt::InputMethodHints hints = inputMethodHints();
   288     if (hints & Qt::ImhLowercaseOnly) {
   307     if (hints & Qt::ImhLowercaseOnly) {
   289         if (!HbInputLowerCaseFilter::instance()->filter(aChar)) {
   308         if (!HbInputLowerCaseFilter::instance()->filter(character)) {
   290             return false;
   309             return false;
   291         }
   310         }
   292     } else if (hints & Qt::ImhUppercaseOnly) {
   311     } else if (hints & Qt::ImhUppercaseOnly) {
   293         if (!HbInputUpperCaseFilter::instance()->filter(aChar)) {
   312         if (!HbInputUpperCaseFilter::instance()->filter(character)) {
   294             return false;
   313             return false;
   295         }
   314         }
   296     }
   315     }
   297 
   316 
   298     HbInputFilter *filter = editorInterface().filter();
   317     HbInputFilter *filter = editorInterface().filter();
   299     if (filter) {
   318     if (filter) {
   300         if (!filter->filter(aChar)) {
   319         if (!filter->filter(character)) {
   301             return false;
   320             return false;
   302         }
   321         }
   303     }
   322     }
   304 
   323 
   305     QString cString;
   324     QString cString;
   306     cString.append(aChar);
   325     cString.append(character);
   307     sendCommitString(cString);
   326     sendCommitString(cString);
   308 
   327 
   309     return true;
   328     return true;
   310 }
   329 }
   311 
   330 
   338 /*!
   357 /*!
   339 Returns cursor micro focus by sending Qt::ImMicroFocus to focused editor.
   358 Returns cursor micro focus by sending Qt::ImMicroFocus to focused editor.
   340 In case of QGraphicsWidget, the returned rectangle is in scene coordinates.
   359 In case of QGraphicsWidget, the returned rectangle is in scene coordinates.
   341 */
   360 */
   342 QRectF HbInputFocusObject::microFocus() const
   361 QRectF HbInputFocusObject::microFocus() const
   343 {  
   362 {
   344     return inputMethodQuery(Qt::ImMicroFocus).toRectF();
   363     return inputMethodQuery(Qt::ImMicroFocus).toRectF();
   345 }
   364 }
   346 
   365 
   347 /*!
   366 /*!
   348 Returns active pre-edit string. Note that this method works only if the pre-edit
   367 Returns active pre-edit string. Note that this method works only if the pre-edit
   528 
   547 
   529 /*!
   548 /*!
   530 Commits given smiley.
   549 Commits given smiley.
   531 */
   550 */
   532 void HbInputFocusObject::commitSmiley(QString smiley)
   551 void HbInputFocusObject::commitSmiley(QString smiley)
   533 {    
   552 {
   534      Q_D(HbInputFocusObject);
   553      Q_D(HbInputFocusObject);
   535 
   554 
   536      if (d->mFocusedObject) {
   555      if (d->mFocusedObject) {
   537          d->mFocusedObject->setProperty("SmileyIcon", smiley);
   556          d->mFocusedObject->setProperty("SmileyIcon", smiley);
   538      }
   557      }
   589 /*!
   608 /*!
   590 Returns true if the input framework recognizes given object as editor.
   609 Returns true if the input framework recognizes given object as editor.
   591 */
   610 */
   592 bool HbInputFocusObject::isEditor(QObject *object)
   611 bool HbInputFocusObject::isEditor(QObject *object)
   593 {
   612 {
   594     if (object && object->inherits("HbAbstractEdit")) {
   613     QGraphicsObject *graphicsObject = qobject_cast<QGraphicsObject*>(object);
   595          return true;
   614     if (graphicsObject) {
       
   615         return ((graphicsObject->flags() & QGraphicsItem::ItemAcceptsInputMethod) != 0);
   596     }
   616     }
   597 
   617 
   598     if (qobject_cast<QLineEdit*>(object)) {
   618     if (qobject_cast<QLineEdit*>(object)) {
   599         return true;
   619         return true;
   600     }
   620     }