##// END OF EJS Templates
Add padding for axis title...
Miikka Heikkinen -
r2413:f80448ee2136
parent child
Show More
@@ -44,7 +44,8 ChartAxis::ChartAxis(QAbstractAxis *axis, QGraphicsItem* item , bool intervalAxi
44 44 m_title(new QGraphicsSimpleTextItem(item)),
45 45 m_animation(0),
46 46 m_labelPadding(5),
47 m_intervalAxis(intervalAxis)
47 m_intervalAxis(intervalAxis),
48 m_titlePadding(3)
48 49 {
49 50 Q_ASSERT(item);
50 51 //initial initialization
@@ -197,6 +198,11 void ChartAxis::setLabelPadding(int padding)
197 198 m_labelPadding = padding;
198 199 }
199 200
201 void ChartAxis::setTitlePadding(int padding)
202 {
203 m_titlePadding = padding;
204 }
205
200 206 bool ChartAxis::isEmpty()
201 207 {
202 208 return m_axisRect.isEmpty() || m_gridRect.isEmpty() || qFuzzyCompare(min(),max());
@@ -56,6 +56,9 public:
56 56 void setLabelPadding(int padding);
57 57 int labelPadding() const { return m_labelPadding;};
58 58
59 void setTitlePadding(int padding);
60 int titlePadding() const { return m_titlePadding;};
61
59 62 QFont titleFont() const;
60 63 QString titleText() const;
61 64
@@ -159,6 +162,7 private:
159 162 int m_labelPadding;
160 163 QStringList m_labelsList;
161 164 bool m_intervalAxis;
165 int m_titlePadding;
162 166
163 167 friend class AxisAnimation;
164 168 friend class ArrowItem;
@@ -88,9 +88,9 void HorizontalAxis::updateGeometry()
88 88
89 89 QPointF center = gridRect.center() - title->boundingRect().center();
90 90 if (alignment() == Qt::AlignTop) {
91 title->setPos(center.x(), axisRect.top());
91 title->setPos(center.x(), axisRect.top() + titlePadding());
92 92 } else if (alignment() == Qt::AlignBottom) {
93 title->setPos(center.x(), axisRect.bottom() - title->boundingRect().height());
93 title->setPos(center.x(), axisRect.bottom() - title->boundingRect().height() - titlePadding());
94 94 }
95 95 }
96 96
@@ -107,7 +107,7 void HorizontalAxis::updateGeometry()
107 107 //label text wrapping
108 108 QString text = labelList.at(i);
109 109 QRectF boundingRect = labelBoundingRect(fn, text);
110 qreal size = axisRect.bottom() - axisRect.top() - labelPadding() - title->boundingRect().height();
110 qreal size = axisRect.bottom() - axisRect.top() - labelPadding() - title->boundingRect().height() - (titlePadding() * 2);
111 111 if (boundingRect.height() > size) {
112 112 QString label = text + "...";
113 113 while (boundingRect.height() >= size && label.length() > 3) {
@@ -191,11 +191,11 QSizeF HorizontalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) co
191 191
192 192 switch (which) {
193 193 case Qt::MinimumSize:
194 sh = QSizeF(fn.boundingRect("...").width(), fn.height());
194 sh = QSizeF(fn.boundingRect("...").width(), fn.height() + (titlePadding() * 2));
195 195 break;
196 196 case Qt::MaximumSize:
197 197 case Qt::PreferredSize:
198 sh = QSizeF(fn.boundingRect(axis()->titleText()).width(), fn.height());
198 sh = QSizeF(fn.boundingRect(axis()->titleText()).width(), fn.height() + (titlePadding() * 2));
199 199 break;
200 200 default:
201 201 break;
@@ -92,10 +92,10 void VerticalAxis::updateGeometry()
92 92
93 93 QPointF center = gridRect.center() - title->boundingRect().center();
94 94 if (alignment() == Qt::AlignLeft) {
95 title->setPos(axisRect.left() - title->boundingRect().width()/2 + title->boundingRect().height()/2 , center.y());
95 title->setPos(axisRect.left() - title->boundingRect().width() / 2 + title->boundingRect().height() / 2 + titlePadding(), center.y());
96 96 }
97 97 else if (alignment() == Qt::AlignRight) {
98 title->setPos(axisRect.right()- title->boundingRect().width()/2 - title->boundingRect().height()/2, center.y());
98 title->setPos(axisRect.right() - title->boundingRect().width() / 2 - title->boundingRect().height() / 2 - titlePadding(), center.y());
99 99 }
100 100 title->setTransformOriginPoint(title->boundingRect().center());
101 101 title->setRotation(270);
@@ -115,7 +115,7 void VerticalAxis::updateGeometry()
115 115 QString text = labelList.at(i);
116 116 QRectF boundingRect = labelBoundingRect(fn, text);
117 117
118 qreal size = axisRect.right() - axisRect.left() - labelPadding() - title->boundingRect().height();
118 qreal size = axisRect.right() - axisRect.left() - labelPadding() - title->boundingRect().height() - (titlePadding() * 2);
119 119 if (boundingRect.width() > size) {
120 120 QString label = text + "...";
121 121 while (boundingRect.width() > size && label.length() > 3) {
@@ -202,11 +202,11 QSizeF VerticalAxis::sizeHint(Qt::SizeHint which, const QSizeF &constraint) cons
202 202
203 203 switch (which) {
204 204 case Qt::MinimumSize:
205 sh = QSizeF(fn.height(), fn.boundingRect("...").width());
205 sh = QSizeF(fn.height() + (titlePadding() * 2), fn.boundingRect("...").width());
206 206 break;
207 207 case Qt::MaximumSize:
208 208 case Qt::PreferredSize:
209 sh = QSizeF(fn.height(), fn.boundingRect(axis()->titleText()).width());
209 sh = QSizeF(fn.height() + (titlePadding() * 2), fn.boundingRect(axis()->titleText()).width());
210 210 break;
211 211 default:
212 212 break;
General Comments 0
You need to be logged in to leave comments. Login now