bar.cpp
74 lines
| 1.3 KiB
| text/x-c
|
CppLexer
sauimone
|
r118 | #include "bar_p.h" | ||
sauimone
|
r56 | #include <QDebug> | ||
Michal Klocek
|
r59 | #include <QPainter> | ||
sauimone
|
r56 | |||
QTCOMMERCIALCHART_BEGIN_NAMESPACE | ||||
Tero Ahola
|
r103 | Bar::Bar(QGraphicsItem *parent) | ||
Tero Ahola
|
r104 | : ChartItem(parent) | ||
sauimone
|
r56 | { | ||
} | ||||
Michal Klocek
|
r115 | void Bar::setSize(const QSizeF& size) | ||
sauimone
|
r74 | { | ||
mWidth = size.width(); | ||||
mHeight = size.height(); | ||||
} | ||||
sauimone
|
r113 | void Bar::resize( qreal w, qreal h ) | ||
sauimone
|
r56 | { | ||
sauimone
|
r97 | // qDebug() << "bar::resize" << w << h; | ||
sauimone
|
r56 | mWidth = w; | ||
mHeight = h; | ||||
} | ||||
void Bar::setColor( QColor col ) | ||||
{ | ||||
mColor = col; | ||||
} | ||||
sauimone
|
r183 | |||
sauimone
|
r56 | void Bar::setPos(qreal x, qreal y) | ||
{ | ||||
sauimone
|
r97 | // qDebug() << "Bar::setpos" << x << y; | ||
sauimone
|
r56 | mXpos = x; | ||
mYpos = y; | ||||
} | ||||
sauimone
|
r183 | void Bar::setPen(QPen pen) | ||
{ | ||||
mPen = pen; | ||||
} | ||||
void Bar::setBrush(QBrush brush) | ||||
{ | ||||
mBrush = brush; | ||||
} | ||||
sauimone
|
r56 | void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) | ||
{ | ||||
sauimone
|
r82 | if (0 == mHeight) { | ||
return; | ||||
} | ||||
sauimone
|
r97 | // TODO: accept brush instead of color | ||
sauimone
|
r183 | painter->setBrush(mBrush); | ||
// QBrush brush(mColor); | ||||
// painter->setBrush(brush); | ||||
sauimone
|
r113 | |||
// This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1. | ||||
int x0 = mXpos; | ||||
int x1 = (mXpos + mWidth); | ||||
int w = x1-x0; | ||||
int y0 = mYpos; | ||||
int y1 = (mYpos + mHeight); | ||||
int h = y1-y0; | ||||
painter->drawRect(x0, y0 ,w ,h); | ||||
sauimone
|
r56 | } | ||
QRectF Bar::boundingRect() const | ||||
{ | ||||
QRectF r(mXpos, mYpos, mXpos + mWidth, mYpos + mHeight); | ||||
return r; | ||||
} | ||||
QTCOMMERCIALCHART_END_NAMESPACE | ||||