mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-09 07:36:48 +02:00
* Keep indentation, but select entire rows in SourceTreeView.
This commit is contained in:
@@ -12,10 +12,31 @@
|
|||||||
#include <QDragEnterEvent>
|
#include <QDragEnterEvent>
|
||||||
#include <QHeaderView>
|
#include <QHeaderView>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
#include <QStyledItemDelegate>
|
||||||
|
|
||||||
using namespace Tomahawk;
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
|
||||||
|
class SourceDelegate : public QStyledItemDelegate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SourceDelegate( QAbstractItemView* parent = 0 ) : QStyledItemDelegate( parent ), m_parent( parent ) {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
|
void updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||||
|
{
|
||||||
|
if ( SourcesModel::indexType( index ) == 1 )
|
||||||
|
editor->setGeometry( option.rect.adjusted( 32, 0, 0, 0 ) );
|
||||||
|
else
|
||||||
|
QStyledItemDelegate::updateEditorGeometry( editor, option, index );
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QAbstractItemView* m_parent;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
SourceTreeView::SourceTreeView( QWidget* parent )
|
SourceTreeView::SourceTreeView( QWidget* parent )
|
||||||
: QTreeView( parent )
|
: QTreeView( parent )
|
||||||
, m_collectionModel( new CollectionModel( this ) )
|
, m_collectionModel( new CollectionModel( this ) )
|
||||||
@@ -31,6 +52,9 @@ SourceTreeView::SourceTreeView( QWidget* parent )
|
|||||||
setDropIndicatorShown( false );
|
setDropIndicatorShown( false );
|
||||||
setAllColumnsShowFocus( true );
|
setAllColumnsShowFocus( true );
|
||||||
setUniformRowHeights( false );
|
setUniformRowHeights( false );
|
||||||
|
setIndentation( 0 );
|
||||||
|
|
||||||
|
setItemDelegate( new SourceDelegate( this ) );
|
||||||
|
|
||||||
setContextMenuPolicy( Qt::CustomContextMenu );
|
setContextMenuPolicy( Qt::CustomContextMenu );
|
||||||
connect( this, SIGNAL( customContextMenuRequested( const QPoint& ) ), SLOT( onCustomContextMenu( const QPoint& ) ) );
|
connect( this, SIGNAL( customContextMenuRequested( const QPoint& ) ), SLOT( onCustomContextMenu( const QPoint& ) ) );
|
||||||
@@ -55,6 +79,7 @@ SourceTreeView::setupMenus()
|
|||||||
m_playlistMenu.clear();
|
m_playlistMenu.clear();
|
||||||
|
|
||||||
m_loadPlaylistAction = m_playlistMenu.addAction( tr( "&Load Playlist" ) );
|
m_loadPlaylistAction = m_playlistMenu.addAction( tr( "&Load Playlist" ) );
|
||||||
|
m_renamePlaylistAction = m_playlistMenu.addAction( tr( "&Rename Playlist" ) );
|
||||||
m_playlistMenu.addSeparator();
|
m_playlistMenu.addSeparator();
|
||||||
m_deletePlaylistAction = m_playlistMenu.addAction( tr( "&Delete Playlist" ) );
|
m_deletePlaylistAction = m_playlistMenu.addAction( tr( "&Delete Playlist" ) );
|
||||||
|
|
||||||
@@ -323,7 +348,31 @@ SourceTreeView::paintEvent( QPaintEvent* event )
|
|||||||
opt.rect = itemRect;
|
opt.rect = itemRect;
|
||||||
opt.state = QStyle::State_Enabled | QStyle::State_Selected;
|
opt.state = QStyle::State_Enabled | QStyle::State_Selected;
|
||||||
|
|
||||||
style()->drawPrimitive( QStyle::PE_PanelItemViewRow, &opt, &painter, this );
|
style()->drawPrimitive( QStyle::PE_PanelItemViewItem, &opt, &painter, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
QTreeView::paintEvent( event );
|
QTreeView::paintEvent( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SourceTreeView::drawRow( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||||
|
{
|
||||||
|
QTreeView::drawRow( painter, option, index );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
SourceDelegate::paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const
|
||||||
|
{
|
||||||
|
QStyleOptionViewItem o = option;
|
||||||
|
o.rect.adjust( 12, 0, 0, 0 );
|
||||||
|
|
||||||
|
if ( ( option.state & QStyle::State_Enabled ) == QStyle::State_Enabled )
|
||||||
|
{
|
||||||
|
o.state = QStyle::State_Enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStyledItemDelegate::paint( painter, option, QModelIndex() );
|
||||||
|
QStyledItemDelegate::paint( painter, o, index );
|
||||||
|
}
|
||||||
|
@@ -33,7 +33,7 @@ private slots:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void drawBranches( QPainter* painter, const QRect& rect, const QModelIndex& index ) const {}
|
void drawBranches( QPainter* painter, const QRect& rect, const QModelIndex& index ) const {}
|
||||||
void drawTree( QPainter* painter, const QRegion& region ) const {}
|
void drawRow( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
|
||||||
|
|
||||||
virtual void paintEvent( QPaintEvent* event );
|
virtual void paintEvent( QPaintEvent* event );
|
||||||
|
|
||||||
@@ -51,6 +51,7 @@ private:
|
|||||||
|
|
||||||
QMenu m_playlistMenu;
|
QMenu m_playlistMenu;
|
||||||
QAction* m_loadPlaylistAction;
|
QAction* m_loadPlaylistAction;
|
||||||
|
QAction* m_renamePlaylistAction;
|
||||||
QAction* m_deletePlaylistAction;
|
QAction* m_deletePlaylistAction;
|
||||||
|
|
||||||
bool m_dragging;
|
bool m_dragging;
|
||||||
|
Reference in New Issue
Block a user