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 FormField *target = static_cast<FormField *>(m_event->target());
69 if (target) {
70 return JSField::wrapField(qjsEngine(this), target, m_event->targetPage());
71 }
72 break;
73 }
74 default: {
75 }
76 }
78}
79
80// Event.value (getter)
81QJSValue JSEvent::value() const
82{
83 return m_event->value().toString();
84}
85
86// Event.value (setter)
87void JSEvent::setValue(const QJSValue &value)
88{
89 m_event->setValue(QVariant(value.toString()));
90}
91
92// Event.rc (getter)
93bool JSEvent::returnCode() const
94{
95 return m_event->returnCode();
96}
97
98// Event.rc (setter)
99void JSEvent::setReturnCode(bool rc)
100{
101 m_event->setReturnCode(rc);
102}
103
104// Event.willCommit (getter)
105bool JSEvent::willCommit() const
106{
107 return m_event->willCommit();
108}
109
110// Event.change (getter)
111QString JSEvent::change() const
112{
113 return m_event->change();
114}
115
116JSEvent::JSEvent(Event *event, QObject *parent)
117 : QObject(parent)
118 , m_event(event)
119{
120}
121
122JSEvent::~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 Tue Mar 26 2024 11:17:35 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.