Skip to content

Commit 5789400

Browse files
authored
Merge pull request #29284 from cbjeukendrup/textstylepopup/when
2 parents 46b0913 + a6d253c commit 5789400

File tree

5 files changed

+63
-11
lines changed

5 files changed

+63
-11
lines changed

src/notation/qml/MuseScore/NotationScene/NotationView.qml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,14 @@ FocusScope {
159159
}
160160

161161
onShowElementPopupRequested: function (popupType, elementRect) {
162-
Qt.callLater(popUpLoader.show, popupType, elementRect)
162+
popUpLoader.openProperties = {
163+
popupType: popupType,
164+
elementRect: elementRect
165+
};
163166
}
164167

165168
onHideElementPopupRequested: {
166-
Qt.callLater(popUpLoader.close)
169+
popUpLoader.openProperties = null;
167170
}
168171

169172
onViewportChanged: {
@@ -187,6 +190,26 @@ FocusScope {
187190
notationViewNavigationSection: navSec
188191
navigationOrderStart: notationView.navigationPanel.order + 1
189192

193+
property var openProperties: null
194+
property bool updateShowScheduled: false
195+
196+
onOpenPropertiesChanged: {
197+
if (!updateShowScheduled) {
198+
Qt.callLater(updateShow)
199+
updateShowScheduled = true;
200+
}
201+
}
202+
203+
function updateShow() {
204+
if (openProperties) {
205+
show(openProperties.popupType, openProperties.elementRect);
206+
} else {
207+
close();
208+
}
209+
210+
popUpLoader.updateShowScheduled = false;
211+
}
212+
190213
onOpened: function(popupType) {
191214
paintView.onElementPopupIsOpenChanged(popupType)
192215
}

src/notation/view/abstractnotationpaintview.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ void AbstractNotationPaintView::showElementPopup(const ElementType& elementType,
574574
return;
575575
}
576576

577+
m_currentElementPopupType = modelType;
577578
emit showElementPopupRequested(modelType, fromLogical(elementRect).toQRectF());
578579
}
579580

@@ -589,6 +590,7 @@ void AbstractNotationPaintView::hideElementPopup(const ElementType& elementType)
589590
const PopupModelType modelType = AbstractElementPopupModel::modelTypeFromElement(elementType);
590591
// Hide the popup if the model type matches the currently open model type, or if no element type was specified...
591592
if (modelType == m_currentElementPopupType || elementType == ElementType::INVALID) {
593+
m_currentElementPopupType = PopupModelType::TYPE_UNDEFINED;
592594
emit hideElementPopupRequested();
593595
}
594596
}

src/notation/view/notationviewinputcontroller.cpp

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -152,22 +152,39 @@ void NotationViewInputController::onNotationChanged()
152152
}
153153
});
154154

155-
currNotation->interaction()->textEditingChanged().onNotify(this, [this]() {
155+
currNotation->interaction()->textEditingStarted().onNotify(this, [this] {
156156
const INotationPtr notation = currentNotation();
157157
if (!notation) {
158158
return;
159159
}
160160

161-
if (notation->interaction()->isTextEditingStarted()) {
162-
const TextBase* item = notation->interaction()->editedText();
163-
if (AbstractElementPopupModel::hasTextStylePopup(item)
164-
&& item->cursor()->hasSelection()) {
165-
m_view->showElementPopup(item->type(), item->canvasBoundingRect());
166-
return;
167-
}
161+
m_view->hideContextMenu();
162+
m_view->hideElementPopup();
163+
164+
const TextBase* item = notation->interaction()->editedText();
165+
if (AbstractElementPopupModel::hasTextStylePopup(item)
166+
&& (!item->isLyrics() || !item->empty())) {
167+
m_view->showElementPopup(item->type(), item->canvasBoundingRect());
168168
}
169+
});
169170

170-
m_view->hideContextMenu();
171+
currNotation->interaction()->textEditingChanged().onNotify(this, [this] {
172+
const INotationPtr notation = currentNotation();
173+
if (!notation) {
174+
return;
175+
}
176+
177+
if (!notation->interaction()->isTextEditingStarted()) {
178+
return;
179+
}
180+
181+
const TextBase* item = notation->interaction()->editedText();
182+
if (AbstractElementPopupModel::hasTextStylePopup(item) && item->cursor()->hasSelection()) {
183+
m_view->showElementPopup(item->type(), item->canvasBoundingRect());
184+
}
185+
});
186+
187+
currNotation->interaction()->textEditingEnded().onReceive(this, [this](const TextBase*) {
171188
m_view->hideElementPopup();
172189
});
173190
}
@@ -933,6 +950,13 @@ void NotationViewInputController::updateTextCursorPosition()
933950
{
934951
if (viewInteraction()->isTextEditingStarted()) {
935952
viewInteraction()->changeTextCursorPosition(m_mouseDownInfo.logicalBeginPoint);
953+
954+
// Show text style popup
955+
const TextBase* item = viewInteraction()->editedText();
956+
if (AbstractElementPopupModel::hasTextStylePopup(item)
957+
&& (!item->isLyrics() || !item->empty())) {
958+
m_view->showElementPopup(item->type(), item->canvasBoundingRect());
959+
}
936960
}
937961
}
938962

src/palette/view/widgets/palettewidget.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ void PaletteWidget::applyElementAtIndex(int index, Qt::KeyboardModifiers modifie
457457
}
458458

459459
notation->interaction()->applyPaletteElement(cell->element.get(), modifiers);
460+
mainWindow()->qWindow()->requestActivate();
460461
}
461462

462463
// ====================================================

src/palette/view/widgets/palettewidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include "modularity/ioc.h"
3535
#include "../../ipaletteconfiguration.h"
36+
#include "ui/imainwindow.h"
3637
#include "ui/iuiactionsregister.h"
3738
#include "ui/iuiconfiguration.h"
3839
#include "context/iglobalcontext.h"
@@ -75,6 +76,7 @@ class PaletteWidget : public QWidget, public muse::async::Asyncable
7576
INJECT_STATIC(engraving::rendering::ISingleRenderer, engravingRender)
7677
INJECT(muse::IInteractive, interactive)
7778
INJECT(muse::ui::IUiConfiguration, uiConfiguration)
79+
muse::Inject<muse::ui::IMainWindow> mainWindow;
7880

7981
public:
8082
PaletteWidget(QWidget* parent = nullptr);

0 commit comments

Comments
 (0)