[vlmc-devel] commit: GraphicsEffectItem: Handle contextual menu ( Hugo Beauzée-Luyssen )

git at videolan.org git at videolan.org
Fri Sep 17 00:38:53 CEST 2010


vlmc | branch: master | Hugo Beauzée-Luyssen <beauze.h at gmail.com> | Thu Sep 16 23:30:28 2010 +0200| [07fe5c3952163e8d46bd99d144ffe05b456fdad4] | committer: Hugo Beauzée-Luyssen 

GraphicsEffectItem: Handle contextual menu

> http://git.videolan.org/gitweb.cgi/vlmc.git/?a=commit;h=07fe5c3952163e8d46bd99d144ffe05b456fdad4
---

 src/Gui/timeline/GraphicsEffectItem.cpp |   34 +++++++++++++++++++++++++++++-
 src/Gui/timeline/GraphicsEffectItem.h   |    1 +
 2 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/src/Gui/timeline/GraphicsEffectItem.cpp b/src/Gui/timeline/GraphicsEffectItem.cpp
index fa5ddaa..5de680b 100644
--- a/src/Gui/timeline/GraphicsEffectItem.cpp
+++ b/src/Gui/timeline/GraphicsEffectItem.cpp
@@ -28,9 +28,13 @@
 #include "EffectInstance.h"
 #include "GraphicsTrack.h"
 #include "Timeline.h"
+#include "TracksScene.h"
 #include "TracksView.h"
 #include "TrackWorkflow.h"
 
+#include <QColorDialog>
+#include <QGraphicsSceneContextMenuEvent>
+#include <QMenu>
 #include <QPainter>
 
 #include <QtDebug>
@@ -44,6 +48,7 @@ GraphicsEffectItem::GraphicsEffectItem( Effect *effect ) :
     m_effectHelper = new EffectHelper( effect->createInstance() );
     connect( m_effectHelper, SIGNAL( lengthUpdated() ), this, SLOT( adjustLength() ) );
     setWidth( m_effectHelper->length() );
+    m_itemColor = Qt::blue;
 }
 
 GraphicsEffectItem::GraphicsEffectItem( EffectHelper *helper ) :
@@ -54,6 +59,7 @@ GraphicsEffectItem::GraphicsEffectItem( EffectHelper *helper ) :
     m_effect = helper->effectInstance()->effect();
     connect( helper, SIGNAL( lengthUpdated() ), this, SLOT( adjustLength() ) );
     setOpacity( 0.8 );
+    m_itemColor = Qt::blue;
 }
 
 const QUuid&
@@ -135,8 +141,8 @@ GraphicsEffectItem::paintRect( QPainter* painter, const QStyleOptionGraphicsItem
 
     QLinearGradient gradient( mapped.topLeft(), mapped.bottomLeft() );
 
-    gradient.setColorAt( 0, Qt::darkBlue );
-    gradient.setColorAt( 1, Qt::blue );
+    gradient.setColorAt( 0, m_itemColor );
+    gradient.setColorAt( 1, m_itemColor.darker() );
 
     painter->setPen( Qt::NoPen );
     painter->setBrush( QBrush( gradient ) );
@@ -296,3 +302,27 @@ GraphicsEffectItem::setContainer( AbstractGraphicsMediaItem *item )
         connect( item, SIGNAL( moved( qint64 ) ), this, SLOT( containerMoved( qint64 ) ) );
     }
 }
+
+void
+GraphicsEffectItem::contextMenuEvent( QGraphicsSceneContextMenuEvent *event )
+{
+    if ( !tracksView() )
+        return;
+
+    QMenu menu( tracksView() );
+
+    QAction* removeAction = menu.addAction( "Remove" );
+    QAction* changeColorAction = menu.addAction( "Set color" );
+
+    QAction* selectedAction = menu.exec( event->screenPos() );
+    if ( !selectedAction )
+        return;
+
+    if ( selectedAction == removeAction )
+        scene()->askRemoveSelectedItems();
+    else if ( selectedAction == changeColorAction )
+    {
+        m_itemColor = QColorDialog::getColor( m_itemColor, tracksView() );
+        update();
+    }
+}
diff --git a/src/Gui/timeline/GraphicsEffectItem.h b/src/Gui/timeline/GraphicsEffectItem.h
index 62bba4f..b6ddaa4 100644
--- a/src/Gui/timeline/GraphicsEffectItem.h
+++ b/src/Gui/timeline/GraphicsEffectItem.h
@@ -62,6 +62,7 @@ class GraphicsEffectItem : public AbstractGraphicsItem
         void                        setContainer( AbstractGraphicsMediaItem *item );
     protected:
         virtual bool                hasResizeBoundaries() const;
+        virtual void                contextMenuEvent( QGraphicsSceneContextMenuEvent *event );
         /**
          * \brief Paint the item's rectangle.
          * \param painter Pointer to a QPainter.



More information about the Vlmc-devel mailing list