diff --git a/src/shell/CMakeLists.txt b/src/shell/CMakeLists.txt index a30d4d680..68bd290fa 100644 --- a/src/shell/CMakeLists.txt +++ b/src/shell/CMakeLists.txt @@ -37,8 +37,10 @@ set(scripting_SRC scripting/appinterface.cpp scripting/applet.cpp scripting/containment.cpp + scripting/desktopscriptengine.cpp scripting/i18n.cpp scripting/layouttemplatepackagestructure.cpp + scripting/panel.cpp scripting/rect.cpp scripting/scriptengine.cpp scripting/widget.cpp diff --git a/src/shell/desktopcorona.cpp b/src/shell/desktopcorona.cpp index 895212361..755319c1d 100644 --- a/src/shell/desktopcorona.cpp +++ b/src/shell/desktopcorona.cpp @@ -26,6 +26,7 @@ #include "panelview.h" #include "view.h" +#include "scripting/desktopscriptengine.h" static const QString s_panelTemplatesPath("plasma-layout-templates/panels/*"); @@ -57,18 +58,25 @@ DesktopCorona::~DesktopCorona() void DesktopCorona::loadDefaultLayout() { //TODO: use Javascript here - Plasma::Containment *cont = createContainment("org.kde.testcontainment"); + /*Plasma::Containment *cont = createContainment("org.kde.testcontainment"); cont->setScreen(0); qDebug() << containmentForScreen(0); Plasma::Applet *appl = cont->createApplet("org.kde.testapplet"); qDebug() << "Containment:" << cont << cont->title(); - qDebug() << "Applet:" << appl->title() << appl; + qDebug() << "Applet:" << appl->title() << appl;*/ - /* - Plasma::Applet *cappl = cont->addApplet("org.kde.testcomponentsapplet"); - qDebug() << "Applet:" << cappl->title() << cappl->icon(); - */ + WorkspaceScripting::DesktopScriptEngine scriptEngine(this, true); + connect(&scriptEngine, SIGNAL(printError(QString)), this, SLOT(printScriptError(QString))); + connect(&scriptEngine, SIGNAL(print(QString)), this, SLOT(printScriptMessage(QString))); + + QString script = package().filePath("defaultlayout"); + QFile file(script); + if (file.open(QIODevice::ReadOnly | QIODevice::Text) ) { + QString code = file.readAll(); + qDebug() << "evaluating startup script:" << script; + scriptEngine.evaluateScript(code); + } } void DesktopCorona::checkScreens(bool signalWhenExists) @@ -163,6 +171,10 @@ QRect DesktopCorona::availableScreenRect(int id) const return m_desktopWidget->availableGeometry(id); } +PanelView *DesktopCorona::panelView(Plasma::Containment *containment) const +{ + return m_panelViews.value(containment); +} ///// SLOTS diff --git a/src/shell/desktopcorona.h b/src/shell/desktopcorona.h index adacae450..279d86552 100644 --- a/src/shell/desktopcorona.h +++ b/src/shell/desktopcorona.h @@ -63,6 +63,7 @@ public: QRegion availableScreenRegion(int id) const; QRect availableScreenRect(int id) const; + PanelView *panelView(Plasma::Containment *containment) const; protected Q_SLOTS: void screenCountChanged(int newCount); diff --git a/src/shell/panelview.cpp b/src/shell/panelview.cpp index cb4af2b85..1b6026e38 100644 --- a/src/shell/panelview.cpp +++ b/src/shell/panelview.cpp @@ -91,6 +91,21 @@ void PanelView::init() setSource(QUrl::fromLocalFile(corona()->package().filePath("views", "Panel.qml"))); } +Qt::Alignment PanelView::alignment() const +{ + return m_alignment; +} + +void PanelView::setAlignment(Qt::Alignment alignment) +{ + if (m_alignment == alignment) { + return; + } + + m_alignment = alignment; + positionPanel(); +} + void PanelView::positionPanel() { if (!containment()) { diff --git a/src/shell/panelview.h b/src/shell/panelview.h index 335ed2cc7..c4f485439 100644 --- a/src/shell/panelview.h +++ b/src/shell/panelview.h @@ -35,6 +35,9 @@ public: virtual void init(); + Qt::Alignment alignment() const; + void setAlignment(Qt::Alignment alignment); + private Q_SLOTS: void positionPanel(); void restore(); diff --git a/src/shell/qmlpackages/desktop/contents/layout.js b/src/shell/qmlpackages/desktop/contents/layout.js new file mode 100644 index 000000000..1fbbdb9c5 --- /dev/null +++ b/src/shell/qmlpackages/desktop/contents/layout.js @@ -0,0 +1,16 @@ + +var panel = new Panel +panel.screen = 0 +panel.location = 'top' +panel.addWidget("org.kde.testapplet") +panel.addWidget("org.kde.testcomponentsapplet") + +for (var i = 0; i < screenCount; ++i) { + var desktop = new Activity + desktop.name = i18n("Desktop") + desktop.screen = i + desktop.wallpaperPlugin = 'org.kde.image' + + desktop.addWidget("org.kde.testapplet") + var testComponents = desktop.addWidget("org.kde.testcomponentsapplet") +} diff --git a/src/shell/scripting/desktopscriptengine.cpp b/src/shell/scripting/desktopscriptengine.cpp new file mode 100644 index 000000000..f908e0a22 --- /dev/null +++ b/src/shell/scripting/desktopscriptengine.cpp @@ -0,0 +1,63 @@ +/* + * Copyright 2010 Aaron Seigo + * + * 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 "desktopscriptengine.h" + +#include +#include +#include + +#include "containment.h" +#include "appinterface.h" + +#include "panel.h" + +namespace WorkspaceScripting +{ + +DesktopScriptEngine::DesktopScriptEngine(Plasma::Corona *corona, bool startup, QObject *parent) + : ScriptEngine(corona, parent), + m_startup(startup) +{ +} + +QScriptValue DesktopScriptEngine::wrap(Plasma::Containment *c) +{ + Containment *wrapper = isPanel(c) ? new Panel(c) : new Containment(c); + return wrap(wrapper); +} + +QScriptValue DesktopScriptEngine::wrap(Containment *c) +{ + return ScriptEngine::wrap(c); +} + +int DesktopScriptEngine::defaultPanelScreen() const +{ + if (m_startup) { + return ScriptEngine::defaultPanelScreen(); + } else { + return qApp->desktop()->screenNumber(QCursor::pos()); + } +} + +} + +#include "desktopscriptengine.moc" + diff --git a/src/shell/scripting/desktopscriptengine.h b/src/shell/scripting/desktopscriptengine.h new file mode 100644 index 000000000..0e448da2d --- /dev/null +++ b/src/shell/scripting/desktopscriptengine.h @@ -0,0 +1,45 @@ +/* + * Copyright 2010 Aaron Seigo + * + * 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 DESKTOPSCRIPTENGINE +#define DESKTOPSCRIPTENGINE + +#include "scriptengine.h" + +namespace WorkspaceScripting +{ + +class DesktopScriptEngine : public ScriptEngine +{ + Q_OBJECT + +public: + DesktopScriptEngine(Plasma::Corona *corona, bool isStartup = true, QObject *parent = 0); + QScriptValue wrap(Plasma::Containment *c); + QScriptValue wrap(Containment *c); + int defaultPanelScreen() const; + +private: + bool m_startup; +}; + +} + +#endif + diff --git a/src/shell/scripting/panel.cpp b/src/shell/scripting/panel.cpp new file mode 100644 index 000000000..1795199da --- /dev/null +++ b/src/shell/scripting/panel.cpp @@ -0,0 +1,343 @@ +/* + * Copyright 2009 Aaron Seigo + * + * 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 "panel.h" + +#include +#include + +#include +#include + +#include "desktopcorona.h" +#include "panelview.h" +#include "scriptengine.h" +#include "widget.h" + +namespace WorkspaceScripting +{ + +Panel::Panel(Plasma::Containment *containment, QObject *parent) + : Containment(containment, parent) +{ + m_corona = qobject_cast(containment->corona()); +} + +Panel::~Panel() +{ +} + +QString Panel::location() const +{ + Plasma::Containment *c = containment(); + if (!c) { + return "floating"; + } + + switch (c->location()) { + case Plasma::Floating: + return "floating"; + break; + case Plasma::Desktop: + return "desktop"; + break; + case Plasma::FullScreen: + return "fullscreen"; + break; + case Plasma::TopEdge: + return "top"; + break; + case Plasma::BottomEdge: + return "bottom"; + break; + case Plasma::LeftEdge: + return "left"; + break; + case Plasma::RightEdge: + return "right"; + break; + } + + return "floating"; +} + +void Panel::setLocation(const QString &locationString) +{ + Plasma::Containment *c = containment(); + if (!c) { + return; + } + + const QString lower = locationString.toLower(); + Plasma::Location loc = Plasma::Floating; + if (lower == "desktop") { + loc = Plasma::Desktop; + } else if (lower == "fullscreen") { + loc = Plasma::FullScreen; + } else if (lower == "top") { + loc = Plasma::TopEdge; + } else if (lower == "bottom") { + loc = Plasma::BottomEdge; + } else if (lower == "left") { + loc = Plasma::LeftEdge; + } else if (lower == "right") { + loc = Plasma::RightEdge; + } + + c->setLocation(loc); +} + +PanelView *Panel::panel() const +{ + Plasma::Containment *c = containment(); + if (!c) { + return 0; + } + + return m_corona->panelView(c); +} + +QString Panel::alignment() const +{ + PanelView *v = panel(); + if (!v) { + return "left"; + } + + switch (v->alignment()) { + case Qt::AlignRight: + return "right"; + break; + case Qt::AlignCenter: + return "center"; + break; + default: + return "left"; + break; + } + + return "left"; +} + +void Panel::setAlignment(const QString &alignment) +{ + PanelView *v = panel(); + if (v) { + bool success = false; + + if (alignment.compare("left", Qt::CaseInsensitive) == 0) { + if (v->alignment() != Qt::AlignLeft) { + success = true; + v->setAlignment(Qt::AlignLeft); + } + } else if (alignment.compare("right", Qt::CaseInsensitive) == 0) { + if (v->alignment() != Qt::AlignRight) { + success = true; + v->setAlignment(Qt::AlignRight); + } + } else if (alignment.compare("center", Qt::CaseInsensitive) == 0) { + if (v->alignment() != Qt::AlignCenter) { + success = true; + v->setAlignment(Qt::AlignCenter); + } + } + + if (success) { + // v->setOffset(0); + } + } +} + +int Panel::offset() const +{ + /*PanelView *v = panel(); + if (v) { + return v->offset(); + }*/ + + return 0; +} + +void Panel::setOffset(int pixels) +{ + /*Plasma::Containment *c = containment(); + if (pixels < 0 || !c) { + return; + } + + PanelView *v = panel(); + if (v) { + QRectF screen = c->corona()->screenGeometry(v->screen()); + QSizeF size = c->size(); + + if (c->formFactor() == Plasma::Vertical) { + if (pixels > screen.height()) { + return; + } + + if (size.height() + pixels > screen.height()) { + c->resize(size.width(), screen.height() - pixels); + } + } else if (pixels > screen.width()) { + return; + } else if (size.width() + pixels > screen.width()) { + size.setWidth(screen.width() - pixels); + c->resize(size); + c->setMinimumSize(size); + c->setMaximumSize(size); + } + + v->setOffset(pixels); + }*/ +} + +int Panel::length() const +{ + Plasma::Containment *c = containment(); + if (!c) { + return 0; + } + QQuickItem *graphicObject = qobject_cast(c->property("graphicObject").value()); + + if (!graphicObject) { + return 0; + } + + if (c->formFactor() == Plasma::Vertical) { + return graphicObject->height(); + } else { + return graphicObject->width(); + } +} + +void Panel::setLength(int pixels) +{ + /*Plasma::Containment *c = containment(); + if (pixels < 0 || !c) { + return; + } + + PanelView *v = panel(); + if (v) { + QRectF screen = c->corona()->screenGeometry(v->screen()); + QSizeF s = c->size(); + if (c->formFactor() == Plasma::Vertical) { + if (pixels > screen.height() - v->offset()) { + return; + } + + s.setHeight(pixels); + } else if (pixels > screen.width() - v->offset()) { + return; + } else { + s.setWidth(pixels); + } + + c->resize(s); + c->setMinimumSize(s); + c->setMaximumSize(s); + }*/ +} + +int Panel::height() const +{ + Plasma::Containment *c = containment(); + if (!c) { + return 0; + } + + QQuickItem *graphicObject = qobject_cast(c->property("graphicObject").value()); + + if (!graphicObject) { + return 0; + } + + return c->formFactor() == Plasma::Vertical ? graphicObject->width() + : graphicObject->height(); +} + +void Panel::setHeight(int height) +{ + /*Plasma::Containment *c = containment(); + if (height < 16 || !c) { + return; + } + + PanelView *v = panel(); + if (v) { + QRect screen = c->corona()->screenGeometry(v->screen()); + QSizeF size = c->size(); + const int max = (c->formFactor() == Plasma::Vertical ? screen.width() : screen.height()) / 3; + height = qBound(16, height, max); + + if (c->formFactor() == Plasma::Vertical) { + size.setWidth(height); + } else { + size.setHeight(height); + } + + c->resize(size); + c->setMinimumSize(size); + c->setMaximumSize(size); + }*/ +} + +QString Panel::hiding() const +{ + /*PanelView *v = panel(); + if (v) { + switch (v->visibilityMode()) { + case PanelView::NormalPanel: + return "none"; + break; + case PanelView::AutoHide: + return "autohide"; + break; + case PanelView::LetWindowsCover: + return "windowscover"; + break; + case PanelView::WindowsGoBelow: + return "windowsbelow"; + break; + } + }*/ + + return "none"; +} + +void Panel::setHiding(const QString &mode) +{ + /*PanelView *v = panel(); + if (v) { + if (mode.compare("autohide", Qt::CaseInsensitive) == 0) { + v->setVisibilityMode(PanelView::AutoHide); + } else if (mode.compare("windowscover", Qt::CaseInsensitive) == 0) { + v->setVisibilityMode(PanelView::LetWindowsCover); + } else if (mode.compare("windowsbelow", Qt::CaseInsensitive) == 0) { + v->setVisibilityMode(PanelView::WindowsGoBelow); + } else { + v->setVisibilityMode(PanelView::NormalPanel); + } + }*/ +} + +} + +#include "panel.moc" + diff --git a/src/shell/scripting/panel.h b/src/shell/scripting/panel.h new file mode 100644 index 000000000..bd0be0d61 --- /dev/null +++ b/src/shell/scripting/panel.h @@ -0,0 +1,97 @@ +/* + * Copyright 2009 Aaron Seigo + * + * 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 PANEL +#define PANEL + +#include +#include +#include + +#include "containment.h" + +class PanelView; +class DesktopCorona; + +namespace WorkspaceScripting +{ + +class Panel : public Containment +{ + Q_OBJECT + Q_PROPERTY(QStringList configKeys READ configKeys) + Q_PROPERTY(QStringList configGroups READ configGroups) + Q_PROPERTY(QStringList currentConfigGroup WRITE setCurrentConfigGroup READ currentConfigGroup) + + Q_PROPERTY(QString name READ name WRITE setName) + Q_PROPERTY(QString version READ version) + Q_PROPERTY(QString type READ type) + Q_PROPERTY(QString formFactor READ formFactor) + Q_PROPERTY(QList widgetIds READ widgetIds) + Q_PROPERTY(int screen READ screen WRITE setScreen) + Q_PROPERTY(QString location READ location WRITE setLocation) + Q_PROPERTY(int id READ id) + + // panel properties + Q_PROPERTY(QString alignment READ alignment WRITE setAlignment) + Q_PROPERTY(int offset READ offset WRITE setOffset) + Q_PROPERTY(int length READ length WRITE setLength) + Q_PROPERTY(int height READ height WRITE setHeight) + Q_PROPERTY(QString hiding READ hiding WRITE setHiding) + +public: + Panel(Plasma::Containment *containment, QObject *parent = 0); + ~Panel(); + + QString location() const; + void setLocation(const QString &location); + + QString alignment() const; + void setAlignment(const QString &alignment); + + int offset() const; + void setOffset(int pixels); + + int length() const; + void setLength(int pixels); + + int height() const; + void setHeight(int height); + + QString hiding() const; + void setHiding(const QString &mode); + +public Q_SLOTS: + void remove() { Containment::remove(); } + void showConfigurationInterface() { Containment::showConfigurationInterface(); } + + // from the applet interface + QVariant readConfig(const QString &key, const QVariant &def = QString()) const { return Applet::readConfig(key, def); } + void writeConfig(const QString &key, const QVariant &value) { Applet::writeConfig(key, value); } + void reloadConfig() { Applet::reloadConfig(); } + +private: + PanelView *panel() const; + DesktopCorona *m_corona; +}; + +} + +#endif +