Skip to content

Commit

Permalink
Allow user to reorder Format-Style menu
Browse files Browse the repository at this point in the history
  • Loading branch information
fauziew committed Apr 24, 2021
1 parent 983c9a5 commit 196433d
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 35 deletions.
106 changes: 106 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,9 @@ 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 +1068,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 +1148,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 +1202,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
60 changes: 25 additions & 35 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 @@ -226,7 +235,7 @@
</widget>
<widget class="QStackedWidget" name="pageStack">
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<widget class="QWidget" name="PageScore">
<layout class="QVBoxLayout" name="verticalLayout_20">
Expand Down Expand Up @@ -264,8 +273,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>623</width>
<height>696</height>
<width>697</width>
<height>570</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
Expand Down Expand Up @@ -854,8 +863,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>634</width>
<height>674</height>
<width>697</width>
<height>630</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_4">
Expand Down Expand Up @@ -2256,8 +2265,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>738</width>
<height>392</height>
<width>735</width>
<height>551</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
Expand Down Expand Up @@ -3944,8 +3953,8 @@ By default, they will be placed such as that their right end are at the same lev
<rect>
<x>0</x>
<y>0</y>
<width>422</width>
<height>900</height>
<width>433</width>
<height>680</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_56">
Expand Down Expand Up @@ -6131,8 +6140,8 @@ By default, they will be placed such as that their right end are at the same lev
<rect>
<x>0</x>
<y>0</y>
<width>572</width>
<height>527</height>
<width>544</width>
<height>496</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_54">
Expand Down Expand Up @@ -9889,8 +9898,8 @@ By default, they will be placed such as that their right end are at the same lev
<rect>
<x>0</x>
<y>0</y>
<width>584</width>
<height>465</height>
<width>583</width>
<height>420</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_57">
Expand Down Expand Up @@ -11289,7 +11298,7 @@ By default, they will be placed such as that their right end are at the same lev
<rect>
<x>0</x>
<y>0</y>
<width>574</width>
<width>601</width>
<height>551</height>
</rect>
</property>
Expand Down Expand Up @@ -13347,25 +13356,6 @@ By default, they will be placed such as that their right end are at the same lev
<tabstop>buttonTogglePagelist</tabstop>
<tabstop>resetStylesButton</tabstop>
</tabstops>
<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>
<resources/>
<connections/>
</ui>

0 comments on commit 196433d

Please sign in to comment.