From 05361085127d9849ee02b59b115a516c1bd05106 Mon Sep 17 00:00:00 2001 From: Aleks Kissinger Date: Sun, 19 Apr 2020 11:29:14 +0100 Subject: draw fill color in edge style icon --- src/data/style.cpp | 69 ++++++++++++++++++++++++++++++++-------------------- src/gui/pathitem.cpp | 7 ++++-- 2 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/data/style.cpp b/src/data/style.cpp index af6a13f..f4aa892 100644 --- a/src/data/style.cpp +++ b/src/data/style.cpp @@ -62,9 +62,11 @@ QColor Style::fillColor(bool tikzitOverride) const QBrush Style::brush() const { - QString col = propertyWithDefault("fill", "none", true); - if (col == "none") return Qt::NoBrush; - else return QBrush(tikzit->colorByName(col)); + if (hasFill()) { + return QBrush(fillColor()); + } else { + return Qt::NoBrush; + } } bool Style::hasFill() const @@ -74,7 +76,8 @@ bool Style::hasFill() const bool Style::hasStroke() const { - return (propertyWithDefault("draw", "none") != "none"); + if (isEdgeStyle()) return propertyWithDefault("draw", "black") != "none"; + else return (propertyWithDefault("draw", "none") != "none"); } QString Style::shape(bool tikzitOverride) const @@ -164,24 +167,28 @@ Style::DrawStyle Style::drawStyle() const QPen Style::pen() const { - QPen p(strokeColor()); - p.setWidthF((float)strokeThickness() * 2.0f); - - QVector pat; - switch (drawStyle()) { - case Dashed: - pat << 3.0 << 3.0; - p.setDashPattern(pat); - break; - case Dotted: - pat << 1.0 << 1.0; - p.setDashPattern(pat); - break; - case Solid: - break; - } + if (hasStroke()) { + QPen p(strokeColor()); + p.setWidthF((float)strokeThickness() * 2.0f); + + QVector pat; + switch (drawStyle()) { + case Dashed: + pat << 3.0 << 3.0; + p.setDashPattern(pat); + break; + case Dotted: + pat << 1.0 << 1.0; + p.setDashPattern(pat); + break; + case Solid: + break; + } - return p; + return p; + } else { + return Qt::NoPen; + } } QPainterPath Style::path() const @@ -237,19 +244,27 @@ QIcon Style::icon() const px.fill(Qt::transparent); QPainter painter(&px); - if (_data == 0) { - QPen pen(Qt::black); - pen.setWidth(3); - } else { - painter.setPen(pen()); +// if (_data == 0) { +// QPen pen(Qt::black); +// pen.setWidth(3); +// } else { +// painter.setPen(pen()); +// } + + QPen pn = pen(); + painter.setPen(pn); + + if (hasFill()) { + painter.fillRect(10,50,80,30,brush()); } painter.drawLine(10, 50, 90, 50); - QPen pn = pen(); pn.setStyle(Qt::SolidLine); painter.setPen(pn); + + switch (arrowHead()) { case Pointer: painter.drawLine(90,50,80,40); diff --git a/src/gui/pathitem.cpp b/src/gui/pathitem.cpp index 107281f..b45c0a5 100644 --- a/src/gui/pathitem.cpp +++ b/src/gui/pathitem.cpp @@ -33,8 +33,11 @@ void PathItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidge { Style *st = _path->edges().first()->style(); QPen pen = st->pen(); - painter->setPen(st->pen()); - painter->setBrush(st->brush()); + QBrush brush = st->brush(); + QColor c = brush.color(); + brush.setColor(QColor(c.red(),c.green(),c.blue(),200)); + painter->setPen(pen); + painter->setBrush(brush); painter->drawPath(painterPath()); } -- cgit v1.2.3