From c82a725e47663171d1ec79a6e23e9aa0dd7c6f94 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 17 Jun 2018 15:34:00 +0100 Subject: [PATCH] Fills working again in FGQCanvas --- utils/fgqcanvas/fgcanvaselement.cpp | 17 ++++++++++++----- utils/fgqcanvas/fgcanvaselement.h | 12 ++++++++++++ utils/fgqcanvas/fgcanvaspath.cpp | 5 ++++- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/utils/fgqcanvas/fgcanvaselement.cpp b/utils/fgqcanvas/fgcanvaselement.cpp index 4a489a6fc..9f4af0d13 100644 --- a/utils/fgqcanvas/fgcanvaselement.cpp +++ b/utils/fgqcanvas/fgcanvaselement.cpp @@ -47,7 +47,8 @@ QTransform qTransformFromCanvas(LocalProp* prop) bool FGCanvasElement::isStyleProperty(QByteArray name) { if ((name == "font") || (name == "line-height") || (name == "alignment") - || (name == "character-size") || (name == "fill") || (name == "background")) + || (name == "character-size") || (name == "fill") || (name == "background") + || (name == "fill-opacity")) { return true; } @@ -126,9 +127,9 @@ void FGCanvasElement::polish() _clipDirty = false; if (qq) { if (_hasClip) { - qq->setGlobalClip(_clipRect); + // qq->setGlobalClip(_clipRect); } else { - qq->clearClip(); + // qq->clearClip(); } } } @@ -139,6 +140,11 @@ void FGCanvasElement::polish() if (_styleDirty) { _fillColor = parseColorValue(getCascadedStyle("fill")); + const auto opacity = getCascadedStyle("fill-opacity"); + if (!opacity.isNull()) { + _fillColor.setAlphaF(opacity.toFloat()); + } + _styleDirty = false; } @@ -278,7 +284,7 @@ bool FGCanvasElement::onChildAdded(LocalProp *prop) } else if (prop->name() == "update") { // disable updates optionally? return true; - } else if (nm == "clip") { + } else if ((nm == "clip") || (nm == "clip-frame")) { connect(prop, &LocalProp::valueChanged, this, &FGCanvasElement::markClipDirty); return true; } @@ -344,6 +350,7 @@ void FGCanvasElement::markClipDirty() { _clipDirty = true; parseCSSClip(_propertyRoot->value("clip", QVariant()).toByteArray()); + _clipFrame = static_cast(_propertyRoot->value("clip-frame", 0).toInt()); requestPolish(); } @@ -490,7 +497,7 @@ void FGCanvasElement::parseCSSClip(QByteArray value) const float left = parseCSSValue(clipRectDesc.at(3)); _clipRect = QRectF(left, top, right - left, bottom - top); - qDebug() << "final clip rect:" << _clipRect << "from" << value; + // qDebug() << "final clip rect:" << _clipRect << "from" << value; _hasClip = true; requestPolish(); diff --git a/utils/fgqcanvas/fgcanvaselement.h b/utils/fgqcanvas/fgcanvaselement.h index 8d59f1e24..8775cdcb7 100644 --- a/utils/fgqcanvas/fgcanvaselement.h +++ b/utils/fgqcanvas/fgcanvaselement.h @@ -32,6 +32,17 @@ class CanvasItem; class QQuickItem; class CanvasConnection; +/** + * Coordinate reference frame (eg. "clip" property) + */ +enum class ReferenceFrame +{ + GLOBAL, ///< Global coordinates + PARENT, ///< Coordinates relative to parent coordinate frame + LOCAL ///< Coordinates relative to local coordinates (parent + /// coordinates with local transformations applied) +}; + class FGCanvasElement : public QObject { Q_OBJECT @@ -122,6 +133,7 @@ private: mutable bool _clipDirty = true; mutable bool _hasClip = false; mutable QRectF _clipRect; + mutable ReferenceFrame _clipFrame = ReferenceFrame::GLOBAL; void parseCSSClip(QByteArray value); float parseCSSValue(QByteArray value) const; diff --git a/utils/fgqcanvas/fgcanvaspath.cpp b/utils/fgqcanvas/fgcanvaspath.cpp index 11758ff89..4d4dcfd25 100644 --- a/utils/fgqcanvas/fgcanvaspath.cpp +++ b/utils/fgqcanvas/fgcanvaspath.cpp @@ -445,6 +445,9 @@ void FGCanvasPath::doPolish() _penDirty = false; } + if (_quickPath) { + _quickPath->setFillColor(fillColor()); + } } void FGCanvasPath::markStyleDirty() @@ -522,7 +525,7 @@ bool FGCanvasPath::onChildAdded(LocalProp *prop) return true; } - qDebug() << "path saw child:" << prop->name() << prop->index(); + qWarning() << "path saw unrecognized child:" << prop->name() << prop->index(); return false; }