diff --git a/declarativeimports/plasmacomponents/fullscreendialog.cpp b/declarativeimports/plasmacomponents/fullscreendialog.cpp new file mode 100644 index 000000000..62d103ce0 --- /dev/null +++ b/declarativeimports/plasmacomponents/fullscreendialog.cpp @@ -0,0 +1,252 @@ +/*************************************************************************** + * Copyright 2012 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 02110-1301 USA . * + ***************************************************************************/ + +#include "fullscreendialog.h" +#include "../core/declarativeitemcontainer_p.h" +#include "plasmacomponentsplugin.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + + +uint FullScreenDialog::s_numItems = 0; + +FullScreenDialog::FullScreenDialog(QObject *parent) + : QObject(parent) +{ + m_view = new QGraphicsView(); + m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + m_view->installEventFilter(this); + m_view->setAutoFillBackground(false); + m_view->viewport()->setAutoFillBackground(false); + m_view->setAttribute(Qt::WA_TranslucentBackground); + m_view->setAttribute(Qt::WA_OpaquePaintEvent); + m_view->setAttribute(Qt::WA_NoSystemBackground); + m_view->viewport()->setAttribute(Qt::WA_OpaquePaintEvent); + m_view->viewport()->setAttribute(Qt::WA_NoSystemBackground); + m_view->setWindowFlags(m_view->windowFlags() | Qt::FramelessWindowHint | Qt::CustomizeWindowHint); + m_view->setFrameShape(QFrame::NoFrame); + KWindowSystem::setOnAllDesktops(m_view->winId(), true); + unsigned long state = NET::Sticky | NET::StaysOnTop | NET::KeepAbove | NET::SkipTaskbar | NET::SkipPager | NET::MaxVert | NET::MaxHoriz; + KWindowSystem::setState(m_view->effectiveWinId(), state); + + //Try to figure out the path of the dialog component + QString componentsPlatform = getenv("KDE_PLASMA_COMPONENTS_PLATFORM"); + if (componentsPlatform.isEmpty()) { + KConfigGroup cg(KSharedConfig::openConfig("kdeclarativerc"), "Components-platform"); + componentsPlatform = cg.readEntry("name", "desktop"); + } + + QString filePath; + if (componentsPlatform == "desktop") { + foreach(const QString &importPath, KGlobal::dirs()->findDirs("module", "imports/")) { + filePath = importPath % "org/kde/plasma/components/Dialog.qml"; + QFile f(filePath); + if (f.exists()) { + break; + } + } + } else { + foreach(const QString &importPath, KGlobal::dirs()->findDirs("module", "platformimports/" % componentsPlatform)) { + filePath = importPath % "org/kde/plasma/components/Dialog.qml"; + QFile f(filePath); + if (f.exists()) { + break; + } + } + } + + + QDeclarativeEngine *engine = EngineBookKeeping::self()->engineFor(this); + QDeclarativeComponent *component = new QDeclarativeComponent(engine, filePath, this); + + QDeclarativeContext *creationContext = component->creationContext(); + m_rootObject = component->create(creationContext); + setMainItem(qobject_cast(m_rootObject.data())); +} + +FullScreenDialog::~FullScreenDialog() +{ + delete m_view; +} + +QGraphicsObject *FullScreenDialog::mainItem() const +{ + return m_mainItem.data(); +} + +void FullScreenDialog::setMainItem(QGraphicsObject *mainItem) +{ + if (m_mainItem.data() != mainItem) { + if (m_mainItem) { + m_mainItem.data()->setParent(mainItem->parent()); + m_mainItem.data()->removeEventFilter(this); + m_mainItem.data()->setY(0); + m_scene = 0; + } + m_mainItem = mainItem; + if (mainItem) { + mainItem->setParentItem(0); + mainItem->setParent(this); + m_scene = mainItem->scene(); + } + + mainItem->installEventFilter(this); + + //if this is called in Compenent.onCompleted we have to wait a loop the item is added to a scene + QTimer::singleShot(0, this, SLOT(syncMainItem())); + } +} + +void FullScreenDialog::syncMainItem() +{ + if (!m_mainItem) { + return; + } + + //not have a scene? go up in the hyerarchy until we find something with a scene + QGraphicsScene *scene = m_mainItem.data()->scene(); + if (!scene) { + QObject *parent = m_mainItem.data(); + while ((parent = parent->parent())) { + QGraphicsObject *qo = qobject_cast(parent); + if (qo) { + scene = qo->scene(); + + if (scene) { + scene->addItem(m_mainItem.data()); + ++s_numItems; + Plasma::Corona *corona = qobject_cast(scene); + QDeclarativeItem *di = qobject_cast(m_mainItem.data()); + + if (corona && di) { + if (!m_declarativeItemContainer) { + m_declarativeItemContainer = new DeclarativeItemContainer(); + scene->addItem(m_declarativeItemContainer); + corona->addOffscreenWidget(m_declarativeItemContainer); + } + m_declarativeItemContainer->setDeclarativeItem(di); + } else { + m_mainItem.data()->setY(-10000*s_numItems); + m_mainItem.data()->setY(10000*s_numItems); + } + break; + } + } + } + } + + if (!scene) { + return; + } + + m_view->setScene(scene); + + + if (m_declarativeItemContainer) { + m_declarativeItemContainer->resize(m_view->size()); + m_view->setSceneRect(m_declarativeItemContainer->geometry()); + } else { + m_mainItem.data()->setProperty("width", m_view->size().width()); + m_mainItem.data()->setProperty("height", m_view->size().height()); + QRectF itemGeometry(QPointF(m_mainItem.data()->x(), m_mainItem.data()->y()), + QSizeF(m_mainItem.data()->boundingRect().size())); + m_view->setSceneRect(itemGeometry); + } +} + +bool FullScreenDialog::isVisible() const +{ + return m_view->isVisible(); +} + +void FullScreenDialog::setVisible(const bool visible) +{ + if (m_view->isVisible() != visible) { + m_view->setVisible(visible); + if (visible) { + m_view->setVisible(visible); + m_view->raise(); + } + } +} + + +QDeclarativeListProperty FullScreenDialog::title() const +{ + if (m_rootObject) { + return m_rootObject.data()->property("title").value >(); + } else { + return QDeclarativeListProperty(); + } +} + +QDeclarativeListProperty FullScreenDialog::content() const +{ + if (m_rootObject) { + return m_rootObject.data()->property("content").value >(); + } else { + return QDeclarativeListProperty(); + } +} + +QDeclarativeListProperty FullScreenDialog::buttons() const +{ + if (m_rootObject) { + return m_rootObject.data()->property("buttons").value >(); + } else { + return QDeclarativeListProperty(); + } +} + +DialogStatus::Status FullScreenDialog::status() const +{ + if (m_rootObject) { + return (DialogStatus::Status)m_rootObject.data()->property("status").toInt(); + } else { + return DialogStatus::Closed; + } +} + + +bool FullScreenDialog::eventFilter(QObject *watched, QEvent *event) +{ + if (watched == m_view && + (event->type() == QEvent::Resize || event->type() == QEvent::Move)) { + syncMainItem(); + } + return false; +} + + + +#include "fullscreendialog.moc" + diff --git a/declarativeimports/plasmacomponents/fullscreendialog.h b/declarativeimports/plasmacomponents/fullscreendialog.h new file mode 100644 index 000000000..5c8d2cca8 --- /dev/null +++ b/declarativeimports/plasmacomponents/fullscreendialog.h @@ -0,0 +1,87 @@ +/*************************************************************************** + * Copyright 2012 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 02110-1301 USA . * + ***************************************************************************/ +#ifndef FULLSCREENDIALOG_P +#define FULLSCREENDIALOG_P + +#include +#include +#include +#include +#include +#include + +#include "enums.h" + +class QGraphicsObject; +class QGraphicsView; +class QGraphicsScene; +class DeclarativeItemContainer; + +class FullScreenDialog : public QObject +{ + Q_OBJECT + + Q_PROPERTY(QDeclarativeListProperty title READ title) + Q_PROPERTY(QDeclarativeListProperty content READ content) + Q_PROPERTY(QDeclarativeListProperty buttons READ buttons) + Q_PROPERTY(DialogStatus::Status status READ status NOTIFY statusChanged) + /*property alias content: contentItem.children + property alias buttons: buttonItem.children + property int status: DialogStatus.Closed*/ + + +public: + FullScreenDialog(QObject *parent = 0); + ~FullScreenDialog(); + + QGraphicsObject *mainItem() const; + void setMainItem(QGraphicsObject *mainItem); + + bool isVisible() const; + void setVisible(const bool visible); + + //QML properties + QDeclarativeListProperty title()const ; + QDeclarativeListProperty content() const; + QDeclarativeListProperty buttons() const; + DialogStatus::Status status() const; + +Q_SIGNALS: + void accepted(); + void rejected(); + void clickedOutside(); + void statusChanged(); + + +protected Q_SLOTS: + void syncMainItem(); + +protected: + bool eventFilter(QObject *watched, QEvent *event); + +private: + QGraphicsView *m_view; + QWeakPointer m_mainItem; + DeclarativeItemContainer *m_declarativeItemContainer; + QGraphicsScene *m_scene; + QWeakPointer m_rootObject; + static uint s_numItems; +}; + +#endif diff --git a/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp b/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp index 28374bc89..f74046b9c 100644 --- a/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp +++ b/declarativeimports/plasmacomponents/plasmacomponentsplugin.cpp @@ -91,14 +91,16 @@ void PlasmaComponentsPlugin::registerTypes(const char *uri) componentsPlatform = cg.readEntry("name", "desktop"); } + //platform specific c++ components if (componentsPlatform == "desktop") { qmlRegisterType(uri, 0, 1, "QueryDialog"); qmlRegisterType(uri, 0, 1, "Menu"); qmlRegisterType(uri, 0, 1, "MenuItem"); + } else { + qmlRegisterType(uri, 0, 1, "Dialog"); } - qmlRegisterType(uri, 0, 1, "FullScreenDialog"); qmlRegisterType(uri, 0, 1, "RangeModel"); qmlRegisterUncreatableType(uri, 0, 1, "DialogStatus", "");