Commit c24f5b99 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

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

Some stuff are still broken in the IconView.
parent 69d72d72
......@@ -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;
}
......@@ -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 );
......
......@@ -48,6 +48,7 @@
#include <QTreeWidgetItem>
#include <QSignalMapper>
#include <QDialogButtonBox>
#include <QKeyEvent>
#define MINWIDTH_BOX 90
#define LAST_COLUMN 10
......
......@@ -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 );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment