[gegl-qt] Move child QGraphicsItem handling into NodeViewImplementation
- From: Jon Nordby <jonnor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl-qt] Move child QGraphicsItem handling into NodeViewImplementation
- Date: Sat, 24 Sep 2011 20:19:13 +0000 (UTC)
commit 6540fe9731fad370888dd55edfc5a41d10fc5aab
Author: Jon Nordby <jononor gmail com>
Date: Sat Sep 24 21:18:37 2011 +0200
Move child QGraphicsItem handling into NodeViewImplementation
Reduces responsibility of the widget (NodeViewDeclarativeItem)
and allows reuse in NodeViewGraphicsWidget.
gegl-qt/internal/nodeviewimplementation.cpp | 70 ++++++++++++++++++++++++++-
gegl-qt/internal/nodeviewimplementation.h | 7 +++
gegl-qt/nodeviewdeclarativeitem.cpp | 56 ++--------------------
gegl-qt/nodeviewdeclarativeitem.h | 5 --
4 files changed, 80 insertions(+), 58 deletions(-)
---
diff --git a/gegl-qt/internal/nodeviewimplementation.cpp b/gegl-qt/internal/nodeviewimplementation.cpp
index 881d24c..23d4e7d 100644
--- a/gegl-qt/internal/nodeviewimplementation.cpp
+++ b/gegl-qt/internal/nodeviewimplementation.cpp
@@ -17,6 +17,7 @@
*/
#include "nodeviewimplementation.h"
+#include "internal/nodeviewchilditem.h"
#include <QtCore>
#include <QTransform>
@@ -91,10 +92,16 @@ NodeViewImplementation::NodeViewImplementation(DrawTransform drawTransform, QObj
, mOptions(0)
, mViewportSize(-1.0, -1.0)
, mDrawTransform(drawTransform)
+ , mChildItem(mDrawTransform == DrawTransformExternal ? new NodeViewChildItem(this, 0) : 0)
{
setOptions(0); // default
connect(timer, SIGNAL(timeout()), this, SLOT(processNode()));
+
+ if (mDrawTransform == DrawTransformExternal) {
+ connect(this, SIGNAL(viewAreaChanged(QRectF)),
+ this, SLOT(handleViewAreaChanged(QRectF)));
+ }
}
NodeViewImplementation::~NodeViewImplementation()
@@ -104,6 +111,7 @@ NodeViewImplementation::~NodeViewImplementation()
gegl_processor_destroy(processor);
}
delete mOptions;
+ delete mChildItem;
}
QTransform
@@ -172,6 +180,15 @@ NodeViewImplementation::setOptions(NodeViewOptions *newOptions)
connect(options(), SIGNAL(autoScalePolicyChanged()),
this, SLOT(updateAutoCenterScale()));
+ if (mDrawTransform == DrawTransformExternal) {
+
+ connect(options(), SIGNAL(scaleChanged()),
+ this, SLOT(handleScaleChanged()));
+ connect(options(), SIGNAL(translationChanged()),
+ this, SLOT(handleTranslationChanged()));
+ }
+
+
Q_EMIT viewAreaChanged(QRectF(0.0, 0.0, -1.0, -1.0)); // Redraws everything
}
@@ -244,6 +261,11 @@ void
NodeViewImplementation::viewportSizeChanged(QSizeF newSize)
{
mViewportSize = newSize;
+
+ if (mChildItem) {
+ mChildItem->updateSize(newSize);
+ }
+
updateAutoCenterScale();
}
@@ -290,7 +312,7 @@ NodeViewImplementation::nodeComputed(GeglRectangle *rect)
Q_EMIT viewAreaChanged(viewArea);
}
-/* XXX: Should this really be part of this class? Consider moving to dedicted class? */
+
void
NodeViewImplementation::paint(QPainter *painter, const QRectF & viewRect)
{
@@ -325,3 +347,49 @@ NodeViewImplementation::paint(QPainter *painter, const QRectF & viewRect)
g_free(buffer);
}
+
+
+void
+NodeViewImplementation::handleScaleChanged()
+{
+ float newScale = options()->scale();
+
+ if (!mChildItem || mChildItem->scale() == newScale) {
+ return;
+ }
+
+ mChildItem->setScale(newScale);
+}
+
+void
+NodeViewImplementation::handleTranslationChanged()
+{
+ float newX = options()->translationX();
+ float newY = options()->translationY();
+
+ if (!mChildItem || mChildItem->x() == newX || mChildItem->y() == newY) {
+ return;
+ }
+
+ mChildItem->setPos(newX, newY);
+}
+
+QGraphicsItem *
+NodeViewImplementation::childItem()
+{
+ return mChildItem;
+}
+
+void
+NodeViewImplementation::handleViewAreaChanged(QRectF rect)
+{
+ if (!mChildItem) {
+ return;
+ }
+
+ if (rect.isValid()) {
+ mChildItem->update(rect);
+ } else {
+ mChildItem->update(mChildItem->boundingRect());
+ }
+}
diff --git a/gegl-qt/internal/nodeviewimplementation.h b/gegl-qt/internal/nodeviewimplementation.h
index 12bbc0f..ba982ba 100644
--- a/gegl-qt/internal/nodeviewimplementation.h
+++ b/gegl-qt/internal/nodeviewimplementation.h
@@ -26,6 +26,8 @@
namespace GeglQt {
+class NodeViewChildItem;
+
class NodeViewImplementation : public QObject
{
Q_OBJECT
@@ -47,6 +49,7 @@ public:
void setOptions(GeglQt::NodeViewOptions *newOptions);
void paint(QPainter *painter, const QRectF & viewRect);
+ QGraphicsItem *childItem();
public Q_SLOTS:
void viewportSizeChanged(QSizeF newSize);
@@ -63,6 +66,9 @@ private Q_SLOTS:
void processNode();
void transformationChanged();
void updateAutoCenterScale();
+ void handleScaleChanged();
+ void handleTranslationChanged();
+ void handleViewAreaChanged(QRectF rect);
private:
void modelAreaChanged();
@@ -76,6 +82,7 @@ private:
GeglQt::NodeViewOptions *mOptions;
QSizeF mViewportSize;
DrawTransform mDrawTransform;
+ NodeViewChildItem *mChildItem;
};
}
diff --git a/gegl-qt/nodeviewdeclarativeitem.cpp b/gegl-qt/nodeviewdeclarativeitem.cpp
index d8f12e7..353e030 100644
--- a/gegl-qt/nodeviewdeclarativeitem.cpp
+++ b/gegl-qt/nodeviewdeclarativeitem.cpp
@@ -18,34 +18,23 @@
#include "nodeviewdeclarativeitem.h"
#include "internal/nodeviewimplementation.h"
-#include "internal/nodeviewchilditem.h"
using namespace GeglQt;
NodeViewDeclarativeItem::NodeViewDeclarativeItem(QDeclarativeItem *parent)
: QDeclarativeItem(parent)
, priv(new NodeViewImplementation(NodeViewImplementation::DrawTransformExternal))
- , childItem(new NodeViewChildItem(priv, 0))
{
setFlag(QGraphicsItem::ItemHasNoContents, false);
- childItem->setParentItem(static_cast<QGraphicsItem *>(this));
+ priv->childItem()->setParentItem(static_cast<QGraphicsItem *>(this));
- connect(priv, SIGNAL(viewAreaChanged(QRectF)),
- this, SLOT(invalidate(QRectF)));
connect(priv, SIGNAL(viewportSizeRequest(QSizeF)),
this, SLOT(viewportSizeChangeRequested(QSizeF)));
-
- connect(this, SIGNAL(optionsChanged()),
- this, SLOT(handleOptionsChanged()));
-
- // Initial signal is emitted before the connection, call handler manually
- handleOptionsChanged();
}
NodeViewDeclarativeItem::~NodeViewDeclarativeItem()
{
- delete childItem;
delete priv;
}
@@ -97,11 +86,8 @@ NodeViewDeclarativeItem::options() const
void
NodeViewDeclarativeItem::invalidate(QRectF rect)
{
- if (rect.isValid()) {
- childItem->update(rect);
- } else {
- childItem->update(childItem->boundingRect());
- }
+ // Handled by private class
+ Q_UNUSED(rect);
}
void
@@ -117,7 +103,7 @@ NodeViewDeclarativeItem::paint(QPainter *painter,
const QStyleOptionGraphicsItem *option,
QWidget *widget)
{
- // Handled by child item
+ // Handled by private class
Q_UNUSED(widget);
Q_UNUSED(option);
Q_UNUSED(widget);
@@ -129,40 +115,6 @@ NodeViewDeclarativeItem::geometryChanged(const QRectF & newGeometry,
{
QDeclarativeItem::geometryChanged(newGeometry, oldGeometry);
- childItem->updateSize(newGeometry.size());
priv->viewportSizeChanged(newGeometry.size());
}
-void
-NodeViewDeclarativeItem::handleScaleChanged()
-{
- float newScale = options()->scale();
-
- if (childItem->scale() == newScale) {
- return;
- }
-
- childItem->setScale(newScale);
-}
-
-void
-NodeViewDeclarativeItem::handleTranslationChanged()
-{
- float newX = options()->translationX();
- float newY = options()->translationY();
-
- if (childItem->x() == newX || childItem->y() == newY) {
- return;
- }
-
- childItem->setPos(newX, newY);
-}
-
-void
-NodeViewDeclarativeItem::handleOptionsChanged()
-{
- connect(options(), SIGNAL(scaleChanged()),
- this, SLOT(handleScaleChanged()));
- connect(options(), SIGNAL(translationChanged()),
- this, SLOT(handleTranslationChanged()));
-}
diff --git a/gegl-qt/nodeviewdeclarativeitem.h b/gegl-qt/nodeviewdeclarativeitem.h
index 58a3fc4..a844643 100644
--- a/gegl-qt/nodeviewdeclarativeitem.h
+++ b/gegl-qt/nodeviewdeclarativeitem.h
@@ -30,7 +30,6 @@ typedef GeglNode * GeglNodePtr;
namespace GeglQt {
class NodeViewImplementation;
-class NodeViewChildItem; // FIXME: should be handled internally
class NodeViewDeclarativeItem : public QDeclarativeItem
{
@@ -65,14 +64,10 @@ Q_SIGNALS:
private Q_SLOTS:
void invalidate(QRectF rect);
void viewportSizeChangeRequested(QSizeF);
- void handleScaleChanged();
- void handleTranslationChanged();
- void handleOptionsChanged();
private:
Q_DISABLE_COPY(NodeViewDeclarativeItem)
NodeViewImplementation *priv;
- NodeViewChildItem *childItem; //FIXME: need to go into priv
};
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]