Skip to content

Commit

Permalink
palette shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
divya-urs committed Aug 13, 2017
1 parent a66d69a commit 7e51189
Show file tree
Hide file tree
Showing 20 changed files with 1,394 additions and 16 deletions.
11 changes: 9 additions & 2 deletions mscore/CMakeLists.txt
Expand Up @@ -29,10 +29,17 @@ 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)
#set (SCRIPT_FILES qmledit.cpp paletteShortcutManager.cpp)
#set (SCRIPT_UI paletteShortcutManager.ui)
endif (SCRIPT_INTERFACE)

#if (SCRIPT_INTERFACE)
# set (SCRIPT_FILES qmledit.cpp paletteShortcutManager.cpp)
# set (SCRIPT_UI paletteShortcutManager.ui)
#endif (SCRIPT_INTERFACE)

QT5_WRAP_UI (ui_headers
insertmeasuresdialog.ui editinstrument.ui editstyle.ui instrdialog.ui instrwidget.ui
measuresdialog.ui pagesettings.ui mixer.ui playpanel.ui prefsdialog.ui measureproperties.ui
Expand Down
32 changes: 32 additions & 0 deletions mscore/menus.cpp
Expand Up @@ -1527,6 +1527,13 @@ Palette* MuseScore::newFretboardDiagramPalette()
void MuseScore::setAdvancedPalette()
{
mscore->getPaletteBox();
// get shortcut list before clearing palettebox
QList<Shortcut> shortcuts;
for (Palette* p : paletteBox->palettes()) {
for (PaletteCell* cell : p->getCells()) {
shortcuts.append(cell->shortcut);
}
}
paletteBox->clear();
paletteBox->addPalette(newClefsPalette(PaletteType::ADVANCED));
paletteBox->addPalette(newKeySigPalette(PaletteType::ADVANCED));
Expand All @@ -1553,6 +1560,18 @@ 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);
//cell->shortcut = shortcuts[i];
//i++;
}
}
for (int i = 0; i < shortcuts.size(); i++) {
cells[i]->shortcut = shortcuts[i];
}
}

//---------------------------------------------------------
Expand All @@ -1562,6 +1581,12 @@ void MuseScore::setAdvancedPalette()
void MuseScore::setBasicPalette()
{
mscore->getPaletteBox();
QList<Shortcut> shortcuts;
for (Palette* p : paletteBox->palettes()) {
for (PaletteCell* cell : p->getCells()) {
shortcuts.append(cell->shortcut);
}
}
paletteBox->clear();
paletteBox->addPalette(newClefsPalette(PaletteType::BASIC));
paletteBox->addPalette(newKeySigPalette(PaletteType::BASIC));
Expand All @@ -1577,6 +1602,13 @@ void MuseScore::setBasicPalette()
paletteBox->addPalette(newRepeatsPalette());
paletteBox->addPalette(newBreaksPalette());
paletteBox->addPalette(newBeamPalette(PaletteType::BASIC));
int i = 0;
for (Palette* p : paletteBox->palettes()) {
for (PaletteCell* cell : p->getCells()) {
cell->shortcut = shortcuts[i];
i++;
}
}
}

//---------------------------------------------------------
Expand Down
147 changes: 146 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 @@ -112,6 +111,8 @@
#include "startcenter.h"
#include "help.h"
#include "awl/aslider.h"
//#include "pluginCreator.h"
//#include "pluginManager.h"

#ifdef USE_LAME
#include "exportmp3.h"
Expand Down Expand Up @@ -4234,6 +4235,59 @@ 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.paletteCellListMaster.size(); ++i) {
PaletteCellDescription* d = &preferences.paletteCellListMaster[i];
registerPaletteShortcut(d);
}
for (int i = 0; i < preferences.paletteCellList.size(); ++i) {
PaletteCellDescription* d = &preferences.paletteCellList[i];
registerPaletteShortcut(d);
}
}

//---------------------------------------------------------
// showMediaDialog
//---------------------------------------------------------
Expand Down Expand Up @@ -4933,6 +4987,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, p->getCurrentIdx());
return;
}
}
}
else if(cmd == "resource-manager"){
ResourceManager r(0);
r.exec();
Expand Down Expand Up @@ -5446,6 +5515,82 @@ SynthesizerState MuseScore::synthesizerState()
return synti ? synti->state() : state;
}

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

void MuseScore::registerPaletteShortcut(PaletteCellDescription* p)
{
QString name = p->cell->name;
/*int paletteShortcutIdx = paletteShortcuts.indexOf(p->cell);
if (paletteShortcutIdx == -1) {
paletteShortcuts.append(p->cell);
paletteShortcutIdx = paletteShortcuts.size() - 1;
}
else {
paletteShortcuts.replace(paletteShortcutIdx, p->cell);
}
QAction* a = p->shortcut.action();
int i = paletteCellActions.indexOf(a);
paletteCellActions.removeAll(a);
//if (i == -1)
paletteCellActions.append(a);
//else
// paletteCellActions.replace(i, a);
i = paletteCellActions.indexOf(a);
//int paletteShortcutIdx = paletteShortcuts.size() - 1;
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);
paletteShortcutMapper->removeMappings(a);
paletteShortcutMapper->setMapping(a, paletteShortcutIdx);*/
paletteShortcuts.append(p->cell);
QAction* a = p->shortcut.action();
paletteCellActions.append(a);
int paletteShortcutIdx = paletteShortcuts.size() - 1;
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)
{
//QString s = p->cell->getParent()->name() + ":" + p->cell->cellName();
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->getParent();
if (!p)
p = c->getParentMaster();

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 7e51189

Please sign in to comment.