[vlc-devel] commit: Qt: delete QVLCTreeView class and use event filters for the 2 different views. (Jean-Baptiste Kempf )

git version control git at videolan.org
Wed Dec 16 11:27:15 CET 2009


vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Wed Dec 16 11:25:19 2009 +0100| [c24f5b99ca237526dc742734ad9e6e11a4c28cfa] | committer: Jean-Baptiste Kempf 

Qt: delete QVLCTreeView class and use event filters for the 2 different views.

Some stuff are still broken in the IconView.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c24f5b99ca237526dc742734ad9e6e11a4c28cfa
---

 .../gui/qt4/components/playlist/standardpanel.cpp  |   44 +++++++++++++++++-
 .../gui/qt4/components/playlist/standardpanel.hpp  |    4 +-
 modules/gui/qt4/components/preferences_widgets.cpp |    1 +
 modules/gui/qt4/util/customwidgets.hpp             |   46 +-------------------
 4 files changed, 46 insertions(+), 49 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp
index 9561814..53da40d 100644
--- a/modules/gui/qt4/components/playlist/standardpanel.cpp
+++ b/modules/gui/qt4/components/playlist/standardpanel.cpp
@@ -60,7 +60,7 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
     model = new PLModel( p_playlist, p_intf, p_root, this );
 
     /* Create and configure the QTreeView */
-    view = new QVLCTreeView;
+    view = new QTreeView;
     view->setModel( model );
     view2 = NULL;
 
@@ -80,6 +80,7 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
     view->setAcceptDrops( true );
     view->setDropIndicatorShown( true );
 
+    installEventFilter( view );
     /* Saved Settings */
     getSettings()->beginGroup("Playlist");
     if( getSettings()->contains( "headerStateV2" ) )
@@ -101,8 +102,6 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
     /* Connections for the TreeView */
     CONNECT( view, activated( const QModelIndex& ) ,
              model,activateItem( const QModelIndex& ) );
-    CONNECT( view, rightClicked( QModelIndex , QPoint ),
-             this, doPopup( QModelIndex, QPoint ) );
     CONNECT( view->header(), customContextMenuRequested( const QPoint & ),
              this, popupSelectColumn( QPoint ) );
     CONNECT( model, currentChanged( const QModelIndex& ),
@@ -304,6 +303,7 @@ void StandardPLPanel::toggleView()
             view2->setViewMode( QListView::IconMode );
             view2->setMovement( QListView::Snap );
             layout->addWidget( view2, 1, 0, 1, -1 );
+            installEventFilter( view2 );
         }
         view->hide();
         view2->show();
@@ -313,6 +313,44 @@ void StandardPLPanel::toggleView()
         view2->hide();
         view->show();
     }
+}
 
+bool StandardPLPanel::eventFilter( QObject *obj, QEvent *event )
+{
+    QAbstractItemView *view = qobject_cast<QAbstractItemView *>(obj);
+    if( !view ) return false;
 
+    switch( event->type() )
+    {
+        case QEvent::MouseButtonPress:
+            {
+                QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
+                if( mouseEvent->button() & Qt::RightButton )
+                {
+                    QModelIndex index = view->indexAt(
+                            QPoint( mouseEvent->x(), mouseEvent->y() ) );
+                    doPopup( index, QCursor::pos() );
+                    return true;
+                }
+                else if( mouseEvent->button() & Qt::LeftButton )
+                {
+                    if( !view->indexAt( QPoint( mouseEvent->x(),
+                                                mouseEvent->y() ) ).isValid() )
+                        view->clearSelection();
+                }
+                // view->mousePressEvent( mouseEvent );
+            }
+            return true;
+        case QEvent::MouseButtonRelease:
+            {
+                QMouseEvent *mouseEvent2 = static_cast<QMouseEvent *>(event);
+                if( mouseEvent2->button() & Qt::RightButton )
+                    return false; /* Do NOT forward to QTreeView!! */
+                // view->mouseReleaseEvent( mouseEvent );
+                return true;
+            }
+        default:
+            return false;
+    }
+    return true;
 }
diff --git a/modules/gui/qt4/components/playlist/standardpanel.hpp b/modules/gui/qt4/components/playlist/standardpanel.hpp
index 91540d5..b350af7 100644
--- a/modules/gui/qt4/components/playlist/standardpanel.hpp
+++ b/modules/gui/qt4/components/playlist/standardpanel.hpp
@@ -57,6 +57,8 @@ protected:
 
     virtual void keyPressEvent( QKeyEvent *e );
 
+    bool eventFilter(QObject *obj, QEvent *event);
+
     PLModel *model;
 private:
     intf_thread_t *p_intf;
@@ -72,6 +74,7 @@ private:
     int currentRootId;
     QSignalMapper *selectColumnsSigMapper;
 
+    void doPopup( QModelIndex index, QPoint point );
 public slots:
     void removeItem( int );
     virtual void setRoot( playlist_item_t * );
@@ -79,7 +82,6 @@ private slots:
     void deleteSelection();
     void handleExpansion( const QModelIndex& );
     void gotoPlayingItem();
-    void doPopup( QModelIndex index, QPoint point );
     void search( const QString& searchText );
     void popupAdd();
     void popupSelectColumn( QPoint );
diff --git a/modules/gui/qt4/components/preferences_widgets.cpp b/modules/gui/qt4/components/preferences_widgets.cpp
index 4c36ce5..24712fe 100644
--- a/modules/gui/qt4/components/preferences_widgets.cpp
+++ b/modules/gui/qt4/components/preferences_widgets.cpp
@@ -48,6 +48,7 @@
 #include <QTreeWidgetItem>
 #include <QSignalMapper>
 #include <QDialogButtonBox>
+#include <QKeyEvent>
 
 #define MINWIDTH_BOX 90
 #define LAST_COLUMN 10
diff --git a/modules/gui/qt4/util/customwidgets.hpp b/modules/gui/qt4/util/customwidgets.hpp
index 690e1f2..132c5fc 100644
--- a/modules/gui/qt4/util/customwidgets.hpp
+++ b/modules/gui/qt4/util/customwidgets.hpp
@@ -95,55 +95,11 @@ private:
     QIcon::Mode iconMode;
 };
 
-/*****************************************************************
- * Custom views
- *****************************************************************/
-#include <QMouseEvent>
-#include <QTreeView>
-#include <QCursor>
-#include <QPoint>
-#include <QModelIndex>
-
-/**
-  Special QTreeView that can emit rightClicked()
-  */
-class QVLCTreeView : public QTreeView
-{
-    Q_OBJECT;
-public:
-    void mouseReleaseEvent( QMouseEvent* e )
-    {
-        if( e->button() & Qt::RightButton )
-            return; /* Do NOT forward to QTreeView!! */
-        QTreeView::mouseReleaseEvent( e );
-    }
-
-    void mousePressEvent( QMouseEvent* e )
-    {
-        if( e->button() & Qt::RightButton )
-        {
-            QModelIndex index = indexAt( QPoint( e->x(), e->y() ) );
-            if( index.isValid() )
-                setSelection( visualRect( index ), QItemSelectionModel::ClearAndSelect );
-            emit rightClicked( index, QCursor::pos() );
-            return;
-        }
-        if( e->button() & Qt::LeftButton )
-        {
-            if( !indexAt( QPoint( e->x(), e->y() ) ).isValid() )
-                clearSelection();
-        }
-        QTreeView::mousePressEvent( e );
-    }
-
-signals:
-    void rightClicked( QModelIndex, QPoint  );
-};
-
 /* VLC Key/Wheel hotkeys interactions */
 
 class QKeyEvent;
 class QWheelEvent;
+class QInputEvent;
 
 int qtKeyModifiersToVLC( QInputEvent* e );
 int qtEventToVLCKey( QKeyEvent *e );




More information about the vlc-devel mailing list