/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2021 MuseScore BVBA and others
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* 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 .
*/
#ifndef MU_UI_INTERACTIVEPROVIDER_H
#define MU_UI_INTERACTIVEPROVIDER_H
#include
#include
#include
#include
#include "modularity/ioc.h"
#include "../iinteractiveprovider.h"
#include "../iinteractiveuriregister.h"
#include "../imainwindow.h"
#include "retval.h"
namespace mu::ui {
class QmlLaunchData : public QObject
{
Q_OBJECT
public:
explicit QmlLaunchData(QObject* parent = nullptr);
Q_INVOKABLE QVariant value(const QString& key) const;
Q_INVOKABLE void setValue(const QString& key, const QVariant& val);
Q_INVOKABLE QVariant data() const;
private:
QVariantMap m_data;
};
class InteractiveProvider : public QObject, public IInteractiveProvider
{
Q_OBJECT
INJECT(ui, IInteractiveUriRegister, uriRegister)
INJECT(ui, IMainWindow, mainWindow)
public:
explicit InteractiveProvider();
RetVal question(const std::string& title, const framework::IInteractive::Text& text,
const framework::IInteractive::ButtonDatas& buttons, int defBtn = int(framework::IInteractive::Button::NoButton),
const framework::IInteractive::Options& options = {}) override;
RetVal info(const std::string& title, const std::string& text, const framework::IInteractive::ButtonDatas& buttons,
int defBtn = int(framework::IInteractive::Button::NoButton),
const framework::IInteractive::Options& options = {}) override;
RetVal warning(const std::string& title, const std::string& text, const framework::IInteractive::ButtonDatas& buttons,
int defBtn = int(framework::IInteractive::Button::NoButton),
const framework::IInteractive::Options& options = {}) override;
RetVal error(const std::string& title, const std::string& text, const framework::IInteractive::ButtonDatas& buttons,
int defBtn = int(framework::IInteractive::Button::NoButton),
const framework::IInteractive::Options& options = {}) override;
RetVal open(const UriQuery& uri) override;
RetVal isOpened(const Uri& uri) const override;
RetVal isOpened(const UriQuery& uri) const override;
async::Channel opened() const override;
void raise(const UriQuery& uri) override;
void close(const Uri& uri) override;
void close(const UriQuery& uri) override;
ValCh currentUri() const override;
std::vector stack() const override;
QWindow* topWindow() const override;
bool topWindowIsWidget() const override;
Q_INVOKABLE QString objectId(const QVariant& val) const;
Q_INVOKABLE void onOpen(const QVariant& type, const QVariant& objectId, QObject* window = nullptr);
Q_INVOKABLE void onClose(const QString& objectId, const QVariant& rv);
signals:
void fireOpen(QmlLaunchData* data);
void fireClose(QVariant data);
void fireRaise(QVariant data);
void fireOpenStandardDialog(QmlLaunchData* data);
private:
struct OpenData
{
bool sync = false;
QString objectId;
};
struct ObjectInfo
{
UriQuery uriQuery;
QVariant objectId;
QObject* window = nullptr;
};
void raiseWindowInStack(QObject* newActiveWindow);
void fillData(QmlLaunchData* data, const UriQuery& q) const;
void fillData(QObject* object, const UriQuery& q) const;
void fillStandardDialogData(QmlLaunchData* data, const QString& type, const QString& title, const framework::IInteractive::Text& text,
const framework::IInteractive::ButtonDatas& buttons, int defBtn,
const framework::IInteractive::Options& options) const;
Ret toRet(const QVariant& jsr) const;
RetVal toRetVal(const QVariant& jsrv) const;
RetVal openWidgetDialog(const UriQuery& q);
RetVal openQml(const UriQuery& q);
RetVal openStandardDialog(const QString& type, const QString& title, const framework::IInteractive::Text& text,
const framework::IInteractive::ButtonDatas& buttons,
int defBtn = int(framework::IInteractive::Button::NoButton),
const framework::IInteractive::Options& options = {});
void closeObject(const ObjectInfo& obj);
void closeQml(const QVariant& objectId);
void raiseQml(const QVariant& objectId);
std::vector allOpenObjects() const;
void notifyAboutCurrentUriChanged();
UriQuery m_openingUriQuery;
QStack m_stack;
std::vector m_floatingObjects;
async::Channel m_currentUriChanged;
QMap > m_retvals;
async::Channel m_opened;
};
}
#endif // MU_UI_INTERACTIVEPROVIDER_H