2 #include "SUIT_ToolButton.h"
4 #include <qpopupmenu.h>
7 SUIT_ToolButton::SUIT_ToolButton( QWidget *parent,
9 bool changeItemAfterClick)
10 : QToolButton( parent, name ),
11 myChangeItemAfterClick( changeItemAfterClick )
17 SUIT_ToolButton::SUIT_ToolButton( const QPixmap & pm,
18 const QString &textLabel,
19 const QString& grouptext,
24 bool changeItemAfterClick)
25 :QToolButton(pm, textLabel, grouptext, receiver, slot, parent, name),
26 myChangeItemAfterClick( changeItemAfterClick )
32 //********************************************************************************
33 void SUIT_ToolButton::initialize()
36 myPopup = new QPopupMenu( this );
38 connect( myPopup, SIGNAL(activated(int)), SLOT(OnSelectAction(int)) );
42 //********************************************************************************
43 void SUIT_ToolButton::drawButton( QPainter * p )
45 QToolButton::drawButton(p);
49 QStyle::visualRect(QRect(0, 0, width(), height()), this).rect( &x, &y, &w, &h );
50 style().drawPrimitive( QStyle::PE_ArrowDown,
51 p, QRect(x+w/2+3, y+h/2+3, w/2, h/2), //QRect(x+(w-x)/2, y+(h-y)/2, w, h)
52 colorGroup(), isEnabled() );
56 //********************************************************************************
57 void SUIT_ToolButton::AddAction(QAction* theAction)
59 bool aIsFirst = false;
60 if ( myPopup->count() == 0 )
63 setPixmap(theAction->iconSet().pixmap());
64 setTextLabel(theAction->text());
65 theAction->addTo( myPopup );
66 QMenuItem* aItem = myPopup->findItem(myPopup->idAt(0));
69 mySignal = aItem->signal();
73 theAction->addTo( myPopup );
77 //********************************************************************************
78 void SUIT_ToolButton::SetItem(int theIndex)
80 int anId = myPopup->idAt(theIndex);
83 // Protection against unexpected null pointers returned
84 if ( myPopup->iconSet(anId) )
85 setPixmap(myPopup->iconSet(anId)->pixmap());
86 setTextLabel(myPopup->text(anId));
87 QMenuItem* aItem = myPopup->findItem(anId);
90 mySignal = aItem->signal();
95 //********************************************************************************
96 void SUIT_ToolButton::OnSelectAction(int theItemID)
98 if (myChangeItemAfterClick)
100 // Protection against unexpected null pointers returned
101 if ( myPopup->iconSet(theItemID) )
102 setPixmap(myPopup->iconSet(theItemID)->pixmap());
103 setTextLabel(myPopup->text(theItemID));
104 QMenuItem* aItem = myPopup->findItem(theItemID);
107 mySignal = aItem->signal();
114 //********************************************************************************
115 void SUIT_ToolButton::mouseReleaseEvent ( QMouseEvent * theEvent)
117 QToolButton::mouseReleaseEvent(theEvent);
118 if (mySignal != NULL)
120 mySignal->activate();