[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdegraphics/okular/ui
From:       Pino Toscano <toscano.pino () tiscali ! it>
Date:       2007-07-17 20:58:38
Message-ID: 1184705918.597319.31804.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 689185 by pino:

Now the annotations can be dragged and moved after being placed on a page, even if \
the page is rotated. Ctrl+right mouse button is what is needed to do that.
At the moment, only line, stamp and geometric annotations can be moved with mouse \
dragging.


 M  +18 -0     annotationguiutils.cpp  
 M  +2 -0      annotationguiutils.h  
 M  +88 -2     pageview.cpp  


--- trunk/KDE/kdegraphics/okular/ui/annotationguiutils.cpp #689184:689185
@@ -82,3 +82,21 @@
     return contents( ann ).replace( "\n", "<br>" );
 }
 
+bool AnnotationGuiUtils::canBeMoved( Okular::Annotation * ann )
+{
+    if ( !ann )
+        return false;
+
+    switch( ann->subType() )
+    {
+        case Okular::Annotation::ALine:
+        case Okular::Annotation::AStamp:
+        case Okular::Annotation::AGeom:
+            return true;
+            break;
+        default:
+            break;
+    }
+    return false;
+}
+
--- trunk/KDE/kdegraphics/okular/ui/annotationguiutils.h #689184:689185
@@ -26,6 +26,8 @@
 
         static QString contents( const Okular::Annotation * annotation );
         static QString contentsHtml( const Okular::Annotation * annotation );
+
+        static bool canBeMoved( Okular::Annotation * annotation );
 };
 
 
--- trunk/KDE/kdegraphics/okular/ui/pageview.cpp #689184:689185
@@ -99,6 +99,8 @@
     bool mouseTextSelecting;
     QSet< int > pagesWithTextSelection;
     bool mouseOnRect;
+    Okular::Annotation * mouseAnn;
+    QPoint mouseAnnPos;
 
     // viewport move
     bool viewportMoveActive;
@@ -257,6 +259,7 @@
     d->mouseSelecting = false;
     d->mouseTextSelecting = false;
     d->mouseOnRect = false;
+    d->mouseAnn = 0;
     d->viewportMoveActive = false;
     d->viewportMoveTimer = 0;
     d->scrollIncrement = 0;
@@ -1119,6 +1122,29 @@
     Q_UNUSED(e)
 }
 
+static QPoint rotateInRect( const QPoint &rotated, Okular::Rotation rotation )
+{
+    QPoint ret;
+
+    switch ( rotation )
+    {
+        case Okular::Rotation90:
+            ret = QPoint( rotated.y(), -rotated.x() );
+            break;
+        case Okular::Rotation180:
+            ret = QPoint( -rotated.x(), -rotated.y() );
+            break;
+        case Okular::Rotation270:
+            ret = QPoint( -rotated.y(), rotated.x() );
+            break;
+        case Okular::Rotation0:  // no modifications
+        default: // other cases
+            ret = rotated;
+    }
+
+    return ret;
+}
+
 void PageView::contentsMouseMoveEvent( QMouseEvent * e )
 {
     // don't perform any mouse action when no document is shown
@@ -1178,8 +1204,33 @@
         case MouseNormal:
             if ( leftButton )
             {
+                if ( d->mouseAnn )
+                {
+                    PageViewItem * pageItem = pickItemOnPoint( e->x(), e->y() );
+                    if ( pageItem )
+                    {
+                        const QRect & itemRect = pageItem->geometry();
+                        QPoint newpos( e->x() - itemRect.left(), e->y() - \
itemRect.top() ); +                        Okular::NormalizedRect r = \
d->mouseAnn->boundingRectangle(); +                        QPoint p( newpos - \
d->mouseAnnPos ); +                        QPointF pf( rotateInRect( p, \
pageItem->page()->totalOrientation() ) ); +                        if ( \
pageItem->page()->totalOrientation() % 2 == 0 ) +                        {
+                            pf.rx() /= pageItem->width();
+                            pf.ry() /= pageItem->height();
+                        }
+                        else
+                        {
+                            pf.rx() /= pageItem->height();
+                            pf.ry() /= pageItem->width();
+                        }
+                        d->mouseAnn->translate( Okular::NormalizedPoint( pf.x(), \
pf.y() ) ); +                        d->mouseAnnPos = newpos;
+                        d->document->modifyPageAnnotation( pageItem->pageNumber(), \
d->mouseAnn ); +                    }
+                }
                 // drag page
-                if ( !d->mouseGrabPos.isNull() )
+                else if ( !d->mouseGrabPos.isNull() )
                 {
                     QPoint mousePos = e->globalPos();
                     QPoint delta = d->mouseGrabPos - mousePos;
@@ -1316,9 +1367,27 @@
         case MouseNormal:   // drag start / click / link following
             if ( leftButton )
             {
+                PageViewItem * pageItem = 0;
+                if ( ( e->modifiers() & Qt::ControlModifier ) && ( pageItem = \
pickItemOnPoint( e->x(), e->y() ) ) ) +                {
+                    // find out normalized mouse coords inside current item
+                    const QRect & itemRect = pageItem->geometry();
+                    double nX = (double)(e->x() - itemRect.left()) / \
itemRect.width(); +                    double nY = (double)(e->y() - itemRect.top()) \
/ itemRect.height(); +                    const Okular::ObjectRect * orect = \
pageItem->page()->objectRect( Okular::ObjectRect::OAnnotation, nX, nY, \
itemRect.width(), itemRect.height() ); +                    d->mouseAnnPos = QPoint( \
e->x() - itemRect.left(), e->y() - itemRect.top() ); +                    if ( orect \
) +                        d->mouseAnn = ( (Okular::AnnotationObjectRect *)orect \
)->annotation(); +                    // consider no annotation caught if its type is \
not movable +                    if ( d->mouseAnn && !AnnotationGuiUtils::canBeMoved( \
d->mouseAnn ) ) +                        d->mouseAnn = 0;
+                }
+                if ( !d->mouseAnn )
+                {
                 d->mouseGrabPos = d->mouseOnRect ? QPoint() : d->mousePressPos;
                 if ( !d->mouseOnRect )
                     setCursor( Qt::SizeAllCursor );
+                }
             }
             else if ( rightButton )
             {
@@ -1409,6 +1478,12 @@
         return;
     }
 
+    if ( d->mouseAnn )
+    {
+        setCursor( Qt::ArrowCursor );
+        d->mouseAnn = 0;
+    }
+
     bool leftButton = e->button() == Qt::LeftButton;
     bool rightButton = e->button() == Qt::RightButton;
     switch ( d->mouseMode )
@@ -2258,6 +2333,8 @@
         // if over a ObjectRect (of type Link) change cursor to hand
         if ( d->mouseMode == MouseTextSelect )
             setCursor( Qt::IBeamCursor );
+        else if ( d->mouseAnn )
+            setCursor( Qt::ClosedHandCursor );
         else
         {
             const Okular::ObjectRect * linkobj = pageItem->page()->objectRect( \
Okular::ObjectRect::Action, nX, nY, pageItem->width(), pageItem->height() ); @@ \
-2270,7 +2347,16 @@  else
             {
                 d->mouseOnRect = false;
-                setCursor( Qt::ArrowCursor );
+                if ( annotobj
+                     && ( QApplication::keyboardModifiers() & Qt::ControlModifier )
+                     && AnnotationGuiUtils::canBeMoved( static_cast< const \
Okular::AnnotationObjectRect * >( annotobj )->annotation() ) ) +                {
+                    setCursor( Qt::OpenHandCursor );
+                }
+                else
+                {
+                    setCursor( Qt::ArrowCursor );
+                }
             }
         }
     }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic