From 4318870597dec6518e9f29906656009b8ded9ecd Mon Sep 17 00:00:00 2001 From: san Date: Thu, 28 Jul 2011 14:36:04 +0000 Subject: [PATCH] Added checking of inexistent action in menu backup list. --- src/Qtx/QtxMenu.cxx | 76 +++++++++++++++++++++++++++++++-------------- src/Qtx/QtxMenu.h | 4 ++- 2 files changed, 55 insertions(+), 25 deletions(-) diff --git a/src/Qtx/QtxMenu.cxx b/src/Qtx/QtxMenu.cxx index 2b402f834..5ed9b5676 100644 --- a/src/Qtx/QtxMenu.cxx +++ b/src/Qtx/QtxMenu.cxx @@ -628,6 +628,8 @@ public: Expander( QWidget* = 0 ); virtual ~Expander(); + virtual bool eventFilter( QObject*, QEvent* ); + protected: virtual QWidget* createWidget( QWidget* ); virtual void deleteWidget( QWidget* ); @@ -654,6 +656,14 @@ QtxMenu::Expander::~Expander() { } +bool QtxMenu::Expander::eventFilter( QObject* o, QEvent* e ) +{ + if ( e->type() == QEvent::Enter ) + emit hovered(); + + return QWidgetAction::eventFilter( o, e ); +} + /*! \brief Creates the expanding button when action added into menu. \internal @@ -670,7 +680,7 @@ QWidget* QtxMenu::Expander::createWidget( QWidget* parent ) virtual void resizeEvent( QResizeEvent* e ) { QToolButton::resizeEvent( e ); - + /* QPixmap pix( size() ); QPainter p( &pix ); icon().paint( &p, rect() ); @@ -680,23 +690,25 @@ QWidget* QtxMenu::Expander::createWidget( QWidget* parent ) { QBitmap bm; QImage img = pix.toImage(); - if ( img.hasAlphaChannel() ) - bm = QPixmap::fromImage( img.createAlphaMask() ); - else - bm = QPixmap::fromImage( img.createHeuristicMask() ); - - pix.setMask( bm ); - } + if ( img.hasAlphaChannel() ) + bm = QPixmap::fromImage( img.createAlphaMask() ); + else + bm = QPixmap::fromImage( img.createHeuristicMask() ); - if ( !pix.mask().isNull() ) - setMask( pix.mask() ); + pix.setMask( bm ); + } + + if ( !pix.mask().isNull() ) + setMask( pix.mask() ); + */ }; }; - QToolButton* tb = new Button( parent ); + QToolButton* tb = new QToolButton( parent ); QPixmap pix( expand_button_xpm ); tb->setIcon( pix ); tb->setAutoRaise( true ); + tb->installEventFilter( this ); connect( tb, SIGNAL( clicked( bool ) ), this, SIGNAL( triggered( bool ) ) ); @@ -750,8 +762,7 @@ QtxMenu::QtxMenu( QWidget* parent ) myExpandTimer = new QTimer( this ); myExpandTimer->setSingleShot( true ); - myExpandTimer->setInterval( 0 ); - // myExpandTimer->setInterval( 5000 ); + myExpandTimer->setInterval( 5000 ); connect( menuAction(), SIGNAL( changed() ), this, SLOT( onMenuActionChanged() ) ); @@ -1158,17 +1169,17 @@ void QtxMenu::expandMenu() QSet set = actions().toSet(); - QList bakList = myActionBackup; + ActionList bakList = myActionBackup; - for ( QList::iterator itr = myActionBackup.begin(); itr != myActionBackup.end(); ++itr ) + for ( ActionList::iterator itr = myActionBackup.begin(); itr != myActionBackup.end(); ++itr ) { QAction* a = *itr; - if ( set.contains( a ) ) + if ( !a || set.contains( a ) ) continue; QAction* before = 0; - for ( QList::iterator it = itr; it != myActionBackup.end() && !before; ++it ) + for ( ActionList::iterator it = itr; it != myActionBackup.end() && !before; ++it ) { if ( set.contains( *it ) ) before = *it; @@ -1192,8 +1203,8 @@ void QtxMenu::expandMenu() */ void QtxMenu::collapseMenu() { - ActionList lst = actions(); - ActionList anActionBackup = lst; + QList lst = actions(); + ActionList anActionBackup; QSet visible = collapsedActions(); @@ -1201,6 +1212,8 @@ void QtxMenu::collapseMenu() for ( QList::iterator itr = lst.begin(); itr != lst.end(); ++itr ) { QAction* a = *itr; + anActionBackup.append( a ); + bool vis = a == myExpandAction || a->isSeparator() || visible.contains( a ); if ( !vis && a->isVisible() ) { @@ -1225,7 +1238,13 @@ int QtxMenu::collapseQuantity() const int num = collapseLimit(); if ( collapseLimitMode() == LimitAuto ) { QList lst; - lst = !myActionBackup.isEmpty() ? myActionBackup : actions(); + if ( myActionBackup.isEmpty() ) + lst = actions(); + else { + for ( ActionList::const_iterator itr = myActionBackup.begin(); itr != myActionBackup.end(); ++itr ) + if ( *itr ) + lst.append( *itr ); + } int count = 0; for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) { @@ -1246,8 +1265,14 @@ int QtxMenu::collapseQuantity() const QSet QtxMenu::collapsedActions() const { QList lst; - - lst = !myActionBackup.isEmpty() ? myActionBackup : actions(); + + if ( myActionBackup.isEmpty() ) + lst = actions(); + else { + for ( ActionList::const_iterator itr = myActionBackup.begin(); itr != myActionBackup.end(); ++itr ) + if ( *itr ) + lst.append( *itr ); + } QSet visible; QMap > freqMap; @@ -1326,8 +1351,11 @@ void QtxMenu::onExpandMenu() */ void QtxMenu::onActionHovered( QAction* a ) { - if ( a == myExpandAction && expandingDelay() ) - myShortTimer->start(); + if ( a == myExpandAction ) { + setActiveAction( myExpandAction ); + if ( expandingDelay() ) + myShortTimer->start(); + } else myShortTimer->stop(); } diff --git a/src/Qtx/QtxMenu.h b/src/Qtx/QtxMenu.h index 84f6cb77e..b81a6eb01 100644 --- a/src/Qtx/QtxMenu.h +++ b/src/Qtx/QtxMenu.h @@ -26,6 +26,7 @@ #include "Qtx.h" #include +#include class QWidgetAction; @@ -117,7 +118,8 @@ private: QWidget* topLevelMenu( const QMenu* ) const; private: - typedef QList ActionList; + typedef QPointer ActionPtr; + typedef QList ActionList; typedef QMap PriorityMap; private: -- 2.39.2