@@ -28,6 +28,7 | |||||
28 | #include <QValueAxis> |
|
28 | #include <QValueAxis> | |
29 | #include <QLogValueAxis> |
|
29 | #include <QLogValueAxis> | |
30 | #include <QGraphicsLayout> |
|
30 | #include <QGraphicsLayout> | |
|
31 | #include <QTextDocument> | |||
31 |
|
32 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
34 | |||
@@ -62,6 +63,7 void CartesianChartAxis::createItems(int count) | |||||
62 | QGraphicsLineItem *arrow = new QGraphicsLineItem(this); |
|
63 | QGraphicsLineItem *arrow = new QGraphicsLineItem(this); | |
63 | QGraphicsLineItem *grid = new QGraphicsLineItem(this); |
|
64 | QGraphicsLineItem *grid = new QGraphicsLineItem(this); | |
64 | QGraphicsTextItem *label = new QGraphicsTextItem(this); |
|
65 | QGraphicsTextItem *label = new QGraphicsTextItem(this); | |
|
66 | label->document()->setDocumentMargin(ChartPresenter::textMargin()); | |||
65 | QGraphicsTextItem *title = titleItem(); |
|
67 | QGraphicsTextItem *title = titleItem(); | |
66 | arrow->setPen(axis()->linePen()); |
|
68 | arrow->setPen(axis()->linePen()); | |
67 | grid->setPen(axis()->gridLinePen()); |
|
69 | grid->setPen(axis()->gridLinePen()); |
@@ -24,6 +24,7 | |||||
24 | #include "abstractchartlayout_p.h" |
|
24 | #include "abstractchartlayout_p.h" | |
25 | #include <qmath.h> |
|
25 | #include <qmath.h> | |
26 | #include <QDateTime> |
|
26 | #include <QDateTime> | |
|
27 | #include <QTextDocument> | |||
27 |
|
28 | |||
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
29 |
|
30 | |||
@@ -56,6 +57,7 ChartAxisElement::ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, boo | |||||
56 | m_shades->setZValue(ChartPresenter::ShadesZValue); |
|
57 | m_shades->setZValue(ChartPresenter::ShadesZValue); | |
57 | m_grid->setZValue(ChartPresenter::GridZValue); |
|
58 | m_grid->setZValue(ChartPresenter::GridZValue); | |
58 | m_title->setZValue(ChartPresenter::GridZValue); |
|
59 | m_title->setZValue(ChartPresenter::GridZValue); | |
|
60 | m_title->document()->setDocumentMargin(ChartPresenter::textMargin()); | |||
59 | handleVisibleChanged(axis->isVisible()); |
|
61 | handleVisibleChanged(axis->isVisible()); | |
60 | connectSlots(); |
|
62 | connectSlots(); | |
61 |
|
63 |
@@ -61,8 +61,8 public: | |||||
61 | QAbstractAxis *axis() const { return m_axis; } |
|
61 | QAbstractAxis *axis() const { return m_axis; } | |
62 | void setLayout(QVector<qreal> &layout) { m_layout = layout; } |
|
62 | void setLayout(QVector<qreal> &layout) { m_layout = layout; } | |
63 | QVector<qreal> &layout() { return m_layout; } // Modifiable reference |
|
63 | QVector<qreal> &layout() { return m_layout; } // Modifiable reference | |
64 |
inline qreal labelPadding() const { return qreal( |
|
64 | inline qreal labelPadding() const { return qreal(4.0); } | |
65 |
inline qreal titlePadding() const { return qreal( |
|
65 | inline qreal titlePadding() const { return qreal(2.0); } | |
66 | void setLabels(const QStringList &labels) { m_labelsList = labels; } |
|
66 | void setLabels(const QStringList &labels) { m_labelsList = labels; } | |
67 | QStringList labels() const { return m_labelsList; } |
|
67 | QStringList labels() const { return m_labelsList; } | |
68 |
|
68 |
@@ -25,6 +25,7 | |||||
25 | #include "qabstractaxis_p.h" |
|
25 | #include "qabstractaxis_p.h" | |
26 | #include <QDebug> |
|
26 | #include <QDebug> | |
27 | #include <qmath.h> |
|
27 | #include <qmath.h> | |
|
28 | #include <QTextDocument> | |||
28 |
|
29 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
31 | |||
@@ -247,6 +248,7 void PolarChartAxisAngular::createItems(int count) | |||||
247 | QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem()); |
|
248 | QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem()); | |
248 | QGraphicsLineItem *grid = new QGraphicsLineItem(presenter()->rootItem()); |
|
249 | QGraphicsLineItem *grid = new QGraphicsLineItem(presenter()->rootItem()); | |
249 | QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem()); |
|
250 | QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem()); | |
|
251 | label->document()->setDocumentMargin(ChartPresenter::textMargin()); | |||
250 | QGraphicsTextItem *title = titleItem(); |
|
252 | QGraphicsTextItem *title = titleItem(); | |
251 | arrow->setPen(axis()->linePen()); |
|
253 | arrow->setPen(axis()->linePen()); | |
252 | grid->setPen(axis()->gridLinePen()); |
|
254 | grid->setPen(axis()->gridLinePen()); |
@@ -23,6 +23,7 | |||||
23 | #include "abstractchartlayout_p.h" |
|
23 | #include "abstractchartlayout_p.h" | |
24 | #include "qabstractaxis_p.h" |
|
24 | #include "qabstractaxis_p.h" | |
25 | #include "linearrowitem_p.h" |
|
25 | #include "linearrowitem_p.h" | |
|
26 | #include <QTextDocument> | |||
26 |
|
27 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
29 | |||
@@ -236,6 +237,7 void PolarChartAxisRadial::createItems(int count) | |||||
236 | QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem()); |
|
237 | QGraphicsLineItem *arrow = new QGraphicsLineItem(presenter()->rootItem()); | |
237 | QGraphicsEllipseItem *grid = new QGraphicsEllipseItem(presenter()->rootItem()); |
|
238 | QGraphicsEllipseItem *grid = new QGraphicsEllipseItem(presenter()->rootItem()); | |
238 | QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem()); |
|
239 | QGraphicsTextItem *label = new QGraphicsTextItem(presenter()->rootItem()); | |
|
240 | label->document()->setDocumentMargin(ChartPresenter::textMargin()); | |||
239 | QGraphicsTextItem *title = titleItem(); |
|
241 | QGraphicsTextItem *title = titleItem(); | |
240 | arrow->setPen(axis()->linePen()); |
|
242 | arrow->setPen(axis()->linePen()); | |
241 | grid->setPen(axis()->gridLinePen()); |
|
243 | grid->setPen(axis()->gridLinePen()); |
@@ -77,7 +77,7 void VerticalAxis::updateGeometry() | |||||
77 | QString truncatedTitle = ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), |
|
77 | QString truncatedTitle = ChartPresenter::truncatedText(axis()->titleFont(), titleText, qreal(0.0), | |
78 | gridRect.height(), Qt::Horizontal, titleBoundingRect); |
|
78 | gridRect.height(), Qt::Horizontal, titleBoundingRect); | |
79 | qreal titleSpace = availableSpace - minimumLabelWidth; |
|
79 | qreal titleSpace = availableSpace - minimumLabelWidth; | |
80 |
if (titleSpace < titleBoundingRect. |
|
80 | if (titleSpace < titleBoundingRect.height()) { | |
81 | // Need to also truncate title vertically (multiline title) |
|
81 | // Need to also truncate title vertically (multiline title) | |
82 | bool skip = false; |
|
82 | bool skip = false; | |
83 | if (truncatedTitle.endsWith("...")) { |
|
83 | if (truncatedTitle.endsWith("...")) { |
@@ -30,6 +30,7 | |||||
30 | #include "baranimation_p.h" |
|
30 | #include "baranimation_p.h" | |
31 | #include "chartdataset_p.h" |
|
31 | #include "chartdataset_p.h" | |
32 | #include <QPainter> |
|
32 | #include <QPainter> | |
|
33 | #include <QTextDocument> | |||
33 |
|
34 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
36 | |||
@@ -164,7 +165,9 void AbstractBarChartItem::handleDataStructureChanged() | |||||
164 | // m_layout.append(QRectF(0, 0, 1, 1)); |
|
165 | // m_layout.append(QRectF(0, 0, 1, 1)); | |
165 |
|
166 | |||
166 | // Labels |
|
167 | // Labels | |
167 |
|
|
168 | QGraphicsTextItem *newLabel = new QGraphicsTextItem(this); | |
|
169 | newLabel->document()->setDocumentMargin(ChartPresenter::textMargin()); | |||
|
170 | m_labels.append(newLabel); | |||
168 | } |
|
171 | } | |
169 | } |
|
172 | } | |
170 |
|
173 |
@@ -33,6 +33,7 | |||||
33 | #include "polarchartlayout_p.h" |
|
33 | #include "polarchartlayout_p.h" | |
34 | #include "charttitle_p.h" |
|
34 | #include "charttitle_p.h" | |
35 | #include <QTimer> |
|
35 | #include <QTimer> | |
|
36 | #include <QTextDocument> | |||
36 |
|
37 | |||
37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
38 |
|
39 | |||
@@ -387,6 +388,11 ChartTitle *ChartPresenter::titleElement() | |||||
387 | QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle) |
|
388 | QRectF ChartPresenter::textBoundingRect(const QFont &font, const QString &text, qreal angle) | |
388 | { |
|
389 | { | |
389 | static QGraphicsTextItem dummyTextItem; |
|
390 | static QGraphicsTextItem dummyTextItem; | |
|
391 | static bool initMargin = true; | |||
|
392 | if (initMargin) { | |||
|
393 | dummyTextItem.document()->setDocumentMargin(textMargin()); | |||
|
394 | initMargin = false; | |||
|
395 | } | |||
390 |
|
396 | |||
391 | dummyTextItem.setFont(font); |
|
397 | dummyTextItem.setFont(font); | |
392 | dummyTextItem.setHtml(text); |
|
398 | dummyTextItem.setHtml(text); |
@@ -147,6 +147,7 public: | |||||
147 | static QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0); |
|
147 | static QRectF textBoundingRect(const QFont &font, const QString &text, qreal angle = 0.0); | |
148 | static QString truncatedText(const QFont &font, const QString &text, qreal angle, qreal maxSize, |
|
148 | static QString truncatedText(const QFont &font, const QString &text, qreal angle, qreal maxSize, | |
149 | Qt::Orientation constraintOrientation, QRectF &boundingRect); |
|
149 | Qt::Orientation constraintOrientation, QRectF &boundingRect); | |
|
150 | inline static qreal textMargin() { return qreal(0.5); } | |||
150 | private: |
|
151 | private: | |
151 | void createBackgroundItem(); |
|
152 | void createBackgroundItem(); | |
152 | void createPlotAreaBackgroundItem(); |
|
153 | void createPlotAreaBackgroundItem(); |
@@ -23,13 +23,14 | |||||
23 | #include <QFont> |
|
23 | #include <QFont> | |
24 | #include <QFontMetrics> |
|
24 | #include <QFontMetrics> | |
25 | #include <QDebug> |
|
25 | #include <QDebug> | |
|
26 | #include <QTextDocument> | |||
26 |
|
27 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
29 | |||
29 | ChartTitle::ChartTitle(QGraphicsItem *parent) |
|
30 | ChartTitle::ChartTitle(QGraphicsItem *parent) | |
30 | : QGraphicsTextItem(parent) |
|
31 | : QGraphicsTextItem(parent) | |
31 | { |
|
32 | { | |
32 |
|
33 | document()->setDocumentMargin(ChartPresenter::textMargin()); | ||
33 | } |
|
34 | } | |
34 |
|
35 | |||
35 | ChartTitle::~ChartTitle() |
|
36 | ChartTitle::~ChartTitle() |
@@ -21,6 +21,7 | |||||
21 | #include <QPainter> |
|
21 | #include <QPainter> | |
22 | #include <QGraphicsSceneEvent> |
|
22 | #include <QGraphicsSceneEvent> | |
23 | #include <QGraphicsTextItem> |
|
23 | #include <QGraphicsTextItem> | |
|
24 | #include <QTextDocument> | |||
24 |
|
25 | |||
25 | #include "qlegend.h" |
|
26 | #include "qlegend.h" | |
26 | #include "qlegend_p.h" |
|
27 | #include "qlegend_p.h" | |
@@ -38,12 +39,13 LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject | |||||
38 | m_boundingRect(0,0,0,0), |
|
39 | m_boundingRect(0,0,0,0), | |
39 | m_textItem(new QGraphicsTextItem(this)), |
|
40 | m_textItem(new QGraphicsTextItem(this)), | |
40 | m_rectItem(new QGraphicsRectItem(this)), |
|
41 | m_rectItem(new QGraphicsRectItem(this)), | |
41 |
m_margin( |
|
42 | m_margin(3), | |
42 |
m_space( |
|
43 | m_space(4), | |
43 | m_hovering(false), |
|
44 | m_hovering(false), | |
44 | m_pressPos(0, 0) |
|
45 | m_pressPos(0, 0) | |
45 | { |
|
46 | { | |
46 | m_rectItem->setRect(m_markerRect); |
|
47 | m_rectItem->setRect(m_markerRect); | |
|
48 | m_textItem->document()->setDocumentMargin(ChartPresenter::textMargin()); | |||
47 | setAcceptHoverEvents(true); |
|
49 | setAcceptHoverEvents(true); | |
48 | } |
|
50 | } | |
49 |
|
51 | |||
@@ -122,7 +124,8 void LegendMarkerItem::setGeometry(const QRectF &rect) | |||||
122 |
|
124 | |||
123 | m_textItem->setPos(x - m_margin, y / 2 - textRect.height() / 2); |
|
125 | m_textItem->setPos(x - m_margin, y / 2 - textRect.height() / 2); | |
124 | m_rectItem->setRect(m_markerRect); |
|
126 | m_rectItem->setRect(m_markerRect); | |
125 | m_rectItem->setPos(m_margin, y / 2 - m_markerRect.height() / 2); |
|
127 | // The textMargin adjustments to position are done to make default case rects less blurry with anti-aliasing | |
|
128 | m_rectItem->setPos(m_margin - ChartPresenter::textMargin(), y / 2.0 - m_markerRect.height() / 2.0 + ChartPresenter::textMargin()); | |||
126 |
|
129 | |||
127 | prepareGeometryChange(); |
|
130 | prepareGeometryChange(); | |
128 | m_boundingRect = QRectF(0, 0, x + textRect.width() + m_margin, y); |
|
131 | m_boundingRect = QRectF(0, 0, x + textRect.width() + m_margin, y); |
General Comments 0
You need to be logged in to leave comments.
Login now