Merge branch 'master' of git://anongit.kde.org/kde-runtime
This commit is contained in:
commit
93790aec7f
@ -8,6 +8,7 @@ set(corebindings_SRCS
|
||||
datasource.cpp
|
||||
svgitem.cpp
|
||||
framesvgitem.cpp
|
||||
dialog.cpp
|
||||
)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "framesvgitem_p.h"
|
||||
#include "svgitem_p.h"
|
||||
#include "theme_p.h"
|
||||
#include "dialog.h"
|
||||
|
||||
void CoreBindingsPlugin::registerTypes(const char *uri)
|
||||
{
|
||||
@ -47,6 +48,8 @@ void CoreBindingsPlugin::registerTypes(const char *uri)
|
||||
qmlRegisterType<Plasma::DataModel>(uri, 0, 1, "DataModel");
|
||||
qmlRegisterType<Plasma::SortFilterModel>(uri, 0, 1, "SortFilterModel");
|
||||
|
||||
qmlRegisterType<DialogProxy>(uri, 0, 1, "Dialog");
|
||||
|
||||
qmlRegisterInterface<Plasma::Service>("Service");
|
||||
qRegisterMetaType<Plasma::Service*>("Service");
|
||||
|
||||
|
107
declarativeimports/core/dialog.cpp
Normal file
107
declarativeimports/core/dialog.cpp
Normal file
@ -0,0 +1,107 @@
|
||||
/***************************************************************************
|
||||
* Copyright 2011 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 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
|
||||
#include "dialog.h"
|
||||
|
||||
#include <QGraphicsObject>
|
||||
#include <QGraphicsWidget>
|
||||
#include <QTimer>
|
||||
|
||||
#include <Plasma/Corona>
|
||||
#include <Plasma/Dialog>
|
||||
|
||||
DialogProxy::DialogProxy(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_dialog = new Plasma::Dialog();
|
||||
}
|
||||
|
||||
DialogProxy::~DialogProxy()
|
||||
{
|
||||
delete m_dialog;
|
||||
}
|
||||
|
||||
QGraphicsObject *DialogProxy::mainItem() const
|
||||
{
|
||||
return m_dialog->graphicsWidget();
|
||||
}
|
||||
|
||||
void DialogProxy::setMainItem(QGraphicsObject *mainItem)
|
||||
{
|
||||
if (m_mainItem.data() != mainItem) {
|
||||
m_mainItem = mainItem;
|
||||
|
||||
//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()));
|
||||
emit mainItemChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void DialogProxy::syncMainItem()
|
||||
{
|
||||
if (!m_mainItem) {
|
||||
return;
|
||||
}
|
||||
|
||||
//not have a scene? go up in the hyerarchy until we find something with a scene
|
||||
if (!m_mainItem.data()->scene()) {
|
||||
QObject *parent = m_mainItem.data();
|
||||
while (parent = parent->parent()) {
|
||||
QGraphicsObject *qo = qobject_cast<QGraphicsObject *>(parent);
|
||||
if (qo) {
|
||||
QGraphicsScene *scene = qo->scene();
|
||||
scene->addItem(m_mainItem.data());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//FIXME: make Dialog accept qgraphicsobjects
|
||||
m_dialog->setGraphicsWidget(qobject_cast<QGraphicsWidget *>(m_mainItem.data()));
|
||||
}
|
||||
|
||||
bool DialogProxy::isVisible() const
|
||||
{
|
||||
return m_dialog->isVisible();
|
||||
}
|
||||
|
||||
void DialogProxy::setVisible(const bool visible)
|
||||
{
|
||||
if (m_dialog->isVisible() == visible) {
|
||||
m_dialog->setVisible(visible);
|
||||
emit visibleChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void DialogProxy::showPopup(QGraphicsObject *item)
|
||||
{
|
||||
if (m_dialog->isVisible()) {
|
||||
m_dialog->hide();
|
||||
} else {
|
||||
Plasma::Corona *corona = qobject_cast<Plasma::Corona *>(item->scene());
|
||||
if (corona) {
|
||||
m_dialog->move(corona->popupPosition(item, m_dialog->size()));
|
||||
}
|
||||
m_dialog->show();
|
||||
}
|
||||
emit visibleChanged();
|
||||
}
|
||||
|
||||
#include "dialog.moc"
|
||||
|
63
declarativeimports/core/dialog.h
Normal file
63
declarativeimports/core/dialog.h
Normal file
@ -0,0 +1,63 @@
|
||||
/***************************************************************************
|
||||
* Copyright 2011 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 02110-1301 USA . *
|
||||
***************************************************************************/
|
||||
#ifndef DIALOG_PROXY_P
|
||||
#define DIALOG_PROXY_P
|
||||
|
||||
#include <QObject>
|
||||
#include <QWeakPointer>
|
||||
|
||||
class QGraphicsObject;
|
||||
|
||||
namespace Plasma
|
||||
{
|
||||
class Dialog;
|
||||
}
|
||||
|
||||
class DialogProxy : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(QGraphicsObject *mainItem READ mainItem WRITE setMainItem NOTIFY mainItemChanged)
|
||||
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged)
|
||||
|
||||
public:
|
||||
DialogProxy(QObject *parent = 0);
|
||||
~DialogProxy();
|
||||
|
||||
QGraphicsObject *mainItem() const;
|
||||
void setMainItem(QGraphicsObject *mainItem);
|
||||
|
||||
bool isVisible() const;
|
||||
void setVisible(const bool visible);
|
||||
|
||||
Q_INVOKABLE void showPopup(QGraphicsObject *item);
|
||||
|
||||
Q_SIGNALS:
|
||||
void mainItemChanged();
|
||||
void visibleChanged();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void syncMainItem();
|
||||
|
||||
private:
|
||||
Plasma::Dialog *m_dialog;
|
||||
QWeakPointer<QGraphicsObject> m_mainItem;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user