Commit 6241fbf7 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Qt: limit the number of entries in the right click to 25

Close #6103
parent 575ef3b3
...@@ -1083,7 +1083,7 @@ void VLCMenuBar::PopupMenu( intf_thread_t *p_intf, bool show ) ...@@ -1083,7 +1083,7 @@ void VLCMenuBar::PopupMenu( intf_thread_t *p_intf, bool show )
} }
/* */ /* */
QMenuView *plMenu = new QMenuView( menu ); QMenuView *plMenu = new QMenuView( menu, 25 );
plMenu->setTitle( qtr("Playlist") ); plMenu->setTitle( qtr("Playlist") );
PLModel *model = PLModel::getPLModel( p_intf ); PLModel *model = PLModel::getPLModel( p_intf );
plMenu->setModel( model ); plMenu->setModel( model );
......
...@@ -37,15 +37,14 @@ ...@@ -37,15 +37,14 @@
* *
* This is now linked to VLC's models. It should be splittable in the future. * This is now linked to VLC's models. It should be splittable in the future.
* *
* TODO: - limit the number of the menu, as a Q_PROPERTY * TODO: - limit the width of the entries
* - limit the width of the entries
* - deal with a root item * - deal with a root item
***/ ***/
Q_DECLARE_METATYPE(QModelIndex); // So we can store it in a QVariant Q_DECLARE_METATYPE(QModelIndex); // So we can store it in a QVariant
QMenuView::QMenuView( QWidget * parent ) QMenuView::QMenuView( QWidget * parent, int _iMaxVisibleCount )
: QMenu( parent ) : QMenu( parent ), iMaxVisibleCount( _iMaxVisibleCount )
{ {
m_model = NULL; m_model = NULL;
...@@ -75,7 +74,9 @@ void QMenuView::rebuild() ...@@ -75,7 +74,9 @@ void QMenuView::rebuild()
/* */ /* */
void QMenuView::build( const QModelIndex &parent ) void QMenuView::build( const QModelIndex &parent )
{ {
for( int i = 0; i < m_model->rowCount( parent ); i++ ) int i_count = iMaxVisibleCount == 0 ? m_model->rowCount( parent )
: __MIN( iMaxVisibleCount, m_model->rowCount( parent ) );
for( int i = 0; i < i_count; i++ )
{ {
QModelIndex idx = m_model->index(i, 0, parent); QModelIndex idx = m_model->index(i, 0, parent);
if( m_model->hasChildren( idx ) ) if( m_model->hasChildren( idx ) )
......
...@@ -32,13 +32,16 @@ class QMenuView : public QMenu ...@@ -32,13 +32,16 @@ class QMenuView : public QMenu
Q_OBJECT; Q_OBJECT;
public: public:
QMenuView( QWidget * parent = 0 ); QMenuView( QWidget * parent = 0, int iMaxVisibleCount = 0 );
virtual ~QMenuView(){} virtual ~QMenuView(){}
/* Model */ /* Model */
void setModel( QAbstractItemModel * model ) { m_model = model; } void setModel( QAbstractItemModel * model ) { m_model = model; }
QAbstractItemModel * model() const { return m_model; } QAbstractItemModel * model() const { return m_model; }
/* Size limit */
void setMaximumItemCount( int count ) { iMaxVisibleCount = count; }
private: private:
QAbstractItemModel *m_model; QAbstractItemModel *m_model;
...@@ -46,6 +49,8 @@ private: ...@@ -46,6 +49,8 @@ private:
void build( const QModelIndex &parent ); void build( const QModelIndex &parent );
int iMaxVisibleCount;
private slots: private slots:
void rebuild(); void rebuild();
void activate(QAction*); void activate(QAction*);
......
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