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