From: san Date: Wed, 20 Jul 2011 12:33:14 +0000 (+0000) Subject: Menu actions visible in collapsed state were highlited. X-Git-Tag: V5_1_14~12 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=480d6531a1e45ef62e3b5b72f6915ba03f10c996;p=modules%2Fgui.git Menu actions visible in collapsed state were highlited. --- diff --git a/src/Qtx/QtxMenu.cxx b/src/Qtx/QtxMenu.cxx index 40bc2bac3..fa639ff4d 100644 --- a/src/Qtx/QtxMenu.cxx +++ b/src/Qtx/QtxMenu.cxx @@ -748,7 +748,8 @@ QtxMenu::QtxMenu( QWidget* parent ) myExpandTimer = new QTimer( this ); myExpandTimer->setSingleShot( true ); - myExpandTimer->setInterval( 5000 ); + myExpandTimer->setInterval( 0 ); + // myExpandTimer->setInterval( 5000 ); connect( menuAction(), SIGNAL( changed() ), this, SLOT( onMenuActionChanged() ) ); @@ -985,6 +986,49 @@ void QtxMenu::setVisible( bool on ) } } +void QtxMenu::paintEvent( QPaintEvent* e ) +{ + QPixmap pix( rect().size() ); + pix.fill( this, 0, 0 ); + + QPainter::setRedirected( this, &pix ); + QMenu::paintEvent( e ); + QPainter::restoreRedirected( this ); + + if ( isTopLevelMenu() ) { + QRgb bg = palette().color( QPalette::Light ).rgb(); + QImage img = pix.toImage(); + + QList lst = actions(); + QSet visible = collapsedActions(); + + for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) { + QAction* a = *it; + QRect r = actionGeometry( a ); + + int x, y, w, h; + r.getRect( &x, &y, &w, &h ); + + if ( a == myExpandAction || a == myTitleAction || !visible.contains( a ) ) + continue; + + QRgb rc = img.pixel( x, y ); + for ( int i = 0; i < w - 1; i++ ) { + for ( int j = 0; j < h; j++ ) { + if ( img.pixel( x + i, y + j ) == rc ) { + img.setPixel( x + i, y + j, bg ); + } + } + } + } + + pix = QPixmap::fromImage( img ); + } + + QPainter p( this ); + p.drawPixmap( rect(), pix ); +} + /*! \brief Reimplemented for internal reasons. Activation the expand item by keys perform menu expanding. @@ -1136,23 +1180,53 @@ void QtxMenu::expandMenu() */ void QtxMenu::collapseMenu() { - QList lst = actions(); + ActionList lst = actions(); + ActionList anActionBackup = lst; - QSet visible; - QMap > freqMap; + QSet visible = collapsedActions(); + + int hidden = 0; + for ( QList::iterator itr = lst.begin(); itr != lst.end(); ++itr ) + { + QAction* a = *itr; + bool vis = a == myExpandAction || a->isSeparator() || visible.contains( a ); + if ( !vis && a->isVisible() ) + { + hidden++; + removeAction( a ); + } + } + + if ( myExpandAction ) + myExpandAction->setVisible( hidden ); + + updateExpander(); - ActionList anActionBackup; - QList< QPair > freqList; + if ( expandingDelay() > 0 ) + myExpandTimer->start(); + + myActionBackup = anActionBackup; +} + +/*! + \brief Returns the set of the action which will be visible in collapsed state. + \internal +*/ +QSet QtxMenu::collapsedActions() const +{ + QList lst; + + lst = !myActionBackup.isEmpty() ? myActionBackup : actions(); + QSet visible; + QMap > freqMap; for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) { QAction* a = *it; - anActionBackup.append( a ); - if ( a->isSeparator() || !a->isVisible() ) continue; - int priority = actionPriority( a ); + int priority = a == defaultAction() ? -1 : actionPriority( a ); if ( priority < 0 ) visible.insert( a ); else @@ -1179,27 +1253,7 @@ void QtxMenu::collapseMenu() } } - int hidden = 0; - for ( QList::iterator itr = lst.begin(); itr != lst.end(); ++itr ) - { - QAction* a = *itr; - bool vis = a == myExpandAction || a->isSeparator() || visible.contains( a ); - if ( !vis && a->isVisible() ) - { - hidden++; - removeAction( a ); - } - } - - if ( myExpandAction ) - myExpandAction->setVisible( hidden ); - - updateExpander(); - - if ( expandingDelay() > 0 ) - myExpandTimer->start(); - - myActionBackup = anActionBackup; + return visible; } /*! diff --git a/src/Qtx/QtxMenu.h b/src/Qtx/QtxMenu.h index 40a9be4a3..c4da05b47 100644 --- a/src/Qtx/QtxMenu.h +++ b/src/Qtx/QtxMenu.h @@ -96,6 +96,7 @@ private slots: void onActionTriggered( QAction* ); protected: + virtual void paintEvent( QPaintEvent* ); virtual void keyPressEvent( QKeyEvent* ); private: @@ -107,6 +108,8 @@ private: void collapseMenu(); void updateExpander(); + QSet collapsedActions() const; + QWidget* topLevelMenu() const; bool isTopLevelMenu() const; QWidget* topLevelMenu( const QMenu* ) const;