diff --git a/src/qchart.cpp b/src/qchart.cpp index 87a4801..112bad0 100644 --- a/src/qchart.cpp +++ b/src/qchart.cpp @@ -68,7 +68,7 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags), d_ptr(new QChartPrivate()) { - d_ptr->m_legend = new QLegend(this); + d_ptr->m_legend = new ScrolledQLegend(this); d_ptr->m_dataset = new ChartDataSet(this); d_ptr->m_presenter = new ChartPresenter(this,d_ptr->m_dataset); d_ptr->m_presenter->setTheme(QChart::ChartThemeLight, false); diff --git a/src/qlegend.cpp b/src/qlegend.cpp index 595dd79..e01d6ac 100644 --- a/src/qlegend.cpp +++ b/src/qlegend.cpp @@ -102,8 +102,7 @@ QLegend::QLegend(QChart *chart):QGraphicsWidget(chart), m_width(0), m_height(0), m_visible(false), - m_dirty(false), - m_scroller(new Scroller(this)) + m_dirty(false) { setZValue(ChartPresenter::LegendZValue); setFlags(QGraphicsItem::ItemClipsChildrenToShape); @@ -542,22 +541,6 @@ void QLegend::showEvent(QShowEvent *event) updateLayout(); } -void QLegend::mousePressEvent(QGraphicsSceneMouseEvent* event) -{ - //Q_UNUSED(event); - m_scroller->mousePressEvent(event); -} -void QLegend::mouseMoveEvent(QGraphicsSceneMouseEvent* event) -{ - //Q_UNUSED(event); - m_scroller->mouseMoveEvent(event); -} -void QLegend::mouseReleaseEvent(QGraphicsSceneMouseEvent* event) -{ - //Q_UNUSED(event); - m_scroller->mouseReleaseEvent(event); -} - #include "moc_qlegend.cpp" QTCOMMERCIALCHART_END_NAMESPACE diff --git a/src/qlegend.h b/src/qlegend.h index a6ff2ba..15d0605 100644 --- a/src/qlegend.h +++ b/src/qlegend.h @@ -25,6 +25,7 @@ #include #include #include +#include "scroller_p.h" QTCOMMERCIALCHART_BEGIN_NAMESPACE @@ -39,7 +40,6 @@ class QAreaSeries; class LegendScrollButton; class QSeries; class QChart; -class Scroller; class QTCOMMERCIALCHART_EXPORT QLegend : public QGraphicsWidget { @@ -90,9 +90,6 @@ protected: void resizeEvent(QGraphicsSceneResizeEvent *event); void hideEvent(QHideEvent *event); void showEvent(QShowEvent *event); - void mousePressEvent(QGraphicsSceneMouseEvent* event); - void mouseMoveEvent(QGraphicsSceneMouseEvent* event); - void mouseReleaseEvent(QGraphicsSceneMouseEvent* event); public Q_SLOTS: // PIMPL ---> @@ -142,11 +139,41 @@ private: qreal m_height; bool m_visible; bool m_dirty; - Scroller* m_scroller; - friend class QChart; + friend class ScrolledQLegend; // <--- PIMPL }; +class ScrolledQLegend: public QLegend, public Scroller +{ + +public: + ScrolledQLegend(QChart *chart):QLegend(chart) + { + } + + void setOffset(const QPointF& point) + { + QLegend::setOffset(point); + } + QPointF offset() const + { + return QLegend::offset(); + } + + void mousePressEvent(QGraphicsSceneMouseEvent* event){ + Scroller::mousePressEvent(event); + //QLegend::mousePressEvent(event); + } + void mouseMoveEvent(QGraphicsSceneMouseEvent* event){ + Scroller::mouseMoveEvent(event); + //QLegend::mouseMoveEvent(event); + } + void mouseReleaseEvent(QGraphicsSceneMouseEvent* event){ + Scroller::mouseReleaseEvent(event); + //QLegend::mouseReleaseEvent(event); + } +}; + QTCOMMERCIALCHART_END_NAMESPACE #endif // QLEGEND_H diff --git a/src/scroller.cpp b/src/scroller.cpp index 2b8e04a..dce7817 100644 --- a/src/scroller.cpp +++ b/src/scroller.cpp @@ -24,12 +24,11 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE -Scroller::Scroller(QLegend* legend): +Scroller::Scroller(): m_ticker(this), m_state(Idle), m_moveThreshold(10), -m_timeTreshold(50), -m_legend(legend) +m_timeTreshold(50) { } @@ -220,16 +219,6 @@ void Scroller::calculateSpeed(const QPointF& position) } } -void Scroller::setOffset(const QPointF& point) -{ - m_legend->setOffset(point); -} - -QPointF Scroller::offset() const -{ - return m_legend->offset(); -} - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ScrollTicker::ScrollTicker(Scroller *scroller,QObject* parent):QObject(parent), diff --git a/src/scroller_p.h b/src/scroller_p.h index 8700127..0cac15a 100644 --- a/src/scroller_p.h +++ b/src/scroller_p.h @@ -67,11 +67,11 @@ public: Stop }; - explicit Scroller(QLegend* legend); + Scroller(); virtual ~Scroller(); - virtual void setOffset(const QPointF& point); - virtual QPointF offset() const; + virtual void setOffset(const QPointF& point) = 0; + virtual QPointF offset() const = 0; public: void scrollTick(); @@ -97,7 +97,6 @@ private: QPointF m_fraction; int m_moveThreshold; int m_timeTreshold; - QLegend* m_legend; };