mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 18:56:34 +01:00
Created QML Windows API
This commit is contained in:
parent
7f5f3a8bfc
commit
637d4cfef0
@ -169,6 +169,10 @@ set(SRCS ${SRCS}
|
||||
plugins/qml/api/tabs/qmltabs.cpp
|
||||
plugins/qml/api/notifications/qmlnotifications.cpp
|
||||
plugins/qml/api/clipboard/qmlclipboard.cpp
|
||||
plugins/qml/api/windows/qmlwindow.cpp
|
||||
plugins/qml/api/windows/qmlwindows.cpp
|
||||
plugins/qml/api/windows/qmlwindowstate.cpp
|
||||
plugins/qml/api/windows/qmlwindowtype.cpp
|
||||
popupwindow/popuplocationbar.cpp
|
||||
popupwindow/popupstatusbarmessage.cpp
|
||||
popupwindow/popupwebview.cpp
|
||||
|
127
src/lib/plugins/qml/api/windows/qmlwindow.cpp
Normal file
127
src/lib/plugins/qml/api/windows/qmlwindow.cpp
Normal file
@ -0,0 +1,127 @@
|
||||
/* ============================================================
|
||||
* 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 "qmlwindow.h"
|
||||
#include "mainapplication.h"
|
||||
#include "../tabs/qmltab.h"
|
||||
#include "tabwidget.h"
|
||||
|
||||
QmlWindow::QmlWindow(BrowserWindow *window, QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_window(window)
|
||||
{
|
||||
}
|
||||
|
||||
int QmlWindow::id() const
|
||||
{
|
||||
if (!mApp->windowIdHash().contains(m_window)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return mApp->windowIdHash().value(m_window);
|
||||
}
|
||||
|
||||
bool QmlWindow::incognito() const
|
||||
{
|
||||
return mApp->isPrivate();
|
||||
}
|
||||
|
||||
QString QmlWindow::title() const
|
||||
{
|
||||
if (!m_window) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
return m_window->windowTitle();
|
||||
}
|
||||
|
||||
QmlWindowState::WindowState QmlWindow::state() const
|
||||
{
|
||||
if (!m_window) {
|
||||
return QmlWindowState::Invalid;
|
||||
}
|
||||
|
||||
if (m_window->isFullScreen()) {
|
||||
return QmlWindowState::FullScreen;
|
||||
} else if (m_window->isMaximized()) {
|
||||
return QmlWindowState::Maximized;
|
||||
} else if (m_window->isMinimized()) {
|
||||
return QmlWindowState::Minimized;
|
||||
} else {
|
||||
return QmlWindowState::Normal;
|
||||
}
|
||||
}
|
||||
|
||||
QmlWindowType::WindowType QmlWindow::type() const
|
||||
{
|
||||
if (!m_window) {
|
||||
return QmlWindowType::OtherRestoredWindow;
|
||||
}
|
||||
|
||||
switch (m_window->windowType()) {
|
||||
case Qz::BW_FirstAppWindow:
|
||||
return QmlWindowType::FirstAppWindow;
|
||||
case Qz::BW_MacFirstWindow:
|
||||
return QmlWindowType::MacFirstWindow;
|
||||
case Qz::BW_NewWindow:
|
||||
return QmlWindowType::NewWindow;
|
||||
default:
|
||||
return QmlWindowType::OtherRestoredWindow;
|
||||
}
|
||||
}
|
||||
|
||||
QList<QObject*> QmlWindow::tabs() const
|
||||
{
|
||||
if (!m_window) {
|
||||
return QList<QObject*>();
|
||||
}
|
||||
|
||||
QList<QObject*> list;
|
||||
|
||||
for (WebTab *tab : m_window->tabWidget()->allTabs(true)) {
|
||||
list.append(new QmlTab(tab));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
bool QmlWindow::focussed() const
|
||||
{
|
||||
if (!m_window) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return m_window->isActiveWindow();
|
||||
}
|
||||
|
||||
int QmlWindow::height() const
|
||||
{
|
||||
if (!m_window) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return m_window->height();
|
||||
}
|
||||
|
||||
int QmlWindow::width() const
|
||||
{
|
||||
if (!m_window) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return m_window->width();
|
||||
}
|
50
src/lib/plugins/qml/api/windows/qmlwindow.h
Normal file
50
src/lib/plugins/qml/api/windows/qmlwindow.h
Normal file
@ -0,0 +1,50 @@
|
||||
/* ============================================================
|
||||
* 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 <QObject>
|
||||
#include "browserwindow.h"
|
||||
#include "qmlwindowstate.h"
|
||||
#include "qmlwindowtype.h"
|
||||
|
||||
class QmlWindow : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int id READ id CONSTANT)
|
||||
Q_PROPERTY(bool incognito READ incognito CONSTANT)
|
||||
Q_PROPERTY(QString title READ title CONSTANT)
|
||||
Q_PROPERTY(QmlWindowState::WindowState state READ state CONSTANT)
|
||||
Q_PROPERTY(QmlWindowType::WindowType type READ type CONSTANT)
|
||||
Q_PROPERTY(QList<QObject*> tabs READ tabs CONSTANT)
|
||||
Q_PROPERTY(bool focussed READ focussed CONSTANT)
|
||||
Q_PROPERTY(int height READ height CONSTANT)
|
||||
Q_PROPERTY(int width READ width CONSTANT)
|
||||
public:
|
||||
QmlWindow(BrowserWindow *window = 0, QObject *parent = 0);
|
||||
int id() const;
|
||||
bool incognito() const;
|
||||
QString title() const;
|
||||
QmlWindowState::WindowState state() const;
|
||||
QmlWindowType::WindowType type() const;
|
||||
QList<QObject*> tabs() const;
|
||||
bool focussed() const;
|
||||
int height() const;
|
||||
int width() const;
|
||||
private:
|
||||
BrowserWindow *m_window;
|
||||
};
|
85
src/lib/plugins/qml/api/windows/qmlwindows.cpp
Normal file
85
src/lib/plugins/qml/api/windows/qmlwindows.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
/* ============================================================
|
||||
* 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 "qmlwindows.h"
|
||||
#include "mainapplication.h"
|
||||
#include "pluginproxy.h"
|
||||
|
||||
QmlWindows::QmlWindows(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
connect(mApp->plugins(), &PluginProxy::mainWindowCreated, this, [this](BrowserWindow *window){
|
||||
QmlWindow *qmlWindow = new QmlWindow(window);
|
||||
emit created(qmlWindow);
|
||||
});
|
||||
|
||||
connect(mApp->plugins(), &PluginProxy::mainWindowDeleted, this, [this](BrowserWindow *window){
|
||||
QmlWindow *qmlWindow = new QmlWindow(window);
|
||||
emit removed(qmlWindow);
|
||||
});
|
||||
}
|
||||
|
||||
QmlWindow *QmlWindows::get(const QVariantMap &map) const
|
||||
{
|
||||
if (!map.contains(QSL("id"))) {
|
||||
qWarning() << "Unable to get window:" << "id not defined";
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int id = map.value(QSL("id")).toInt();
|
||||
return new QmlWindow(getBrowserWindow(id));
|
||||
}
|
||||
|
||||
QmlWindow *QmlWindows::getCurrent() const
|
||||
{
|
||||
return new QmlWindow(mApp->getWindow());
|
||||
}
|
||||
|
||||
QList<QObject*> QmlWindows::getAll() const
|
||||
{
|
||||
QList<QObject*> list;
|
||||
for (BrowserWindow *window : mApp->windows()) {
|
||||
list.append(new QmlWindow(window));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
QmlWindow *QmlWindows::create(const QVariantMap &map) const
|
||||
{
|
||||
QUrl url = QUrl::fromEncoded(map.value(QSL("url")).toString().toUtf8());
|
||||
Qz::BrowserWindowType type = Qz::BrowserWindowType(map.value(QSL("type"), QmlWindowType::NewWindow).toInt());
|
||||
BrowserWindow *window = mApp->createWindow(type, url);
|
||||
return new QmlWindow(window);
|
||||
}
|
||||
|
||||
void QmlWindows::remove(int windowId) const
|
||||
{
|
||||
BrowserWindow *window = getBrowserWindow(windowId);
|
||||
window->close();
|
||||
}
|
||||
|
||||
BrowserWindow *QmlWindows::getBrowserWindow(int windowId) const
|
||||
{
|
||||
for (BrowserWindow *window : mApp->windows()) {
|
||||
if (mApp->windowIdHash().value(window) == windowId) {
|
||||
return window;
|
||||
}
|
||||
}
|
||||
|
||||
qWarning() << "Unable to get window with given id";
|
||||
return nullptr;
|
||||
}
|
38
src/lib/plugins/qml/api/windows/qmlwindows.h
Normal file
38
src/lib/plugins/qml/api/windows/qmlwindows.h
Normal file
@ -0,0 +1,38 @@
|
||||
/* ============================================================
|
||||
* 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 <QObject>
|
||||
#include "qmlwindow.h"
|
||||
|
||||
class QmlWindows : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QmlWindows(QObject *parent = 0);
|
||||
Q_INVOKABLE QmlWindow *get(const QVariantMap &map) const;
|
||||
Q_INVOKABLE QmlWindow *getCurrent() const;
|
||||
Q_INVOKABLE QList<QObject*> getAll() const;
|
||||
Q_INVOKABLE QmlWindow *create(const QVariantMap &map) const;
|
||||
Q_INVOKABLE void remove(int windowId) const;
|
||||
Q_SIGNALS:
|
||||
void created(QmlWindow *window);
|
||||
void removed(QmlWindow *window);
|
||||
private:
|
||||
BrowserWindow *getBrowserWindow(int windowId) const;
|
||||
};
|
23
src/lib/plugins/qml/api/windows/qmlwindowstate.cpp
Normal file
23
src/lib/plugins/qml/api/windows/qmlwindowstate.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
/* ============================================================
|
||||
* 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 "qmlwindowstate.h"
|
||||
|
||||
QmlWindowState::QmlWindowState(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
36
src/lib/plugins/qml/api/windows/qmlwindowstate.h
Normal file
36
src/lib/plugins/qml/api/windows/qmlwindowstate.h
Normal file
@ -0,0 +1,36 @@
|
||||
/* ============================================================
|
||||
* 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 <QObject>
|
||||
|
||||
class QmlWindowState : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum WindowState {
|
||||
FullScreen,
|
||||
Maximized,
|
||||
Minimized,
|
||||
Normal,
|
||||
Invalid
|
||||
};
|
||||
Q_ENUMS(WindowState)
|
||||
|
||||
QmlWindowState(QObject *parent = 0);
|
||||
};
|
23
src/lib/plugins/qml/api/windows/qmlwindowtype.cpp
Normal file
23
src/lib/plugins/qml/api/windows/qmlwindowtype.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
/* ============================================================
|
||||
* 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 "qmlwindowtype.h"
|
||||
|
||||
QmlWindowType::QmlWindowType(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
}
|
36
src/lib/plugins/qml/api/windows/qmlwindowtype.h
Normal file
36
src/lib/plugins/qml/api/windows/qmlwindowtype.h
Normal file
@ -0,0 +1,36 @@
|
||||
/* ============================================================
|
||||
* 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 <QObject>
|
||||
#include "qzcommon.h"
|
||||
|
||||
class QmlWindowType : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum WindowType {
|
||||
FirstAppWindow = Qz::BW_FirstAppWindow,
|
||||
MacFirstWindow = Qz::BW_MacFirstWindow,
|
||||
NewWindow = Qz::BW_NewWindow,
|
||||
OtherRestoredWindow = Qz::BW_OtherRestoredWindow
|
||||
};
|
||||
Q_ENUMS(WindowType)
|
||||
|
||||
QmlWindowType(QObject *parent = 0);
|
||||
};
|
@ -29,6 +29,10 @@
|
||||
#include "api/tabs/qmltabs.h"
|
||||
#include "api/notifications/qmlnotifications.h"
|
||||
#include "api/clipboard/qmlclipboard.h"
|
||||
#include "api/windows/qmlwindow.h"
|
||||
#include "api/windows/qmlwindows.h"
|
||||
#include "api/windows/qmlwindowstate.h"
|
||||
#include "api/windows/qmlwindowtype.h"
|
||||
|
||||
#include <QQmlEngine>
|
||||
|
||||
@ -110,4 +114,19 @@ void QmlPlugins::registerQmlTypes()
|
||||
auto *object = new QmlClipboard();
|
||||
return object;
|
||||
});
|
||||
|
||||
// Windows
|
||||
qmlRegisterUncreatableType<QmlWindow>("org.kde.falkon", 1, 0, "Window", "Unable to register type: Window");
|
||||
|
||||
qmlRegisterUncreatableType<QmlWindowState>("org.kde.falkon", 1, 0, "WindowState", "Unable to register type: WindowState");
|
||||
|
||||
qmlRegisterUncreatableType<QmlWindowType>("org.kde.falkon", 1, 0, "WindowType", "Unable to register type: WindowType");
|
||||
|
||||
qmlRegisterSingletonType<QmlWindows>("org.kde.falkon", 1, 0, "Windows", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
|
||||
Q_UNUSED(engine)
|
||||
Q_UNUSED(scriptEngine)
|
||||
|
||||
auto *object = new QmlWindows();
|
||||
return object;
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user