2012-05-26 14:49:10 +02:00
|
|
|
//=============================================================================
|
|
|
|
// MuseScore
|
|
|
|
// Linux Music Score Editor
|
|
|
|
// $Id: plugins.cpp 5568 2012-04-22 10:08:43Z wschweer $
|
|
|
|
//
|
|
|
|
// Copyright (C) 2009-2010 Werner Schweer and others
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//=============================================================================
|
|
|
|
|
|
|
|
#include "musescore.h"
|
|
|
|
#include "libmscore/score.h"
|
|
|
|
#include "libmscore/undo.h"
|
|
|
|
#include "globals.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "preferences.h"
|
|
|
|
#include "libmscore/chord.h"
|
|
|
|
#include "libmscore/note.h"
|
|
|
|
#include "libmscore/utils.h"
|
|
|
|
#include "libmscore/mscore.h"
|
2012-05-28 19:34:13 +02:00
|
|
|
#include "libmscore/measurebase.h"
|
|
|
|
#include "libmscore/measure.h"
|
|
|
|
#include "libmscore/segment.h"
|
2012-05-29 22:55:30 +02:00
|
|
|
#include "libmscore/rest.h"
|
2012-05-30 20:54:26 +02:00
|
|
|
#include "libmscore/stafftext.h"
|
2012-05-28 11:29:21 +02:00
|
|
|
#include "plugins.h"
|
2012-06-28 10:03:19 +02:00
|
|
|
#include "libmscore/cursor.h"
|
2012-06-29 18:10:35 +02:00
|
|
|
#include "libmscore/page.h"
|
|
|
|
#include "libmscore/system.h"
|
2012-07-06 14:21:05 +02:00
|
|
|
#include "libmscore/staff.h"
|
|
|
|
#include "libmscore/part.h"
|
|
|
|
#include "libmscore/timesig.h"
|
|
|
|
#include "libmscore/harmony.h"
|
2012-05-26 14:49:10 +02:00
|
|
|
|
2012-05-30 17:12:30 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// QmlPlugin
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
QmlPlugin::QmlPlugin(QDeclarativeItem* parent)
|
|
|
|
: QDeclarativeItem(parent)
|
|
|
|
{
|
|
|
|
}
|
2012-05-26 14:49:10 +02:00
|
|
|
|
2012-05-30 17:12:30 +02:00
|
|
|
QmlPlugin::~QmlPlugin()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-05 17:15:46 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// curScore
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Score* QmlPlugin::curScore() const
|
|
|
|
{
|
|
|
|
return mscore->currentScore();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// scores
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
QDeclarativeListProperty<Score> QmlPlugin::scores()
|
|
|
|
{
|
|
|
|
return QDeclarativeListProperty<Score>(this, mscore->scores());
|
|
|
|
}
|
|
|
|
|
2012-07-10 17:17:17 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// writeScore
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
bool QmlPlugin::writeScore(Score* s, const QString& name, const QString& ext)
|
|
|
|
{
|
|
|
|
return mscore->saveAs(s, true, name, ext);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// readScore
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
Score* QmlPlugin::readScore(const QString& name)
|
|
|
|
{
|
|
|
|
return mscore->openScore(name);
|
|
|
|
}
|
|
|
|
|
2012-05-26 14:49:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// registerPlugin
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2012-06-06 14:16:06 +02:00
|
|
|
void MuseScore::registerPlugin(PluginDescription* plugin)
|
2012-05-26 14:49:10 +02:00
|
|
|
{
|
2012-06-06 14:16:06 +02:00
|
|
|
QString pluginPath = plugin->path;
|
2012-05-26 14:49:10 +02:00
|
|
|
QFileInfo np(pluginPath);
|
2012-05-28 19:34:13 +02:00
|
|
|
if (np.suffix() != "qml")
|
|
|
|
return;
|
2012-05-26 14:49:10 +02:00
|
|
|
QString baseName = np.baseName();
|
|
|
|
|
|
|
|
foreach(QString s, plugins) {
|
|
|
|
QFileInfo fi(s);
|
|
|
|
if (fi.baseName() == baseName) {
|
|
|
|
if (MScore::debugMode)
|
|
|
|
qDebug(" Plugin <%s> already registered\n", qPrintable(pluginPath));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QFile f(pluginPath);
|
|
|
|
if (!f.open(QIODevice::ReadOnly)) {
|
|
|
|
if (MScore::debugMode)
|
|
|
|
qDebug("Loading Plugin <%s> failed\n", qPrintable(pluginPath));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (MScore::debugMode)
|
2012-05-28 11:29:21 +02:00
|
|
|
qDebug("Register Plugin <%s>", qPrintable(pluginPath));
|
2012-05-26 14:49:10 +02:00
|
|
|
f.close();
|
2012-05-28 19:34:13 +02:00
|
|
|
QObject* obj = 0;
|
2012-07-02 18:05:10 +02:00
|
|
|
QDeclarativeComponent component(qml(), QUrl::fromLocalFile(pluginPath));
|
2012-06-05 17:34:19 +02:00
|
|
|
obj = component.create();
|
|
|
|
if (obj == 0) {
|
|
|
|
qDebug("creating component <%s> failed", qPrintable(pluginPath));
|
|
|
|
foreach(QDeclarativeError e, component.errors()) {
|
|
|
|
qDebug(" line %d: %s", e.line(), qPrintable(e.description()));
|
2012-05-30 20:54:26 +02:00
|
|
|
}
|
2012-06-05 17:34:19 +02:00
|
|
|
return;
|
2012-05-26 14:49:10 +02:00
|
|
|
}
|
2012-06-05 17:34:19 +02:00
|
|
|
QmlPlugin* item = qobject_cast<QmlPlugin*>(obj);
|
|
|
|
QString menuPath = item->menuPath();
|
2012-06-06 14:16:06 +02:00
|
|
|
plugin->menuPath = menuPath;
|
2012-06-05 17:34:19 +02:00
|
|
|
plugins.append(pluginPath);
|
2012-06-06 14:16:06 +02:00
|
|
|
createMenuEntry(plugin);
|
|
|
|
|
|
|
|
QAction* a = plugin->shortcut.action();
|
|
|
|
pluginActions.append(a);
|
|
|
|
int pluginIdx = plugins.size() - 1; // plugin is already appended
|
|
|
|
connect(a, SIGNAL(triggered()), pluginMapper, SLOT(map()));
|
|
|
|
pluginMapper->setMapping(a, pluginIdx);
|
|
|
|
|
2012-05-28 19:34:13 +02:00
|
|
|
delete obj;
|
2012-05-28 11:29:21 +02:00
|
|
|
}
|
2012-05-26 14:49:10 +02:00
|
|
|
|
2012-07-02 18:05:10 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// qml
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
QDeclarativeEngine* MuseScore::qml()
|
|
|
|
{
|
|
|
|
if (_qml == 0) {
|
|
|
|
//-----------some qt bindings
|
|
|
|
_qml = new QDeclarativeEngine;
|
|
|
|
qmlRegisterType<MsProcess> ("MuseScore", 1, 0, "QProcess");
|
|
|
|
qmlRegisterType<MsFile> ("MuseScore", 1, 0, "QFile");
|
|
|
|
//-----------mscore bindings
|
2012-07-13 14:36:26 +02:00
|
|
|
qmlRegisterType<MScore> ("MuseScore", 1, 0, "MScore");
|
2012-07-02 18:05:10 +02:00
|
|
|
qmlRegisterType<MsScoreView>("MuseScore", 1, 0, "ScoreView");
|
|
|
|
qmlRegisterType<QmlPlugin> ("MuseScore", 1, 0, "MuseScore");
|
|
|
|
qmlRegisterType<Score> ("MuseScore", 1, 0, "Score");
|
|
|
|
qmlRegisterType<Segment> ("MuseScore", 1, 0, "Segment");
|
|
|
|
qmlRegisterType<Chord> ("MuseScore", 1, 0, "Chord");
|
|
|
|
qmlRegisterType<Note> ("MuseScore", 1, 0, "Note");
|
|
|
|
qmlRegisterType<Rest> ("MuseScore", 1, 0, "Rest");
|
|
|
|
qmlRegisterType<Measure> ("MuseScore", 1, 0, "Measure");
|
|
|
|
qmlRegisterType<Cursor> ("MuseScore", 1, 0, "Cursor");
|
|
|
|
qmlRegisterType<StaffText> ("MuseScore", 1, 0, "StaffText");
|
2012-07-06 14:21:05 +02:00
|
|
|
qmlRegisterType<Part> ("MuseScore", 1, 0, "Part");
|
|
|
|
qmlRegisterType<Staff> ("MuseScore", 1, 0, "Staff");
|
|
|
|
qmlRegisterType<Harmony> ("MuseScore", 1, 0, "Harmony");
|
|
|
|
qmlRegisterType<PageFormat> ("MuseScore", 1, 0, "PageFormat");
|
|
|
|
qmlRegisterType<TimeSig> ("MuseScore", 1, 0, "TimeSig");
|
2012-07-02 18:05:10 +02:00
|
|
|
//-----------virtual classes
|
|
|
|
qmlRegisterType<Element>();
|
|
|
|
qmlRegisterType<ChordRest>();
|
|
|
|
}
|
|
|
|
return _qml;
|
|
|
|
}
|
|
|
|
|
2012-05-28 11:29:21 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// createMenuEntry
|
2012-06-06 14:16:06 +02:00
|
|
|
// syntax: "entry.entry.entry"
|
2012-05-28 11:29:21 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2012-06-06 14:16:06 +02:00
|
|
|
void MuseScore::createMenuEntry(PluginDescription* plugin)
|
2012-05-28 11:29:21 +02:00
|
|
|
{
|
2012-05-26 14:49:10 +02:00
|
|
|
if (!pluginMapper)
|
|
|
|
return;
|
|
|
|
|
2012-06-06 14:16:06 +02:00
|
|
|
QString menu = plugin->menuPath;
|
2012-05-26 14:49:10 +02:00
|
|
|
QStringList ml;
|
|
|
|
QString s;
|
|
|
|
bool escape = false;
|
|
|
|
foreach (QChar c, menu) {
|
|
|
|
if (escape) {
|
|
|
|
escape = false;
|
|
|
|
s += c;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (c == '\\')
|
|
|
|
escape = true;
|
|
|
|
else {
|
|
|
|
if (c == '.') {
|
|
|
|
ml += s;
|
|
|
|
s = "";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
s += c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!s.isEmpty())
|
|
|
|
ml += s;
|
|
|
|
|
|
|
|
int n = ml.size();
|
|
|
|
QWidget* curMenu = menuBar();
|
|
|
|
|
|
|
|
for(int i = 0; i < n; ++i) {
|
|
|
|
QString m = ml[i];
|
|
|
|
bool found = false;
|
|
|
|
QList<QObject*> ol = curMenu->children();
|
|
|
|
foreach(QObject* o, ol) {
|
|
|
|
QMenu* menu = qobject_cast<QMenu*>(o);
|
|
|
|
if (!menu)
|
|
|
|
continue;
|
|
|
|
if (menu->objectName() == m || menu->title() == m) {
|
|
|
|
curMenu = menu;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!found) {
|
|
|
|
if (i == 0) {
|
|
|
|
curMenu = new QMenu(m, menuBar());
|
|
|
|
curMenu->setObjectName(m);
|
|
|
|
menuBar()->insertMenu(menuBar()->actions().back(), (QMenu*)curMenu);
|
|
|
|
if (MScore::debugMode)
|
|
|
|
qDebug("add Menu <%s>\n", qPrintable(m));
|
|
|
|
}
|
|
|
|
else if (i + 1 == n) {
|
|
|
|
QStringList sl = m.split(":");
|
2012-06-06 14:16:06 +02:00
|
|
|
QAction* a = plugin->shortcut.action();
|
2012-05-26 14:49:10 +02:00
|
|
|
QMenu* cm = static_cast<QMenu*>(curMenu);
|
|
|
|
if (sl.size() == 2) {
|
|
|
|
QList<QAction*> al = cm->actions();
|
|
|
|
QAction* ba = 0;
|
|
|
|
foreach(QAction* ia, al) {
|
|
|
|
if (ia->text() == sl[0]) {
|
|
|
|
ba = ia;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-06-06 14:16:06 +02:00
|
|
|
a->setText(sl[1]);
|
2012-05-26 14:49:10 +02:00
|
|
|
cm->insertAction(ba, a);
|
|
|
|
}
|
|
|
|
else {
|
2012-06-06 14:16:06 +02:00
|
|
|
a->setText(m);
|
|
|
|
cm->addAction(a);
|
2012-05-26 14:49:10 +02:00
|
|
|
}
|
2012-06-06 14:16:06 +02:00
|
|
|
|
2012-05-26 14:49:10 +02:00
|
|
|
if (MScore::debugMode)
|
|
|
|
qDebug("add action <%s>\n", qPrintable(m));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
curMenu = ((QMenu*)curMenu)->addMenu(m);
|
|
|
|
if (MScore::debugMode)
|
|
|
|
qDebug("add menu <%s>\n", qPrintable(m));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// pluginIdxFromPath
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
int MuseScore::pluginIdxFromPath(QString pluginPath) {
|
|
|
|
QFileInfo np(pluginPath);
|
|
|
|
QString baseName = np.baseName();
|
|
|
|
int idx = 0;
|
|
|
|
foreach(QString s, plugins) {
|
|
|
|
QFileInfo fi(s);
|
2012-05-28 19:34:13 +02:00
|
|
|
if (fi.baseName() == baseName)
|
2012-05-26 14:49:10 +02:00
|
|
|
return idx;
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
return -1;
|
2012-05-28 19:34:13 +02:00
|
|
|
}
|
2012-05-26 14:49:10 +02:00
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// loadPlugins
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MuseScore::loadPlugins()
|
|
|
|
{
|
|
|
|
pluginMapper = new QSignalMapper(this);
|
|
|
|
connect(pluginMapper, SIGNAL(mapped(int)), SLOT(pluginTriggered(int)));
|
|
|
|
foreach(PluginDescription* d, preferences.pluginList) {
|
2012-06-06 14:16:06 +02:00
|
|
|
if (d->load)
|
|
|
|
registerPlugin(d);
|
2012-05-26 14:49:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// unloadPlugins
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MuseScore::unloadPlugins()
|
|
|
|
{
|
2012-05-28 11:29:21 +02:00
|
|
|
for (int idx = 0; idx < plugins.size() ; idx++) {
|
2012-05-29 23:17:49 +02:00
|
|
|
; // TODO
|
2012-05-28 11:29:21 +02:00
|
|
|
}
|
2012-05-26 14:49:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// loadPlugin
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
bool MuseScore::loadPlugin(const QString& filename)
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
QDir pluginDir(mscoreGlobalShare + "plugins");
|
|
|
|
if (MScore::debugMode)
|
|
|
|
qDebug("Plugin Path <%s>\n", qPrintable(mscoreGlobalShare + "plugins"));
|
|
|
|
|
2012-05-28 19:34:13 +02:00
|
|
|
if (filename.endsWith(".qml")){
|
2012-05-26 14:49:10 +02:00
|
|
|
QFileInfo fi(pluginDir, filename);
|
|
|
|
if (fi.exists()) {
|
|
|
|
QString path(fi.filePath());
|
2012-06-06 14:16:06 +02:00
|
|
|
//TODO registerPlugin(path);
|
2012-05-26 14:49:10 +02:00
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// pluginTriggered
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MuseScore::pluginTriggered(int idx)
|
|
|
|
{
|
|
|
|
QString pp = plugins[idx];
|
2012-05-28 19:34:13 +02:00
|
|
|
QDeclarativeView* view = new QDeclarativeView;
|
2012-07-13 11:26:08 +02:00
|
|
|
view->setResizeMode(QDeclarativeView::SizeViewToRootObject);
|
2012-05-28 19:34:13 +02:00
|
|
|
view->setSource(QUrl::fromLocalFile(pp));
|
|
|
|
connect((QObject*)view->engine(), SIGNAL(quit()), view, SLOT(close()));
|
|
|
|
view->show();
|
|
|
|
QmlPlugin* p = (QmlPlugin*)(view->rootObject());
|
2012-06-06 14:16:06 +02:00
|
|
|
if (p->pluginType() == "dock") {
|
2012-06-05 17:34:19 +02:00
|
|
|
QDockWidget* dock = new QDockWidget("Plugin", 0);
|
2012-06-06 14:16:06 +02:00
|
|
|
dock->setAttribute(Qt::WA_DeleteOnClose);
|
2012-06-05 17:34:19 +02:00
|
|
|
dock->setWidget(view);
|
2012-06-06 14:16:06 +02:00
|
|
|
Qt::DockWidgetArea area = Qt::RightDockWidgetArea;
|
|
|
|
if (p->dockArea() == "left")
|
|
|
|
area = Qt::LeftDockWidgetArea;
|
|
|
|
else if (p->dockArea() == "top")
|
|
|
|
area = Qt::TopDockWidgetArea;
|
|
|
|
else if (p->dockArea() == "bottom")
|
|
|
|
area = Qt::BottomDockWidgetArea;
|
|
|
|
addDockWidget(area, dock);
|
2012-06-05 17:34:19 +02:00
|
|
|
connect((QObject*)view->engine(), SIGNAL(quit()), dock, SLOT(close()));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
connect((QObject*)view->engine(), SIGNAL(quit()), view, SLOT(close()));
|
|
|
|
}
|
2012-06-08 19:06:52 +02:00
|
|
|
if (cs)
|
|
|
|
cs->startCmd();
|
2012-05-28 19:34:13 +02:00
|
|
|
p->runPlugin();
|
2012-06-08 19:06:52 +02:00
|
|
|
if (cs)
|
|
|
|
cs->endCmd();
|
|
|
|
endCmd();
|
2012-05-26 14:49:10 +02:00
|
|
|
}
|
2012-05-30 20:54:26 +02:00
|
|
|
|
2012-07-13 16:11:39 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// newElement
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2012-05-30 20:54:26 +02:00
|
|
|
Element* QmlPlugin::newElement(int t)
|
|
|
|
{
|
|
|
|
Score* score = curScore();
|
|
|
|
if (score == 0)
|
|
|
|
return 0;
|
|
|
|
return Element::create(ElementType(t), score);
|
|
|
|
}
|
|
|
|
|
2012-06-07 09:24:05 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// newScore
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
2012-06-08 19:06:52 +02:00
|
|
|
Score* QmlPlugin::newScore(const QString& name, const QString& part, int measures)
|
2012-06-07 09:24:05 +02:00
|
|
|
{
|
2012-06-08 19:06:52 +02:00
|
|
|
if (mscore->currentScore()) {
|
|
|
|
mscore->currentScore()->endCmd();
|
|
|
|
mscore->endCmd();
|
|
|
|
}
|
2012-06-07 09:24:05 +02:00
|
|
|
Score* score = new Score(MScore::defaultStyle());
|
|
|
|
int view = mscore->appendScore(score);
|
|
|
|
mscore->setCurrentView(0, view);
|
2012-06-08 19:06:52 +02:00
|
|
|
qApp->processEvents();
|
|
|
|
score->setName(name);
|
|
|
|
score->appendPart(part);
|
|
|
|
score->appendMeasures(measures);
|
|
|
|
score->doLayout();
|
|
|
|
score->startCmd();
|
2012-06-07 09:24:05 +02:00
|
|
|
return score;
|
|
|
|
}
|
|
|
|
|
2012-06-08 19:06:52 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// cmd
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void QmlPlugin::cmd(const QString& s)
|
|
|
|
{
|
|
|
|
Shortcut* sc = Shortcut::getShortcut(s.toAscii().data());
|
2012-06-29 18:10:35 +02:00
|
|
|
if (sc)
|
2012-06-08 19:06:52 +02:00
|
|
|
mscore->cmd(sc->action());
|
|
|
|
else
|
|
|
|
printf("QmlPlugin:cmd: not found <%s>\n", qPrintable(s));
|
|
|
|
}
|
|
|
|
|
2012-06-29 18:10:35 +02:00
|
|
|
//---------------------------------------------------------
|
|
|
|
// MsScoreView
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
MsScoreView::MsScoreView(QDeclarativeItem* parent)
|
|
|
|
: QDeclarativeItem(parent)
|
|
|
|
{
|
|
|
|
setFlag(QGraphicsItem::ItemHasNoContents, false);
|
|
|
|
setCacheMode(QGraphicsItem::ItemCoordinateCache);
|
|
|
|
setAcceptedMouseButtons(Qt::LeftButton);
|
|
|
|
score = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setScore
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MsScoreView::setScore(Score* s)
|
|
|
|
{
|
|
|
|
_currentPage = 0;
|
|
|
|
score = s;
|
|
|
|
|
2012-07-09 16:14:48 +02:00
|
|
|
if (score) {
|
|
|
|
score->doLayout();
|
2012-06-29 18:10:35 +02:00
|
|
|
|
2012-07-09 16:14:48 +02:00
|
|
|
Page* page = score->pages()[_currentPage];
|
|
|
|
QRectF pr(page->abbox());
|
|
|
|
qreal m1 = width() / pr.width();
|
|
|
|
qreal m2 = height() / pr.height();
|
|
|
|
mag = qMax(m1, m2);
|
2012-06-29 18:10:35 +02:00
|
|
|
|
2012-07-09 16:14:48 +02:00
|
|
|
_boundingRect = QRectF(0.0, 0.0, pr.width() * mag, pr.height() * mag);
|
2012-06-29 18:10:35 +02:00
|
|
|
|
2012-07-09 16:14:48 +02:00
|
|
|
setWidth(pr.width() * mag);
|
|
|
|
setHeight(pr.height() * mag);
|
|
|
|
}
|
2012-06-29 18:10:35 +02:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// paint
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MsScoreView::paint(QPainter* p, const QStyleOptionGraphicsItem*, QWidget*)
|
|
|
|
{
|
|
|
|
p->setRenderHint(QPainter::Antialiasing, true);
|
|
|
|
p->setRenderHint(QPainter::TextAntialiasing, true);
|
|
|
|
p->fillRect(QRect(0, 0, width(), height()), _color);
|
2012-07-09 16:14:48 +02:00
|
|
|
if (!score)
|
|
|
|
return;
|
2012-06-29 18:10:35 +02:00
|
|
|
p->scale(mag, mag);
|
|
|
|
|
|
|
|
Page* page = score->pages()[_currentPage];
|
|
|
|
QList<const Element*> el;
|
|
|
|
foreach(System* s, *page->systems()) {
|
|
|
|
foreach(MeasureBase* m, s->measures())
|
|
|
|
m->scanElements(&el, collectElements, false);
|
|
|
|
}
|
|
|
|
page->scanElements(&el, collectElements, false);
|
|
|
|
|
|
|
|
foreach(const Element* e, el) {
|
|
|
|
QPointF pos(e->pagePos());
|
|
|
|
p->translate(pos);
|
|
|
|
e->draw(p);
|
|
|
|
p->translate(-pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// setCurrentPage
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MsScoreView::setCurrentPage(int n)
|
|
|
|
{
|
|
|
|
if (score == 0)
|
|
|
|
return;
|
|
|
|
if (n < 0)
|
|
|
|
n = 0;
|
|
|
|
int nn = score->pages().size();
|
|
|
|
if (nn == 0)
|
|
|
|
return;
|
|
|
|
if (n >= nn)
|
|
|
|
n = nn - 1;
|
|
|
|
_currentPage = n;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// nextPage
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MsScoreView::nextPage()
|
|
|
|
{
|
|
|
|
setCurrentPage(_currentPage + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------
|
|
|
|
// prevPage
|
|
|
|
//---------------------------------------------------------
|
|
|
|
|
|
|
|
void MsScoreView::prevPage()
|
|
|
|
{
|
|
|
|
setCurrentPage(_currentPage - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const QRectF& MsScoreView::getGrip(int) const
|
|
|
|
{
|
|
|
|
static const QRectF a;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
const QTransform& MsScoreView::matrix() const
|
|
|
|
{
|
|
|
|
static const QTransform t;
|
|
|
|
return t; // _matrix;
|
|
|
|
}
|
|
|
|
|