if ( !wid )
return;
- QList<QAction*> items = wid->actions();
- if ( items.isEmpty() )
- return;
-
- bool action = false;
- for ( int i = 0; i < items.count(); i++ )
+ if ( wid->inherits( "QMenu") || wid->inherits( "QMenuBar") )
{
- QAction* a = items[i];
- if ( a->isSeparator() ) {
- a->setVisible(action);
- action = false;
- }
- else if ( a->isVisible() ) {
- action = true;
- if ( recursive && a->menu() )
- simplifySeparators( a->menu(), recursive );
+ if ( qobject_cast<QMenu*>( wid ) )
+ qobject_cast<QMenu*>( wid )->setSeparatorsCollapsible( true );
+ if ( recursive )
+ {
+ foreach ( QAction* action, wid->actions() )
+ {
+ if ( action->menu() )
+ simplifySeparators( action->menu(), recursive );
+ }
}
}
+ else
+ {
+ QList<QAction*> actions = wid->actions();
+ if ( actions.isEmpty() )
+ return;
- action = false;
- for ( int i = items.count() - 1; i > 0; i-- ) {
- QAction* a = items[i];
- if ( a->isSeparator() ) {
- a->setVisible(action);
- action = false;
+ bool is_action = false;
+ for ( int i = 0; i < actions.count(); i++ )
+ {
+ QAction* action = actions[i];
+ if ( action->isSeparator() )
+ {
+ action->setVisible( is_action );
+ is_action = false;
+ }
+ else if ( action->isVisible() )
+ {
+ is_action = true;
+ }
+ }
+ is_action = false;
+ for ( int i = actions.count() - 1; i > 0; i-- )
+ {
+ QAction* action = actions[i];
+ if ( action->isSeparator() )
+ {
+ action->setVisible( is_action );
+ is_action = false;
+ }
+ else if ( action->isVisible() )
+ {
+ is_action = true;
+ }
}
- else if ( a->isVisible() )
- action = true;
}
}
#include <QWidgetAction>
#include <QLinearGradient>
#include <QAbstractTextDocumentLayout>
-#include <QTimer>
/*!
\class QtxMenu::Title
removeTitle();
insertTitle();
}
-
-/*!
- \brief Paint event
-*/
-void QtxMenu::paintEvent( QPaintEvent* e )
-{
- // Force menu resizing, see resizeAfterRepaint().
- QMenu::paintEvent(e);
- QTimer::singleShot( 0, this, SLOT( resizeAfterRepaint() ) );
-}
-
-void QtxMenu::resizeAfterRepaint()
-{
- // this slot is used as a workaround about annoying problem
- // on some X window System desktops like KDE 5, Unity and other
- // that causes setting incorrect menu's geometry
- // after it appears on a screen.
- resize( sizeHint() );
-}