sync dialog size when a declarativeitem changes size
This commit is contained in:
parent
c77d815ec7
commit
ccdb4cebdf
@ -19,6 +19,8 @@
|
|||||||
|
|
||||||
#include "declarativeitemcontainer_p.h"
|
#include "declarativeitemcontainer_p.h"
|
||||||
|
|
||||||
|
#include <KDebug>
|
||||||
|
|
||||||
DeclarativeItemContainer::DeclarativeItemContainer(QGraphicsItem *parent)
|
DeclarativeItemContainer::DeclarativeItemContainer(QGraphicsItem *parent)
|
||||||
: QGraphicsWidget(parent)
|
: QGraphicsWidget(parent)
|
||||||
{
|
{
|
||||||
@ -31,7 +33,7 @@ DeclarativeItemContainer::~DeclarativeItemContainer()
|
|||||||
void DeclarativeItemContainer::setDeclarativeItem(QDeclarativeItem *item, bool reparent)
|
void DeclarativeItemContainer::setDeclarativeItem(QDeclarativeItem *item, bool reparent)
|
||||||
{
|
{
|
||||||
if (m_declarativeItem) {
|
if (m_declarativeItem) {
|
||||||
m_declarativeItem.data()->removeSceneEventFilter(this);
|
disconnect(m_declarativeItem.data(), 0, this, 0);
|
||||||
}
|
}
|
||||||
m_declarativeItem = item;
|
m_declarativeItem = item;
|
||||||
if (reparent) {
|
if (reparent) {
|
||||||
@ -40,7 +42,8 @@ void DeclarativeItemContainer::setDeclarativeItem(QDeclarativeItem *item, bool r
|
|||||||
setMinimumWidth(item->implicitWidth());
|
setMinimumWidth(item->implicitWidth());
|
||||||
setMinimumHeight(item->implicitHeight());
|
setMinimumHeight(item->implicitHeight());
|
||||||
resize(item->width(), item->height());
|
resize(item->width(), item->height());
|
||||||
item->installSceneEventFilter(this);
|
connect(m_declarativeItem.data(), SIGNAL(widthChanged()), this, SLOT(widthChanged()));
|
||||||
|
connect(m_declarativeItem.data(), SIGNAL(heightChanged()), this, SLOT(heightChanged()));
|
||||||
}
|
}
|
||||||
|
|
||||||
QDeclarativeItem *DeclarativeItemContainer::declarativeItem() const
|
QDeclarativeItem *DeclarativeItemContainer::declarativeItem() const
|
||||||
@ -56,11 +59,26 @@ void DeclarativeItemContainer::resizeEvent(QGraphicsSceneResizeEvent *event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DeclarativeItemContainer::sceneEventFilter(QGraphicsItem *watched, QEvent *event)
|
void DeclarativeItemContainer::widthChanged()
|
||||||
{
|
{
|
||||||
if (event->type() == QEvent::GraphicsSceneResize) {
|
if (!m_declarativeItem) {
|
||||||
resize(watched->boundingRect().size());
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QGraphicsWidget::sceneEventFilter(watched, event);
|
QSizeF newSize(size());
|
||||||
|
newSize.setWidth(m_declarativeItem.data()->width());
|
||||||
|
resize(newSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DeclarativeItemContainer::heightChanged()
|
||||||
|
{
|
||||||
|
if (!m_declarativeItem) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QSizeF newSize(size());
|
||||||
|
newSize.setHeight(m_declarativeItem.data()->height());
|
||||||
|
resize(newSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "declarativeitemcontainer_p.moc"
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
|
|
||||||
class DeclarativeItemContainer : public QGraphicsWidget
|
class DeclarativeItemContainer : public QGraphicsWidget
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DeclarativeItemContainer(QGraphicsItem *parent = 0);
|
DeclarativeItemContainer(QGraphicsItem *parent = 0);
|
||||||
~DeclarativeItemContainer();
|
~DeclarativeItemContainer();
|
||||||
@ -37,7 +39,10 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
||||||
bool sceneEventFilter(QGraphicsItem *watched, QEvent *event);
|
|
||||||
|
protected Q_SLOTS:
|
||||||
|
void widthChanged();
|
||||||
|
void heightChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWeakPointer<QDeclarativeItem> m_declarativeItem;
|
QWeakPointer<QDeclarativeItem> m_declarativeItem;
|
||||||
|
Loading…
Reference in New Issue
Block a user