compile
[kdegraphics.git] / okular / core / action.cpp
blobdf665b9f8c53129cd2ec0f741886b2164d0079d6
1 /***************************************************************************
2 * Copyright (C) 2004-2005 by Enrico Ros <eros.kde@email.it> *
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 ***************************************************************************/
10 #include "action.h"
12 // kde includes
13 #include <klocale.h>
15 // local includes
16 #include "document.h"
17 #include "sourcereference_p.h"
18 #include "sound.h"
20 using namespace Okular;
22 class Okular::ActionPrivate
24 public:
25 ActionPrivate()
29 virtual ~ActionPrivate()
34 Action::Action( ActionPrivate &dd )
35 : d_ptr( &dd )
39 Action::~Action()
41 delete d_ptr;
44 QString Action::actionTip() const
46 return "";
49 // GotoAction
51 class Okular::GotoActionPrivate : public Okular::ActionPrivate
53 public:
54 GotoActionPrivate( const QString &fileName, const DocumentViewport &viewport )
55 : ActionPrivate(), m_extFileName( fileName ), m_vp( viewport )
59 QString m_extFileName;
60 DocumentViewport m_vp;
63 GotoAction::GotoAction( const QString& fileName, const DocumentViewport & viewport )
64 : Action( *new GotoActionPrivate( fileName, viewport ) )
68 GotoAction::~GotoAction()
72 Action::ActionType GotoAction::actionType() const
74 return Goto;
77 QString GotoAction::actionTip() const
79 Q_D( const GotoAction );
80 return d->m_extFileName.isEmpty() ? ( d->m_vp.isValid() ? i18n( "Go to page %1", d->m_vp.pageNumber + 1 ) : "" ) :
81 i18n("Open external file");
84 bool GotoAction::isExternal() const
86 Q_D( const GotoAction );
87 return !d->m_extFileName.isEmpty();
90 QString GotoAction::fileName() const
92 Q_D( const GotoAction );
93 return d->m_extFileName;
96 DocumentViewport GotoAction::destViewport() const
98 Q_D( const GotoAction );
99 return d->m_vp;
102 // ExecuteAction
104 class Okular::ExecuteActionPrivate : public Okular::ActionPrivate
106 public:
107 ExecuteActionPrivate( const QString &file, const QString & parameters )
108 : ActionPrivate(), m_fileName( file ), m_parameters( parameters )
112 QString m_fileName;
113 QString m_parameters;
116 ExecuteAction::ExecuteAction( const QString &file, const QString & parameters )
117 : Action( *new ExecuteActionPrivate( file, parameters ) )
121 ExecuteAction::~ExecuteAction()
125 Action::ActionType ExecuteAction::actionType() const
127 return Execute;
130 QString ExecuteAction::actionTip() const
132 Q_D( const Okular::ExecuteAction );
133 return i18n( "Execute '%1'...", d->m_fileName );
136 QString ExecuteAction::fileName() const
138 Q_D( const Okular::ExecuteAction );
139 return d->m_fileName;
142 QString ExecuteAction::parameters() const
144 Q_D( const Okular::ExecuteAction );
145 return d->m_parameters;
148 // BrowseAction
150 class Okular::BrowseActionPrivate : public Okular::ActionPrivate
152 public:
153 BrowseActionPrivate( const QString &url )
154 : ActionPrivate(), m_url( url )
158 QString m_url;
161 BrowseAction::BrowseAction( const QString &url )
162 : Action( *new BrowseActionPrivate( url ) )
166 BrowseAction::~BrowseAction()
170 Action::ActionType BrowseAction::actionType() const
172 return Browse;
175 QString BrowseAction::actionTip() const
177 Q_D( const Okular::BrowseAction );
178 QString source;
179 int row = 0, col = 0;
180 if ( extractLilyPondSourceReference( d->m_url, &source, &row, &col ) )
182 return sourceReferenceToolTip( source, row, col );
184 return d->m_url;
187 QString BrowseAction::url() const
189 Q_D( const Okular::BrowseAction );
190 return d->m_url;
193 // DocumentAction
195 class Okular::DocumentActionPrivate : public Okular::ActionPrivate
197 public:
198 DocumentActionPrivate( enum DocumentAction::DocumentActionType documentActionType )
199 : ActionPrivate(), m_type( documentActionType )
203 DocumentAction::DocumentActionType m_type;
206 DocumentAction::DocumentAction( enum DocumentActionType documentActionType )
207 : Action( *new DocumentActionPrivate( documentActionType ) )
211 DocumentAction::~DocumentAction()
215 DocumentAction::DocumentActionType DocumentAction::documentActionType() const
217 Q_D( const Okular::DocumentAction );
218 return d->m_type;
221 Action::ActionType DocumentAction::actionType() const
223 return DocAction;
226 QString DocumentAction::actionTip() const
228 Q_D( const Okular::DocumentAction );
229 switch ( d->m_type )
231 case PageFirst:
232 return i18n( "First Page" );
233 case PagePrev:
234 return i18n( "Previous Page" );
235 case PageNext:
236 return i18n( "Next Page" );
237 case PageLast:
238 return i18n( "Last Page" );
239 case HistoryBack:
240 return i18n( "Back" );
241 case HistoryForward:
242 return i18n( "Forward" );
243 case Quit:
244 return i18n( "Quit" );
245 case Presentation:
246 return i18n( "Start Presentation" );
247 case EndPresentation:
248 return i18n( "End Presentation" );
249 case Find:
250 return i18n( "Find..." );
251 case GoToPage:
252 return i18n( "Go To Page..." );
253 case Close:
254 default: ;
257 return QString();
260 // SoundAction
262 class Okular::SoundActionPrivate : public Okular::ActionPrivate
264 public:
265 SoundActionPrivate( double volume, bool sync, bool repeat, bool mix, Okular::Sound *sound )
266 : ActionPrivate(), m_volume( volume ), m_sync( sync ),
267 m_repeat( repeat ), m_mix( mix ), m_sound( sound )
271 ~SoundActionPrivate()
273 delete m_sound;
276 double m_volume;
277 bool m_sync : 1;
278 bool m_repeat : 1;
279 bool m_mix : 1;
280 Okular::Sound *m_sound;
283 SoundAction::SoundAction( double volume, bool sync, bool repeat, bool mix, Okular::Sound *sound )
284 : Action( *new SoundActionPrivate( volume, sync, repeat, mix, sound ) )
288 SoundAction::~SoundAction()
292 Action::ActionType SoundAction::actionType() const
294 return Sound;
297 QString SoundAction::actionTip() const
299 return i18n( "Play sound..." );
302 double SoundAction::volume() const
304 Q_D( const Okular::SoundAction );
305 return d->m_volume;
308 bool SoundAction::synchronous() const
310 Q_D( const Okular::SoundAction );
311 return d->m_sync;
314 bool SoundAction::repeat() const
316 Q_D( const Okular::SoundAction );
317 return d->m_repeat;
320 bool SoundAction::mix() const
322 Q_D( const Okular::SoundAction );
323 return d->m_mix;
326 Okular::Sound *SoundAction::sound() const
328 Q_D( const Okular::SoundAction );
329 return d->m_sound;
332 // ScriptAction
334 class Okular::ScriptActionPrivate : public Okular::ActionPrivate
336 public:
337 ScriptActionPrivate( enum ScriptType type, const QString &script )
338 : ActionPrivate(), m_scriptType( type ), m_script( script )
342 ScriptType m_scriptType;
343 QString m_script;
346 ScriptAction::ScriptAction( enum ScriptType type, const QString &script )
347 : Action( *new ScriptActionPrivate( type, script ) )
351 ScriptAction::~ScriptAction()
355 Action::ActionType ScriptAction::actionType() const
357 return Script;
360 QString ScriptAction::actionTip() const
362 Q_D( const Okular::ScriptAction );
363 switch ( d->m_scriptType )
365 case JavaScript:
366 return i18n( "JavaScript Script" );
369 return QString();
372 ScriptType ScriptAction::scriptType() const
374 Q_D( const Okular::ScriptAction );
375 return d->m_scriptType;
378 QString ScriptAction::script() const
380 Q_D( const Okular::ScriptAction );
381 return d->m_script;
384 // MovieAction
386 #if 0
387 class Okular::MovieActionPrivate : public Okular::ActionPrivate
389 public:
390 MovieActionPrivate()
391 : ActionPrivate()
396 MovieAction::MovieAction()
397 : Action( *new MovieActionPrivate() )
401 MovieAction::~MovieAction()
405 Action::ActionType MovieAction::actionType() const
407 return Movie;
410 QString MovieAction::actionTip() const
412 return i18n( "Play movie..." );
414 #endif