mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
Created QML SideBar API
This commit is contained in:
parent
0a0d9b79b4
commit
987e4c75ae
|
@ -174,6 +174,7 @@ set(SRCS ${SRCS}
|
|||
plugins/qml/api/windows/qmlwindowstate.cpp
|
||||
plugins/qml/api/windows/qmlwindowtype.cpp
|
||||
plugins/qml/api/browseraction/qmlbrowseraction.cpp
|
||||
plugins/qml/api/sidebar/qmlsidebar.cpp
|
||||
popupwindow/popuplocationbar.cpp
|
||||
popupwindow/popupstatusbarmessage.cpp
|
||||
popupwindow/popupwebview.cpp
|
||||
|
|
110
src/lib/plugins/qml/api/sidebar/qmlsidebar.cpp
Normal file
110
src/lib/plugins/qml/api/sidebar/qmlsidebar.cpp
Normal file
|
@ -0,0 +1,110 @@
|
|||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "qmlsidebar.h"
|
||||
#include "mainapplication.h"
|
||||
#include <QAction>
|
||||
#include <QQuickWindow>
|
||||
|
||||
QmlSideBar::QmlSideBar(QObject *parent)
|
||||
: SideBarInterface(parent)
|
||||
, m_item(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
QString QmlSideBar::name() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
void QmlSideBar::setName(const QString &name)
|
||||
{
|
||||
m_name = name;
|
||||
}
|
||||
|
||||
QString QmlSideBar::title() const
|
||||
{
|
||||
return m_title;
|
||||
}
|
||||
|
||||
void QmlSideBar::setTitle(const QString &title)
|
||||
{
|
||||
m_title = title;
|
||||
}
|
||||
|
||||
QString QmlSideBar::icon() const
|
||||
{
|
||||
return m_iconUrl;
|
||||
}
|
||||
|
||||
void QmlSideBar::setIcon(const QString &icon)
|
||||
{
|
||||
m_iconUrl = icon;
|
||||
}
|
||||
|
||||
QString QmlSideBar::shortcut() const
|
||||
{
|
||||
return m_shortcut;
|
||||
}
|
||||
|
||||
void QmlSideBar::setShortcut(const QString &shortcut)
|
||||
{
|
||||
m_shortcut = shortcut;
|
||||
}
|
||||
|
||||
bool QmlSideBar::checkable()
|
||||
{
|
||||
return m_checkable;
|
||||
}
|
||||
|
||||
void QmlSideBar::setCheckable(bool checkable)
|
||||
{
|
||||
m_checkable = checkable;
|
||||
}
|
||||
|
||||
QQmlComponent *QmlSideBar::item() const
|
||||
{
|
||||
return m_item;
|
||||
}
|
||||
|
||||
void QmlSideBar::setItem(QQmlComponent *item)
|
||||
{
|
||||
m_item = item;
|
||||
}
|
||||
|
||||
QAction *QmlSideBar::createMenuAction()
|
||||
{
|
||||
QAction *action = new QAction;
|
||||
action->setText(m_title);
|
||||
action->setCheckable(m_checkable);
|
||||
action->setShortcut(QKeySequence(m_shortcut));
|
||||
action->setIcon(QIcon(QUrl(m_iconUrl).toLocalFile()));
|
||||
return action;
|
||||
}
|
||||
|
||||
QWidget *QmlSideBar::createSideBarWidget(BrowserWindow *mainWindow)
|
||||
{
|
||||
Q_UNUSED(mainWindow)
|
||||
|
||||
QQuickWindow *window = qobject_cast<QQuickWindow*>(m_item->create());
|
||||
if (!window) {
|
||||
qWarning() << "Unable to create QQuickWindow";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return QWidget::createWindowContainer(window);
|
||||
}
|
58
src/lib/plugins/qml/api/sidebar/qmlsidebar.h
Normal file
58
src/lib/plugins/qml/api/sidebar/qmlsidebar.h
Normal file
|
@ -0,0 +1,58 @@
|
|||
/* ============================================================
|
||||
* Falkon - Qt web browser
|
||||
* Copyright (C) 2018 Anmol Gautam <tarptaeya@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#pragma once
|
||||
#include "sidebarinterface.h"
|
||||
#include <QQmlComponent>
|
||||
|
||||
class QmlSideBar : public SideBarInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString name READ name WRITE setName)
|
||||
Q_PROPERTY(QString title READ title WRITE setTitle)
|
||||
Q_PROPERTY(QString icon READ icon WRITE setIcon)
|
||||
Q_PROPERTY(QString shortcut READ shortcut WRITE setShortcut)
|
||||
Q_PROPERTY(bool checkable READ checkable WRITE setCheckable)
|
||||
Q_PROPERTY(QQmlComponent* item READ item WRITE setItem)
|
||||
Q_CLASSINFO("DefaultProperty", "item")
|
||||
|
||||
public:
|
||||
QmlSideBar(QObject *parent = nullptr);
|
||||
QString name() const;
|
||||
void setName(const QString &name);
|
||||
QString title() const;
|
||||
void setTitle(const QString &title);
|
||||
QString icon() const;
|
||||
void setIcon(const QString &icon);
|
||||
QString shortcut() const;
|
||||
void setShortcut(const QString &shortcut);
|
||||
bool checkable();
|
||||
void setCheckable(bool checkable);
|
||||
QQmlComponent *item() const;
|
||||
void setItem(QQmlComponent *item);
|
||||
|
||||
QAction *createMenuAction();
|
||||
QWidget *createSideBarWidget(BrowserWindow *mainWindow);
|
||||
|
||||
private:
|
||||
QString m_name;
|
||||
QString m_title;
|
||||
QString m_iconUrl;
|
||||
QString m_shortcut;
|
||||
bool m_checkable;
|
||||
QQmlComponent *m_item;
|
||||
};
|
|
@ -21,6 +21,7 @@
|
|||
#include "statusbar.h"
|
||||
#include "browserwindow.h"
|
||||
#include "navigationbar.h"
|
||||
#include "sidebar.h"
|
||||
#include <QDebug>
|
||||
|
||||
QmlPluginInterface::QmlPluginInterface()
|
||||
|
@ -121,6 +122,17 @@ void QmlPluginInterface::setBrowserAction(QmlBrowserAction *browserAction)
|
|||
connect(m_browserAction, &QmlBrowserAction::locationChanged, this, &QmlPluginInterface::addButton);
|
||||
}
|
||||
|
||||
QmlSideBar *QmlPluginInterface::sideBar() const
|
||||
{
|
||||
return m_sideBar;
|
||||
}
|
||||
|
||||
void QmlPluginInterface::setSideBar(QmlSideBar *sideBar)
|
||||
{
|
||||
m_sideBar = sideBar;
|
||||
SideBarManager::addSidebar(m_sideBar->name(), m_sideBar);
|
||||
}
|
||||
|
||||
void QmlPluginInterface::addButton()
|
||||
{
|
||||
if (m_browserAction->location().testFlag(QmlBrowserAction::NavigationToolBar)) {
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "desktopfile.h"
|
||||
#include "plugininterface.h"
|
||||
#include "api/browseraction/qmlbrowseraction.h"
|
||||
#include "api/sidebar/qmlsidebar.h"
|
||||
|
||||
class QmlPluginInterface : public QObject, public PluginInterface
|
||||
{
|
||||
|
@ -33,7 +34,7 @@ class QmlPluginInterface : public QObject, public PluginInterface
|
|||
Q_PROPERTY(QJSValue unload READ jsUnload WRITE setJsUnload)
|
||||
Q_PROPERTY(QJSValue testPlugin READ jsTestPlugin WRITE setJsTestPlugin)
|
||||
Q_PROPERTY(QmlBrowserAction* browserAction READ browserAction WRITE setBrowserAction)
|
||||
Q_CLASSINFO("DefaultProperty", "browserAction")
|
||||
Q_PROPERTY(QmlSideBar* sideBar READ sideBar WRITE setSideBar)
|
||||
|
||||
public:
|
||||
explicit QmlPluginInterface();
|
||||
|
@ -52,6 +53,7 @@ private:
|
|||
QJSValue m_jsUnload;
|
||||
QJSValue m_jsTestPlugin;
|
||||
QmlBrowserAction *m_browserAction;
|
||||
QmlSideBar *m_sideBar;
|
||||
|
||||
QJSValue jsInit() const;
|
||||
void setJsInit(const QJSValue &init);
|
||||
|
@ -61,6 +63,8 @@ private:
|
|||
void setJsTestPlugin(const QJSValue &testPlugin);
|
||||
QmlBrowserAction *browserAction() const;
|
||||
void setBrowserAction(QmlBrowserAction *browserAction);
|
||||
QmlSideBar *sideBar() const;
|
||||
void setSideBar(QmlSideBar *sideBar);
|
||||
|
||||
void addButton();
|
||||
void addToolButton();
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "api/windows/qmlwindowstate.h"
|
||||
#include "api/windows/qmlwindowtype.h"
|
||||
#include "api/browseraction/qmlbrowseraction.h"
|
||||
#include "api/sidebar/qmlsidebar.h"
|
||||
|
||||
#include <QQmlEngine>
|
||||
|
||||
|
@ -133,4 +134,7 @@ void QmlPlugins::registerQmlTypes()
|
|||
|
||||
// BrowserAction
|
||||
qmlRegisterType<QmlBrowserAction>("org.kde.falkon", 1, 0, "BrowserAction");
|
||||
|
||||
// SideBar
|
||||
qmlRegisterType<QmlSideBar>("org.kde.falkon", 1, 0, "SideBar");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user