18 #include <QMainWindow>
19 #include <QMouseEvent>
34 QGraphicsView( parent ), mShiftKeyPressed( false ), mRubberBandItem( 0 ), mRubberBandLineItem( 0 ), mMoveContentItem( 0 ), mPaintingEnabled( true )
36 setResizeAnchor( QGraphicsView::AnchorViewCenter );
37 setMouseTracking(
true );
38 viewport()->setMouseTracking(
true );
48 QPointF scenePoint = mapToScene( e->pos() );
52 if ( e->button() == Qt::RightButton )
59 selectedItem->update();
61 QPointF itemPoint = selectedItem->mapFromScene( scenePoint );
85 QGraphicsView::mousePressEvent( e );
105 mRubberBandLineItem =
new QGraphicsLineItem( snappedScenePoint.x(), snappedScenePoint.y(), snappedScenePoint.x(), snappedScenePoint.y() );
106 mRubberBandLineItem->setZValue( 100 );
107 scene()->addItem( mRubberBandLineItem );
119 t.translate( snappedScenePoint.x(), snappedScenePoint.y() );
130 newLabelItem->
setText( tr(
"Quantum GIS" ) );
132 newLabelItem->
setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), newLabelItem->rect().width(), newLabelItem->rect().height() ) );
141 newScaleBar->
setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 20, 20 ) );
150 newLegend->
setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), newLegend->rect().width(), newLegend->rect().height() ) );
158 newPicture->
setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 30, 30 ) );
166 newTable->
setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 50, 50 ) );
184 QPointF scenePoint = mapToScene( e->pos() );
190 QGraphicsView::mouseReleaseEvent( e );
217 QPointF scenePoint = mapToScene( e->pos() );
281 if ( e->buttons() == Qt::NoButton )
285 QGraphicsView::mouseMoveEvent( e );
290 QPointF scenePoint = mapToScene( e->pos() );
295 QGraphicsView::mouseMoveEvent( e );
358 composerMap->update();
375 if ( e->key() == Qt::Key_Shift )
386 QList<QgsComposerItem*>::iterator itemIt = composerItemList.begin();
389 if ( e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace )
391 for ( ; itemIt != composerItemList.end(); ++itemIt )
401 QUndoCommand* parentCommand =
new QUndoCommand( tr(
"Remove item group" ) );
403 QSet<QgsComposerItem*> groupedItems = itemGroup->
items();
404 QSet<QgsComposerItem*>::iterator it = groupedItems.begin();
405 for ( ; it != groupedItems.end(); ++it )
425 else if ( e->key() == Qt::Key_Left )
427 for ( ; itemIt != composerItemList.end(); ++itemIt )
429 ( *itemIt )->move( -1.0, 0.0 );
432 else if ( e->key() == Qt::Key_Right )
434 for ( ; itemIt != composerItemList.end(); ++itemIt )
436 ( *itemIt )->move( 1.0, 0.0 );
439 else if ( e->key() == Qt::Key_Down )
441 for ( ; itemIt != composerItemList.end(); ++itemIt )
443 ( *itemIt )->move( 0.0, 1.0 );
446 else if ( e->key() == Qt::Key_Up )
448 for ( ; itemIt != composerItemList.end(); ++itemIt )
450 ( *itemIt )->move( 0.0, -1.0 );
457 if ( e->key() == Qt::Key_Shift )
465 QPointF scenePoint = mapToScene( event->pos() );
471 if ( theItem->isSelected() )
473 QPointF itemPoint = theItem->mapFromScene( scenePoint );
475 theItem->zoomContent( event->delta(), itemPoint.x(), itemPoint.y() );
476 theItem->endCommand();
485 QGraphicsView::paintEvent( event );
516 scene()->clearSelection();
526 scene()->clearSelection();
534 scene()->addItem( map );
539 scene()->clearSelection();
549 if ( mapItemList.size() > 0 )
554 scene()->addItem( scaleBar );
556 scene()->clearSelection();
566 if ( mapItemList.size() > 0 )
570 scene()->addItem( legend );
572 scene()->clearSelection();
580 scene()->addItem( picture );
582 scene()->clearSelection();
590 scene()->addItem( shape );
592 scene()->clearSelection();
600 scene()->addItem( table );
602 scene()->clearSelection();
616 if ( selectionList.size() < 2 )
622 QList<QgsComposerItem*>::iterator itemIter = selectionList.begin();
623 for ( ; itemIter != selectionList.end(); ++itemIter )
625 itemGroup->
addItem( *itemIter );
641 QList<QgsComposerItem*>::iterator itemIter = selectionList.begin();
642 for ( ; itemIter != selectionList.end(); ++itemIter )
719 QMainWindow* composerObject = 0;
720 QObject* currentObject = parent();
721 if ( !currentObject )
723 return qobject_cast<QMainWindow *>( currentObject );
728 composerObject = qobject_cast<QMainWindow*>( currentObject );
729 if ( composerObject || currentObject->parent() == 0 )
731 return composerObject;
733 currentObject = currentObject->parent();