]> git.sesse.net Git - vlc/commitdiff
Qt: delete QVLCTreeView class and use event filters for the 2 different views.
authorJean-Baptiste Kempf <jb@videolan.org>
Wed, 16 Dec 2009 10:25:19 +0000 (11:25 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Wed, 16 Dec 2009 10:25:19 +0000 (11:25 +0100)
Some stuff are still broken in the IconView.

modules/gui/qt4/components/playlist/standardpanel.cpp
modules/gui/qt4/components/playlist/standardpanel.hpp
modules/gui/qt4/components/preferences_widgets.cpp
modules/gui/qt4/util/customwidgets.hpp

index 9561814dd46f00b0a914f513668d662654745cb3..53da40d95ac8754c81c172d4999baded963b7df4 100644 (file)
@@ -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;
 }
index 91540d5ff5ea124a91a9b9f7ad88e46be3b019bb..b350af7a9bd95aadf40794daa3ae90043d113915 100644 (file)
@@ -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 );
index 4c36ce5db6b974cf7c7f2d056ccc82ff774a89e8..24712fe46e83c78ece9379df6a8ad4192cfc25e5 100644 (file)
@@ -48,6 +48,7 @@
 #include <QTreeWidgetItem>
 #include <QSignalMapper>
 #include <QDialogButtonBox>
+#include <QKeyEvent>
 
 #define MINWIDTH_BOX 90
 #define LAST_COLUMN 10
index 690e1f2edebb4fb607d0fecba29f5141e511632b..132c5fc30b45c4c4d9291e77c9cc23d84b22724a 100644 (file)
@@ -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 );