Remove QDeclarativeView from DeclarativeScript
The view is never shown or used in any way except to create the QDeclarativeEngine. So instead of using a view as a wrapper, let's create a QDeclarativeEngine and a Component and create the script from the Component. To have Plasma.Dialog working we also need to add the created script item to a QGraphicsScene.
This commit is contained in:
parent
edb074cbc2
commit
b88f7ad8ce
2 changed files with 30 additions and 14 deletions
|
@ -529,7 +529,9 @@ void KWin::ScriptUnloaderAgent::scriptUnload(qint64 id)
|
|||
|
||||
KWin::DeclarativeScript::DeclarativeScript(int id, QString scriptName, QString pluginName, QObject* parent)
|
||||
: AbstractScript(id, scriptName, pluginName, parent)
|
||||
, m_view(new QDeclarativeView())
|
||||
, m_engine(new QDeclarativeEngine(this))
|
||||
, m_component(new QDeclarativeComponent(m_engine, this))
|
||||
, m_scene(new QGraphicsScene(this))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -542,21 +544,14 @@ void KWin::DeclarativeScript::run()
|
|||
if (running()) {
|
||||
return;
|
||||
}
|
||||
m_view->setAttribute(Qt::WA_TranslucentBackground);
|
||||
m_view->setWindowFlags(Qt::X11BypassWindowManagerHint);
|
||||
m_view->setResizeMode(QDeclarativeView::SizeViewToRootObject);
|
||||
QPalette pal = m_view->palette();
|
||||
pal.setColor(m_view->backgroundRole(), Qt::transparent);
|
||||
m_view->setPalette(pal);
|
||||
|
||||
|
||||
foreach (const QString &importPath, KGlobal::dirs()->findDirs("module", "imports")) {
|
||||
m_view->engine()->addImportPath(importPath);
|
||||
m_engine->addImportPath(importPath);
|
||||
}
|
||||
|
||||
// add read config
|
||||
KDeclarative kdeclarative;
|
||||
kdeclarative.setDeclarativeEngine(m_view->engine());
|
||||
kdeclarative.setDeclarativeEngine(m_engine);
|
||||
kdeclarative.initialize();
|
||||
kdeclarative.setupBindings();
|
||||
installScriptFunctions(kdeclarative.scriptEngine());
|
||||
|
@ -568,9 +563,23 @@ void KWin::DeclarativeScript::run()
|
|||
qmlRegisterType<KWin::ScriptingClientModel::ClientFilterModel>("org.kde.kwin", 0, 1, "ClientFilterModel");
|
||||
qmlRegisterType<KWin::Client>();
|
||||
|
||||
m_view->rootContext()->setContextProperty("options", options);
|
||||
m_engine->rootContext()->setContextProperty("options", options);
|
||||
|
||||
m_view->setSource(QUrl::fromLocalFile(scriptFile().fileName()));
|
||||
m_component->loadUrl(QUrl::fromLocalFile(scriptFile().fileName()));
|
||||
if (m_component->isLoading()) {
|
||||
connect(m_component, SIGNAL(statusChanged(QDeclarativeComponent::Status)), SLOT(createComponent()));
|
||||
} else {
|
||||
createComponent();
|
||||
}
|
||||
}
|
||||
|
||||
void KWin::DeclarativeScript::createComponent()
|
||||
{
|
||||
if (m_component->isError()) {
|
||||
kDebug(1212) << "Component failed to load: " << m_component->errors();
|
||||
} else {
|
||||
m_scene->addItem(qobject_cast<QDeclarativeItem*>(m_component->create()));
|
||||
}
|
||||
setRunning(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,9 +30,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
#include <QStringList>
|
||||
#include <QtScript/QScriptEngineAgent>
|
||||
|
||||
class QDeclarativeComponent;
|
||||
class QDeclarativeEngine;
|
||||
class QAction;
|
||||
class QDeclarativeView;
|
||||
class QDBusPendingCallWatcher;
|
||||
class QGraphicsScene;
|
||||
class QMenu;
|
||||
class QMutex;
|
||||
class QScriptEngine;
|
||||
|
@ -275,8 +277,13 @@ public:
|
|||
public Q_SLOTS:
|
||||
Q_SCRIPTABLE void run();
|
||||
|
||||
private Q_SLOTS:
|
||||
void createComponent();
|
||||
|
||||
private:
|
||||
QScopedPointer<QDeclarativeView> m_view;
|
||||
QDeclarativeEngine *m_engine;
|
||||
QDeclarativeComponent *m_component;
|
||||
QGraphicsScene *m_scene;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue