1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 07:49:42 +01:00

readded the editorEvent which somehow got lost in the previous merge and cleaned up a bit

This commit is contained in:
Michael Zanetti 2011-08-20 21:30:55 +02:00
parent 42508b7917
commit a14db5e7f2
5 changed files with 30 additions and 14 deletions

View File

@ -28,7 +28,6 @@ SourceTreeItem::SourceTreeItem( SourcesModel* model, SourceTreeItem* parent, Sou
, m_type( thisType )
, m_parent( parent )
, m_model( model )
//, m_dropHovering( false )
{
connect( this, SIGNAL( beginChildRowsAdded( int,int ) ), m_model, SLOT( onItemRowsAddedBegin( int,int ) ) );
connect( this, SIGNAL( beginChildRowsRemoved( int,int ) ), m_model, SLOT( onItemRowsRemovedBegin( int,int ) ) );

View File

@ -66,8 +66,6 @@ public:
virtual bool setData( const QVariant&, bool ) { return false; }
virtual int peerSortValue() const { return 0; } // How to sort relative to peers in the tree.
virtual int IDValue() const { return 0; }
// virtual bool dropHovering() const { return m_dropHovering; }
// virtual void setDropHovering( bool dropHovering ) { m_dropHovering = dropHovering; emit updated(); }
virtual DropTypes supportedDropTypes() const { return DropTypesNone; }
virtual void setDropType( DropType type ) { m_dropType = type; }

View File

@ -5,9 +5,11 @@
#include "items/playlistitems.h"
#include "utils/tomahawkutils.h"
#include "items/temporarypageitem.h"
#include <QApplication>
#include <QPainter>
#include <QMouseEvent>
#define TREEVIEW_INDENT_ADD -7
@ -291,6 +293,32 @@ SourceDelegate::updateEditorGeometry( QWidget* editor, const QStyleOptionViewIte
editor->setGeometry( editor->geometry().adjusted( 2*TREEVIEW_INDENT_ADD, 0, 0, 0 ) );
}
bool
SourceDelegate::editorEvent ( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index )
{
if ( event->type() == QEvent::MouseButtonRelease )
{
SourcesModel::RowType type = static_cast< SourcesModel::RowType >( index.data( SourcesModel::SourceTreeItemTypeRole ).toInt() );
if ( type == SourcesModel::TemporaryPage )
{
TemporaryPageItem* gpi = qobject_cast< TemporaryPageItem* >( index.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >() );
Q_ASSERT( gpi );
QMouseEvent* ev = static_cast< QMouseEvent* >( event );
QStyleOptionViewItemV4 o = option;
initStyleOption( &o, index );
int padding = 3;
QRect r ( o.rect.right() - padding - m_iconHeight, padding + o.rect.y(), m_iconHeight, m_iconHeight );
if ( r.contains( ev->pos() ) )
gpi->removeFromList();
}
}
return QStyledItemDelegate::editorEvent ( event, model, option, index );
}
int
SourceDelegate::dropTypeCount( SourceTreeItem* item ) const
{

View File

@ -20,9 +20,11 @@ protected:
virtual void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
virtual void updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
virtual int dropTypeCount( SourceTreeItem* item ) const;
virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
private:
QAbstractItemView* m_parent;
mutable int m_iconHeight;
QModelIndex m_dropHoverIndex;
mutable SourceTreeItem::DropType m_hoveredDropType; // Hack to keep easily track of the current highlighted DropType in paint()
};

View File

@ -439,11 +439,6 @@ SourceTreeView::dragLeaveEvent( QDragLeaveEvent* event )
m_dragging = false;
setDirtyRegion( m_dropRect );
// SourceTreeItem* oldItem = m_dropIndex.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >();
// if ( oldItem )
// {
// oldItem->setDropHovering( false );
// }
m_delegate->setDropHoverIndex( QModelIndex() );
dataChanged(m_dropIndex, m_dropIndex);
m_dropIndex = QPersistentModelIndex();
@ -461,11 +456,6 @@ SourceTreeView::dragMoveEvent( QDragMoveEvent* event )
setDirtyRegion( m_dropRect );
const QPoint pos = event->pos();
const QModelIndex index = indexAt( pos );
// SourceTreeItem* oldItem = m_dropIndex.data( SourcesModel::SourceTreeItemRole ).value< SourceTreeItem* >();
// if ( oldItem )
// {
// oldItem->setDropHovering( false );
// }
m_delegate->setDropHoverIndex( QModelIndex() );
dataChanged(m_dropIndex, m_dropIndex);
m_dropIndex = QPersistentModelIndex( index );
@ -479,7 +469,6 @@ SourceTreeView::dragMoveEvent( QDragMoveEvent* event )
if( item->willAcceptDrag( event->mimeData() ) )
{
accept = true;
// item->setDropHovering( true );
m_delegate->setDropHoverIndex( index );
dataChanged(index, index);
}