ginebra2/EditorWidget.cpp
changeset 9 b39122337a00
parent 7 a1f515018ac1
child 12 afcd8e6d025b
equal deleted inserted replaced
7:a1f515018ac1 9:b39122337a00
    16  * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
    16  * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/".
    17  *
    17  *
    18  * Description:
    18  * Description:
    19  *
    19  *
    20  */
    20  */
       
    21 #include <QIcon>
       
    22 
       
    23 #ifdef ORBIT_UI
       
    24 #include <hbaction.h>
       
    25 #include <hbicon.h>
       
    26 #include <hbinputmethod.h>
       
    27 #include <hbinputeditorinterface.h>
       
    28 #include <hbinputsettingproxy.h>
       
    29 #endif
    21 
    30 
    22 #include "EditorWidget.h"
    31 #include "EditorWidget.h"
    23 #include "Utilities.h"
    32 #include "Utilities.h"
    24 #include "ChromeEffect.h"
    33 #include "ChromeEffect.h"
    25 
    34 
    26 // FIXME ;;; Must address the following issues:
    35 // FIXME ;;; Must address the following issues:
    27 //
    36 //
    28 // * On Symbian, when focus is outside editor and user clicks inside editor, the editor
    37 // * Clean ORBIT_UI flag by creating new class for orbit ui
    29 //   receives FocusIn event but does not make the blinking cursor visible until
    38 // * Replace QGraphicsTextItem with HbTextItem for orbit ui
    30 //   the user starts to type or presses arrow keys.
       
    31 //
    39 //
    32 // * Edit selection is not visible.
       
    33 //
       
    34 
       
    35 
    40 
    36 namespace GVA {
    41 namespace GVA {
    37 
    42 
    38   // Methods for class EditorItem
    43   // Methods for class EditorItem
    39 
    44 
    42 
    47 
    43   GTextLineItem::GTextLineItem(QGraphicsItem * parent)
    48   GTextLineItem::GTextLineItem(QGraphicsItem * parent)
    44   : QGraphicsTextItem(parent)
    49   : QGraphicsTextItem(parent)
    45   , m_maxTextLength(0)
    50   , m_maxTextLength(0)
    46   , m_hints(Qt::ImhNoPredictiveText) // disable the predictive text
    51   , m_hints(Qt::ImhNoPredictiveText) // disable the predictive text
       
    52   , m_setSpecificBtn(false)
    47   {
    53   {
    48     // Disable wrapping, force text to be stored and displayed
    54     // Disable wrapping, force text to be stored and displayed
    49     // as a single line.
    55     // as a single line.
    50     QTextOption textOption = document()->defaultTextOption();
    56     QTextOption textOption = document()->defaultTextOption();
    51     textOption.setWrapMode(QTextOption::NoWrap);
    57     textOption.setWrapMode(QTextOption::NoWrap);
    86     } else if (m_maxTextLength > 0 && length <= 0) {
    92     } else if (m_maxTextLength > 0 && length <= 0) {
    87         disconnect(document(), SIGNAL(contentsChange(int, int, int)), this, SLOT(contentsChange(int, int, int)));
    93         disconnect(document(), SIGNAL(contentsChange(int, int, int)), this, SLOT(contentsChange(int, int, int)));
    88     }
    94     }
    89     m_maxTextLength = length;
    95     m_maxTextLength = length;
    90   }
    96   }
       
    97   
       
    98   void GTextLineItem::setSpecificButton(QString& commitString, QString& buttonIconPath) {
       
    99     m_spBtnCommitString = commitString;
       
   100     m_spBtnIconPath = buttonIconPath;
       
   101     m_setSpecificBtn = true;
       
   102   }
    91 
   103 
    92   void GTextLineItem::contentsChange(int position, int charsRemoved, int charsAdded)
   104   void GTextLineItem::contentsChange(int position, int charsRemoved, int charsAdded)
    93   {
   105   {
    94     Q_UNUSED(position);
   106     Q_UNUSED(position);
    95     Q_UNUSED(charsRemoved);
   107     Q_UNUSED(charsRemoved);
    97     if( m_maxTextLength > 0 && toPlainText().length() > m_maxTextLength ) {
   109     if( m_maxTextLength > 0 && toPlainText().length() > m_maxTextLength ) {
    98       QTextCursor cursor = textCursor();
   110       QTextCursor cursor = textCursor();
    99       cursor.deletePreviousChar();
   111       cursor.deletePreviousChar();
   100       setTextCursor(cursor);
   112       setTextCursor(cursor);
   101     }
   113     }
       
   114   }
       
   115 
       
   116   void GTextLineItem::specificBtnTriggered(bool checked)
       
   117   {
       
   118 #ifdef ORBIT_UI
       
   119     QInputContext *ic = qApp->inputContext();
       
   120     QInputMethodEvent *imEvent = new QInputMethodEvent();
       
   121     imEvent->setCommitString(QString(m_spBtnCommitString));
       
   122     if (ic)
       
   123       ic->sendEvent(*imEvent);
       
   124     delete imEvent;
       
   125 #endif
   102   }
   126   }
   103 
   127 
   104   // Get the pixel offset of the cursor. Needed to implement scrolling.
   128   // Get the pixel offset of the cursor. Needed to implement scrolling.
   105 
   129 
   106   qreal GTextLineItem::cursorX()
   130   qreal GTextLineItem::cursorX()
   179   void GTextLineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
   203   void GTextLineItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
   180   {
   204   {
   181     QGraphicsTextItem::mouseReleaseEvent(event);
   205     QGraphicsTextItem::mouseReleaseEvent(event);
   182     QPointF pos = event->pos();
   206     QPointF pos = event->pos();
   183     emit tapped(pos);
   207     emit tapped(pos);
       
   208 
       
   209     // add specific button
       
   210 #ifdef ORBIT_UI
       
   211     if (m_setSpecificBtn) { 
       
   212       HbEditorInterface editorInterface(this);
       
   213       QList<HbAction*> actionsList = editorInterface.actions();
       
   214       for (int i = 0; i < actionsList.size(); ++i) {
       
   215         editorInterface.removeAction(actionsList.at(i));
       
   216       }
       
   217       QIcon icon(m_spBtnIconPath);
       
   218       HbAction* action = new HbAction(HbIcon(icon), QString(""), this);
       
   219       connect(action, SIGNAL(triggered(bool)), this, SLOT(specificBtnTriggered(bool)));
       
   220 
       
   221       editorInterface.addAction(action);
       
   222       m_setSpecificBtn = false;
       
   223     }
       
   224 #endif
       
   225 
   184     // open vkb by single tap
   226     // open vkb by single tap
   185     QWidget * widget = event->widget();
   227     QWidget * widget = event->widget();
   186     QEvent vkbEvent(QEvent::RequestSoftwareInputPanel);
   228     QEvent vkbEvent(QEvent::RequestSoftwareInputPanel);
   187     QApplication::sendEvent(widget, &vkbEvent);
   229     QApplication::sendEvent(widget, &vkbEvent);
       
   230 
       
   231     // disable prediction
       
   232 #ifdef ORBIT_UI
       
   233     HbInputSettingProxy* hbISProxy = HbInputSettingProxy::instance();
       
   234     if (hbISProxy->predictiveInputStatusForActiveKeyboard())
       
   235       hbISProxy->togglePrediction();
       
   236 #endif
   188   }
   237   }
   189 
   238 
   190   void GTextLineItem::keyPressEvent(QKeyEvent * event)
   239   void GTextLineItem::keyPressEvent(QKeyEvent * event)
   191   {
   240   {
   192     // Signal horizontal cursor movement so that an editor widget can
   241     // Signal horizontal cursor movement so that an editor widget can
   210     Q_UNUSED(event);
   259     Q_UNUSED(event);
   211     // disable the drag & drop to fix the auto-delete-all issue
   260     // disable the drag & drop to fix the auto-delete-all issue
   212     QApplication::setStartDragDistance(1000);
   261     QApplication::setStartDragDistance(1000);
   213     QGraphicsTextItem::focusInEvent(event);
   262     QGraphicsTextItem::focusInEvent(event);
   214 
   263 
       
   264 #ifndef ORBIT_UI
   215     QWidget* fw = QApplication::focusWidget();
   265     QWidget* fw = QApplication::focusWidget();
   216     Qt::InputMethodHints hints = fw->inputMethodHints();
   266     Qt::InputMethodHints hints = fw->inputMethodHints();
   217     if (hints != m_hints)
   267     if (hints != m_hints)
   218       fw->setInputMethodHints(m_hints);
   268       fw->setInputMethodHints(m_hints);
       
   269 #endif
   219 
   270 
   220     if (event->reason() != Qt::PopupFocusReason) // to fix the special char issue on VKB
   271     if (event->reason() != Qt::PopupFocusReason) // to fix the special char issue on VKB
   221       emit focusChanged(true);
   272       emit focusChanged(true);
   222   }
   273   }
   223 
   274