Improve Appearance of Reply Curve (#4077)

This commit is contained in:
Daniel Sage
2022-11-02 04:19:44 -04:00
committed by GitHub
parent 495f3ed4a9
commit 7640677a43
7 changed files with 44 additions and 43 deletions
+28 -14
View File
@@ -442,11 +442,12 @@ int TextIconLayoutElement::getXFromIndex(int index)
}
ReplyCurveLayoutElement::ReplyCurveLayoutElement(MessageElement &creator,
const QSize &size,
float thickness,
int width, float thickness,
float radius,
float neededMargin)
: MessageLayoutElement(creator, size)
: MessageLayoutElement(creator, QSize(width, 0))
, pen_(QColor("#888"), thickness, Qt::SolidLine, Qt::RoundCap)
, radius_(radius)
, neededMargin_(neededMargin)
{
}
@@ -454,23 +455,36 @@ ReplyCurveLayoutElement::ReplyCurveLayoutElement(MessageElement &creator,
void ReplyCurveLayoutElement::paint(QPainter &painter)
{
QRectF paintRect(this->getRect());
QPainterPath bezierPath;
QPainterPath path;
qreal top = paintRect.top() + paintRect.height() * 0.25; // 25% from top
qreal left = paintRect.left() + this->neededMargin_;
qreal bottom = paintRect.bottom() - this->neededMargin_;
QPointF startPoint(left, bottom);
QPointF controlPoint(left, top);
QPointF endPoint(paintRect.right(), top);
QRectF curveRect = paintRect.marginsRemoved(QMarginsF(
this->neededMargin_, this->neededMargin_, 0, this->neededMargin_));
// Create curve path
bezierPath.moveTo(startPoint);
bezierPath.quadTo(controlPoint, endPoint);
// Make sure that our curveRect can always fit the radius curve
if (curveRect.height() < this->radius_)
{
curveRect.setTop(curveRect.top() -
(this->radius_ - curveRect.height()));
}
QPointF bStartPoint(curveRect.left(), curveRect.top() + this->radius_);
QPointF bEndPoint(curveRect.left() + this->radius_, curveRect.top());
QPointF bControlPoint(curveRect.topLeft());
// Draw line from bottom left to curve
path.moveTo(curveRect.bottomLeft());
path.lineTo(bStartPoint);
// Draw curve path
path.quadTo(bControlPoint, bEndPoint);
// Draw line from curve to top right
path.lineTo(curveRect.topRight());
// Render curve
painter.setPen(this->pen_);
painter.setRenderHint(QPainter::Antialiasing);
painter.drawPath(bezierPath);
painter.drawPath(path);
}
void ReplyCurveLayoutElement::paintAnimated(QPainter &painter, int yOffset)