Okular

js_event.cpp
1/*
2 SPDX-FileCopyrightText: 2018 Intevation GmbH <intevation@intevation.de>
3
4 SPDX-License-Identifier: GPL-2.0-or-later
5*/
6
7#include "js_event_p.h"
8
9#include "event_p.h"
10#include "js_field_p.h"
11
12#include <QJSEngine>
13
14using namespace Okular;
15
16// Event.name
17QString JSEvent::name() const
18{
19 return m_event->name();
20}
21
22// Event.type
23QString JSEvent::type() const
24{
25 return m_event->type();
26}
27
28// Event.targetName (getter)
29QString JSEvent::targetName() const
30{
31 return m_event->targetName();
32}
33
34// Event.targetName (setter)
35void JSEvent::setTargetName(const QString &targetName)
36{
37 m_event->setTargetName(targetName);
38}
39
40// Event.shift
41bool JSEvent::shift() const
42{
43 return m_event->shiftModifier();
44}
45
46// Event.source
47QJSValue JSEvent::source() const
48{
49 if (m_event->eventType() == Event::FieldCalculate) {
50 FormField *src = m_event->source();
51 if (src) {
52 return JSField::wrapField(qjsEngine(this), src, m_event->sourcePage());
53 }
54 }
56}
57
58// Event.target
59QJSValue JSEvent::target() const
60{
61 switch (m_event->eventType()) {
62 case Event::FieldCalculate:
63 case Event::FieldFormat:
64 case Event::FieldKeystroke:
65 case Event::FieldFocus:
66 case Event::FieldValidate:
67 case Event::FieldMouseUp:
68 case Event::FieldMouseDown:
69 case Event::FieldMouseEnter:
70 case Event::FieldMouseExit: {
71 FormField *target = static_cast<FormField *>(m_event->target());
72 if (target) {
73 return JSField::wrapField(qjsEngine(this), target, m_event->targetPage());
74 }
75 break;
76 }
77 case Event::DocOpen:
78 case Event::DocWillClose:
79 case Event::DocWillSave:
80 case Event::DocWillPrint:
81 case Event::DocDidSave:
82 case Event::DocDidPrint: {
83 return qjsEngine(this)->globalObject().property(QStringLiteral("Doc"));
84 }
85 default: {
86 }
87 }
89}
90
91// Event.value (getter)
92QJSValue JSEvent::value() const
93{
94 return m_event->value().toString();
95}
96
97// Event.value (setter)
98void JSEvent::setValue(const QJSValue &value)
99{
100 m_event->setValue(QVariant(value.toString()));
101}
102
103// Event.rc (getter)
104bool JSEvent::returnCode() const
105{
106 return m_event->returnCode();
107}
108
109// Event.rc (setter)
110void JSEvent::setReturnCode(bool rc)
111{
112 m_event->setReturnCode(rc);
113}
114
115// Event.willCommit (getter)
116bool JSEvent::willCommit() const
117{
118 return m_event->willCommit();
119}
120
121// Event.change (getter)
122QString JSEvent::change() const
123{
124 return m_event->change();
125}
126
127// Event.selStart (getter)
128int JSEvent::selStart() const
129{
130 return m_event->selStart();
131}
132
133// Event.selEnd (getter)
134int JSEvent::selEnd() const
135{
136 return m_event->selEnd();
137}
138
139JSEvent::JSEvent(Event *event, QObject *parent)
140 : QObject(parent)
141 , m_event(event)
142{
143}
144
145JSEvent::~JSEvent() = default;
The base interface of a form field.
Definition form.h:40
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
global.h
Definition action.h:17
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:47:55 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.