@@ -1,149 +1,149 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | // W A R N I N G |
|
21 | // W A R N I N G | |
22 | // ------------- |
|
22 | // ------------- | |
23 | // |
|
23 | // | |
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
24 | // This file is not part of the QtCommercial Chart API. It exists purely as an | |
25 | // implementation detail. This header file may change from version to |
|
25 | // implementation detail. This header file may change from version to | |
26 | // version without notice, or even be removed. |
|
26 | // version without notice, or even be removed. | |
27 | // |
|
27 | // | |
28 | // We mean it. |
|
28 | // We mean it. | |
29 |
|
29 | |||
30 | #ifndef CHARTAXISELEMENT_H |
|
30 | #ifndef CHARTAXISELEMENT_H | |
31 | #define CHARTAXISELEMENT_H |
|
31 | #define CHARTAXISELEMENT_H | |
32 |
|
32 | |||
33 | #include "qchartglobal.h" |
|
33 | #include "qchartglobal.h" | |
34 | #include "chartelement_p.h" |
|
34 | #include "chartelement_p.h" | |
35 | #include "axisanimation_p.h" |
|
35 | #include "axisanimation_p.h" | |
36 | #include <QGraphicsItem> |
|
36 | #include <QGraphicsItem> | |
37 | #include <QGraphicsLayoutItem> |
|
37 | #include <QGraphicsLayoutItem> | |
38 | #include <QFont> |
|
38 | #include <QFont> | |
39 |
|
39 | |||
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
40 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
41 |
|
41 | |||
42 | class ChartPresenter; |
|
42 | class ChartPresenter; | |
43 | class QAbstractAxis; |
|
43 | class QAbstractAxis; | |
44 |
|
44 | |||
45 | class ChartAxisElement : public ChartElement, public QGraphicsLayoutItem |
|
45 | class ChartAxisElement : public ChartElement, public QGraphicsLayoutItem | |
46 | { |
|
46 | { | |
47 | Q_OBJECT |
|
47 | Q_OBJECT | |
48 | public: |
|
48 | public: | |
49 | ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis = false); |
|
49 | ChartAxisElement(QAbstractAxis *axis, QGraphicsItem *item, bool intervalAxis = false); | |
50 | ~ChartAxisElement(); |
|
50 | ~ChartAxisElement(); | |
51 |
|
51 | |||
52 | virtual QRectF gridGeometry() const = 0; |
|
52 | virtual QRectF gridGeometry() const = 0; | |
53 | virtual void setGeometry(const QRectF &axis, const QRectF &grid) = 0; |
|
53 | virtual void setGeometry(const QRectF &axis, const QRectF &grid) = 0; | |
54 | virtual bool isEmpty() = 0; |
|
54 | virtual bool isEmpty() = 0; | |
55 |
|
55 | |||
56 | void setAnimation(AxisAnimation *animation) { m_animation = animation; } |
|
56 | void setAnimation(AxisAnimation *animation) { m_animation = animation; } | |
57 | AxisAnimation *animation() const { return m_animation; } |
|
57 | AxisAnimation *animation() const { return m_animation; } | |
58 |
|
58 | |||
59 | QAbstractAxis *axis() const { return m_axis; } |
|
59 | QAbstractAxis *axis() const { return m_axis; } | |
60 | void setLayout(QVector<qreal> &layout) { m_layout = layout; } |
|
60 | void setLayout(QVector<qreal> &layout) { m_layout = layout; } | |
61 | QVector<qreal> &layout() { return m_layout; } // Modifiable reference |
|
61 | QVector<qreal> &layout() { return m_layout; } // Modifiable reference | |
62 |
inline qreal labelPadding() const { return qreal( |
|
62 | inline qreal labelPadding() const { return qreal(1.0); } | |
63 |
inline qreal titlePadding() const { return qreal( |
|
63 | inline qreal titlePadding() const { return qreal(1.0); } | |
64 | void setLabels(const QStringList &labels) { m_labelsList = labels; } |
|
64 | void setLabels(const QStringList &labels) { m_labelsList = labels; } | |
65 | QStringList labels() const { return m_labelsList; } |
|
65 | QStringList labels() const { return m_labelsList; } | |
66 |
|
66 | |||
67 | qreal min() const; |
|
67 | qreal min() const; | |
68 | qreal max() const; |
|
68 | qreal max() const; | |
69 |
|
69 | |||
70 | QRectF axisGeometry() const { return m_axisRect; } |
|
70 | QRectF axisGeometry() const { return m_axisRect; } | |
71 | void setAxisGeometry(const QRectF &axisGeometry) { m_axisRect = axisGeometry; } |
|
71 | void setAxisGeometry(const QRectF &axisGeometry) { m_axisRect = axisGeometry; } | |
72 |
|
72 | |||
73 | void axisSelected(); |
|
73 | void axisSelected(); | |
74 |
|
74 | |||
75 | //this flag indicates that axis is used to show intervals it means labels are in between ticks |
|
75 | //this flag indicates that axis is used to show intervals it means labels are in between ticks | |
76 | bool intervalAxis() const { return m_intervalAxis; } |
|
76 | bool intervalAxis() const { return m_intervalAxis; } | |
77 |
|
77 | |||
78 | static QStringList createValueLabels(qreal max, qreal min, int ticks, const QString &format); |
|
78 | static QStringList createValueLabels(qreal max, qreal min, int ticks, const QString &format); | |
79 | static QStringList createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString &format); |
|
79 | static QStringList createLogValueLabels(qreal min, qreal max, qreal base, int ticks, const QString &format); | |
80 | static QStringList createDateTimeLabels(qreal max, qreal min, int ticks, const QString &format); |
|
80 | static QStringList createDateTimeLabels(qreal max, qreal min, int ticks, const QString &format); | |
81 |
|
81 | |||
82 | // from QGraphicsLayoutItem |
|
82 | // from QGraphicsLayoutItem | |
83 | QRectF boundingRect() const |
|
83 | QRectF boundingRect() const | |
84 | { |
|
84 | { | |
85 | return QRectF(); |
|
85 | return QRectF(); | |
86 | } |
|
86 | } | |
87 |
|
87 | |||
88 | // from QGraphicsLayoutItem |
|
88 | // from QGraphicsLayoutItem | |
89 | void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) |
|
89 | void paint(QPainter*, const QStyleOptionGraphicsItem*, QWidget*) | |
90 | { |
|
90 | { | |
91 | } |
|
91 | } | |
92 |
|
92 | |||
93 | protected: |
|
93 | protected: | |
94 | virtual QVector<qreal> calculateLayout() const = 0; |
|
94 | virtual QVector<qreal> calculateLayout() const = 0; | |
95 | virtual void updateLayout(QVector<qreal> &layout) = 0; |
|
95 | virtual void updateLayout(QVector<qreal> &layout) = 0; | |
96 |
|
96 | |||
97 | QList<QGraphicsItem *> gridItems() { return m_grid->childItems(); } |
|
97 | QList<QGraphicsItem *> gridItems() { return m_grid->childItems(); } | |
98 | QList<QGraphicsItem *> labelItems() { return m_labels->childItems(); } |
|
98 | QList<QGraphicsItem *> labelItems() { return m_labels->childItems(); } | |
99 | QList<QGraphicsItem *> shadeItems() { return m_shades->childItems(); } |
|
99 | QList<QGraphicsItem *> shadeItems() { return m_shades->childItems(); } | |
100 | QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems(); } |
|
100 | QList<QGraphicsItem *> arrowItems() { return m_arrow->childItems(); } | |
101 | QGraphicsTextItem *titleItem() const { return m_title.data(); } |
|
101 | QGraphicsTextItem *titleItem() const { return m_title.data(); } | |
102 | QGraphicsItemGroup *gridGroup() { return m_grid.data(); } |
|
102 | QGraphicsItemGroup *gridGroup() { return m_grid.data(); } | |
103 | QGraphicsItemGroup *labelGroup() { return m_labels.data(); } |
|
103 | QGraphicsItemGroup *labelGroup() { return m_labels.data(); } | |
104 | QGraphicsItemGroup *shadeGroup() { return m_shades.data(); } |
|
104 | QGraphicsItemGroup *shadeGroup() { return m_shades.data(); } | |
105 | QGraphicsItemGroup *arrowGroup() { return m_arrow.data(); } |
|
105 | QGraphicsItemGroup *arrowGroup() { return m_arrow.data(); } | |
106 |
|
106 | |||
107 | public Q_SLOTS: |
|
107 | public Q_SLOTS: | |
108 | void handleVisibleChanged(bool visible); |
|
108 | void handleVisibleChanged(bool visible); | |
109 | void handleArrowVisibleChanged(bool visible); |
|
109 | void handleArrowVisibleChanged(bool visible); | |
110 | void handleGridVisibleChanged(bool visible); |
|
110 | void handleGridVisibleChanged(bool visible); | |
111 | void handleLabelsVisibleChanged(bool visible); |
|
111 | void handleLabelsVisibleChanged(bool visible); | |
112 | void handleShadesVisibleChanged(bool visible); |
|
112 | void handleShadesVisibleChanged(bool visible); | |
113 | void handleLabelsAngleChanged(int angle); |
|
113 | void handleLabelsAngleChanged(int angle); | |
114 | virtual void handleShadesBrushChanged(const QBrush &brush) = 0; |
|
114 | virtual void handleShadesBrushChanged(const QBrush &brush) = 0; | |
115 | virtual void handleShadesPenChanged(const QPen &pen) = 0; |
|
115 | virtual void handleShadesPenChanged(const QPen &pen) = 0; | |
116 | virtual void handleArrowPenChanged(const QPen &pen) = 0; |
|
116 | virtual void handleArrowPenChanged(const QPen &pen) = 0; | |
117 | virtual void handleGridPenChanged(const QPen &pen) = 0; |
|
117 | virtual void handleGridPenChanged(const QPen &pen) = 0; | |
118 | void handleLabelsPenChanged(const QPen &pen); |
|
118 | void handleLabelsPenChanged(const QPen &pen); | |
119 | void handleLabelsBrushChanged(const QBrush &brush); |
|
119 | void handleLabelsBrushChanged(const QBrush &brush); | |
120 | void handleLabelsFontChanged(const QFont &font); |
|
120 | void handleLabelsFontChanged(const QFont &font); | |
121 | void handleTitlePenChanged(const QPen &pen); |
|
121 | void handleTitlePenChanged(const QPen &pen); | |
122 | void handleTitleBrushChanged(const QBrush &brush); |
|
122 | void handleTitleBrushChanged(const QBrush &brush); | |
123 | void handleTitleFontChanged(const QFont &font); |
|
123 | void handleTitleFontChanged(const QFont &font); | |
124 | void handleTitleTextChanged(const QString &title); |
|
124 | void handleTitleTextChanged(const QString &title); | |
125 | void handleTitleVisibleChanged(bool visible); |
|
125 | void handleTitleVisibleChanged(bool visible); | |
126 | void handleRangeChanged(qreal min, qreal max); |
|
126 | void handleRangeChanged(qreal min, qreal max); | |
127 |
|
127 | |||
128 | Q_SIGNALS: |
|
128 | Q_SIGNALS: | |
129 | void clicked(); |
|
129 | void clicked(); | |
130 |
|
130 | |||
131 | private: |
|
131 | private: | |
132 | void connectSlots(); |
|
132 | void connectSlots(); | |
133 |
|
133 | |||
134 | QAbstractAxis *m_axis; |
|
134 | QAbstractAxis *m_axis; | |
135 | AxisAnimation *m_animation; |
|
135 | AxisAnimation *m_animation; | |
136 | QVector<qreal> m_layout; |
|
136 | QVector<qreal> m_layout; | |
137 | QStringList m_labelsList; |
|
137 | QStringList m_labelsList; | |
138 | QRectF m_axisRect; |
|
138 | QRectF m_axisRect; | |
139 | QScopedPointer<QGraphicsItemGroup> m_grid; |
|
139 | QScopedPointer<QGraphicsItemGroup> m_grid; | |
140 | QScopedPointer<QGraphicsItemGroup> m_arrow; |
|
140 | QScopedPointer<QGraphicsItemGroup> m_arrow; | |
141 | QScopedPointer<QGraphicsItemGroup> m_shades; |
|
141 | QScopedPointer<QGraphicsItemGroup> m_shades; | |
142 | QScopedPointer<QGraphicsItemGroup> m_labels; |
|
142 | QScopedPointer<QGraphicsItemGroup> m_labels; | |
143 | QScopedPointer<QGraphicsTextItem> m_title; |
|
143 | QScopedPointer<QGraphicsTextItem> m_title; | |
144 | bool m_intervalAxis; |
|
144 | bool m_intervalAxis; | |
145 | }; |
|
145 | }; | |
146 |
|
146 | |||
147 | QTCOMMERCIALCHART_END_NAMESPACE |
|
147 | QTCOMMERCIALCHART_END_NAMESPACE | |
148 |
|
148 | |||
149 | #endif /* CHARTAXISELEMENT_H */ |
|
149 | #endif /* CHARTAXISELEMENT_H */ |
@@ -1,186 +1,186 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QPainter> |
|
21 | #include <QPainter> | |
22 | #include <QGraphicsSceneEvent> |
|
22 | #include <QGraphicsSceneEvent> | |
23 | #include <QGraphicsTextItem> |
|
23 | #include <QGraphicsTextItem> | |
24 |
|
24 | |||
25 | #include "qlegend.h" |
|
25 | #include "qlegend.h" | |
26 | #include "qlegend_p.h" |
|
26 | #include "qlegend_p.h" | |
27 | #include "qlegendmarker.h" |
|
27 | #include "qlegendmarker.h" | |
28 | #include "qlegendmarker_p.h" |
|
28 | #include "qlegendmarker_p.h" | |
29 | #include "legendmarkeritem_p.h" |
|
29 | #include "legendmarkeritem_p.h" | |
30 | #include "chartpresenter_p.h" |
|
30 | #include "chartpresenter_p.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) : |
|
34 | LegendMarkerItem::LegendMarkerItem(QLegendMarkerPrivate *marker, QGraphicsObject *parent) : | |
35 | QGraphicsObject(parent), |
|
35 | QGraphicsObject(parent), | |
36 | m_marker(marker), |
|
36 | m_marker(marker), | |
37 | m_markerRect(0,0,10.0,10.0), |
|
37 | m_markerRect(0,0,10.0,10.0), | |
38 | m_boundingRect(0,0,0,0), |
|
38 | m_boundingRect(0,0,0,0), | |
39 | m_textItem(new QGraphicsTextItem(this)), |
|
39 | m_textItem(new QGraphicsTextItem(this)), | |
40 | m_rectItem(new QGraphicsRectItem(this)), |
|
40 | m_rectItem(new QGraphicsRectItem(this)), | |
41 |
m_margin( |
|
41 | m_margin(1), | |
42 |
m_space( |
|
42 | m_space(2), | |
43 | m_hovering(false), |
|
43 | m_hovering(false), | |
44 | m_pressPos(0, 0) |
|
44 | m_pressPos(0, 0) | |
45 | { |
|
45 | { | |
46 | m_rectItem->setRect(m_markerRect); |
|
46 | m_rectItem->setRect(m_markerRect); | |
47 | setAcceptHoverEvents(true); |
|
47 | setAcceptHoverEvents(true); | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | LegendMarkerItem::~LegendMarkerItem() |
|
50 | LegendMarkerItem::~LegendMarkerItem() | |
51 | { |
|
51 | { | |
52 | if (m_hovering) { |
|
52 | if (m_hovering) { | |
53 | emit m_marker->q_ptr->hovered(false); |
|
53 | emit m_marker->q_ptr->hovered(false); | |
54 | } |
|
54 | } | |
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | void LegendMarkerItem::setPen(const QPen &pen) |
|
57 | void LegendMarkerItem::setPen(const QPen &pen) | |
58 | { |
|
58 | { | |
59 | m_rectItem->setPen(pen); |
|
59 | m_rectItem->setPen(pen); | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | QPen LegendMarkerItem::pen() const |
|
62 | QPen LegendMarkerItem::pen() const | |
63 | { |
|
63 | { | |
64 | return m_rectItem->pen(); |
|
64 | return m_rectItem->pen(); | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | void LegendMarkerItem::setBrush(const QBrush &brush) |
|
67 | void LegendMarkerItem::setBrush(const QBrush &brush) | |
68 | { |
|
68 | { | |
69 | m_rectItem->setBrush(brush); |
|
69 | m_rectItem->setBrush(brush); | |
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | QBrush LegendMarkerItem::brush() const |
|
72 | QBrush LegendMarkerItem::brush() const | |
73 | { |
|
73 | { | |
74 | return m_rectItem->brush(); |
|
74 | return m_rectItem->brush(); | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void LegendMarkerItem::setFont(const QFont &font) |
|
77 | void LegendMarkerItem::setFont(const QFont &font) | |
78 | { |
|
78 | { | |
79 | m_textItem->setFont(font); |
|
79 | m_textItem->setFont(font); | |
80 | QFontMetrics fn(font); |
|
80 | QFontMetrics fn(font); | |
81 | m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2); |
|
81 | m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2); | |
82 | updateGeometry(); |
|
82 | updateGeometry(); | |
83 | } |
|
83 | } | |
84 |
|
84 | |||
85 | QFont LegendMarkerItem::font() const |
|
85 | QFont LegendMarkerItem::font() const | |
86 | { |
|
86 | { | |
87 | return m_textItem->font(); |
|
87 | return m_textItem->font(); | |
88 | } |
|
88 | } | |
89 |
|
89 | |||
90 | void LegendMarkerItem::setLabel(const QString label) |
|
90 | void LegendMarkerItem::setLabel(const QString label) | |
91 | { |
|
91 | { | |
92 | m_label = label; |
|
92 | m_label = label; | |
93 | updateGeometry(); |
|
93 | updateGeometry(); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | QString LegendMarkerItem::label() const |
|
96 | QString LegendMarkerItem::label() const | |
97 | { |
|
97 | { | |
98 | return m_label; |
|
98 | return m_label; | |
99 | } |
|
99 | } | |
100 |
|
100 | |||
101 | void LegendMarkerItem::setLabelBrush(const QBrush &brush) |
|
101 | void LegendMarkerItem::setLabelBrush(const QBrush &brush) | |
102 | { |
|
102 | { | |
103 | m_textItem->setDefaultTextColor(brush.color()); |
|
103 | m_textItem->setDefaultTextColor(brush.color()); | |
104 | } |
|
104 | } | |
105 |
|
105 | |||
106 | QBrush LegendMarkerItem::labelBrush() const |
|
106 | QBrush LegendMarkerItem::labelBrush() const | |
107 | { |
|
107 | { | |
108 | return QBrush(m_textItem->defaultTextColor()); |
|
108 | return QBrush(m_textItem->defaultTextColor()); | |
109 | } |
|
109 | } | |
110 |
|
110 | |||
111 | void LegendMarkerItem::setGeometry(const QRectF &rect) |
|
111 | void LegendMarkerItem::setGeometry(const QRectF &rect) | |
112 | { |
|
112 | { | |
113 | qreal width = rect.width(); |
|
113 | qreal width = rect.width(); | |
114 | qreal x = m_margin + m_markerRect.width() + m_space + m_margin; |
|
114 | qreal x = m_margin + m_markerRect.width() + m_space + m_margin; | |
115 | QRectF truncatedRect; |
|
115 | QRectF truncatedRect; | |
116 |
|
116 | |||
117 | m_textItem->setHtml(ChartPresenter::truncatedText(m_textItem->font(), m_label, qreal(0.0), width - x, Qt::Horizontal, truncatedRect)); |
|
117 | m_textItem->setHtml(ChartPresenter::truncatedText(m_textItem->font(), m_label, qreal(0.0), width - x, Qt::Horizontal, truncatedRect)); | |
118 |
|
118 | |||
119 | qreal y = qMax(m_markerRect.height() + 2 * m_margin, truncatedRect.height() + 2 * m_margin); |
|
119 | qreal y = qMax(m_markerRect.height() + 2 * m_margin, truncatedRect.height() + 2 * m_margin); | |
120 |
|
120 | |||
121 | const QRectF &textRect = m_textItem->boundingRect(); |
|
121 | const QRectF &textRect = m_textItem->boundingRect(); | |
122 |
|
122 | |||
123 | m_textItem->setPos(x - m_margin, y / 2 - textRect.height() / 2); |
|
123 | m_textItem->setPos(x - m_margin, y / 2 - textRect.height() / 2); | |
124 | m_rectItem->setRect(m_markerRect); |
|
124 | m_rectItem->setRect(m_markerRect); | |
125 | m_rectItem->setPos(m_margin, y / 2 - m_markerRect.height() / 2); |
|
125 | m_rectItem->setPos(m_margin, y / 2 - m_markerRect.height() / 2); | |
126 |
|
126 | |||
127 | prepareGeometryChange(); |
|
127 | prepareGeometryChange(); | |
128 | m_boundingRect = QRectF(0, 0, x + textRect.width() + m_margin, y); |
|
128 | m_boundingRect = QRectF(0, 0, x + textRect.width() + m_margin, y); | |
129 | } |
|
129 | } | |
130 |
|
130 | |||
131 | QRectF LegendMarkerItem::boundingRect() const |
|
131 | QRectF LegendMarkerItem::boundingRect() const | |
132 | { |
|
132 | { | |
133 | return m_boundingRect; |
|
133 | return m_boundingRect; | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
136 | void LegendMarkerItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
137 | { |
|
137 | { | |
138 | Q_UNUSED(option) |
|
138 | Q_UNUSED(option) | |
139 | Q_UNUSED(widget) |
|
139 | Q_UNUSED(widget) | |
140 | Q_UNUSED(painter) |
|
140 | Q_UNUSED(painter) | |
141 | } |
|
141 | } | |
142 |
|
142 | |||
143 | QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const |
|
143 | QSizeF LegendMarkerItem::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const | |
144 | { |
|
144 | { | |
145 | Q_UNUSED(constraint) |
|
145 | Q_UNUSED(constraint) | |
146 |
|
146 | |||
147 | QSizeF sh; |
|
147 | QSizeF sh; | |
148 |
|
148 | |||
149 | switch (which) { |
|
149 | switch (which) { | |
150 | case Qt::MinimumSize: { |
|
150 | case Qt::MinimumSize: { | |
151 | QRectF labelRect = ChartPresenter::textBoundingRect(m_textItem->font(), "..."); |
|
151 | QRectF labelRect = ChartPresenter::textBoundingRect(m_textItem->font(), "..."); | |
152 | sh = QSizeF(labelRect.width() + (2.0 * m_margin) + m_space + m_markerRect.width(), |
|
152 | sh = QSizeF(labelRect.width() + (2.0 * m_margin) + m_space + m_markerRect.width(), | |
153 | qMax(m_markerRect.height(), labelRect.height()) + (2.0 * m_margin)); |
|
153 | qMax(m_markerRect.height(), labelRect.height()) + (2.0 * m_margin)); | |
154 | break; |
|
154 | break; | |
155 | } |
|
155 | } | |
156 | case Qt::PreferredSize: { |
|
156 | case Qt::PreferredSize: { | |
157 | QRectF labelRect = ChartPresenter::textBoundingRect(m_textItem->font(), m_label); |
|
157 | QRectF labelRect = ChartPresenter::textBoundingRect(m_textItem->font(), m_label); | |
158 | sh = QSizeF(labelRect.width() + (2.0 * m_margin) + m_space + m_markerRect.width(), |
|
158 | sh = QSizeF(labelRect.width() + (2.0 * m_margin) + m_space + m_markerRect.width(), | |
159 | qMax(m_markerRect.height(), labelRect.height()) + (2.0 * m_margin)); |
|
159 | qMax(m_markerRect.height(), labelRect.height()) + (2.0 * m_margin)); | |
160 | break; |
|
160 | break; | |
161 | } |
|
161 | } | |
162 | default: |
|
162 | default: | |
163 | break; |
|
163 | break; | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | return sh; |
|
166 | return sh; | |
167 | } |
|
167 | } | |
168 |
|
168 | |||
169 | void LegendMarkerItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) |
|
169 | void LegendMarkerItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event) | |
170 | { |
|
170 | { | |
171 | Q_UNUSED(event) |
|
171 | Q_UNUSED(event) | |
172 | m_hovering = true; |
|
172 | m_hovering = true; | |
173 | emit m_marker->q_ptr->hovered(true); |
|
173 | emit m_marker->q_ptr->hovered(true); | |
174 | } |
|
174 | } | |
175 |
|
175 | |||
176 | void LegendMarkerItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) |
|
176 | void LegendMarkerItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) | |
177 | { |
|
177 | { | |
178 | Q_UNUSED(event) |
|
178 | Q_UNUSED(event) | |
179 | m_hovering = false; |
|
179 | m_hovering = false; | |
180 | emit m_marker->q_ptr->hovered(false); |
|
180 | emit m_marker->q_ptr->hovered(false); | |
181 | } |
|
181 | } | |
182 |
|
182 | |||
183 |
|
183 | |||
184 | #include "moc_legendmarkeritem_p.cpp" |
|
184 | #include "moc_legendmarkeritem_p.cpp" | |
185 |
|
185 | |||
186 | QTCOMMERCIALCHART_END_NAMESPACE |
|
186 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now