@@ -53,7 +53,7 class LegendMarkerItem : public QGraphicsObject, public QGraphicsLayoutItem | |||||
53 | Q_OBJECT |
|
53 | Q_OBJECT | |
54 | Q_INTERFACES(QGraphicsLayoutItem) |
|
54 | Q_INTERFACES(QGraphicsLayoutItem) | |
55 | public: |
|
55 | public: | |
56 | explicit LegendMarkerItem(QAbstractSeries *m_series, QGraphicsObject *parent); |
|
56 | explicit LegendMarkerItem(QAbstractSeries *m_series, QGraphicsObject *parent = 0); | |
57 |
|
57 | |||
58 | void setPen(const QPen &pen); |
|
58 | void setPen(const QPen &pen); | |
59 | QPen pen() const; |
|
59 | QPen pen() const; |
@@ -107,80 +107,9 QLegendMarkerPrivate::QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarke | |||||
107 | q_ptr(q), |
|
107 | q_ptr(q), | |
108 | m_series(series) |
|
108 | m_series(series) | |
109 | { |
|
109 | { | |
110 |
m_item = new LegendMarkerItem(m_series |
|
110 | m_item = new LegendMarkerItem(m_series); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | void QLegendMarkerPrivate::setGeometry(const QRectF& rect) |
|
|||
114 | { |
|
|||
115 | QFontMetrics fn (m_font); |
|
|||
116 |
|
||||
117 |
|
||||
118 | int width = rect.width(); |
|
|||
119 | qreal x = m_margin + m_markerRect.width() + m_space + m_margin; |
|
|||
120 | qreal y = qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin); |
|
|||
121 |
|
||||
122 | if (fn.boundingRect(m_label).width() + x > width) |
|
|||
123 | { |
|
|||
124 | QString string = m_label + "..."; |
|
|||
125 | while(fn.boundingRect(string).width() + x > width && string.length() > 3) |
|
|||
126 | string.remove(string.length() - 4, 1); |
|
|||
127 | m_textItem->setText(string); |
|
|||
128 | } |
|
|||
129 | else |
|
|||
130 | m_textItem->setText(m_label); |
|
|||
131 |
|
||||
132 | const QRectF& textRect = m_textItem->boundingRect(); |
|
|||
133 |
|
||||
134 |
|
||||
135 | m_textItem->setPos(x-m_margin,y/2 - textRect.height()/2); |
|
|||
136 | m_rectItem->setRect(m_markerRect); |
|
|||
137 | m_rectItem->setPos(m_margin,y/2 - m_markerRect.height()/2); |
|
|||
138 |
|
||||
139 | prepareGeometryChange(); |
|
|||
140 | m_boundingRect = QRectF(0,0,x+textRect.width()+m_margin,y); |
|
|||
141 | } |
|
|||
142 |
|
||||
143 | QRectF QLegendMarkerPrivate::boundingRect() const |
|
|||
144 | { |
|
|||
145 | return m_boundingRect; |
|
|||
146 | } |
|
|||
147 |
|
||||
148 | void QLegendMarkerPrivate::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
|||
149 | { |
|
|||
150 | Q_UNUSED(option) |
|
|||
151 | Q_UNUSED(widget) |
|
|||
152 | Q_UNUSED(painter) |
|
|||
153 | } |
|
|||
154 |
|
||||
155 | QSizeF QLegendMarkerPrivate::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const |
|
|||
156 | { |
|
|||
157 | Q_UNUSED(constraint) |
|
|||
158 |
|
||||
159 | QFontMetrics fn(m_textItem->font()); |
|
|||
160 | QSizeF sh; |
|
|||
161 |
|
||||
162 | switch (which) { |
|
|||
163 | case Qt::MinimumSize: |
|
|||
164 | sh = QSizeF(fn.boundingRect("...").width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); |
|
|||
165 | break; |
|
|||
166 | case Qt::PreferredSize: |
|
|||
167 | sh = QSizeF(fn.boundingRect(m_label).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin)); |
|
|||
168 | break; |
|
|||
169 | default: |
|
|||
170 | break; |
|
|||
171 | } |
|
|||
172 |
|
||||
173 | return sh; |
|
|||
174 | } |
|
|||
175 |
|
||||
176 | void QLegendMarkerPrivate::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
|||
177 | { |
|
|||
178 | qDebug() << "QLegendMarkerPrivate::mousePressEvent" << event; |
|
|||
179 | QGraphicsObject::mousePressEvent(event); |
|
|||
180 | //TODO: selected signal removed for now |
|
|||
181 | } |
|
|||
182 |
|
||||
183 |
|
||||
184 | #include "moc_qlegendmarker.cpp" |
|
113 | #include "moc_qlegendmarker.cpp" | |
185 | #include "moc_qlegendmarker_p.cpp" |
|
114 | #include "moc_qlegendmarker_p.cpp" | |
186 |
|
115 |
@@ -52,10 +52,9 class QPieSeries; | |||||
52 | class QLegendMarker; |
|
52 | class QLegendMarker; | |
53 | class LegendMarkerItem; |
|
53 | class LegendMarkerItem; | |
54 |
|
54 | |||
55 |
class QLegendMarkerPrivate : public Q |
|
55 | class QLegendMarkerPrivate : public QObject | |
56 | { |
|
56 | { | |
57 | Q_OBJECT |
|
57 | Q_OBJECT | |
58 | Q_INTERFACES(QGraphicsLayoutItem) |
|
|||
59 | public: |
|
58 | public: | |
60 | explicit QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q); |
|
59 | explicit QLegendMarkerPrivate(QAbstractSeries *series, QLegendMarker *q); | |
61 | /* |
|
60 | /* | |
@@ -74,17 +73,6 public: | |||||
74 | void setLabelBrush(const QBrush &brush); |
|
73 | void setLabelBrush(const QBrush &brush); | |
75 | QBrush labelBrush() const; |
|
74 | QBrush labelBrush() const; | |
76 | */ |
|
75 | */ | |
77 | void setGeometry(const QRectF& rect); |
|
|||
78 |
|
||||
79 | QRectF boundingRect() const; |
|
|||
80 |
|
||||
81 | void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
|||
82 |
|
||||
83 | QSizeF sizeHint (Qt::SizeHint which, const QSizeF& constraint) const; |
|
|||
84 |
|
||||
85 | protected: |
|
|||
86 | // From QGraphicsObject |
|
|||
87 | void mousePressEvent(QGraphicsSceneMouseEvent *event); |
|
|||
88 |
|
76 | |||
89 | public Q_SLOTS: |
|
77 | public Q_SLOTS: | |
90 | virtual void updated() {}; |
|
78 | virtual void updated() {}; |
General Comments 0
You need to be logged in to leave comments.
Login now