Skip to content

Commit

Permalink
palette shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
divya-urs committed Nov 30, 2017
1 parent e356a89 commit eec3df6
Show file tree
Hide file tree
Showing 20 changed files with 1,106 additions and 16 deletions.
4 changes: 2 additions & 2 deletions mscore/CMakeLists.txt
Expand Up @@ -29,8 +29,8 @@ include_directories(
)

if (SCRIPT_INTERFACE)
set (SCRIPT_FILES mscorePlugins pluginCreator.cpp qmledit.cpp pluginManager.cpp)
set (SCRIPT_UI pluginCreator.ui pluginManager.ui)
set (SCRIPT_FILES mscorePlugins pluginCreator.cpp qmledit.cpp pluginManager.cpp paletteShortcutManager.cpp)
set (SCRIPT_UI pluginCreator.ui pluginManager.ui paletteShortcutManager.ui)
endif (SCRIPT_INTERFACE)

QT5_WRAP_UI (ui_headers
Expand Down
63 changes: 61 additions & 2 deletions mscore/menus.cpp
Expand Up @@ -1544,7 +1544,13 @@ Palette* MuseScore::newFretboardDiagramPalette()

void MuseScore::setAdvancedPalette()
{
mscore->getPaletteBox();
bool empty = true;
QList<Shortcut> shortcuts; // stores advanced workspace shortcuts
if (!preferences.paletteCellListAdv.isEmpty())
empty = false;
for (PaletteCellDescription d : preferences.paletteCellListAdv) {
shortcuts.append(d.cell->shortcut);
}
paletteBox->clear();
paletteBox->addPalette(newClefsPalette(PaletteType::ADVANCED));
paletteBox->addPalette(newKeySigPalette(PaletteType::ADVANCED));
Expand All @@ -1571,6 +1577,31 @@ void MuseScore::setAdvancedPalette()
paletteBox->addPalette(newBreaksPalette());
paletteBox->addPalette(newFramePalette());
paletteBox->addPalette(newBeamPalette(PaletteType::ADVANCED));
// set shortcuts in new palettes
QList<PaletteCell*> cells;
for (Palette* p : paletteBox->palettes()) {
for (PaletteCell* cell : p->getCells()) {
cells.append(cell);
}
}
preferences.paletteCellList.clear();
for (int i = 0; i < shortcuts.size(); i++) {
PaletteCell* cell = cells[i];
if (cell->name == "Show More") {
continue;
}
if (!empty)
cell->shortcut = shortcuts[i];
int s = preferences.paletteCellList.size();
cell->id = s;
PaletteCellDescription pd;
pd.cell = cell;
pd.description = cell->name;
pd.shortcut = cell->shortcut;
pd.shortcut.setDescr(cell->name);
pd.shortcut.setState(STATE_NORMAL | STATE_NOTE_ENTRY);
preferences.paletteCellList.append(pd);
}
}

//---------------------------------------------------------
Expand All @@ -1579,7 +1610,13 @@ void MuseScore::setAdvancedPalette()

void MuseScore::setBasicPalette()
{
mscore->getPaletteBox();
bool empty = true;
QList<Shortcut> shortcuts; // stores basic workspace shortcuts
if (!preferences.paletteCellListBasic.isEmpty())
empty = false;
for (PaletteCellDescription d : preferences.paletteCellListBasic) {
shortcuts.append(d.cell->shortcut);
}
paletteBox->clear();
paletteBox->addPalette(newClefsPalette(PaletteType::BASIC));
paletteBox->addPalette(newKeySigPalette(PaletteType::BASIC));
Expand All @@ -1595,6 +1632,28 @@ void MuseScore::setBasicPalette()
paletteBox->addPalette(newRepeatsPalette());
paletteBox->addPalette(newBreaksPalette());
paletteBox->addPalette(newBeamPalette(PaletteType::BASIC));
int i = 0;
preferences.paletteCellList.clear();
for (Palette* p : paletteBox->palettes()) {
for (PaletteCell* cell : p->getCells()) {
if (cell->name == "Show More") {
i++;
continue;
}
if (!empty)
cell->shortcut = shortcuts[i];
int s = preferences.paletteCellList.size();
cell->id = s;
PaletteCellDescription pd;
pd.cell = cell;
pd.description = cell->name;
pd.shortcut = cell->shortcut;
pd.shortcut.setDescr(cell->name);
pd.shortcut.setState(STATE_NORMAL | STATE_NOTE_ENTRY);
preferences.paletteCellList.append(pd);
i++;
}
}
}

//---------------------------------------------------------
Expand Down
122 changes: 121 additions & 1 deletion mscore/musescore.cpp
Expand Up @@ -36,7 +36,6 @@
#include "mixer.h"
#include "selectionwindow.h"
#include "palette.h"
#include "palettebox.h"
#include "libmscore/part.h"
#include "libmscore/drumset.h"
#include "libmscore/instrtemplate.h"
Expand Down Expand Up @@ -4259,6 +4258,55 @@ void MuseScore::showPluginManager()
#endif
}

//---------------------------------------------------------
// showPaletteShortcutManager
//---------------------------------------------------------

void MuseScore::showPaletteShortcutManager()
{
#ifdef SCRIPT_INTERFACE
if (!paletteShortcutManager)
paletteShortcutManager = new PaletteShortcutManager(0);
paletteShortcutManager->init();
paletteShortcutManager->show();
#endif
}

//---------------------------------------------------------
// getPaletteShortcutManager
//---------------------------------------------------------

PaletteShortcutManager* MuseScore::getPaletteShortcutManager()
{
#ifdef SCRIPT_INTERFACE
if (!paletteShortcutManager)
paletteShortcutManager = new PaletteShortcutManager(0);
paletteShortcutManager->init1();
return paletteShortcutManager;
#endif
}

QMenuBar* MuseScore::getMenuBar()
{
return menuBar();
}

//---------------------------------------------------------
// loadPaletteShortcuts
//---------------------------------------------------------

void MuseScore::loadPaletteShortcuts()
{
if (!paletteShortcutMapper) {
paletteShortcutMapper = new QSignalMapper(this);
connect(paletteShortcutMapper, SIGNAL(mapped(int)), SLOT(paletteShortcutTriggered(int)));
}
for (int i = 0; i < preferences.paletteCellList.size(); ++i) {
PaletteCellDescription* d = &preferences.paletteCellList[i];
registerPaletteShortcut(d);
}
}

//---------------------------------------------------------
// showMediaDialog
//---------------------------------------------------------
Expand Down Expand Up @@ -4962,6 +5010,21 @@ void MuseScore::cmd(QAction* a, const QString& cmd)
showPluginCreator(a);
else if (cmd == "plugin-manager")
showPluginManager();
else if (cmd == "palette-shortcut-manager")
showPaletteShortcutManager();
else if (cmd == "set-palette-shortcut") {
PaletteBox* pb = mscore->getPaletteBox();
for (Palette* p : pb->palettes()) {
if (p->getCurrentIdx() != -1) {
PaletteCell* c = p->getCells()[p->getCurrentIdx()];
if (c == 0)
return;
PaletteShortcutManager* pm = getPaletteShortcutManager();
pm->setShortcut(c);
return;
}
}
}
else if(cmd == "resource-manager"){
ResourceManager r(0);
r.exec();
Expand Down Expand Up @@ -5484,6 +5547,63 @@ SynthesizerState MuseScore::synthesizerState()
return synti ? synti->state() : state;
}

//---------------------------------------------------------
// registerPaletteShortcut
//---------------------------------------------------------

void MuseScore::registerPaletteShortcut(PaletteCellDescription* p)
{
bool alreadyPresent = false;
int paletteShortcutIdx = -1;

for (int i = 0; i < paletteShortcuts.size(); i++) {
if (paletteShortcuts[i]->id == p->cell->id) {
paletteShortcutIdx = i;
alreadyPresent = true;
break;
}
}
if (paletteShortcutIdx == -1) {
paletteShortcuts.append(p->cell);
paletteShortcutIdx = paletteShortcuts.size() - 1;
}
QAction* a = p->shortcut.action();
if (!alreadyPresent) {
paletteCellActions.append(a);
}
if (!paletteShortcutMapper) {
paletteShortcutMapper = new QSignalMapper(this);
connect(paletteShortcutMapper, SIGNAL(mapped(int)), SLOT(paletteShortcutTriggered(int)));
}
connect(a, SIGNAL(triggered()), paletteShortcutMapper, SLOT(map()));
paletteShortcutMapper->setMapping(a, paletteShortcutIdx);
}

//---------------------------------------------------------
// unregisterPaletteShortcut
//---------------------------------------------------------

void MuseScore::unregisterPaletteShortcut(PaletteCellDescription* p)
{
paletteShortcuts.removeAll(p->cell);
QAction* a = p->shortcut.action();
paletteCellActions.removeAll(a);
disconnect(a, SIGNAL(triggered()), paletteShortcutMapper, SLOT(map()));
paletteShortcutMapper->removeMappings(a);
}

//---------------------------------------------------------
// paletteShortcutTriggered
//---------------------------------------------------------

void MuseScore::paletteShortcutTriggered(int i)
{
PaletteCell* c = paletteShortcuts[i];
Palette* p = c->parent;
if (p)
p->applyPaletteElement(c);
}

//---------------------------------------------------------
// canSaveMp3
//---------------------------------------------------------
Expand Down
23 changes: 23 additions & 0 deletions mscore/musescore.h
Expand Up @@ -34,6 +34,10 @@
#include "libmscore/musescoreCore.h"
#include "libmscore/score.h"
#include "newwizard.h"
#include "preferences.h"
#include "paletteShortcutManager.h"
#include "pluginManager.h"
#include "pluginCreator.h"

namespace Ms {

Expand Down Expand Up @@ -91,6 +95,7 @@ class Sym;
class MasterPalette;
class PluginCreator;
class PluginManager;
class PaletteShortcutManager;
class MasterSynthesizer;
class SynthesizerState;
class Driver;
Expand All @@ -101,6 +106,7 @@ class HelpBrowser;
class ToolbarEditor;

struct PluginDescription;
struct PaletteCellDescription;
enum class SelState : char;
enum class IconType : signed char;
enum class MagIdx : char;
Expand Down Expand Up @@ -277,6 +283,7 @@ class MuseScore : public QMainWindow, public MuseScoreCore {
MasterPalette* masterPalette { 0 };
PluginCreator* _pluginCreator { 0 };
PluginManager* pluginManager { 0 };
PaletteShortcutManager* paletteShortcutManager { 0 };
SelectionWindow* selectionWindow { 0 };

QMenu* menuFile;
Expand Down Expand Up @@ -334,6 +341,7 @@ class MuseScore : public QMainWindow, public MuseScoreCore {

bool _midiinEnabled { true };
QList<QString> plugins;
QList<PaletteCell*> paletteShortcuts;
ScriptEngine* se { 0 };
QString pluginPath;

Expand All @@ -342,7 +350,9 @@ class MuseScore : public QMainWindow, public MuseScoreCore {

QTimer* autoSaveTimer;
QList<QAction*> pluginActions;
QList<QAction*> paletteCellActions;
QSignalMapper* pluginMapper { 0 };
QSignalMapper* paletteShortcutMapper { 0 };

PianorollEditor* pianorollEditor { 0 };
DrumrollEditor* drumrollEditor { 0 };
Expand Down Expand Up @@ -518,6 +528,7 @@ class MuseScore : public QMainWindow, public MuseScoreCore {
void dirtyChanged(Score*);
void setPos(int tick);
void pluginTriggered(int);
void paletteShortcutTriggered(int);
void handleMessage(const QString& message);
void setCurrentScoreView(ScoreView*);
void setCurrentScoreView(int);
Expand Down Expand Up @@ -565,6 +576,12 @@ class MuseScore : public QMainWindow, public MuseScoreCore {
void updateDrumTools(const Drumset* ds);
void showPluginCreator(QAction*);
void showPluginManager();
void showPaletteShortcutManager();
PaletteShortcutManager* getPaletteShortcutManager();
bool paletteShortcutMapperNull() { return paletteShortcutMapper == 0; }
void clearPaletteShortcutMapper() { paletteShortcutMapper = 0; }
PreferenceDialog* getPreferenceDialog() { return preferenceDialog; }
void clearPaletteShortcuts() { paletteShortcuts.clear(); }

// void updateTabNames();
QProgressBar* showProgressBar();
Expand All @@ -589,6 +606,7 @@ class MuseScore : public QMainWindow, public MuseScoreCore {
virtual void setCurrentView(int tabIdx, int idx);
void loadPlugins();
void unloadPlugins();
void loadPaletteShortcuts();

ScoreState state() const { return _sstate; }
void changeState(ScoreState);
Expand Down Expand Up @@ -735,13 +753,18 @@ class MuseScore : public QMainWindow, public MuseScoreCore {
void registerPlugin(PluginDescription*);
void unregisterPlugin(PluginDescription*);

void registerPaletteShortcut(PaletteCellDescription*);
void unregisterPaletteShortcut(PaletteCellDescription*);

Q_INVOKABLE void showStartcenter(bool);
void showPlayPanel(bool);

QFileInfoList recentScores() const;
void saveDialogState(const char* name, QFileDialog* d);
void restoreDialogState(const char* name, QFileDialog* d);

QMenuBar* getMenuBar();

QPixmap extractThumbnail(const QString& name);

void showLoginDialog();
Expand Down

0 comments on commit eec3df6

Please sign in to comment.