get rid of WidgetExplorerView

The widget explorer window is done by a Dialog, allowing for more flexibility in shell packages
This commit is contained in:
Marco Martin 2013-10-21 22:05:19 +02:00
parent 2f042a51f6
commit 876ade83a0
9 changed files with 341 additions and 451 deletions

View File

@ -100,6 +100,7 @@ void DialogProxy::setMainItem(QQuickItem *mainItem)
if (mainItem->metaObject()->indexOfSignal("heightChanged")) { if (mainItem->metaObject()->indexOfSignal("heightChanged")) {
connect(mainItem, SIGNAL(heightChanged()), m_syncTimer, SLOT(start())); connect(mainItem, SIGNAL(heightChanged()), m_syncTimer, SLOT(start()));
} }
syncToMainItemSize();
} }
//if this is called in Compenent.onCompleted we have to wait a loop the item is added to a scene //if this is called in Compenent.onCompleted we have to wait a loop the item is added to a scene
@ -354,7 +355,7 @@ void DialogProxy::syncToMainItemSize()
void DialogProxy::setAttribute(int attribute, bool on) void DialogProxy::setAttribute(int attribute, bool on)
{ {
setAttribute((Qt::WidgetAttribute)attribute, on); //setAttribute((Qt::WidgetAttribute)attribute, on);
if (attribute == Qt::WA_X11NetWmWindowTypeDock) { if (attribute == Qt::WA_X11NetWmWindowTypeDock) {
KWindowSystem::setOnAllDesktops(winId(), true); KWindowSystem::setOnAllDesktops(winId(), true);

View File

@ -39,7 +39,6 @@ set(widgetexplorer_SRC
widgetexplorer/kcategorizeditemsviewmodels.cpp widgetexplorer/kcategorizeditemsviewmodels.cpp
widgetexplorer/plasmaappletitemmodel.cpp widgetexplorer/plasmaappletitemmodel.cpp
widgetexplorer/widgetexplorer.cpp widgetexplorer/widgetexplorer.cpp
widgetexplorer/widgetexplorerview.cpp
) )
add_executable(plasma-shell add_executable(plasma-shell

View File

@ -22,161 +22,228 @@ import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.qtextracomponents 2.0 import org.kde.qtextracomponents 2.0
Item { PlasmaCore.Dialog {
id: main id: dialog
location: PlasmaCore.Types.LeftEdge
width: 240 Component.onCompleted: dialog.visible = true;
height: 800 mainItem: Item {
//this is used to perfectly align the filter field and delegates id: main
property int cellWidth: theme.defaultFont.pixelSize * 20
PlasmaCore.FrameSvgItem { width: 240
imagePath: "dialogs/background" height: 800
anchors.fill: parent //this is used to perfectly align the filter field and delegates
anchors.margins: margins property int cellWidth: theme.defaultFont.pixelSize * 20
//color: "orange"
//opacity: 0.3
}
property int minimumWidth: cellWidth + ( property int minimumWidth: cellWidth + (
widgetExplorer.orientation == Qt.Horizontal widgetExplorer.orientation == Qt.Horizontal
? 0 ? 0
: (scrollBar.width + 4 * 2) // 4 * 2 == left and right margins : (scrollBar.width + 4 * 2) // 4 * 2 == left and right margins
) )
property int minimumHeight: topBar.height + list.delegateHeight + (widgetExplorer.orientation == Qt.Horizontal ? scrollBar.height : 0) + 4 property int minimumHeight: 800//topBar.height + list.delegateHeight + (widgetExplorer.orientation == Qt.Horizontal ? scrollBar.height : 0) + 4
property Item getWidgetsButton property Item getWidgetsButton
property Item categoryButton property Item categoryButton
PlasmaComponents.ContextMenu { PlasmaComponents.ContextMenu {
id: categoriesDialog id: categoriesDialog
visualParent: main.categoryButton visualParent: main.categoryButton
} }
Repeater { Repeater {
parent: categoriesDialog parent: categoriesDialog
model: widgetExplorer.filterModel model: widgetExplorer.filterModel
delegate: PlasmaComponents.MenuItem { delegate: Item {
text: display PlasmaComponents.MenuItem {
separator: model["separator"] != undefined ? model["separator"] : false text: display
onClicked: { separator: model["separator"] != undefined ? model["separator"] : false
list.contentX = 0 onClicked: {
list.contentY = 0 list.contentX = 0
main.categoryButton.text = display list.contentY = 0
widgetExplorer.widgetsModel.filterQuery = model["filterData"] main.categoryButton.text = display
widgetExplorer.widgetsModel.filterType = model["filterType"] widgetExplorer.widgetsModel.filterQuery = model["filterData"]
widgetExplorer.widgetsModel.filterType = model["filterType"]
}
Component.onCompleted: {
parent = categoriesDialog
}
}
} }
}
PlasmaComponents.ContextMenu {
id: getWidgetsDialog
visualParent: main.getWidgetsButton
}
Repeater {
parent: getWidgetsDialog
model: widgetExplorer.widgetsMenuActions
delegate: Item {
PlasmaComponents.MenuItem {
icon: modelData.icon
text: modelData.text
separator: modelData.separator
onClicked: modelData.trigger()
Component.onCompleted: {
parent = getWidgetsDialog
}
}
}
}
PlasmaCore.Dialog {
id: tooltipDialog
property Item appletDelegate
Component.onCompleted: { Component.onCompleted: {
parent = categoriesDialog tooltipDialog.setAttribute(Qt.WA_X11NetWmWindowTypeToolTip, true)
tooltipDialog.windowFlags = Qt.Window|Qt.WindowStaysOnTopHint|Qt.X11BypassWindowManagerHint
}
onAppletDelegateChanged: {
if (!appletDelegate) {
toolTipHideTimer.restart()
toolTipShowTimer.running = false
} else if (tooltipDialog.visible) {
var point = main.tooltipPosition()
tooltipDialog.x = point.x
tooltipDialog.y = point.y
} else {
toolTipShowTimer.restart()
toolTipHideTimer.running = false
}
}
mainItem: Tooltip { id: tooltipWidget }
Behavior on x {
enabled: widgetExplorer.orientation == Qt.Horizontal
NumberAnimation { duration: 250 }
}
Behavior on y {
enabled: widgetExplorer.orientation == Qt.Vertical
NumberAnimation { duration: 250 }
} }
} }
} Timer {
id: toolTipShowTimer
PlasmaComponents.ContextMenu { interval: 500
id: getWidgetsDialog repeat: false
visualParent: main.getWidgetsButton onTriggered: {
}
Repeater {
parent: getWidgetsDialog
model: widgetExplorer.widgetsMenuActions
delegate: PlasmaComponents.MenuItem {
icon: modelData.icon
text: modelData.text
separator: modelData.separator
onClicked: modelData.trigger()
Component.onCompleted: {
parent = getWidgetsDialog
}
}
}
PlasmaCore.Dialog {
id: tooltipDialog
property Item appletDelegate
Component.onCompleted: {
tooltipDialog.setAttribute(Qt.WA_X11NetWmWindowTypeToolTip, true)
tooltipDialog.windowFlags = Qt.Window|Qt.WindowStaysOnTopHint|Qt.X11BypassWindowManagerHint
}
onAppletDelegateChanged: {
if (!appletDelegate) {
toolTipHideTimer.restart()
toolTipShowTimer.running = false
} else if (tooltipDialog.visible) {
var point = main.tooltipPosition() var point = main.tooltipPosition()
tooltipDialog.x = point.x tooltipDialog.x = point.x
tooltipDialog.y = point.y tooltipDialog.y = point.y
} else { tooltipDialog.visible = true
toolTipShowTimer.restart()
toolTipHideTimer.running = false
} }
} }
mainItem: Tooltip { id: tooltipWidget } Timer {
Behavior on x { id: toolTipHideTimer
enabled: widgetExplorer.orientation == Qt.Horizontal interval: 1000
NumberAnimation { duration: 250 } repeat: false
onTriggered: tooltipDialog.visible = false
} }
Behavior on y { function tooltipPosition() {
enabled: widgetExplorer.orientation == Qt.Vertical return widgetExplorer.tooltipPosition(tooltipDialog.appletDelegate, tooltipDialog.width, tooltipDialog.height);
NumberAnimation { duration: 250 }
} }
}
Timer {
id: toolTipShowTimer
interval: 500
repeat: false
onTriggered: {
var point = main.tooltipPosition()
tooltipDialog.x = point.x
tooltipDialog.y = point.y
tooltipDialog.visible = true
}
}
Timer {
id: toolTipHideTimer
interval: 1000
repeat: false
onTriggered: tooltipDialog.visible = false
}
function tooltipPosition() {
return widgetExplorer.tooltipPosition(tooltipDialog.appletDelegate, tooltipDialog.width, tooltipDialog.height);
}
Loader { Loader {
id: topBar id: topBar
property Item categoryButton property Item categoryButton
sourceComponent: (widgetExplorer.orientation == Qt.Horizontal) ? horizontalTopBarComponent : verticalTopBarComponent sourceComponent: (widgetExplorer.orientation == Qt.Horizontal) ? horizontalTopBarComponent : verticalTopBarComponent
height: item.height + 2 height: item.height + 2
anchors {
top: parent.top
left: parent.left
right: parent.right
topMargin: widgetExplorer.orientation == Qt.Horizontal ? 4 : 0
leftMargin: 4
}
}
Component {
id: horizontalTopBarComponent
Item {
anchors { anchors {
top: parent.top top: parent.top
left: parent.left left: parent.left
right: parent.right right: parent.right
topMargin: widgetExplorer.orientation == Qt.Horizontal ? 4 : 0
leftMargin: 4
} }
height: filterField.height }
Row {
spacing: 5 Component {
id: horizontalTopBarComponent
Item {
anchors { anchors {
top: parent.top
left: parent.left left: parent.left
leftMargin: 2 right: parent.right
}
height: filterField.height
Row {
spacing: 5
anchors {
left: parent.left
leftMargin: 2
}
PlasmaComponents.TextField {
id: filterField
width: list.width / Math.floor(list.width / cellWidth) - 4
clearButtonShown: true
placeholderText: i18n("Enter search term...")
onTextChanged: {
list.contentX = 0
list.contentY = 0
widgetExplorer.widgetsModel.searchTerm = text
}
Component.onCompleted: forceActiveFocus()
}
PlasmaComponents.Button {
id: categoryButton
text: i18n("Categories")
onClicked: categoriesDialog.open(0, categoryButton.height)
}
}
Row {
anchors.right: parent.right
spacing: 5
PlasmaComponents.Button {
id: getWidgetsButton
iconSource: "get-hot-new-stuff"
text: i18n("Get new widgets")
onClicked: getWidgetsDialog.open()
}
Repeater {
model: widgetExplorer.extraActions.length
PlasmaComponents.Button {
iconSource: widgetExplorer.extraActions[modelData].icon
text: widgetExplorer.extraActions[modelData].text
onClicked: {
widgetExplorer.extraActions[modelData].trigger()
}
}
}
PlasmaComponents.ToolButton {
iconSource: "window-close"
onClicked: widgetExplorer.close()
}
}
Component.onCompleted: {
main.getWidgetsButton = getWidgetsButton
main.categoryButton = categoryButton
}
}
}
Component {
id: verticalTopBarComponent
Column {
anchors.top: parent.top
anchors.left:parent.left
anchors.right: parent.right
spacing: 4
PlasmaComponents.ToolButton {
anchors.right: parent.right
iconSource: "window-close"
onClicked: widgetExplorer.close()
} }
PlasmaComponents.TextField { PlasmaComponents.TextField {
id: filterField anchors {
width: list.width / Math.floor(list.width / cellWidth) - 4 left: parent.left
right: parent.right
}
clearButtonShown: true clearButtonShown: true
placeholderText: i18n("Enter search term...") placeholderText: i18n("Enter search term...")
onTextChanged: { onTextChanged: {
@ -187,15 +254,100 @@ Item {
Component.onCompleted: forceActiveFocus() Component.onCompleted: forceActiveFocus()
} }
PlasmaComponents.Button { PlasmaComponents.Button {
anchors {
left: parent.left
right: parent.right
}
id: categoryButton id: categoryButton
text: i18n("Categories") text: i18n("Categories")
onClicked: categoriesDialog.open(0, categoryButton.height) onClicked: categoriesDialog.open(0, categoryButton.height)
} }
Component.onCompleted: {
main.categoryButton = categoryButton
}
} }
Row { }
anchors.right: parent.right
spacing: 5 MouseEventListener {
id: listParent
anchors {
top: topBar.bottom
left: parent.left
right: widgetExplorer.orientation == Qt.Horizontal
? parent.right
: (scrollBar.visible ? scrollBar.left : parent.right)
bottom: widgetExplorer.orientation == Qt.Horizontal ? scrollBar.top : bottomBar.top
leftMargin: 4
bottomMargin: 4
}
onWheelMoved: {
//use this only if the wheel orientation is vertical and the list orientation is horizontal, otherwise will be the list itself managing the wheel
if (wheel.orientation == Qt.Vertical && list.orientation == ListView.Horizontal) {
var delta = wheel.delta > 0 ? 20 : -20
list.contentX = Math.min(Math.max(0, list.contentWidth - list.width),
Math.max(0, list.contentX - delta))
}
}
ListView {
id: list
property int delegateWidth: (widgetExplorer.orientation == Qt.Horizontal) ? (list.width / Math.floor(list.width / cellWidth)) : list.width
property int delegateHeight: theme.defaultFont.pixelSize * 7 - 4
anchors.fill: parent
orientation: widgetExplorer.orientation == Qt.Horizontal ? ListView.Horizontal : ListView.Vertical
snapMode: ListView.SnapToItem
model: widgetExplorer.widgetsModel
clip: widgetExplorer.orientation == Qt.Vertical
delegate: AppletDelegate {}
}
}
PlasmaComponents.ScrollBar {
id: scrollBar
orientation: widgetExplorer.orientation == Qt.Horizontal ? ListView.Horizontal : ListView.Vertical
anchors {
top: widgetExplorer.orientation == Qt.Horizontal ? undefined : listParent.top
bottom: widgetExplorer.orientation == Qt.Horizontal ? parent.bottom : bottomBar.top
left: widgetExplorer.orientation == Qt.Horizontal ? parent.left : undefined
right: parent.right
}
flickableItem: list
}
Loader {
id: bottomBar
sourceComponent: (widgetExplorer.orientation == Qt.Horizontal) ? undefined : verticalBottomBarComponent
//height: item.height
height: 48 // FIXME
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
leftMargin: 4
}
}
Component {
id: verticalBottomBarComponent
Column {
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
}
spacing: 4
PlasmaComponents.Button { PlasmaComponents.Button {
anchors {
left: parent.left
right: parent.right
}
id: getWidgetsButton id: getWidgetsButton
iconSource: "get-hot-new-stuff" iconSource: "get-hot-new-stuff"
text: i18n("Get new widgets") text: i18n("Get new widgets")
@ -205,6 +357,10 @@ Item {
Repeater { Repeater {
model: widgetExplorer.extraActions.length model: widgetExplorer.extraActions.length
PlasmaComponents.Button { PlasmaComponents.Button {
anchors {
left: parent.left
right: parent.right
}
iconSource: widgetExplorer.extraActions[modelData].icon iconSource: widgetExplorer.extraActions[modelData].icon
text: widgetExplorer.extraActions[modelData].text text: widgetExplorer.extraActions[modelData].text
onClicked: { onClicked: {
@ -212,165 +368,11 @@ Item {
} }
} }
} }
PlasmaComponents.ToolButton {
iconSource: "window-close" Component.onCompleted: {
onClicked: widgetExplorer.closeClicked() main.getWidgetsButton = getWidgetsButton
} }
} }
Component.onCompleted: {
main.getWidgetsButton = getWidgetsButton
main.categoryButton = categoryButton
}
}
}
Component {
id: verticalTopBarComponent
Column {
anchors.top: parent.top
anchors.left:parent.left
anchors.right: parent.right
spacing: 4
PlasmaComponents.ToolButton {
anchors.right: parent.right
iconSource: "window-close"
onClicked: widgetExplorer.closeClicked()
}
PlasmaComponents.TextField {
anchors {
left: parent.left
right: parent.right
}
clearButtonShown: true
placeholderText: i18n("Enter search term...")
onTextChanged: {
list.contentX = 0
list.contentY = 0
widgetExplorer.widgetsModel.searchTerm = text
}
Component.onCompleted: forceActiveFocus()
}
PlasmaComponents.Button {
anchors {
left: parent.left
right: parent.right
}
id: categoryButton
text: i18n("Categories")
onClicked: categoriesDialog.open(0, categoryButton.height)
}
Component.onCompleted: {
main.categoryButton = categoryButton
}
}
}
MouseEventListener {
id: listParent
anchors {
top: topBar.bottom
left: parent.left
right: widgetExplorer.orientation == Qt.Horizontal
? parent.right
: (scrollBar.visible ? scrollBar.left : parent.right)
bottom: widgetExplorer.orientation == Qt.Horizontal ? scrollBar.top : bottomBar.top
leftMargin: 4
bottomMargin: 4
}
onWheelMoved: {
//use this only if the wheel orientation is vertical and the list orientation is horizontal, otherwise will be the list itself managing the wheel
if (wheel.orientation == Qt.Vertical && list.orientation == ListView.Horizontal) {
var delta = wheel.delta > 0 ? 20 : -20
list.contentX = Math.min(Math.max(0, list.contentWidth - list.width),
Math.max(0, list.contentX - delta))
}
}
ListView {
id: list
property int delegateWidth: (widgetExplorer.orientation == Qt.Horizontal) ? (list.width / Math.floor(list.width / cellWidth)) : list.width
property int delegateHeight: theme.defaultFont.pixelSize * 7 - 4
anchors.fill: parent
orientation: widgetExplorer.orientation == Qt.Horizontal ? ListView.Horizontal : ListView.Vertical
snapMode: ListView.SnapToItem
model: widgetExplorer.widgetsModel
clip: widgetExplorer.orientation == Qt.Vertical
delegate: AppletDelegate {}
}
}
PlasmaComponents.ScrollBar {
id: scrollBar
orientation: widgetExplorer.orientation == Qt.Horizontal ? ListView.Horizontal : ListView.Vertical
anchors {
top: widgetExplorer.orientation == Qt.Horizontal ? undefined : listParent.top
bottom: widgetExplorer.orientation == Qt.Horizontal ? parent.bottom : bottomBar.top
left: widgetExplorer.orientation == Qt.Horizontal ? parent.left : undefined
right: parent.right
}
flickableItem: list
}
Loader {
id: bottomBar
sourceComponent: (widgetExplorer.orientation == Qt.Horizontal) ? undefined : verticalBottomBarComponent
//height: item.height
height: 48 // FIXME
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
leftMargin: 4
}
}
Component {
id: verticalBottomBarComponent
Column {
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
}
spacing: 4
PlasmaComponents.Button {
anchors {
left: parent.left
right: parent.right
}
id: getWidgetsButton
iconSource: "get-hot-new-stuff"
text: i18n("Get new widgets")
onClicked: getWidgetsDialog.open()
}
Repeater {
model: widgetExplorer.extraActions.length
PlasmaComponents.Button {
anchors {
left: parent.left
right: parent.right
}
iconSource: widgetExplorer.extraActions[modelData].icon
text: widgetExplorer.extraActions[modelData].text
onClicked: {
widgetExplorer.extraActions[modelData].trigger()
}
}
}
Component.onCompleted: {
main.getWidgetsButton = getWidgetsButton
}
} }
} }
} }

View File

@ -17,7 +17,6 @@
*/ */
import QtQuick 2.0 import QtQuick 2.0
//import org.kde.plasma 2.0
import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.core 2.0 as PlasmaCore

View File

@ -35,14 +35,14 @@
#include "desktopview.h" #include "desktopview.h"
#include "panelview.h" #include "panelview.h"
#include "scripting/desktopscriptengine.h" #include "scripting/desktopscriptengine.h"
#include "widgetexplorer/widgetexplorerview.h" #include "widgetexplorer/widgetexplorer.h"
#include "configview.h" #include "configview.h"
class ShellCorona::Private { class ShellCorona::Private {
public: public:
Private() Private()
: desktopWidget(QApplication::desktop()), : desktopWidget(QApplication::desktop()),
widgetExplorerView(nullptr) widgetExplorer(nullptr)
{ {
appConfigSyncTimer.setSingleShot(true); appConfigSyncTimer.setSingleShot(true);
// constant controlling how long between requesting a configuration sync // constant controlling how long between requesting a configuration sync
@ -53,7 +53,7 @@ public:
QString shell; QString shell;
QDesktopWidget * desktopWidget; QDesktopWidget * desktopWidget;
QList <DesktopView *> views; QList <DesktopView *> views;
WidgetExplorerView * widgetExplorerView; QPointer<WidgetExplorer> widgetExplorer;
QHash <Plasma::Containment *, PanelView *> panelViews; QHash <Plasma::Containment *, PanelView *> panelViews;
KConfigGroup desktopDefaultsConfig; KConfigGroup desktopDefaultsConfig;
WorkspaceScripting::DesktopScriptEngine * scriptEngine; WorkspaceScripting::DesktopScriptEngine * scriptEngine;
@ -404,23 +404,22 @@ void ShellCorona::handleContainmentAdded(Plasma::Containment* c)
void ShellCorona::showWidgetExplorer() void ShellCorona::showWidgetExplorer()
{ {
if (!d->widgetExplorerView) { if (!d->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;
d->widgetExplorerView = new WidgetExplorerView(expqml); d->widgetExplorer = new WidgetExplorer();
d->widgetExplorerView->init(); d->widgetExplorer.data()->setSource(QUrl::fromLocalFile(expqml));
} }
Plasma::Containment *c = 0; Plasma::Containment *c = 0;
c = dynamic_cast<Plasma::Containment*>(sender()); c = dynamic_cast<Plasma::Containment*>(sender());
if (c) { if (c) {
qDebug() << "Found containment."; qDebug() << "Found containment.";
d->widgetExplorerView->setContainment(c); d->widgetExplorer.data()->setContainment(c);
} else { } else {
// FIXME: try harder to find a suitable containment? // FIXME: try harder to find a suitable containment?
qWarning() << "containment not set, don't know where to add the applet."; qWarning() << "containment not set, don't know where to add the applet.";
} }
d->widgetExplorerView->show();
} }
void ShellCorona::syncAppConfig() void ShellCorona::syncAppConfig()

View File

@ -21,8 +21,12 @@
#include "widgetexplorer.h" #include "widgetexplorer.h"
#include <QQmlEngine>
#include <QQmlContext>
#include <klocalizedstring.h> #include <klocalizedstring.h>
#include <kservicetypetrader.h> #include <kservicetypetrader.h>
#include <kdeclarative/qmlobject.h>
#include <Plasma/Applet> #include <Plasma/Applet>
#include <Plasma/Corona> #include <Plasma/Corona>
@ -56,7 +60,8 @@ public:
: q(w), : q(w),
containment(0), containment(0),
itemModel(w), itemModel(w),
filterModel(w) filterModel(w),
qmlObject(new QmlObject(w))
{ {
} }
@ -94,9 +99,7 @@ public:
KCategorizedItemsViewModels::DefaultFilterModel filterModel; KCategorizedItemsViewModels::DefaultFilterModel filterModel;
DefaultItemFilterProxyModel filterItemModel; DefaultItemFilterProxyModel filterItemModel;
// Plasma::DeclarativeWidget *declarativeWidget; QmlObject *qmlObject;
// QGraphicsLinearLayout *mainLayout;
}; };
void WidgetExplorerPrivate::initFilters() void WidgetExplorerPrivate::initFilters()
@ -374,6 +377,7 @@ WidgetExplorer::WidgetExplorer(Plasma::Types::Location loc, QObject *parent)
d(new WidgetExplorerPrivate(this)) d(new WidgetExplorerPrivate(this))
{ {
d->init(loc); d->init(loc);
populateWidgetList();
} }
WidgetExplorer::WidgetExplorer(QObject *parent) WidgetExplorer::WidgetExplorer(QObject *parent)
@ -381,6 +385,7 @@ WidgetExplorer::WidgetExplorer(QObject *parent)
d(new WidgetExplorerPrivate(this)) d(new WidgetExplorerPrivate(this))
{ {
d->init(Plasma::Types::LeftEdge); d->init(Plasma::Types::LeftEdge);
populateWidgetList();
} }
WidgetExplorer::~WidgetExplorer() WidgetExplorer::~WidgetExplorer()
@ -419,6 +424,19 @@ QString WidgetExplorer::application()
return d->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();
}
QUrl WidgetExplorer::source() const
{
return d->qmlObject->source();
}
void WidgetExplorer::setContainment(Plasma::Containment *containment) void WidgetExplorer::setContainment(Plasma::Containment *containment)
{ {
if (d->containment != containment) { if (d->containment != containment) {
@ -481,7 +499,7 @@ void WidgetExplorer::addApplet(const QString &pluginName)
void WidgetExplorer::immutabilityChanged(Plasma::Types::ImmutabilityType type) void WidgetExplorer::immutabilityChanged(Plasma::Types::ImmutabilityType type)
{ {
if (type != Plasma::Types::Mutable) { if (type != Plasma::Types::Mutable) {
emit closeClicked(); close();
} }
} }
@ -600,6 +618,12 @@ void WidgetExplorer::uninstall(const QString &pluginName)
} }
} }
void WidgetExplorer::close()
{
//d->qmlObject->engine()->rootContext()->setContextProperty("widgetExplorer", 0);
deleteLater();
}
/* /*
QPoint WidgetExplorer::tooltipPosition(QGraphicsObject *item, int tipWidth, int tipHeight) QPoint WidgetExplorer::tooltipPosition(QGraphicsObject *item, int tipWidth, int tipHeight)
{ {

View File

@ -108,6 +108,18 @@ public:
QString application(); 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 * 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 * before the widget explorer will be usable as the widget list will remain
@ -149,6 +161,7 @@ public:
Q_INVOKABLE void uninstall(const QString &pluginName); Q_INVOKABLE void uninstall(const QString &pluginName);
Q_INVOKABLE void close();
//Q_INVOKABLE QPoint tooltipPosition(QGraphicsObject *item, int tipWidth, int tipHeight); //Q_INVOKABLE QPoint tooltipPosition(QGraphicsObject *item, int tipWidth, int tipHeight);
Q_SIGNALS: Q_SIGNALS:

View File

@ -1,96 +0,0 @@
/*
* Copyright 2013 Sebastian Kügler <sebas@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "widgetexplorerview.h"
#include <QQmlContext>
#include <QQmlError>
#include <QQuickItem>
#include <klocalizedstring.h>
#include <kwindowsystem.h>
#include <kwindoweffects.h>
#include <Plasma/Containment>
WidgetExplorerView::WidgetExplorerView(const QString &qmlPath, QWindow *parent)
: QQuickView(parent),
m_containment(0),
m_widgetExplorer(0),
m_qmlPath(qmlPath)
{
QSurfaceFormat format;
format.setAlphaBufferSize(8);
setFormat(format);
setClearBeforeRendering(true);
setColor(QColor(Qt::transparent));
setFlags(Qt::FramelessWindowHint);
//KWindowSystem::setType(winId(), NET::Dock);
//TODO: how to take the shape from the framesvg?
KWindowEffects::enableBlurBehind(winId(), true);
// connect(this, &View::locationChanged,
// this, &WidgetExplorerView::positionPanel);
}
WidgetExplorerView::~WidgetExplorerView()
{
}
void WidgetExplorerView::init()
{
qDebug() << "Loading WidgetExplorer: " << m_qmlPath;
m_widgetExplorer = new WidgetExplorer(this);
m_widgetExplorer->populateWidgetList();
m_widgetExplorer->setContainment(m_containment);
rootContext()->setContextProperty("widgetExplorer", m_widgetExplorer);
setTitle(i18n("Add Widgets"));
setColor(Qt::transparent);
setResizeMode(QQuickView::SizeRootObjectToView);
setSource(QUrl::fromLocalFile(m_qmlPath));
connect(m_widgetExplorer, &WidgetExplorer::closeClicked, this, &QQuickView::close);
connect(this, &QQuickView::statusChanged, this, &WidgetExplorerView::widgetExplorerStatusChanged);
connect(this, &QQuickView::visibleChanged, this, &WidgetExplorerView::widgetExplorerClosed);
}
void WidgetExplorerView::setContainment(Plasma::Containment* c)
{
m_containment = c;
m_widgetExplorer->setContainment(c);
}
void WidgetExplorerView::widgetExplorerClosed(bool visible)
{
if (!visible) {
}
}
void WidgetExplorerView::widgetExplorerStatusChanged()
{
foreach (QQmlError e, errors()) {
qWarning() << "Error in WidgetExplorer: " << e.toString();
}
}

View File

@ -1,51 +0,0 @@
/*
* Copyright 2013 Sebastian Kügler <sebas@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef WIDGETEXPLORERVIEW_H
#define WIDGETEXPLORERVIEW_H
#include <QQuickView>
#include "widgetexplorer.h"
namespace Plasma {
class Containment;
}
class WidgetExplorerView : public QQuickView
{
Q_OBJECT
public:
explicit WidgetExplorerView(const QString &qmlPath, QWindow *parent = 0);
virtual ~WidgetExplorerView();
virtual void init();
void setContainment(Plasma::Containment* c);
private Q_SLOTS:
void widgetExplorerClosed(bool visible);
void widgetExplorerStatusChanged();
private:
Plasma::Containment* m_containment;
WidgetExplorer* m_widgetExplorer;
QString m_qmlPath;
};
#endif // WIDGETEXPLORERVIEW_H