FGQCanvas clipping / default text color fixes
Also fix some compiler warnings, but the main thing is text now defaults to white correctly if no color was set explicitly, and local/parent clip-reference-frames are supported.
This commit is contained in:
parent
4deb61d0af
commit
da65411ef4
5 changed files with 29 additions and 20 deletions
|
@ -175,30 +175,34 @@ void FGCanvasElement::paint(FGCanvasPaintContext *context) const
|
|||
QPainter* p = context->painter();
|
||||
p->save();
|
||||
|
||||
QTransform combined = combinedTransform();
|
||||
|
||||
if (_hasClip)
|
||||
{
|
||||
QTransform t = p->transform();
|
||||
|
||||
// clip is defined in the global coordinate system
|
||||
if (_clipFrame != ReferenceFrame::GLOBAL) {
|
||||
qWarning() << Q_FUNC_INFO << "implement support for non-global clips";
|
||||
if (_clipFrame == ReferenceFrame::GLOBAL) {
|
||||
// this rpelaces the transform entirely
|
||||
p->setTransform(context->globalCoordinateTransform());
|
||||
} else if (_clipFrame == ReferenceFrame::LOCAL) {
|
||||
p->setTransform(combined, true /* combine */);
|
||||
} else if (_clipFrame == ReferenceFrame::PARENT) {
|
||||
// incoming transform is already our parent
|
||||
} else {
|
||||
qWarning() << "Unhandled clip type:" << static_cast<int>(_clipFrame) << "at" << property()->path();
|
||||
}
|
||||
|
||||
#if defined(DEBUG_PAINTING)
|
||||
p->save();
|
||||
p->setTransform(context->globalCoordinateTransform());
|
||||
p->setPen(Qt::yellow);
|
||||
p->setBrush(QBrush(Qt::yellow, Qt::DiagCrossPattern));
|
||||
p->drawRect(_clipRect);
|
||||
p->restore();
|
||||
#endif
|
||||
|
||||
QTransform t = p->transform();
|
||||
p->setTransform(context->globalCoordinateTransform());
|
||||
p->setClipRect(_clipRect);
|
||||
p->setClipping(true);
|
||||
p->setTransform(t);
|
||||
p->setClipRect(_clipRect);
|
||||
p->setTransform(t); // restore the previous transformation
|
||||
}
|
||||
|
||||
QTransform combined = combinedTransform();
|
||||
p->setTransform(combined, true /* combine */);
|
||||
|
||||
if (!_fillColor.isValid()) {
|
||||
|
@ -385,7 +389,7 @@ void FGCanvasElement::markClipDirty()
|
|||
requestPolish();
|
||||
}
|
||||
|
||||
float FGCanvasElement::parseCSSValue(QByteArray value) const
|
||||
double FGCanvasElement::parseCSSValue(QByteArray value) const
|
||||
{
|
||||
value = value.trimmed();
|
||||
// deal with %, px suffixes
|
||||
|
@ -396,7 +400,7 @@ float FGCanvasElement::parseCSSValue(QByteArray value) const
|
|||
value.truncate(value.length() - 2);
|
||||
}
|
||||
bool ok = false;
|
||||
float v = value.toFloat(&ok);
|
||||
qreal v = value.toDouble(&ok);
|
||||
if (!ok) {
|
||||
qWarning() << "failed to parse:" << value;
|
||||
}
|
||||
|
@ -406,7 +410,7 @@ float FGCanvasElement::parseCSSValue(QByteArray value) const
|
|||
QColor FGCanvasElement::parseColorValue(QVariant value) const
|
||||
{
|
||||
QString colorString = value.toString();
|
||||
if (colorString.isEmpty() || colorString == "none") {
|
||||
if (colorString.isEmpty() || (colorString == QStringLiteral("none"))) {
|
||||
return QColor(); // return an invalid color
|
||||
}
|
||||
|
||||
|
|
|
@ -140,7 +140,7 @@ private:
|
|||
mutable ReferenceFrame _clipFrame = ReferenceFrame::GLOBAL;
|
||||
|
||||
void parseCSSClip(QByteArray value);
|
||||
float parseCSSValue(QByteArray value) const;
|
||||
double parseCSSValue(QByteArray value) const;
|
||||
};
|
||||
|
||||
using FGCanvasElementVec = std::vector<FGCanvasElement*>;
|
||||
|
|
|
@ -218,13 +218,13 @@ signals:
|
|||
void strokeChanged(QPen stroke);
|
||||
|
||||
protected:
|
||||
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
|
||||
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override
|
||||
{
|
||||
QQuickItem::geometryChanged(newGeometry, oldGeometry);
|
||||
update();
|
||||
}
|
||||
|
||||
QRectF boundingRect() const
|
||||
QRectF boundingRect() const override
|
||||
{
|
||||
if ((width() == 0.0) || (height() == 0.0)) {
|
||||
return QRectF(0.0, 0.0, implicitWidth(), implicitHeight());
|
||||
|
|
|
@ -210,7 +210,12 @@ void FGCanvasText::dumpElement()
|
|||
void FGCanvasText::doPaint(FGCanvasPaintContext *context) const
|
||||
{
|
||||
context->painter()->setFont(_font);
|
||||
context->painter()->setPen(fillColor());
|
||||
QColor c = fillColor();
|
||||
if (!c.isValid()) {
|
||||
c = Qt::white;
|
||||
}
|
||||
|
||||
context->painter()->setPen(c);
|
||||
context->painter()->setBrush(Qt::NoBrush);
|
||||
QRectF rect(0, 0, 1000, 1000);
|
||||
|
||||
|
|
|
@ -89,13 +89,13 @@ public:
|
|||
}
|
||||
|
||||
protected:
|
||||
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
|
||||
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override
|
||||
{
|
||||
QQuickItem::geometryChanged(newGeometry, oldGeometry);
|
||||
update();
|
||||
}
|
||||
|
||||
QRectF boundingRect() const
|
||||
QRectF boundingRect() const override
|
||||
{
|
||||
if (!widthValid() || !heightValid()) {
|
||||
return QRectF(QPointF(), m_size);
|
||||
|
|
Loading…
Reference in a new issue