Move widgetexplorerview into its own class
This commit is contained in:
parent
9bc347006d
commit
f9b52427e7
@ -50,6 +50,7 @@ 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(testplasma2
|
add_executable(testplasma2
|
||||||
|
@ -33,7 +33,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"
|
#include "widgetexplorer/widgetexplorerview.h"
|
||||||
|
|
||||||
|
|
||||||
static const QString s_panelTemplatesPath("plasma-layout-templates/panels/*");
|
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)
|
DesktopCorona::DesktopCorona(QObject *parent)
|
||||||
: Plasma::Corona(parent),
|
: Plasma::Corona(parent),
|
||||||
m_desktopWidget(QApplication::desktop()),
|
m_desktopWidget(QApplication::desktop()),
|
||||||
m_widgetExplorer(0),
|
|
||||||
m_widgetExplorerView(0)
|
m_widgetExplorerView(0)
|
||||||
{
|
{
|
||||||
m_desktopDefaultsConfig = KConfigGroup(KSharedConfig::openConfig(package().filePath("defaults")), "Desktop");
|
m_desktopDefaultsConfig = KConfigGroup(KSharedConfig::openConfig(package().filePath("defaults")), "Desktop");
|
||||||
@ -275,26 +274,16 @@ void DesktopCorona::showWidgetExplorer()
|
|||||||
{
|
{
|
||||||
if (!m_widgetExplorerView) {
|
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");
|
QString expqml = package().filePath("widgetexplorer");
|
||||||
qDebug() << "Script to load for WidgetExplorer: " << expqml;
|
qDebug() << "Script to load for WidgetExplorer: " << expqml;
|
||||||
m_widgetExplorerView->setSource(QUrl::fromLocalFile(expqml));
|
m_widgetExplorerView = new WidgetExplorerView(expqml);
|
||||||
connect(m_widgetExplorerView, &QQuickView::statusChanged, this, &DesktopCorona::widgetExplorerStatusChanged);
|
m_widgetExplorerView->init();
|
||||||
connect(m_widgetExplorerView, &QQuickView::visibleChanged, this, &DesktopCorona::widgetExplorerClosed);
|
|
||||||
}
|
}
|
||||||
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.";
|
||||||
m_widgetExplorer->setContainment(c);
|
m_widgetExplorerView->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.";
|
||||||
@ -302,21 +291,6 @@ void DesktopCorona::showWidgetExplorer()
|
|||||||
m_widgetExplorerView->show();
|
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)
|
void DesktopCorona::printScriptError(const QString &error)
|
||||||
{
|
{
|
||||||
qWarning() << error;
|
qWarning() << error;
|
||||||
|
@ -27,7 +27,7 @@ class QDesktopWidget;
|
|||||||
class QQuickView;
|
class QQuickView;
|
||||||
class PanelView;
|
class PanelView;
|
||||||
class View;
|
class View;
|
||||||
class WidgetExplorer;
|
class WidgetExplorerView;
|
||||||
|
|
||||||
namespace Plasma
|
namespace Plasma
|
||||||
{
|
{
|
||||||
@ -86,14 +86,11 @@ protected Q_SLOTS:
|
|||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void handleContainmentAdded(Plasma::Containment *c);
|
void handleContainmentAdded(Plasma::Containment *c);
|
||||||
void showWidgetExplorer();
|
void showWidgetExplorer();
|
||||||
void widgetExplorerClosed(bool visible);
|
|
||||||
void widgetExplorerStatusChanged();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QDesktopWidget *m_desktopWidget;
|
QDesktopWidget *m_desktopWidget;
|
||||||
QList <View *> m_views;
|
QList <View *> m_views;
|
||||||
WidgetExplorer *m_widgetExplorer;
|
WidgetExplorerView *m_widgetExplorerView;
|
||||||
QQuickView *m_widgetExplorerView;
|
|
||||||
QHash<Plasma::Containment *, PanelView *> m_panelViews;
|
QHash<Plasma::Containment *, PanelView *> m_panelViews;
|
||||||
KConfigGroup m_desktopDefaultsConfig;
|
KConfigGroup m_desktopDefaultsConfig;
|
||||||
};
|
};
|
||||||
|
95
src/shell/widgetexplorer/widgetexplorerview.cpp
Normal file
95
src/shell/widgetexplorer/widgetexplorerview.cpp
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
51
src/shell/widgetexplorer/widgetexplorerview.h
Normal file
51
src/shell/widgetexplorer/widgetexplorerview.h
Normal 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
|
Loading…
x
Reference in New Issue
Block a user