You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
2.4 KiB
123 lines
2.4 KiB
14 years ago
|
#include <tqapplication.h>
|
||
|
#include <tqpainter.h>
|
||
|
#include <tqpixmap.h>
|
||
|
#include <tqwidget.h>
|
||
|
#include <tqlabel.h>
|
||
|
#include <tqmessagebox.h>
|
||
|
#include <tqfile.h>
|
||
14 years ago
|
#include <ctype.h>
|
||
|
#include <poppler-qt.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
14 years ago
|
class PDFDisplay : public TQWidget // picture display widget
|
||
14 years ago
|
{
|
||
|
public:
|
||
|
PDFDisplay( Poppler::Document *d );
|
||
|
~PDFDisplay();
|
||
|
protected:
|
||
14 years ago
|
void paintEvent( TQPaintEvent * );
|
||
|
void keyPressEvent( TQKeyEvent * );
|
||
14 years ago
|
private:
|
||
|
void display();
|
||
|
|
||
|
int currentPage;
|
||
14 years ago
|
TQPixmap *pixmap;
|
||
14 years ago
|
Poppler::Document *doc;
|
||
|
};
|
||
|
|
||
|
PDFDisplay::PDFDisplay( Poppler::Document *d )
|
||
|
{
|
||
|
doc = d;
|
||
|
pixmap = 0;
|
||
|
currentPage = 0;
|
||
|
display();
|
||
|
}
|
||
|
|
||
|
PDFDisplay::~PDFDisplay()
|
||
|
{
|
||
|
delete doc;
|
||
|
delete pixmap;
|
||
|
}
|
||
|
|
||
14 years ago
|
void PDFDisplay::paintEvent( TQPaintEvent *e )
|
||
14 years ago
|
{
|
||
14 years ago
|
TQPainter paint( this ); // paint widget
|
||
14 years ago
|
if (pixmap)
|
||
|
paint.drawPixmap(0, 0, *pixmap);
|
||
|
}
|
||
|
|
||
14 years ago
|
void PDFDisplay::keyPressEvent( TQKeyEvent *e )
|
||
14 years ago
|
{
|
||
14 years ago
|
if (e->key() == TQt::Key_Down)
|
||
14 years ago
|
{
|
||
|
if (currentPage + 1 < doc->getNumPages())
|
||
|
{
|
||
|
currentPage++;
|
||
|
display();
|
||
|
}
|
||
|
}
|
||
14 years ago
|
else if (e->key() == TQt::Key_Up)
|
||
14 years ago
|
{
|
||
|
if (currentPage > 0)
|
||
|
{
|
||
|
currentPage--;
|
||
|
display();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void PDFDisplay::display()
|
||
|
{
|
||
|
if (doc) {
|
||
|
Poppler::Page *page = doc->getPage(currentPage);
|
||
|
if (page) {
|
||
|
delete pixmap;
|
||
|
page->renderToPixmap(&pixmap, -1, -1, -1, -1);
|
||
|
delete page;
|
||
|
update();
|
||
|
}
|
||
|
} else {
|
||
|
printf("doc not loaded\n");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int main( int argc, char **argv )
|
||
|
{
|
||
14 years ago
|
TQApplication a( argc, argv ); // TQApplication required!
|
||
14 years ago
|
|
||
|
if ( argc < 2 || (argc == 3 && strcmp(argv[2], "-extract") != 0) || argc > 3)
|
||
|
{
|
||
|
// use argument as file name
|
||
|
printf("usage: test-poppler-qt filename [-extract]\n");
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
Poppler::Document *doc = Poppler::Document::load(argv[1]);
|
||
|
if (!doc)
|
||
|
{
|
||
|
printf("doc not loaded\n");
|
||
|
exit(1);
|
||
|
}
|
||
|
|
||
|
if (argc == 2)
|
||
|
{
|
||
|
PDFDisplay test( doc ); // create picture display
|
||
|
a.setMainWidget( &test); // set main widget
|
||
14 years ago
|
test.setCaption("Poppler-TQt Test");
|
||
14 years ago
|
test.show(); // show it
|
||
|
|
||
|
return a.exec(); // start event loop
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Poppler::Page *page = doc->getPage(0);
|
||
|
|
||
14 years ago
|
TQLabel *l = new TQLabel(page->getText(Poppler::Rectangle()), 0);
|
||
14 years ago
|
l->show();
|
||
|
a.setMainWidget(l); // set main widget
|
||
|
delete page;
|
||
|
delete doc;
|
||
|
return a.exec();
|
||
|
}
|
||
|
}
|