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 );
47 connect( this, SIGNAL( toggled( bool ) ),
48 SLOT( stateChanged( bool ) ) );
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 );
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::stateChanged( bool newState )
93 handleChildrenEnablement( newState );
96 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
99 bool YQCheckBoxFrame::event(QEvent *e)
101 /* now on to something very fishy. The purpose of this widget
102 * is for whatever reason to provide a checkbox with a groupbox
103 * without the children having any connection to it.
105 * So we use this trick to undo everything the base class did
107 QHash<QWidget*, bool> widgetState;
109 QObjectList childList = children();
110 for (int i = 0; i < childList.size(); ++i)
112 QObject *o = childList.at(i);
113 if (o->isWidgetType())
115 QWidget *w = static_cast<QWidget *>(o);
116 widgetState[w] = w->isEnabled();
120 bool ret = QGroupBox::event( e );
122 childList = children();
123 for (int i = 0; i < childList.size(); ++i)
125 QObject *o = childList.at(i);
126 if (o->isWidgetType())
128 QWidget *w = static_cast<QWidget *>(o);
129 if ( widgetState.contains( w ) )
130 w->setEnabled( widgetState[w] );
137 void YQCheckBoxFrame::childEvent( QChildEvent * )
139 // Reimplemented to prevent the parent class disabling child widgets
140 // according to its default policy.
142 // y2debug( "ChildEvent" );
147 YQCheckBoxFrame::setSize( int newWidth, int newHeight )
149 resize ( newWidth, newHeight );
153 int left, top, right, bottom;
154 getContentsMargins( &left, &top, &right, &bottom );
155 int newChildWidth = newWidth - left - right;
156 int newChildHeight = newHeight - bottom - top;
158 firstChild()->setSize( newChildWidth, newChildHeight );
160 QWidget * qChild = (QWidget *) firstChild()->widgetRep();
161 qChild->move( left, top );
166 int YQCheckBoxFrame::preferredWidth()
168 int preferredWidth = hasChildren() ? firstChild()->preferredWidth() : 0;
169 int left, top, right, bottom;
170 getContentsMargins( &left, &top, &right, &bottom );
172 preferredWidth += left + right;
174 return preferredWidth;
178 int YQCheckBoxFrame::preferredHeight()
180 int preferredHeight = hasChildren() ? firstChild()->preferredHeight() : 0;
181 int left, top, right, bottom;
182 getContentsMargins( &left, &top, &right, &bottom );
184 preferredHeight += top + left;
186 return preferredHeight;
190 bool YQCheckBoxFrame::setKeyboardFocus()
200 #include "YQCheckBoxFrame.moc"