1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
13 File: YQCheckBoxFrame.cc
15 Author: Stefan Hundhammer <sh@suse.de>
20 #define y2log_component "qt-ui"
21 #include <ycp/y2log.h>
22 #include <qcheckbox.h>
33 #include "YQCheckBoxFrame.h"
38 YQCheckBoxFrame::YQCheckBoxFrame( YWidget * parent,
41 : QGroupBox( (QWidget *) parent->widgetRep() )
42 , YCheckBoxFrame( parent, label, checked)
44 setWidgetRep ( this );
45 QGroupBox::setTitle( fromUTF8( label ) );
46 QGroupBox::setCheckable( true );
47 preventQGroupBoxAutoEnablement();
53 void YQCheckBoxFrame::setLabel( const string & newLabel )
55 YCheckBoxFrame::setLabel( newLabel );
56 QGroupBox::setTitle( fromUTF8( label() ) );
60 bool YQCheckBoxFrame::value()
62 return _checkBox ? _checkBox->isChecked() : QGroupBox::isChecked();
66 void YQCheckBoxFrame::setValue( bool newValue )
69 _checkBox->setChecked( newValue );
71 setChecked( newValue );
75 void YQCheckBoxFrame::setEnabled( bool enabled )
79 QGroupBox::setEnabled( true );
80 handleChildrenEnablement( value() );
84 QGroupBox::setEnabled( true );
85 YWidget::setChildrenEnabled( false );
88 YWidget::setEnabled( enabled );
92 void YQCheckBoxFrame::preventQGroupBoxAutoEnablement()
95 * This is a nasty hack. But it is necessary because QGroupBox handles its
96 * internal check box too nearsightedly: It forces all children to be
97 * enabled or disabled depending on the status of the check box. The
98 * behaviour cannot be inverted or suppressed.
100 * In some cases, however, it makes sense to let the application decide to
101 * handle that differently. Since the YaST2 UI is a toolkit, we leave this
102 * decision up to the application rather than forcing any specific behaviour.
105 // Find the check box in the child hierarchy (as a direct child)
107 _checkBox = dynamic_cast<QCheckBox *>( QObject::child( 0, // objName
108 "QCheckBox", // inheritsClass
109 false ) ); // recursive
113 y2warning( "Can't find QCheckBox child" );
115 connect( this, SIGNAL( toggled ( bool ) ),
116 this, SLOT ( stateChanged( bool ) ) );
121 // Disconnect all signals to this object.
123 // In particular, disconnect the connection from the check box's
124 // 'toggled()' signal to this object's parent class's (private)
125 // setChildrenEnabled() method.
127 disconnect( _checkBox, // sender
130 0 ); // slot (private method in parent class)
132 // Connect the check box directly to this class.
134 connect( _checkBox, SIGNAL( toggled ( bool ) ),
135 this, SLOT ( stateChanged( bool ) ) );
139 void YQCheckBoxFrame::stateChanged( bool newState )
141 y2debug( "new state: %d", newState );
142 handleChildrenEnablement( newState );
145 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
149 void YQCheckBoxFrame::childEvent( QChildEvent * )
151 // Reimplemented to prevent the parent class disabling child widgets
152 // according to its default policy.
154 // y2debug( "ChildEvent" );
159 YQCheckBoxFrame::setSize( int newWidth, int newHeight )
161 resize ( newWidth, newHeight );
165 #warning possibly this hack is not needed
167 int newChildWidth = max ( 0, newWidth - 2 * frameWidth() - 1 );
168 int newChildHeight = max ( 0, newHeight - frameWidth() - fontMetrics().height() - TOP_MARGIN - 1 );
170 firstChild()->setSize( newChildWidth, newChildHeight );
172 QWidget * qChild = (QWidget *) firstChild()->widgetRep();
173 qChild->move( frameWidth(), fontMetrics().height() + TOP_MARGIN );
179 int YQCheckBoxFrame::preferredWidth()
182 int childPreferredWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
184 preferredWidth = max( childPreferredWidth,
185 (10 + fontMetrics().width( title() ) ) );
186 // preferredWidth += 2*frameWidth() + 1;
188 return preferredWidth;
192 int YQCheckBoxFrame::preferredHeight()
194 int preferredHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
195 // preferredHeight += frameWidth() + fontMetrics().height() + TOP_MARGIN + 1;
197 return preferredHeight;
201 bool YQCheckBoxFrame::setKeyboardFocus()
211 #include "YQCheckBoxFrame.moc"