24 #include "KDChartAbstractCoordinatePlane_p.h"
29 #include <KDABLibFakes>
31 #include <QGridLayout>
32 #include <QRubberBand>
33 #include <QMouseEvent>
34 #include <QtCore/qmath.h>
36 using namespace KDChart;
40 AbstractCoordinatePlane::Private::Private()
44 , referenceCoordinatePlane( 0 )
45 , enableCornerSpacers( true )
46 , enableRubberBandZooming( false )
65 void AbstractCoordinatePlane::init()
70 Qt::QueuedConnection );
78 d->diagrams.append( diagram );
79 diagram->setParent(
d->parent );
83 connect( diagram, SIGNAL( modelsChanged() ),
this, SLOT(
layoutPlanes() ) );
84 connect( diagram, SIGNAL( modelDataChanged() ),
this, SLOT(
update()) );
85 connect( diagram, SIGNAL( modelDataChanged() ),
this, SLOT(
relayout()) );
95 if ( diagram && oldDiagram_ != diagram ) {
97 if (
d->diagrams.count() ) {
99 oldDiagram =
d->diagrams.first();
100 if ( oldDiagram == diagram )
116 const int idx =
d->diagrams.indexOf( diagram );
118 d->diagrams.removeAt( idx );
119 diagram->setParent( 0 );
121 disconnect( diagram, SIGNAL( modelsChanged() ),
this, SLOT(
layoutPlanes() ) );
122 disconnect( diagram, SIGNAL( modelDataChanged() ),
this, SLOT(
update()) );
123 disconnect( diagram, SIGNAL( modelDataChanged() ),
this, SLOT(
relayout()) );
132 if (
d->diagrams.isEmpty() )
136 return d->diagrams.first();
149 qCopy(
d->diagrams.begin(),
d->diagrams.end(), std::back_inserter( list ) );
159 d->gridAttributes = a;
165 return d->gridAttributes;
170 return d->grid->updateData(
this );
175 d->grid->setNeedRecalculate();
180 d->referenceCoordinatePlane = plane;
185 return d->referenceCoordinatePlane;
213 return Qt::Vertical | Qt::Horizontal;
220 return QSize(QLAYOUTSIZE_MAX, QLAYOUTSIZE_MAX);
225 return QSize(60, 60);
232 return maximumSize();
237 if (
d->geometry != r ) {
240 emit internal_geometryChanged(
d->geometry, r );
268 emit needLayoutPlanes();
273 d->enableRubberBandZooming = enable;
275 if ( !enable &&
d->rubberBand != 0 )
277 delete d->rubberBand;
284 return d->enableRubberBandZooming;
289 if (
d->enableCornerSpacers == enable )
return;
291 d->enableCornerSpacers = enable;
297 return d->enableCornerSpacers;
302 if ( event->button() == Qt::LeftButton )
304 if (
d->enableRubberBandZooming &&
d->rubberBand == 0 )
305 d->rubberBand =
new QRubberBand( QRubberBand::Rectangle, qobject_cast< QWidget* >( parent() ) );
307 if (
d->rubberBand != 0 )
309 d->rubberBandOrigin =
event->pos();
310 d->rubberBand->setGeometry( QRect( event->pos(), QSize() ) );
311 d->rubberBand->show();
316 else if ( event->button() == Qt::RightButton )
318 if (
d->enableRubberBandZooming && !
d->rubberBandZoomConfigHistory.isEmpty() )
322 setZoomFactorX( config.
xFactor );
323 setZoomFactorY( config.
yFactor );
324 setZoomCenter( config.
center() );
336 a->mousePressEvent( event );
342 if ( event->button() == Qt::RightButton )
346 mousePressEvent( event );
350 a->mouseDoubleClickEvent( event );
356 if (
d->rubberBand != 0 )
359 d->rubberBandZoomConfigHistory.push(
ZoomParameters( zoomFactorX(), zoomFactorY(), zoomCenter() ) );
362 const qreal rubberWidth =
static_cast< qreal
>(
d->rubberBand->width() );
363 const qreal rubberHeight =
static_cast< qreal
>(
d->rubberBand->height() );
365 if ( rubberWidth > 0.0 && rubberHeight > 0.0 )
368 const qreal centerX = qFloor(
d->rubberBand->geometry().width() / 2.0 +
d->rubberBand->geometry().x() );
369 const qreal centerY = qCeil(
d->rubberBand->geometry().height() / 2.0 +
d->rubberBand->geometry().y() );
371 const qreal rubberCenterX =
static_cast< qreal
>( centerX - geometry().x() );
372 const qreal rubberCenterY =
static_cast< qreal
>( centerY - geometry().y() );
375 const qreal myWidth =
static_cast< qreal
>( geometry().width() );
376 const qreal myHeight =
static_cast< qreal
>( geometry().height() );
379 const qreal newCenterX = rubberCenterX / myWidth / zoomFactorX() + zoomCenter().x() - 0.5 / zoomFactorX();
380 const qreal newCenterY = rubberCenterY / myHeight / zoomFactorY() + zoomCenter().y() - 0.5 / zoomFactorY();
383 const qreal newZoomFactorX = zoomFactorX() * myWidth / rubberWidth;
384 const qreal newZoomFactorY = zoomFactorY() * myHeight / rubberHeight;
387 const QPointF newZoomCenter( newCenterX, newCenterY );
389 setZoomFactorX( newZoomFactorX );
390 setZoomFactorY( newZoomFactorY );
391 setZoomCenter( newZoomCenter );
394 d->rubberBand->parentWidget()->update();
395 delete d->rubberBand;
403 a->mouseReleaseEvent( event );
409 if (
d->rubberBand != 0 )
411 const QRect normalized = QRect(
d->rubberBandOrigin, event->pos() ).normalized();
412 d->rubberBand->setGeometry( normalized & geometry() );
419 a->mouseMoveEvent( event );
423 #if QT_VERSION < 0x040400 || defined(Q_COMPILER_MANGLES_RETURN_TYPE)
428 return d->isVisiblePoint(
this, point );
437 #if !defined(QT_NO_DEBUG_STREAM)
442 stream <<
"DataDimension("
443 <<
" start=" << r.
start