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,7 +22,12 @@ 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: dialog
location: PlasmaCore.Types.LeftEdge
Component.onCompleted: dialog.visible = true;
mainItem: Item {
id: main id: main
width: 240 width: 240
@ -30,20 +35,12 @@ Item {
//this is used to perfectly align the filter field and delegates //this is used to perfectly align the filter field and delegates
property int cellWidth: theme.defaultFont.pixelSize * 20 property int cellWidth: theme.defaultFont.pixelSize * 20
PlasmaCore.FrameSvgItem {
imagePath: "dialogs/background"
anchors.fill: parent
anchors.margins: margins
//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
@ -55,7 +52,8 @@ Item {
Repeater { Repeater {
parent: categoriesDialog parent: categoriesDialog
model: widgetExplorer.filterModel model: widgetExplorer.filterModel
delegate: PlasmaComponents.MenuItem { delegate: Item {
PlasmaComponents.MenuItem {
text: display text: display
separator: model["separator"] != undefined ? model["separator"] : false separator: model["separator"] != undefined ? model["separator"] : false
onClicked: { onClicked: {
@ -70,6 +68,7 @@ Item {
} }
} }
} }
}
PlasmaComponents.ContextMenu { PlasmaComponents.ContextMenu {
id: getWidgetsDialog id: getWidgetsDialog
@ -78,7 +77,8 @@ Item {
Repeater { Repeater {
parent: getWidgetsDialog parent: getWidgetsDialog
model: widgetExplorer.widgetsMenuActions model: widgetExplorer.widgetsMenuActions
delegate: PlasmaComponents.MenuItem { delegate: Item {
PlasmaComponents.MenuItem {
icon: modelData.icon icon: modelData.icon
text: modelData.text text: modelData.text
separator: modelData.separator separator: modelData.separator
@ -88,6 +88,7 @@ Item {
} }
} }
} }
}
PlasmaCore.Dialog { PlasmaCore.Dialog {
id: tooltipDialog id: tooltipDialog
@ -214,7 +215,7 @@ Item {
} }
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
iconSource: "window-close" iconSource: "window-close"
onClicked: widgetExplorer.closeClicked() onClicked: widgetExplorer.close()
} }
} }
Component.onCompleted: { Component.onCompleted: {
@ -236,7 +237,7 @@ Item {
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
anchors.right: parent.right anchors.right: parent.right
iconSource: "window-close" iconSource: "window-close"
onClicked: widgetExplorer.closeClicked() onClicked: widgetExplorer.close()
} }
PlasmaComponents.TextField { PlasmaComponents.TextField {
anchors { anchors {
@ -374,3 +375,4 @@ Item {
} }
} }
} }
}

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