src/hbwidgets/editors/hbabstractedit_p.cpp
changeset 7 923ff622b8b9
parent 6 c3690ec91ef8
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
6:c3690ec91ef8 7:923ff622b8b9
    37 #include "hbabstractedit_p.h"
    37 #include "hbabstractedit_p.h"
    38 #include "hbabstractedit.h"
    38 #include "hbabstractedit.h"
    39 #include "hbstyleoption_p.h"
    39 #include "hbstyleoption_p.h"
    40 #include "hbscrollarea.h"
    40 #include "hbscrollarea.h"
    41 #include "hbvalidator.h"
    41 #include "hbvalidator.h"
    42 #include "hbmeshlayout_p.h"
       
    43 #include "hbmenu.h"
    42 #include "hbmenu.h"
    44 #include "hbselectioncontrol_p.h"
    43 #include "hbselectioncontrol_p.h"
    45 #include "hbcolorscheme.h"
    44 #include "hbcolorscheme.h"
    46 #include "hbsmileyengine_p.h"
    45 #include "hbsmileyengine_p.h"
    47 #include "hbtextmeasurementutility_p.h"
    46 #include "hbtextmeasurementutility_p.h"
    48 #include "hbfeaturemanager_r.h"
    47 #include "hbfeaturemanager_r.h"
    49 #include "hbinputeditorinterface.h"
    48 #include "hbinputeditorinterface.h"
    50 #include "hbinputvkbhost.h"
    49 #include "hbinputvkbhost.h"
       
    50 #include "hbinputmethod.h"
       
    51 #include "hbinputfocusobject.h"
       
    52 
    51 
    53 
    52 #include <QValidator>
    54 #include <QValidator>
    53 #include <QTextLayout>
    55 #include <QTextLayout>
    54 #include <QTextBlock>
    56 #include <QTextBlock>
    55 #include <QTextList>
    57 #include <QTextList>
    93 {
    95 {
    94 public:
    96 public:
    95 
    97 
    96     HbEditItem(HbAbstractEdit *parent) : HbWidget(parent), edit(parent)
    98     HbEditItem(HbAbstractEdit *parent) : HbWidget(parent), edit(parent)
    97     {
    99     {
       
   100     	setFlag(QGraphicsItem::ItemUsesExtendedStyleOption, true);
    98     };
   101     };
    99 
   102 
   100     virtual ~HbEditItem() {};
   103     virtual ~HbEditItem() {};
   101 
   104 
   102     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0)
   105     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0)
   375     if (cursor.isNull()) {
   378     if (cursor.isNull()) {
   376         cursor = QTextCursor(doc);
   379         cursor = QTextCursor(doc);
   377     }
   380     }
   378 
   381 
   379     cursor.setPosition(pos, mode);
   382     cursor.setPosition(pos, mode);
   380 
   383     ensureCursorVisible();
   381     cursorChanged(HbValidator::CursorChangeFromMouse);
   384     cursorChanged(HbValidator::CursorChangeFromMouse);
   382 }
   385 }
   383 
   386 
   384 bool HbAbstractEditPrivate::cursorMoveKeyEvent(QKeyEvent *e)
   387 bool HbAbstractEditPrivate::cursorMoveKeyEvent(QKeyEvent *e)
   385 {
   388 {
   579     }
   582     }
   580 }
   583 }
   581 
   584 
   582 void HbAbstractEditPrivate::setTextInteractionFlags(Qt::TextInteractionFlags flags)
   585 void HbAbstractEditPrivate::setTextInteractionFlags(Qt::TextInteractionFlags flags)
   583 {
   586 {
   584     Q_Q(HbAbstractEdit);
       
   585 
       
   586     if (flags == interactionFlags)
   587     if (flags == interactionFlags)
   587         return;
   588         return;
   588     interactionFlags = flags;
   589     interactionFlags = flags;
   589 
   590 
   590     if (q->hasFocus()) {
   591     if (hasInputFocus()) {
   591         setBlinkingCursorEnabled(flags & Qt::TextEditable);
   592         setBlinkingCursorEnabled(flags & Qt::TextEditable);
   592     }
   593     }
   593 }
   594 }
   594 
   595 
   595 void HbAbstractEditPrivate::_q_updateRequest(QRectF rect)
   596 void HbAbstractEditPrivate::_q_updateRequest(QRectF rect)
   775     }
   776     }
   776 
   777 
   777     if (cursor.hasSelection()) {
   778     if (cursor.hasSelection()) {
   778         QAbstractTextDocumentLayout::Selection selection;
   779         QAbstractTextDocumentLayout::Selection selection;
   779         selection.cursor = cursor;
   780         selection.cursor = cursor;
   780         QPalette::ColorGroup cg = q->hasFocus() ? QPalette::Active : QPalette::Inactive;
   781         QPalette::ColorGroup cg = hasInputFocus() ? QPalette::Active : QPalette::Inactive;
   781         selection.format.setBackground(ctx.palette.brush(cg, QPalette::Highlight));
   782         selection.format.setBackground(ctx.palette.brush(cg, QPalette::Highlight));
   782         selection.format.setForeground(ctx.palette.brush(cg, QPalette::HighlightedText));
   783         selection.format.setForeground(ctx.palette.brush(cg, QPalette::HighlightedText));
   783 
   784 
   784         HbStyleOption opt;
   785         HbStyleOption opt;
   785         q->initStyleOption(&opt);
   786         q->initStyleOption(&opt);
  1076             q->showContextMenu(q->mapToScene(point));
  1077             q->showContextMenu(q->mapToScene(point));
  1077         }
  1078         }
  1078     } else {
  1079     } else {
  1079         // Currently focused widget to listen to InputContext before updating the cursor position
  1080         // Currently focused widget to listen to InputContext before updating the cursor position
  1080         sendMouseEventToInputContext(point);
  1081         sendMouseEventToInputContext(point);
       
  1082 
       
  1083         // translate the point to have the Y ccordinate inside the viewport
       
  1084         QPointF translatedPoint(point);
       
  1085         if(translatedPoint.y() < viewPortRect().top()) {
       
  1086             translatedPoint.setY(viewPortRect().top() + 1);
       
  1087         } else if(translatedPoint.y() > viewPortRect().bottom()){
       
  1088             translatedPoint.setY(viewPortRect().bottom() - 1);
       
  1089         }
       
  1090 
  1081         // need to get the cursor position again since input context can change the document
  1091         // need to get the cursor position again since input context can change the document
  1082         newCursorPos = hitTest(point, Qt::FuzzyHit);
  1092         newCursorPos = hitTest(translatedPoint, Qt::FuzzyHit);
  1083         setCursorPosition(newCursorPos);
  1093         setCursorPosition(newCursorPos);
  1084 
  1094 
  1085         if (interactionFlags & Qt::TextEditable) {
  1095         if (interactionFlags & Qt::TextEditable) {
  1086             updateCurrentCharFormat();
  1096             updateCurrentCharFormat();
  1087         }
  1097         }
  1088         cursorChanged(HbValidator::CursorChangeFromMouse);
  1098 
  1089 
  1099         QString anchor(q->anchorAt(translatedPoint));
  1090         QString anchor(q->anchorAt(point));
       
  1091         if(!anchor.isEmpty()) {
  1100         if(!anchor.isEmpty()) {
  1092             emit q->anchorTapped(anchor);
  1101             emit q->anchorTapped(anchor);
  1093         }
  1102         }
  1094     }
  1103     }
  1095 }
  1104 }
  1232 void HbAbstractEditPrivate::closeInputPanel()
  1241 void HbAbstractEditPrivate::closeInputPanel()
  1233 {
  1242 {
  1234     sendInputPanelEvent(QEvent::CloseSoftwareInputPanel);
  1243     sendInputPanelEvent(QEvent::CloseSoftwareInputPanel);
  1235 }
  1244 }
  1236 
  1245 
  1237 #include "hbinputeditorinterface.h"
  1246 bool HbAbstractEditPrivate::hasInputFocus() const
  1238 #include "hbinputvkbhost.h"
  1247 {
  1239 
  1248     Q_Q(const HbAbstractEdit);
  1240 void HbAbstractEditPrivate::minimizeInputPanel()
  1249 
  1241 {
  1250     HbInputMethod* inputMethod = HbInputMethod::activeInputMethod();
  1242     Q_Q(HbAbstractEdit);
  1251     if (inputMethod && inputMethod->focusObject() &&
  1243 
  1252         qobject_cast<HbAbstractEdit*>(inputMethod->focusObject()->object()) == q) {
  1244     HbEditorInterface ei(q);
  1253         return true;
  1245     HbVkbHost* vkbHost = ei.vkbHost();
  1254     }
  1246     vkbHost->minimizeKeypad();
  1255     return false;
       
  1256 }
       
  1257 
       
  1258 void HbAbstractEditPrivate::setInputFocusEnabled(bool enable)
       
  1259 {
       
  1260     QGraphicsItem *focusItem = focusPrimitive(HbWidget::FocusHighlightActive);
       
  1261     if (focusItem) {
       
  1262         focusItem->setVisible(enable);
       
  1263     }
       
  1264 
       
  1265     setBlinkingCursorEnabled(enable);
       
  1266     repaintOldAndNewSelection(selectionCursor);
  1247 }
  1267 }
  1248 
  1268 
  1249 #include "moc_hbabstractedit.cpp"
  1269 #include "moc_hbabstractedit.cpp"