File indexing completed on 2024-12-22 04:41:14

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #pragma once
0019 
0020 #include "qmlaction.h"
0021 #include <QMenu>
0022 #include <QQmlEngine>
0023 
0024 class QmlEngine;
0025 
0026 /**
0027  * @brief The class exposing WebView contextmenu to QML as Menu API
0028  */
0029 class QmlMenu : public QObject
0030 {
0031     Q_OBJECT
0032 public:
0033     explicit QmlMenu(QMenu *menu, QQmlEngine *engine, QObject *parent = nullptr);
0034     /**
0035      * @brief Adds action to menu
0036      * @param A JavaScript object containing properties for action.
0037      *        The icon property must be in form of url of the path
0038      *        and shortcut in form string.
0039      * @return action of type [QmlAction](@ref QmlAction)
0040      */
0041     Q_INVOKABLE QmlAction *addAction(const QVariantMap &map);
0042     /**
0043      * @brief Adds sub-menu to menu
0044      * @param A JavaScript object containing properties of menu.
0045      *        The icon property must be in form of url of the path.
0046      * @return menu of type [QmlMenu](@ref QmlMenu)
0047      */
0048     Q_INVOKABLE QmlMenu *addMenu(const QVariantMap &map);
0049     /**
0050      * @brief Adds a separator to menu
0051      */
0052     Q_INVOKABLE void addSeparator();
0053 
0054 Q_SIGNALS:
0055     /**
0056      * @brief This signal is emitted when the menu is triggred
0057      */
0058     void triggered();
0059 
0060 private:
0061     QMenu *m_menu = nullptr;
0062     QString m_pluginPath;
0063     QmlEngine *m_engine = nullptr;
0064 };