Commit c3581f43 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: PLTreeView: use delegate for emphasing font.

Also fixes a mistake in 229c807c
where isCurrent == isSelected
parent c0d24a1b
...@@ -525,25 +525,7 @@ void StandardPLPanel::createCoverView() ...@@ -525,25 +525,7 @@ void StandardPLPanel::createCoverView()
void StandardPLPanel::createTreeView() void StandardPLPanel::createTreeView()
{ {
/* Create and configure the QTreeView */ /* Create and configure the QTreeView */
treeView = new PlTreeView; treeView = new PlTreeView( model, this );
treeView->setIconSize( QSize( 20, 20 ) );
treeView->setAlternatingRowColors( true );
treeView->setAnimated( true );
treeView->setUniformRowHeights( true );
treeView->setSortingEnabled( true );
treeView->setAttribute( Qt::WA_MacShowFocusRect, false );
treeView->header()->setSortIndicator( -1 , Qt::AscendingOrder );
treeView->header()->setSortIndicatorShown( true );
treeView->header()->setClickable( true );
treeView->header()->setContextMenuPolicy( Qt::CustomContextMenu );
treeView->setSelectionBehavior( QAbstractItemView::SelectRows );
treeView->setSelectionMode( QAbstractItemView::ExtendedSelection );
treeView->setDragEnabled( true );
treeView->setAcceptDrops( true );
treeView->setDropIndicatorShown( true );
treeView->setContextMenuPolicy( Qt::CustomContextMenu );
/* setModel after setSortingEnabled(true), or the model will sort immediately! */ /* setModel after setSortingEnabled(true), or the model will sort immediately! */
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <QDrag> #include <QDrag>
#include <QDragMoveEvent> #include <QDragMoveEvent>
#include <QMetaType> #include <QMetaType>
#include <QHeaderView>
#include "assert.h" #include "assert.h"
...@@ -80,7 +81,7 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt ...@@ -80,7 +81,7 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
QFont font( index.data( Qt::FontRole ).value<QFont>() ); QFont font( index.data( Qt::FontRole ).value<QFont>() );
font.setPointSize( __MAX( font.pointSize() + i_zoom, 4 ) ); font.setPointSize( __MAX( font.pointSize() + i_zoom, 4 ) );
font.setBold( option.state & QStyle::State_Selected ); font.setBold( index.data( PLModel::IsCurrentRole ).toBool() );
painter->setFont( font ); painter->setFont( font );
QFontMetrics fm = painter->fontMetrics(); QFontMetrics fm = painter->fontMetrics();
...@@ -221,7 +222,7 @@ void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt ...@@ -221,7 +222,7 @@ void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
//Draw title info //Draw title info
f.setItalic( true ); f.setItalic( true );
f.setPointSize( __MAX( f.pointSize() + i_zoom, 4 ) ); f.setPointSize( __MAX( f.pointSize() + i_zoom, 4 ) );
f.setBold( option.state & QStyle::State_Selected ); f.setBold( index.data( PLModel::IsCurrentRole ).toBool() );
painter->setFont( f ); painter->setFont( f );
QFontMetrics fm( painter->fontMetrics() ); QFontMetrics fm( painter->fontMetrics() );
...@@ -272,6 +273,21 @@ QSize PlListViewItemDelegate::sizeHint ( const QStyleOptionViewItem &, const QMo ...@@ -272,6 +273,21 @@ QSize PlListViewItemDelegate::sizeHint ( const QStyleOptionViewItem &, const QMo
return QSize( 0, height ); return QSize( 0, height );
} }
void PlTreeViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const
{
if ( index.data( PLModel::IsCurrentRole ).toBool() )
{
QStyleOptionViewItem myoptions = option;
myoptions.font.setBold( true );
AbstractPlViewItemDelegate::paint( painter, myoptions, index );
}
else
{
AbstractPlViewItemDelegate::paint( painter, option, index );
}
}
static inline void plViewStartDrag( QAbstractItemView *view, const Qt::DropActions & supportedActions ) static inline void plViewStartDrag( QAbstractItemView *view, const Qt::DropActions & supportedActions )
{ {
QDrag *drag = new QDrag( view ); QDrag *drag = new QDrag( view );
...@@ -384,6 +400,29 @@ bool PlListView::viewportEvent ( QEvent * event ) ...@@ -384,6 +400,29 @@ bool PlListView::viewportEvent ( QEvent * event )
} }
} }
PlTreeView::PlTreeView( PLModel *, QWidget *parent ) : QTreeView( parent )
{
setItemDelegate( new PlTreeViewItemDelegate( this ) );
setIconSize( QSize( 20, 20 ) );
setAlternatingRowColors( true );
setAnimated( true );
setUniformRowHeights( true );
setSortingEnabled( true );
setAttribute( Qt::WA_MacShowFocusRect, false );
header()->setSortIndicator( -1 , Qt::AscendingOrder );
header()->setSortIndicatorShown( true );
header()->setClickable( true );
header()->setContextMenuPolicy( Qt::CustomContextMenu );
setSelectionBehavior( QAbstractItemView::SelectRows );
setSelectionMode( QAbstractItemView::ExtendedSelection );
setDragEnabled( true );
setAcceptDrops( true );
setDropIndicatorShown( true );
setContextMenuPolicy( Qt::CustomContextMenu );
}
void PlTreeView::setModel( QAbstractItemModel * model ) void PlTreeView::setModel( QAbstractItemModel * model )
{ {
QTreeView::setModel( model ); QTreeView::setModel( model );
......
...@@ -69,6 +69,16 @@ public: ...@@ -69,6 +69,16 @@ public:
virtual QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const; virtual QSize sizeHint ( const QStyleOptionViewItem & option, const QModelIndex & index ) const;
}; };
class PlTreeViewItemDelegate : public AbstractPlViewItemDelegate
{
Q_OBJECT
public:
PlTreeViewItemDelegate(QWidget *parent = 0) : AbstractPlViewItemDelegate(parent) {}
virtual void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
};
class PlIconView : public QListView class PlIconView : public QListView
{ {
Q_OBJECT Q_OBJECT
...@@ -98,6 +108,8 @@ class PlTreeView : public QTreeView ...@@ -98,6 +108,8 @@ class PlTreeView : public QTreeView
{ {
Q_OBJECT Q_OBJECT
public:
PlTreeView( PLModel *, QWidget *parent = 0 );
protected: protected:
virtual void startDrag ( Qt::DropActions supportedActions ); virtual void startDrag ( Qt::DropActions supportedActions );
virtual void dragMoveEvent ( QDragMoveEvent * event ); virtual void dragMoveEvent ( QDragMoveEvent * event );
......
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