@@ -11,6 +11,8 Bar::Bar(QString category, QGraphicsItem *parent) | |||
|
11 | 11 | mYpos(0), |
|
12 | 12 | mWidth(0), |
|
13 | 13 | mHeight(0), |
|
14 | mBrush(QBrush()), | |
|
15 | mPen(QPen()), | |
|
14 | 16 | mCategory(category) |
|
15 | 17 | { |
|
16 | 18 | setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton); |
@@ -54,6 +56,7 void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidg | |||
|
54 | 56 | if (0 == mHeight) { |
|
55 | 57 | return; |
|
56 | 58 | } |
|
59 | painter->setPen(mPen); | |
|
57 | 60 | painter->setBrush(mBrush); |
|
58 | 61 | |
|
59 | 62 | // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1. |
@@ -48,6 +48,7 void PercentBarPresenter::layoutChanged() | |||
|
48 | 48 | |
|
49 | 49 | // TODO: width settable per bar? |
|
50 | 50 | bar->resize(mBarWidth, barHeight); |
|
51 | bar->setPen(mSeries->barsetAt(set)->pen()); | |
|
51 | 52 | bar->setBrush(mSeries->barsetAt(set)->brush()); |
|
52 | 53 | bar->setPos(xPos, yPos-barHeight); |
|
53 | 54 | itemIndex++; |
@@ -122,7 +122,7 void ChartTheme::decorate(QAreaSeries* series, int index,bool force) | |||
|
122 | 122 | QBrush brush; |
|
123 | 123 | |
|
124 | 124 | if (pen == series->pen() || force){ |
|
125 |
pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), |
|
|
125 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
|
126 | 126 | pen.setWidthF(2); |
|
127 | 127 | series->setPen(pen); |
|
128 | 128 | } |
@@ -147,9 +147,10 void ChartTheme::decorate(QLineSeries* series,int index,bool force) | |||
|
147 | 147 | void ChartTheme::decorate(QBarSeries* series,int index,bool force) |
|
148 | 148 | { |
|
149 | 149 | QBrush brush; |
|
150 | QPen pen; | |
|
150 | 151 | QList<QBarSet*> sets = series->barSets(); |
|
151 | 152 | |
|
152 |
for (int i |
|
|
153 | for (int i(0); i < sets.count(); i++) { | |
|
153 | 154 | qreal pos = 0.5; |
|
154 | 155 | if (sets.count() > 1) |
|
155 | 156 | pos = (qreal) i / (qreal) (sets.count() - 1); |
@@ -158,76 +159,28 void ChartTheme::decorate(QBarSeries* series,int index,bool force) | |||
|
158 | 159 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
159 | 160 | sets.at(i)->setBrush(QBrush(c)); |
|
160 | 161 | } |
|
161 | // Pick label color as far as possible from bar color (within gradient). | |
|
162 | // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :) | |
|
163 | // TODO: better picking of label color? | |
|
164 | QColor c; | |
|
165 | ||
|
166 | if (pos < 0.3) { | |
|
167 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); | |
|
168 | } else { | |
|
169 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); | |
|
170 | } | |
|
171 | sets.at(i)->setFloatingValuePen(QPen(c)); | |
|
172 | ||
|
173 | } | |
|
174 | } | |
|
175 | ||
|
176 | void ChartTheme::decorate(QStackedBarSeries* series,int index,bool force) | |
|
177 | { | |
|
178 | QBrush brush; | |
|
179 | QList<QBarSet*> sets = series->barSets(); | |
|
180 | ||
|
181 | for (int i=0; i<sets.count(); i++) { | |
|
182 | qreal pos = 0.5; | |
|
183 | if (sets.count() > 1) | |
|
184 | pos = (qreal) i / (qreal) (sets.count() - 1); | |
|
185 | if(brush == sets.at(i)->brush() || force){ | |
|
186 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
|
187 | sets.at(i)->setBrush(QBrush(c)); | |
|
188 | } | |
|
189 | QColor c; | |
|
190 | if (pos < 0.3) { | |
|
191 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); | |
|
192 | } else { | |
|
193 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); | |
|
194 | } | |
|
195 | sets.at(i)->setFloatingValuePen(QPen(c)); | |
|
196 | } | |
|
197 | } | |
|
198 | 162 | |
|
199 | void ChartTheme::decorate(QPercentBarSeries* series,int index,bool force) | |
|
200 | { | |
|
201 | QBrush brush; | |
|
202 | QList<QBarSet*> sets = series->barSets(); | |
|
163 | // Pick label color from the opposite end of the gradient. | |
|
164 | // 0.3 as a boundary seems to work well. | |
|
165 | if (pos < 0.3) | |
|
166 | sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); | |
|
167 | else | |
|
168 | sets.at(i)->setFloatingValuePen(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); | |
|
203 | 169 | |
|
204 | for (int i=0; i<sets.count(); i++) { | |
|
205 | qreal pos = 0.5; | |
|
206 |
|
|
|
207 | pos = (qreal) i / (qreal) (sets.count() - 1); | |
|
208 | ||
|
209 | if(brush == sets.at(i)->brush() || force){ | |
|
210 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); | |
|
211 | sets.at(i)->setBrush(QBrush(c)); | |
|
212 | } | |
|
213 | QColor c; | |
|
214 | if (pos < 0.3) { | |
|
215 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1); | |
|
216 | } else { | |
|
217 | c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0); | |
|
170 | if (pen == sets.at(i)->pen() || force) { | |
|
171 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
|
172 | sets.at(i)->setPen(c); | |
|
218 | 173 | } |
|
219 | sets.at(i)->setFloatingValuePen(QPen(c)); | |
|
220 | 174 | } |
|
221 | 175 | } |
|
222 | 176 | |
|
223 | 177 | void ChartTheme::decorate(QScatterSeries* series, int index,bool force) |
|
224 | 178 | { |
|
225 | ||
|
226 | 179 | QPen pen; |
|
227 | 180 | QBrush brush; |
|
228 | 181 | |
|
229 | 182 | if (pen == series->pen() || force) { |
|
230 |
pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), |
|
|
183 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); | |
|
231 | 184 | pen.setWidthF(2); |
|
232 | 185 | series->setPen(pen); |
|
233 | 186 | } |
@@ -240,17 +193,17 void ChartTheme::decorate(QScatterSeries* series, int index,bool force) | |||
|
240 | 193 | |
|
241 | 194 | void ChartTheme::decorate(QPieSeries* series, int index, bool force) |
|
242 | 195 | { |
|
243 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
|
244 | ||
|
245 | 196 | QPen pen; |
|
246 | 197 | QBrush brush; |
|
247 | 198 | |
|
248 | 199 | for (int i(0); i < series->slices().count(); i++) { |
|
249 | qreal pos = (qreal) i / (qreal) series->count(); | |
|
250 | 200 |
if( |
|
251 |
QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0. |
|
|
201 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); | |
|
252 | 202 | series->slices().at(i)->setSlicePen(penColor); |
|
253 | 203 | } |
|
204 | ||
|
205 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient | |
|
206 | qreal pos = (qreal) i / (qreal) series->count(); | |
|
254 | 207 |
if( |
|
255 | 208 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
256 | 209 | series->slices().at(i)->setSliceBrush(brushColor); |
@@ -44,10 +44,7 public: | |||
|
44 | 44 | QChart::ChartTheme id() const {return m_id;} |
|
45 | 45 | void decorate(QChart* chart,bool force = true); |
|
46 | 46 | void decorate(QLegend* legend,bool force = true); |
|
47 | //void decorate(ChartItem* item, QSeries* series,int index); | |
|
48 | 47 | void decorate(QBarSeries* series, int index,bool force = true); |
|
49 | void decorate(QStackedBarSeries* series, int index,bool force = true); | |
|
50 | void decorate(QPercentBarSeries* series, int index,bool force = true); | |
|
51 | 48 | void decorate(QLineSeries* series, int index,bool force = true); |
|
52 | 49 | void decorate(QAreaSeries* series, int index,bool force = true); |
|
53 | 50 | void decorate(QScatterSeries* series, int index,bool force = true); |
@@ -6,18 +6,12 | |||
|
6 | 6 | |
|
7 | 7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
8 | 8 | |
|
9 | ||
|
10 | ||
|
11 | ||
|
12 | ||
|
13 | ||
|
14 | ||
|
15 | 9 | ScatterChartItem::ScatterChartItem(QScatterSeries *series, QGraphicsItem *parent) : |
|
16 | 10 | XYChartItem(series,parent), |
|
17 | 11 | m_series(series), |
|
18 | 12 | m_items(this), |
|
19 | 13 | m_shape(QScatterSeries::MarkerShapeRectangle), |
|
20 |
m_size(1 |
|
|
14 | m_size(15) | |
|
21 | 15 | |
|
22 | 16 | { |
|
23 | 17 | Q_ASSERT(parent); |
General Comments 0
You need to be logged in to leave comments.
Login now