From 569925b61b59e936f1c0223caf58e821b0e04ee1 Mon Sep 17 00:00:00 2001 From: James Turner <zakalawe@mac.com> Date: Sun, 18 Dec 2016 23:52:16 +0000 Subject: [PATCH] Remote-canvas work, based on Extra-500 testing. --- utils/fgqcanvas/fgcanvaselement.cpp | 61 ++++++++++++++++++++++++----- utils/fgqcanvas/fgcanvaselement.h | 6 +++ utils/fgqcanvas/fgcanvasgroup.cpp | 43 -------------------- utils/fgqcanvas/fgcanvasgroup.h | 4 -- utils/fgqcanvas/fgcanvaspath.cpp | 4 +- utils/fgqcanvas/fgcanvastext.cpp | 2 +- utils/fgqcanvas/fgqcanvasimage.cpp | 14 +++++++ utils/fgqcanvas/fgqcanvasimage.h | 3 ++ 8 files changed, 79 insertions(+), 58 deletions(-) diff --git a/utils/fgqcanvas/fgcanvaselement.cpp b/utils/fgqcanvas/fgcanvaselement.cpp index 480bac9c5..b66030ec5 100644 --- a/utils/fgqcanvas/fgcanvaselement.cpp +++ b/utils/fgqcanvas/fgcanvaselement.cpp @@ -27,7 +27,7 @@ QTransform qTransformFromCanvas(LocalProp* prop) bool FGCanvasElement::isStyleProperty(QByteArray name) { if ((name == "font") || (name == "line-height") || (name == "alignment") - || (name == "character-size") || (name == "fill")) + || (name == "character-size") || (name == "fill") || (name == "background")) { return true; } @@ -61,10 +61,30 @@ void FGCanvasElement::paint(FGCanvasPaintContext *context) const return; } - // qDebug() << "painting" << _svgElementId << "at" << _propertyRoot->path(); + QPainter* p = context->painter(); - context->painter()->save(); - context->painter()->setTransform(combinedTransform(), true /* combine */); + if (_clipDirty) { + // re-calculate clip + QVariant clipSpec = _propertyRoot->value("clip", QVariant()); + if (clipSpec.isNull()) { + _hasClip = false; + } else { + // https://www.w3.org/wiki/CSS/Properties/clip for the stupid order here + QStringList clipRectDesc = clipSpec.toString().split(','); + int top = clipRectDesc.at(0).toInt(); + int right = clipRectDesc.at(1).toInt(); + int bottom = clipRectDesc.at(2).toInt(); + int left = clipRectDesc.at(3).toInt(); + + _clipRect = QRectF(left, top, right - left, bottom - top); + _hasClip = true; + } + + _clipDirty = false; + } + + p->save(); + p->setTransform(combinedTransform(), true /* combine */); if (_styleDirty) { _fillColor = parseColorValue(getCascadedStyle("fill")); @@ -72,14 +92,29 @@ void FGCanvasElement::paint(FGCanvasPaintContext *context) const } if (!_fillColor.isValid()) { - context->painter()->setBrush(Qt::NoBrush); + p->setBrush(Qt::NoBrush); } else { - context->painter()->setBrush(_fillColor); + p->setBrush(_fillColor); + } + + if (_hasClip) { + p->save(); + p->setPen(Qt::yellow); + p->setBrush(QBrush(Qt::yellow, Qt::DiagCrossPattern)); + p->drawRect(_clipRect); + p->restore(); + + // context->painter()->setClipRect(_clipRect); + // context->painter()->setClipping(true); } doPaint(context); - context->painter()->restore(); + if (_hasClip) { + p->setClipping(false); + } + + p->restore(); } void FGCanvasElement::doPaint(FGCanvasPaintContext* context) const @@ -132,10 +167,10 @@ bool FGCanvasElement::onChildAdded(LocalProp *prop) } else if (nm == "visible") { return true; } else if (nm == "tf-rot-index") { - connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::markTransformsDirty); + // ignored, this is noise from the Nasal SVG parswer return true; } else if (nm.startsWith("center-offset-")) { - connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::markTransformsDirty); + // ignored, this is noise from the Nasal SVG parswer return true; } else if (nm == "center") { connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::onCenterChanged); @@ -156,6 +191,9 @@ bool FGCanvasElement::onChildAdded(LocalProp *prop) } else if (prop->name() == "update") { // disable updates optionally? return true; + } else if (nm == "clip") { + connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::markClipDirty); + return true; } if (isStyleProperty(nm)) { @@ -208,6 +246,11 @@ void FGCanvasElement::markTransformsDirty() _transformsDirty = true; } +void FGCanvasElement::markClipDirty() +{ + _clipDirty = true; +} + QColor FGCanvasElement::parseColorValue(QVariant value) const { QString colorString = value.toString(); diff --git a/utils/fgqcanvas/fgcanvaselement.h b/utils/fgqcanvas/fgcanvaselement.h index 6a84d3b87..b86cd9e75 100644 --- a/utils/fgqcanvas/fgcanvaselement.h +++ b/utils/fgqcanvas/fgcanvaselement.h @@ -57,6 +57,8 @@ private: void onVisibleChanged(QVariant value); + void markClipDirty(); + private: friend class FGCanvasGroup; @@ -71,6 +73,10 @@ private: mutable QColor _fillColor; int _zIndex = 0; QByteArray _svgElementId; + + mutable bool _clipDirty = true; + mutable bool _hasClip = false; + mutable QRectF _clipRect; }; using FGCanvasElementVec = std::vector<FGCanvasElement*>; diff --git a/utils/fgqcanvas/fgcanvasgroup.cpp b/utils/fgqcanvas/fgcanvasgroup.cpp index fd56fcc11..a5950b30d 100644 --- a/utils/fgqcanvas/fgcanvasgroup.cpp +++ b/utils/fgqcanvas/fgcanvasgroup.cpp @@ -53,26 +53,6 @@ unsigned int FGCanvasGroup::indexOfChild(const FGCanvasElement *e) const void FGCanvasGroup::doPaint(FGCanvasPaintContext *context) const { - if (_clipDirty) { - // re-calculate clip - QVariant clipSpec = _propertyRoot->value("clip", QVariant()); - if (clipSpec.isNull()) { - _hasClip = false; - } else { - // https://www.w3.org/wiki/CSS/Properties/clip for the stupid order here - QStringList clipRectDesc = clipSpec.toString().split(','); - int top = clipRectDesc.at(0).toInt(); - int right = clipRectDesc.at(1).toInt(); - int bottom = clipRectDesc.at(2).toInt(); - int left = clipRectDesc.at(3).toInt(); - - _clipRect = QRectF(left, top, right - left, bottom - top); - _hasClip = true; - } - - _clipDirty = false; - } - if (_zIndicesDirty) { std::sort(_children.begin(), _children.end(), [](const FGCanvasElement* a, FGCanvasElement* b) { return a->zIndex() < b->zIndex(); }); @@ -84,24 +64,9 @@ void FGCanvasGroup::doPaint(FGCanvasPaintContext *context) const _cachedSymbolDirty = false; } - if (_hasClip) { - context->painter()->save(); - context->painter()->setPen(Qt::yellow); - context->painter()->setBrush(QBrush(Qt::yellow, Qt::DiagCrossPattern)); - context->painter()->drawRect(_clipRect); - context->painter()->restore(); - - // context->painter()->setClipRect(_clipRect); - // context->painter()->setClipping(true); - } - for (FGCanvasElement* element : _children) { element->paint(context); } - - if (_hasClip) { - context->painter()->setClipping(false); - } } bool FGCanvasGroup::onChildAdded(LocalProp *prop) @@ -134,9 +99,6 @@ bool FGCanvasGroup::onChildAdded(LocalProp *prop) _children.push_back(new FGQCanvasMap(this, prop)); newChildCount++; return true; - } else if (nm == "clip") { - connect(prop, &LocalProp::valueChanged, this, &FGCanvasGroup::markClipDirty); - return true; } else if (nm == "symbol-type") { connect(prop, &LocalProp::valueChanged, this, &FGCanvasGroup::markCachedSymbolDirty); return true; @@ -199,11 +161,6 @@ void FGCanvasGroup::markStyleDirty() } } -void FGCanvasGroup::markClipDirty() -{ - _clipDirty = true; -} - void FGCanvasGroup::markCachedSymbolDirty() { _cachedSymbolDirty = true; diff --git a/utils/fgqcanvas/fgcanvasgroup.h b/utils/fgqcanvas/fgcanvasgroup.h index 3c21f30f6..2696c14be 100644 --- a/utils/fgqcanvas/fgcanvasgroup.h +++ b/utils/fgqcanvas/fgcanvasgroup.h @@ -33,15 +33,11 @@ protected: virtual void markStyleDirty() override; private: - void markClipDirty(); void markCachedSymbolDirty(); int indexOfChildWithProp(LocalProp *prop) const; private: mutable FGCanvasElementVec _children; - mutable bool _clipDirty = true; - mutable bool _hasClip = false; - mutable QRectF _clipRect; mutable bool _zIndicesDirty = false; mutable bool _cachedSymbolDirty = false; }; diff --git a/utils/fgqcanvas/fgcanvaspath.cpp b/utils/fgqcanvas/fgcanvaspath.cpp index dfe4f7967..c6f9cd210 100644 --- a/utils/fgqcanvas/fgcanvaspath.cpp +++ b/utils/fgqcanvas/fgcanvaspath.cpp @@ -344,7 +344,7 @@ bool FGCanvasPath::rebuildFromRect(std::vector<int>& commands, std::vector<float LocalProp* rectProp = _propertyRoot->getWithPath("rect"); if (hasComplexBorderRadius(_propertyRoot)) { // build a full path - qWarning() << "implement me"; + qWarning() << Q_FUNC_INFO << "implement me"; _paintType = Path; } else { float top = rectProp->value("top", 0.0).toFloat(); @@ -622,6 +622,8 @@ static Qt::PenCapStyle qtCapFromCanvas(QString s) return Qt::FlatCap; } else if (s == "round") { return Qt::RoundCap; + } else if (s == "square") { + return Qt::SquareCap; } else { qDebug() << Q_FUNC_INFO << s; } diff --git a/utils/fgqcanvas/fgcanvastext.cpp b/utils/fgqcanvas/fgcanvastext.cpp index 35d28ec11..1c321e1c0 100644 --- a/utils/fgqcanvas/fgcanvastext.cpp +++ b/utils/fgqcanvas/fgcanvastext.cpp @@ -21,7 +21,7 @@ void FGCanvasText::doPaint(FGCanvasPaintContext *context) const context->painter()->setFont(_font); context->painter()->setPen(fillColor()); - + context->painter()->setBrush(Qt::NoBrush); QRectF rect(0, 0, 1000, 1000); if (_alignment & Qt::AlignBottom) { diff --git a/utils/fgqcanvas/fgqcanvasimage.cpp b/utils/fgqcanvas/fgqcanvasimage.cpp index 0d2611318..6e028f5fb 100644 --- a/utils/fgqcanvas/fgqcanvasimage.cpp +++ b/utils/fgqcanvas/fgqcanvasimage.cpp @@ -28,12 +28,26 @@ bool FGQCanvasImage::onChildAdded(LocalProp *prop) return true; } + const QByteArray nm = prop->name(); + if ((nm == "source") || (nm == "src") || (nm == "size") || (nm == "file")) { + connect(prop, &LocalProp::valueChanged, this, &FGQCanvasImage::markImageDirty); + return true; + } + qDebug() << "image saw child:" << prop->name(); return false; } +void FGQCanvasImage::markImageDirty() +{ + _imageDirty = true; +} + void FGQCanvasImage::rebuildImage() const { + qDebug() << "source" << _propertyRoot->value("source", QString()); + qDebug() << "src" << _propertyRoot->value("src", QString()); + qDebug() << "file" << _propertyRoot->value("file", QString()); } diff --git a/utils/fgqcanvas/fgqcanvasimage.h b/utils/fgqcanvas/fgqcanvasimage.h index 35e3da239..f52f617ef 100644 --- a/utils/fgqcanvas/fgqcanvasimage.h +++ b/utils/fgqcanvas/fgqcanvasimage.h @@ -19,10 +19,13 @@ private: bool onChildAdded(LocalProp *prop) override; void rebuildImage() const; + + void markImageDirty(); private: mutable bool _imageDirty; mutable QPixmap _image; QString _source; + mutable QSizeF _destSize; }; #endif // FGQCANVASIMAGE_H