-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathabstractTool.h
More file actions
286 lines (214 loc) · 7.79 KB
/
Copy pathabstractTool.h
File metadata and controls
286 lines (214 loc) · 7.79 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#ifndef _abstractTool_H
#define _abstractTool_H
/***************************************************************
* abstractTool.h
* @Author: Jonathan Verner (jonathan.verner@matfyz.cz)
* @License: GPL v2.0 or later
* @Created: 2008-10-17.
* @Last Change: 2008-10-17.
* @Revision: 0.0
* Description:
* Usage:
* TODO:
*CHANGES:
***************************************************************/
#include <QtCore/QString>
#include <QtCore/QDate>
#include <QtCore/QTime>
#include <QtCore/QMap>
#include <QtCore/QVariant>
#include <QtGui/QPixmap>
#include <QtGui/QGraphicsItem>
#include <QtGui/QGraphicsObject>
#include <QtGui/QColor>
class QToolBar;
class QStackedWidget;
class abstractAnnotation;
class renderTeX;
class QWidget;
class QPoint;
class pdfScene;
class QGraphicsSceneMouseEvent;
class QGraphicsSceneHoverEvent;
class toolBox;
class viewEvent;
class QLabel;
class QMenu;
class QTabWidget;
class QTextEdit;
class propertyTab;
namespace PoDoFo {
class PdfAnnotation;
class PdfDocument;
class PdfPage;
class PdfAnnotation;
}
class pdfCoords;
class abstractTool : public QObject {
Q_OBJECT
private:
QString toolName;
QString author;
QColor color;
renderTeX *renderer;
QVector<abstractAnnotation *> int2annot;
QString selectedText;
protected:
QStackedWidget *editArea;
toolBox *toolBar;
pdfScene *scene;
QTabWidget *editor;
QTextEdit *contentEdit;
propertyTab *propertyEdit;
QMenu *cntxMenu;
abstractAnnotation *currentEditItem;
void setToolName( QString ToolName ) { toolName = ToolName; };
void setTeXToolTip( abstractAnnotation *annotation );
int getApproxWidth( QString text );
protected slots:
void deleteCurrentAnnotation();
void editCurrentAnnotationProperties();
void updateContent();
void updateAuthor();
void updateColor();
void teXToolTipReady( int annotID );
void nextEditorTab();
void prevEditorTab();
virtual void prepareEditItem( abstractAnnotation *item );
public:
abstractTool( pdfScene *Scene, toolBox *ToolBar, QStackedWidget *EditArea );
~abstractTool();
QString getAuthor() const { return author; };
QColor getColor() const { return color; };
void setAuthor( const QString &Author ) { author = Author;};
/* Sets the color of the annotation, whatever
* that means. The abstract implementation
* just sets the private color variable */
virtual QColor setColor( const QColor &col );
QString getToolName() { return toolName; };
/* Returns a pointer to a newly created annotation, if the annotation was recognized,
* otherwise returns NULL. Note that the new annotation should have its position
* relative to the page. However this should be intuitive :-) */
virtual abstractAnnotation *processAnnotation( PoDoFo::PdfDocument *doc, PoDoFo::PdfAnnotation *annotation, pdfCoords *transform ) = 0;
/* Called when the user wants to add a new annotation at scenePos
* (scene coordinates) */
virtual void newActionEvent( const QPointF *scenePos ) = 0;
/* Edit the item (i.e. show an editing widget, etc.),
* if the item is currently already being edited, hide
* it instead */
virtual void editItem( abstractAnnotation *item );
/* Finish editing the currently edited item (if any) */
virtual void finishEditing();
/* Called by the view when an event happens. Returns true, if
* tool handles the event, otherwise returns false; */
virtual bool handleEvent( viewEvent *ev );
/* Returns true, if the tool handles events for the item it */
virtual bool acceptEventsFor( QGraphicsItem *it ) = 0;
/* Returns the context menu for the item *it */
virtual QMenu *contextMenu( QGraphicsItem *it );
public slots:
virtual void hideEditor();
signals:
void needKeyFocus( bool );
friend class abstractAnnotation;
};
class abstractAnnotation : public QGraphicsObject {
Q_OBJECT
public:
/* The enumeration type holding
* supported annotation types.
*/
enum eAnnotationTypes {
eHilight,
eUnderline,
eSquiggly,
eStrikeOut,
eFreeText,
eLink,
eText,
eNone
};
private:
QPixmap toolTipPixMap, icon;
QString toolTipRichText;
bool waitingForToolTip, haveToolTip, moved, showingToolTip;
enum toolTipType { pixmap, text };
toolTipType tp;
QString author,content;
QDate date;
QTime time;
QColor color;
/*
* The contents of the Rect key from the annotation dictionary
* transformed into QGraphicsView Page-coordinates. Currently
* this does not change throughout the lifetime of the annotation,
* but users should not rely on this behaviour.
*/
QRectF annotationRect;
protected:
/* Data that will be stored in a the 'CommentData'
* subdictionary of the annotation dictionary */
QMap<QString, QVariant> implementationData;
/* The type of the annotation */
enum eAnnotationTypes annotType;
/* If \param annot != NULL, converts the annotation type from the
* PoDoFo::EPdfAnnotation enum to eAnnotationTypes enum.
* If \param annot == NULL, returns eNone
*
* \param annot NULL OK
*/
static enum eAnnotationTypes getTypeFromPoDoFo( const PoDoFo::PdfAnnotation *annot );
/* The tool that corresponds to the annotation type */
abstractTool *myTool;
bool movable;
virtual void setMyToolTip(const QPixmap &pixMap);
virtual void setMyToolTip(const QString &richText);
void setIcon( const QPixmap &icon);
QPixmap getMyToolTipPixmap() const { return toolTipPixMap; };
bool havePixmapTooltip() const { return (tp == pixmap); };
void saveInfo2PDF( PoDoFo::PdfAnnotation *annot );
/* Reads data common to all annotations from PDF annotation \param annot
* The data currently read: Author, Content, Color, Rect, implementation data
* It also sets the annotation type */
void loadInfoFromPDF( PoDoFo::PdfAnnotation* annot, pdfCoords* transform );
/* Note that the constructor, as it is currently implemented,
* must cope with \param annot == NULL and \param transform == NULL */
abstractAnnotation( abstractTool *tool, PoDoFo::PdfAnnotation *annot, pdfCoords *transform );
friend class abstractTool;
public:
static bool isA( PoDoFo::PdfAnnotation *annotation ) { return false; };
public:
abstractAnnotation( abstractTool *tool );
virtual ~abstractAnnotation() {};
bool showToolTip( const QPoint &scPos );
void hideToolTip();
/* ??? if returns true, then it accepted the edit event ??? */
virtual bool editSelf();
virtual void finishEditing();
/* Returns the context menu for the item *it */
virtual QMenu *contextMenu();
bool hasToolTip();
virtual bool isMovable() { return movable; };
void setContent( QString Content );
void setAuthor( QString a ) { author = a; };
void setDate( QDate d ) { date = d; };
void setTime( QTime t ) { time = t; };
void setColor( QColor col ) { if ( col.isValid() ) color = col; };
virtual QString getContent() const { return content; };
QColor getColor() const { return color; };
QString getAuthor() const { return author; };
QDate getDate() const { return date; };
QTime getTime() const { return time; };
QRectF getAnnotRect() const { return annotationRect; };
enum eAnnotationTypes getTyp() const { return annotType; };
virtual QRectF boundingRect() const;
virtual void paint( QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget );
/* Creates a new PoDoFo::PdfAnnotation on page \param pg,
* sets the Color, Author, Date and Time and returns it.
* The Rect key of the Annotation dictionary is determined
* by calling the boundingRect() method */
virtual PoDoFo::PdfAnnotation *saveToPdfPage( PoDoFo::PdfDocument *document, PoDoFo::PdfPage *pg, pdfCoords *coords );
signals:
void needKeyFocus( bool );
};
#endif /* _abstractTool_H */