MuseScore/mscore/qmlplugin.cpp

133 lines
3.6 KiB
C++
Raw Normal View History

2012-12-10 09:15:50 +01:00
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2002-2012 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 "qmlplugin.h"
#include "shortcut.h"
#include "musescoreCore.h"
#include "libmscore/score.h"
2013-05-13 18:49:17 +02:00
namespace Ms {
2012-12-10 09:15:50 +01:00
extern MuseScoreCore* mscoreCore;
//---------------------------------------------------------
// QmlPlugin
//---------------------------------------------------------
2013-05-16 17:06:31 +02:00
QmlPlugin::QmlPlugin(QQuickItem* parent)
: QQuickItem(parent)
2012-12-10 09:15:50 +01:00
{
msc = mscoreCore;
}
QmlPlugin::~QmlPlugin()
{
}
//---------------------------------------------------------
// curScore
//---------------------------------------------------------
Score* QmlPlugin::curScore() const
{
return msc->currentScore();
}
//---------------------------------------------------------
// scores
//---------------------------------------------------------
2013-05-16 17:06:31 +02:00
QQmlListProperty<Score> QmlPlugin::scores()
2012-12-10 09:15:50 +01:00
{
2013-05-16 17:06:31 +02:00
return QQmlListProperty<Score>(this, msc->scores());
2012-12-10 09:15:50 +01:00
}
//---------------------------------------------------------
// writeScore
//---------------------------------------------------------
bool QmlPlugin::writeScore(Score* s, const QString& name, const QString& ext)
{
if(!s)
return false;
return msc->saveAs(s, true, name, ext);
}
//---------------------------------------------------------
// readScore
//---------------------------------------------------------
Score* QmlPlugin::readScore(const QString& name)
{
return msc->openScore(name);
}
//---------------------------------------------------------
// newElement
//---------------------------------------------------------
2013-07-11 09:33:04 +02:00
Ms::Element* QmlPlugin::newElement(int t)
2012-12-10 09:15:50 +01:00
{
Score* score = curScore();
if (score == 0)
return 0;
Element* e = Element::create(ElementType(t), score);
2014-04-25 18:43:25 +02:00
Ms::MScore::qml()->setObjectOwnership(e, QQmlEngine::CppOwnership);
2014-04-25 14:26:32 +02:00
return e;
2012-12-10 09:15:50 +01:00
}
//---------------------------------------------------------
// newScore
//---------------------------------------------------------
Score* QmlPlugin::newScore(const QString& name, const QString& part, int measures)
{
if (msc->currentScore()) {
msc->currentScore()->endCmd();
msc->endCmd();
}
Score* score = new Score(MScore::defaultStyle());
score->setName(name);
score->appendPart(part);
score->appendMeasures(measures);
score->doLayout();
int view = msc->appendScore(score);
msc->setCurrentView(0, view);
qApp->processEvents();
2012-12-10 09:15:50 +01:00
score->startCmd();
return score;
}
//---------------------------------------------------------
// cmd
//---------------------------------------------------------
void QmlPlugin::cmd(const QString& s)
{
2013-01-02 16:39:19 +01:00
Shortcut* sc = Shortcut::getShortcut(s.toLatin1().data());
2012-12-10 09:15:50 +01:00
if (sc)
msc->cmd(sc->action());
else
2014-03-04 16:48:06 +01:00
qDebug("QmlPlugin:cmd: not found <%s>", qPrintable(s));
2012-12-10 09:15:50 +01:00
}
//---------------------------------------------------------
// newQProcess
//---------------------------------------------------------
MsProcess* QmlPlugin::newQProcess()
{
return 0; // TODO: new MsProcess(this);
}
2013-05-13 18:49:17 +02:00
}
2012-12-10 09:15:50 +01:00