Commit 58dc2946 authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: PLModel: move zoom value out of model

parent 029b9fae
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "qt4.hpp" #include "qt4.hpp"
#include "components/playlist/playlist_model.hpp" #include "components/playlist/playlist_model.hpp"
#include "dialogs_provider.hpp" /* THEDP */
#include "input_manager.hpp" /* THEMIM */ #include "input_manager.hpp" /* THEMIM */
#include <vlc_intf_strings.h> /* I_DIR */ #include <vlc_intf_strings.h> /* I_DIR */
...@@ -41,6 +40,7 @@ ...@@ -41,6 +40,7 @@
#include <QIcon> #include <QIcon>
#include <QFont> #include <QFont>
#include <QTimer> #include <QTimer>
#include <QAction>
QIcon PLModel::icons[ITEM_TYPE_NUMBER]; QIcon PLModel::icons[ITEM_TYPE_NUMBER];
...@@ -74,8 +74,6 @@ PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */ ...@@ -74,8 +74,6 @@ PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
ADD_ICON( NODE, ":/type/node" ); ADD_ICON( NODE, ":/type/node" );
#undef ADD_ICON #undef ADD_ICON
i_zoom = getSettings()->value( "Playlist/zoom", 0 ).toInt();
rebuild( p_root ); rebuild( p_root );
DCONNECT( THEMIM->getIM(), metaChanged( input_item_t *), DCONNECT( THEMIM->getIM(), metaChanged( input_item_t *),
this, processInputItemUpdate( input_item_t *) ); this, processInputItemUpdate( input_item_t *) );
...@@ -90,7 +88,6 @@ PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */ ...@@ -90,7 +88,6 @@ PLModel::PLModel( playlist_t *_p_playlist, /* THEPL */
PLModel::~PLModel() PLModel::~PLModel()
{ {
getSettings()->setValue( "Playlist/zoom", i_zoom );
delete rootItem; delete rootItem;
} }
...@@ -367,7 +364,6 @@ QVariant PLModel::data( const QModelIndex &index, const int role ) const ...@@ -367,7 +364,6 @@ QVariant PLModel::data( const QModelIndex &index, const int role ) const
else if( role == Qt::FontRole ) else if( role == Qt::FontRole )
{ {
QFont f; QFont f;
f.setPointSize( __MAX( f.pointSize() + i_zoom, 4 ) );
if( isCurrent( index ) ) if( isCurrent( index ) )
f.setBold( true ); f.setBold( true );
return QVariant( f ); return QVariant( f );
......
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
#include <QInputDialog> #include <QInputDialog>
#include <QDesktopServices> #include <QDesktopServices>
#include <QUrl> #include <QUrl>
#include <QFont>
#include <assert.h> #include <assert.h>
...@@ -88,6 +89,8 @@ StandardPLPanel::StandardPLPanel( PlaylistWidget *_parent, ...@@ -88,6 +89,8 @@ 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();
showView( i_savedViewMode ); showView( i_savedViewMode );
DCONNECT( THEMIM, leafBecameParent( int ), DCONNECT( THEMIM, leafBecameParent( int ),
...@@ -106,6 +109,7 @@ StandardPLPanel::~StandardPLPanel() ...@@ -106,6 +109,7 @@ 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()->endGroup(); getSettings()->endGroup();
} }
...@@ -245,8 +249,8 @@ bool StandardPLPanel::popup( const QModelIndex & index, const QPoint &point, con ...@@ -245,8 +249,8 @@ bool StandardPLPanel::popup( const QModelIndex & index, const QPoint &point, con
/* Zoom */ /* Zoom */
QMenu *zoomMenu = new QMenu( qtr( "Display size" ) ); QMenu *zoomMenu = new QMenu( qtr( "Display size" ) );
zoomMenu->addAction( qtr( "Increase" ), model, SLOT( increaseZoom() ) ); zoomMenu->addAction( qtr( "Increase" ), this, SLOT( increaseZoom() ) );
zoomMenu->addAction( qtr( "Decrease" ), model, SLOT( decreaseZoom() ) ); zoomMenu->addAction( qtr( "Decrease" ), this, SLOT( decreaseZoom() ) );
menu.addMenu( zoomMenu ); menu.addMenu( zoomMenu );
CONNECT( &menu, triggered( QAction * ), model, actionSlot( QAction * ) ); CONNECT( &menu, triggered( QAction * ), model, actionSlot( QAction * ) );
...@@ -561,6 +565,20 @@ void StandardPLPanel::createTreeView() ...@@ -561,6 +565,20 @@ void StandardPLPanel::createTreeView()
viewStack->addWidget( treeView ); 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 ) void StandardPLPanel::changeModel( bool b_ml )
{ {
#ifdef MEDIA_LIBRARY #ifdef MEDIA_LIBRARY
...@@ -646,6 +664,7 @@ void StandardPLPanel::showView( int i_view ) ...@@ -646,6 +664,7 @@ void StandardPLPanel::showView( int i_view )
} }
} }
updateZoom( i_zoom );
viewStack->setCurrentWidget( currentView ); viewStack->setCurrentWidget( currentView );
browseInto(); browseInto();
gotoPlayingItem(); gotoPlayingItem();
......
...@@ -86,6 +86,7 @@ private: ...@@ -86,6 +86,7 @@ private:
PlIconView *iconView; PlIconView *iconView;
PlListView *listView; PlListView *listView;
PicFlowView *picFlowView; PicFlowView *picFlowView;
int i_zoom;
QAbstractItemView *currentView; QAbstractItemView *currentView;
...@@ -100,6 +101,7 @@ private: ...@@ -100,6 +101,7 @@ private:
void createIconView(); void createIconView();
void createListView(); void createListView();
void createCoverView(); void createCoverView();
void updateZoom( int i_zoom );
void changeModel ( bool b_ml ); void changeModel ( bool b_ml );
bool eventFilter ( QObject * watched, QEvent * event ); bool eventFilter ( QObject * watched, QEvent * event );
...@@ -130,6 +132,8 @@ private slots: ...@@ -130,6 +132,8 @@ private slots:
void popupExplore(); void popupExplore();
void popupStream(); void popupStream();
void popupSave(); void popupSave();
void increaseZoom() { updateZoom( i_zoom + 1 ); };
void decreaseZoom() { updateZoom( i_zoom - 1 ); };
void toggleColumnShown( int ); void toggleColumnShown( int );
void showView( int ); void showView( int );
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <QFontMetrics> #include <QFontMetrics>
#include <QDrag> #include <QDrag>
#include <QDragMoveEvent> #include <QDragMoveEvent>
#include <QMetaType>
#include "assert.h" #include "assert.h"
...@@ -78,6 +79,7 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt ...@@ -78,6 +79,7 @@ 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 ) );
painter->setFont( font ); painter->setFont( font );
QFontMetrics fm = painter->fontMetrics(); QFontMetrics fm = painter->fontMetrics();
...@@ -163,6 +165,7 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt ...@@ -163,6 +165,7 @@ 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();
...@@ -216,6 +219,7 @@ void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt ...@@ -216,6 +219,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 ) );
painter->setFont( f ); painter->setFont( f );
QFontMetrics fm( painter->fontMetrics() ); QFontMetrics fm( painter->fontMetrics() );
......
...@@ -32,12 +32,19 @@ ...@@ -32,12 +32,19 @@
class QPainter; class QPainter;
class PLModel; class PLModel;
class QFont;
class AbstractPlViewItemDelegate : public QStyledItemDelegate class AbstractPlViewItemDelegate : public QStyledItemDelegate
{ {
Q_OBJECT
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; };
protected:
int i_zoom;
}; };
class PlIconViewItemDelegate : public AbstractPlViewItemDelegate class PlIconViewItemDelegate : public AbstractPlViewItemDelegate
......
...@@ -76,15 +76,3 @@ QPixmap VLCModel::getArtPixmap( const QModelIndex & index, const QSize & size ) ...@@ -76,15 +76,3 @@ QPixmap VLCModel::getArtPixmap( const QModelIndex & index, const QSize & size )
return artPix; return artPix;
} }
void VLCModel::increaseZoom()
{
i_zoom++;
emit layoutChanged();
}
void VLCModel::decreaseZoom()
{
i_zoom--;
emit layoutChanged();
}
...@@ -113,13 +113,9 @@ public: ...@@ -113,13 +113,9 @@ public:
public slots: public slots:
virtual void activateItem( const QModelIndex &index ) = 0; virtual void activateItem( const QModelIndex &index ) = 0;
virtual void actionSlot( QAction *action ) = 0; virtual void actionSlot( QAction *action ) = 0;
void increaseZoom();
void decreaseZoom();
protected: protected:
intf_thread_t *p_intf; 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) Q_DECLARE_METATYPE(VLCModel::actionsContainerType)
......
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