2 #include "SUIT_ToolButton.h"
4 #include <qpopupmenu.h>
8 SUIT_ToolButton::SUIT_ToolButton( QWidget *parent,
10 bool changeItemAfterClick)
11 : QToolButton( parent, name ),
12 myChangeItemAfterClick( changeItemAfterClick )
18 SUIT_ToolButton::SUIT_ToolButton( const QPixmap & pm,
19 const QString &textLabel,
20 const QString& grouptext,
25 bool changeItemAfterClick)
26 :QToolButton(pm, textLabel, grouptext, receiver, slot, parent, name),
27 myChangeItemAfterClick( changeItemAfterClick )
33 /*!Initialize tool buttons.*/
34 void SUIT_ToolButton::initialize()
37 myPopup = new QPopupMenu( this );
39 connect( myPopup, SIGNAL(activated(int)), SLOT(OnSelectAction(int)) );
43 /*!drawButton is redefined to draw DownArrow*/
44 void SUIT_ToolButton::drawButton( QPainter * p )
46 QToolButton::drawButton(p);
50 QStyle::visualRect(QRect(0, 0, width(), height()), this).rect( &x, &y, &w, &h );
51 style().drawPrimitive( QStyle::PE_ArrowDown,
52 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)
53 colorGroup(), isEnabled() );
57 /*! Add action into popup*/
58 void SUIT_ToolButton::AddAction(QAction* theAction)
60 bool aIsFirst = false;
61 if ( myPopup->count() == 0 )
64 setPixmap(theAction->iconSet().pixmap());
65 setTextLabel(theAction->text());
66 theAction->addTo( myPopup );
67 QMenuItem* aItem = myPopup->findItem(myPopup->idAt(0));
70 mySignal = aItem->signal();
74 theAction->addTo( myPopup );
77 /*! Sets myPopup item with theIndex as current*/
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();
96 * On select action (icon and text set with id = \a theItemID)
98 void SUIT_ToolButton::OnSelectAction(int theItemID)
100 if (myChangeItemAfterClick)
102 // Protection against unexpected null pointers returned
103 if ( myPopup->iconSet(theItemID) )
104 setPixmap(myPopup->iconSet(theItemID)->pixmap());
105 setTextLabel(myPopup->text(theItemID));
106 QMenuItem* aItem = myPopup->findItem(theItemID);
109 mySignal = aItem->signal();
116 /*!On mouse release event.*/
117 void SUIT_ToolButton::mouseReleaseEvent ( QMouseEvent * theEvent)
119 QToolButton::mouseReleaseEvent(theEvent);
120 if (mySignal != NULL)
122 mySignal->activate();