okular/core/script/js_app_p.h
Alexis Murzeau 2609f4001a Add support for app.popUpMenu and submenus in popUpMenuEx
These functions from `app` are JS functions that can be used by PDF
files.

Based on popUpMenuEx, the implementation of popUpMenu converts arguments
to app.popUpMenuEx format and then call it.

The popMenuEx function is improved to handle submenus as well using
`oSubMenu`.

app.popUpMenu is used in Altium Designer and EasyEDA exported PDFs.
See an example here:
https://www.st.com/en/evaluation-tools/32f723ediscovery.html#cad-resources
https://www.st.com/resource/en/schematic_pack/mb1260-f723e-d03_schematic.pdf

BUGS: 479777
2024-01-17 19:01:08 +00:00

75 lines
2.5 KiB
C++

/*
SPDX-FileCopyrightText: 2008 Pino Toscano <pino@kde.org>
SPDX-FileCopyrightText: 2008 Harri Porten <porten@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef OKULAR_SCRIPT_JS_APP_P_H
#define OKULAR_SCRIPT_JS_APP_P_H
#include <QJSValue>
#include <QObject>
#include <QPoint>
class QMenu;
class QTimer;
namespace Okular
{
class DocumentPrivate;
class JSApp : public QObject
{
Q_OBJECT
Q_PROPERTY(int formsVersion READ formsVersion CONSTANT)
Q_PROPERTY(QString language READ language CONSTANT)
Q_PROPERTY(int numPlugIns READ numPlugIns CONSTANT)
Q_PROPERTY(QString platform READ platform CONSTANT)
Q_PROPERTY(QJSValue plugIns READ plugIns CONSTANT)
Q_PROPERTY(QStringList printColorProfiles READ printColorProfiles CONSTANT)
Q_PROPERTY(QStringList printerNames READ printerNames CONSTANT)
Q_PROPERTY(QString viewerType READ viewerType CONSTANT)
Q_PROPERTY(QString viewerVariation READ viewerVariation CONSTANT)
Q_PROPERTY(int viewerVersion READ viewerVersion CONSTANT)
public:
explicit JSApp(DocumentPrivate *doc, QTimer *watchdogTimer, QObject *parent = nullptr);
~JSApp() override;
static void clearCachedFields();
int formsVersion() const;
QString language() const;
int numPlugIns() const;
QString platform() const;
QJSValue plugIns() const;
QStringList printColorProfiles() const;
QStringList printerNames() const;
QString viewerType() const;
QString viewerVariation() const;
int viewerVersion() const;
Q_INVOKABLE int alert(const QJSValue &arguments);
Q_INVOKABLE int alert(const QString &cMsg, int nIcon = 0, int nType = 0, const QString &cTitle = {}, const QJSValue &oDoc = {}, const QJSValue &oCheckbox = {});
Q_INVOKABLE void beep(int nType = 4);
Q_INVOKABLE QJSValue getNthPlugInName(int nIndex) const;
Q_INVOKABLE void goBack();
Q_INVOKABLE void goForward();
Q_INVOKABLE QJSValue setInterval(const QString &cExpr, int nMilliseconds);
Q_INVOKABLE void clearInterval(const QJSValue &oInterval);
Q_INVOKABLE QJSValue setTimeOut(const QString &cExpr, int nMilliseconds);
Q_INVOKABLE void clearTimeOut(const QJSValue &oTime);
Q_INVOKABLE QJSValue okular_popUpMenuEx(const QJSValue &arguments);
private:
QJSValue wrapTimer(QTimer *timer) const;
static bool createPopUpMenuTree(int depth, QMenu *rootMenu, const QJSValue &arguments);
DocumentPrivate *m_doc = nullptr;
QTimer *m_watchdogTimer = nullptr;
};
}
#endif