forked from jonathanverner/comment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestPdfPageItem.cpp
182 lines (143 loc) · 5.27 KB
/
testPdfPageItem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/** This file is part of project comment
*
* File: testPdfPageItem.cpp
* Created: 2008-10-12
* Author: Jonathan Verner <[email protected]>
* License: GPL v2 or later
*
* Copyright (C) 2010 Jonathan Verner <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include <poppler-qt4.h>
#include <QtGui/QApplication>
#include <QtCore/QString>
#include <QtCore/QDebug>
#include <QtCore/QFile>
#include <QtGui/QAction>
#include <QtGui/QImage>
#include <QtGui/QGraphicsScene>
#include <QtGui/QPixmap>
#include <QtGui/QLabel>
#include "testView.h"
#include "pdfPageItem.h"
//#include "commentItem.h"
int main(int argc, char **argv) {
QApplication app( argc, argv );
if ( argc < 3 ) {
qDebug() << "Usage: " << argv[0] << " pdf-file page-number";
return -1;
}
QString fileName( argv[1] ), pgn( argv[2] );
bool ok;
int pgNum = pgn.toInt(&ok);
if ( ! ok ) {
qDebug() << "Error: " << pgn << "is not a number";
qDebug() << "Usage: " << argv[0] << " pdf-file page-number";
return -1;
}
if ( pgNum < 1 ) {
qDebug() << "Error: " << pgn << "is not a valid page number";
qDebug() << "Usage: " << argv[0] << " pdf-file page-number";
return -1;
}
pgNum--;
QFile fl( fileName );
if ( ! fl.exists() ) {
qDebug() << "File not found: " << fileName;
return -1;
}
Poppler::Document *pdf = Poppler::Document::load( fileName );
if ( ! pdf ) {
qDebug() << "Error reading file " << fileName;
return -1;
} else {
pdf->setRenderHint( Poppler::Document::TextAntialiasing, true );
pdf->setRenderHint( Poppler::Document::Antialiasing, true );
}
if ( pdf->numPages() < pgNum ) {
qDebug() << pgNum <<": No such page in pdf file. Pdf file has " << pdf->numPages() << " pages.";
return -1;
}
Poppler::Page *page = pdf->page( pgNum );
QGraphicsScene scene;
// pdfPageItem pdfPage( page );
// commentItem comment(100,100);
testView view( &scene );
QPixmap comment_icon, hover;
comment_icon.load("comment.png");
hover.load("hover.png");
pdfPageItem *pageItem;
qreal y=0;
for(int i = 0; i < pdf->numPages(); i++ ) {
pageItem = new pdfPageItem( pdf->page( i ) );
pageItem->setPos(10,y);
y+=pageItem->boundingRect().height()+10;
scene.addItem( pageItem );
};
// scene.addItem( &pdfPage );
// scene.addItem( &comment );
scene.setBackgroundBrush(Qt::gray);
// comment.setZValue( 1 );
// comment.setIcon( comment_icon );
// comment.setText(" Toto je testovaci comment " );
// view.ignore_item_interaction( &pdfPage );
// comment.setToolTip( hover );
// scene.setSceneRect(0,0,600,800);
// testPageView view( &scene, page, 0 );
// scene.addRect(QRect(0,0,50,50));
// view.ukaz();
view.show();
QAction *quitAct = new QAction( &view );
/*QAction *nextAct = new QAction( &view );*/
/*QAction *prevAct = new QAction( &view );*/
QAction *zoomInAct = new QAction( &view );
QAction *zoomOutAct = new QAction( &view );
/*QAction *leftAct = new QAction( &view );*/
/*QAction *rightAct = new QAction( &view );*/
/*QAction *upAct = new QAction( &view );*/
/*QAction *downAct = new QAction( &view );*/
quitAct->setShortcut((QString) "Ctrl+Q");
/*nextAct->setShortcut((QString) "Ctrl+N");*/
/*prevAct->setShortcut((QString) "Ctrl+P");*/
zoomInAct->setShortcut((QString) "Ctrl++");
zoomOutAct->setShortcut((QString) "Ctrl+-");
/* */
/*leftAct->setShortcut((QString) "Left");*/
/*rightAct->setShortcut((QString) "Right");*/
/*upAct->setShortcut((QString) "Up");*/
/*downAct->setShortcut((QString) "Down");*/
view.addAction(quitAct);
/*view.addAction(nextAct);*/
/*view.addAction(prevAct);*/
view.addAction(zoomInAct);
view.addAction(zoomOutAct);
/*view.addAction(leftAct);*/
/*view.addAction(rightAct);*/
/*view.addAction(upAct);*/
/*view.addAction(downAct);*/
QObject::connect( quitAct, SIGNAL( triggered() ), &app, SLOT( quit() ) );
/*QObject::connect( nextAct, SIGNAL( triggered() ), &view, SLOT( nextview() ) );*/
/*QObject::connect( prevAct, SIGNAL( triggered() ), &view, SLOT( prevview() ) );*/
QObject::connect( zoomInAct, SIGNAL( triggered() ), &view, SLOT( zoomIN() ) );
QObject::connect( zoomOutAct, SIGNAL( triggered() ), &view, SLOT( zoomOUT() ) );
/* QObject::connect( leftAct, SIGNAL( triggered() ), &view, SLOT( left() ) );
QObject::connect( rightAct, SIGNAL( triggered() ), &view, SLOT( right() ) );
QObject::connect( upAct, SIGNAL( triggered() ), &view, SLOT( up() ) );
QObject::connect( downAct, SIGNAL( triggered() ), &view, SLOT( down() ) ); */
app.exec();
return 0;
}