add WidgetExplorer object to the rootContext

- WidgetExplorer is parented to the view, and deleted / init'ed along
  with it
- the model is populated before the QML UI is loaded

The explorer now shows a list of widgets, no interaction atm.
This commit is contained in:
Sebastian Kügler 2013-03-21 04:03:05 +01:00
parent bc2b5bd9fc
commit 1619430697
2 changed files with 26 additions and 12 deletions

View File

@ -22,7 +22,9 @@
#include <QApplication> #include <QApplication>
#include <QDebug> #include <QDebug>
#include <QDesktopWidget> #include <QDesktopWidget>
#include <QQmlContext>
#include <QQuickView> #include <QQuickView>
#include <QTimer>
#include <KLocalizedString> #include <KLocalizedString>
#include <Plasma/Package> #include <Plasma/Package>
@ -30,6 +32,7 @@
#include "panelview.h" #include "panelview.h"
#include "view.h" #include "view.h"
#include "scripting/desktopscriptengine.h" #include "scripting/desktopscriptengine.h"
#include "widgetexplorer/widgetexplorer.h"
static const QString s_panelTemplatesPath("plasma-layout-templates/panels/*"); static const QString s_panelTemplatesPath("plasma-layout-templates/panels/*");
@ -37,7 +40,8 @@ static const QString s_panelTemplatesPath("plasma-layout-templates/panels/*");
DesktopCorona::DesktopCorona(QObject *parent) DesktopCorona::DesktopCorona(QObject *parent)
: Plasma::Corona(parent), : Plasma::Corona(parent),
m_desktopWidget(QApplication::desktop()), m_desktopWidget(QApplication::desktop()),
m_widgetExplorer(0) m_widgetExplorer(0),
m_widgetExplorerView(0)
{ {
m_desktopDefaultsConfig = KConfigGroup(KSharedConfig::openConfig(package().filePath("defaults")), "Desktop"); m_desktopDefaultsConfig = KConfigGroup(KSharedConfig::openConfig(package().filePath("defaults")), "Desktop");
@ -52,6 +56,8 @@ DesktopCorona::DesktopCorona(QObject *parent)
connect(this, SIGNAL(screenOwnerChanged(int, int, Plasma::Containment *)), connect(this, SIGNAL(screenOwnerChanged(int, int, Plasma::Containment *)),
this, SLOT(updateScreenOwner(int, int, Plasma::Containment *))); this, SLOT(updateScreenOwner(int, int, Plasma::Containment *)));
checkViews(); checkViews();
//QTimer::singleShot(1000, this, SLOT(showWidgetExplorer())); // just for easier debugging
} }
DesktopCorona::~DesktopCorona() DesktopCorona::~DesktopCorona()
@ -268,29 +274,35 @@ void DesktopCorona::handleContainmentAdded(Plasma::Containment* c)
void DesktopCorona::showWidgetExplorer() void DesktopCorona::showWidgetExplorer()
{ {
if (!m_widgetExplorer) { if (!m_widgetExplorerView) {
m_widgetExplorer = new QQuickView;
m_widgetExplorer->setTitle(i18n("Add Widgets")); m_widgetExplorerView = new QQuickView;
m_widgetExplorerView->setTitle(i18n("Add Widgets"));
m_widgetExplorer = new WidgetExplorer(m_widgetExplorerView);
m_widgetExplorer->populateWidgetList();
m_widgetExplorerView->rootContext()->setContextProperty("widgetExplorer", m_widgetExplorer);
QString expqml = package().filePath("widgetexplorer"); QString expqml = package().filePath("widgetexplorer");
qDebug() << "Script to load for WidgetExplorer: " << expqml; qDebug() << "Script to load for WidgetExplorer: " << expqml;
m_widgetExplorer->setSource(QUrl::fromLocalFile(expqml)); m_widgetExplorerView->setSource(QUrl::fromLocalFile(expqml));
connect(m_widgetExplorer, &QQuickView::statusChanged, this, &DesktopCorona::widgetExplorerStatusChanged); connect(m_widgetExplorerView, &QQuickView::statusChanged, this, &DesktopCorona::widgetExplorerStatusChanged);
connect(m_widgetExplorer, &QQuickView::visibleChanged, this, &DesktopCorona::widgetExplorerClosed); connect(m_widgetExplorerView, &QQuickView::visibleChanged, this, &DesktopCorona::widgetExplorerClosed);
} }
m_widgetExplorer->show(); m_widgetExplorerView->show();
} }
void DesktopCorona::widgetExplorerClosed(bool visible) void DesktopCorona::widgetExplorerClosed(bool visible)
{ {
if (!visible) { if (!visible) {
m_widgetExplorer->deleteLater(); m_widgetExplorerView->deleteLater();
m_widgetExplorer = 0; m_widgetExplorerView = 0;
} }
} }
void DesktopCorona::widgetExplorerStatusChanged() void DesktopCorona::widgetExplorerStatusChanged()
{ {
foreach (QQmlError e, m_widgetExplorer->errors()) { foreach (QQmlError e, m_widgetExplorerView->errors()) {
qWarning() << "Error in WidgetExplorer: " << e.toString(); qWarning() << "Error in WidgetExplorer: " << e.toString();
} }
} }

View File

@ -27,6 +27,7 @@ class QDesktopWidget;
class QQuickView; class QQuickView;
class PanelView; class PanelView;
class View; class View;
class WidgetExplorer;
namespace Plasma namespace Plasma
{ {
@ -91,7 +92,8 @@ private Q_SLOTS:
private: private:
QDesktopWidget *m_desktopWidget; QDesktopWidget *m_desktopWidget;
QList <View *> m_views; QList <View *> m_views;
QQuickView *m_widgetExplorer; WidgetExplorer *m_widgetExplorer;
QQuickView *m_widgetExplorerView;
QHash<Plasma::Containment *, PanelView *> m_panelViews; QHash<Plasma::Containment *, PanelView *> m_panelViews;
KConfigGroup m_desktopDefaultsConfig; KConfigGroup m_desktopDefaultsConfig;
}; };