src/hbwidgets/editors/hbselectioncontrol_p.cpp
changeset 2 06ff229162e9
parent 1 f7ac710697a9
child 5 627c4a0fd0e7
equal deleted inserted replaced
1:f7ac710697a9 2:06ff229162e9
    33 //
    33 //
    34 // We mean it.
    34 // We mean it.
    35 //
    35 //
    36 
    36 
    37 #include "hbselectioncontrol_p.h"
    37 #include "hbselectioncontrol_p.h"
    38 #include "hbstyleoption.h"
    38 #include "hbstyleoption_p.h"
    39 #include "hbeffect.h"
    39 #include "hbeffect.h"
    40 #include "hbdialog_p.h"
    40 #include "hbdialog_p.h"
    41 #include "hbabstractedit.h"
    41 #include "hbabstractedit.h"
    42 #include "hbabstractedit_p.h"
    42 #include "hbabstractedit_p.h"
    43 #include "hbtoucharea.h"
    43 #include "hbtoucharea.h"
    94 
    94 
    95 public:
    95 public:
    96 
    96 
    97     HbAbstractEdit *mEdit;
    97     HbAbstractEdit *mEdit;
    98     QGraphicsItem *mTopLevelAncestor;
    98     QGraphicsItem *mTopLevelAncestor;
    99     QPointF mMouseOffset;
       
   100 
    99 
   101     QGraphicsItem *mSelectionStartHandle;
   100     QGraphicsItem *mSelectionStartHandle;
   102     QGraphicsItem *mSelectionEndHandle;
   101     QGraphicsItem *mSelectionEndHandle;
   103     HbTouchArea* mSelectionStartTouchArea;
   102     HbTouchArea* mSelectionStartTouchArea;
   104     HbTouchArea* mSelectionEndTouchArea;
   103     HbTouchArea* mSelectionEndTouchArea;
   298     mPressed = HbSelectionControl::DummyHandle;
   297     mPressed = HbSelectionControl::DummyHandle;
   299 
   298 
   300     // Find out which handle is being moved
   299     // Find out which handle is being moved
   301     if (mSelectionStartTouchArea->contains(q->mapToItem(mSelectionStartTouchArea, point))) {
   300     if (mSelectionStartTouchArea->contains(q->mapToItem(mSelectionStartTouchArea, point))) {
   302         mPressed = HbSelectionControl::SelectionStartHandle;
   301         mPressed = HbSelectionControl::SelectionStartHandle;
   303         mMouseOffset = mSelectionStartHandle->pos() - point;
       
   304     }
   302     }
   305     if (mSelectionEndTouchArea->contains(q->mapToItem(mSelectionEndTouchArea, point))) {
   303     if (mSelectionEndTouchArea->contains(q->mapToItem(mSelectionEndTouchArea, point))) {
   306         bool useArea = true;
   304         bool useArea = true;
   307         if(mPressed != HbSelectionControl::DummyHandle) {
   305         if(mPressed != HbSelectionControl::DummyHandle) {
   308 
   306 
   320                 useArea = false;
   318                 useArea = false;
   321             }
   319             }
   322         }
   320         }
   323         if (useArea) {
   321         if (useArea) {
   324             mPressed = HbSelectionControl::SelectionEndHandle;
   322             mPressed = HbSelectionControl::SelectionEndHandle;
   325             mMouseOffset = mSelectionEndHandle->pos() - point;
       
   326         }
   323         }
   327     }
   324     }
   328 
   325 
   329     if (mPressed == HbSelectionControl::DummyHandle) {
   326     if (mPressed == HbSelectionControl::DummyHandle) {
   330         // Hit is outside touch areas, ignore
   327         // Hit is outside touch areas, ignore
   377 
   374 
   378 void HbSelectionControlPrivate::panGestureUpdated(HbPanGesture *gesture)
   375 void HbSelectionControlPrivate::panGestureUpdated(HbPanGesture *gesture)
   379 {
   376 {
   380     Q_Q(HbSelectionControl);
   377     Q_Q(HbSelectionControl);
   381 
   378 
       
   379     QRectF docRect = QRectF(mEdit->mapFromItem(HbAbstractEditPrivate::d_ptr(mEdit)->canvas->parentItem(),
       
   380                             HbAbstractEditPrivate::d_ptr(mEdit)->canvas->pos()),
       
   381                             HbAbstractEditPrivate::d_ptr(mEdit)->doc->size());
       
   382     
   382     QPointF editPos = mEdit->mapFromScene(gesture->sceneStartPos() + gesture->sceneOffset());
   383     QPointF editPos = mEdit->mapFromScene(gesture->sceneStartPos() + gesture->sceneOffset());
       
   384     QPointF origEditPos = editPos;
       
   385     bool outsideCanvas = !docRect.contains(origEditPos);
       
   386 
       
   387     // Constrain editPos within docRect
       
   388     editPos = QPointF(qMin(qMax(editPos.x(),docRect.left()),docRect.right()),
       
   389                       qMin(qMax(editPos.y(),docRect.top()),docRect.bottom()));
   383 
   390 
   384     QRectF handleRect = mSelectionStartHandle->boundingRect();
   391     QRectF handleRect = mSelectionStartHandle->boundingRect();
   385     handleRect.moveTopLeft(editPos + mMouseOffset);
   392 
   386 
   393     handleRect.moveCenter(editPos);
       
   394 
       
   395     // Set hitTestPos based on which handle was grabbed
   387     QPointF hitTestPos = handleRect.center();
   396     QPointF hitTestPos = handleRect.center();
   388 
   397 
   389     if (mPressed == HbSelectionControl::SelectionStartHandle) {
   398     if (mPressed == HbSelectionControl::SelectionStartHandle) {
   390         hitTestPos.setY(handleRect.bottom()+1);
   399         hitTestPos.setY(handleRect.bottom()+1);
   391     } else {
   400     } else {
   392         hitTestPos.setY(handleRect.top()-1);
   401         hitTestPos.setY(handleRect.top()-1);
   393     }
   402     }
   394 
   403 
   395     QTextCursor cursor = mEdit->textCursor();
   404     // Override hitTestPos if origEditPos was outside the canvas
       
   405     if (outsideCanvas) {
       
   406         if (origEditPos.y() < docRect.top()) {
       
   407             hitTestPos.setY(handleRect.bottom()+1);
       
   408         } else if (docRect.bottom() < origEditPos.y()) {
       
   409             hitTestPos.setY(handleRect.top()-1);
       
   410         }
       
   411     }
       
   412 
       
   413     QTextCursor cursor;
       
   414     cursor = mEdit->textCursor();
   396     // Hit test for the center of current selection touch area
   415     // Hit test for the center of current selection touch area
   397     int hitPos = HbAbstractEditPrivate::d_ptr(mEdit)->hitTest(hitTestPos,Qt::FuzzyHit);
   416     int hitPos = HbAbstractEditPrivate::d_ptr(mEdit)->hitTest(hitTestPos,Qt::FuzzyHit);
       
   417 
       
   418     // if no valid hit pos or empty selection return
   398     if (hitPos == -1 || hitPos == cursor.anchor()) {
   419     if (hitPos == -1 || hitPos == cursor.anchor()) {
   399         return;
   420         return;
   400     }
   421     }
   401 
       
   402 
   422 
   403     bool handlesMoved(false);
   423     bool handlesMoved(false);
   404     if (hitPos != cursor.position()) {
   424     if (hitPos != cursor.position()) {
   405         handlesMoved = true;
   425         handlesMoved = true;
   406     }
   426     }