~ubuntu-branches/ubuntu/natty/luatex/natty

« back to all changes in this revision

Viewing changes to source/libs/poppler/poppler-0.12.4/qt/test-poppler-qt.cpp

  • Committer: Package Import Robot
  • Author(s): Norbert Preining
  • Date: 2010-12-13 23:22:59 UTC
  • mfrom: (0.2.1) (1.5.4) (4.3.12 experimental)
  • Revision ID: package-import@ubuntu.com-20101213232259-nqq2mq5z5x6qldw3
Tags: 0.65.0-1
* new upstream release
* ship two source packages as they are distributed by upstream, only
  renamed to match source package requirements. Fix debian/rules
  to install the manual pdf from the right place

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <qapplication.h>
 
2
#include <qpainter.h>
 
3
#include <qpixmap.h>
 
4
#include <qwidget.h>
 
5
#include <qlabel.h>
 
6
#include <qmessagebox.h>
 
7
#include <qfile.h>
 
8
#include <ctype.h>
 
9
#include <poppler-qt.h>
 
10
#include <stdlib.h>
 
11
 
 
12
class PDFDisplay : public QWidget           // picture display widget
 
13
{
 
14
public:
 
15
    PDFDisplay( Poppler::Document *d );
 
16
   ~PDFDisplay();
 
17
protected:
 
18
    void        paintEvent( QPaintEvent * );
 
19
    void        keyPressEvent( QKeyEvent * );
 
20
private:
 
21
    void display();
 
22
    
 
23
    int currentPage;
 
24
    QPixmap     *pixmap;
 
25
    Poppler::Document *doc;
 
26
};
 
27
 
 
28
PDFDisplay::PDFDisplay( Poppler::Document *d )
 
29
{
 
30
  doc = d;
 
31
  pixmap = 0;
 
32
  currentPage = 0;
 
33
  display();
 
34
}
 
35
 
 
36
PDFDisplay::~PDFDisplay()
 
37
{
 
38
  delete doc;
 
39
  delete pixmap;
 
40
}
 
41
 
 
42
void PDFDisplay::paintEvent( QPaintEvent *e )
 
43
{
 
44
  QPainter paint( this );                     // paint widget
 
45
  if (pixmap)
 
46
    paint.drawPixmap(0, 0, *pixmap);
 
47
}
 
48
 
 
49
void PDFDisplay::keyPressEvent( QKeyEvent *e )
 
50
{
 
51
  if (e->key() == Qt::Key_Down)
 
52
  {
 
53
    if (currentPage + 1 < doc->getNumPages())
 
54
    {
 
55
      currentPage++;
 
56
      display();
 
57
    }
 
58
  }
 
59
  else if (e->key() == Qt::Key_Up)
 
60
  {
 
61
    if (currentPage > 0)
 
62
    {
 
63
      currentPage--;
 
64
      display();
 
65
    }
 
66
  }
 
67
}
 
68
 
 
69
void PDFDisplay::display()
 
70
{
 
71
  if (doc) {
 
72
    Poppler::Page *page = doc->getPage(currentPage);
 
73
    if (page) {
 
74
      delete pixmap;
 
75
      page->renderToPixmap(&pixmap, -1, -1, -1, -1);
 
76
      delete page;
 
77
      update();
 
78
    }
 
79
  } else {
 
80
    printf("doc not loaded\n");
 
81
  }
 
82
}
 
83
 
 
84
int main( int argc, char **argv )
 
85
{
 
86
  QApplication a( argc, argv );               // QApplication required!
 
87
 
 
88
  if ( argc < 2  || (argc == 3 && strcmp(argv[2], "-extract") != 0) || argc > 3)
 
89
  {
 
90
    // use argument as file name
 
91
    printf("usage: test-poppler-qt filename [-extract]\n");
 
92
    exit(1);
 
93
  }
 
94
  
 
95
  Poppler::Document *doc = Poppler::Document::load(argv[1]);
 
96
  if (!doc)
 
97
  {
 
98
    printf("doc not loaded\n");
 
99
    exit(1);
 
100
  }
 
101
  
 
102
  if (argc == 2)
 
103
  {  
 
104
    PDFDisplay test( doc );        // create picture display
 
105
    a.setMainWidget( &test);                // set main widget
 
106
    test.setCaption("Poppler-Qt Test");
 
107
    test.show();                            // show it
 
108
 
 
109
    return a.exec();                        // start event loop
 
110
  }
 
111
  else
 
112
  {
 
113
    Poppler::Page *page = doc->getPage(0);
 
114
 
 
115
    QLabel *l = new QLabel(page->getText(Poppler::Rectangle()), 0);
 
116
    l->show();
 
117
    a.setMainWidget(l);                // set main widget
 
118
    delete page;
 
119
    delete doc;
 
120
    return a.exec();
 
121
  }
 
122
}