Skip to content

Commit

Permalink
Merge pull request musescore#10837 from Eism/tooltips_open_fix
Browse files Browse the repository at this point in the history
[MU4] Tooltips open fix
  • Loading branch information
RomanPudashkin committed Mar 23, 2022
2 parents e58dc23 + 0a5c274 commit a4c9b9f
Show file tree
Hide file tree
Showing 15 changed files with 217 additions and 373 deletions.
71 changes: 1 addition & 70 deletions src/appshell/qml/DevTools/Gallery/GeneralComponentsGallery.qml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ Rectangle {

model: [
{ textRole: "Dropdown", componentRole: dropdownSample },
{ textRole: "StyledPopup", componentRole: popupSample },
{ textRole: "StyledPopupView", componentRole: styledPopupViewComponent },
{ textRole: "StyledPopup", componentRole: styledPopupViewComponent },
{ textRole: "StyledMenu", componentRole: styledMenuComponent },
{ textRole: "StyledMenuScrollable", componentRole: styledScrollableMenuComponent },
{ textRole: "CheckBox", componentRole: checkBoxSample },
Expand Down Expand Up @@ -162,74 +161,6 @@ Rectangle {
}
}

Component {
id: popupSample

Row {
spacing: 12

FlatButton {
id: popupDownButton

text: "Show Popup downward"

onClicked: {
if (popupDown.opened) {
popupDown.close()
} else {
popupDown.open()
}
}
}

StyledPopup {
id: popupDown

width: 200
height: 200

anchorItem: popupDownButton

StyledTextLabel {
text: "Hello, World!"

anchors.centerIn: parent
}
}

FlatButton {
id: popupUpButton

text: "Show Popup upward"

onClicked: {
if (popupUp.opened) {
popupUp.close()
} else {
popupUp.open()
}
}
}

StyledPopup {
id: popupUp

width: 200
height: 200

anchorItem: popupUpButton

opensUpward: true

StyledTextLabel {
text: "Hello, World!"

anchors.centerIn: parent
}
}
}
}

Component {
id: styledPopupViewComponent

Expand Down
183 changes: 0 additions & 183 deletions src/framework/uicomponents/qml/MuseScore/UiComponents/StyledPopup.qml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ StyledPopupView {
padding: 8
margins: 8

x: (root.parent.width / 2) - ((content.width + padding * 2 + margins * 2) / 2)
y: root.parent.height

contentWidth: Math.min(content.width, 300 - margins * 2)
contentHeight: content.height

openPolicy: PopupView.NoActivateFocus

Column {
id: content

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ RadioButtonGroup 1.0 RadioButtonGroup.qml
SeparatorLine 1.0 SeparatorLine.qml
Dropdown 1.0 Dropdown.qml
Icon 1.0 Icon.qml
StyledPopup 1.0 StyledPopup.qml
TextInputField 1.0 TextInputField.qml
ValueAdjustControl 1.0 ValueAdjustControl.qml
RoundedRectangle 1.0 RoundedRectangle.qml
Expand Down
1 change: 0 additions & 1 deletion src/framework/uicomponents/uicomponents.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<file>qml/MuseScore/UiComponents/RadioButtonGroup.qml</file>
<file>qml/MuseScore/UiComponents/TextInputField.qml</file>
<file>qml/MuseScore/UiComponents/ValueAdjustControl.qml</file>
<file>qml/MuseScore/UiComponents/StyledPopup.qml</file>
<file>qml/MuseScore/UiComponents/Icon.qml</file>
<file>qml/MuseScore/UiComponents/SeparatorLine.qml</file>
<file>qml/MuseScore/UiComponents/FlatRadioButton.qml</file>
Expand Down
17 changes: 16 additions & 1 deletion src/framework/uicomponents/view/popupview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void PopupView::open()
m_window->setResizable(m_resizable);
}

m_window->show(m_globalPos.toPoint());
m_window->show(m_globalPos.toPoint(), m_openPolicy != OpenPolicy::NoActivateFocus);

m_globalPos = QPointF(); // invalidate

Expand Down Expand Up @@ -235,6 +235,11 @@ bool PopupView::isOpened() const
return m_window ? m_window->isVisible() : false;
}

PopupView::OpenPolicy PopupView::openPolicy() const
{
return m_openPolicy;
}

PopupView::ClosePolicy PopupView::closePolicy() const
{
return m_closePolicy;
Expand Down Expand Up @@ -314,6 +319,16 @@ void PopupView::setLocalY(qreal y)
repositionWindowIfNeed();
}

void PopupView::setOpenPolicy(PopupView::OpenPolicy openPolicy)
{
if (m_openPolicy == openPolicy) {
return;
}

m_openPolicy = openPolicy;
emit openPolicyChanged(m_openPolicy);
}

void PopupView::repositionWindowIfNeed()
{
if (isOpened() && !isDialog()) {
Expand Down
12 changes: 12 additions & 0 deletions src/framework/uicomponents/view/popupview.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class PopupView : public QObject, public QQmlParserStatus
Q_PROPERTY(Qt::AlignmentFlag cascadeAlign READ cascadeAlign WRITE setCascadeAlign NOTIFY cascadeAlignChanged)

Q_PROPERTY(bool isOpened READ isOpened NOTIFY isOpenedChanged)
Q_PROPERTY(OpenPolicy openPolicy READ openPolicy WRITE setOpenPolicy NOTIFY openPolicyChanged)
Q_PROPERTY(ClosePolicy closePolicy READ closePolicy WRITE setClosePolicy NOTIFY closePolicyChanged)

//! NOTE We use QObject (instead ui::NavigationControl) for avoid add UI module dependency at link time.
Expand All @@ -80,6 +81,7 @@ class PopupView : public QObject, public QQmlParserStatus
Q_PROPERTY(bool resizable READ resizable WRITE setResizable NOTIFY resizableChanged)
Q_PROPERTY(QVariantMap ret READ ret WRITE setRet NOTIFY retChanged)

Q_ENUMS(OpenPolicy)
Q_ENUMS(ClosePolicy)

INJECT(uicomponents, ui::IMainWindow, mainWindow)
Expand All @@ -91,6 +93,11 @@ class PopupView : public QObject, public QQmlParserStatus
explicit PopupView(QQuickItem* parent = nullptr);
~PopupView() override = default;

enum OpenPolicy {
Default = 0,
NoActivateFocus
};

enum ClosePolicy {
NoAutoClose = 0,
CloseOnPressOutsideParent
Expand All @@ -113,7 +120,9 @@ class PopupView : public QObject, public QQmlParserStatus

Q_INVOKABLE void setParentWindow(QWindow* window);

OpenPolicy openPolicy() const;
ClosePolicy closePolicy() const;

QObject* navigationParentControl() const;

bool isOpened() const;
Expand Down Expand Up @@ -142,6 +151,7 @@ public slots:
void setContentItem(QQuickItem* content);
void setLocalX(qreal x);
void setLocalY(qreal y);
void setOpenPolicy(OpenPolicy openPolicy);
void setClosePolicy(ClosePolicy closePolicy);
void setNavigationParentControl(QObject* parentNavigationControl);
void setObjectId(QString objectId);
Expand All @@ -163,6 +173,7 @@ public slots:
void windowChanged();
void xChanged(qreal x);
void yChanged(qreal y);
void openPolicyChanged(OpenPolicy openPolicy);
void closePolicyChanged(ClosePolicy closePolicy);
void navigationParentControlChanged(QObject* navigationParentControl);
void objectIdChanged(QString objectId);
Expand Down Expand Up @@ -226,6 +237,7 @@ private slots:

QPointF m_localPos;
QPointF m_globalPos;
OpenPolicy m_openPolicy = OpenPolicy::Default;
ClosePolicy m_closePolicy = ClosePolicy::CloseOnPressOutsideParent;
QObject* m_navigationParentControl = nullptr;
QString m_objectId;
Expand Down

0 comments on commit a4c9b9f

Please sign in to comment.