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
|
/*
SPDX-FileCopyrightText: 2004-2005 Enrico Ros <eros.kde@email.it>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "action.h"
// kde includes
#include <KLocalizedString>
// local includes
#include "document.h"
#include "movie.h"
#include "sound.h"
#include "sourcereference_p.h"
using namespace Okular;
class Okular::ActionPrivate
{
public:
ActionPrivate()
{
}
virtual ~ActionPrivate()
{
qDeleteAll(m_nextActions);
}
ActionPrivate(const ActionPrivate &) = delete;
ActionPrivate &operator=(const ActionPrivate &) = delete;
QVariant m_nativeId;
std::shared_ptr<const void> m_nativeHandle;
QList<Action *> m_nextActions;
};
Action::Action(ActionPrivate &dd)
: d_ptr(&dd)
{
}
Action::~Action()
{
delete d_ptr;
}
QString Action::actionTip() const
{
return QLatin1String("");
}
void Action::setNativeId(const QVariant &id)
{
Q_D(Action);
d->m_nativeId = id;
}
QVariant Action::nativeId() const
{
Q_D(const Action);
return d->m_nativeId;
}
QList<Action *> Action::nextActions() const
{
Q_D(const Action);
return d->m_nextActions;
}
void Action::setNativeHandle(std::shared_ptr<const void> handle)
{
Q_D(Action);
d->m_nativeHandle = std::move(handle);
}
const void *Action::nativeHandle() const
{
Q_D(const Action);
return d->m_nativeHandle.get();
}
void Action::setNextActions(const QList<Action *> &actions)
{
Q_D(Action);
qDeleteAll(d->m_nextActions);
d->m_nextActions = actions;
}
// GotoAction
class Okular::GotoActionPrivate : public Okular::ActionPrivate
{
public:
GotoActionPrivate(const QString &fileName, const DocumentViewport &viewport)
: ActionPrivate()
, m_extFileName(fileName)
, m_vp(viewport)
{
}
GotoActionPrivate(const QString &fileName, const QString &namedDestination)
: ActionPrivate()
, m_extFileName(fileName)
, m_dest(namedDestination)
{
}
QString m_extFileName;
DocumentViewport m_vp;
QString m_dest;
};
GotoAction::GotoAction(const QString &fileName, const DocumentViewport &viewport)
: Action(*new GotoActionPrivate(fileName, viewport))
{
}
GotoAction::GotoAction(const QString &fileName, const QString &namedDestination)
: Action(*new GotoActionPrivate(fileName, namedDestination))
{
}
GotoAction::~GotoAction()
{
}
Action::ActionType GotoAction::actionType() const
{
return Goto;
}
QString GotoAction::actionTip() const
{
Q_D(const GotoAction);
return d->m_extFileName.isEmpty() ? (d->m_vp.isValid() ? i18n("Go to page %1", d->m_vp.pageNumber + 1) : QLatin1String("")) : i18n("Open external file");
}
bool GotoAction::isExternal() const
{
Q_D(const GotoAction);
return !d->m_extFileName.isEmpty();
}
QString GotoAction::fileName() const
{
Q_D(const GotoAction);
return d->m_extFileName;
}
DocumentViewport GotoAction::destViewport() const
{
Q_D(const GotoAction);
return d->m_vp;
}
QString GotoAction::destinationName() const
{
Q_D(const GotoAction);
return d->m_dest;
}
// ExecuteAction
class Okular::ExecuteActionPrivate : public Okular::ActionPrivate
{
public:
ExecuteActionPrivate(const QString &file, const QString ¶meters)
: ActionPrivate()
, m_fileName(file)
, m_parameters(parameters)
{
}
QString m_fileName;
QString m_parameters;
};
ExecuteAction::ExecuteAction(const QString &file, const QString ¶meters)
: Action(*new ExecuteActionPrivate(file, parameters))
{
}
ExecuteAction::~ExecuteAction()
{
}
Action::ActionType ExecuteAction::actionType() const
{
return Execute;
}
QString ExecuteAction::actionTip() const
{
Q_D(const Okular::ExecuteAction);
return i18n("Execute '%1'…", d->m_fileName);
}
QString ExecuteAction::fileName() const
{
Q_D(const Okular::ExecuteAction);
return d->m_fileName;
}
QString ExecuteAction::parameters() const
{
Q_D(const Okular::ExecuteAction);
return d->m_parameters;
}
// BrowseAction
class Okular::BrowseActionPrivate : public Okular::ActionPrivate
{
public:
explicit BrowseActionPrivate(const QUrl &url)
: ActionPrivate()
, m_url(url)
{
}
QUrl m_url;
};
BrowseAction::BrowseAction(const QUrl &url)
: Action(*new BrowseActionPrivate(url))
{
}
BrowseAction::~BrowseAction()
{
}
Action::ActionType BrowseAction::actionType() const
{
return Browse;
}
QString BrowseAction::actionTip() const
{
Q_D(const Okular::BrowseAction);
if (auto ref = extractLilyPondSourceReference(d->m_url)) {
return sourceReferenceToolTip(*ref);
}
return d->m_url.toDisplayString();
}
QUrl BrowseAction::url() const
{
Q_D(const Okular::BrowseAction);
return d->m_url;
}
// DocumentAction
class Okular::DocumentActionPrivate : public Okular::ActionPrivate
{
public:
explicit DocumentActionPrivate(enum DocumentAction::DocumentActionType documentActionType)
: ActionPrivate()
, m_type(documentActionType)
{
}
DocumentAction::DocumentActionType m_type;
};
DocumentAction::DocumentAction(enum DocumentActionType documentActionType)
: Action(*new DocumentActionPrivate(documentActionType))
{
}
DocumentAction::~DocumentAction()
{
}
DocumentAction::DocumentActionType DocumentAction::documentActionType() const
{
Q_D(const Okular::DocumentAction);
return d->m_type;
}
Action::ActionType DocumentAction::actionType() const
{
return DocAction;
}
QString DocumentAction::actionTip() const
{
Q_D(const Okular::DocumentAction);
switch (d->m_type) {
case PageFirst:
return i18n("First Page");
case PagePrev:
return i18n("Previous Page");
case PageNext:
return i18n("Next Page");
case PageLast:
return i18n("Last Page");
case HistoryBack:
return i18n("Back");
case HistoryForward:
return i18n("Forward");
case Quit:
return i18n("Quit");
case Presentation:
return i18n("Start Presentation");
case EndPresentation:
return i18n("End Presentation");
case Find:
return i18n("Find…");
case GoToPage:
return i18n("Go To Page…");
case Close:
default:;
}
return QString();
}
// SoundAction
class Okular::SoundActionPrivate : public Okular::ActionPrivate
{
public:
SoundActionPrivate(double volume, bool sync, bool repeat, bool mix, Okular::Sound *sound)
: ActionPrivate()
, m_volume(volume)
, m_sync(sync)
, m_repeat(repeat)
, m_mix(mix)
, m_sound(sound)
{
}
~SoundActionPrivate() override
{
delete m_sound;
}
double m_volume;
bool m_sync : 1;
bool m_repeat : 1;
bool m_mix : 1;
Okular::Sound *m_sound;
};
SoundAction::SoundAction(double volume, bool sync, bool repeat, bool mix, Okular::Sound *sound)
: Action(*new SoundActionPrivate(volume, sync, repeat, mix, sound))
{
}
SoundAction::~SoundAction()
{
}
Action::ActionType SoundAction::actionType() const
{
return Sound;
}
QString SoundAction::actionTip() const
{
return i18n("Play sound…");
}
double SoundAction::volume() const
{
Q_D(const Okular::SoundAction);
return d->m_volume;
}
bool SoundAction::synchronous() const
{
Q_D(const Okular::SoundAction);
return d->m_sync;
}
bool SoundAction::repeat() const
{
Q_D(const Okular::SoundAction);
return d->m_repeat;
}
bool SoundAction::mix() const
{
Q_D(const Okular::SoundAction);
return d->m_mix;
}
Okular::Sound *SoundAction::sound() const
{
Q_D(const Okular::SoundAction);
return d->m_sound;
}
// ScriptAction
class Okular::ScriptActionPrivate : public Okular::ActionPrivate
{
public:
ScriptActionPrivate(enum ScriptType type, const QString &script)
: ActionPrivate()
, m_scriptType(type)
, m_script(script)
{
}
ScriptType m_scriptType;
QString m_script;
};
ScriptAction::ScriptAction(enum ScriptType type, const QString &script)
: Action(*new ScriptActionPrivate(type, script))
{
}
ScriptAction::~ScriptAction()
{
}
Action::ActionType ScriptAction::actionType() const
{
return Script;
}
QString ScriptAction::actionTip() const
{
Q_D(const Okular::ScriptAction);
switch (d->m_scriptType) {
case JavaScript:
return i18n("JavaScript Script");
}
return QString();
}
ScriptType ScriptAction::scriptType() const
{
Q_D(const Okular::ScriptAction);
return d->m_scriptType;
}
QString ScriptAction::script() const
{
Q_D(const Okular::ScriptAction);
return d->m_script;
}
// MovieAction
class Okular::MovieActionPrivate : public Okular::ActionPrivate
{
public:
explicit MovieActionPrivate(MovieAction::OperationType operation)
: ActionPrivate()
, m_operation(operation)
, m_annotation(nullptr)
{
}
MovieAction::OperationType m_operation;
MovieAnnotation *m_annotation;
};
MovieAction::MovieAction(OperationType operation)
: Action(*new MovieActionPrivate(operation))
{
}
MovieAction::~MovieAction()
{
}
Action::ActionType MovieAction::actionType() const
{
return Movie;
}
QString MovieAction::actionTip() const
{
return i18n("Play movie…");
}
MovieAction::OperationType MovieAction::operation() const
{
Q_D(const Okular::MovieAction);
return d->m_operation;
}
void MovieAction::setAnnotation(MovieAnnotation *annotation)
{
Q_D(Okular::MovieAction);
d->m_annotation = annotation;
}
MovieAnnotation *MovieAction::annotation() const
{
Q_D(const Okular::MovieAction);
return d->m_annotation;
}
// RenditionAction
class Okular::RenditionActionPrivate : public Okular::ActionPrivate
{
public:
RenditionActionPrivate(RenditionAction::OperationType operation, Okular::Movie *movie, enum ScriptType scriptType, const QString &script)
: ActionPrivate()
, m_operation(operation)
, m_movie(movie)
, m_scriptType(scriptType)
, m_script(script)
, m_annotation(nullptr)
{
}
RenditionAction::OperationType m_operation;
Okular::Movie *m_movie;
ScriptType m_scriptType;
QString m_script;
ScreenAnnotation *m_annotation;
};
RenditionAction::RenditionAction(OperationType operation, Okular::Movie *movie, enum ScriptType scriptType, const QString &script)
: Action(*new RenditionActionPrivate(operation, movie, scriptType, script))
{
}
RenditionAction::~RenditionAction()
{
}
Action::ActionType RenditionAction::actionType() const
{
return Rendition;
}
QString RenditionAction::actionTip() const
{
Q_D(const Okular::RenditionAction);
switch (d->m_operation) {
default:
case None:
switch (d->m_scriptType) {
case JavaScript:
return i18n("JavaScript Script");
default:
return QString();
}
case Play:
return i18n("Play movie");
case Stop:
return i18n("Stop movie");
case Pause:
return i18n("Pause movie");
case Resume:
return i18n("Resume movie");
}
}
RenditionAction::OperationType RenditionAction::operation() const
{
Q_D(const Okular::RenditionAction);
return d->m_operation;
}
Okular::Movie *RenditionAction::movie() const
{
Q_D(const Okular::RenditionAction);
return d->m_movie;
}
ScriptType RenditionAction::scriptType() const
{
Q_D(const Okular::RenditionAction);
return d->m_scriptType;
}
QString RenditionAction::script() const
{
Q_D(const Okular::RenditionAction);
return d->m_script;
}
void RenditionAction::setAnnotation(ScreenAnnotation *annotation)
{
Q_D(Okular::RenditionAction);
d->m_annotation = annotation;
}
ScreenAnnotation *RenditionAction::annotation() const
{
Q_D(const Okular::RenditionAction);
return d->m_annotation;
}
BackendOpaqueAction::BackendOpaqueAction()
: Action(*new ActionPrivate())
{
}
Action::ActionType BackendOpaqueAction::actionType() const
{
return BackendOpaque;
}
|