diff --git a/src/axis/cartesianchartaxis.cpp b/src/axis/cartesianchartaxis.cpp index db42f6f..522223d 100644 --- a/src/axis/cartesianchartaxis.cpp +++ b/src/axis/cartesianchartaxis.cpp @@ -28,6 +28,7 @@ #include #include #include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -62,6 +63,7 @@ void CartesianChartAxis::createItems(int count) QGraphicsLineItem *arrow = new QGraphicsLineItem(this); QGraphicsLineItem *grid = new QGraphicsLineItem(this); QGraphicsTextItem *label = new QGraphicsTextItem(this); + label->document()->setDocumentMargin(ChartPresenter::textMargin()); QGraphicsTextItem *title = titleItem(); arrow->setPen(axis()->linePen()); grid->setPen(axis()->gridLinePen()); diff --git a/src/axis/chartaxiselement.cpp b/src/axis/chartaxiselement.cpp index 95f343c..1fa133d 100644 --- a/src/axis/chartaxiselement.cpp +++ b/src/axis/chartaxiselement.cpp @@ -24,6 +24,7 @@ #include "abstractchartlayout_p.h" #include #include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -56,6 +57,7 @@ ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, boo m_shades->setZValue(ChartPresenter::ShadesZValue); m_grid->setZValue(ChartPresenter::GridZValue); m_title->setZValue(ChartPresenter::GridZValue); + m_title->document()->setDocumentMargin(ChartPresenter::textMargin()); handleVisibleChanged(axis->isVisible()); connectSlots(); diff --git a/src/axis/chartaxiselement_p.h b/src/axis/chartaxiselement_p.h index 1cc5222..c0f9a28 100644 --- a/src/axis/chartaxiselement_p.h +++ b/src/axis/chartaxiselement_p.h @@ -61,8 +61,8 @@ public: QAbstractAxis *axis() const { return m_axis; } void setLayout(QVector &layout) { m_layout = layout; } QVector &layout() { return m_layout; } // Modifiable reference - inline qreal labelPadding() const { return qreal(1.0); } - inline qreal titlePadding() const { return qreal(1.0); } + inline qreal labelPadding() const { return qreal(4.0); } + inline qreal titlePadding() const { return qreal(2.0); } void setLabels(const QStringList &labels) { m_labelsList = labels; } QStringList labels() const { return m_labelsList; } diff --git a/src/axis/polarchartaxisangular.cpp b/src/axis/polarchartaxisangular.cpp index d5ddb04..f82b3f2 100644 --- a/src/axis/polarchartaxisangular.cpp +++ b/src/axis/polarchartaxisangular.cpp @@ -25,6 +25,7 @@ #include "qabstractaxis_p.h" #include #include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -247,6 +248,7 @@ void PolarChartAxisAngular::createItems(int count) QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem()); QGraphicsLineItem *grid = new QGraphicsLineItem(presenter()->rootItem()); QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem()); + label->document()->setDocumentMargin(ChartPresenter::textMargin()); QGraphicsTextItem *title = titleItem(); arrow->setPen(axis()->linePen()); grid->setPen(axis()->gridLinePen()); diff --git a/src/axis/polarchartaxisradial.cpp b/src/axis/polarchartaxisradial.cpp index 7a42185..bfb2732 100644 --- a/src/axis/polarchartaxisradial.cpp +++ b/src/axis/polarchartaxisradial.cpp @@ -23,6 +23,7 @@ #include "abstractchartlayout_p.h" #include "qabstractaxis_p.h" #include "linearrowitem_p.h" +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -236,6 +237,7 @@ void PolarChartAxisRadial::createItems(int count) QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem()); QGraphicsEllipseItem *grid = new QGraphicsEllipseItem(presenter()->rootItem()); QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem()); + label->document()->setDocumentMargin(ChartPresenter::textMargin()); QGraphicsTextItem *title = titleItem(); arrow->setPen(axis()->linePen()); grid->setPen(axis()->gridLinePen()); diff --git a/src/axis/verticalaxis.cpp b/src/axis/verticalaxis.cpp index 0656e9a..e0d3451 100644 --- a/src/axis/verticalaxis.cpp +++ b/src/axis/verticalaxis.cpp @@ -77,7 +77,7 @@ void VerticalAxis::updateGeometry() QString truncatedTitle = ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), gridRect.height(), Qt::Horizontal, titleBoundingRect); qreal titleSpace = availableSpace - minimumLabelWidth; - if (titleSpace < titleBoundingRect.width()) { + if (titleSpace < titleBoundingRect.height()) { // Need to also truncate title vertically (multiline title) bool skip = false; if (truncatedTitle.endsWith("...")) { diff --git a/src/barchart/abstractbarchartitem.cpp b/src/barchart/abstractbarchartitem.cpp index 6ed9226..af3c6b1 100644 --- a/src/barchart/abstractbarchartitem.cpp +++ b/src/barchart/abstractbarchartitem.cpp @@ -30,6 +30,7 @@ #include "baranimation_p.h" #include "chartdataset_p.h" #include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -164,7 +165,9 @@ void AbstractBarChartItem::handleDataStructureChanged() // m_layout.append(QRectF(0, 0, 1, 1)); // Labels - m_labels.append(new QGraphicsTextItem(this)); + QGraphicsTextItem *newLabel = new QGraphicsTextItem(this); + newLabel->document()->setDocumentMargin(ChartPresenter::textMargin()); + m_labels.append(newLabel); } } diff --git a/src/chartpresenter.cpp b/src/chartpresenter.cpp index 70509cc..765a228 100644 --- a/src/chartpresenter.cpp +++ b/src/chartpresenter.cpp @@ -33,6 +33,7 @@ #include "polarchartlayout_p.h" #include "charttitle_p.h" #include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -387,6 +388,11 @@ ChartTitle *ChartPresenter::titleElement() QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle) { static QGraphicsTextItem dummyTextItem; + static bool initMargin = true; + if (initMargin) { + dummyTextItem.document()->setDocumentMargin(textMargin()); + initMargin = false; + } dummyTextItem.setFont(font); dummyTextItem.setHtml(text); diff --git a/src/chartpresenter_p.h b/src/chartpresenter_p.h index c1ced6b..93a616f 100644 --- a/src/chartpresenter_p.h +++ b/src/chartpresenter_p.h @@ -147,6 +147,7 @@ public: static QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0); static QString truncatedText(const QFont &font, const QString &text, qreal angle, qreal maxSize, Qt::Orientation constraintOrientation, QRectF &boundingRect); + inline static qreal textMargin() { return qreal(0.5); } private: void createBackgroundItem(); void createPlotAreaBackgroundItem(); diff --git a/src/charttitle.cpp b/src/charttitle.cpp index 41c50c4..d5306cf 100644 --- a/src/charttitle.cpp +++ b/src/charttitle.cpp @@ -23,13 +23,14 @@ #include #include #include +#include QTCOMMERCIALCHART_BEGIN_NAMESPACE ChartTitle::ChartTitle(QGraphicsItem *parent) : QGraphicsTextItem(parent) { - + document()->setDocumentMargin(ChartPresenter::textMargin()); } ChartTitle::~ChartTitle() diff --git a/src/legend/legendmarkeritem.cpp b/src/legend/legendmarkeritem.cpp index 727b663..fbd809f 100644 --- a/src/legend/legendmarkeritem.cpp +++ b/src/legend/legendmarkeritem.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "qlegend.h" #include "qlegend_p.h" @@ -38,12 +39,13 @@ LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject m_boundingRect(0,0,0,0), m_textItem(new QGraphicsTextItem(this)), m_rectItem(new QGraphicsRectItem(this)), - m_margin(1), - m_space(2), + m_margin(3), + m_space(4), m_hovering(false), m_pressPos(0, 0) { m_rectItem->setRect(m_markerRect); + m_textItem->document()->setDocumentMargin(ChartPresenter::textMargin()); setAcceptHoverEvents(true); } @@ -122,7 +124,8 @@ void LegendMarkerItem::setGeometry(const QRectF &rect) m_textItem->setPos(x - m_margin, y / 2 - textRect.height() / 2); m_rectItem->setRect(m_markerRect); - m_rectItem->setPos(m_margin, y / 2 - m_markerRect.height() / 2); + // The textMargin adjustments to position are done to make default case rects less blurry with anti-aliasing + m_rectItem->setPos(m_margin - ChartPresenter::textMargin(), y / 2.0 - m_markerRect.height() / 2.0 + ChartPresenter::textMargin()); prepareGeometryChange(); m_boundingRect = QRectF(0, 0, x + textRect.width() + m_margin, y);