Revision: 4909
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4909&view=rev
Author:   hofman
Date:     2008-11-03 13:17:16 +0000 (Mon, 03 Nov 2008)

Log Message:
-----------
implement gesture rotation in main pdfview

Modified Paths:
--------------
    trunk/SKPDFView.h
    trunk/SKPDFView.m

Modified: trunk/SKPDFView.h
===================================================================
--- trunk/SKPDFView.h   2008-11-03 11:26:08 UTC (rev 4908)
+++ trunk/SKPDFView.h   2008-11-03 13:17:16 UTC (rev 4909)
@@ -127,6 +127,8 @@
     int dragMask;
     NSBezierPath *bezierPath;
     unsigned int pathPageIndex;
+    float gestureRotation;
+    unsigned int gesturePageIndex;
     
     int trackingRect;
     CFMutableArrayRef PDFToolTipRects;

Modified: trunk/SKPDFView.m
===================================================================
--- trunk/SKPDFView.m   2008-11-03 11:26:08 UTC (rev 4908)
+++ trunk/SKPDFView.m   2008-11-03 13:17:16 UTC (rev 4909)
@@ -117,6 +117,20 @@
 
 #pragma mark -
 
[EMAIL PROTECTED] NSResponder (SKLeopardPrivate)
+- (void)magnifyWithEvent:(NSEvent *)theEvent;
+- (void)rotateWithEvent:(NSEvent *)theEvent;
+- (void)beginGestureWithEvent:(NSEvent *)theEvent;
+- (void)endGestureWithEvent:(NSEvent *)theEvent;
[EMAIL PROTECTED]
+
[EMAIL PROTECTED] NSEvent (SKLeopardPrivate)
+- (float)magnification;
+- (float)rotation;
[EMAIL PROTECTED]
+
+#pragma mark -
+
 @interface PDFView (SKLeopardPrivate)
 - (void)addTooltipsForVisiblePages;
 @end
@@ -244,6 +258,9 @@
     didSelect = NO;
     mouseDownInAnnotation = NO;
     
+    gestureRotation = 0.0;
+    gesturePageIndex = NSNotFound;
+    
     trackingRect = 0;
     PDFToolTipRects = CFArrayCreateMutable(NULL, 0, NULL);
     
@@ -1543,6 +1560,42 @@
     }
 }
 
+- (void)rotatePageAtIndex:(unsigned int)idx by:(int)rotation {
+    NSUndoManager *undoManager = [self undoManager];
+    [[undoManager prepareWithInvocationTarget:self] rotatePageAtIndex:idx 
by:-rotation];
+    [undoManager setActionName:NSLocalizedString(@"Rotate Page", @"Undo action 
name")];
+    [[[[self window] windowController] document] 
undoableActionDoesntDirtyDocument];
+    
+    PDFPage *page = [[self document] pageAtIndex:idx];
+    [page setRotation:[page rotation] + rotation];
+    
+    [[NSNotificationCenter defaultCenter] 
postNotificationName:SKPDFPageBoundsDidChangeNotification 
+            object:[self document] userInfo:[NSDictionary 
dictionaryWithObjectsAndKeys:SKPDFPageActionRotate, SKPDFPageActionKey, page, 
SKPDFPagePageKey, nil]];
+}
+
+- (void)beginGestureWithEvent:(NSEvent *)theEvent {
+    if ([[SKPDFView superclass] instancesRespondToSelector:_cmd])
+        [super beginGestureWithEvent:theEvent];
+    gestureRotation = 0.0;
+    gesturePageIndex = [[self currentPage] pageIndex];
+}
+
+- (void)endGestureWithEvent:(NSEvent *)theEvent {
+    if ([[SKPDFView superclass] instancesRespondToSelector:_cmd])
+        [super endGestureWithEvent:theEvent];
+    gestureRotation = 0.0;
+    gesturePageIndex = NSNotFound;
+}
+
+- (void)rotateWithEvent:(NSEvent *)theEvent {
+    if ([theEvent respondsToSelector:@selector(rotation)])
+        gestureRotation += [theEvent rotation];
+    if (fabsf(gestureRotation) > 45.0 && gesturePageIndex != NSNotFound) {
+        [self rotatePageAtIndex:gesturePageIndex by:90.0 * 
roundf(gestureRotation / 90.0)];
+        gestureRotation -= 90.0 * roundf(gestureRotation / 90.0);
+    }
+}
+
 - (void)checkSpellingStartingAtIndex:(int)anIndex onPage:(PDFPage *)page {
     unsigned int i, first = [page pageIndex];
     unsigned int count = [[self document] pageCount];


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to