summaryrefslogtreecommitdiff
path: root/qt5/src/poppler-link.h
blob: 7f52e20310c34ec07be6469181ec2c0e4ef4f4bc (plain)
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
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
/* poppler-link.h: qt interface to poppler
 * Copyright (C) 2006, 2013, 2016, 2018, 2019, Albert Astals Cid <aacid@kde.org>
 * Copyright (C) 2007-2008, 2010, Pino Toscano <pino@kde.org>
 * Copyright (C) 2010, 2012, Guillermo Amaral <gamaral@kdab.com>
 * Copyright (C) 2012, Tobias Koenig <tokoe@kdab.com>
 * Copyright (C) 2013, Anthony Granger <grangeranthony@gmail.com>
 * Copyright (C) 2018 Intevation GmbH <intevation@intevation.de>
 * Adapting code from
 *   Copyright (C) 2004 by Enrico Ros <eros.kde@email.it>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef _POPPLER_LINK_H_
#define _POPPLER_LINK_H_

#include <QtCore/QString>
#include <QtCore/QRectF>
#include <QtCore/QSharedDataPointer>
#include <QtCore/QVector>
#include "poppler-export.h"

struct Ref;
class MediaRendition;

namespace Poppler {

class LinkPrivate;
class LinkGotoPrivate;
class LinkExecutePrivate;
class LinkBrowsePrivate;
class LinkActionPrivate;
class LinkSoundPrivate;
class LinkJavaScriptPrivate;
class LinkMoviePrivate;
class LinkDestinationData;
class LinkDestinationPrivate;
class LinkRenditionPrivate;
class LinkOCGStatePrivate;
class LinkHidePrivate;
class MediaRendition;
class MovieAnnotation;
class ScreenAnnotation;
class SoundObject;

/**
 * \short A destination.
 *
 * The LinkDestination class represent a "destination" (in terms of visual
 * viewport to be displayed) for \link Poppler::LinkGoto GoTo\endlink links,
 * and items in the table of contents (TOC) of a document.
 *
 * Coordinates are in 0..1 range
 */
class POPPLER_QT5_EXPORT LinkDestination
{
	public:
		/**
		 * The possible kind of "viewport destination".
		 */
		enum Kind
		{
			/**
			 * The new viewport is specified in terms of:
			 * - possible new left coordinate (see isChangeLeft() )
			 * - possible new top coordinate (see isChangeTop() )
			 * - possible new zoom level (see isChangeZoom() )
			 */
			destXYZ = 1,
			destFit = 2,
			destFitH = 3,
			destFitV = 4,
			destFitR = 5,
			destFitB = 6,
			destFitBH = 7,
			destFitBV = 8
		};

		/// \cond PRIVATE
		LinkDestination(const LinkDestinationData &data);
		LinkDestination(const QString &description);
		/// \endcond
		/**
		 * Copy constructor.
		 */
		LinkDestination(const LinkDestination &other);
		/**
		 * Destructor.
		 */
		~LinkDestination();

		// Accessors.
		/**
		 * The kind of destination.
		 */
		Kind kind() const;
		/**
		 * Which page is the target of this destination.
		 *
		 * \note this number is 1-based, so for a 5 pages document the
		 *       valid page numbers go from 1 to 5 (both included).
		 */
		int pageNumber() const;
		/**
		 * The new left for the viewport of the target page, in case
		 * it is specified to be changed (see isChangeLeft() )
		 */
		double left() const;
		double bottom() const;
		double right() const;
		/**
		 * The new top for the viewport of the target page, in case
		 * it is specified to be changed (see isChangeTop() )
		 */
		double top() const;
		double zoom() const;
		/**
		 * Whether the left of the viewport on the target page should
		 * be changed.
		 *
		 * \see left()
		 */
		bool isChangeLeft() const;
		/**
		 * Whether the top of the viewport on the target page should
		 * be changed.
		 *
		 * \see top()
		 */
		bool isChangeTop() const;
		/**
		 * Whether the zoom level should be changed.
		 *
		 * \see zoom()
		 */
		bool isChangeZoom() const;

		/**
		 * Return a string repesentation of this destination.
		 */
		QString toString() const;

		/**
		 * Return the name of this destination.
		 *
		 * \since 0.12
		 */
		QString destinationName() const;

		/**
		 * Assignment operator.
		 */
		LinkDestination& operator=(const LinkDestination &other);

	private:
		QSharedDataPointer< LinkDestinationPrivate > d;
};

/**
 * \short Encapsulates data that describes a link.
 *
 * This is the base class for links. It makes mandatory for inherited
 * kind of links to reimplement the linkType() method and return the type of
 * the link described by the reimplemented class.
 */
class POPPLER_QT5_EXPORT Link
{
	friend class OptContentModel;

	public:
		/// \cond PRIVATE
		Link( const QRectF &linkArea );
		/// \endcond
		
		/**
		 * The possible kinds of link.
		 *
		 * Inherited classes must return an unique identifier
		 */
		enum LinkType
		{
		    None,     ///< Unknown link
		    Goto,     ///< A "Go To" link
		    Execute,  ///< A command to be executed
		    Browse,   ///< An URL to be browsed (eg "http://poppler.freedesktop.org")
		    Action,   ///< A "standard" action to be executed in the viewer
		    Sound,    ///< A link representing a sound to be played
		    Movie,    ///< An action to be executed on a movie
		    Rendition,    ///< A rendition link \since 0.20
		    JavaScript,   ///< A JavaScript code to be interpreted \since 0.10
		    OCGState,      ///< An Optional Content Group state change \since 0.50
		    Hide,     ///< An action to hide a field \since 0.64
		};

		/**
		 * The type of this link.
		 */
		virtual LinkType linkType() const;

		/**
		 * Destructor.
		 */
		virtual ~Link();
		
		/**
		 * The area of a Page where the link should be active.
		 *
		 * \note this can be a null rect, in this case the link represents
		 * a general action. The area is given in 0..1 range
		 */
		QRectF linkArea() const;

		/**
		 * Get the next links to be activated / executed after this link.
		 *
		 * \since 0.64
		 */
		QVector<Link *> nextLinks() const;

	protected:
		/// \cond PRIVATE
		Link( LinkPrivate &dd );
		Q_DECLARE_PRIVATE( Link )
		LinkPrivate *d_ptr;
		/// \endcond
		
	private:
		Q_DISABLE_COPY( Link )
};


/**
 * \brief Viewport reaching request.
 *
 * With a LinkGoto link, the document requests the specified viewport to be
 * reached (aka, displayed in a viewer). Furthermore, if a file name is specified,
 * then the destination refers to that document (and not to the document the
 * current LinkGoto belongs to).
 */
class POPPLER_QT5_EXPORT LinkGoto : public Link
{
	public:
		/**
		 * Create a new Goto link.
		 *
		 * \param linkArea the active area of the link
		 * \param extFileName if not empty, the file name to be open
		 * \param destination the destination to be reached
		 */
		// TODO Next ABI break, make extFileName const &
		LinkGoto( const QRectF &linkArea, QString extFileName, const LinkDestination & destination );
		/**
		 * Destructor.
		 */
		~LinkGoto();

		/**
		 * Whether the destination is in an external document
		 * (i.e. not the current document)
		 */
		bool isExternal() const;
		// query for goto parameters
		/**
		 * The file name of the document the destination() refers to,
		 * or an empty string in case it refers to the current document.
		 */
		QString fileName() const;
		/**
		 * The destination to reach.
		 */
		LinkDestination destination() const;
		LinkType linkType() const override;

	private:
		Q_DECLARE_PRIVATE( LinkGoto )
		Q_DISABLE_COPY( LinkGoto )
};

/**
 * \brief Generic execution request.
 *
 * The LinkExecute link represent a "file name" execution request. The result
 * depends on the \link fileName() file name\endlink:
 * - if it is a document, then it is requested to be open
 * - otherwise, it represents an executable to be run with the specified parameters
 */
class POPPLER_QT5_EXPORT LinkExecute : public Link
{
	public:
		/**
		 * The file name to be executed
		 */
		QString fileName() const;
		/**
		 * The parameters for the command.
		 */
		QString parameters() const;

		/**
		 * Create a new Execute link.
		 *
		 * \param linkArea the active area of the link
		 * \param file the file name to be open, or the program to be execute
		 * \param params the parameters for the program to execute
		 */
		LinkExecute( const QRectF &linkArea, const QString & file, const QString & params );
		/**
		 * Destructor.
		 */
		~LinkExecute();
		LinkType linkType() const override;

	private:
		Q_DECLARE_PRIVATE( LinkExecute )
		Q_DISABLE_COPY( LinkExecute )
};

/**
 * \brief An URL to browse.
 *
 * The LinkBrowse link holds a URL (eg 'http://poppler.freedesktop.org',
 * 'mailto:john@some.org', etc) to be open.
 *
 * The format of the URL is specified by RFC 2396 (http://www.ietf.org/rfc/rfc2396.txt)
 */
class POPPLER_QT5_EXPORT LinkBrowse : public Link
{
	public:
		/**
		 * The URL to open
		 */
		QString url() const;

		/**
		 * Create a new browse link.
		 *
		 * \param linkArea the active area of the link
		 * \param url the URL to be open
		 */
		LinkBrowse( const QRectF &linkArea, const QString &url );
		/**
		 * Destructor.
		 */
		~LinkBrowse();
		LinkType linkType() const override;

	private:
		Q_DECLARE_PRIVATE( LinkBrowse )
		Q_DISABLE_COPY( LinkBrowse )
};	

/**
 * \brief "Standard" action request.
 *
 * The LinkAction class represents a link that request a "standard" action
 * to be performed by the viewer on the displayed document.
 */
class POPPLER_QT5_EXPORT LinkAction : public Link
{
	public:
		/**
		 * The possible types of actions
		 */
		enum ActionType { PageFirst = 1,
		                  PagePrev = 2,
		                  PageNext = 3,
		                  PageLast = 4,
		                  HistoryBack = 5,
		                  HistoryForward = 6,
		                  Quit = 7,
		                  Presentation = 8,
		                  EndPresentation = 9,
		                  Find = 10,
		                  GoToPage = 11,
		                  Close = 12,
		                  Print = 13    ///< \since 0.16
		};

		/**
		 * The action of the current LinkAction
		 */
		ActionType actionType() const;

		/**
		 * Create a new Action link, that executes a specified action
		 * on the document.
		 *
		 * \param linkArea the active area of the link
		 * \param actionType which action should be executed
		 */
		LinkAction( const QRectF &linkArea, ActionType actionType );
		/**
		 * Destructor.
		 */
		~LinkAction();
		LinkType linkType() const override;

	private:
		Q_DECLARE_PRIVATE( LinkAction )
		Q_DISABLE_COPY( LinkAction )
};

/**
 * Sound: a sound to be played.
 *
 * \since 0.6
 */
class POPPLER_QT5_EXPORT LinkSound : public Link
{
	public:
		// create a Link_Sound
		LinkSound( const QRectF &linkArea, double volume, bool sync, bool repeat, bool mix, SoundObject *sound );
		/**
		 * Destructor.
		 */
		~LinkSound();

		LinkType linkType() const override;

		/**
		 * The volume to be used when playing the sound.
		 *
		 * The volume is in the range [ -1, 1 ], where:
		 * - a negative number: no volume (mute)
		 * - 1: full volume
		 */
		double volume() const;
		/**
		 * Whether the playback of the sound should be synchronous
		 * (thus blocking, waiting for the end of the sound playback).
		 */
		bool synchronous() const;
		/**
		 * Whether the sound should be played continuously (that is,
		 * started again when it ends)
		 */
		bool repeat() const;
		/**
		 * Whether the playback of this sound can be mixed with
		 * playbacks with other sounds of the same document.
		 *
		 * \note When false, any other playback must be stopped before
		 *       playing the sound.
		 */
		bool mix() const;
		/**
		 * The sound object to be played
		 */
		SoundObject *sound() const;

	private:
		Q_DECLARE_PRIVATE( LinkSound )
		Q_DISABLE_COPY( LinkSound )
};

/**
 * Rendition: Rendition link.
 *
 * \since 0.20
 */
class POPPLER_QT5_EXPORT LinkRendition : public Link
{
	public:
		/**
		 * Describes the possible rendition actions.
		 *
		 * \since 0.22
		 */
		enum RenditionAction {
			NoRendition,
			PlayRendition,
			StopRendition,
			PauseRendition,
			ResumeRendition
		};

		/**
		 * Create a new rendition link.
		 *
		 * \param linkArea the active area of the link
		 * \param rendition the media rendition object. Ownership is taken
		 * \param operation the numeric operation (action) (@see ::LinkRendition::RenditionOperation)
		 * \param script the java script code
		 * \param annotationReference the object reference of the screen annotation associated with this rendition action
		 * \since 0.22
		 */
		// TODO Next ABI break, remove & from annotationReference
		LinkRendition( const QRectF &linkArea, ::MediaRendition *rendition, int operation, const QString &script, const Ref &annotationReference );

		/**
		 * Destructor.
		 */
		~LinkRendition();

		LinkType linkType() const override;

		/**
		 * Returns the media rendition object if the redition provides one, @c 0 otherwise
		 */
		MediaRendition *rendition() const;

		/**
		 * Returns the action that should be executed if a rendition object is provided.
		 *
		 * \since 0.22
		 */
		RenditionAction action() const;

		/**
		 * The JS code that shall be executed or an empty string.
		 *
		 * \since 0.22
		 */
		QString script() const;

		/**
		 * Returns whether the given @p annotation is the referenced screen annotation for this rendition @p link.
		 *
		 * \since 0.22
		 */
		bool isReferencedAnnotation( const ScreenAnnotation *annotation ) const;

	private:
		Q_DECLARE_PRIVATE( LinkRendition )
		Q_DISABLE_COPY( LinkRendition )
};

/**
 * JavaScript: a JavaScript code to be interpreted.
 *
 * \since 0.10
 */
class POPPLER_QT5_EXPORT LinkJavaScript : public Link
{
	public:
		/**
		 * Create a new JavaScript link.
		 *
		 * \param linkArea the active area of the link
		 * \param js the JS code to be interpreted
		 */
		LinkJavaScript( const QRectF &linkArea, const QString &js );
		/**
		 * Destructor.
		 */
		~LinkJavaScript();

		LinkType linkType() const override;

		/**
		 * The JS code
		 */
		QString script() const;

	private:
		Q_DECLARE_PRIVATE( LinkJavaScript )
		Q_DISABLE_COPY( LinkJavaScript )
};	

/**
 * Movie: a movie to be played.
 *
 * \since 0.20
 */
class POPPLER_QT5_EXPORT LinkMovie : public Link
{
	public:
		/**
		 * Describes the operation to be performed on the movie.
		 */
		enum Operation { Play,
		                 Stop,
		                 Pause,
		                 Resume
		};

		/**
		 * Create a new Movie link.
		 *
		 * \param linkArea the active area of the link
		 * \param operation the operation to be performed on the movie
		 * \param annotationTitle the title of the movie annotation identifying the movie to be played
		 * \param annotationReference the object reference of the movie annotation identifying the movie to be played
		 *
		 * Note: This constructor is supposed to be used by Poppler::Page only.
		 */
		// TODO Next ABI break, remove & from annotationReference
		LinkMovie( const QRectF &linkArea, Operation operation, const QString &annotationTitle, const Ref &annotationReference );
		/**
		 * Destructor.
		 */
		~LinkMovie();
		LinkType linkType() const override;
		/**
		 * Returns the operation to be performed on the movie.
		 */
		Operation operation() const;
		/**
		 * Returns whether the given @p annotation is the referenced movie annotation for this movie @p link.
		 */
		bool isReferencedAnnotation( const MovieAnnotation *annotation ) const;

	private:
		Q_DECLARE_PRIVATE( LinkMovie )
		Q_DISABLE_COPY( LinkMovie )
};

/**
 * OCGState: an optional content group state change.
 *
 * \since 0.50
 */
class POPPLER_QT5_EXPORT LinkOCGState : public Link
{
	public:
		/**
		 * Create a new OCGState link. This is only used by Poppler::Page.
		 */
		LinkOCGState( LinkOCGStatePrivate *ocgp );
		/**
		 * Destructor.
		 */
		~LinkOCGState();

		LinkType linkType() const override;

	private:
		Q_DECLARE_PRIVATE( LinkOCGState )
		Q_DISABLE_COPY( LinkOCGState )
};

/**
 * Hide: an action to show / hide a field.
 *
 * \since 0.64
 */
class POPPLER_QT5_EXPORT LinkHide: public Link
{
	public:
		/**
		 * Create a new Hide link. This is only used by Poppler::Page.
		 */
		LinkHide( LinkHidePrivate *lhidep );
		/**
		 * Destructor.
		 */
		~LinkHide();

		LinkType linkType() const override;

		/**
		 * The fully qualified target names of the action.
		 */
		QVector< QString > targets() const;

		/**
		 * Should this action change the visibility of the target to true.
		 */
		bool isShowAction() const;

	private:
		Q_DECLARE_PRIVATE( LinkHide )
		Q_DISABLE_COPY( LinkHide )
};

}

#endif