Skip to content

Commit

Permalink
Fix #315237: Don't switch tab when opening a score when a modal is open
Browse files Browse the repository at this point in the history
- Don't switch tab when opening a score when a modal is open
- Make ScoreMigrationDialog QQuickWidget, so that it gets recognized by QApplication::activeModalWidget()
- (This caused an issue that the QML content wasn't focussed when the dialog was opened, which I fixed too.)

Result:
- When you open one score, it is appended to the tab bar, and its tab is activated
- The ScoreMigrationDialog for that score is shown
- When you open a second score, it is appended to the tab bar, but its tab is not activated, because a modal dialog is open (namely the ScoreMigrationDialog for score 1)
- When you close the dialog for score 1 and then switch to score 2 's tab, the ScoreMigrationDialog is shown for score 2.
  • Loading branch information
cbjeukendrup authored and vpereverzev committed Jan 27, 2021
1 parent 0ef97b5 commit afd77df
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
4 changes: 2 additions & 2 deletions mscore/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ Score* MuseScore::openScore(const QString& fn, bool switchTab, const bool consid
QString path = fi.canonicalFilePath();
for (Score* s : scoreList) {
if (s->masterScore() && s->masterScore()->fileInfo()->canonicalFilePath() == path) {
if (switchTab)
if (switchTab && QApplication::activeModalWidget() == nullptr)
setCurrentScoreView(scoreList.indexOf(s->masterScore()));
return 0;
}
Expand Down Expand Up @@ -438,7 +438,7 @@ Score* MuseScore::openScore(const QString& fn, bool switchTab, const bool consid

if (considerInCurrentSession) {
const int tabIdx = appendScore(score);
if (switchTab)
if (switchTab && QApplication::activeModalWidget() == nullptr)
setCurrentScoreView(tabIdx);
writeSessionFile(false);
}
Expand Down
23 changes: 14 additions & 9 deletions mscore/migration/scoremigrationdialog.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
#include "scoremigrationdialog.h"

#include <QQuickItem>

ScoreMigrationDialog::ScoreMigrationDialog(QQmlEngine* engine, Ms::Score* score)
: QQuickView(engine, nullptr), m_dialogModel(new ScoreMigrationDialogModel(score, this))
: QQuickWidget(engine, nullptr), m_dialogModel(new ScoreMigrationDialogModel(score, this))
{
setMinimumWidth(600);
setMinimumHeight(m_dialogModel->isAutomaticPlacementAvailable() ? 570 : 548);

setFlags(Qt::Dialog);
setWindowFlags(Qt::Dialog);
setWindowModality(Qt::ApplicationModal);

setTitle(score->title());
setWindowTitle(score->title());
setSource(QUrl(QStringLiteral("qrc:/qml/migration/ScoreMigrationDialog.qml")));

setModality(Qt::ApplicationModal);
setResizeMode(QQuickView::SizeRootObjectToView);
setResizeMode(SizeRootObjectToView);

connect(m_dialogModel, &ScoreMigrationDialogModel::closeRequested, this, &QQuickView::close);
connect(m_dialogModel, &ScoreMigrationDialogModel::closeRequested, this, &QQuickWidget::close);

if (rootObject())
rootObject()->setProperty("model", QVariant::fromValue(m_dialogModel));
}

void ScoreMigrationDialog::focusInEvent(QFocusEvent* event)
{
QQuickView::focusInEvent(event);
QQuickWidget::focusInEvent(event);
rootObject()->forceActiveFocus();
}

void ScoreMigrationDialog::showEvent(QShowEvent* event)
{
QQuickWidget::showEvent(event);
setFocus();
rootObject()->forceActiveFocus();
}
6 changes: 2 additions & 4 deletions mscore/migration/scoremigrationdialog.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
#ifndef SCOREMIGRATIONDIALOG_H
#define SCOREMIGRATIONDIALOG_H

#include <QQuickView>
#include <QQmlEngine>

#include "scoremigrationdialogmodel.h"

class ScoreMigrationDialog : public QQuickView
class ScoreMigrationDialog : public QQuickWidget
{
Q_OBJECT

public:
explicit ScoreMigrationDialog(QQmlEngine* engine, Ms::Score *score);

private:
void showEvent(QShowEvent* event) override;
void focusInEvent(QFocusEvent* event) override;

ScoreMigrationDialogModel* m_dialogModel = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion mscore/startcenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ void Startcenter::loadScore(QString s)
newScore();
}
else {
mscore->openScore(s);
close();
mscore->openScore(s);
}
}

Expand Down

0 comments on commit afd77df

Please sign in to comment.