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>
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 );
46 preventQGroupBoxAutoEnablement();
52 void YQCheckBoxFrame::setLabel( const string & newLabel )
54 YCheckBoxFrame::setLabel( newLabel );
55 QGroupBox::setTitle( fromUTF8( label() ) );
59 bool YQCheckBoxFrame::value()
61 return _checkBox ? _checkBox->isChecked() : QGroupBox::isChecked();
65 void YQCheckBoxFrame::setValue( bool newValue )
68 _checkBox->setChecked( newValue );
70 setChecked( newValue );
74 void YQCheckBoxFrame::setEnabled( bool enabled )
78 QGroupBox::setEnabled( true );
79 handleChildrenEnablement( value() );
83 QGroupBox::setEnabled( true );
84 YWidget::setChildrenEnabled( false );
87 YWidget::setEnabled( enabled );
91 void YQCheckBoxFrame::preventQGroupBoxAutoEnablement()
94 * This is a nasty hack. But it is necessary because QGroupBox handles its
95 * internal check box too nearsightedly: It forces all children to be
96 * enabled or disabled depending on the status of the check box. The
97 * behaviour cannot be inverted or suppressed.
99 * In some cases, however, it makes sense to let the application decide to
100 * handle that differently. Since the YaST2 UI is a toolkit, we leave this
101 * decision up to the application rather than forcing any specific behaviour.
104 // Find the check box in the child hierarchy (as a direct child)
105 // NOTE findChild search recursively by default
106 _checkBox = QObject::findChild<QCheckBox *>();
110 y2warning( "Can't find QCheckBox child" );
112 connect( this, SIGNAL( toggled ( bool ) ),
113 this, SLOT ( stateChanged( bool ) ) );
118 // Disconnect all signals to this object.
120 // In particular, disconnect the connection from the check box's
121 // 'toggled()' signal to this object's parent class's (private)
122 // setChildrenEnabled() method.
124 disconnect( _checkBox, // sender
127 0 ); // slot (private method in parent class)
129 // Connect the check box directly to this class.
131 connect( _checkBox, SIGNAL( toggled ( bool ) ),
132 this, SLOT ( stateChanged( bool ) ) );
136 void YQCheckBoxFrame::stateChanged( bool newState )
138 y2debug( "new state: %d", newState );
139 handleChildrenEnablement( newState );
142 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
146 void YQCheckBoxFrame::childEvent( QChildEvent * )
148 // Reimplemented to prevent the parent class disabling child widgets
149 // according to its default policy.
151 // y2debug( "ChildEvent" );
156 YQCheckBoxFrame::setSize( int newWidth, int newHeight )
158 resize ( newWidth, newHeight );
162 #warning possibly this hack is not needed
164 int newChildWidth = max ( 0, newWidth - 2 * frameWidth() - 1 );
165 int newChildHeight = max ( 0, newHeight - frameWidth() - fontMetrics().height() - TOP_MARGIN - 1 );
167 firstChild()->setSize( newChildWidth, newChildHeight );
169 QWidget * qChild = (QWidget *) firstChild()->widgetRep();
170 qChild->move( frameWidth(), fontMetrics().height() + TOP_MARGIN );
176 int YQCheckBoxFrame::preferredWidth()
179 int childPreferredWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
181 preferredWidth = max( childPreferredWidth,
182 (10 + fontMetrics().width( title() ) ) );
183 // preferredWidth += 2*frameWidth() + 1;
185 return preferredWidth;
189 int YQCheckBoxFrame::preferredHeight()
191 int preferredHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
192 // preferredHeight += frameWidth() + fontMetrics().height() + TOP_MARGIN + 1;
194 return preferredHeight;
198 bool YQCheckBoxFrame::setKeyboardFocus()
208 #include "YQCheckBoxFrame.moc"