18 #include <QApplication>
19 #include <QMainWindow>
20 #include <QMouseEvent>
24 #include <QGridLayout>
43 : QGraphicsView( parent )
44 , mRubberBandItem( 0 )
45 , mRubberBandLineItem( 0 )
46 , mMoveContentItem( 0 )
47 , mPaintingEnabled( true )
48 , mHorizontalRuler( 0 )
54 setResizeAnchor( QGraphicsView::AnchorViewCenter );
55 setMouseTracking(
true );
56 viewport()->setMouseTracking(
true );
57 setFrameShape( QFrame::NoFrame );
67 QPointF scenePoint = mapToScene( e->pos() );
71 if ( e->button() == Qt::RightButton )
78 selectedItem->update();
80 QPointF itemPoint = selectedItem->mapFromScene( scenePoint );
91 if ( !( e->modifiers() & Qt::ShiftModifier ) )
124 mRubberBandLineItem =
new QGraphicsLineItem( snappedScenePoint.x(), snappedScenePoint.y(), snappedScenePoint.x(), snappedScenePoint.y() );
125 mRubberBandLineItem->setZValue( 100 );
126 scene()->addItem( mRubberBandLineItem );
141 t.translate( snappedScenePoint.x(), snappedScenePoint.y() );
155 newLabelItem->
setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), newLabelItem->rect().width(), newLabelItem->rect().height() ) );
166 newScaleBar->
setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 20, 20 ) );
169 if ( mapItemList.size() > 0 )
184 newLegend->
setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), newLegend->rect().width(), newLegend->rect().height() ) );
196 newPicture->
setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 30, 30 ) );
206 newTable->
setSceneRect( QRectF( snappedScenePoint.x(), snappedScenePoint.y(), 50, 50 ) );
265 QPointF scenePoint = mapToScene( e->pos() );
299 QPointF scenePoint = mapToScene( e->pos() );
380 if ( e->buttons() == Qt::NoButton )
389 QPointF scenePoint = mapToScene( e->pos() );
460 composerMap->update();
485 QList<QgsComposerItem*>::iterator itemIt = composerItemList.begin();
487 if ( e->matches( QKeySequence::Copy ) || e->matches( QKeySequence::Cut ) )
490 QDomElement documentElement = doc.createElement(
"ComposerItemClipboard" );
491 for ( ; itemIt != composerItemList.end(); ++itemIt )
497 QSet<QgsComposerItem*> groupedItems = itemGroup->
items();
498 QSet<QgsComposerItem*>::iterator it = groupedItems.begin();
499 for ( ; it != groupedItems.end(); ++it )
501 ( *it )->writeXML( documentElement, doc );
504 ( *itemIt )->writeXML( documentElement, doc );
505 if ( e->matches( QKeySequence::Cut ) )
510 doc.appendChild( documentElement );
513 if ( e->matches( QKeySequence::Copy ) )
516 QDomNodeList composerItemsNodes = doc.elementsByTagName(
"ComposerItem" );
517 for (
int i = 0; i < composerItemsNodes.count(); ++i )
519 QDomNode composerItemNode = composerItemsNodes.at( i );
520 if ( composerItemNode.isElement() )
522 composerItemNode.toElement().removeAttribute(
"uuid" );
527 QMimeData *mimeData =
new QMimeData;
528 mimeData->setData(
"text/xml", doc.toByteArray() );
529 QClipboard *clipboard = QApplication::clipboard();
530 clipboard->setMimeData( mimeData );
534 if ( e->matches( QKeySequence::Paste ) || ( e->key() == Qt::Key_V && e->modifiers() & Qt::ControlModifier && e->modifiers() & Qt::ShiftModifier ) )
537 QClipboard *clipboard = QApplication::clipboard();
538 if ( doc.setContent( clipboard->mimeData()->data(
"text/xml" ) ) )
540 QDomElement docElem = doc.documentElement();
541 if ( docElem.tagName() ==
"ComposerItemClipboard" )
545 QPointF pt = mapToScene( mapFromGlobal( QCursor::pos() ) );
546 bool pasteInPlace = ( e->modifiers() & Qt::ShiftModifier );
554 if ( e->key() == Qt::Key_Delete || e->key() == Qt::Key_Backspace )
556 for ( ; itemIt != composerItemList.end(); ++itemIt )
565 else if ( e->key() == Qt::Key_Left )
567 for ( ; itemIt != composerItemList.end(); ++itemIt )
570 ( *itemIt )->move( -1.0, 0.0 );
571 ( *itemIt )->endCommand();
574 else if ( e->key() == Qt::Key_Right )
576 for ( ; itemIt != composerItemList.end(); ++itemIt )
579 ( *itemIt )->move( 1.0, 0.0 );
580 ( *itemIt )->endCommand();
583 else if ( e->key() == Qt::Key_Down )
585 for ( ; itemIt != composerItemList.end(); ++itemIt )
588 ( *itemIt )->move( 0.0, 1.0 );
589 ( *itemIt )->endCommand();
592 else if ( e->key() == Qt::Key_Up )
594 for ( ; itemIt != composerItemList.end(); ++itemIt )
597 ( *itemIt )->move( 0.0, -1.0 );
598 ( *itemIt )->endCommand();
605 QPointF scenePoint = mapToScene( event->pos() );
611 if ( theItem->isSelected() )
613 QPointF itemPoint = theItem->mapFromScene( scenePoint );
615 theItem->zoomContent( event->delta(), itemPoint.x(), itemPoint.y() );
616 theItem->endCommand();
692 if ( selectionList.size() < 2 )
698 QList<QgsComposerItem*>::iterator itemIter = selectionList.begin();
699 for ( ; itemIter != selectionList.end(); ++itemIter )
701 itemGroup->
addItem( *itemIter );
717 QList<QgsComposerItem*>::iterator itemIter = selectionList.begin();
718 for ( ; itemIter != selectionList.end(); ++itemIter )
733 QMainWindow* composerObject = 0;
734 QObject* currentObject = parent();
735 if ( !currentObject )
737 return qobject_cast<QMainWindow *>( currentObject );
742 composerObject = qobject_cast<QMainWindow*>( currentObject );
743 if ( composerObject || currentObject->parent() == 0 )
745 return composerObject;
747 currentObject = currentObject->parent();