From ad4cce5f62737e1a2ddd1bc87b8a82bb0c100d2e Mon Sep 17 00:00:00 2001 From: lasconic Date: Sun, 14 Jul 2013 14:31:54 +0200 Subject: [PATCH] add plugin type 'dialog', enable plugin without UI --- mscore/pluginCreator.cpp | 45 +++++++++++------------ mscore/plugins.cpp | 55 ++++++++++++++++++----------- share/plugins/helloqml/helloqml.qml | 1 + share/plugins/scorelist.qml | 1 + share/plugins/view.qml | 1 + 5 files changed, 60 insertions(+), 43 deletions(-) diff --git a/mscore/pluginCreator.cpp b/mscore/pluginCreator.cpp index 6d9ca5eec4..e23eb717af 100644 --- a/mscore/pluginCreator.cpp +++ b/mscore/pluginCreator.cpp @@ -289,32 +289,33 @@ void PluginCreator::runClicked() run->setEnabled(false); item = qobject_cast(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(); diff --git a/mscore/plugins.cpp b/mscore/plugins.cpp index 4a4f872b50..7c7ed761ff 100644 --- a/mscore/plugins.cpp +++ b/mscore/plugins.cpp @@ -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(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) diff --git a/share/plugins/helloqml/helloqml.qml b/share/plugins/helloqml/helloqml.qml index e1c8f9f999..a12068cc4b 100644 --- a/share/plugins/helloqml/helloqml.qml +++ b/share/plugins/helloqml/helloqml.qml @@ -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 diff --git a/share/plugins/scorelist.qml b/share/plugins/scorelist.qml index 739aab1ff6..30e8439184 100644 --- a/share/plugins/scorelist.qml +++ b/share/plugins/scorelist.qml @@ -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 diff --git a/share/plugins/view.qml b/share/plugins/view.qml index 176cdd4b1f..da0d8382e6 100644 --- a/share/plugins/view.qml +++ b/share/plugins/view.qml @@ -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