From f2f322800988e37bc8c80e26059107634950decc Mon Sep 17 00:00:00 2001 From: san Date: Fri, 22 Jul 2011 13:56:21 +0000 Subject: [PATCH] LimitAuto mode was added. Some minor fixes. --- src/Qtx/QtxMenu.cxx | 85 +++++++++++++++++++++++++++++++-------------- src/Qtx/QtxMenu.h | 2 ++ 2 files changed, 60 insertions(+), 27 deletions(-) diff --git a/src/Qtx/QtxMenu.cxx b/src/Qtx/QtxMenu.cxx index fa639ff4d..2b402f834 100644 --- a/src/Qtx/QtxMenu.cxx +++ b/src/Qtx/QtxMenu.cxx @@ -37,6 +37,8 @@ #include #include +#define HIGHLIGHT_COLLAPSED + //static const char* expand_button_xpm[] = { /* width height num_colors chars_per_pixel */ //" 18 18 16 1", @@ -737,7 +739,7 @@ QtxMenu::QtxMenu( QWidget* parent ) myTitleMode( TitleOff ), myTitleAlign( Qt::AlignVCenter | Qt::AlignLeft ), myLimit( 7 ), - myLimitMode( LimitTotal ), + myLimitMode( LimitAuto ), myExpandAction( 0 ) { myTitleAction = new TitleMgr( this ); @@ -988,45 +990,55 @@ void QtxMenu::setVisible( bool on ) void QtxMenu::paintEvent( QPaintEvent* e ) { +#ifdef HIGHLIGHT_COLLAPSED QPixmap pix( rect().size() ); - pix.fill( this, 0, 0 ); + if ( menuCollapsible() ) { + pix.fill( this, 0, 0 ); + + QPainter::setRedirected( this, &pix ); + } +#endif - QPainter::setRedirected( this, &pix ); QMenu::paintEvent( e ); - QPainter::restoreRedirected( this ); - if ( isTopLevelMenu() ) { - QRgb bg = palette().color( QPalette::Light ).rgb(); - QImage img = pix.toImage(); +#ifdef HIGHLIGHT_COLLAPSED + if ( menuCollapsible() ) { + QPainter::restoreRedirected( this ); - QList lst = actions(); - QSet visible = collapsedActions(); + if ( isTopLevelMenu() ) { + QRgb bg = palette().color( QPalette::Light ).rgb(); + QImage img = pix.toImage(); - for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) { - QAction* a = *it; - QRect r = actionGeometry( a ); + 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 ); + int x, y, w, h; + r.getRect( &x, &y, &w, &h ); - if ( a == myExpandAction || a == myTitleAction || !visible.contains( a ) ) - continue; + if ( a == myExpandAction || a == myTitleAction || !visible.contains( a ) || a == activeAction() ) + 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 ); + 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 ); } - pix = QPixmap::fromImage( img ); + QPainter p( this ); + p.drawPixmap( rect(), pix ); } - - QPainter p( this ); - p.drawPixmap( rect(), pix ); +#endif } /*! @@ -1208,6 +1220,25 @@ void QtxMenu::collapseMenu() myActionBackup = anActionBackup; } +int QtxMenu::collapseQuantity() const +{ + int num = collapseLimit(); + if ( collapseLimitMode() == LimitAuto ) { + QList lst; + lst = !myActionBackup.isEmpty() ? myActionBackup : actions(); + + int count = 0; + for ( QList::iterator it = lst.begin(); it != lst.end(); ++it ) { + QAction* a = *it; + if ( a->isVisible() && !a->isSeparator() ) + count++; + } + + num = qMax( 5, count * 30 / 100 ); + } + return num; +} + /*! \brief Returns the set of the action which will be visible in collapsed state. \internal @@ -1237,8 +1268,8 @@ QSet QtxMenu::collapsedActions() const } } - int limit = collapseLimit(); - if ( collapseLimitMode() == LimitTotal ) + int limit = collapseQuantity(); + if ( collapseLimitMode() != LimitFrequent ) limit -= visible.count(); if ( limit > 0 ) diff --git a/src/Qtx/QtxMenu.h b/src/Qtx/QtxMenu.h index c4da05b47..84f6cb77e 100644 --- a/src/Qtx/QtxMenu.h +++ b/src/Qtx/QtxMenu.h @@ -53,6 +53,7 @@ public: } TitleMode; typedef enum { + LimitAuto, LimitFrequent, LimitTotal } CollapseLimitMode; @@ -108,6 +109,7 @@ private: void collapseMenu(); void updateExpander(); + int collapseQuantity() const; QSet collapsedActions() const; QWidget* topLevelMenu() const; -- 2.39.2