Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #16077 part 2: Double click a header/footer to open the corresponding menu #5887

Merged
merged 1 commit into from
Apr 29, 2020

Conversation

SKefalidis
Copy link
Contributor

@SKefalidis SKefalidis commented Mar 29, 2020

Resolves: https://musescore.org/en/node/16077

Related PR: #5886

Added the ability to double click a header/footer to go their menu (dialog).

First of all, to be able to double click you need to be able to select. Headers/footers were not selectable because they were not in Page->items, which means that they were not in the bspTree. Adding them to the bspTree causes graphical glitches and it requires extensive workarounds to bypass the constness of Page::draw. That's why they are added manually in ScoreView::elementsNear.

After giving them the ability to be selected, they need to be non-editable, which means setting their flag to generated and disabling their inspector. Editing them via the inspector causes more graphical glitches and makes the logic in ScoreView::mouseDoubleClickEvent more complex. If we want the ability to edit them via the inspector, more extensive changes have to be made.

Edited for the latest push: I changed the way headers/footers are stored in the program to enable the ability to click any one of the 3 headers/footers to go to the dialog. While doing that I changed the pointer initialization to nullptr and converted some things to the new representation (which uses vectors).

  • I signed CLA
  • I made sure the code in the PR follows the coding rules
  • I made sure the code compiles on my machine
  • I made sure there are no unnecessary changes in the code
  • I made sure the title of the PR reflects the core meaning of the issue you are solving
  • I made sure the commit message(s) contain a description and answer the question "Why do those changes fix that particular issue?" or "Why are those changes really necessary as improvements?"
  • I made sure the commit message title starts with "fix #424242:" if there is a related issue
  • [n\a] I created the test (mtest, vtest, script test) to verify the changes I made

@@ -735,6 +735,7 @@ const std::map<ElementType, EditStylePage> EditStyle::PAGES = {
{ ElementType::FIGURED_BASS, &EditStyle::PageFiguredBass },
{ ElementType::HARMONY, &EditStyle::PageChordSymbols },
{ ElementType::FRET_DIAGRAM, &EditStyle::PageFretboardDiagrams },
{ ElementType::TEXT, &EditStyle::PageHeaderFooter }, // gotoElement if the element is Text leads to the footer dialog
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this also catch other text elements?

Copy link
Contributor Author

@SKefalidis SKefalidis Mar 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will, as I explained in the original message. It does not cause an immediate problem. In the future, it might, but adding friends is also a problem and this is very elegant (if I may so myself) because it does not change much but acomplishes it's goal. In my opinion headers/footers need to be reworked.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear, this adds "Style..." to the context menu for every text element, and all of them go to the Header/Footer page.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, I hadn't seen that connection. I'll change this then.

Copy link
Contributor Author

@SKefalidis SKefalidis Mar 29, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IsaacWeiss I can think of 3 solutions. Either through 'friend' (like the PR mentioned in the op) or by hardcoding the value of the page and having a unit test to check if the value is correct. I could also create a special 'gotoFooterHeader' for this case.

cout << "success" << endl;
}
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation style

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SKefalidis unaddressed comment ^

return;
else if (!clickedElement->isEditable()) {
if (clickedElement->isText()
&& (static_cast<Text*>(clickedElement)->tid() == Tid::FOOTER || static_cast<Text*>(clickedElement)->tid() == Tid::HEADER)) { // double-click an instrument name to open the edit staff/part properties menu
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use toText(clickedElement) as a shortcut for the static_cast

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

if (clickedElement->isText()
&& (static_cast<Text*>(clickedElement)->tid() == Tid::FOOTER || static_cast<Text*>(clickedElement)->tid() == Tid::HEADER)) { // double-click an instrument name to open the edit staff/part properties menu
elementPropertyAction("style", clickedElement);
cout << "success" << endl;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugging artifact?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, this one got away, will fix that.

@@ -4727,6 +4727,10 @@ QList<Element*> ScoreView::elementsNear(QPointF p)
QRectF r(p.x() - w, p.y() - w, 3.0 * w, 3.0 * w);

QList<Element*> el = page->items(r);
if(score()->headerText() != nullptr) // gives the ability to select the header
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after if

@SKefalidis
Copy link
Contributor Author

Fixed formatting.

@SKefalidis SKefalidis force-pushed the dc-footer branch 2 times, most recently from de8bf75 to 18e458d Compare March 29, 2020 19:22
@SKefalidis
Copy link
Contributor Author

Everything should be in order now.

headerText()->styleChanged();
if (footerText())
footerText()->styleChanged();
for(int i = 0; i < 3; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after for

headerText()->styleChanged();
if (footerText())
footerText()->styleChanged();
for(int i = 0; i < 3; i++) {
Copy link
Contributor

@igorkorsukov igorkorsukov Apr 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here you need to add a comment what is 3

Text* _headerText { 0 };
Text* _footerText { 0 };
vector<Text*> _headersText { nullptr, nullptr, nullptr };
vector<Text*> _footersText { nullptr, nullptr, nullptr };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add std before vector (std::vector)

Text* _headerText { 0 };
Text* _footerText { 0 };
vector<Text*> _headersText { nullptr, nullptr, nullptr };
vector<Text*> _footersText { nullptr, nullptr, nullptr };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here you need to add a comment why three

return;
else if (!clickedElement->isEditable()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need for else

if (!clickedElement)
    return;

if (!clickedElement->isEditable()) {
    ...
    return
}

...

ie = new InspectorText(this);
if (element()->isText()) {
// don't allow footers/headers to be edited via the inspector
if(toText(element())->tid() != Tid::FOOTER && toText(element())->tid() != Tid::HEADER)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space after if

@@ -4727,6 +4727,12 @@ QList<Element*> ScoreView::elementsNear(QPointF p)
QRectF r(p.x() - w, p.y() - w, 3.0 * w, 3.0 * w);

QList<Element*> el = page->items(r);
for(int i = 0; i < 3; i++) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here you need to add a comment what is 3
I think it's even better to add a constant (mscore.h), since it is used in several places.
The name of the constant will show what it is and where it is used.

@SKefalidis SKefalidis force-pushed the dc-footer branch 2 times, most recently from 9d7f417 to 79fd942 Compare April 17, 2020 10:28
@SKefalidis
Copy link
Contributor Author

Updated as advised by @igorkorsukov

}
}
else {
text = score()->footerText();
text = score()->footerText(area - 3); // because they are 3 4 5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it better to replace area - 3 with area - MAX_FOOTERS?

cout << "success" << endl;
}
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SKefalidis unaddressed comment ^

@anatoly-os
Copy link
Contributor

@SKefalidis two comments remain unaddressed and rebase is needed.

@SKefalidis
Copy link
Contributor Author

@anatoly-os Rebase completed, suggestions incorporated.

@anatoly-os anatoly-os merged commit 81662a2 into musescore:master Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants