a very simple panel controller

dummy, but setting the offset already works
This commit is contained in:
Marco Martin 2013-03-19 22:06:06 +01:00
parent 8285189fe7
commit 5e3723cd7c
8 changed files with 222 additions and 1 deletions

View File

@ -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;

View File

@ -53,6 +53,7 @@ add_executable(testplasma2
shellpluginloader.cpp
shellpackage.cpp
view.cpp
panelconfigview.cpp
${scripting_SRC}
)

View File

@ -0,0 +1,81 @@
/*
* Copyright 2013 Marco Martin <mart@kde.org>
*
* 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 <QDebug>
#include <QDir>
#include <QQmlComponent>
#include <QQmlEngine>
#include <QQmlContext>
#include <KGlobal>
#include <KLocalizedString>
#include <Plasma/Containment>
#include <Plasma/Corona>
#include <Plasma/PluginLoader>
//////////////////////////////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"

View File

@ -0,0 +1,55 @@
/*
* Copyright 2013 Marco Martin <mart@kde.org>
*
* 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 <QQuickItem>
#include <QQuickView>
#include <QJSValue>
#include <QQmlListProperty>
#include <QStandardItemModel>
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

View File

@ -18,12 +18,15 @@
#include "panelview.h"
#include <QAction>
#include <QDebug>
#include <QScreen>
#include <KActionCollection>
#include <KWindowSystem>
#include <kwindoweffects.h>
#include <Plasma/Containment>
#include <Plasma/Package>
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()

View File

@ -21,11 +21,14 @@
#include "view.h"
#include "panelconfigview.h"
#include <QtCore/qpointer.h>
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<PanelConfigView> m_panelConfigView;
};
#endif // PANELVIEW_H

View File

@ -0,0 +1,50 @@
/*
* Copyright 2013 Marco Martin <mart@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 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
}

View File

@ -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);
}