add plugin type 'dialog', enable plugin without UI

This commit is contained in:
lasconic 2013-07-14 14:31:54 +02:00
parent f877275a81
commit ad4cce5f62
5 changed files with 60 additions and 43 deletions

View file

@ -289,32 +289,33 @@ void PluginCreator::runClicked()
run->setEnabled(false);
item = qobject_cast<QmlPlugin*>(obj);
view = new QQuickView(qml, 0);
view->setResizeMode(QQuickView::SizeViewToRootObject);
item->setParentItem(view->contentItem());
view->show();
if (item->pluginType() == "dock" || item->pluginType() == "dialog") {
view = new QQuickView(qml, 0);
view->setResizeMode(QQuickView::SizeViewToRootObject);
item->setParentItem(view->contentItem());
view->show();
if (item->pluginType() == "dock") {
dock = new QDockWidget("Plugin", 0);
dock->setAttribute(Qt::WA_DeleteOnClose);
dock->setWidget(QWidget::createWindowContainer(view));
Qt::DockWidgetArea area = Qt::RightDockWidgetArea;
if (item->dockArea() == "left")
area = Qt::LeftDockWidgetArea;
else if (item->dockArea() == "top")
area = Qt::TopDockWidgetArea;
else if (item->dockArea() == "bottom")
area = Qt::BottomDockWidgetArea;
addDockWidget(area, dock);
if (item->pluginType() == "dock") {
dock = new QDockWidget("Plugin", 0);
dock->setAttribute(Qt::WA_DeleteOnClose);
dock->setWidget(QWidget::createWindowContainer(view));
Qt::DockWidgetArea area = Qt::RightDockWidgetArea;
if (item->dockArea() == "left")
area = Qt::LeftDockWidgetArea;
else if (item->dockArea() == "top")
area = Qt::TopDockWidgetArea;
else if (item->dockArea() == "bottom")
area = Qt::BottomDockWidgetArea;
addDockWidget(area, dock);
connect(dock, SIGNAL(destroyed()), SLOT(closePlugin()));
dock->widget()->setAttribute(Qt::WA_DeleteOnClose);
}
view->raise();
connect(view, SIGNAL(destroyed()), SLOT(closePlugin()));
}
view->raise();
connect(qml, SIGNAL(quit()), SLOT(closePlugin()));
connect(view, SIGNAL(destroyed()), SLOT(closePlugin()));
if (dock) {
connect(dock, SIGNAL(destroyed()), SLOT(closePlugin()));
dock->widget()->setAttribute(Qt::WA_DeleteOnClose);
}
if (mscore->currentScore())
mscore->currentScore()->startCmd();

View file

@ -355,30 +355,43 @@ void MuseScore::pluginTriggered(int idx)
{
QString pp = plugins[idx];
QQuickView* view = new QQuickView(qml(), 0);
view->setSource(QUrl::fromLocalFile(pp));
view->setResizeMode(QQuickView::SizeViewToRootObject);
QmlPlugin* p = (QmlPlugin*)(view->rootObject());
QQmlEngine* engine = view->engine();
QQmlEngine* engine = qml();
if (p->pluginType() == "dock") {
QDockWidget* dock = new QDockWidget("Plugin", 0);
dock->setAttribute(Qt::WA_DeleteOnClose);
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;
QWidget* w = QWidget::createWindowContainer(view);
dock->setWidget(w);
addDockWidget(area, dock);
connect(engine, SIGNAL(quit()), dock, SLOT(close()));
QQmlComponent component(engine);
component.loadUrl(QUrl::fromLocalFile(pp));
QObject* obj = component.create();
if (obj == 0) {
foreach(QQmlError e, component.errors())
qDebug(" line %d: %s\n", e.line(), qPrintable(e.description()));
return;
}
else {
connect(engine, SIGNAL(quit()), view, SLOT(close()));
QmlPlugin* p = qobject_cast<QmlPlugin*>(obj);
if (p->pluginType() == "dock" || p->pluginType() == "dialog") {
QQuickView* view = new QQuickView(engine, 0);
view->setResizeMode(QQuickView::SizeViewToRootObject);
p->setParentItem(view->contentItem());
view->show();
if (p->pluginType() == "dock") {
QDockWidget* dock = new QDockWidget("Plugin", 0);
dock->setAttribute(Qt::WA_DeleteOnClose);
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;
QWidget* w = QWidget::createWindowContainer(view);
dock->setWidget(w);
addDockWidget(area, dock);
connect(engine, SIGNAL(quit()), dock, SLOT(close()));
}
else {
connect(engine, SIGNAL(quit()), view, SLOT(close()));
view->show();
}
}
if (cs)

View file

@ -6,6 +6,7 @@ MuseScore {
menuPath: "Plugins.helloQml"
version: "2.0"
description: qsTr("This demo plugin shows some basic tasks.")
pluginType: "dialog"
width: 150
height: 75

View file

@ -6,6 +6,7 @@ MuseScore {
menuPath: "Plugins.scorelist"
version: "2.0"
description: "This test plugin interates through the score list."
pluginType: "dialog"
width: 150
height: 75

View file

@ -5,6 +5,7 @@ MuseScore {
version: "1.0"
description: "Demo plugin to demonstrate the use of a ScoreView"
menuPath: "Plugins.ScoreView"
pluginType: "dialog"
width: 400
height: 400