24 #include <QChildEvent>
26 #include <QAbstractButton>
27 #include <QSignalMapper>
33 : q(q), clickedMapper(), pressedMapper(), releasedMapper(),
34 currentId( -1 ), nextId( 0 ), wantToBeId( -1 )
36 connect( &clickedMapper, SIGNAL(mapped(
int)), q, SLOT(slotClicked(
int)) );
37 connect( &pressedMapper, SIGNAL(mapped(
int)), q, SIGNAL(
pressed(
int)) );
38 connect( &releasedMapper, SIGNAL(mapped(
int)), q, SIGNAL(
released(
int)) );
41 void slotClicked(
int id );
44 QSignalMapper clickedMapper;
45 QSignalMapper pressedMapper;
46 QSignalMapper releasedMapper;
55 :
QGroupBox( parent ), d( new Private( this ) )
66 if ( !testAttribute( Qt::WA_WState_Polished ) )
75 QAbstractButton* button = 0;
76 for ( ; it != itEnd; ++it )
78 if ( ( it.value() ==
id ) && ( button = qobject_cast<QAbstractButton*>( it.key() ) ) )
80 button->setChecked(
true );
98 if ( event->polished() )
100 QAbstractButton* button = qobject_cast<QAbstractButton*>(
event->child() );
101 if ( !d->btnMap.contains( event->child() ) && button )
103 connect( button, SIGNAL(
clicked()), &d->clickedMapper, SLOT(map()) );
104 d->clickedMapper.setMapping( button, d->nextId );
106 connect( button, SIGNAL(
pressed()), &d->pressedMapper, SLOT(map()) );
107 d->pressedMapper.setMapping( button, d->nextId );
109 connect( button, SIGNAL(
released()), &d->releasedMapper, SLOT(map()) );
110 d->releasedMapper.setMapping( button, d->nextId );
112 d->btnMap[ button ] = d->nextId;
114 if ( d->nextId == d->wantToBeId )
116 d->currentId = d->wantToBeId;
118 button->setChecked(
true );
125 else if ( event->removed() )
129 if ( it != d->btnMap.constEnd() )
131 d->clickedMapper.removeMappings( obj );
132 d->pressedMapper.removeMappings( obj );
133 d->releasedMapper.removeMappings( obj );
135 if ( it.value() == d->currentId )
138 d->btnMap.remove( obj );
143 QGroupBox::childEvent( event );
149 if ( it != d->btnMap.constEnd() )
156 void KButtonGroup::Private::slotClicked(
int id )
163 #include "kbuttongroup.moc"