From 5e3723cd7c5d25fde6afade19bb0618e5dbce029 Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Tue, 19 Mar 2013 22:06:06 +0100 Subject: [PATCH] a very simple panel controller dummy, but setting the offset already works --- .../qml/plasmoid/containmentconfigview.cpp | 4 +- src/shell/CMakeLists.txt | 1 + src/shell/panelconfigview.cpp | 81 +++++++++++++++++++ src/shell/panelconfigview.h | 55 +++++++++++++ src/shell/panelview.cpp | 21 +++++ src/shell/panelview.h | 9 +++ .../components/PanelConfiguration.qml | 50 ++++++++++++ src/shell/shellpackage.cpp | 2 + 8 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 src/shell/panelconfigview.cpp create mode 100644 src/shell/panelconfigview.h create mode 100644 src/shell/qmlpackages/desktop/contents/components/PanelConfiguration.qml diff --git a/src/scriptengines/qml/plasmoid/containmentconfigview.cpp b/src/scriptengines/qml/plasmoid/containmentconfigview.cpp index 91fb68bc8..aeef78095 100644 --- a/src/scriptengines/qml/plasmoid/containmentconfigview.cpp +++ b/src/scriptengines/qml/plasmoid/containmentconfigview.cpp @@ -97,7 +97,9 @@ void ContainmentConfigView::setCurrentWallpaper(const QString &wallpaper) if (m_contianmentInterface->containment()->wallpaper() == wallpaper) { delete m_currentWallpaperConfig; - m_currentWallpaperConfig = m_contianmentInterface->wallpaperInterface()->configuration(); + if (m_contianmentInterface->wallpaperInterface()) { + m_currentWallpaperConfig = m_contianmentInterface->wallpaperInterface()->configuration(); + } } else { if (m_contianmentInterface->containment()->wallpaper() != m_currentWallpaper) { delete m_currentWallpaperConfig; diff --git a/src/shell/CMakeLists.txt b/src/shell/CMakeLists.txt index 68bd290fa..4b722024f 100644 --- a/src/shell/CMakeLists.txt +++ b/src/shell/CMakeLists.txt @@ -53,6 +53,7 @@ add_executable(testplasma2 shellpluginloader.cpp shellpackage.cpp view.cpp + panelconfigview.cpp ${scripting_SRC} ) diff --git a/src/shell/panelconfigview.cpp b/src/shell/panelconfigview.cpp new file mode 100644 index 000000000..5501eb425 --- /dev/null +++ b/src/shell/panelconfigview.cpp @@ -0,0 +1,81 @@ +/* + * Copyright 2013 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library 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 "panelconfigview.h" +#include "panelview.h" + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +//////////////////////////////PanelConfigView +PanelConfigView::PanelConfigView(Plasma::Containment *containment, PanelView *panelView, QWindow *parent) + : QQuickView(parent), + m_containment(containment) +{ + + //FIXME: problem on nvidia, all windows should be transparent or won't show + setColor(Qt::transparent); + setTitle(i18n("%1 Settings", m_containment->title())); + + + if (!m_containment->corona()->package().isValid()) { + qWarning() << "Invalid home screen package"; + } + + setResizeMode(QQuickView::SizeViewToRootObject); + + engine()->rootContext()->setContextProperty("panel", panelView); + engine()->rootContext()->setContextProperty("configDialog", this); + setSource(QUrl::fromLocalFile(panelView->corona()->package().filePath("panelconfigurationui"))); +} + +PanelConfigView::~PanelConfigView() +{ +} + + +//To emulate Qt::WA_DeleteOnClose that QWindow doesn't have +void PanelConfigView::hideEvent(QHideEvent *ev) +{ + QQuickWindow::hideEvent(ev); + deleteLater(); +} + +void PanelConfigView::resizeEvent(QResizeEvent *re) +{ + if (!rootObject()) { + return; + } + rootObject()->setWidth(re->size().width()); + rootObject()->setHeight(re->size().height()); + QQuickWindow::resizeEvent(re); +} + + +#include "moc_panelconfigview.cpp" diff --git a/src/shell/panelconfigview.h b/src/shell/panelconfigview.h new file mode 100644 index 000000000..447d83dbe --- /dev/null +++ b/src/shell/panelconfigview.h @@ -0,0 +1,55 @@ +/* + * Copyright 2013 Marco Martin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, 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 Library 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 PANELCONFIGVIEW_H +#define PANELCONFIGVIEW_H + +#include +#include +#include +#include +#include + +class AppletInterface; +class ConfigPropertyMap; +class PanelView; + +namespace Plasma { + class Containment; +} + +//TODO: this should be a subclass of ConfigView currently in the scriptengine +//TODO: that class should be moved here +class PanelConfigView : public QQuickView +{ + Q_OBJECT + +public: + PanelConfigView(Plasma::Containment *interface, PanelView *panelView, QWindow *parent = 0); + virtual ~PanelConfigView(); + +protected: + void hideEvent(QHideEvent *ev); + void resizeEvent(QResizeEvent *re); + +private: + Plasma::Containment *m_containment; +}; + +#endif // multiple inclusion guard diff --git a/src/shell/panelview.cpp b/src/shell/panelview.cpp index 62cd47a35..dadca50a3 100644 --- a/src/shell/panelview.cpp +++ b/src/shell/panelview.cpp @@ -18,12 +18,15 @@ #include "panelview.h" +#include #include #include +#include #include #include +#include #include PanelView::PanelView(Plasma::Corona *corona, QWindow *parent) @@ -44,6 +47,9 @@ PanelView::PanelView(Plasma::Corona *corona, QWindow *parent) //TODO: how to take the shape from the framesvg? KWindowEffects::enableBlurBehind(winId(), true); + connect(this, &View::containmentChanged, + this, &PanelView::manageNewContainment); + //Screen management connect(screen(), &QScreen::virtualGeometryChanged, this, &PanelView::positionPanel); @@ -119,6 +125,21 @@ void PanelView::setOffset(int offset) m_offset = offset; positionPanel(); + emit offsetChanged(); +} + +void PanelView::manageNewContainment() +{ + connect(containment()->actions()->action("configure"), &QAction::triggered, + this, &PanelView::showPanelController); +} + +void PanelView::showPanelController() +{ + if (!m_panelConfigView) { + m_panelConfigView = new PanelConfigView(containment(), this); + } + m_panelConfigView->show(); } void PanelView::positionPanel() diff --git a/src/shell/panelview.h b/src/shell/panelview.h index 68e5cc19f..f2de8ddd8 100644 --- a/src/shell/panelview.h +++ b/src/shell/panelview.h @@ -21,11 +21,14 @@ #include "view.h" +#include "panelconfigview.h" +#include class PanelView : public View { Q_OBJECT + Q_PROPERTY(int offset READ offset WRITE setOffset NOTIFY offsetChanged) public: explicit PanelView(Plasma::Corona *corona, QWindow *parent = 0); @@ -41,7 +44,12 @@ public: int offset() const; void setOffset(int offset); +Q_SIGNALS: + void offsetChanged(); + private Q_SLOTS: + void manageNewContainment(); + void showPanelController(); void positionPanel(); void restore(); @@ -50,6 +58,7 @@ private: int m_maxLength; int m_minLength; Qt::Alignment m_alignment; + QPointer m_panelConfigView; }; #endif // PANELVIEW_H diff --git a/src/shell/qmlpackages/desktop/contents/components/PanelConfiguration.qml b/src/shell/qmlpackages/desktop/contents/components/PanelConfiguration.qml new file mode 100644 index 000000000..1a4e0652d --- /dev/null +++ b/src/shell/qmlpackages/desktop/contents/components/PanelConfiguration.qml @@ -0,0 +1,50 @@ +/* + * Copyright 2013 Marco Martin + * + * 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 2.010-1301, USA. + */ + +import QtQuick 2.0 +import org.kde.plasma.components 2.0 as PlasmaComponents +import org.kde.plasma.extras 2.0 as PlasmaExtras +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.configuration 2.0 + + +//TODO: all of this will be done with desktop components +Rectangle { + id: root + +//BEGIN properties + color: "lightgray" + width: 640 + height: 64 +//END properties + +//BEGIN UI components + Rectangle { + width: 32 + height: 32 + MouseArea { + drag { + target: parent + axis: Drag.XAxis + } + anchors.fill: parent + onPositionChanged: panel.offset = parent.x + } + } +//END UI components +} diff --git a/src/shell/shellpackage.cpp b/src/shell/shellpackage.cpp index e06778167..2aff402c3 100644 --- a/src/shell/shellpackage.cpp +++ b/src/shell/shellpackage.cpp @@ -47,6 +47,8 @@ void ShellPackageStructure::initPackage(Plasma::Package *package) package->addFileDefinition("configurationui", "components/Configuration.qml", i18n("QML component for the configuratuion dialog")); package->addFileDefinition("defaultcompactrepresentation", "components/DefaultCompactRepresentation.qml", i18n("Compact representation of an applet when collapsed in a popup, for instance as an icon. applets can override this component.")); package->addFileDefinition("widgetexplorer", "components/WidgetExplorer.qml", i18n("Widgets explorer UI")); + package->addFileDefinition("panelconfigurationui", "components/PanelConfiguration.qml", i18n("Panel configuration UI")); + //package->setRequired("mainscript", true); }