mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 16:44:39 +03:00
Update font size if there is not enough space
This commit is contained in:
parent
2ce293f85d
commit
47ba3d0b4f
@ -677,23 +677,35 @@ void AbstractChart::prepareLegendToPaint(QRectF &legendRect, QPainter *painter)
|
|||||||
case ChartItem::LegendAlignBottomLeft:
|
case ChartItem::LegendAlignBottomLeft:
|
||||||
case ChartItem::LegendAlignBottomCenter:
|
case ChartItem::LegendAlignBottomCenter:
|
||||||
case ChartItem::LegendAlignBottomRight: {
|
case ChartItem::LegendAlignBottomRight: {
|
||||||
// TODO_ES handle resize horizontal legend (wrapping text)
|
const qreal maxWidth = legendRect.width() * 0.9;
|
||||||
|
qreal legendWidth = std::accumulate(m_legendColumnWidths.cbegin(), m_legendColumnWidths.cend(), 0.0);
|
||||||
|
if (legendWidth < maxWidth) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
while ( (legendWidth > maxWidth) && tmpFont.pixelSize() > 1) {
|
||||||
|
tmpFont.setPixelSize(tmpFont.pixelSize() - 1);
|
||||||
|
calcChartLegendSize(tmpFont, legendRect.width());
|
||||||
|
legendWidth = std::accumulate(m_legendColumnWidths.cbegin(), m_legendColumnWidths.cend(), 0.0);
|
||||||
|
}
|
||||||
|
painter->setFont(tmpFont);
|
||||||
|
legendRect = calcChartLegendRect(tmpFont, legendRect, true, 0, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ChartItem::LegendAlignRightTop:
|
case ChartItem::LegendAlignRightTop:
|
||||||
case ChartItem::LegendAlignRightCenter:
|
case ChartItem::LegendAlignRightCenter:
|
||||||
case ChartItem::LegendAlignRightBottom:
|
case ChartItem::LegendAlignRightBottom:
|
||||||
QSizeF legendSize = calcChartLegendSize(tmpFont, legendRect.width());
|
QSizeF legendSize = calcChartLegendSize(tmpFont, legendRect.width());
|
||||||
if ((legendSize.height() > legendRect.height() || legendSize.width() > legendRect.width())) {
|
if ((legendSize.height() <= legendRect.height() && legendSize.width() <= legendRect.width())) {
|
||||||
while ( (legendSize.height() > legendRect.height() || legendSize.width() > legendRect.width())
|
return;
|
||||||
&& tmpFont.pixelSize() > 1)
|
|
||||||
{
|
|
||||||
tmpFont.setPixelSize(tmpFont.pixelSize()-1);
|
|
||||||
legendSize = calcChartLegendSize(tmpFont, legendRect.width());
|
|
||||||
}
|
|
||||||
painter->setFont(tmpFont);
|
|
||||||
legendRect = calcChartLegendRect(tmpFont, legendRect, true, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
while ((legendSize.height() > legendRect.height() || legendSize.width() > legendRect.width())
|
||||||
|
&& tmpFont.pixelSize() > 1)
|
||||||
|
{
|
||||||
|
tmpFont.setPixelSize(tmpFont.pixelSize() - 1);
|
||||||
|
legendSize = calcChartLegendSize(tmpFont, legendRect.width());
|
||||||
|
}
|
||||||
|
painter->setFont(tmpFont);
|
||||||
|
legendRect = calcChartLegendRect(tmpFont, legendRect, true, 0, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1203,6 +1215,7 @@ QVector<qreal> AbstractChart::legendColumnWidths() const
|
|||||||
void AbstractBarChart::paintChartLegend(QPainter *painter, QRectF legendRect)
|
void AbstractBarChart::paintChartLegend(QPainter *painter, QRectF legendRect)
|
||||||
{
|
{
|
||||||
prepareLegendToPaint(legendRect, painter);
|
prepareLegendToPaint(legendRect, painter);
|
||||||
|
// TODO_ES after calculating bottom legend size, handle difference of sizes
|
||||||
painter->setPen(Qt::black);
|
painter->setPen(Qt::black);
|
||||||
painter->setRenderHint(QPainter::Antialiasing,false);
|
painter->setRenderHint(QPainter::Antialiasing,false);
|
||||||
if (m_chartItem->drawLegendBorder())
|
if (m_chartItem->drawLegendBorder())
|
||||||
|
Loading…
Reference in New Issue
Block a user