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>
24 #include <QVBoxLayout>
32 #include "YQCheckBoxFrame.h"
37 YQCheckBoxFrame::YQCheckBoxFrame( YWidget * parent,
40 : QGroupBox( (QWidget *) parent->widgetRep() )
41 , YCheckBoxFrame( parent, label, checked)
43 setWidgetRep ( this );
44 QGroupBox::setTitle( fromUTF8( label ) );
45 QGroupBox::setCheckable( true );
51 void YQCheckBoxFrame::setLabel( const string & newLabel )
53 YCheckBoxFrame::setLabel( newLabel );
54 QGroupBox::setTitle( fromUTF8( label() ) );
58 bool YQCheckBoxFrame::value()
60 return _checkBox ? _checkBox->isChecked() : QGroupBox::isChecked();
64 void YQCheckBoxFrame::setValue( bool newValue )
67 _checkBox->setChecked( newValue );
69 setChecked( newValue );
72 void YQCheckBoxFrame::setEnabled( bool enabled )
76 QGroupBox::setEnabled( true );
77 handleChildrenEnablement( value() );
81 QGroupBox::setEnabled( true );
82 YWidget::setChildrenEnabled( false );
85 YWidget::setEnabled( enabled );
89 void YQCheckBoxFrame::stateChanged( bool newState )
91 y2debug( "new state: %d", newState );
92 handleChildrenEnablement( newState );
95 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
99 void YQCheckBoxFrame::childEvent( QChildEvent * )
101 // Reimplemented to prevent the parent class disabling child widgets
102 // according to its default policy.
104 // y2debug( "ChildEvent" );
109 YQCheckBoxFrame::setSize( int newWidth, int newHeight )
111 resize ( newWidth, newHeight );
115 int left, top, right, bottom;
116 getContentsMargins( &left, &top, &right, &bottom );
117 int newChildWidth = newWidth - left - right;
118 int newChildHeight = newHeight - bottom - top;
120 firstChild()->setSize( newChildWidth, newChildHeight );
122 QWidget * qChild = (QWidget *) firstChild()->widgetRep();
123 qChild->move( left, top );
128 int YQCheckBoxFrame::preferredWidth()
131 int childPreferredWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
133 preferredWidth = max( childPreferredWidth,
134 (10 + fontMetrics().width( title() ) ) );
135 int left, top, right, bottom;
136 getContentsMargins( &left, &top, &right, &bottom );
138 preferredWidth += left + right;
140 return preferredWidth;
144 int YQCheckBoxFrame::preferredHeight()
146 int preferredHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
147 int left, top, right, bottom;
148 getContentsMargins( &left, &top, &right, &bottom );
150 preferredHeight += top + left;
152 return preferredHeight;
156 bool YQCheckBoxFrame::setKeyboardFocus()
166 #include "YQCheckBoxFrame.moc"