Commit 6704074e authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: drop zoom for FontRole (fix #11874)

Applies to all view.
parent 59f5a57b
...@@ -297,7 +297,17 @@ void PLModel::activateItem( playlist_item_t *p_item ) ...@@ -297,7 +297,17 @@ void PLModel::activateItem( playlist_item_t *p_item )
/****************** Base model mandatory implementations *****************/ /****************** Base model mandatory implementations *****************/
QVariant PLModel::data( const QModelIndex &index, const int role ) const QVariant PLModel::data( const QModelIndex &index, const int role ) const
{ {
if( !index.isValid() ) return QVariant(); switch( role )
{
case Qt::FontRole:
return customFont;
default:
if( !index.isValid() )
return QVariant();
}
PLItem *item = getItem( index ); PLItem *item = getItem( index );
if( role == Qt::DisplayRole ) if( role == Qt::DisplayRole )
{ {
...@@ -345,10 +355,6 @@ QVariant PLModel::data( const QModelIndex &index, const int role ) const ...@@ -345,10 +355,6 @@ QVariant PLModel::data( const QModelIndex &index, const int role ) const
return QVariant(); return QVariant();
} }
} }
else if( role == Qt::FontRole )
{
return QVariant( QFont() );
}
else if( role == Qt::BackgroundRole && isCurrent( index ) ) else if( role == Qt::BackgroundRole && isCurrent( index ) )
{ {
return QVariant( QBrush( Qt::gray ) ); return QVariant( QBrush( Qt::gray ) );
...@@ -368,6 +374,18 @@ QVariant PLModel::data( const QModelIndex &index, const int role ) const ...@@ -368,6 +374,18 @@ QVariant PLModel::data( const QModelIndex &index, const int role ) const
return QVariant(); return QVariant();
} }
bool PLModel::setData( const QModelIndex &index, const QVariant & value, int role )
{
switch( role )
{
case Qt::FontRole:
customFont = value.value<QFont>();
return true;
default:
return VLCModel::setData( index, value, role );
}
}
/* Seek from current index toward the top and see if index is one of parent nodes */ /* Seek from current index toward the top and see if index is one of parent nodes */
bool PLModel::isParent( const QModelIndex &index, const QModelIndex &current ) const bool PLModel::isParent( const QModelIndex &index, const QModelIndex &current ) const
{ {
......
...@@ -73,6 +73,7 @@ public: ...@@ -73,6 +73,7 @@ public:
/* Data structure */ /* Data structure */
QVariant data( const QModelIndex &index, const int role ) const Q_DECL_OVERRIDE; QVariant data( const QModelIndex &index, const int role ) const Q_DECL_OVERRIDE;
bool setData( const QModelIndex &index, const QVariant & value, int role = Qt::EditRole ) Q_DECL_OVERRIDE;
int rowCount( const QModelIndex &parent = QModelIndex() ) const Q_DECL_OVERRIDE; int rowCount( const QModelIndex &parent = QModelIndex() ) const Q_DECL_OVERRIDE;
Qt::ItemFlags flags( const QModelIndex &index ) const Q_DECL_OVERRIDE; Qt::ItemFlags flags( const QModelIndex &index ) const Q_DECL_OVERRIDE;
QModelIndex index( const int r, const int c, const QModelIndex &parent ) const Q_DECL_OVERRIDE; QModelIndex index( const int r, const int c, const QModelIndex &parent ) const Q_DECL_OVERRIDE;
...@@ -153,6 +154,7 @@ private: ...@@ -153,6 +154,7 @@ private:
/* */ /* */
QString latestSearch; QString latestSearch;
QFont customFont;
private slots: private slots:
void processInputItemUpdate( input_item_t *); void processInputItemUpdate( input_item_t *);
......
...@@ -106,7 +106,10 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, ...@@ -106,7 +106,10 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
/* Saved Settings */ /* Saved Settings */
int i_savedViewMode = getSettings()->value( "Playlist/view-mode", TREE_VIEW ).toInt(); int i_savedViewMode = getSettings()->value( "Playlist/view-mode", TREE_VIEW ).toInt();
i_zoom = getSettings()->value( "Playlist/zoom", 0 ).toInt();
QFont font = QApplication::font();
font.setPointSize( font.pointSize() + getSettings()->value( "Playlist/zoom", 0 ).toInt() );
model->setData( QModelIndex(), font, Qt::FontRole );
showView( i_savedViewMode ); showView( i_savedViewMode );
...@@ -126,7 +129,9 @@ StandardPLPanel::~StandardPLPanel() ...@@ -126,7 +129,9 @@ StandardPLPanel::~StandardPLPanel()
if( treeView ) if( treeView )
getSettings()->setValue( "headerStateV2", treeView->header()->saveState() ); getSettings()->setValue( "headerStateV2", treeView->header()->saveState() );
getSettings()->setValue( "view-mode", currentViewIndex() ); getSettings()->setValue( "view-mode", currentViewIndex() );
getSettings()->setValue( "zoom", i_zoom ); getSettings()->setValue( "zoom",
model->data( QModelIndex(), Qt::FontRole ).value<QFont>().pointSize()
- QApplication::font().pointSize() );
getSettings()->endGroup(); getSettings()->endGroup();
} }
...@@ -659,16 +664,12 @@ void StandardPLPanel::createTreeView() ...@@ -659,16 +664,12 @@ void StandardPLPanel::createTreeView()
void StandardPLPanel::updateZoom( int i ) void StandardPLPanel::updateZoom( int i )
{ {
if ( i < 5 - QApplication::font().pointSize() ) return; QVariant fontdata = model->data( QModelIndex(), Qt::FontRole );
if ( i > 3 + QApplication::font().pointSize() ) return; QFont font = fontdata.value<QFont>();
i_zoom = i; font.setPointSize( font.pointSize() + i );
#define A_ZOOM( view ) \ if ( font.pointSize() < 5 - QApplication::font().pointSize() ) return;
if ( view ) \ if ( font.pointSize() > 3 + QApplication::font().pointSize() ) return;
qobject_cast<AbstractPlViewItemDelegate*>( view->itemDelegate() )->setZoom( i_zoom ) model->setData( QModelIndex(), font, Qt::FontRole );
/* Can't iterate as picflow & tree aren't using custom delegate */
A_ZOOM( iconView );
A_ZOOM( listView );
#undef A_ZOOM
} }
void StandardPLPanel::showView( int i_view ) void StandardPLPanel::showView( int i_view )
...@@ -739,7 +740,6 @@ void StandardPLPanel::showView( int i_view ) ...@@ -739,7 +740,6 @@ void StandardPLPanel::showView( int i_view )
} }
} }
updateZoom( i_zoom );
viewStack->setCurrentWidget( currentView ); viewStack->setCurrentWidget( currentView );
browseInto(); browseInto();
gotoPlayingItem(); gotoPlayingItem();
......
...@@ -85,7 +85,6 @@ private: ...@@ -85,7 +85,6 @@ private:
PlIconView *iconView; PlIconView *iconView;
PlListView *listView; PlListView *listView;
PicFlowView *picFlowView; PicFlowView *picFlowView;
int i_zoom;
QAbstractItemView *currentView; QAbstractItemView *currentView;
...@@ -128,8 +127,8 @@ private slots: ...@@ -128,8 +127,8 @@ private slots:
void popupPlView( const QPoint & ); void popupPlView( const QPoint & );
void popupSelectColumn( QPoint ); void popupSelectColumn( QPoint );
void popupAction( QAction * ); void popupAction( QAction * );
void increaseZoom() { updateZoom( i_zoom + 1 ); }; void increaseZoom() { updateZoom( 1 ); };
void decreaseZoom() { updateZoom( i_zoom - 1 ); }; void decreaseZoom() { updateZoom( -1 ); };
void toggleColumnShown( int ); void toggleColumnShown( int );
void cycleViews(); void cycleViews();
......
...@@ -80,7 +80,6 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt ...@@ -80,7 +80,6 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
QString artist = VLCModel::getMeta( index, COLUMN_ARTIST ); QString artist = VLCModel::getMeta( index, COLUMN_ARTIST );
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.setBold( index.data( VLCModel::IsCurrentRole ).toBool() ); font.setBold( index.data( VLCModel::IsCurrentRole ).toBool() );
painter->setFont( font ); painter->setFont( font );
QFontMetrics fm = painter->fontMetrics(); QFontMetrics fm = painter->fontMetrics();
...@@ -167,7 +166,6 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt ...@@ -167,7 +166,6 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
QSize PlIconViewItemDelegate::sizeHint ( const QStyleOptionViewItem &, const QModelIndex & index ) const QSize PlIconViewItemDelegate::sizeHint ( const QStyleOptionViewItem &, const QModelIndex & index ) const
{ {
QFont f( index.data( Qt::FontRole ).value<QFont>() ); QFont f( index.data( Qt::FontRole ).value<QFont>() );
f.setPointSize( __MAX( f.pointSize() + i_zoom, 4 ) );
f.setBold( true ); f.setBold( true );
QFontMetrics fm( f ); QFontMetrics fm( f );
int textHeight = fm.height(); int textHeight = fm.height();
...@@ -221,7 +219,6 @@ void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt ...@@ -221,7 +219,6 @@ 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.setBold( index.data( VLCModel::IsCurrentRole ).toBool() ); f.setBold( index.data( VLCModel::IsCurrentRole ).toBool() );
painter->setFont( f ); painter->setFont( f );
QFontMetrics fm( painter->fontMetrics() ); QFontMetrics fm( painter->fontMetrics() );
......
...@@ -39,10 +39,6 @@ class AbstractPlViewItemDelegate : public QStyledItemDelegate ...@@ -39,10 +39,6 @@ class AbstractPlViewItemDelegate : public QStyledItemDelegate
public: public:
AbstractPlViewItemDelegate( QWidget * parent = 0 ) : QStyledItemDelegate(parent) {} AbstractPlViewItemDelegate( QWidget * parent = 0 ) : QStyledItemDelegate(parent) {}
void paintBackground( QPainter *, const QStyleOptionViewItem &, const QModelIndex & ) const; void paintBackground( QPainter *, const QStyleOptionViewItem &, const QModelIndex & ) const;
void setZoom( int z ) { i_zoom = z; emit sizeHintChanged( QModelIndex() ); };
protected:
int i_zoom;
}; };
class PlIconViewItemDelegate : public AbstractPlViewItemDelegate class PlIconViewItemDelegate : public AbstractPlViewItemDelegate
......
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