##// END OF EJS Templates
better use of gradients in barcharts
sauimone -
r512:db1a02a52a65
parent child
Show More
@@ -56,6 +56,7 int main(int argc, char *argv[])
56 QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues()));
56 QObject::connect(set1,SIGNAL(clicked(QString)),set1,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues()));
57 QObject::connect(set2,SIGNAL(clicked(QString)),set2,SIGNAL(toggleFloatingValues()));
58 QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues()));
58 QObject::connect(set3,SIGNAL(clicked(QString)),set3,SIGNAL(toggleFloatingValues()));
59 QObject::connect(set4,SIGNAL(clicked(QString)),set4,SIGNAL(toggleFloatingValues()));
59 //! [4]
60 //! [4]
60
61
61 //! [5]
62 //! [5]
@@ -61,6 +61,7 void BarPresenter::layoutChanged()
61 Separator* sep = mSeparators.at(s);
61 Separator* sep = mSeparators.at(s);
62 sep->setPos(xPos,0);
62 sep->setPos(xPos,0);
63 sep->setSize(QSizeF(1,mHeight));
63 sep->setSize(QSizeF(1,mHeight));
64 sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme
64 xPos += categoryWidth;
65 xPos += categoryWidth;
65 }
66 }
66
67
@@ -73,10 +74,10 void BarPresenter::layoutChanged()
73 qreal barHeight = mSeries->valueAt(set,category) * scale;
74 qreal barHeight = mSeries->valueAt(set,category) * scale;
74 BarValue* value = mFloatingValues.at(itemIndex);
75 BarValue* value = mFloatingValues.at(itemIndex);
75
76
76 // TODO: remove hard coding, apply layout
77 QBarSet* barSet = mSeries->barsetAt(set);
77 value->resize(100,50);
78 value->resize(100,50); // TODO: proper layout for this.
78 value->setPos(xPos, yPos-barHeight/2);
79 value->setPos(xPos, yPos-barHeight/2);
79 value->setPen(QPen(QColor(255,255,255,255)));
80 value->setPen(barSet->floatingValuePen());
80
81
81 if (mSeries->valueAt(set,category) != 0) {
82 if (mSeries->valueAt(set,category) != 0) {
82 value->setValueString(QString::number(mSeries->valueAt(set,category)));
83 value->setValueString(QString::number(mSeries->valueAt(set,category)));
@@ -78,7 +78,6 void BarPresenterBase::dataChanged()
78 int count = mSeries->categoryCount() - 1; // There is one less separator than columns
78 int count = mSeries->categoryCount() - 1; // There is one less separator than columns
79 for (int i=0; i<count; i++) {
79 for (int i=0; i<count; i++) {
80 Separator* sep = new Separator(this);
80 Separator* sep = new Separator(this);
81 sep->setColor(QColor(255,0,0,255)); // TODO: color for separations from theme
82 sep->setVisible(mSeries->separatorsVisible());
81 sep->setVisible(mSeries->separatorsVisible());
83 childItems().append(sep);
82 childItems().append(sep);
84 mSeparators.append(sep);
83 mSeparators.append(sep);
@@ -76,10 +76,10 void PercentBarPresenter::layoutChanged()
76 qreal barHeight = mSeries->valueAt(set,category) * scale;
76 qreal barHeight = mSeries->valueAt(set,category) * scale;
77 BarValue* value = mFloatingValues.at(itemIndex);
77 BarValue* value = mFloatingValues.at(itemIndex);
78
78
79 // TODO: remove hard coding, apply layout
79 QBarSet* barSet = mSeries->barsetAt(set);
80 value->resize(100,50);
80 value->resize(100,50); // TODO: proper layout for this.
81 value->setPos(xPos, yPos-barHeight/2);
81 value->setPos(xPos, yPos-barHeight/2);
82 value->setPen(QPen(QColor(255,255,255,255)));
82 value->setPen(barSet->floatingValuePen());
83
83
84 if (mSeries->valueAt(set,category) != 0) {
84 if (mSeries->valueAt(set,category) != 0) {
85 int p = mSeries->percentageAt(set,category) * 100;
85 int p = mSeries->percentageAt(set,category) * 100;
@@ -154,6 +154,22 QBrush QBarSet::brush() const
154 }
154 }
155
155
156 /*!
156 /*!
157 Sets the pen for floating values that are drawn on top of this set
158 */
159 void QBarSet::setFloatingValuePen(const QPen pen)
160 {
161 mFloatingValuePen = pen;
162 }
163
164 /*!
165 Returns the pen for floating values that are drawn on top of this set
166 */
167 QPen QBarSet::floatingValuePen() const
168 {
169 return mFloatingValuePen;
170 }
171
172 /*!
157 \internal \a pos
173 \internal \a pos
158 */
174 */
159 void QBarSet::barHoverEnterEvent(QPoint pos)
175 void QBarSet::barHoverEnterEvent(QPoint pos)
@@ -33,6 +33,9 public:
33 void setBrush(const QBrush brush);
33 void setBrush(const QBrush brush);
34 QBrush brush() const;
34 QBrush brush() const;
35
35
36 void setFloatingValuePen(const QPen pen);
37 QPen floatingValuePen() const;
38
36 Q_SIGNALS:
39 Q_SIGNALS:
37 void clicked(QString category); // Clicked and hover signals exposed to user
40 void clicked(QString category); // Clicked and hover signals exposed to user
38 void rightClicked(QString category);
41 void rightClicked(QString category);
@@ -59,7 +62,7 private:
59 QMap<QString,qreal> mMappedValues;
62 QMap<QString,qreal> mMappedValues;
60 QPen mPen;
63 QPen mPen;
61 QBrush mBrush;
64 QBrush mBrush;
62
65 QPen mFloatingValuePen;
63 };
66 };
64
67
65 QTCOMMERCIALCHART_END_NAMESPACE
68 QTCOMMERCIALCHART_END_NAMESPACE
@@ -83,10 +83,10 void StackedBarPresenter::layoutChanged()
83 qreal barHeight = mSeries->valueAt(set,category) * scale;
83 qreal barHeight = mSeries->valueAt(set,category) * scale;
84 BarValue* value = mFloatingValues.at(itemIndex);
84 BarValue* value = mFloatingValues.at(itemIndex);
85
85
86 // TODO: remove hard coding, apply layout
86 QBarSet* barSet = mSeries->barsetAt(set);
87 value->resize(100,50);
87 value->resize(100,50); // TODO: proper layout for this.
88 value->setPos(xPos, yPos-barHeight/2);
88 value->setPos(xPos, yPos-barHeight/2);
89 value->setPen(QPen(QColor(255,255,255,255)));
89 value->setPen(barSet->floatingValuePen());
90
90
91 if (mSeries->valueAt(set,category) != 0) {
91 if (mSeries->valueAt(set,category) != 0) {
92 value->setValueString(QString::number(mSeries->valueAt(set,category)));
92 value->setValueString(QString::number(mSeries->valueAt(set,category)));
@@ -160,6 +160,16 void ChartTheme::decorate(BarPresenter* item, QBarSeries* series,int count)
160 qreal pos = (qreal) i / (qreal) sets.count();
160 qreal pos = (qreal) i / (qreal) sets.count();
161 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
161 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
162 sets.at(i)->setBrush(QBrush(c));
162 sets.at(i)->setBrush(QBrush(c));
163
164 // Pick label color as far as possible from bar color (within gradient).
165 // 0.3 is magic number that was picked as value that gave enough contrast with icy theme gradient :)
166 // TODO: better picking of label color?
167 if (pos < 0.3) {
168 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1);
169 } else {
170 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 0);
171 }
172 sets.at(i)->setFloatingValuePen(QPen(c));
163 }
173 }
164 }
174 }
165
175
@@ -170,6 +180,13 void ChartTheme::decorate(StackedBarPresenter* item, QStackedBarSeries* series,i
170 qreal pos = (qreal) i / (qreal) sets.count();
180 qreal pos = (qreal) i / (qreal) sets.count();
171 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
181 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
172 sets.at(i)->setBrush(QBrush(c));
182 sets.at(i)->setBrush(QBrush(c));
183
184 if (pos < 0.3) {
185 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1);
186 } else {
187 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 0);
188 }
189 sets.at(i)->setFloatingValuePen(QPen(c));
173 }
190 }
174 }
191 }
175
192
@@ -180,6 +197,13 void ChartTheme::decorate(PercentBarPresenter* item, QPercentBarSeries* series,i
180 qreal pos = (qreal) i / (qreal) sets.count();
197 qreal pos = (qreal) i / (qreal) sets.count();
181 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
198 QColor c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), pos);
182 sets.at(i)->setBrush(QBrush(c));
199 sets.at(i)->setBrush(QBrush(c));
200
201 if (pos < 0.3) {
202 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 1);
203 } else {
204 c = colorAt(m_seriesGradients.at(count % m_seriesGradients.size()), 0);
205 }
206 sets.at(i)->setFloatingValuePen(QPen(c));
183 }
207 }
184 }
208 }
185
209
General Comments 0
You need to be logged in to leave comments. Login now