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

Allow users to reorder Format-Style menu #7997

Merged
merged 1 commit into from
Apr 28, 2021
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
107 changes: 107 additions & 0 deletions src/notation/view/widgets/editstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
*/

#include "editstyle.h"
#include "settings.h"

#include <QButtonGroup>
#include <QSignalMapper>
#include <sstream>

#include "alignSelect.h"
#include "colorlabel.h"
Expand All @@ -39,12 +41,15 @@

using namespace mu::notation;
using namespace mu::ui;
using namespace mu::framework;

static const QChar GO_NEXT_ICON = iconCodeToChar(IconCode::Code::ARROW_RIGHT);
static const QChar GO_PREV_ICON = iconCodeToChar(IconCode::Code::ARROW_LEFT);
static const QChar OPEN_FILE_ICON = iconCodeToChar(IconCode::Code::OPEN_FILE);
static const QChar RESET_ICON = iconCodeToChar(IconCode::Code::REDO);

static const Settings::Key STYLE_MENU_ORDER("notation", "ui/styleMenuOrder");

static const char* lineStyles[] = {
QT_TRANSLATE_NOOP("notation", "Continuous"),
QT_TRANSLATE_NOOP("notation", "Dashed"),
Expand Down Expand Up @@ -486,6 +491,13 @@ EditStyle::EditStyle(QWidget* parent)
tupletBracketType->addItem(tr("None", "no tuplet bracket type"), int(TupletBracketType::SHOW_NO_BRACKET));

pageList->setCurrentRow(0);

numberOfPage = pageList->count();
settings()->setDefaultValue(STYLE_MENU_ORDER, Val(ConsecutiveStr(numberOfPage)));
stringToArray(settings()->value(STYLE_MENU_ORDER).toString(), pageListMap);
pageListResetOrder();
pageStack->setCurrentIndex(pageListMap[0]);

accidentalsGroup->setVisible(false); // disable, not yet implemented

musicalSymbolFont->clear();
Expand Down Expand Up @@ -738,6 +750,10 @@ EditStyle::EditStyle(QWidget* parent)
connect(textStyles, SIGNAL(currentRowChanged(int)), SLOT(textStyleChanged(int)));
textStyles->setCurrentRow(0);

connect(pageList->model(), SIGNAL(rowsMoved(QModelIndex,int,int,QModelIndex,int)),
this, SLOT(pageListMoved(QModelIndex,int,int,QModelIndex,int)));
connect(pageList, SIGNAL(currentRowChanged(int)), this, SLOT(pageListRowChanged(int)));

adjustPagesStackSize(0);

WidgetStateStore::restoreGeometry(this);
Expand Down Expand Up @@ -1053,6 +1069,51 @@ EditStylePage EditStyle::pageForElement(Element* e)
}
}

//--------------------------------------------------------
// arrayToString
//--------------------------------------------------------

std::string EditStyle::arrayToString(int* arr)
{
std::string s;
for (int i = 0; i < numberOfPage; i++) {
s = s.append(std::to_string(arr[i]).append(","));
}
return s;
}

//--------------------------------------------------------
// stringToArray
//--------------------------------------------------------

void EditStyle::stringToArray(std::string s, int* arr)
{
size_t j = 0;
std::string n = "";
for (size_t i = 0; i < s.length(); i++) {
if (s[i] == ',') {
arr[j] = stoi(n);
j++;
n = "";
} else {
n = n + s[i];
}
}
}

//---------------------------------------------------------
// consecutiveStr
//---------------------------------------------------------

std::string EditStyle::ConsecutiveStr(int D)
{
std::string s;
for (int i = 0; i < D; i++) {
s = s.append(std::to_string(i).append(","));
}
return s;
}

//---------------------------------------------------------
// elementHasPage
/// check if the element `e` has a style page related to it
Expand Down Expand Up @@ -1088,6 +1149,51 @@ void EditStyle::setPage(int idx)
}
}

//---------------------------------------------------------
// pageListRowChanged
//---------------------------------------------------------

void EditStyle::pageListRowChanged(int row)
{
pageStack->setCurrentIndex(pageListMap[row]);
}

//---------------------------------------------------------
// pageListMoved
//---------------------------------------------------------

void EditStyle::pageListMoved(QModelIndex, int Start, int, QModelIndex, int End)
{
if (End > Start) {
int startPageIndex = pageListMap[Start];
for (int i = Start; i < (End - 1); i++) {
pageListMap[i] = pageListMap[i + 1];
}
pageListMap[End - 1] = startPageIndex;
} else {
int startPageIndex = pageListMap[Start];
for (int i = Start; i > End; i--) {
pageListMap[i] = pageListMap[i - 1];
}
pageListMap[End] = startPageIndex;
}
}

//---------------------------------------------------------
// pageListResetOrder
//---------------------------------------------------------

void EditStyle::pageListResetOrder()
{
QList<QString> originalOrder;
for (int i = 0; i < numberOfPage; i++) {
originalOrder.append(pageList->item(i)->text());
}
for (int i = 0; i < numberOfPage; i++) {
pageList->item(i)->setText(originalOrder[pageListMap[i]]);
}
}

//---------------------------------------------------------
// buttonClicked
//---------------------------------------------------------
Expand All @@ -1097,6 +1203,7 @@ void EditStyle::buttonClicked(QAbstractButton* b)
switch (buttonBox->standardButton(b)) {
case QDialogButtonBox::Ok:
accept();
settings()->setValue(STYLE_MENU_ORDER, Val(arrayToString(pageListMap)));
break;
case QDialogButtonBox::Cancel:
reject();
Expand Down
10 changes: 10 additions & 0 deletions src/notation/view/widgets/editstyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class EditStyle : public QDialog, private Ui::EditStyleBase

static EditStylePage pageForElement(Element*);

private:
int numberOfPage;
int pageListMap[50];

private slots:
void selectChordDescriptionFile();
void setChordStyle(bool);
Expand All @@ -117,6 +121,12 @@ private slots:
void editUserStyleName();
void endEditUserStyleName();
void resetUserStyleName();
void pageListRowChanged(int);
void pageListResetOrder();
void pageListMoved(QModelIndex, int, int, QModelIndex, int);
void stringToArray(std::string, int*);
std::string arrayToString(int*);
std::string ConsecutiveStr(int);

public:
EditStyle(QWidget* = nullptr);
Expand Down
27 changes: 9 additions & 18 deletions src/notation/view/widgets/editstyle.ui
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
<height>0</height>
</size>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
Expand Down Expand Up @@ -13350,22 +13359,4 @@ By default, they will be placed such as that their right end are at the same lev
<resources>
<include location="../../notationscene.qrc"/>
</resources>
<connections>
<connection>
<sender>pageList</sender>
<signal>currentRowChanged(int)</signal>
<receiver>pageStack</receiver>
<slot>setCurrentIndex(int)</slot>
<hints>
<hint type="sourcelabel">
<x>42</x>
<y>22</y>
</hint>
<hint type="destinationlabel">
<x>395</x>
<y>16</y>
</hint>
</hints>
</connection>
</connections>
fauziew marked this conversation as resolved.
Show resolved Hide resolved
</ui>