1 //=============================================================================
2 //  MusE Score
3 //  Linux Music Score Editor
4 //
5 //  Copyright (C) 2007-2016 Werner Schweer and others
6 //
7 //  This program is free software; you can redistribute it and/or modify
8 //  it under the terms of the GNU General Public License version 2.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #include "symboldialog.h"
21 #include "menus.h"
22 #include "palette.h"
23 #include "libmscore/score.h"
24 #include "libmscore/sym.h"
25 #include "libmscore/style.h"
26 #include "libmscore/element.h"
27 #include "libmscore/symbol.h"
28 
29 namespace Ms {
30 
31 extern MasterScore* gscore;
32 
33 //---------------------------------------------------------
34 //   createSymbolPalette
35 //---------------------------------------------------------
36 
createSymbolPalette()37 void SymbolDialog::createSymbolPalette()
38       {
39       sp = new Palette();
40       sp->setIsSymbolsPaletteInMasterPalette(true);
41       createSymbols();
42       }
43 
44 //---------------------------------------------------------
45 //   createSymbols
46 //---------------------------------------------------------
47 
createSymbols()48 void SymbolDialog::createSymbols()
49       {
50       int currentIndex = fontList->currentIndex();
51       const ScoreFont* f = &ScoreFont::scoreFonts()[currentIndex];
52       // init the font if not done yet
53       ScoreFont::fontFactory(f->name());
54       sp->clear();
55       for (auto name : (*smuflRanges())[range]) {
56             SymId id     = Sym::name2id(name);
57             if (search->text().isEmpty()
58                || Sym::id2userName(id).contains(search->text(), Qt::CaseInsensitive)) {
59                   Symbol* s = new Symbol(gscore);
60                   s->setSym(SymId(id), f);
61                   sp->append(s, qApp->translate("symUserNames", Sym::id2userName(SymId(id)).toUtf8()) + " \"<sym>" + Sym::id2name(SymId(id)) + "</sym>\"");
62                   }
63             }
64       }
65 
66 //---------------------------------------------------------
67 //   SymbolDialog
68 //---------------------------------------------------------
69 
SymbolDialog(const QString & s,QWidget * parent)70 SymbolDialog::SymbolDialog(const QString& s, QWidget* parent)
71    : QWidget(parent, Qt::WindowFlags(Qt::Dialog | Qt::Window))
72       {
73       setupUi(this);
74       range = s;        // smufl symbol range
75       int idx = 0;
76       int currentIndex = 0;
77       for (const ScoreFont& f : ScoreFont::scoreFonts()) {
78             fontList->addItem(f.name());
79             if (f.name() == "Leland" || f.name() == "Bravura")
80                   currentIndex = idx;
81             ++idx;
82             }
83       fontList->setCurrentIndex(currentIndex);
84 
85       QLayout* l = new QVBoxLayout();
86       frame->setLayout(l);
87       createSymbolPalette();
88 
89       QScrollArea* sa = new PaletteScrollArea(sp);
90       l->addWidget(sa);
91 
92       sp->setAcceptDrops(false);
93       sp->setDrawGrid(true);
94       sp->setSelectable(true);
95 
96       connect(systemFlag, SIGNAL(stateChanged(int)), SLOT(systemFlagChanged(int)));
97       connect(fontList, SIGNAL(currentIndexChanged(int)), SLOT(systemFontChanged(int)));
98 
99       sa->setWidget(sp);
100       }
101 
102 //---------------------------------------------------------
103 //   systemFlagChanged
104 //---------------------------------------------------------
105 
systemFlagChanged(int state)106 void SymbolDialog::systemFlagChanged(int state)
107       {
108       bool sysFlag = state == Qt::Checked;
109       for (int i = 0; i < sp->size(); ++i) {
110             Element* e = sp->element(i);
111             if (e && e->type() == ElementType::SYMBOL)
112                   static_cast<Symbol*>(e)->setSystemFlag(sysFlag);
113             }
114       }
115 
116 //---------------------------------------------------------
117 //   systemFontChanged
118 //---------------------------------------------------------
119 
systemFontChanged(int)120 void SymbolDialog::systemFontChanged(int)
121       {
122       createSymbols();
123       }
124 
on_search_textChanged(const QString & searchPhrase)125 void SymbolDialog::on_search_textChanged(const QString &searchPhrase)
126       {
127       Q_UNUSED(searchPhrase);
128       createSymbols();
129       }
130 
on_clearSearch_clicked()131 void SymbolDialog::on_clearSearch_clicked()
132       {
133       search->clear();
134       createSymbols();
135       }
136 
137 //---------------------------------------------------------
138 //   changeEvent
139 //---------------------------------------------------------
140 
changeEvent(QEvent * event)141 void SymbolDialog::changeEvent(QEvent *event)
142       {
143       QWidget::changeEvent(event);
144       if (event->type() == QEvent::LanguageChange)
145             retranslate();
146       }
147 
148 }
149 
150