@@ -1,50 +1,50 | |||||
1 | #include "bar.h" |
|
1 | #include "bar.h" | |
2 | #include <QDebug> |
|
2 | #include <QDebug> | |
3 |
#include <Q |
|
3 | #include <QPainter> | |
4 |
|
4 | |||
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
5 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
6 |
|
6 | |||
7 | Bar::Bar(QGraphicsItem *parent) |
|
7 | Bar::Bar(QGraphicsItem *parent) | |
8 | : QGraphicsItem(parent) |
|
8 | : QGraphicsItem(parent) | |
9 | { |
|
9 | { | |
10 | } |
|
10 | } | |
11 |
|
11 | |||
12 | void Bar::resize( int w, int h ) |
|
12 | void Bar::resize( int w, int h ) | |
13 | { |
|
13 | { | |
14 | mWidth = w; |
|
14 | mWidth = w; | |
15 | mHeight = h; |
|
15 | mHeight = h; | |
16 | } |
|
16 | } | |
17 |
|
17 | |||
18 | void Bar::setColor( QColor col ) |
|
18 | void Bar::setColor( QColor col ) | |
19 | { |
|
19 | { | |
20 | mColor = col; |
|
20 | mColor = col; | |
21 | } |
|
21 | } | |
22 | void Bar::setPos(qreal x, qreal y) |
|
22 | void Bar::setPos(qreal x, qreal y) | |
23 | { |
|
23 | { | |
24 | mXpos = x; |
|
24 | mXpos = x; | |
25 | mYpos = y; |
|
25 | mYpos = y; | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) |
|
28 | void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | |
29 | { |
|
29 | { | |
30 | // Set color for bar. TODO: gradients, textures etc |
|
30 | // Set color for bar. TODO: gradients, textures etc | |
31 | QPen pen = painter->pen(); |
|
31 | QPen pen = painter->pen(); | |
32 | pen.setColor( mColor ); |
|
32 | pen.setColor( mColor ); | |
33 | pen.setWidth( mWidth ); |
|
33 | pen.setWidth( mWidth ); | |
34 | painter->setPen(pen); |
|
34 | painter->setPen(pen); | |
35 |
|
35 | |||
36 | // Draw bar |
|
36 | // Draw bar | |
37 | // TODO: Pen width affects bar height for now. This should be rect |
|
37 | // TODO: Pen width affects bar height for now. This should be rect | |
38 | painter->drawLine(scenePos().x() + mXpos, scenePos().y() + mYpos + parentItem()->boundingRect().height() - mHeight - mWidth, |
|
38 | painter->drawLine(scenePos().x() + mXpos, scenePos().y() + mYpos + parentItem()->boundingRect().height() - mHeight - mWidth, | |
39 | scenePos().x() + mXpos, scenePos().y() + mYpos + parentItem()->boundingRect().height() - mWidth); |
|
39 | scenePos().x() + mXpos, scenePos().y() + mYpos + parentItem()->boundingRect().height() - mWidth); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | QRectF Bar::boundingRect() const |
|
42 | QRectF Bar::boundingRect() const | |
43 | { |
|
43 | { | |
44 | // TODO: check validity of this (I suppose there is easier way, and currently this bit incorrect :) |
|
44 | // TODO: check validity of this (I suppose there is easier way, and currently this bit incorrect :) | |
45 | // QRectF r(scenePos().x()+mXpos, scenePos().y()+mYpos, scenePos().x() + mWidth, scenePos().y() + mHeight ); |
|
45 | // QRectF r(scenePos().x()+mXpos, scenePos().y()+mYpos, scenePos().x() + mWidth, scenePos().y() + mHeight ); | |
46 | QRectF r(mXpos, mYpos, mXpos + mWidth, mYpos + mHeight); |
|
46 | QRectF r(mXpos, mYpos, mXpos + mWidth, mYpos + mHeight); | |
47 | return r; |
|
47 | return r; | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | QTCOMMERCIALCHART_END_NAMESPACE |
|
50 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now