diff --git a/src/shell/desktopcorona.cpp b/src/shell/desktopcorona.cpp index 073481ddc..1155ad1ff 100644 --- a/src/shell/desktopcorona.cpp +++ b/src/shell/desktopcorona.cpp @@ -22,6 +22,8 @@ #include #include #include +#include + #include #include "panelview.h" @@ -33,7 +35,8 @@ static const QString s_panelTemplatesPath("plasma-layout-templates/panels/*"); DesktopCorona::DesktopCorona(QObject *parent) : Plasma::Corona(parent), - m_desktopWidget(QApplication::desktop()) + m_desktopWidget(QApplication::desktop()), + m_widgetExplorer(0) { m_desktopDefaultsConfig = KConfigGroup(KSharedConfig::openConfig(package().filePath("defaults")), "Desktop"); @@ -43,6 +46,7 @@ DesktopCorona::DesktopCorona(QObject *parent) this, SLOT(screenCountChanged(int))); connect(m_desktopWidget, SIGNAL(workAreaResized(int)), this, SLOT(workAreaResized(int))); + connect(this, &DesktopCorona::containmentAdded, this, &DesktopCorona::handleContainmentAdded); connect(this, SIGNAL(screenOwnerChanged(int, int, Plasma::Containment *)), this, SLOT(updateScreenOwner(int, int, Plasma::Containment *))); @@ -256,6 +260,39 @@ void DesktopCorona::updateScreenOwner(int wasScreen, int isScreen, Plasma::Conta } } +void DesktopCorona::handleContainmentAdded(Plasma::Containment* c) +{ + connect(c, &Plasma::Containment::showAddWidgetsInterface, this, &DesktopCorona::showWidgetExplorer); +} + +void DesktopCorona::showWidgetExplorer() +{ + if (!m_widgetExplorer) { + m_widgetExplorer = new QQuickView; + QString expqml = package().filePath("widgetexplorer"); + qDebug() << "Script to load for WidgetExplorer: " << expqml; + m_widgetExplorer->setSource(QUrl::fromLocalFile(expqml)); + connect(m_widgetExplorer, &QQuickView::statusChanged, this, &DesktopCorona::widgetExplorerStatusChanged); + connect(m_widgetExplorer, &QQuickView::visibleChanged, this, &DesktopCorona::widgetExplorerClosed); + } + m_widgetExplorer->show(); +} + +void DesktopCorona::widgetExplorerClosed(bool visible) +{ + if (!visible) { + m_widgetExplorer->deleteLater(); + m_widgetExplorer = 0; + } +} + +void DesktopCorona::widgetExplorerStatusChanged() +{ + foreach (QQmlError e, m_widgetExplorer->errors()) { + qWarning() << "Error in WidgetExplorer: " << e.toString(); + } +} + void DesktopCorona::printScriptError(const QString &error) { qWarning() << error; diff --git a/src/shell/desktopcorona.h b/src/shell/desktopcorona.h index 2fd700345..dc8d5d656 100644 --- a/src/shell/desktopcorona.h +++ b/src/shell/desktopcorona.h @@ -24,6 +24,7 @@ class * Free Software Foundation, Inc., #include "plasma/corona.h" class QDesktopWidget; +class QQuickView; class PanelView; class View; @@ -81,9 +82,16 @@ protected Q_SLOTS: void printScriptError(const QString &error); void printScriptMessage(const QString &message); +private Q_SLOTS: + void handleContainmentAdded(Plasma::Containment *c); + void showWidgetExplorer(); + void widgetExplorerClosed(bool visible); + void widgetExplorerStatusChanged(); + private: QDesktopWidget *m_desktopWidget; QList m_views; + QQuickView *m_widgetExplorer; QHash m_panelViews; KConfigGroup m_desktopDefaultsConfig; }; diff --git a/src/shell/shellpackage.cpp b/src/shell/shellpackage.cpp index 2aff402c3..70fadd92e 100644 --- a/src/shell/shellpackage.cpp +++ b/src/shell/shellpackage.cpp @@ -31,6 +31,7 @@ void ShellPackageStructure::initPackage(Plasma::Package *package) //Directories package->addDirectoryDefinition("components", "components", i18n("UI components")); package->addDirectoryDefinition("views", "views", i18n("User interface for the views that will show containments")); + package->addDirectoryDefinition("explorer", "explorer", i18n("Explorer UI for adding widgets")); package->setMimeTypes("components", QStringList() << "text/x-qml"); package->setMimeTypes("views", QStringList() << "text/x-qml"); @@ -46,7 +47,7 @@ void ShellPackageStructure::initPackage(Plasma::Package *package) package->addFileDefinition("compactapplet", "components/CompactApplet.qml", i18n("QML component that shows an applet in a popup")); package->addFileDefinition("configurationui", "components/Configuration.qml", i18n("QML component for the configuratuion dialog")); package->addFileDefinition("defaultcompactrepresentation", "components/DefaultCompactRepresentation.qml", i18n("Compact representation of an applet when collapsed in a popup, for instance as an icon. applets can override this component.")); - package->addFileDefinition("widgetexplorer", "components/WidgetExplorer.qml", i18n("Widgets explorer UI")); + package->addFileDefinition("widgetexplorer", "explorer/WidgetExplorer.qml", i18n("Widgets explorer UI")); package->addFileDefinition("panelconfigurationui", "components/PanelConfiguration.qml", i18n("Panel configuration UI"));