[vlc-commits] Qt: limit the number of entries in the right click to 25
Jean-Baptiste Kempf
git at videolan.org
Mon Feb 20 19:12:29 CET 2012
vlc | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Mon Feb 20 19:12:02 2012 +0100| [6241fbf7201744c8eafd32b660ba1156f14a758d] | committer: Jean-Baptiste Kempf
Qt: limit the number of entries in the right click to 25
Close #6103
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=6241fbf7201744c8eafd32b660ba1156f14a758d
---
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 a242593..f9b97b1 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*);
More information about the vlc-commits
mailing list