]> git.sesse.net Git - vlc/commitdiff
Qt: drop zoom for FontRole (fix #11874)
authorFrancois Cartegnie <fcvlcdev@free.fr>
Tue, 24 Feb 2015 19:55:36 +0000 (20:55 +0100)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Tue, 24 Feb 2015 19:55:36 +0000 (20:55 +0100)
Applies to all view.

modules/gui/qt4/components/playlist/playlist_model.cpp
modules/gui/qt4/components/playlist/playlist_model.hpp
modules/gui/qt4/components/playlist/standardpanel.cpp
modules/gui/qt4/components/playlist/standardpanel.hpp
modules/gui/qt4/components/playlist/views.cpp
modules/gui/qt4/components/playlist/views.hpp

index 1872ce33de4c1cbf6d9bb14d2979578fc7605576..c5526099bf8ea15eb9c28c8545427c0e0f2dae4f 100644 (file)
@@ -297,7 +297,17 @@ void PLModel::activateItem( playlist_item_t *p_item )
 /****************** Base model mandatory implementations *****************/
 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 );
     if( role == Qt::DisplayRole )
     {
@@ -345,10 +355,6 @@ QVariant PLModel::data( const QModelIndex &index, const int role ) const
             return QVariant();
         }
     }
-    else if( role == Qt::FontRole )
-    {
-        return QVariant( QFont() );
-    }
     else if( role == Qt::BackgroundRole && isCurrent( index ) )
     {
         return QVariant( QBrush( Qt::gray ) );
@@ -368,6 +374,18 @@ QVariant PLModel::data( const QModelIndex &index, const int role ) const
     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 */
 bool PLModel::isParent( const QModelIndex &index, const QModelIndex &current ) const
 {
index 035681f8b065010a1c0e18278117389b20a50115..4f3e9fa768e1969759b9a88379db4cc902f5d9b2 100644 (file)
@@ -73,6 +73,7 @@ public:
 
     /* Data structure */
     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;
     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;
@@ -153,6 +154,7 @@ private:
 
     /* */
     QString latestSearch;
+    QFont   customFont;
 
 private slots:
     void processInputItemUpdate( input_item_t *);
index fa4a2ba2212ddc184e8f874315193fe89db276ba..07ab62b5e7c99d24d9b1b99049603559f0947b22 100644 (file)
@@ -106,7 +106,10 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent,
 
     /* Saved Settings */
     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 );
 
@@ -126,7 +129,9 @@ StandardPLPanel::~StandardPLPanel()
     if( treeView )
         getSettings()->setValue( "headerStateV2", treeView->header()->saveState() );
     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();
 }
 
@@ -659,16 +664,12 @@ void StandardPLPanel::createTreeView()
 
 void StandardPLPanel::updateZoom( int i )
 {
-    if ( i < 5 - QApplication::font().pointSize() ) return;
-    if ( i > 3 + QApplication::font().pointSize() ) return;
-    i_zoom = i;
-#define A_ZOOM( view ) \
-    if ( view ) \
-    qobject_cast<AbstractPlViewItemDelegate*>( view->itemDelegate() )->setZoom( i_zoom )
-    /* Can't iterate as picflow & tree aren't using custom delegate */
-    A_ZOOM( iconView );
-    A_ZOOM( listView );
-#undef A_ZOOM
+    QVariant fontdata = model->data( QModelIndex(), Qt::FontRole );
+    QFont font = fontdata.value<QFont>();
+    font.setPointSize( font.pointSize() + i );
+    if ( font.pointSize() < 5 - QApplication::font().pointSize() ) return;
+    if ( font.pointSize() > 3 + QApplication::font().pointSize() ) return;
+    model->setData( QModelIndex(), font, Qt::FontRole );
 }
 
 void StandardPLPanel::showView( int i_view )
@@ -739,7 +740,6 @@ void StandardPLPanel::showView( int i_view )
         }
     }
 
-    updateZoom( i_zoom );
     viewStack->setCurrentWidget( currentView );
     browseInto();
     gotoPlayingItem();
index cc280fddc2099249e0750d65bf8cbbae6674ce97..4e0cc421e97935a820614c938096a0051f68dcb2 100644 (file)
@@ -85,7 +85,6 @@ private:
     PlIconView        *iconView;
     PlListView        *listView;
     PicFlowView       *picFlowView;
-    int i_zoom;
 
     QAbstractItemView *currentView;
 
@@ -128,8 +127,8 @@ private slots:
     void popupPlView( const QPoint & );
     void popupSelectColumn( QPoint );
     void popupAction( QAction * );
-    void increaseZoom() { updateZoom( i_zoom + 1 ); };
-    void decreaseZoom() { updateZoom( i_zoom - 1 ); };
+    void increaseZoom() { updateZoom( 1 ); };
+    void decreaseZoom() { updateZoom( -1 ); };
     void toggleColumnShown( int );
 
     void cycleViews();
index 29526804d3136d53b6e86546bbac24518bc3736f..0bbb44a27498d3bc55f9d608cc21d8b671074f70 100644 (file)
@@ -80,7 +80,6 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
     QString artist = VLCModel::getMeta( index, COLUMN_ARTIST );
 
     QFont font( index.data( Qt::FontRole ).value<QFont>() );
-    font.setPointSize( __MAX( font.pointSize() + i_zoom, 4 ) );
     font.setBold( index.data( VLCModel::IsCurrentRole ).toBool() );
     painter->setFont( font );
     QFontMetrics fm = painter->fontMetrics();
@@ -167,7 +166,6 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
 QSize PlIconViewItemDelegate::sizeHint ( const QStyleOptionViewItem &, const QModelIndex & index ) const
 {
     QFont f( index.data( Qt::FontRole ).value<QFont>() );
-    f.setPointSize( __MAX( f.pointSize() + i_zoom, 4 ) );
     f.setBold( true );
     QFontMetrics fm( f );
     int textHeight = fm.height();
@@ -221,7 +219,6 @@ void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
 
     //Draw title info
     f.setItalic( true );
-    f.setPointSize( __MAX( f.pointSize() + i_zoom, 4 ) );
     f.setBold( index.data( VLCModel::IsCurrentRole ).toBool() );
     painter->setFont( f );
     QFontMetrics fm( painter->fontMetrics() );
index 7a0e3bb7631946cf28b376a5cbff64e7beb02fd2..9a2c91e56f6737610153bf9a882e9d257d439c15 100644 (file)
@@ -39,10 +39,6 @@ class AbstractPlViewItemDelegate : public QStyledItemDelegate
 public:
     AbstractPlViewItemDelegate( QWidget * parent = 0 ) : QStyledItemDelegate(parent) {}
     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