Okular

action.cpp
1/*
2 SPDX-FileCopyrightText: 2004-2005 Enrico Ros <eros.kde@email.it>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "action.h"
8
9// kde includes
10#include <KLocalizedString>
11
12// local includes
13#include "document.h"
14#include "movie.h"
15#include "sound.h"
16#include "sourcereference_p.h"
17
18using namespace Okular;
19
20class Okular::ActionPrivate
21{
22public:
23 ActionPrivate()
24 {
25 }
26
27 virtual ~ActionPrivate()
28 {
29 qDeleteAll(m_nextActions);
30 }
31
32 ActionPrivate(const ActionPrivate &) = delete;
33 ActionPrivate &operator=(const ActionPrivate &) = delete;
34
35 QVariant m_nativeId;
36 QVector<Action *> m_nextActions;
37};
38
39Action::Action(ActionPrivate &dd)
40 : d_ptr(&dd)
41{
42}
43
44Action::~Action()
45{
46 delete d_ptr;
47}
48
49QString Action::actionTip() const
50{
51 return QLatin1String("");
52}
53
54void Action::setNativeId(const QVariant &id)
55{
56 Q_D(Action);
57 d->m_nativeId = id;
58}
59
60QVariant Action::nativeId() const
61{
62 Q_D(const Action);
63 return d->m_nativeId;
64}
65
66QVector<Action *> Action::nextActions() const
67{
68 Q_D(const Action);
69 return d->m_nextActions;
70}
71
72void Action::setNextActions(const QVector<Action *> &actions)
73{
74 Q_D(Action);
75 qDeleteAll(d->m_nextActions);
76 d->m_nextActions = actions;
77}
78
79// GotoAction
80
81class Okular::GotoActionPrivate : public Okular::ActionPrivate
82{
83public:
84 GotoActionPrivate(const QString &fileName, const DocumentViewport &viewport)
85 : ActionPrivate()
86 , m_extFileName(fileName)
87 , m_vp(viewport)
88 {
89 }
90
91 GotoActionPrivate(const QString &fileName, const QString &namedDestination)
92 : ActionPrivate()
93 , m_extFileName(fileName)
94 , m_dest(namedDestination)
95 {
96 }
97
98 QString m_extFileName;
100 QString m_dest;
101};
102
103GotoAction::GotoAction(const QString &fileName, const DocumentViewport &viewport)
104 : Action(*new GotoActionPrivate(fileName, viewport))
105{
106}
107
108GotoAction::GotoAction(const QString &fileName, const QString &namedDestination)
109 : Action(*new GotoActionPrivate(fileName, namedDestination))
110{
111}
112
116
118{
119 return Goto;
120}
121
123{
124 Q_D(const GotoAction);
125 return d->m_extFileName.isEmpty() ? (d->m_vp.isValid() ? i18n("Go to page %1", d->m_vp.pageNumber + 1) : QLatin1String("")) : i18n("Open external file");
126}
127
129{
130 Q_D(const GotoAction);
131 return !d->m_extFileName.isEmpty();
132}
133
135{
136 Q_D(const GotoAction);
137 return d->m_extFileName;
138}
139
141{
142 Q_D(const GotoAction);
143 return d->m_vp;
144}
145
147{
148 Q_D(const GotoAction);
149 return d->m_dest;
150}
151
152// ExecuteAction
153
154class Okular::ExecuteActionPrivate : public Okular::ActionPrivate
155{
156public:
157 ExecuteActionPrivate(const QString &file, const QString &parameters)
158 : ActionPrivate()
159 , m_fileName(file)
160 , m_parameters(parameters)
161 {
162 }
163
164 QString m_fileName;
165 QString m_parameters;
166};
167
168ExecuteAction::ExecuteAction(const QString &file, const QString &parameters)
169 : Action(*new ExecuteActionPrivate(file, parameters))
170{
171}
172
176
181
183{
185 return i18n("Execute '%1'...", d->m_fileName);
186}
187
189{
191 return d->m_fileName;
192}
193
195{
197 return d->m_parameters;
198}
199
200// BrowseAction
201
202class Okular::BrowseActionPrivate : public Okular::ActionPrivate
203{
204public:
205 explicit BrowseActionPrivate(const QUrl &url)
206 : ActionPrivate()
207 , m_url(url)
208 {
209 }
210
211 QUrl m_url;
212};
213
215 : Action(*new BrowseActionPrivate(url))
216{
217}
218
222
227
229{
231 QString source;
232 int row = 0, col = 0;
233 if (extractLilyPondSourceReference(d->m_url, &source, &row, &col)) {
234 return sourceReferenceToolTip(source, row, col);
235 }
236 return d->m_url.toDisplayString();
237}
238
240{
242 return d->m_url;
243}
244
245// DocumentAction
246
247class Okular::DocumentActionPrivate : public Okular::ActionPrivate
248{
249public:
250 explicit DocumentActionPrivate(enum DocumentAction::DocumentActionType documentActionType)
251 : ActionPrivate()
252 , m_type(documentActionType)
253 {
254 }
255
257};
258
260 : Action(*new DocumentActionPrivate(documentActionType))
261{
262}
263
267
273
278
280{
282 switch (d->m_type) {
283 case PageFirst:
284 return i18n("First Page");
285 case PagePrev:
286 return i18n("Previous Page");
287 case PageNext:
288 return i18n("Next Page");
289 case PageLast:
290 return i18n("Last Page");
291 case HistoryBack:
292 return i18n("Back");
293 case HistoryForward:
294 return i18n("Forward");
295 case Quit:
296 return i18n("Quit");
297 case Presentation:
298 return i18n("Start Presentation");
299 case EndPresentation:
300 return i18n("End Presentation");
301 case Find:
302 return i18n("Find...");
303 case GoToPage:
304 return i18n("Go To Page...");
305 case Close:
306 default:;
307 }
308
309 return QString();
310}
311
312// SoundAction
313
314class Okular::SoundActionPrivate : public Okular::ActionPrivate
315{
316public:
317 SoundActionPrivate(double volume, bool sync, bool repeat, bool mix, Okular::Sound *sound)
318 : ActionPrivate()
319 , m_volume(volume)
320 , m_sync(sync)
321 , m_repeat(repeat)
322 , m_mix(mix)
323 , m_sound(sound)
324 {
325 }
326
327 ~SoundActionPrivate() override
328 {
329 delete m_sound;
330 }
331
332 double m_volume;
333 bool m_sync : 1;
334 bool m_repeat : 1;
335 bool m_mix : 1;
336 Okular::Sound *m_sound;
337};
338
339SoundAction::SoundAction(double volume, bool sync, bool repeat, bool mix, Okular::Sound *sound)
340 : Action(*new SoundActionPrivate(volume, sync, repeat, mix, sound))
341{
342}
343
347
352
354{
355 return i18n("Play sound...");
356}
357
359{
361 return d->m_volume;
362}
363
365{
367 return d->m_sync;
368}
369
371{
373 return d->m_repeat;
374}
375
377{
379 return d->m_mix;
380}
381
383{
385 return d->m_sound;
386}
387
388// ScriptAction
389
390class Okular::ScriptActionPrivate : public Okular::ActionPrivate
391{
392public:
393 ScriptActionPrivate(enum ScriptType type, const QString &script)
394 : ActionPrivate()
395 , m_scriptType(type)
396 , m_script(script)
397 {
398 }
399
400 ScriptType m_scriptType;
401 QString m_script;
402};
403
405 : Action(*new ScriptActionPrivate(type, script))
406{
407}
408
412
417
419{
421 switch (d->m_scriptType) {
422 case JavaScript:
423 return i18n("JavaScript Script");
424 }
425
426 return QString();
427}
428
430{
432 return d->m_scriptType;
433}
434
436{
438 return d->m_script;
439}
440
441// MovieAction
442
443class Okular::MovieActionPrivate : public Okular::ActionPrivate
444{
445public:
446 explicit MovieActionPrivate(MovieAction::OperationType operation)
447 : ActionPrivate()
448 , m_operation(operation)
449 , m_annotation(nullptr)
450 {
451 }
452
453 MovieAction::OperationType m_operation;
454 MovieAnnotation *m_annotation;
455};
456
458 : Action(*new MovieActionPrivate(operation))
459{
460}
461
465
470
472{
473 return i18n("Play movie...");
474}
475
477{
479 return d->m_operation;
480}
481
483{
485 d->m_annotation = annotation;
486}
487
489{
491 return d->m_annotation;
492}
493
494// RenditionAction
495
496class Okular::RenditionActionPrivate : public Okular::ActionPrivate
497{
498public:
499 RenditionActionPrivate(RenditionAction::OperationType operation, Okular::Movie *movie, enum ScriptType scriptType, const QString &script)
500 : ActionPrivate()
501 , m_operation(operation)
502 , m_movie(movie)
503 , m_scriptType(scriptType)
504 , m_script(script)
505 , m_annotation(nullptr)
506 {
507 }
508
510 Okular::Movie *m_movie;
511 ScriptType m_scriptType;
512 QString m_script;
513 ScreenAnnotation *m_annotation;
514};
515
516RenditionAction::RenditionAction(OperationType operation, Okular::Movie *movie, enum ScriptType scriptType, const QString &script)
517 : Action(*new RenditionActionPrivate(operation, movie, scriptType, script))
518{
519}
520
524
529
531{
533
534 switch (d->m_operation) {
535 default:
536 case None:
537 switch (d->m_scriptType) {
538 case JavaScript:
539 return i18n("JavaScript Script");
540 default:
541 return QString();
542 }
543 case Play:
544 return i18n("Play movie");
545 case Stop:
546 return i18n("Stop movie");
547 case Pause:
548 return i18n("Pause movie");
549 case Resume:
550 return i18n("Resume movie");
551 }
552}
553
555{
557 return d->m_operation;
558}
559
561{
563 return d->m_movie;
564}
565
567{
569 return d->m_scriptType;
570}
571
573{
575 return d->m_script;
576}
577
579{
581 d->m_annotation = annotation;
582}
583
585{
587 return d->m_annotation;
588}
589
590BackendOpaqueAction::BackendOpaqueAction()
591 : Action(*new ActionPrivate())
592{
593}
594
595Action::ActionType BackendOpaqueAction::actionType() const
596{
597 return BackendOpaque;
598}
Encapsulates data that describes an action.
Definition action.h:41
ActionType
Describes the type of action.
Definition action.h:46
@ Execute
Execute a command or external application.
Definition action.h:48
@ Goto
Goto a given page or external document.
Definition action.h:47
@ DocAction
Start a custom action.
Definition action.h:50
@ BackendOpaque
Calls back to the backend with the action.
Definition action.h:55
@ Movie
Play a movie.
Definition action.h:52
@ Browse
Browse a given website.
Definition action.h:49
@ Script
Executes a Script code.
Definition action.h:53
@ Rendition
Play a movie and/or execute a Script code.
Definition action.h:54
@ Sound
Play a sound.
Definition action.h:51
The Browse action browses an url by opening a web browser or email client, depending on the url proto...
Definition action.h:239
ActionType actionType() const override
Returns the action type.
Definition action.cpp:223
~BrowseAction() override
Destroys the browse action.
Definition action.cpp:219
BrowseAction(const QUrl &url)
Creates a new browse action.
Definition action.cpp:214
QUrl url() const
Returns the url to browse.
Definition action.cpp:239
QString actionTip() const override
Returns the action tip.
Definition action.cpp:228
The DocumentAction action contains an action that is performed on the current document.
Definition action.h:278
DocumentActionType documentActionType() const
Returns the type of action.
Definition action.cpp:268
~DocumentAction() override
Destroys the document action.
Definition action.cpp:264
ActionType actionType() const override
Returns the action type.
Definition action.cpp:274
DocumentActionType
Describes the possible action types.
Definition action.h:283
@ Quit
Quit application.
Definition action.h:290
@ PageNext
Jump to next page.
Definition action.h:286
@ Find
Open find dialog.
Definition action.h:293
@ Presentation
Start presentation.
Definition action.h:291
@ PageLast
Jump to last page.
Definition action.h:287
@ PageFirst
Jump to first page.
Definition action.h:284
@ GoToPage
Goto page.
Definition action.h:294
@ Close
Close document.
Definition action.h:295
@ HistoryForward
Go forward in page history.
Definition action.h:289
@ EndPresentation
End presentation.
Definition action.h:292
@ PagePrev
Jump to previous page.
Definition action.h:285
@ HistoryBack
Go back in page history.
Definition action.h:288
DocumentAction(enum DocumentActionType documentActionType)
Creates a new document action.
Definition action.cpp:259
QString actionTip() const override
Returns the action tip.
Definition action.cpp:279
A view on the document.
Definition document.h:1350
The Execute action executes an external application.
Definition action.h:194
ActionType actionType() const override
Returns the action type.
Definition action.cpp:177
QString fileName() const
Returns the file name of the application to execute.
Definition action.cpp:188
QString actionTip() const override
Returns the action tip.
Definition action.cpp:182
~ExecuteAction() override
Destroys the execute action.
Definition action.cpp:173
ExecuteAction(const QString &fileName, const QString &parameters)
Creates a new execute action.
Definition action.cpp:168
QString parameters() const
Returns the parameters of the application to execute.
Definition action.cpp:194
The Goto action changes the viewport to another page or loads an external document.
Definition action.h:128
QString actionTip() const override
Returns the action tip.
Definition action.cpp:122
ActionType actionType() const override
Returns the action type.
Definition action.cpp:117
bool isExternal() const
Returns whether the goto action points to an external document.
Definition action.cpp:128
QString destinationName() const
Returns the document named destination the goto action points to.
Definition action.cpp:146
GotoAction(const QString &fileName, const DocumentViewport &viewport)
Creates a new goto action.
Definition action.cpp:103
~GotoAction() override
Destroys the goto action.
Definition action.cpp:113
QString fileName() const
Returns the filename of the external document.
Definition action.cpp:134
DocumentViewport destViewport() const
Returns the document viewport the goto action points to.
Definition action.cpp:140
The Movie action executes an operation on a video on activation.
Definition action.h:446
QString actionTip() const override
Returns the action tip.
Definition action.cpp:471
void setAnnotation(MovieAnnotation *annotation)
Sets the annotation that is associated with the movie action.
Definition action.cpp:482
~MovieAction() override
Destroys the movie action.
Definition action.cpp:462
MovieAnnotation * annotation() const
Returns the annotation or 0 if no annotation has been set.
Definition action.cpp:488
MovieAction(OperationType operation)
Creates a new movie action.
Definition action.cpp:457
OperationType operation() const
Returns the operation type.
Definition action.cpp:476
ActionType actionType() const override
Returns the action type.
Definition action.cpp:466
OperationType
Describes the possible operation types.
Definition action.h:451
Movie annotation.
Contains information about a movie object.
Definition movie.h:26
The Rendition action executes an operation on a video or executes some JavaScript code on activation.
Definition action.h:500
ScriptType scriptType() const
Returns the type of script.
Definition action.cpp:566
QString actionTip() const override
Returns the action tip.
Definition action.cpp:530
~RenditionAction() override
Destroys the rendition action.
Definition action.cpp:521
ScreenAnnotation * annotation() const
Returns the annotation or 0 if no annotation has been set.
Definition action.cpp:584
void setAnnotation(ScreenAnnotation *annotation)
Sets the annotation that is associated with the rendition action.
Definition action.cpp:578
ActionType actionType() const override
Returns the action type.
Definition action.cpp:525
RenditionAction(OperationType operation, Okular::Movie *movie, enum ScriptType scriptType, const QString &script)
Creates a new rendition action.
Definition action.cpp:516
Okular::Movie * movie() const
Returns the movie object or 0 if no movie object was set on construction time.
Definition action.cpp:560
OperationType
Describes the possible operation types.
Definition action.h:505
@ Stop
Stop playing the video.
Definition action.h:508
@ Pause
Pause the video.
Definition action.h:509
@ Resume
Resume playing the video.
Definition action.h:510
@ None
Execute only the JavaScript.
Definition action.h:506
@ Play
Start playing the video.
Definition action.h:507
QString script() const
Returns the script code.
Definition action.cpp:572
OperationType operation() const
Returns the operation type.
Definition action.cpp:554
Screen annotation.
The Script action executes a Script code.
Definition action.h:400
QString actionTip() const override
Returns the action tip.
Definition action.cpp:418
ScriptType scriptType() const
Returns the type of action.
Definition action.cpp:429
ScriptAction(enum ScriptType type, const QString &script)
Creates a new Script action.
Definition action.cpp:404
~ScriptAction() override
Destroys the browse action.
Definition action.cpp:409
ActionType actionType() const override
Returns the action type.
Definition action.cpp:413
QString script() const
Returns the code.
Definition action.cpp:435
The Sound action plays a sound on activation.
Definition action.h:336
SoundAction(double volume, bool synchronous, bool repeat, bool mix, Okular::Sound *sound)
Creates a new sound action.
Definition action.cpp:339
~SoundAction() override
Destroys the sound action.
Definition action.cpp:344
bool mix() const
Returns whether the sound shall be mixed.
Definition action.cpp:376
bool synchronous() const
Returns whether the sound shall be played synchronous.
Definition action.cpp:364
ActionType actionType() const override
Returns the action type.
Definition action.cpp:348
double volume() const
Returns the volume of the sound.
Definition action.cpp:358
bool repeat() const
Returns whether the sound shall be repeated.
Definition action.cpp:370
QString actionTip() const override
Returns the action tip.
Definition action.cpp:353
Okular::Sound * sound() const
Returns the sound object which contains the sound data.
Definition action.cpp:382
Contains information about a sound object.
Definition sound.h:24
QString i18n(const char *text, const TYPE &arg...)
global.h
Definition action.h:17
ScriptType
Describes the possible script types.
Definition global.h:75
@ JavaScript
JavaScript code.
Definition global.h:76
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:35 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.