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 std::shared_ptr<const void> m_nativeHandle;
37 QVector<Action *> m_nextActions;
38};
39
40Action::Action(ActionPrivate &dd)
41 : d_ptr(&dd)
42{
43}
44
45Action::~Action()
46{
47 delete d_ptr;
48}
49
50QString Action::actionTip() const
51{
52 return QLatin1String("");
53}
54
55void Action::setNativeId(const QVariant &id)
56{
57 Q_D(Action);
58 d->m_nativeId = id;
59}
60
61QVariant Action::nativeId() const
62{
63 Q_D(const Action);
64 return d->m_nativeId;
65}
66
67QVector<Action *> Action::nextActions() const
68{
69 Q_D(const Action);
70 return d->m_nextActions;
71}
72
73void Action::setNativeHandle(std::shared_ptr<const void> handle)
74{
75 Q_D(Action);
76 d->m_nativeHandle = std::move(handle);
77}
78const void *Action::nativeHandle() const
79{
80 Q_D(const Action);
81 return d->m_nativeHandle.get();
82}
83
84void Action::setNextActions(const QVector<Action *> &actions)
85{
86 Q_D(Action);
87 qDeleteAll(d->m_nextActions);
88 d->m_nextActions = actions;
89}
90
91// GotoAction
92
93class Okular::GotoActionPrivate : public Okular::ActionPrivate
94{
95public:
96 GotoActionPrivate(const QString &fileName, const DocumentViewport &viewport)
97 : ActionPrivate()
98 , m_extFileName(fileName)
99 , m_vp(viewport)
100 {
101 }
102
103 GotoActionPrivate(const QString &fileName, const QString &namedDestination)
104 : ActionPrivate()
105 , m_extFileName(fileName)
106 , m_dest(namedDestination)
107 {
108 }
109
110 QString m_extFileName;
111 DocumentViewport m_vp;
112 QString m_dest;
113};
114
115GotoAction::GotoAction(const QString &fileName, const DocumentViewport &viewport)
116 : Action(*new GotoActionPrivate(fileName, viewport))
117{
118}
119
120GotoAction::GotoAction(const QString &fileName, const QString &namedDestination)
121 : Action(*new GotoActionPrivate(fileName, namedDestination))
122{
123}
124
128
130{
131 return Goto;
132}
133
135{
136 Q_D(const GotoAction);
137 return d->m_extFileName.isEmpty() ? (d->m_vp.isValid() ? i18n("Go to page %1", d->m_vp.pageNumber + 1) : QLatin1String("")) : i18n("Open external file");
138}
139
141{
142 Q_D(const GotoAction);
143 return !d->m_extFileName.isEmpty();
144}
145
147{
148 Q_D(const GotoAction);
149 return d->m_extFileName;
150}
151
153{
154 Q_D(const GotoAction);
155 return d->m_vp;
156}
157
159{
160 Q_D(const GotoAction);
161 return d->m_dest;
162}
163
164// ExecuteAction
165
166class Okular::ExecuteActionPrivate : public Okular::ActionPrivate
167{
168public:
169 ExecuteActionPrivate(const QString &file, const QString &parameters)
170 : ActionPrivate()
171 , m_fileName(file)
172 , m_parameters(parameters)
173 {
174 }
175
176 QString m_fileName;
177 QString m_parameters;
178};
179
180ExecuteAction::ExecuteAction(const QString &file, const QString &parameters)
181 : Action(*new ExecuteActionPrivate(file, parameters))
182{
183}
184
188
193
195{
197 return i18n("Execute '%1'...", d->m_fileName);
198}
199
201{
203 return d->m_fileName;
204}
205
207{
209 return d->m_parameters;
210}
211
212// BrowseAction
213
214class Okular::BrowseActionPrivate : public Okular::ActionPrivate
215{
216public:
217 explicit BrowseActionPrivate(const QUrl &url)
218 : ActionPrivate()
219 , m_url(url)
220 {
221 }
222
223 QUrl m_url;
224};
225
227 : Action(*new BrowseActionPrivate(url))
228{
229}
230
234
239
241{
243 QString source;
244 int row = 0, col = 0;
245 if (extractLilyPondSourceReference(d->m_url, &source, &row, &col)) {
246 return sourceReferenceToolTip(source, row, col);
247 }
248 return d->m_url.toDisplayString();
249}
250
252{
254 return d->m_url;
255}
256
257// DocumentAction
258
259class Okular::DocumentActionPrivate : public Okular::ActionPrivate
260{
261public:
262 explicit DocumentActionPrivate(enum DocumentAction::DocumentActionType documentActionType)
263 : ActionPrivate()
264 , m_type(documentActionType)
265 {
266 }
267
269};
270
272 : Action(*new DocumentActionPrivate(documentActionType))
273{
274}
275
279
285
290
292{
294 switch (d->m_type) {
295 case PageFirst:
296 return i18n("First Page");
297 case PagePrev:
298 return i18n("Previous Page");
299 case PageNext:
300 return i18n("Next Page");
301 case PageLast:
302 return i18n("Last Page");
303 case HistoryBack:
304 return i18n("Back");
305 case HistoryForward:
306 return i18n("Forward");
307 case Quit:
308 return i18n("Quit");
309 case Presentation:
310 return i18n("Start Presentation");
311 case EndPresentation:
312 return i18n("End Presentation");
313 case Find:
314 return i18n("Find...");
315 case GoToPage:
316 return i18n("Go To Page...");
317 case Close:
318 default:;
319 }
320
321 return QString();
322}
323
324// SoundAction
325
326class Okular::SoundActionPrivate : public Okular::ActionPrivate
327{
328public:
329 SoundActionPrivate(double volume, bool sync, bool repeat, bool mix, Okular::Sound *sound)
330 : ActionPrivate()
331 , m_volume(volume)
332 , m_sync(sync)
333 , m_repeat(repeat)
334 , m_mix(mix)
335 , m_sound(sound)
336 {
337 }
338
339 ~SoundActionPrivate() override
340 {
341 delete m_sound;
342 }
343
344 double m_volume;
345 bool m_sync : 1;
346 bool m_repeat : 1;
347 bool m_mix : 1;
348 Okular::Sound *m_sound;
349};
350
351SoundAction::SoundAction(double volume, bool sync, bool repeat, bool mix, Okular::Sound *sound)
352 : Action(*new SoundActionPrivate(volume, sync, repeat, mix, sound))
353{
354}
355
359
364
366{
367 return i18n("Play sound...");
368}
369
371{
373 return d->m_volume;
374}
375
377{
379 return d->m_sync;
380}
381
383{
385 return d->m_repeat;
386}
387
389{
391 return d->m_mix;
392}
393
395{
397 return d->m_sound;
398}
399
400// ScriptAction
401
402class Okular::ScriptActionPrivate : public Okular::ActionPrivate
403{
404public:
405 ScriptActionPrivate(enum ScriptType type, const QString &script)
406 : ActionPrivate()
407 , m_scriptType(type)
408 , m_script(script)
409 {
410 }
411
412 ScriptType m_scriptType;
413 QString m_script;
414};
415
417 : Action(*new ScriptActionPrivate(type, script))
418{
419}
420
424
429
431{
433 switch (d->m_scriptType) {
434 case JavaScript:
435 return i18n("JavaScript Script");
436 }
437
438 return QString();
439}
440
442{
444 return d->m_scriptType;
445}
446
448{
450 return d->m_script;
451}
452
453// MovieAction
454
455class Okular::MovieActionPrivate : public Okular::ActionPrivate
456{
457public:
458 explicit MovieActionPrivate(MovieAction::OperationType operation)
459 : ActionPrivate()
460 , m_operation(operation)
461 , m_annotation(nullptr)
462 {
463 }
464
465 MovieAction::OperationType m_operation;
466 MovieAnnotation *m_annotation;
467};
468
470 : Action(*new MovieActionPrivate(operation))
471{
472}
473
477
482
484{
485 return i18n("Play movie...");
486}
487
489{
491 return d->m_operation;
492}
493
495{
497 d->m_annotation = annotation;
498}
499
501{
503 return d->m_annotation;
504}
505
506// RenditionAction
507
508class Okular::RenditionActionPrivate : public Okular::ActionPrivate
509{
510public:
511 RenditionActionPrivate(RenditionAction::OperationType operation, Okular::Movie *movie, enum ScriptType scriptType, const QString &script)
512 : ActionPrivate()
513 , m_operation(operation)
514 , m_movie(movie)
515 , m_scriptType(scriptType)
516 , m_script(script)
517 , m_annotation(nullptr)
518 {
519 }
520
522 Okular::Movie *m_movie;
523 ScriptType m_scriptType;
524 QString m_script;
525 ScreenAnnotation *m_annotation;
526};
527
528RenditionAction::RenditionAction(OperationType operation, Okular::Movie *movie, enum ScriptType scriptType, const QString &script)
529 : Action(*new RenditionActionPrivate(operation, movie, scriptType, script))
530{
531}
532
536
541
543{
545
546 switch (d->m_operation) {
547 default:
548 case None:
549 switch (d->m_scriptType) {
550 case JavaScript:
551 return i18n("JavaScript Script");
552 default:
553 return QString();
554 }
555 case Play:
556 return i18n("Play movie");
557 case Stop:
558 return i18n("Stop movie");
559 case Pause:
560 return i18n("Pause movie");
561 case Resume:
562 return i18n("Resume movie");
563 }
564}
565
567{
569 return d->m_operation;
570}
571
573{
575 return d->m_movie;
576}
577
579{
581 return d->m_scriptType;
582}
583
585{
587 return d->m_script;
588}
589
591{
593 d->m_annotation = annotation;
594}
595
597{
599 return d->m_annotation;
600}
601
602BackendOpaqueAction::BackendOpaqueAction()
603 : Action(*new ActionPrivate())
604{
605}
606
607Action::ActionType BackendOpaqueAction::actionType() const
608{
609 return BackendOpaque;
610}
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:262
ActionType actionType() const override
Returns the action type.
Definition action.cpp:235
~BrowseAction() override
Destroys the browse action.
Definition action.cpp:231
BrowseAction(const QUrl &url)
Creates a new browse action.
Definition action.cpp:226
QUrl url() const
Returns the url to browse.
Definition action.cpp:251
QString actionTip() const override
Returns the action tip.
Definition action.cpp:240
The DocumentAction action contains an action that is performed on the current document.
Definition action.h:301
DocumentActionType documentActionType() const
Returns the type of action.
Definition action.cpp:280
~DocumentAction() override
Destroys the document action.
Definition action.cpp:276
ActionType actionType() const override
Returns the action type.
Definition action.cpp:286
DocumentActionType
Describes the possible action types.
Definition action.h:306
@ Quit
Quit application.
Definition action.h:313
@ PageNext
Jump to next page.
Definition action.h:309
@ Find
Open find dialog.
Definition action.h:316
@ Presentation
Start presentation.
Definition action.h:314
@ PageLast
Jump to last page.
Definition action.h:310
@ PageFirst
Jump to first page.
Definition action.h:307
@ GoToPage
Goto page.
Definition action.h:317
@ Close
Close document.
Definition action.h:318
@ HistoryForward
Go forward in page history.
Definition action.h:312
@ EndPresentation
End presentation.
Definition action.h:315
@ PagePrev
Jump to previous page.
Definition action.h:308
@ HistoryBack
Go back in page history.
Definition action.h:311
DocumentAction(enum DocumentActionType documentActionType)
Creates a new document action.
Definition action.cpp:271
QString actionTip() const override
Returns the action tip.
Definition action.cpp:291
A view on the document.
Definition document.h:1450
The Execute action executes an external application.
Definition action.h:217
ActionType actionType() const override
Returns the action type.
Definition action.cpp:189
QString fileName() const
Returns the file name of the application to execute.
Definition action.cpp:200
QString actionTip() const override
Returns the action tip.
Definition action.cpp:194
~ExecuteAction() override
Destroys the execute action.
Definition action.cpp:185
ExecuteAction(const QString &fileName, const QString &parameters)
Creates a new execute action.
Definition action.cpp:180
QString parameters() const
Returns the parameters of the application to execute.
Definition action.cpp:206
The Goto action changes the viewport to another page or loads an external document.
Definition action.h:151
QString actionTip() const override
Returns the action tip.
Definition action.cpp:134
ActionType actionType() const override
Returns the action type.
Definition action.cpp:129
bool isExternal() const
Returns whether the goto action points to an external document.
Definition action.cpp:140
QString destinationName() const
Returns the document named destination the goto action points to.
Definition action.cpp:158
GotoAction(const QString &fileName, const DocumentViewport &viewport)
Creates a new goto action.
Definition action.cpp:115
~GotoAction() override
Destroys the goto action.
Definition action.cpp:125
QString fileName() const
Returns the filename of the external document.
Definition action.cpp:146
DocumentViewport destViewport() const
Returns the document viewport the goto action points to.
Definition action.cpp:152
The Movie action executes an operation on a video on activation.
Definition action.h:469
QString actionTip() const override
Returns the action tip.
Definition action.cpp:483
void setAnnotation(MovieAnnotation *annotation)
Sets the annotation that is associated with the movie action.
Definition action.cpp:494
~MovieAction() override
Destroys the movie action.
Definition action.cpp:474
MovieAnnotation * annotation() const
Returns the annotation or 0 if no annotation has been set.
Definition action.cpp:500
MovieAction(OperationType operation)
Creates a new movie action.
Definition action.cpp:469
OperationType operation() const
Returns the operation type.
Definition action.cpp:488
ActionType actionType() const override
Returns the action type.
Definition action.cpp:478
OperationType
Describes the possible operation types.
Definition action.h:474
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:523
ScriptType scriptType() const
Returns the type of script.
Definition action.cpp:578
QString actionTip() const override
Returns the action tip.
Definition action.cpp:542
~RenditionAction() override
Destroys the rendition action.
Definition action.cpp:533
ScreenAnnotation * annotation() const
Returns the annotation or 0 if no annotation has been set.
Definition action.cpp:596
void setAnnotation(ScreenAnnotation *annotation)
Sets the annotation that is associated with the rendition action.
Definition action.cpp:590
ActionType actionType() const override
Returns the action type.
Definition action.cpp:537
RenditionAction(OperationType operation, Okular::Movie *movie, enum ScriptType scriptType, const QString &script)
Creates a new rendition action.
Definition action.cpp:528
Okular::Movie * movie() const
Returns the movie object or 0 if no movie object was set on construction time.
Definition action.cpp:572
OperationType
Describes the possible operation types.
Definition action.h:528
@ Stop
Stop playing the video.
Definition action.h:531
@ Pause
Pause the video.
Definition action.h:532
@ Resume
Resume playing the video.
Definition action.h:533
@ None
Execute only the JavaScript.
Definition action.h:529
@ Play
Start playing the video.
Definition action.h:530
QString script() const
Returns the script code.
Definition action.cpp:584
OperationType operation() const
Returns the operation type.
Definition action.cpp:566
Screen annotation.
The Script action executes a Script code.
Definition action.h:423
QString actionTip() const override
Returns the action tip.
Definition action.cpp:430
ScriptType scriptType() const
Returns the type of action.
Definition action.cpp:441
ScriptAction(enum ScriptType type, const QString &script)
Creates a new Script action.
Definition action.cpp:416
~ScriptAction() override
Destroys the browse action.
Definition action.cpp:421
ActionType actionType() const override
Returns the action type.
Definition action.cpp:425
QString script() const
Returns the code.
Definition action.cpp:447
The Sound action plays a sound on activation.
Definition action.h:359
SoundAction(double volume, bool synchronous, bool repeat, bool mix, Okular::Sound *sound)
Creates a new sound action.
Definition action.cpp:351
~SoundAction() override
Destroys the sound action.
Definition action.cpp:356
bool mix() const
Returns whether the sound shall be mixed.
Definition action.cpp:388
bool synchronous() const
Returns whether the sound shall be played synchronous.
Definition action.cpp:376
ActionType actionType() const override
Returns the action type.
Definition action.cpp:360
double volume() const
Returns the volume of the sound.
Definition action.cpp:370
bool repeat() const
Returns whether the sound shall be repeated.
Definition action.cpp:382
QString actionTip() const override
Returns the action tip.
Definition action.cpp:365
Okular::Sound * sound() const
Returns the sound object which contains the sound data.
Definition action.cpp:394
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 Sat Dec 21 2024 16:58:33 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.