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