From 2566309c9abd94b7bcf10f14b9604d0f9268102c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20K=C3=BCgler?= Date: Wed, 20 Feb 2013 04:25:29 +0100 Subject: [PATCH] Start porting PlasmaCore.Dialog This commit enables the build of PlasmaCore.Dialog. Most of the code is disabled, as it's quite wired up with QGraphicsWidgets. The remaining pieces are actually able to bring up a window, but don't display anything. --- src/declarativeimports/core/CMakeLists.txt | 2 +- .../core/corebindingsplugin.cpp | 6 +- src/declarativeimports/core/dialog.cpp | 83 ++++++++++--------- src/declarativeimports/core/dialog.h | 21 ++--- 4 files changed, 60 insertions(+), 52 deletions(-) diff --git a/src/declarativeimports/core/CMakeLists.txt b/src/declarativeimports/core/CMakeLists.txt index eb20b5db3..cf12f81c9 100644 --- a/src/declarativeimports/core/CMakeLists.txt +++ b/src/declarativeimports/core/CMakeLists.txt @@ -17,7 +17,7 @@ set(corebindings_SRCS runnermodel.cpp svgitem.cpp framesvgitem.cpp -# dialog.cpp + dialog.cpp # tooltip.cpp dataenginebindings.cpp iconitem.cpp diff --git a/src/declarativeimports/core/corebindingsplugin.cpp b/src/declarativeimports/core/corebindingsplugin.cpp index c828e04b4..2979f9ab9 100644 --- a/src/declarativeimports/core/corebindingsplugin.cpp +++ b/src/declarativeimports/core/corebindingsplugin.cpp @@ -38,7 +38,7 @@ #include "runnermodel.h" #include "svgitem.h" #include "theme.h" -// #include "dialog.h" +#include "dialog.h" #include "iconitem.h" // #include "tooltip.h" // #include "dataenginebindings_p.h" @@ -84,8 +84,8 @@ void CoreBindingsPlugin::registerTypes(const char *uri) qmlRegisterType(uri, 0, 1, "DataSource"); qmlRegisterType(uri, 0, 1, "DataModel"); qmlRegisterType(uri, 0, 1, "SortFilterModel"); -// -// qmlRegisterType(uri, 0, 1, "Dialog"); + + qmlRegisterType(uri, 0, 1, "Dialog"); // qmlRegisterType(uri, 0, 1, "ToolTip"); // qmlRegisterInterface("Service"); diff --git a/src/declarativeimports/core/dialog.cpp b/src/declarativeimports/core/dialog.cpp index 05d31abcb..98bcdc55a 100644 --- a/src/declarativeimports/core/dialog.cpp +++ b/src/declarativeimports/core/dialog.cpp @@ -18,27 +18,27 @@ ***************************************************************************/ #include "dialog.h" -#include "declarativeitemcontainer_p.h" +//#include "declarativeitemcontainer_p.h" #include #include #include -#include -#include +#include +#include #include #include #include #include -#include -#include +// #include +//#include int DialogProxy::offscreenX = 0; int DialogProxy::offscreenY = 0; -DialogMargins::DialogMargins(Plasma::Dialog *dialog, QObject *parent) +DialogMargins::DialogMargins(QQuickWindow *dialog, QObject *parent) : QObject(parent), m_left(0), m_top(0), m_right(0), m_bottom(0), m_dialog(dialog) @@ -49,7 +49,7 @@ DialogMargins::DialogMargins(Plasma::Dialog *dialog, QObject *parent) void DialogMargins::checkMargins() { int left, top, right, bottom; - m_dialog->getContentsMargins(&left, &top, &right, &bottom); + //m_dialog->getContentsMargins(&left, &top, &right, &bottom); if (left != m_left) { m_left = left; @@ -95,10 +95,10 @@ DialogProxy::DialogProxy(QQuickItem *parent) m_activeWindow(false), m_location(Plasma::Floating) { - m_dialog = new Plasma::Dialog(); + m_dialog = new QQuickWindow(); m_margins = new DialogMargins(m_dialog, this); m_dialog->installEventFilter(this); - m_flags = m_dialog->windowFlags(); + m_flags = m_dialog->flags(); } DialogProxy::~DialogProxy() @@ -107,12 +107,12 @@ DialogProxy::~DialogProxy() delete m_dialog; } -QGraphicsObject *DialogProxy::mainItem() const +QQuickItem *DialogProxy::mainItem() const { return m_mainItem.data(); } -void DialogProxy::setMainItem(QGraphicsObject *mainItem) +void DialogProxy::setMainItem(QQuickItem *mainItem) { if (m_mainItem.data() != mainItem) { if (m_mainItem) { @@ -134,11 +134,12 @@ void DialogProxy::setMainItem(QGraphicsObject *mainItem) void DialogProxy::syncMainItem() { + /* if (!m_mainItem) { return; } - if (static_cast(m_dialog->graphicsWidget()) == m_mainItem.data() || + if (static_cast(m_dialog->graphicsWidget()) == m_mainItem.data() || (m_declarativeItemContainer && m_declarativeItemContainer->declarativeItem() == m_mainItem.data())) { return; } @@ -148,7 +149,7 @@ void DialogProxy::syncMainItem() if (!scene) { QObject *parent = m_mainItem.data(); while ((parent = parent->parent())) { - QGraphicsObject *qo = qobject_cast(parent); + QQuickItem *qo = qobject_cast(parent); if (qo) { scene = qo->scene(); if (scene) { @@ -164,9 +165,9 @@ void DialogProxy::syncMainItem() } //the parent of the qobject never changed, only the parentitem, so put it back what it was - m_mainItem.data()->setParentItem(qobject_cast(m_mainItem.data()->parent())); + m_mainItem.data()->setParentItem(qobject_cast(m_mainItem.data()->parent())); - QGraphicsWidget *widget = qobject_cast(m_mainItem.data()); + QQuickItem *widget = qobject_cast(m_mainItem.data()); if (widget) { if (m_declarativeItemContainer) { m_declarativeItemContainer->deleteLater(); @@ -183,13 +184,15 @@ void DialogProxy::syncMainItem() widget = m_declarativeItemContainer; } } - m_dialog->setGraphicsWidget(widget); + //m_dialog->setGraphicsWidget(widget); + widget->setParent(m_dialog); if (!qobject_cast(scene)) { offscreenX -= 10000; offscreenY -= 10000; widget->setPos(offscreenX, offscreenY); } + */ } bool DialogProxy::isVisible() const @@ -207,9 +210,10 @@ void DialogProxy::setVisible(const bool visible) const QRect workArea(KWindowSystem::workArea()); if (!workArea.contains(m_dialog->geometry())) { - m_dialog->move(qBound(workArea.left(), m_dialog->x(), workArea.right() - m_dialog->width()), - qBound(workArea.top(), m_dialog->y(), workArea.bottom() - m_dialog->height()) - ); + //FIXME +// m_dialog->move(qBound(workArea.left(), m_dialog->x(), workArea.right() - m_dialog->width()), +// qBound(workArea.top(), m_dialog->y(), workArea.bottom() - m_dialog->height()) +// ); } m_dialog->setVisible(visible); @@ -219,17 +223,18 @@ void DialogProxy::setVisible(const bool visible) } } -QPoint DialogProxy::popupPosition(QGraphicsObject *item, int alignment) +QPoint DialogProxy::popupPosition(QQuickItem *item, int alignment) { - QGraphicsObject *actualItem = item; + /* + QQuickItem *actualItem = item; //if no item is passed search the root item in order to figure out the view if (!actualItem) { - actualItem = qobject_cast(parent()); + actualItem = qobject_cast(parent()); //search the root object while (true) { - QGraphicsObject *ancestor = qobject_cast(actualItem->parent()); + QQuickItem *ancestor = qobject_cast(actualItem->parent()); if (ancestor) { actualItem = ancestor; @@ -244,7 +249,7 @@ QPoint DialogProxy::popupPosition(QGraphicsObject *item, int alignment) //ensure the dialog has the proper size syncMainItem(); - m_dialog->syncToGraphicsWidget(); + //m_dialog->syncToGraphicsWidget(); Plasma::Corona *corona = qobject_cast(actualItem->scene()); if (corona && item) { @@ -316,27 +321,29 @@ QPoint DialogProxy::popupPosition(QGraphicsObject *item, int alignment) } return menuPos; } + */ + return QPoint(200, 400); } int DialogProxy::x() const { - return m_dialog->pos().x(); + return m_dialog->geometry().topLeft().x(); } void DialogProxy::setX(int x) { - m_dialog->move(x, m_dialog->pos().y()); + //m_dialog->move(x, m_dialog->geometry().topLeft().y()); } int DialogProxy::y() const { - return m_dialog->pos().y(); + return m_dialog->geometry().topLeft().y(); } void DialogProxy::setY(int y) { - m_dialog->move(m_dialog->pos().x(), y); + //m_dialog->move(m_dialog->geometry().topLeft().x(), y); } int DialogProxy::width() const @@ -356,7 +363,7 @@ bool DialogProxy::isActiveWindow() const void DialogProxy::activateWindow() { - m_dialog->activateWindow(); + //m_dialog->activateWindow(); } int DialogProxy::windowFlags() const @@ -374,7 +381,7 @@ qulonglong DialogProxy::windowId() const void DialogProxy::setWindowFlags(const int flags) { m_flags = (Qt::WindowFlags)flags; - m_dialog->setWindowFlags(Qt::FramelessWindowHint|m_flags); + m_dialog->setFlags(Qt::FramelessWindowHint|m_flags); } int DialogProxy::location() const @@ -419,15 +426,15 @@ bool DialogProxy::eventFilter(QObject *watched, QEvent *event) emit heightChanged(); } } else if (watched == m_dialog && event->type() == QEvent::Show) { - Plasma::WindowEffects::slideWindow(m_dialog, m_location); - if (m_dialog->testAttribute(Qt::WA_X11NetWmWindowTypeDock)) { - KWindowSystem::setOnAllDesktops(m_dialog->winId(), true); - } else { - KWindowSystem::setOnAllDesktops(m_dialog->winId(), false); - } + //Plasma::WindowEffects::slideWindow(m_dialog, m_location); +// if (m_dialog->testAttribute(Qt::WA_X11NetWmWindowTypeDock)) { +// KWindowSystem::setOnAllDesktops(m_dialog->winId(), true); +// } else { +// KWindowSystem::setOnAllDesktops(m_dialog->winId(), false); +// } emit visibleChanged(); } else if (watched == m_dialog && event->type() == QEvent::Hide) { - Plasma::WindowEffects::slideWindow(m_dialog, m_location); + //Plasma::WindowEffects::slideWindow(m_dialog, m_location); emit visibleChanged(); } else if (watched == m_dialog && event->type() == QEvent::WindowActivate) { m_activeWindow = true; @@ -441,7 +448,7 @@ bool DialogProxy::eventFilter(QObject *watched, QEvent *event) void DialogProxy::setAttribute(int attribute, bool on) { - m_dialog->setAttribute((Qt::WidgetAttribute)attribute, on); + //m_dialog->setAttribute((Qt::WidgetAttribute)attribute, on); if (attribute == Qt::WA_X11NetWmWindowTypeDock) { KWindowSystem::setOnAllDesktops(m_dialog->winId(), true); diff --git a/src/declarativeimports/core/dialog.h b/src/declarativeimports/core/dialog.h index 043b9a15e..758a397b5 100644 --- a/src/declarativeimports/core/dialog.h +++ b/src/declarativeimports/core/dialog.h @@ -20,12 +20,13 @@ #define DIALOG_PROXY_P #include +#include #include #include #include -class QGraphicsObject; +class QQuickItem; namespace Plasma { @@ -59,7 +60,7 @@ class DialogMargins : public QObject Q_PROPERTY(int bottom READ bottom NOTIFY bottomChanged) public: - DialogMargins(Plasma::Dialog *dialog, QObject *parent = 0); + DialogMargins(QQuickWindow *dialog, QObject *parent = 0); int left() const; int top() const; @@ -80,7 +81,7 @@ private: int m_top; int m_right; int m_bottom; - Plasma::Dialog *m_dialog; + QQuickWindow *m_dialog; friend class DialogProxy; }; @@ -96,7 +97,7 @@ class DialogProxy : public QQuickItem /** * The main QML item that will be displayed in the Dialog */ - Q_PROPERTY(QGraphicsObject *mainItem READ mainItem WRITE setMainItem NOTIFY mainItemChanged) + Q_PROPERTY(QQuickItem *mainItem READ mainItem WRITE setMainItem NOTIFY mainItemChanged) /** * Visibility of the Dialog window. Doesn't have anything to do with the visibility of the mainItem. @@ -160,8 +161,8 @@ public: DialogProxy(QQuickItem *parent = 0); ~DialogProxy(); - QGraphicsObject *mainItem() const; - void setMainItem(QGraphicsObject *mainItem); + QQuickItem *mainItem() const; + void setMainItem(QQuickItem *mainItem); bool isVisible() const; void setVisible(const bool visible); @@ -202,7 +203,7 @@ public: * @arg alignment alignment of the popup compared to the item */ //FIXME: alignment should be Qt::AlignmentFlag - Q_INVOKABLE QPoint popupPosition(QGraphicsObject *item, int alignment=Qt::AlignLeft) ; + Q_INVOKABLE QPoint popupPosition(QQuickItem *item, int alignment=Qt::AlignLeft) ; /** * Set a Qt.WidgetAttribute to the dialog window @@ -230,10 +231,10 @@ protected: bool eventFilter(QObject *watched, QEvent *event); private: - Plasma::Dialog *m_dialog; + QQuickWindow *m_dialog; Qt::WindowFlags m_flags; - DeclarativeItemContainer *m_declarativeItemContainer; - QWeakPointer m_mainItem; + QQuickItem *m_declarativeItemContainer; + QWeakPointer m_mainItem; DialogMargins *m_margins; bool m_activeWindow; Plasma::Location m_location;