1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
|
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2016 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#include "toolbarEditor.h"
#include "musescore.h"
#include "workspace.h"
#include "icons.h"
namespace Ms {
static const char* toolbars[] = {
QT_TRANSLATE_NOOP("toolbar", "Note Input"),
QT_TRANSLATE_NOOP("toolbar", "File Operations"),
QT_TRANSLATE_NOOP("toolbar", "Playback Controls")
};
//---------------------------------------------------------
// showToolbarEditor
//---------------------------------------------------------
void MuseScore::showToolbarEditor()
{
if (!editToolbars) {
editToolbars = new ToolbarEditor(this);
}
editToolbars->init();
editToolbars->show();
}
//---------------------------------------------------------
// ToolbarEditor
//---------------------------------------------------------
ToolbarEditor::ToolbarEditor(QWidget* parent)
: QDialog(parent)
{
setObjectName("ToolbarEditor");
setupUi(this);
for (auto i : toolbars)
toolbarList->addItem(qApp->translate("toolbar", i));
toolbarList->setCurrentRow(0);
new_toolbars = new std::vector<std::list<const char*>*>();
new_toolbars->push_back(mscore->noteInputMenuEntries());
new_toolbars->push_back(mscore->fileOperationEntries());
new_toolbars->push_back(mscore->playbackControlEntries());
connect(toolbarList, SIGNAL(currentRowChanged(int)), SLOT(toolbarChanged(int)));
connect(add, SIGNAL(clicked()), SLOT(addAction()));
connect(remove, SIGNAL(clicked()), SLOT(removeAction()));
connect(up, SIGNAL(clicked()), SLOT(upAction()));
connect(down, SIGNAL(clicked()), SLOT(downAction()));
connect(buttonBox, SIGNAL(accepted()), SLOT(accepted()));
up->setIcon(*icons[int(Icons::arrowUp_ICON)]);
down->setIcon(*icons[int(Icons::arrowDown_ICON)]);
MuseScore::restoreGeometry(this);
}
//---------------------------------------------------------
// init
//---------------------------------------------------------
void ToolbarEditor::init()
{
QString name = Workspace::currentWorkspace->name();
bool writable = !Workspace::currentWorkspace->readOnly();
if (!writable) {
name += " " + tr("(not changeable)");
}
add->setEnabled(writable);
remove->setEnabled(writable);
up->setEnabled(writable);
down->setEnabled(writable);
workspaceName->setText(name);
// Syncs the editor with the current toolbars
new_toolbars->at(0) = mscore->noteInputMenuEntries();
new_toolbars->at(1) = mscore->fileOperationEntries();
new_toolbars->at(2) = mscore->playbackControlEntries();
toolbarChanged(toolbarList->currentRow()); // populate lists
}
//---------------------------------------------------------
// accepted
//---------------------------------------------------------
void ToolbarEditor::accepted()
{
if (Workspace::currentWorkspace->readOnly())
return;
// Updates the toolbars
mscore->setNoteInputMenuEntries(*(new_toolbars->at(0)));
mscore->setFileOperationEntries(*(new_toolbars->at(1)));
mscore->setPlaybackControlEntries(*(new_toolbars->at(2)));
mscore->populateNoteInputMenu();
mscore->populateFileOperations();
mscore->populatePlaybackControls();
Workspace::currentWorkspace->setDirty(true);
}
//---------------------------------------------------------
// populateLists
//---------------------------------------------------------
void ToolbarEditor::populateLists(const std::list<const char*>& all, std::list<const char*>* current)
{
actionList->clear();
availableList->clear();
for (auto i : *current) {
QAction* a = getAction(i);
QListWidgetItem* item;
QString actionName = QString(i);
if (a)
item = new QListWidgetItem(a->icon(), actionName);
else if (actionName.isEmpty())
item = new QListWidgetItem(tr("Separator"));
else
item = new QListWidgetItem(actionName);
item->setData(Qt::UserRole, QVariant::fromValue((void*)i));
actionList->addItem(item);
}
for (auto i : all) {
bool found = false;
for (auto k : *current) {
if (strcmp(k, i) == 0) {
found = true;
break;
}
}
if (!found) {
QAction* a = getAction(i);
QListWidgetItem* item = 0;
QString actionName = QString(i);
if (a)
item = new QListWidgetItem(a->icon(), actionName);
else if (!actionName.isEmpty())
item = new QListWidgetItem(QString(i));
if (item) {
item->setData(Qt::UserRole, QVariant::fromValue((void*)i));
availableList->addItem(item);
}
}
}
QListWidgetItem* item = new QListWidgetItem(tr("Separator"));
item->setData(Qt::UserRole, QVariant::fromValue((void*)""));
availableList->addItem(item);
}
//---------------------------------------------------------
// isSpacer
//---------------------------------------------------------
bool ToolbarEditor::isSpacer(QListWidgetItem* item) const
{
return !*(const char*)(item->data(Qt::UserRole).value<void*>());
}
//---------------------------------------------------------
// addAction
//---------------------------------------------------------
void ToolbarEditor::addAction()
{
int cr = availableList->currentRow();
if (cr == -1)
return;
QListWidgetItem* item = availableList->item(cr);
if (isSpacer(item)) {
QListWidgetItem* nitem = new QListWidgetItem(item->text());
nitem->setData(Qt::UserRole, QVariant::fromValue((void*)""));
item = nitem;
}
else
item = availableList->takeItem(cr);
cr = actionList->currentRow();
if (cr == -1)
actionList->addItem(item);
else
actionList->insertItem(cr, item);
updateNewToolbar(toolbarList->currentRow());
}
//---------------------------------------------------------
// removeAction
//---------------------------------------------------------
void ToolbarEditor::removeAction()
{
int cr = actionList->currentRow();
if (cr == -1)
return;
QListWidgetItem* item = actionList->takeItem(cr);
if (!isSpacer(item))
availableList->addItem(item);
updateNewToolbar(toolbarList->currentRow());
}
//---------------------------------------------------------
// upAction
//---------------------------------------------------------
void ToolbarEditor::upAction()
{
int cr = actionList->currentRow();
if (cr <= 0)
return;
QListWidgetItem* item = actionList->takeItem(cr);
actionList->insertItem(cr - 1, item);
actionList->setCurrentRow(cr - 1);
updateNewToolbar(toolbarList->currentRow());
}
//---------------------------------------------------------
// downAction
//---------------------------------------------------------
void ToolbarEditor::downAction()
{
int cr = actionList->currentRow();
if (cr == -1 || cr == actionList->count()-1)
return;
QListWidgetItem* item = actionList->takeItem(cr);
actionList->insertItem(cr + 1, item);
actionList->setCurrentRow(cr + 1);
updateNewToolbar(toolbarList->currentRow());
}
//---------------------------------------------------------
// toolbarChanged
//---------------------------------------------------------
void ToolbarEditor::toolbarChanged(int tb)
{
switch (tb) {
case 0: // NoteInput
populateLists(MuseScore::allNoteInputMenuEntries(), new_toolbars->at(tb));
break;
case 1: //FileOperations
populateLists(MuseScore::allFileOperationEntries(), new_toolbars->at(tb));
break;
case 2: //PlaybackControls
populateLists(MuseScore::allPlaybackControlEntries(), new_toolbars->at(tb));
}
}
//---------------------------------------------------------
// hideEvent
//---------------------------------------------------------
void ToolbarEditor::hideEvent(QHideEvent* event)
{
MuseScore::saveGeometry(this);
QWidget::hideEvent(event);
}
//---------------------------------------------------------
// updateNewToolbar
//---------------------------------------------------------
void ToolbarEditor::updateNewToolbar(int toolbar_to_update) {
// Updates the current toolbar to the actionList
std::list<const char*> *toolbar_action_list = new std::list<const char*>();
for (int i = 0; i < actionList->count(); ++i) {
QListWidgetItem* a = actionList->item(i);
toolbar_action_list->push_back((const char*)(a->data(Qt::UserRole).value<void*>()));
}
new_toolbars->at(toolbar_to_update) = toolbar_action_list;
}
} // namespace Ms
|