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)
106 // NOTE findChild search recursively by default
107 _checkBox = QObject::findChild<QCheckBox *>();
111 y2warning( "Can't find QCheckBox child" );
113 connect( this, SIGNAL( toggled ( bool ) ),
114 this, SLOT ( stateChanged( bool ) ) );
119 // Disconnect all signals to this object.
121 // In particular, disconnect the connection from the check box's
122 // 'toggled()' signal to this object's parent class's (private)
123 // setChildrenEnabled() method.
125 disconnect( _checkBox, // sender
128 0 ); // slot (private method in parent class)
130 // Connect the check box directly to this class.
132 connect( _checkBox, SIGNAL( toggled ( bool ) ),
133 this, SLOT ( stateChanged( bool ) ) );
137 void YQCheckBoxFrame::stateChanged( bool newState )
139 y2debug( "new state: %d", newState );
140 handleChildrenEnablement( newState );
143 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
147 void YQCheckBoxFrame::childEvent( QChildEvent * )
149 // Reimplemented to prevent the parent class disabling child widgets
150 // according to its default policy.
152 // y2debug( "ChildEvent" );
157 YQCheckBoxFrame::setSize( int newWidth, int newHeight )
159 resize ( newWidth, newHeight );
163 #warning possibly this hack is not needed
165 int newChildWidth = max ( 0, newWidth - 2 * frameWidth() - 1 );
166 int newChildHeight = max ( 0, newHeight - frameWidth() - fontMetrics().height() - TOP_MARGIN - 1 );
168 firstChild()->setSize( newChildWidth, newChildHeight );
170 QWidget * qChild = (QWidget *) firstChild()->widgetRep();
171 qChild->move( frameWidth(), fontMetrics().height() + TOP_MARGIN );
177 int YQCheckBoxFrame::preferredWidth()
180 int childPreferredWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
182 preferredWidth = max( childPreferredWidth,
183 (10 + fontMetrics().width( title() ) ) );
184 // preferredWidth += 2*frameWidth() + 1;
186 return preferredWidth;
190 int YQCheckBoxFrame::preferredHeight()
192 int preferredHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
193 // preferredHeight += frameWidth() + fontMetrics().height() + TOP_MARGIN + 1;
195 return preferredHeight;
199 bool YQCheckBoxFrame::setKeyboardFocus()
209 #include "YQCheckBoxFrame.moc"