widgetexplorer is a pure qobject

doesn't try to load qml
This commit is contained in:
Marco Martin 2013-10-30 10:51:27 +01:00
parent 10a1a422e9
commit 8fbc0a4493
2 changed files with 6 additions and 102 deletions

View File

@ -28,7 +28,6 @@
#include <klocalizedstring.h>
#include <kservicetypetrader.h>
#include <kdeclarative/qmlobject.h>
#include <Plasma/Applet>
#include <Plasma/Corona>
@ -64,7 +63,6 @@ public:
containment(0),
itemModel(w),
filterModel(w),
qmlObject(new QmlObject(w)),
desktopView(0)
{
}
@ -72,7 +70,6 @@ public:
void initFilters();
void initRunningApplets();
void containmentDestroyed();
void setLocation(Plasma::Types::Location loc);
/**
* Tracks a new running applet
@ -84,9 +81,6 @@ public:
*/
void appletRemoved(Plasma::Applet *applet);
//this orientation is just for convenience, is the location that is important
Qt::Orientation orientation;
Plasma::Types::Location location;
WidgetExplorer *q;
QString application;
Plasma::Containment *containment;
@ -101,8 +95,6 @@ public:
KCategorizedItemsViewModels::DefaultFilterModel filterModel;
DefaultItemFilterProxyModel filterItemModel;
DesktopView *desktopView;
QmlObject *qmlObject;
};
void WidgetExplorerPrivate::initFilters()
@ -154,28 +146,6 @@ void WidgetExplorerPrivate::initFilters()
}
void WidgetExplorerPrivate::setLocation(const Plasma::Types::Location loc)
{
Qt::Orientation orient;
if (loc == Plasma::Types::LeftEdge || loc == Plasma::Types::RightEdge) {
orient = Qt::Vertical;
} else {
orient = Qt::Horizontal;
}
if (location == loc) {
return;
}
location = loc;
if (orientation == orient) {
return;
}
emit q->orientationChanged();
}
QObject *WidgetExplorer::widgetsModel() const
{
return &d->filterItemModel;
@ -307,11 +277,10 @@ void WidgetExplorerPrivate::appletRemoved(Plasma::Applet *applet)
//WidgetExplorer
WidgetExplorer::WidgetExplorer(QQuickItem *parent)
:QQuickItem(parent),
WidgetExplorer::WidgetExplorer(QObject *parent)
: QObject(parent),
d(new WidgetExplorerPrivate(this))
{
setLocation(Plasma::Types::LeftEdge);
populateWidgetList();
d->initRunningApplets();
d->filterItemModel.setSortCaseSensitivity(Qt::CaseInsensitive);
@ -325,21 +294,6 @@ WidgetExplorer::~WidgetExplorer()
delete d;
}
void WidgetExplorer::setLocation(Plasma::Types::Location loc)
{
d->setLocation(loc);
emit(locationChanged(loc));
}
Plasma::Types::Location WidgetExplorer::location() const
{
return d->location;
}
Qt::Orientation WidgetExplorer::orientation() const
{
return d->orientation;
}
DesktopView *WidgetExplorer::desktopView()
{
@ -370,25 +324,6 @@ QString WidgetExplorer::application()
return d->application;
}
void WidgetExplorer::setSource(const QUrl &source)
{
d->qmlObject->setInitializationDelayed(true);
d->qmlObject->setSource(source);
d->qmlObject->engine()->rootContext()->setContextProperty("widgetExplorer", this);
d->qmlObject->completeInitialization();
QQuickItem *i = qobject_cast<QQuickItem *>(d->qmlObject->rootObject());
i->setParentItem(this);
//set anchors
QQmlExpression expr(d->qmlObject->engine()->rootContext(), d->qmlObject->rootObject(), "parent");
QQmlProperty prop(d->qmlObject->rootObject(), "anchors.fill");
prop.write(expr.evaluate());
}
QUrl WidgetExplorer::source() const
{
return d->qmlObject->source();
}
void WidgetExplorer::setContainment(Plasma::Containment *containment)
{
if (d->containment != containment) {
@ -402,7 +337,6 @@ void WidgetExplorer::setContainment(Plasma::Containment *containment)
connect(d->containment, SIGNAL(destroyed(QObject*)), this, SLOT(containmentDestroyed()));
connect(d->containment, SIGNAL(immutabilityChanged(Plasma::Types::ImmutabilityType)), this, SLOT(immutabilityChanged(Plasma::Types::ImmutabilityType)));
setLocation(containment->location());
}
d->initRunningApplets();

View File

@ -24,7 +24,7 @@
#define WIDGETEXPLORER_H
#include <QAction>
#include <QQuickItem>
#include <QObject>
#include "plasmaappletitemmodel_p.h"
@ -50,7 +50,7 @@ Q_SIGNALS:
void separatorChanged();
};
class WidgetExplorer : public QQuickItem
class WidgetExplorer : public QObject
{
Q_OBJECT
@ -75,37 +75,14 @@ class WidgetExplorer : public QQuickItem
*/
Q_PROPERTY(QList<QObject *> extraActions READ extraActions NOTIFY extraActionsChanged)
/**
* Plasma location of the panel containment the controller is associated to
*/
Q_PROPERTY(Plasma::Types::Location location READ location NOTIFY locationChanged)
Q_ENUMS(Location)
/**
* Orientation the controller will be disaplayed, depends from location
*/
Q_PROPERTY(Qt::Orientation orientation READ orientation NOTIFY orientationChanged)
Q_PROPERTY(DesktopView *desktopView READ desktopView WRITE setDesktopView NOTIFY desktopViewChanged)
public:
explicit WidgetExplorer(QQuickItem *parent = 0);
explicit WidgetExplorer(QObject *parent = 0);
~WidgetExplorer();
QString application();
/**
* Sets the path of the QML file to parse and execute
*
* @param path the absolute path of a QML file
*/
void setSource(const QUrl &source);
/**
* @return the absolute path of the current QML file
*/
QUrl source() const;
/**
* Populates the widget list for the given application. This must be called
* before the widget explorer will be usable as the widget list will remain
@ -132,11 +109,6 @@ public:
Plasma::Corona *corona() const;
void setLocation(const Plasma::Types::Location loc);
Plasma::Types::Location location() const;
Qt::Orientation orientation() const;
DesktopView *desktopView();
void setDesktopView(DesktopView *view);
@ -155,8 +127,6 @@ public:
//Q_INVOKABLE QPoint tooltipPosition(QGraphicsObject *item, int tipWidth, int tipHeight);
Q_SIGNALS:
void locationChanged(Plasma::Types::Location loc);
void orientationChanged();
void widgetsMenuActionsChanged();
void extraActionsChanged();
void closed();