[gegl-qt] Widgets: Support translation.
- From: Jon Nordby <jonnor src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl-qt] Widgets: Support translation.
- Date: Sun, 31 Jul 2011 17:43:50 +0000 (UTC)
commit 118509aa6b2e1710a68f65ee1850b4a82ee9df0d
Author: Jon Nordby <jononor gmail com>
Date: Sun Jul 31 19:09:43 2011 +0200
Widgets: Support translation.
Also:
- Moved from QRect to QRectF for view coordinate areas.
gegl-qt/geglqtdeclarativeview.cpp | 15 +++++--
gegl-qt/geglqtdeclarativeview.h | 2 +-
gegl-qt/geglqtgraphicswidgetview.cpp | 15 +++++--
gegl-qt/geglqtgraphicswidgetview.h | 2 +-
gegl-qt/geglqtview.cpp | 15 +++++--
gegl-qt/geglqtview.h | 2 +-
gegl-qt/geglqtviewimplementation.cpp | 72 +++++++++++++++++++++++++++++-----
gegl-qt/geglqtviewimplementation.h | 8 +++-
8 files changed, 101 insertions(+), 30 deletions(-)
---
diff --git a/gegl-qt/geglqtdeclarativeview.cpp b/gegl-qt/geglqtdeclarativeview.cpp
index 5882bde..35973ca 100644
--- a/gegl-qt/geglqtdeclarativeview.cpp
+++ b/gegl-qt/geglqtdeclarativeview.cpp
@@ -7,8 +7,8 @@ GeglQtDeclarativeView::GeglQtDeclarativeView(QDeclarativeItem *parent)
{
setFlag(QGraphicsItem::ItemHasNoContents, false);
- connect(priv, SIGNAL(viewAreaChanged(QRect)),
- this, SLOT(invalidate(QRect)));
+ connect(priv, SIGNAL(viewAreaChanged(QRectF)),
+ this, SLOT(invalidate(QRectF)));
}
GeglQtDeclarativeView::~GeglQtDeclarativeView()
@@ -40,10 +40,15 @@ GeglQtDeclarativeView::options() const
}
void
-GeglQtDeclarativeView::invalidate(QRect rect)
+GeglQtDeclarativeView::invalidate(QRectF rect)
{
qDebug() << __PRETTY_FUNCTION__ << rect;
- update(QRectF(rect));
+
+ if (rect.isValid()) {
+ update(rect);
+ } else {
+ update(boundingRect());
+ }
}
void
@@ -52,7 +57,7 @@ GeglQtDeclarativeView::paint(QPainter *painter,
QWidget *widget)
{
Q_UNUSED(widget);
- QRect rect(option->exposedRect.toRect());
+ QRectF rect(option->exposedRect);
qDebug() << __PRETTY_FUNCTION__ << rect;
priv->paint(painter, rect);
diff --git a/gegl-qt/geglqtdeclarativeview.h b/gegl-qt/geglqtdeclarativeview.h
index 0a6708d..d21e833 100644
--- a/gegl-qt/geglqtdeclarativeview.h
+++ b/gegl-qt/geglqtdeclarativeview.h
@@ -30,7 +30,7 @@ Q_SIGNALS:
void inputNodeChanged();
private Q_SLOTS:
- void invalidate(QRect rect);
+ void invalidate(QRectF rect);
private:
GeglQtViewImplementation *priv;
diff --git a/gegl-qt/geglqtgraphicswidgetview.cpp b/gegl-qt/geglqtgraphicswidgetview.cpp
index 0bad69e..b7b9f35 100644
--- a/gegl-qt/geglqtgraphicswidgetview.cpp
+++ b/gegl-qt/geglqtgraphicswidgetview.cpp
@@ -23,8 +23,8 @@ GeglQtGraphicsWidgetView::GeglQtGraphicsWidgetView(QGraphicsItem * parent)
: QGraphicsWidget(parent)
, priv(new GeglQtViewImplementation())
{
- connect(priv, SIGNAL(viewAreaChanged(QRect)),
- this, SLOT(invalidate(QRect)));
+ connect(priv, SIGNAL(viewAreaChanged(QRectF)),
+ this, SLOT(invalidate(QRectF)));
}
@@ -53,10 +53,15 @@ GeglQtGraphicsWidgetView::options() const
}
void
-GeglQtGraphicsWidgetView::invalidate(QRect rect)
+GeglQtGraphicsWidgetView::invalidate(QRectF rect)
{
qDebug() << __PRETTY_FUNCTION__ << rect;
- update(QRectF(rect));
+
+ if (rect.isValid()) {
+ update(rect);
+ } else {
+ update(boundingRect());
+ }
}
void
@@ -65,7 +70,7 @@ GeglQtGraphicsWidgetView::paint(QPainter *painter,
QWidget *widget)
{
Q_UNUSED(widget);
- QRect rect(option->exposedRect.toRect());
+ QRectF rect(option->exposedRect);
qDebug() << __PRETTY_FUNCTION__ << rect;
priv->paint(painter, rect);
diff --git a/gegl-qt/geglqtgraphicswidgetview.h b/gegl-qt/geglqtgraphicswidgetview.h
index fcb09d1..3965ee4 100644
--- a/gegl-qt/geglqtgraphicswidgetview.h
+++ b/gegl-qt/geglqtgraphicswidgetview.h
@@ -42,7 +42,7 @@ public:
//! reimpl end
private Q_SLOTS:
- void invalidate(QRect rect);
+ void invalidate(QRectF rect);
private:
GeglQtViewImplementation *priv;
diff --git a/gegl-qt/geglqtview.cpp b/gegl-qt/geglqtview.cpp
index 2ce042f..668bc1d 100644
--- a/gegl-qt/geglqtview.cpp
+++ b/gegl-qt/geglqtview.cpp
@@ -37,8 +37,8 @@ GeglQtView::GeglQtView(QWidget *parent)
: QWidget(parent),
priv(new GeglQtViewImplementation())
{
- connect(priv, SIGNAL(viewAreaChanged(QRect)),
- this, SLOT(invalidate(QRect)));
+ connect(priv, SIGNAL(viewAreaChanged(QRectF)),
+ this, SLOT(invalidate(QRectF)));
}
GeglQtView::~GeglQtView()
@@ -65,10 +65,15 @@ GeglQtView::options() const
}
void
-GeglQtView::invalidate(QRect rect)
+GeglQtView::invalidate(QRectF rect)
{
qDebug() << __PRETTY_FUNCTION__ << rect;
- update(rect);
+
+ if (rect.isValid()) {
+ update(rect.toRect());
+ } else {
+ update();
+ }
}
//! \brief Draw the view of GeglNode onto the widget
@@ -78,6 +83,6 @@ GeglQtView::paintEvent(QPaintEvent *event)
qDebug() << __PRETTY_FUNCTION__ << event->rect();
QPainter painter(this);
- priv->paint(&painter, event->rect());
+ priv->paint(&painter, QRectF(event->rect()));
}
diff --git a/gegl-qt/geglqtview.h b/gegl-qt/geglqtview.h
index 6ec4b9e..46ffb48 100644
--- a/gegl-qt/geglqtview.h
+++ b/gegl-qt/geglqtview.h
@@ -45,7 +45,7 @@ public:
//! \reimpl end
private Q_SLOTS:
- void invalidate(QRect rect);
+ void invalidate(QRectF rect);
private:
Q_DISABLE_COPY(GeglQtView)
diff --git a/gegl-qt/geglqtviewimplementation.cpp b/gegl-qt/geglqtviewimplementation.cpp
index 942e942..20caadc 100644
--- a/gegl-qt/geglqtviewimplementation.cpp
+++ b/gegl-qt/geglqtviewimplementation.cpp
@@ -18,6 +18,41 @@
#include "geglqtviewimplementation.h"
+#include <QtCore>
+
+/* Utility functions */
+namespace {
+ void gegl_rectangle_set_from_qrect(GeglRectangle *rect, const QRect &qrect)
+ {
+ rect->x = qrect.x();
+ rect->y = qrect.y();
+ rect->width = qrect.width();
+ rect->height = qrect.height();
+ }
+
+ void qrect_set_from_gegl_rectangle(QRect &qrect, const GeglRectangle *rect)
+ {
+ qrect.setX(rect->x);
+ qrect.setY(rect->y);
+ qrect.setWidth(rect->width);
+ qrect.setHeight(rect->height);
+ }
+
+ /* TODO: handle the clipping caused by the viewport size */
+ QRectF viewAreaFromModelArea(const QRectF & modelArea, GeglQtViewOptions *viewOptions)
+ {
+ QTransform transform = viewOptions->transformation();
+ return transform.mapRect(modelArea);
+ }
+
+ QRectF modelAreaFromViewArea(const QRectF & viewArea, GeglQtViewOptions *viewOptions)
+ {
+ Q_ASSERT(transform.isInvertible());
+ QTransform transform = viewOptions->transformation().inverted();
+ return transform.mapRect(viewArea);
+ }
+}
+
/* Just forward to the implementation class. */
static void
invalidated_event(GeglNode *node, GeglRectangle *rect, GeglQtViewImplementation *impl)
@@ -51,8 +86,10 @@ GeglQtViewImplementation::GeglQtViewImplementation(QObject *parent)
, mInputNode(0)
, processor(0)
, timer(new QTimer())
- , mOptions(new GeglQtViewOptions())
+ , mOptions(0)
{
+ setOptions(0); // default
+
connect(timer, SIGNAL(timeout()), this, SLOT(processNode()));
}
@@ -100,7 +137,7 @@ GeglQtViewImplementation::options() const
void
GeglQtViewImplementation::setOptions(GeglQtViewOptions *newOptions)
{
- if (mOptions == newOptions) {
+ if (mOptions && mOptions == newOptions) {
return;
}
@@ -108,6 +145,22 @@ GeglQtViewImplementation::setOptions(GeglQtViewOptions *newOptions)
* Use refcounting instead? */
delete mOptions;
mOptions = newOptions ? newOptions : new GeglQtViewOptions();
+
+ connect(options(), SIGNAL(transformationChanged()),
+ this, SLOT(transformationChanged()));
+}
+
+/* The model->view transformation changed
+ * we must recalculate the viewport */
+void
+GeglQtViewImplementation::transformationChanged()
+{
+ /* OPTIMIZE: On simple transformation changes like
+ * translation, only a portion of the viewport actually needs to be redrawn. */
+
+ QRectF invalidRect(0.0, 0.0, -1.0, -1.0);
+ Q_ASSERT(!invalidRect.isValid());
+ Q_EMIT viewAreaChanged(invalidRect); // Redraws everything
}
/* An area in the GeglNode has been invalidated,
@@ -147,14 +200,15 @@ GeglQtViewImplementation::processNode()
void
GeglQtViewImplementation::nodeComputed(GeglRectangle *rect)
{
- qDebug() << __PRETTY_FUNCTION__ << rect;
- QRect viewArea(rect->x, rect->y, rect->width, rect->height);
- Q_EMIT(viewAreaChanged(viewArea));
+ QRect modelRect;
+ qrect_set_from_gegl_rectangle(modelRect, rect);
+ QRectF viewArea = viewAreaFromModelArea(QRectF(modelRect), options());
+ Q_EMIT viewAreaChanged(viewArea);
}
/* XXX: Should this really be part of this class? Consider moving to dedicted class? */
void
-GeglQtViewImplementation::paint(QPainter *painter, const QRect & viewRect)
+GeglQtViewImplementation::paint(QPainter *painter, const QRectF & viewRect)
{
guchar *buffer = NULL;
GeglRectangle roi;
@@ -175,10 +229,8 @@ GeglQtViewImplementation::paint(QPainter *painter, const QRect & viewRect)
return;
}
- roi.x = viewRect.x();
- roi.y = viewRect.y();
- roi.width = viewRect.width();
- roi.height = viewRect.height();
+ QRect modelRect = modelAreaFromViewArea(viewRect, options()).toRect();
+ gegl_rectangle_set_from_qrect(&roi, modelRect);
buffer = (guchar *)g_malloc ((roi.width) * (roi.height) * 4);
diff --git a/gegl-qt/geglqtviewimplementation.h b/gegl-qt/geglqtviewimplementation.h
index 439d952..e52e47a 100644
--- a/gegl-qt/geglqtviewimplementation.h
+++ b/gegl-qt/geglqtviewimplementation.h
@@ -38,17 +38,21 @@ public:
GeglQtViewOptions *options() const;
void setOptions(GeglQtViewOptions *newOptions);
- void paint(QPainter *painter, const QRect & viewRect);
+ void paint(QPainter *painter, const QRectF & viewRect);
public: // Only public because invalidate_event and computed_event needs them.
void nodeInvalidated(GeglRectangle *rect);
void nodeComputed(GeglRectangle *rect);
Q_SIGNALS:
- void viewAreaChanged(QRect);
+ void viewAreaChanged(QRectF area);
private Q_SLOTS:
void processNode();
+ void transformationChanged();
+
+private:
+ void modelAreaChanged();
private:
GeglNode *mInputNode; // The node the widget displays.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]