diff --git a/src/barchart/bar.cpp b/src/barchart/bar.cpp index 7be89a3..855b85f 100644 --- a/src/barchart/bar.cpp +++ b/src/barchart/bar.cpp @@ -5,17 +5,10 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE Bar::Bar(QGraphicsItem *parent) - : ChartItem(parent) + : QGraphicsObject(parent) { } -void Bar::setSize(const QSizeF& size) -{ - mWidth = size.width(); - mHeight = size.height(); -} - - void Bar::resize( qreal w, qreal h ) { // qDebug() << "bar::resize" << w << h; @@ -23,11 +16,6 @@ void Bar::resize( qreal w, qreal h ) mHeight = h; } -void Bar::setColor( QColor col ) -{ - mColor = col; -} - void Bar::setPos(qreal x, qreal y) { // qDebug() << "Bar::setpos" << x << y; @@ -50,10 +38,8 @@ void Bar::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidg if (0 == mHeight) { return; } - // TODO: accept brush instead of color + painter->setBrush(mBrush); -// QBrush brush(mColor); -// painter->setBrush(brush); // This compensates for rounding errors. drawRect takes ints and cumulative error of pos + size may be over 1. int x0 = mXpos; @@ -71,4 +57,21 @@ QRectF Bar::boundingRect() const return r; } +void Bar::hoverEnterEvent(QGraphicsSceneHoverEvent* /*event*/) +{ + emit hoverEnter(); +} + +void Bar::hoverLeaveEvent(QGraphicsSceneHoverEvent* /*event*/) +{ + emit hoverLeave(); +} + +void Bar::mousePressEvent(QGraphicsSceneMouseEvent* /*event*/) +{ + emit clicked(); +} + +#include "moc_bar_p.cpp" + QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/bar_p.h b/src/barchart/bar_p.h index 013c01d..b7f69cb 100644 --- a/src/barchart/bar_p.h +++ b/src/barchart/bar_p.h @@ -1,35 +1,43 @@ #ifndef BAR_H #define BAR_H -#include "chartitem_p.h" +//#include "chartitem_p.h" #include "qchartglobal.h" -#include +#include #include #include QTCOMMERCIALCHART_BEGIN_NAMESPACE // Single bar item of chart -class Bar : public ChartItem +class Bar : public QGraphicsObject { + Q_OBJECT + public: Bar(QGraphicsItem *parent=0); -public: // from ChartItem - void setSize(const QSizeF &size); +public: // Layout Stuff void resize(qreal w, qreal h); // Size of bar. void setPos(qreal x, qreal y); void setPen(QPen pen); void setBrush(QBrush brush); - void setColor( QColor col); // deprecated public: - // From QGraphicsItem + // From QGraphicsItem void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); QRectF boundingRect() const; + void hoverEnterEvent(QGraphicsSceneHoverEvent *event); + void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); + void mousePressEvent(QGraphicsSceneMouseEvent *event); + +Q_SIGNALS: + void clicked(); + void hoverEnter(); + void hoverLeave(); private: @@ -37,7 +45,6 @@ private: qreal mWidth; qreal mXpos; qreal mYpos; - QColor mColor; QBrush mBrush; QPen mPen; diff --git a/src/barchart/barpresenterbase.cpp b/src/barchart/barpresenterbase.cpp index 4a7cc38..993ea87 100644 --- a/src/barchart/barpresenterbase.cpp +++ b/src/barchart/barpresenterbase.cpp @@ -57,10 +57,13 @@ void BarPresenterBase::dataChanged() } // Create new graphic items for bars - int totalItems = mModel.countTotalItems(); - for (int i=0; i QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -56,8 +57,13 @@ const QBrush& QBarSet::brush() const return mBrush; } +void QBarSet::barClicked() +{ + // Some bar of this set has been clicked + // TODO: What happens then? + qDebug() << "bar Clicked"; +} -//TODO?: -//#include "moc_qbarset.cpp" +#include "moc_qbarset.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/barchart/qbarset.h b/src/barchart/qbarset.h index 89f240a..cc15e97 100644 --- a/src/barchart/qbarset.h +++ b/src/barchart/qbarset.h @@ -7,9 +7,9 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -class QTCOMMERCIALCHART_EXPORT QBarSet // TODO? : public QObject +class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject { - //Q_OBJECT; + Q_OBJECT; public: QBarSet(); @@ -27,12 +27,22 @@ public: void setBrush(const QBrush& brush); const QBrush& brush() const; +// void clicked(); +/* + void hoverEnter(); + void hoverLeave(); +*/ + +public Q_SLOTS: + void barClicked(); + private: QString mName; QList mValues; QPen mPen; QBrush mBrush; + }; QTCOMMERCIALCHART_END_NAMESPACE