[poppler] poppler/qt4/tests: test-poppler-qt4.cpp,1.2,1.3

Brad Hards bradh at freedesktop.org
Wed Aug 3 21:44:57 EST 2005


Update of /cvs/poppler/poppler/qt4/tests
In directory gabe:/tmp/cvs-serv12525/qt4/tests

Modified Files:
	test-poppler-qt4.cpp 
Log Message:
Implement paging ability for Qt4, more than a little based
on Albert's work for Qt3.
Up arrow -> previous page
Down arrow -> next page
q -> quit.

What more could you want from a PDF viewer :-)


Index: test-poppler-qt4.cpp
===================================================================
RCS file: /cvs/poppler/poppler/qt4/tests/test-poppler-qt4.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- test-poppler-qt4.cpp	4 Jul 2005 08:18:52 -0000	1.2
+++ test-poppler-qt4.cpp	3 Aug 2005 11:44:55 -0000	1.3
@@ -12,8 +12,11 @@
     PDFDisplay( Poppler::Document *d );
     ~PDFDisplay();
 protected:
-    void        paintEvent( QPaintEvent * );
+    void paintEvent( QPaintEvent * );
+    void keyPressEvent( QKeyEvent * );
 private:
+    void display();
+    int m_currentPage;
     QPixmap	*pixmap;
     Poppler::Document *doc;
 };
@@ -21,11 +24,19 @@
 PDFDisplay::PDFDisplay( Poppler::Document *d )
 {
     doc = d;
+    m_currentPage = 0;
+    display();
+}
+
+void PDFDisplay::display()
+{
     if (doc) {
-	Poppler::Page *page = doc->page("1");
+	Poppler::Page *page = doc->page(m_currentPage);
 	if (page) {
+	    qDebug() << "Displaying page: " << m_currentPage;
 	    pixmap = new QPixmap(page->pageSize());
 	    page->renderToPixmap(pixmap);
+	    update();
 	    delete page;
 	}
     } else {
@@ -49,6 +60,30 @@
     }
 }
 
+void PDFDisplay::keyPressEvent( QKeyEvent *e )
+{
+  if (e->key() == Qt::Key_Down)
+  {
+    if (m_currentPage + 1 < doc->numPages())
+    {
+      m_currentPage++;
+      display();
+    }
+  }
+  else if (e->key() == Qt::Key_Up)
+  {
+    if (m_currentPage > 0)
+    {
+      m_currentPage--;
+      display();
+    }
+  }
+  else if (e->key() == Qt::Key_Q)
+  {
+      exit(0);
+  }
+}
+
 int main( int argc, char **argv )
 {
     QApplication a( argc, argv );               // QApplication required!
@@ -92,14 +127,6 @@
 
     Poppler::Page *page = doc->page(0);
     qDebug() << "    Page 1 size: " << page->pageSize().width()/72 << "inches x " << page->pageSize().height()/72 << "inches";
-    if ( page->orientation() == Poppler::Page::Landscape ) {
-	qDebug() << "Landscape layout";
-    } else if ( page->orientation() == Poppler::Page::Portrait ) {
-	qDebug() << "Portrait layout";
-    } else {
-	qDebug() << "Unknown layout";
-    }
-
 
     if (argc == 2)
     {  



More information about the poppler mailing list