vlc/vlc-2.0 | branch: master | Jean-Baptiste Kempf <[email protected]> | Mon Feb 20 19:12:02 2012 +0100| [70cf0848d2fcf8e14ca973e392e2533a4934c6dd] | committer: Jean-Baptiste Kempf
Qt: limit the number of entries in the right click to 25 Close #6103 (cherry picked from commit 6241fbf7201744c8eafd32b660ba1156f14a758d) Signed-off-by: Jean-Baptiste Kempf <[email protected]> > http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=70cf0848d2fcf8e14ca973e392e2533a4934c6dd --- modules/gui/qt4/menus.cpp | 2 +- modules/gui/qt4/util/qmenuview.cpp | 11 ++++++----- modules/gui/qt4/util/qmenuview.hpp | 7 ++++++- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/modules/gui/qt4/menus.cpp b/modules/gui/qt4/menus.cpp index 7f825f3..b8f2f4c 100644 --- a/modules/gui/qt4/menus.cpp +++ b/modules/gui/qt4/menus.cpp @@ -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 ); diff --git a/modules/gui/qt4/util/qmenuview.cpp b/modules/gui/qt4/util/qmenuview.cpp index 8ec2d3e..909cbb5 100644 --- a/modules/gui/qt4/util/qmenuview.cpp +++ b/modules/gui/qt4/util/qmenuview.cpp @@ -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 ) ) diff --git a/modules/gui/qt4/util/qmenuview.hpp b/modules/gui/qt4/util/qmenuview.hpp index 8564ec1..d63be2c 100644 --- a/modules/gui/qt4/util/qmenuview.hpp +++ b/modules/gui/qt4/util/qmenuview.hpp @@ -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*); _______________________________________________ vlc-commits mailing list [email protected] http://mailman.videolan.org/listinfo/vlc-commits
