[elvystrac] r1745 - scrolling by whole page works now ok

  • From: elvys@xxxxxxxxxxxxxxxxxxxxxx
  • To: elvystrac@xxxxxxxxxxxxx
  • Date: Tue, 16 Feb 2010 19:25:20 +0100

Author: JirkaH
Date: 2010-02-16 19:25:20 +0100 (Tue, 16 Feb 2010)
New Revision: 1745

Modified:
   branches/client/pdf-presentation-branch/elvys-client/src/pdfviewer.cpp
   branches/client/pdf-presentation-branch/elvys-client/src/pdfzoomed.cpp
   branches/client/pdf-presentation-branch/elvys-client/src/pdfzoomed.h
Log:
scrolling by whole page works now ok


Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdfviewer.cpp
===================================================================
--- branches/client/pdf-presentation-branch/elvys-client/src/pdfviewer.cpp      
2010-02-16 18:01:22 UTC (rev 1744)
+++ branches/client/pdf-presentation-branch/elvys-client/src/pdfviewer.cpp      
2010-02-16 18:25:20 UTC (rev 1745)
@@ -250,13 +250,14 @@
 void PDFViewer::scrollByOnePage(ElvysNs::Direction direction) {
        int curY;
        int curPage;
+       bool aligned;
 
        if ( ! zoomed || scroll == NULL) {
                return;
        }
 
        curY = scroll->verticalScrollBar()->value();
-       curPage = pdfZoomed->whichPage(curY);
+       curPage = pdfZoomed->whichPage(curY, aligned);
 
        mtx.lock();
 
@@ -286,9 +287,12 @@
        }
 
        if (direction == ElvysNs::Up) {
-               scroll->verticalScrollBar()->setValue(lengths[curPage - 1] - 
pages[curPage - 1].h);
+               if (aligned) {
+                       scroll->verticalScrollBar()->setValue(lengths[curPage - 
1] - pages[curPage - 1].h);
+               } else {
+                       scroll->verticalScrollBar()->setValue(lengths[curPage] 
- pages[curPage].h);
+               }
        } else if ( direction == ElvysNs::Down) {
-
                scroll->verticalScrollBar()->setValue(lengths[curPage + 1] - 
pages[curPage + 1].h);
        }
 

Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdfzoomed.cpp
===================================================================
--- branches/client/pdf-presentation-branch/elvys-client/src/pdfzoomed.cpp      
2010-02-16 18:01:22 UTC (rev 1744)
+++ branches/client/pdf-presentation-branch/elvys-client/src/pdfzoomed.cpp      
2010-02-16 18:25:20 UTC (rev 1745)
@@ -73,14 +73,28 @@
 /** Computes which page lay at point y.
   *
   * @param y point at which page should lay
+  * @param aligned serves for returning whether argument @a y was at the page 
boundary or not
   * @return page number or zero if conversion fails
   */
 
-int PDFZoomed::whichPage(int y) {
+int PDFZoomed::whichPage(int y, bool & aligned) {
        int y2 = round((double)y / scaleD);
 
        for( int i = 0; i < lengths.size(); ++i ) {
                if ( y2 <= lengths[i] ) {
+                       if ( i != 0) {
+                               if (y2 == lengths[i-1] + SEP_HEIGHT ) {
+                                       aligned = true;
+                               } else {
+                                       aligned = false;
+                               }
+                       } else {
+                               if (y2 == 0) {
+                                       aligned = true;
+                               } else {
+                                       aligned = false;
+                               }
+                       }
                        return i;
                }
        }
@@ -180,6 +194,7 @@
        int x, y, eventHeight;
        QRect rect;
        int pageTop, pageBottom;
+       bool aligned;
 
        //zjistim kterou oblast ( == ktere stranky ) mam zobrazovat
        QRect eventRect = event->rect();
@@ -189,8 +204,8 @@
 
        painter.begin(this);
 
-       pageTop = whichPage(y);
-       pageBottom = whichPage(y + eventHeight);
+       pageTop = whichPage(y, aligned);
+       pageBottom = whichPage(y + eventHeight, aligned);
 
        for (int i = 0; i < pages.size(); ++i) {
 

Modified: branches/client/pdf-presentation-branch/elvys-client/src/pdfzoomed.h
===================================================================
--- branches/client/pdf-presentation-branch/elvys-client/src/pdfzoomed.h        
2010-02-16 18:01:22 UTC (rev 1744)
+++ branches/client/pdf-presentation-branch/elvys-client/src/pdfzoomed.h        
2010-02-16 18:25:20 UTC (rev 1745)
@@ -35,7 +35,7 @@
                ~PDFZoomed();
                void setKeyBase(QString & _key);
                void setPages(QList <int> & _pageNumbers);
-               int whichPage(int y);
+               int whichPage(int y, bool & aligned);
 
        protected:                              
                void paintEvent(QPaintEvent * event);


Other related posts:

  • » [elvystrac] r1745 - scrolling by whole page works now ok - elvys