Okular

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

KDE's Doxygen guidelines are available online.