Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/framework/global/modularity/ioc.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ struct QmlIoCContext : public QObject

Contextable::GetContext iocCtxForQmlObject(const QObject* o);
modularity::ContextPtr iocCtxForQmlContext(const QQmlContext* c);
modularity::ContextPtr iocCtxForQWidget(const QWidget* o);
muse::Contextable::GetContext iocCtxForQWidget(const QWidget* o);
#endif
}
21 changes: 19 additions & 2 deletions src/framework/global/modularity/ioccontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,26 @@ muse::modularity::ContextPtr muse::iocCtxForQmlContext(const QQmlContext* ctx)
return qmlIoc->ctx;
}

muse::modularity::ContextPtr muse::iocCtxForQWidget(const QWidget*)
muse::Contextable::GetContext muse::iocCtxForQWidget(const QWidget* w)
{
return muse::modularity::globalCtx();
return [w]() {
IF_ASSERT_FAILED(w) {
return modularity::ContextPtr();
}

const QObject* obj = w;
while (obj) {
bool ok = false;
int ctxId = obj->property("ioc_context").toInt(&ok);
if (ok) {
return std::make_shared<modularity::Context>(ctxId);
}
obj = obj->parent();
}

UNREACHABLE;
return modularity::ContextPtr();
};
}

#endif
2 changes: 2 additions & 0 deletions src/framework/interactive/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ else()
endif()
endif()

target_link_libraries(muse_interactive PRIVATE muse::ui)

if (MUSE_QT_SUPPORT)
target_link_libraries(muse_interactive PUBLIC Qt::Core Qt::Gui Qt::Quick Qt::Widgets)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/framework/interactive/dev/testdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
using namespace muse::interactive;

TestDialog::TestDialog(QWidget* parent)
: QDialog(parent),
: muse::ui::WidgetDialog(parent),
ui(new Ui::TestDialog)
{
ui->setupUi(this);
Expand Down
6 changes: 4 additions & 2 deletions src/framework/interactive/dev/testdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@

#pragma once

#include <QDialog>
#include "ui/view/widgetdialog.h"

namespace Ui {
class TestDialog;
}

namespace muse::interactive {
class TestDialog : public QDialog
class TestDialog : public muse::ui::WidgetDialog
{
Q_OBJECT

Expand All @@ -39,6 +39,8 @@ class TestDialog : public QDialog
explicit TestDialog(QWidget* parent = nullptr);
~TestDialog() override;

void componentComplete() override {}

QString title() const;

public slots:
Expand Down
3 changes: 2 additions & 1 deletion src/framework/interactive/iinteractiveuriregister.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "modularity/imoduleinterface.h"
#include "types/uri.h"
#include "interactivetypes.h"
#include "ui/view/widgetdialog.h"

class QWidget;

Expand Down Expand Up @@ -56,7 +57,7 @@ class IInteractiveUriRegister : MODULE_GLOBAL_INTERFACE
template<typename T>
void registerWidgetUri(const Uri& uri)
{
static_assert(std::is_base_of<QWidget, T>::value, "T must derive from QWidget");
static_assert(std::is_base_of<muse::ui::WidgetDialog, T>::value, "T must derive from muse::ui::WidgetDialog");
registerUri(uri, ContainerMeta(ContainerMeta::Type::QWidgetDialog, qRegisterMetaType<T>()));
}

Expand Down
9 changes: 8 additions & 1 deletion src/framework/interactive/internal/interactive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "diagnostics/diagnosticutils.h"

#include "widgetdialogadapter.h"
#include "ui/view/widgetdialog.h"

#include "muse_framework_config.h"

Expand Down Expand Up @@ -1008,15 +1009,21 @@ RetVal<Interactive::OpenData> Interactive::openWidgetDialog(const Uri& uri, cons
QString objectId = QString("%1_%2").arg(widgetMetaTypeId).arg(++count);

QMetaType metaType = QMetaType(widgetMetaTypeId);
QDialog* dialog = static_cast<QDialog*>(metaType.create());
ui::WidgetDialog* dialog = static_cast<ui::WidgetDialog*>(metaType.create());

if (!dialog) {
result.ret = make_ret(Ret::Code::UnknownError);
return result;
}

dialog->setProperty("ioc_context", iocContext()->id);

dialog->classBegin();

fillData(dialog, params);

dialog->componentComplete();

//! NOTE Will be deleted with the dialog
WidgetDialogAdapter* adapter = new WidgetDialogAdapter(dialog);
adapter->onShow([this, objectId, dialog]() {
Expand Down
2 changes: 2 additions & 0 deletions src/framework/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ target_sources(muse_ui PRIVATE
view/widgetstatestore.cpp
view/widgetstatestore.h
view/widgetutils.h
view/widgetdialog.cpp
view/widgetdialog.h
)

if (OS_IS_MAC)
Expand Down
Empty file.
42 changes: 42 additions & 0 deletions src/framework/ui/view/widgetdialog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* SPDX-License-Identifier: GPL-3.0-only
* MuseScore-CLA-applies
*
* MuseScore
* Music Composition & Notation
*
* Copyright (C) 2026 MuseScore Limited 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/>.
*/

#pragma once

#include <QDialog>

#include "modularity/ioc.h"

namespace muse::ui {
class WidgetDialog : public QDialog, public muse::Contextable
{
Q_OBJECT

public:
explicit WidgetDialog(QWidget* parent = nullptr)
: QDialog(parent), muse::Contextable(muse::iocCtxForQWidget(this))
{}

virtual void classBegin() {}
virtual void componentComplete() {}
};
}
2 changes: 1 addition & 1 deletion src/framework/uicomponents/view/topleveldialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
using namespace muse::uicomponents;

TopLevelDialog::TopLevelDialog(QWidget* parent)
: QDialog(parent), muse::Contextable(muse::iocCtxForQWidget(this))
: muse::ui::WidgetDialog(parent)
{
setWindowFlag(Qt::WindowContextHelpButtonHint, false);

Expand Down
6 changes: 4 additions & 2 deletions src/framework/uicomponents/view/topleveldialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,22 @@

#pragma once

#include <QDialog>
#include "ui/view/widgetdialog.h"

#include "modularity/ioc.h"
#include "ui/imainwindow.h"

namespace muse::uicomponents {
class TopLevelDialog : public QDialog, public muse::Contextable
class TopLevelDialog : public muse::ui::WidgetDialog
{
public:
muse::ContextInject<ui::IMainWindow> mainWindow = { this };

public:
explicit TopLevelDialog(QWidget* parent = nullptr);

void componentComplete() override {}

protected:
bool event(QEvent* e) override;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,11 @@ void AbstractAudioWriter::doWrite(io::IODevice& dstDevice, const SoundTrackForma
};

playback()->sequenceIdList()
.onResolve(this, [this, playback, &dstDevice, format, sendProgress](const TrackSequenceIdList& sequenceIdList) {
.onResolve(this, [this, &dstDevice, format, sendProgress](const TrackSequenceIdList& sequenceIdList) {
m_progress.start();

muse::ContextInject<muse::audio::IPlayback> playback = { m_iocContext };

for (const TrackSequenceId sequenceId : sequenceIdList) {
playback()->saveSoundTrackProgressChanged(sequenceId)
.onReceive(this, [sendProgress](int64_t current, int64_t total, SaveSoundTrackStage stage) {
Expand Down
6 changes: 5 additions & 1 deletion src/notationscene/widgets/breaksdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static constexpr int DEFAULT_INTERVAL = 4;
//---------------------------------------------------------

BreaksDialog::BreaksDialog(QWidget* parent)
: QDialog(parent), muse::Contextable(muse::iocCtxForQWidget(this))
: muse::ui::WidgetDialog(parent)
{
setupUi(this);
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
Expand All @@ -53,6 +53,10 @@ BreaksDialog::BreaksDialog(QWidget* parent)
intervalLabel2->setText(part2);
}

void BreaksDialog::componentComplete()
{
}

//---------------------------------------------------------
// accept
//---------------------------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion src/notationscene/widgets/breaksdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#ifndef MU_NOTATION_BREAKSDIALOG_H
#define MU_NOTATION_BREAKSDIALOG_H

#include "ui/view/widgetdialog.h"

#include "ui_breaksdialog.h"

#include "context/iglobalcontext.h"
Expand All @@ -33,7 +35,7 @@ namespace mu::notation {
// BreaksDialog
//---------------------------------------------------------

class BreaksDialog : public QDialog, public Ui::BreaksDialog, public muse::Contextable
class BreaksDialog : public muse::ui::WidgetDialog, private Ui::BreaksDialog
{
Q_OBJECT

Expand All @@ -42,6 +44,8 @@ class BreaksDialog : public QDialog, public Ui::BreaksDialog, public muse::Conte
public:
BreaksDialog(QWidget* parent = nullptr);

void componentComplete() override;

private slots:
void accept() override;

Expand Down
15 changes: 9 additions & 6 deletions src/notationscene/widgets/editstaff.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,13 @@ static const QChar GO_DOWN_ICON = iconCodeToChar(IconCode::Code::ARROW_DOWN);
static const QChar EDIT_ICON = iconCodeToChar(IconCode::Code::EDIT);

EditStaff::EditStaff(QWidget* parent)
: QDialog(parent), muse::Contextable(muse::iocCtxForQWidget(this))
: muse::ui::WidgetDialog(parent)
{
setObjectName("EditStaff");
setupUi(this);
setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
setModal(true);

initStaff();

editStaffTypeDialog = new EditStaffType(this);
editStaffTypeDialog->setWindowModality(Qt::WindowModal);

connect(buttonBox, &QDialogButtonBox::clicked, this, &EditStaff::bboxClicked);
connect(changeInstrument, &QPushButton::clicked, this, &EditStaff::showReplaceInstrumentDialog);
connect(changeStaffType, &QPushButton::clicked, this, &EditStaff::showStaffTypeDialog);
Expand Down Expand Up @@ -108,6 +103,14 @@ EditStaff::EditStaff(QWidget* parent)
setFocus();
}

void EditStaff::componentComplete()
{
editStaffTypeDialog = new EditStaffType(iocContext(), this);
editStaffTypeDialog->setWindowModality(Qt::WindowModal);

initStaff();
}

void EditStaff::setStaff(Staff* s, const Fraction& tick)
{
if (m_staff != nullptr) {
Expand Down
5 changes: 3 additions & 2 deletions src/notationscene/widgets/editstaff.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#pragma once

#include <QDialog>
#include "ui/view/widgetdialog.h"

#include "ui_editstaff.h"
#include "engraving/dom/stafftype.h"
Expand All @@ -37,7 +37,7 @@
namespace mu::notation {
class EditStaffType;

class EditStaff : public QDialog, private Ui::EditStaffBase, public muse::Contextable, public muse::async::Asyncable
class EditStaff : public muse::ui::WidgetDialog, private Ui::EditStaffBase, public muse::async::Asyncable
{
Q_OBJECT

Expand All @@ -49,6 +49,7 @@ class EditStaff : public QDialog, private Ui::EditStaffBase, public muse::Contex
EditStaff(QWidget* parent = nullptr);

private:
void componentComplete() override;
void showEvent(QShowEvent*) override;
void hideEvent(QHideEvent*) override;
void apply();
Expand Down
4 changes: 2 additions & 2 deletions src/notationscene/widgets/editstafftype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ mu::engraving::NoteHeadScheme noteHeadSchemes[] = {
// EditStaffType
//---------------------------------------------------------

EditStaffType::EditStaffType(QWidget* parent)
: QDialog(parent), muse::Contextable(muse::iocCtxForQWidget(this))
EditStaffType::EditStaffType(const muse::modularity::ContextPtr& ctx, QWidget* parent)
: QDialog(parent), muse::Contextable(ctx)
{
setObjectName("EditStaffType");
setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
Expand Down
2 changes: 1 addition & 1 deletion src/notationscene/widgets/editstafftype.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private slots:
void addToTemplatesClicked();

public:
EditStaffType(QWidget* parent = nullptr);
EditStaffType(const muse::modularity::ContextPtr& ctx, QWidget* parent = nullptr);
~EditStaffType() {}
void setStaffType(const mu::engraving::StaffType* staffType);
mu::engraving::StaffType getStaffType() const { return staffType; }
Expand Down
9 changes: 6 additions & 3 deletions src/notationscene/widgets/editstringdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ using namespace muse::ui;
//---------------------------------------------------------

EditStringData::EditStringData(QWidget* parent, const std::vector<instrString>& strings, int frets)
: QDialog(parent), muse::Contextable(muse::iocCtxForQWidget(this))
: muse::ui::WidgetDialog(parent)
{
setObjectName("EditStringData");
setupUi(this);
Expand All @@ -58,6 +58,11 @@ EditStringData::EditStringData(QWidget* parent, const std::vector<instrString>&
_strings = strings;
_frets = frets;

qApp->installEventFilter(this);
}

void EditStringData::componentComplete()
{
if (_strings.empty()) {
initStringsData();
}
Expand All @@ -66,8 +71,6 @@ EditStringData::EditStringData(QWidget* parent, const std::vector<instrString>&

//! NOTE: It is necessary for the correct start of navigation in the dialog
setFocus();

qApp->installEventFilter(this);
}

std::vector<instrString> EditStringData::strings() const
Expand Down
Loading
Loading