Move widgetexplorerview into its own class

This commit is contained in:
Sebastian Kügler 2013-03-26 02:41:58 +01:00
parent 9bc347006d
commit f9b52427e7
5 changed files with 153 additions and 35 deletions

View File

@ -50,6 +50,7 @@ set(widgetexplorer_SRC
widgetexplorer/kcategorizeditemsviewmodels.cpp
widgetexplorer/plasmaappletitemmodel.cpp
widgetexplorer/widgetexplorer.cpp
widgetexplorer/widgetexplorerview.cpp
)
add_executable(testplasma2

View File

@ -33,7 +33,7 @@
#include "panelview.h"
#include "view.h"
#include "scripting/desktopscriptengine.h"
#include "widgetexplorer/widgetexplorer.h"
#include "widgetexplorer/widgetexplorerview.h"
static const QString s_panelTemplatesPath("plasma-layout-templates/panels/*");
@ -41,7 +41,6 @@ static const QString s_panelTemplatesPath("plasma-layout-templates/panels/*");
DesktopCorona::DesktopCorona(QObject *parent)
: Plasma::Corona(parent),
m_desktopWidget(QApplication::desktop()),
m_widgetExplorer(0),
m_widgetExplorerView(0)
{
m_desktopDefaultsConfig = KConfigGroup(KSharedConfig::openConfig(package().filePath("defaults")), "Desktop");
@ -275,26 +274,16 @@ void DesktopCorona::showWidgetExplorer()
{
if (!m_widgetExplorerView) {
m_widgetExplorerView = new QQuickView;
m_widgetExplorerView->setTitle(i18n("Add Widgets"));
m_widgetExplorerView->setColor(Qt::transparent);
m_widgetExplorer = new WidgetExplorer(m_widgetExplorerView);
m_widgetExplorer->populateWidgetList();
m_widgetExplorerView->rootContext()->setContextProperty("widgetExplorer", m_widgetExplorer);
connect(m_widgetExplorer, &WidgetExplorer::closeClicked, m_widgetExplorerView, &QQuickView::close);
QString expqml = package().filePath("widgetexplorer");
qDebug() << "Script to load for WidgetExplorer: " << expqml;
m_widgetExplorerView->setSource(QUrl::fromLocalFile(expqml));
connect(m_widgetExplorerView, &QQuickView::statusChanged, this, &DesktopCorona::widgetExplorerStatusChanged);
connect(m_widgetExplorerView, &QQuickView::visibleChanged, this, &DesktopCorona::widgetExplorerClosed);
m_widgetExplorerView = new WidgetExplorerView(expqml);
m_widgetExplorerView->init();
}
Plasma::Containment *c = 0;
c = dynamic_cast<Plasma::Containment*>(sender());
if (c) {
qDebug() << "Found containment.";
m_widgetExplorer->setContainment(c);
m_widgetExplorerView->setContainment(c);
} else {
// FIXME: try harder to find a suitable containment?
qWarning() << "containment not set, don't know where to add the applet.";
@ -302,21 +291,6 @@ void DesktopCorona::showWidgetExplorer()
m_widgetExplorerView->show();
}
void DesktopCorona::widgetExplorerClosed(bool visible)
{
if (!visible) {
m_widgetExplorerView->deleteLater();
m_widgetExplorerView = 0;
}
}
void DesktopCorona::widgetExplorerStatusChanged()
{
foreach (QQmlError e, m_widgetExplorerView->errors()) {
qWarning() << "Error in WidgetExplorer: " << e.toString();
}
}
void DesktopCorona::printScriptError(const QString &error)
{
qWarning() << error;

View File

@ -27,7 +27,7 @@ class QDesktopWidget;
class QQuickView;
class PanelView;
class View;
class WidgetExplorer;
class WidgetExplorerView;
namespace Plasma
{
@ -86,14 +86,11 @@ protected Q_SLOTS:
private Q_SLOTS:
void handleContainmentAdded(Plasma::Containment *c);
void showWidgetExplorer();
void widgetExplorerClosed(bool visible);
void widgetExplorerStatusChanged();
private:
QDesktopWidget *m_desktopWidget;
QList <View *> m_views;
WidgetExplorer *m_widgetExplorer;
QQuickView *m_widgetExplorerView;
WidgetExplorerView *m_widgetExplorerView;
QHash<Plasma::Containment *, PanelView *> m_panelViews;
KConfigGroup m_desktopDefaultsConfig;
};

View File

@ -0,0 +1,95 @@
/*
* 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 <KLocalizedString>
#include <KWindowSystem>
#include <kwindoweffects.h>
#include <Plasma/Containment>
WidgetExplorerView::WidgetExplorerView(const QString &qmlPath, QWindow *parent)
: QQuickView(parent),
m_containment(0),
m_qmlPath(qmlPath),
m_widgetExplorer(0)
{
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()
{
setTitle(i18n("Add Widgets"));
setColor(Qt::transparent);
m_widgetExplorer = new WidgetExplorer(this);
m_widgetExplorer->populateWidgetList();
rootContext()->setContextProperty("widgetExplorer", m_widgetExplorer);
connect(m_widgetExplorer, &WidgetExplorer::closeClicked, this, &QQuickView::close);
// QString expqml = package().filePath("widgetexplorer");
qDebug() << "Script to load for WidgetExplorer: " << m_qmlPath;
setSource(QUrl::fromLocalFile(m_qmlPath));
connect(this, &QQuickView::statusChanged, this, &WidgetExplorerView::widgetExplorerStatusChanged);
connect(this, &QQuickView::visibleChanged, this, &WidgetExplorerView::widgetExplorerClosed);
setResizeMode(QQuickView::SizeRootObjectToView);
m_widgetExplorer->setContainment(m_containment);
}
void WidgetExplorerView::setContainment(Plasma::Containment* c)
{
m_containment = c;
m_widgetExplorer->setContainment(c);
}
void WidgetExplorerView::widgetExplorerClosed(bool visible)
{
if (!visible) {
deleteLater();
//m_widgetExplorerView = 0;
}
}
void WidgetExplorerView::widgetExplorerStatusChanged()
{
foreach (QQmlError e, errors()) {
qWarning() << "Error in WidgetExplorer: " << e.toString();
}
}

View File

@ -0,0 +1,51 @@
/*
* 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