MuseScore/src/framework/ui/dev/interactivetestsmodel.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

175 lines
6 KiB
C++
Raw Normal View History

/*
* 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 <https://www.gnu.org/licenses/>.
*/
2020-07-30 18:07:01 +02:00
#include "interactivetestsmodel.h"
2021-05-07 19:41:49 +02:00
#include <QTimer>
#include "log.h"
2021-05-07 16:24:29 +02:00
#include "async/async.h"
2021-05-14 10:27:10 +02:00
#include <QAccessible>
2021-01-18 08:15:02 +01:00
using namespace mu::ui;
using namespace mu::framework;
2020-07-30 18:07:01 +02:00
InteractiveTestsModel::InteractiveTestsModel(QObject* parent)
: QObject(parent)
{
2020-07-30 17:50:55 +02:00
ValCh<Uri> uri = interactive()->currentUri();
2020-06-26 14:56:49 +02:00
setCurrentUri(uri.val);
uri.ch.onReceive(this, [this](const Uri& uri) {
setCurrentUri(uri);
});
}
2020-07-30 18:07:01 +02:00
void InteractiveTestsModel::openSampleDialog()
{
LOGI() << "cpp: before open";
RetVal<Val> rv = interactive()->open("musescore://devtools/interactive/sample?color=#474747");
2020-06-26 14:56:49 +02:00
LOGI() << "cpp: after open ret: " << rv.ret.toString() << ", val: " << rv.val.toString();
}
void InteractiveTestsModel::openSampleDialogAsync()
{
2020-06-26 15:09:20 +02:00
LOGI() << "cpp: before open ";
RetVal<Val> rv = interactive()->open("musescore://devtools/interactive/sample?sync=false&color=#D24373");
2020-06-26 14:56:49 +02:00
LOGI() << "cpp: after open ret: " << rv.ret.toString() << ", val: " << rv.val.toString();
}
void InteractiveTestsModel::closeSampleDialog()
{
LOGI() << "cpp: before close ";
interactive()->close("musescore://devtools/interactive/sample");
LOGI() << "cpp: after close";
}
2020-07-30 18:07:01 +02:00
void InteractiveTestsModel::openWidgetDialog()
2020-07-20 20:07:29 +02:00
{
LOGI() << "cpp: before open ";
RetVal<Val> rv = interactive()->open("musescore://devtools/interactive/testdialog?title='And from its properties'");
2020-07-20 20:07:29 +02:00
LOGI() << "cpp: after open ret: " << rv.ret.toString() << ", val: " << rv.val.toString();
}
void InteractiveTestsModel::openWidgetDialogAsync()
2020-07-25 11:43:37 +02:00
{
LOGI() << "cpp: before open ";
RetVal<Val> rv = interactive()->open("musescore://devtools/interactive/testdialog?sync=false&title='And from its properties'");
2020-07-25 11:43:37 +02:00
LOGI() << "cpp: after open ret: " << rv.ret.toString() << ", val: " << rv.val.toString();
}
void InteractiveTestsModel::closeWidgetDialog()
{
LOGI() << "cpp: before close ";
interactive()->close("musescore://devtools/interactive/testdialog");
LOGI() << "cpp: after close";
}
2020-07-30 18:07:01 +02:00
void InteractiveTestsModel::setCurrentUri(const Uri& uri)
2020-06-26 14:56:49 +02:00
{
m_currentUri = QString::fromStdString(uri.toString());
emit currentUriChanged(m_currentUri);
}
2020-07-30 18:07:01 +02:00
QString InteractiveTestsModel::currentUri() const
2020-06-26 14:56:49 +02:00
{
return m_currentUri;
}
2020-06-26 17:20:49 +02:00
2020-07-30 18:07:01 +02:00
void InteractiveTestsModel::question()
2020-06-26 17:20:49 +02:00
{
2021-05-24 16:07:46 +02:00
IInteractive::Result result = interactive()->question(
"Do you really want to delete the 'xxx' workspace?", "",
{ interactive()->buttonData(IInteractive::Button::No),
interactive()->buttonData(IInteractive::Button::Yes) }, 0,
IInteractive::Option::WithIcon);
2020-06-26 17:20:49 +02:00
if (result.standardButton() == IInteractive::Button::Yes) {
2020-06-26 17:20:49 +02:00
LOGI() << "Yes!!";
} else {
2020-06-29 11:09:49 +02:00
LOGI() << "No!!";
2020-06-26 17:20:49 +02:00
}
}
2020-07-30 18:07:01 +02:00
void InteractiveTestsModel::customQuestion()
2020-06-26 17:20:49 +02:00
{
int maybeBtn = int(IInteractive::Button::CustomButton) + 1;
2021-05-21 10:50:23 +02:00
IInteractive::Result result = interactive()->question("Test", "It works?", {
2020-06-26 17:20:49 +02:00
IInteractive::ButtonData(maybeBtn, "Maybe"),
interactive()->buttonData(IInteractive::Button::No)
});
2021-05-21 10:50:23 +02:00
if (result.button() == maybeBtn) {
2020-06-26 17:20:49 +02:00
LOGI() << "Maybe!!";
} else {
LOGE() << "No!!";
}
}
2020-07-30 18:07:01 +02:00
void InteractiveTestsModel::information()
{
2021-05-24 16:07:46 +02:00
IInteractive::Result result = interactive()->info("Tuplet cannot cross barlines", "", {}, 0,
IInteractive::Option::WithIcon | IInteractive::Option::WithShowAgain);
LOGD() << interactive()->buttonData(result.standardButton()).text;
}
2020-07-30 18:07:01 +02:00
void InteractiveTestsModel::warning()
{
2021-05-24 16:07:46 +02:00
int noSaveButton = int(IInteractive::Button::CustomButton) + 1;
int saveButton = noSaveButton + 1;
IInteractive::Result result = interactive()->warning("Do you want to save changes to the score “Untitled” before closing?",
"Your changes will be lost if you dont save them.",
{ IInteractive::ButtonData(noSaveButton, "Dont save"),
interactive()->buttonData(IInteractive::Button::Cancel),
IInteractive::ButtonData(saveButton, "Save", true) }, saveButton,
IInteractive::Option::WithIcon);
if (result.button() == noSaveButton) {
LOGI() << "Dont save!!";
} else if (result.button() == saveButton) {
LOGE() << "Save!!";
} else {
LOGE() << "Cancel!!";
}
}
2020-07-30 18:07:01 +02:00
void InteractiveTestsModel::critical()
{
2021-05-24 16:07:46 +02:00
IInteractive::Result result = interactive()->error("Cannot read file C:/Users/Username/Desktop/Composition.mscz",
"An error has occured when trying to open this file", {}, 0,
IInteractive::Option::WithIcon);
LOGD() << interactive()->buttonData(result.standardButton()).text;
2020-06-29 11:09:49 +02:00
}
2020-07-30 18:07:01 +02:00
void InteractiveTestsModel::require()
2020-06-29 11:09:49 +02:00
{
RetVal<Val> rv = interactive()->open("musescore://devtools/interactive/sample?title='Test'");
2020-06-29 11:09:49 +02:00
if (rv.ret) {
LOGI() << "received: " << rv.val.toString();
} else if (check_ret(rv.ret, Ret::Code::Cancel)) {
LOGI() << "was cancelled";
} else {
LOGE() << "some error: " << rv.ret.code();
}
}