mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-13 20:39:57 +01:00
* Keep indentation, but select entire rows in SourceTreeView.
This commit is contained in:
parent
21a1af7c36
commit
ce66303e13
@ -12,10 +12,31 @@
|
||||
#include <QDragEnterEvent>
|
||||
#include <QHeaderView>
|
||||
#include <QPainter>
|
||||
#include <QStyledItemDelegate>
|
||||
|
||||
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 )
|
||||
: QTreeView( parent )
|
||||
, m_collectionModel( new CollectionModel( this ) )
|
||||
@ -31,6 +52,9 @@ SourceTreeView::SourceTreeView( QWidget* parent )
|
||||
setDropIndicatorShown( false );
|
||||
setAllColumnsShowFocus( true );
|
||||
setUniformRowHeights( false );
|
||||
setIndentation( 0 );
|
||||
|
||||
setItemDelegate( new SourceDelegate( this ) );
|
||||
|
||||
setContextMenuPolicy( Qt::CustomContextMenu );
|
||||
connect( this, SIGNAL( customContextMenuRequested( const QPoint& ) ), SLOT( onCustomContextMenu( const QPoint& ) ) );
|
||||
@ -55,6 +79,7 @@ SourceTreeView::setupMenus()
|
||||
m_playlistMenu.clear();
|
||||
|
||||
m_loadPlaylistAction = m_playlistMenu.addAction( tr( "&Load Playlist" ) );
|
||||
m_renamePlaylistAction = m_playlistMenu.addAction( tr( "&Rename Playlist" ) );
|
||||
m_playlistMenu.addSeparator();
|
||||
m_deletePlaylistAction = m_playlistMenu.addAction( tr( "&Delete Playlist" ) );
|
||||
|
||||
@ -323,7 +348,31 @@ SourceTreeView::paintEvent( QPaintEvent* event )
|
||||
opt.rect = itemRect;
|
||||
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 );
|
||||
}
|
||||
|
||||
|
||||
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:
|
||||
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 );
|
||||
|
||||
@ -51,6 +51,7 @@ private:
|
||||
|
||||
QMenu m_playlistMenu;
|
||||
QAction* m_loadPlaylistAction;
|
||||
QAction* m_renamePlaylistAction;
|
||||
QAction* m_deletePlaylistAction;
|
||||
|
||||
bool m_dragging;
|
||||
|
Loading…
x
Reference in New Issue
Block a user