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>
29 #include "YQCheckBoxFrame.h"
34 YQCheckBoxFrame::YQCheckBoxFrame( YWidget * parent,
37 : QGroupBox( (QWidget *) parent->widgetRep() )
38 , YCheckBoxFrame( parent, label, checked)
40 setWidgetRep ( this );
41 QGroupBox::setTitle( fromUTF8( label ) );
42 QGroupBox::setCheckable( true );
43 preventQGroupBoxAutoEnablement();
49 void YQCheckBoxFrame::setLabel( const string & newLabel )
51 YCheckBoxFrame::setLabel( newLabel );
52 QGroupBox::setTitle( fromUTF8( label() ) );
56 bool YQCheckBoxFrame::value()
58 return _checkBox ? _checkBox->isChecked() : QGroupBox::isChecked();
62 void YQCheckBoxFrame::setValue( bool newValue )
65 _checkBox->setChecked( newValue );
67 setChecked( newValue );
71 void YQCheckBoxFrame::setEnabled( bool enabled )
75 QFrame::setEnabled( true );
76 handleChildrenEnablement( value() );
80 QFrame::setEnabled( true );
81 YWidget::setChildrenEnabled( false );
84 YWidget::setEnabled( enabled );
88 void YQCheckBoxFrame::preventQGroupBoxAutoEnablement()
91 * This is a nasty hack. But it is necessary because QGroupBox handles its
92 * internal check box too nearsightedly: It forces all children to be
93 * enabled or disabled depending on the status of the check box. The
94 * behaviour cannot be inverted or suppressed.
96 * In some cases, however, it makes sense to let the application decide to
97 * handle that differently. Since the YaST2 UI is a toolkit, we leave this
98 * decision up to the application rather than forcing any specific behaviour.
101 // Find the check box in the child hierarchy (as a direct child)
103 _checkBox = dynamic_cast<QCheckBox *>( QObject::child( 0, // objName
104 "QCheckBox", // inheritsClass
105 false ) ); // recursive
109 y2warning( "Can't find QCheckBox child" );
111 connect( this, SIGNAL( toggled ( bool ) ),
112 this, SLOT ( stateChanged( bool ) ) );
117 // Disconnect all signals to this object.
119 // In particular, disconnect the connection from the check box's
120 // 'toggled()' signal to this object's parent class's (private)
121 // setChildrenEnabled() method.
123 disconnect( _checkBox, // sender
126 0 ); // slot (private method in parent class)
128 // Connect the check box directly to this class.
130 connect( _checkBox, SIGNAL( toggled ( bool ) ),
131 this, SLOT ( stateChanged( bool ) ) );
135 void YQCheckBoxFrame::stateChanged( bool newState )
137 y2debug( "new state: %d", newState );
138 handleChildrenEnablement( newState );
141 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
145 void YQCheckBoxFrame::childEvent( QChildEvent * )
147 // Reimplemented to prevent the parent class disabling child widgets
148 // according to its default policy.
150 // y2debug( "ChildEvent" );
155 YQCheckBoxFrame::setSize( int newWidth, int newHeight )
157 resize ( newWidth, newHeight );
161 int newChildWidth = max ( 0, newWidth - 2 * frameWidth() - 1 );
162 int newChildHeight = max ( 0, newHeight - frameWidth() - fontMetrics().height() - TOP_MARGIN - 1 );
164 firstChild()->setSize( newChildWidth, newChildHeight );
166 QWidget * qChild = (QWidget *) firstChild()->widgetRep();
167 qChild->move( frameWidth(), fontMetrics().height() + TOP_MARGIN );
172 int YQCheckBoxFrame::preferredWidth()
175 int childPreferredWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
177 preferredWidth = max( childPreferredWidth,
178 (10 + fontMetrics().width( title() ) ) );
179 preferredWidth += 2*frameWidth() + 1;
181 return preferredWidth;
185 int YQCheckBoxFrame::preferredHeight()
187 int preferredHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
188 preferredHeight += frameWidth() + fontMetrics().height() + TOP_MARGIN + 1;
190 return preferredHeight;
194 bool YQCheckBoxFrame::setKeyboardFocus()
196 QGroupBox::setFocus();
204 #include "YQCheckBoxFrame.moc"