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 #include "sidebarinterface.h" 0020 #include <QQmlComponent> 0021 #include <QQmlParserStatus> 0022 0023 class QmlSideBarHelper; 0024 0025 /** 0026 * @brief The class exposing SideBar API to QML 0027 */ 0028 class QmlSideBar : public QObject, public QQmlParserStatus 0029 { 0030 Q_OBJECT 0031 Q_INTERFACES(QQmlParserStatus) 0032 0033 /** 0034 * @brief name of the sidebar. This is required property. 0035 */ 0036 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged) 0037 0038 /** 0039 * @brief title of the sidebar action. 0040 */ 0041 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) 0042 0043 /** 0044 * @brief icon path of the sidebar action. 0045 * 0046 * The icon path will be search in the following order 0047 * - Theme icon: if the icon is found as a theme icon, then it will 0048 * be used even if the icon file with same name is present 0049 * in the plugin directory 0050 * - Falkon resource: for the icons starting with ":", they are searched in 0051 * falkon resource file 0052 * - Files in plugin directory: All other paths will be resolved relative to 0053 * the plugin directory. If the icon path is outside the 0054 * plugin directory, then it will be resolved as empty path. 0055 */ 0056 Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged) 0057 0058 /** 0059 * @brief shortcut for the sidebar action. 0060 */ 0061 Q_PROPERTY(QString shortcut READ shortcut WRITE setShortcut NOTIFY shortcutChanged) 0062 0063 /** 0064 * @brief represents whether the sidebar action is checkable 0065 */ 0066 Q_PROPERTY(bool checkable READ checkable WRITE setCheckable NOTIFY checkableChanged) 0067 0068 /** 0069 * @brief the GUI of the sidebar. This must be provided as QML Window. 0070 * This is a default property. 0071 */ 0072 Q_PROPERTY(QQmlComponent* item READ item WRITE setItem NOTIFY itemChanged) 0073 Q_CLASSINFO("DefaultProperty", "item") 0074 0075 public: 0076 explicit QmlSideBar(QObject *parent = nullptr); 0077 ~QmlSideBar() override; 0078 void classBegin() override {} 0079 void componentComplete() override; 0080 QString name() const; 0081 SideBarInterface *sideBar() const; 0082 0083 Q_SIGNALS: 0084 /** 0085 * @brief This signal is emitted when name property is changed. 0086 * @param QString represening name 0087 */ 0088 void nameChanged(const QString &name); 0089 0090 /** 0091 * @brief This signal is emitted when title property is changed 0092 * @param QString representing title 0093 */ 0094 void titleChanged(const QString &title); 0095 0096 /** 0097 * @brief This signal is emitted when icon property is changed 0098 * @param QString representing icon path url 0099 */ 0100 void iconChanged(const QString &icon); 0101 0102 /** 0103 * @brief This signal is emitted when shortcut property is changed 0104 * @param QString representing shortcut 0105 */ 0106 void shortcutChanged(const QString &shortcut); 0107 0108 /** 0109 * @brief This signal is emitted when checkable property is changed 0110 * @param checkable 0111 */ 0112 void checkableChanged(bool checkable); 0113 void itemChanged(QQmlComponent *item); 0114 0115 private: 0116 QString m_name; 0117 QString m_title; 0118 QString m_iconUrl; 0119 QString m_shortcut; 0120 bool m_checkable = false; 0121 QQmlComponent *m_item = nullptr; 0122 0123 QmlSideBarHelper *m_sideBarHelper = nullptr; 0124 0125 void setName(const QString &name); 0126 QString title() const; 0127 void setTitle(const QString &title); 0128 QString icon() const; 0129 void setIcon(const QString &icon); 0130 QString shortcut() const; 0131 void setShortcut(const QString &shortcut); 0132 bool checkable(); 0133 void setCheckable(bool checkable); 0134 QQmlComponent *item() const; 0135 void setItem(QQmlComponent *item); 0136 }; 0137 0138 class QmlSideBarHelper : public SideBarInterface 0139 { 0140 Q_OBJECT 0141 public: 0142 explicit QmlSideBarHelper(QObject *parent = nullptr); 0143 QString title() const override; 0144 QAction *createMenuAction() override; 0145 QWidget *createSideBarWidget(BrowserWindow *mainWindow) override; 0146 0147 void setTitle(const QString &title); 0148 void setIcon(const QString &icon); 0149 void setShortcut(const QString &shortcut); 0150 void setCheckable(bool checkable); 0151 void setItem(QQmlComponent *item); 0152 0153 private: 0154 QString m_title; 0155 QString m_iconUrl; 0156 QString m_shortcut; 0157 bool m_checkable = false; 0158 QQmlComponent *m_item = nullptr; 0159 };