Falkon Develop
Cross-platform Qt-based web browser
qmlsidebar.h
Go to the documentation of this file.
1/* ============================================================
2* Falkon - Qt web browser
3* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
4*
5* This program is free software: you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation, either version 3 of the License, or
8* (at your option) any later version.
9*
10* This program is distributed in the hope that it will be useful,
11* but WITHOUT ANY WARRANTY; without even the implied warranty of
12* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13* GNU General Public License for more details.
14*
15* You should have received a copy of the GNU General Public License
16* along with this program. If not, see <http://www.gnu.org/licenses/>.
17* ============================================================ */
18#pragma once
19#include "sidebarinterface.h"
20#include <QQmlComponent>
21#include <QQmlParserStatus>
22
24
28class QmlSideBar : public QObject, public QQmlParserStatus
29{
30 Q_OBJECT
31 Q_INTERFACES(QQmlParserStatus)
32
33
36 Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
37
38
41 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
42
43
56 Q_PROPERTY(QString icon READ icon WRITE setIcon NOTIFY iconChanged)
57
58
61 Q_PROPERTY(QString shortcut READ shortcut WRITE setShortcut NOTIFY shortcutChanged)
62
63
66 Q_PROPERTY(bool checkable READ checkable WRITE setCheckable NOTIFY checkableChanged)
67
68
72 Q_PROPERTY(QQmlComponent* item READ item WRITE setItem NOTIFY itemChanged)
73 Q_CLASSINFO("DefaultProperty", "item")
74
75public:
76 explicit QmlSideBar(QObject *parent = nullptr);
77 ~QmlSideBar() override;
78 void classBegin() override {}
79 void componentComplete() override;
80 QString name() const;
82
83Q_SIGNALS:
88 void nameChanged(const QString &name);
89
94 void titleChanged(const QString &title);
95
100 void iconChanged(const QString &icon);
101
106 void shortcutChanged(const QString &shortcut);
107
113 void itemChanged(QQmlComponent *item);
114
115private:
116 QString m_name;
117 QString m_title;
118 QString m_iconUrl;
119 QString m_shortcut;
120 bool m_checkable = false;
121 QQmlComponent *m_item = nullptr;
122
123 QmlSideBarHelper *m_sideBarHelper = nullptr;
124
125 void setName(const QString &name);
126 QString title() const;
127 void setTitle(const QString &title);
128 QString icon() const;
129 void setIcon(const QString &icon);
130 QString shortcut() const;
131 void setShortcut(const QString &shortcut);
132 bool checkable();
133 void setCheckable(bool checkable);
134 QQmlComponent *item() const;
135 void setItem(QQmlComponent *item);
136};
137
139{
140 Q_OBJECT
141public:
142 explicit QmlSideBarHelper(QObject *parent = nullptr);
143 QString title() const override;
144 QAction *createMenuAction() override;
145 QWidget *createSideBarWidget(BrowserWindow *mainWindow) override;
146
147 void setTitle(const QString &title);
148 void setIcon(const QString &icon);
149 void setShortcut(const QString &shortcut);
150 void setCheckable(bool checkable);
151 void setItem(QQmlComponent *item);
152
153private:
154 QString m_title;
155 QString m_iconUrl;
156 QString m_shortcut;
157 bool m_checkable = false;
158 QQmlComponent *m_item = nullptr;
159};
void setItem(QQmlComponent *item)
Definition: qmlsidebar.cpp:181
QAction * createMenuAction() override
Definition: qmlsidebar.cpp:132
void setIcon(const QString &icon)
Definition: qmlsidebar.cpp:166
void setTitle(const QString &title)
Definition: qmlsidebar.cpp:161
void setCheckable(bool checkable)
Definition: qmlsidebar.cpp:176
QmlSideBarHelper(QObject *parent=nullptr)
Definition: qmlsidebar.cpp:122
void setShortcut(const QString &shortcut)
Definition: qmlsidebar.cpp:171
QString title() const override
Definition: qmlsidebar.cpp:127
QWidget * createSideBarWidget(BrowserWindow *mainWindow) override
Definition: qmlsidebar.cpp:150
The class exposing SideBar API to QML.
Definition: qmlsidebar.h:29
QQmlComponent * item
the GUI of the sidebar. This must be provided as QML Window. This is a default property.
Definition: qmlsidebar.h:72
void iconChanged(const QString &icon)
This signal is emitted when icon property is changed.
QString shortcut
shortcut for the sidebar action.
Definition: qmlsidebar.h:61
SideBarInterface * sideBar() const
Definition: qmlsidebar.cpp:56
~QmlSideBar() override
Definition: qmlsidebar.cpp:41
QmlSideBar(QObject *parent=nullptr)
Definition: qmlsidebar.cpp:29
QString name
name of the sidebar. This is required property.
Definition: qmlsidebar.h:36
bool checkable
represents whether the sidebar action is checkable
Definition: qmlsidebar.h:66
void checkableChanged(bool checkable)
This signal is emitted when checkable property is changed.
void nameChanged(const QString &name)
This signal is emitted when name property is changed.
void itemChanged(QQmlComponent *item)
void componentComplete() override
Definition: qmlsidebar.cpp:46
void titleChanged(const QString &title)
This signal is emitted when title property is changed.
QString title
title of the sidebar action.
Definition: qmlsidebar.h:41
QString icon
icon path of the sidebar action.
Definition: qmlsidebar.h:56
void shortcutChanged(const QString &shortcut)
This signal is emitted when shortcut property is changed.
void classBegin() override
Definition: qmlsidebar.h:78