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

Qt: PLModel: move zoom value out of model

parent 029b9fae
......@@ -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 );
......
......@@ -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();
......
......@@ -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 );
......
......@@ -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() );
......
......@@ -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
......
......@@ -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();
}
......@@ -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)
......
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