Commit 70cf0848 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

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

Close #6103
(cherry picked from commit 6241fbf7)
Signed-off-by: default avatarJean-Baptiste Kempf <jb@videolan.org>
parent 58958fbd
......@@ -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") );
PLModel *model = PLModel::getPLModel( p_intf );
plMenu->setModel( model );
......
......@@ -37,15 +37,14 @@
*
* 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
* - limit the width of the entries
* TODO: - limit the width of the entries
* - deal with a root item
***/
Q_DECLARE_METATYPE(QModelIndex); // So we can store it in a QVariant
QMenuView::QMenuView( QWidget * parent )
: QMenu( parent )
QMenuView::QMenuView( QWidget * parent, int _iMaxVisibleCount )
: QMenu( parent ), iMaxVisibleCount( _iMaxVisibleCount )
{
m_model = NULL;
......@@ -75,7 +74,9 @@ void QMenuView::rebuild()
/* */
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);
if( m_model->hasChildren( idx ) )
......
......@@ -32,13 +32,16 @@ class QMenuView : public QMenu
Q_OBJECT;
public:
QMenuView( QWidget * parent = 0 );
QMenuView( QWidget * parent = 0, int iMaxVisibleCount = 0 );
virtual ~QMenuView(){}
/* Model */
void setModel( QAbstractItemModel * model ) { m_model = model; }
QAbstractItemModel * model() const { return m_model; }
/* Size limit */
void setMaximumItemCount( int count ) { iMaxVisibleCount = count; }
private:
QAbstractItemModel *m_model;
......@@ -46,6 +49,8 @@ private:
void build( const QModelIndex &parent );
int iMaxVisibleCount;
private slots:
void rebuild();
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