[vlc-commits] Qt: PLModel: move zoom value out of model

Francois Cartegnie git at videolan.org
Thu Jul 19 18:02:00 CEST 2012


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Jul 19 17:49:05 2012 +0200| [58dc2946843e33058d8f8be98a9419c435a2b68f] | committer: Francois Cartegnie

Qt: PLModel: move zoom value out of model

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=58dc2946843e33058d8f8be98a9419c435a2b68f
---

 .../gui/qt4/components/playlist/playlist_model.cpp |    6 +----
 .../gui/qt4/components/playlist/standardpanel.cpp  |   23 ++++++++++++++++++--
 .../gui/qt4/components/playlist/standardpanel.hpp  |    4 ++++
 modules/gui/qt4/components/playlist/views.cpp      |    4 ++++
 modules/gui/qt4/components/playlist/views.hpp      |    7 ++++++
 modules/gui/qt4/components/playlist/vlc_model.cpp  |   12 ----------
 modules/gui/qt4/components/playlist/vlc_model.hpp  |    4 ----
 7 files changed, 37 insertions(+), 23 deletions(-)

diff --git a/modules/gui/qt4/components/playlist/playlist_model.cpp b/modules/gui/qt4/components/playlist/playlist_model.cpp
index 96fcc04..9e58022 100644
--- a/modules/gui/qt4/components/playlist/playlist_model.cpp
+++ b/modules/gui/qt4/components/playlist/playlist_model.cpp
@@ -29,7 +29,6 @@
 
 #include "qt4.hpp"
 #include "components/playlist/playlist_model.hpp"
-#include "dialogs_provider.hpp"                         /* THEDP */
 #include "input_manager.hpp"                            /* THEMIM */
 
 #include <vlc_intf_strings.h>                           /* I_DIR */
@@ -41,6 +40,7 @@
 #include <QIcon>
 #include <QFont>
 #include <QTimer>
+#include <QAction>
 
 QIcon PLModel::icons[ITEM_TYPE_NUMBER];
 
@@ -74,8 +74,6 @@ PLModel::PLModel( playlist_t *_p_playlist,  /* THEPL */
     ADD_ICON( NODE, ":/type/node" );
 #undef ADD_ICON
 
-    i_zoom = getSettings()->value( "Playlist/zoom", 0 ).toInt();
-
     rebuild( p_root );
     DCONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
               this, processInputItemUpdate( input_item_t *) );
@@ -90,7 +88,6 @@ PLModel::PLModel( playlist_t *_p_playlist,  /* THEPL */
 
 PLModel::~PLModel()
 {
-    getSettings()->setValue( "Playlist/zoom", i_zoom );
     delete rootItem;
 }
 
@@ -367,7 +364,6 @@ QVariant PLModel::data( const QModelIndex &index, const int role ) const
     else if( role == Qt::FontRole )
     {
         QFont f;
-        f.setPointSize( __MAX( f.pointSize() + i_zoom, 4 ) );
         if( isCurrent( index ) )
             f.setBold( true );
         return QVariant( f );
diff --git a/modules/gui/qt4/components/playlist/standardpanel.cpp b/modules/gui/qt4/components/playlist/standardpanel.cpp
index ec98b45..879c827 100644
--- a/modules/gui/qt4/components/playlist/standardpanel.cpp
+++ b/modules/gui/qt4/components/playlist/standardpanel.cpp
@@ -59,6 +59,7 @@
 #include <QInputDialog>
 #include <QDesktopServices>
 #include <QUrl>
+#include <QFont>
 
 #include <assert.h>
 
@@ -88,6 +89,8 @@ 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();
+
     showView( i_savedViewMode );
 
     DCONNECT( THEMIM, leafBecameParent( int ),
@@ -106,6 +109,7 @@ StandardPLPanel::~StandardPLPanel()
     if( treeView )
         getSettings()->setValue( "headerStateV2", treeView->header()->saveState() );
     getSettings()->setValue( "view-mode", currentViewIndex() );
+    getSettings()->setValue( "zoom", i_zoom );
     getSettings()->endGroup();
 }
 
@@ -245,8 +249,8 @@ bool StandardPLPanel::popup( const QModelIndex & index, const QPoint &point, con
 
     /* Zoom */
     QMenu *zoomMenu = new QMenu( qtr( "Display size" ) );
-    zoomMenu->addAction( qtr( "Increase" ), model, SLOT( increaseZoom() ) );
-    zoomMenu->addAction( qtr( "Decrease" ), model, SLOT( decreaseZoom() ) );
+    zoomMenu->addAction( qtr( "Increase" ), this, SLOT( increaseZoom() ) );
+    zoomMenu->addAction( qtr( "Decrease" ), this, SLOT( decreaseZoom() ) );
     menu.addMenu( zoomMenu );
 
     CONNECT( &menu, triggered( QAction * ), model, actionSlot( QAction * ) );
@@ -561,6 +565,20 @@ void StandardPLPanel::createTreeView()
     viewStack->addWidget( treeView );
 }
 
+void StandardPLPanel::updateZoom( int i )
+{
+    if ( i < 4 - 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
+    currentView->reset();
+}
+
 void StandardPLPanel::changeModel( bool b_ml )
 {
 #ifdef MEDIA_LIBRARY
@@ -646,6 +664,7 @@ void StandardPLPanel::showView( int i_view )
         }
     }
 
+    updateZoom( i_zoom );
     viewStack->setCurrentWidget( currentView );
     browseInto();
     gotoPlayingItem();
diff --git a/modules/gui/qt4/components/playlist/standardpanel.hpp b/modules/gui/qt4/components/playlist/standardpanel.hpp
index 85b83b0..4182ecd 100644
--- a/modules/gui/qt4/components/playlist/standardpanel.hpp
+++ b/modules/gui/qt4/components/playlist/standardpanel.hpp
@@ -86,6 +86,7 @@ private:
     PlIconView        *iconView;
     PlListView        *listView;
     PicFlowView       *picFlowView;
+    int i_zoom;
 
     QAbstractItemView *currentView;
 
@@ -100,6 +101,7 @@ private:
     void createIconView();
     void createListView();
     void createCoverView();
+    void updateZoom( int i_zoom );
     void changeModel ( bool b_ml );
     bool eventFilter ( QObject * watched, QEvent * event );
 
@@ -130,6 +132,8 @@ private slots:
     void popupExplore();
     void popupStream();
     void popupSave();
+    void increaseZoom() { updateZoom( i_zoom + 1 ); };
+    void decreaseZoom() { updateZoom( i_zoom - 1 ); };
     void toggleColumnShown( int );
 
     void showView( int );
diff --git a/modules/gui/qt4/components/playlist/views.cpp b/modules/gui/qt4/components/playlist/views.cpp
index 5983db3..d33222a 100644
--- a/modules/gui/qt4/components/playlist/views.cpp
+++ b/modules/gui/qt4/components/playlist/views.cpp
@@ -32,6 +32,7 @@
 #include <QFontMetrics>
 #include <QDrag>
 #include <QDragMoveEvent>
+#include <QMetaType>
 
 #include "assert.h"
 
@@ -78,6 +79,7 @@ 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 ) );
     painter->setFont( font );
     QFontMetrics fm = painter->fontMetrics();
 
@@ -163,6 +165,7 @@ 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();
@@ -216,6 +219,7 @@ void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
 
     //Draw title info
     f.setItalic( true );
+    f.setPointSize( __MAX( f.pointSize() + i_zoom, 4 ) );
     painter->setFont( f );
     QFontMetrics fm( painter->fontMetrics() );
 
diff --git a/modules/gui/qt4/components/playlist/views.hpp b/modules/gui/qt4/components/playlist/views.hpp
index 0cc15c0..b6a263d 100644
--- a/modules/gui/qt4/components/playlist/views.hpp
+++ b/modules/gui/qt4/components/playlist/views.hpp
@@ -32,12 +32,19 @@
 
 class QPainter;
 class PLModel;
+class QFont;
 
 class AbstractPlViewItemDelegate : public QStyledItemDelegate
 {
+    Q_OBJECT
+
 public:
     AbstractPlViewItemDelegate( QWidget * parent = 0 ) : QStyledItemDelegate(parent) {}
     void paintBackground( QPainter *, const QStyleOptionViewItem &, const QModelIndex & ) const;
+    void setZoom( int z ) { i_zoom = z; };
+
+protected:
+    int i_zoom;
 };
 
 class PlIconViewItemDelegate : public AbstractPlViewItemDelegate
diff --git a/modules/gui/qt4/components/playlist/vlc_model.cpp b/modules/gui/qt4/components/playlist/vlc_model.cpp
index 6b88645..ede9773 100644
--- a/modules/gui/qt4/components/playlist/vlc_model.cpp
+++ b/modules/gui/qt4/components/playlist/vlc_model.cpp
@@ -76,15 +76,3 @@ QPixmap VLCModel::getArtPixmap( const QModelIndex & index, const QSize & size )
 
     return artPix;
 }
-
-void VLCModel::increaseZoom()
-{
-    i_zoom++;
-    emit layoutChanged();
-}
-
-void VLCModel::decreaseZoom()
-{
-    i_zoom--;
-    emit layoutChanged();
-}
diff --git a/modules/gui/qt4/components/playlist/vlc_model.hpp b/modules/gui/qt4/components/playlist/vlc_model.hpp
index 57e07aa..4c1fdb5 100644
--- a/modules/gui/qt4/components/playlist/vlc_model.hpp
+++ b/modules/gui/qt4/components/playlist/vlc_model.hpp
@@ -113,13 +113,9 @@ public:
 public slots:
     virtual void activateItem( const QModelIndex &index ) = 0;
     virtual void actionSlot( QAction *action ) = 0;
-    void increaseZoom();
-    void decreaseZoom();
 
 protected:
     intf_thread_t *p_intf;
-    /* Zoom factor for font-size */
-    int i_zoom; /* FIXME: Probably should belong to View/Delegate */
 };
 
 Q_DECLARE_METATYPE(VLCModel::actionsContainerType)



More information about the vlc-commits mailing list