[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/lib/kofficeui
From: Thorsten Zachmann <t.zachmann () zagge ! de>
Date: 2005-10-31 12:30:11
Message-ID: 1130761811.423107.15329.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 476058 by zachmann:
o Added methodes for snapping.
This might change if I find better ways.
M +113 -0 koGuides.cpp
M +24 -0 koGuides.h
--- trunk/koffice/lib/kofficeui/koGuides.cpp #476057:476058
@@ -29,6 +29,7 @@
#include <koDocument.h>
#include <koPoint.h>
+#include <koRect.h>
#include <koView.h>
#include <kozoomhandler.h>
@@ -342,6 +343,118 @@
}
+KoPoint KoGuides::snapToGuideLines( KoRect &rect, int snap )
+{
+ KoPoint diff( 0, 0 );
+ QValueList<double> hGuideLines;
+ QValueList<double> vGuideLines;
+ getGuideLines( hGuideLines, vGuideLines );
+
+ QValueList<double>::const_iterator it( vGuideLines.begin() );
+ for ( ; it != vGuideLines.end(); ++it )
+ {
+ double tmp = rect.left() - *it;
+ if ( QABS( tmp ) < m_zoomHandler->unzoomItX( snap ) )
+ {
+ diff.setX( tmp );
+ break;
+ }
+ tmp = rect.right() - *it;
+ if ( QABS( tmp ) < m_zoomHandler->unzoomItX( snap ) )
+ {
+ diff.setX( tmp );
+ break;
+ }
+ }
+
+ it = hGuideLines.begin();
+ for ( ; it != hGuideLines.end(); ++it )
+ {
+ double tmp = rect.top() - *it;
+ if ( QABS( tmp ) < m_zoomHandler->unzoomItY( snap ) )
+ {
+ diff.setY( tmp );
+ break;
+ }
+ tmp = rect.bottom() - *it;
+ if ( QABS( tmp ) < m_zoomHandler->unzoomItY( snap ) )
+ {
+ diff.setY( tmp );
+ break;
+ }
+ }
+ return diff;
+}
+
+KoPoint KoGuides::diffGuide( KoRect &rect, double diffx, double diffy )
+{
+ KoPoint move( 0, 0 );
+ QValueList<double> horizHelplines;
+ QValueList<double> vertHelplines;
+ getGuideLines( horizHelplines, vertHelplines );
+
+ QValueList<double>::const_iterator it( vertHelplines.begin() );
+ for ( ; it != vertHelplines.end(); ++it )
+ {
+ double movexl = *it - rect.left();
+ double movexr = *it - rect.right();
+ if ( diffx > 0 )
+ {
+ if ( diffx > movexl && movexl > move.x() )
+ {
+ move.setX( movexl );
+ }
+ if ( diffx > movexr && movexr > move.x() )
+ {
+ move.setX( movexr );
+ }
+ }
+ else
+ {
+ if ( diffx < movexl && movexl < move.x() )
+ {
+ move.setX( movexl );
+ }
+ if ( diffx < movexr && movexr < move.x() )
+ {
+ move.setX( movexr );
+ }
+ }
+ }
+
+ it = horizHelplines.begin();
+ for ( ; it != horizHelplines.end(); ++it )
+ {
+ double moveyl = *it - rect.top();
+ double moveyr = *it - rect.bottom();
+ if ( diffy > 0 )
+ {
+ if ( diffy > moveyl && moveyl > move.y() )
+ {
+ move.setY( moveyl );
+ }
+ if ( diffy > moveyr && moveyr > move.y() )
+ {
+ move.setY( moveyr );
+ }
+ }
+ else
+ {
+ if ( diffy < moveyl && moveyl < move.y() )
+ {
+ move.setY( moveyl );
+ }
+ if ( diffy < moveyr && moveyr < move.y() )
+ {
+ move.setY( moveyr );
+ }
+ }
+ }
+
+ return move;
+}
+
+
void KoGuides::moveGuide( const QPoint &pos, bool horizontal, int rulerWidth )
{
int x = pos.x() - rulerWidth;
--- trunk/koffice/lib/kofficeui/koGuides.h #476057:476058
@@ -28,6 +28,7 @@
class QPaintDevice;
class KoPoint;
+class KoRect;
class KoView;
class KoZoomHandler;
@@ -128,6 +129,29 @@
*/
void getGuideLines( QValueList<double> &horizontalPos, QValueList<double> &verticalPos ) const;
+ /**
+ * @brief Snap rect to guidelines
+ *
+ * This looks fo a guide which is in reach for the guide as defined in snap.
+ *
+ * @param rect the rect which should be snapped
+ * @param snap the distance the guide should snap
+ *
+ * @return the distance to the guide or ( 0, 0 ) if there is no guide to snap to.
+ */
+ KoPoint snapToGuideLines( KoRect &rect, int snap );
+
+ /**
+ * @brief Find the next guide distance to snap to
+ *
+ * @param rect the rect which should be snapped
+ * @param diffx The range in x distance in which the guide has to be.
+ * @param diffy The range in y distance in which the guide has to be.
+ *
+ * @return the distance to the guide or ( 0, 0 ) if there is no guide to snap to.
+ */
+ KoPoint diffGuide( KoRect &rect, double diffx, double diffy );
+
public slots:
/**
* @brief Move Guide
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic