diff --git a/src/lib/plugins/qml/api/browseraction/qmlbrowseraction.cpp b/src/lib/plugins/qml/api/browseraction/qmlbrowseraction.cpp index ab07ddef..afcf5842 100644 --- a/src/lib/plugins/qml/api/browseraction/qmlbrowseraction.cpp +++ b/src/lib/plugins/qml/api/browseraction/qmlbrowseraction.cpp @@ -1,89 +1,106 @@ +/* ============================================================ +* Falkon - Qt web browser +* Copyright (C) 2018 Anmol Gautam +* +* 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 . +* ============================================================ */ #include "qmlbrowseraction.h" #include "mainapplication.h" #include QmlBrowserAction::QmlBrowserAction(QObject *parent) : AbstractButtonInterface(parent) , m_popup(nullptr) { connect(this, &AbstractButtonInterface::clicked, this, &QmlBrowserAction::clicked); } QString QmlBrowserAction::id() const { return m_id; } void QmlBrowserAction::setId(const QString &id) { m_id = id; } QString QmlBrowserAction::name() const { return m_name; } void QmlBrowserAction::setName(const QString &name) { m_name = name; } QString QmlBrowserAction::iconUrl() const { return m_iconUrl; } void QmlBrowserAction::setIconUrl(const QString &iconUrl) { m_iconUrl = iconUrl; QString fileName = QUrl(m_iconUrl.toUtf8()).toLocalFile(); setIcon(QIcon(fileName)); } QQmlComponent* QmlBrowserAction::popup() const { return m_popup; } void QmlBrowserAction::setPopup(QQmlComponent* popup) { m_popup = popup; } QmlBrowserAction::LocationFlags QmlBrowserAction::location() const { return m_displayFlags; } void QmlBrowserAction::setLocation(const LocationFlags &locationFlags) { m_displayFlags = locationFlags; emit locationChanged(); } void QmlBrowserAction::clicked(ClickController *clickController) { if (!m_popup) { qWarning() << "No popup to show"; return; } QQuickWindow *quickWindow = dynamic_cast(m_popup->create()); if (!quickWindow) { qWarning() << "Cannot create QQuickWindow from popup"; return; } quickWindow->setFlags(Qt::Popup); quickWindow->setPosition(clickController->callPopupPosition(quickWindow->size())); connect(quickWindow, &QQuickWindow::activeChanged, this, [quickWindow, clickController]{ if (!quickWindow->isActive()) { quickWindow->destroy(); clickController->callPopupClosed(); } }); quickWindow->show(); quickWindow->requestActivate(); } diff --git a/src/lib/plugins/qml/api/browseraction/qmlbrowseraction.h b/src/lib/plugins/qml/api/browseraction/qmlbrowseraction.h index e94f9d0d..47ef6395 100644 --- a/src/lib/plugins/qml/api/browseraction/qmlbrowseraction.h +++ b/src/lib/plugins/qml/api/browseraction/qmlbrowseraction.h @@ -1,50 +1,67 @@ +/* ============================================================ +* Falkon - Qt web browser +* Copyright (C) 2018 Anmol Gautam +* +* 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 . +* ============================================================ */ #pragma once #include "abstractbuttoninterface.h" #include class QmlBrowserAction : public AbstractButtonInterface { Q_OBJECT Q_PROPERTY(QString identity READ id WRITE setId) Q_PROPERTY(QString name READ name WRITE setName) Q_PROPERTY(QString title READ title WRITE setTitle) Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip) Q_PROPERTY(QString icon READ iconUrl WRITE setIconUrl) Q_PROPERTY(QString badgeText READ badgeText WRITE setBadgeText) Q_PROPERTY(QQmlComponent* popup READ popup WRITE setPopup) Q_PROPERTY(LocationFlags location READ location WRITE setLocation NOTIFY locationChanged) public: enum Location { NavigationToolBar = 0x1, StatusBar = 0x2 }; Q_DECLARE_FLAGS(LocationFlags, Location) Q_ENUMS(LocationFlags) explicit QmlBrowserAction(QObject *parent = nullptr); QString id() const; void setId(const QString &id); QString name() const; void setName(const QString &name); QString iconUrl() const; void setIconUrl(const QString &iconUrl); QQmlComponent* popup() const; void setPopup(QQmlComponent* popup); LocationFlags location() const; void setLocation(const LocationFlags &locationFlags); Q_SIGNALS: void locationChanged(); private: QString m_id; QString m_name; QString m_iconUrl; QQmlComponent* m_popup; LocationFlags m_displayFlags; void clicked(ClickController *clickController); }; Q_DECLARE_OPERATORS_FOR_FLAGS(QmlBrowserAction::LocationFlags)