1 /*---------------------------------------------------------------------\
3 | __ __ ____ _____ ____ |
4 | \ \ / /_ _/ ___|_ _|___ \ |
5 | \ V / _` \___ \ | | __) | |
6 | | | (_| |___) || | / __/ |
7 | |_|\__,_|____/ |_| |_____| |
11 \----------------------------------------------------------------------/
15 Author: Stefan Hundhammer <sh@suse.de>
20 #include <qcheckbox.h>
21 #include <q3boxlayout.h>
22 #define y2log_component "qt-ui"
23 #include <ycp/y2log.h>
26 #include "YQApplication.h"
29 #include "YQCheckBox.h"
35 YQCheckBox::YQCheckBox( YWidget * parent,
38 : Q3GroupBox( (QWidget *) parent->widgetRep() )
39 , YCheckBox( parent, label )
42 setFrameStyle( NoFrame );
44 QBoxLayout * layout = new QBoxLayout( this, QBoxLayout::LeftToRight );
46 _qt_checkBox = new QCheckBox( fromUTF8( label ), this );
47 YUI_CHECK_NEW( _qt_checkBox );
49 layout->addSpacing( SPACING );
50 layout->addWidget( _qt_checkBox );
51 layout->addSpacing( SPACING );
53 _qt_checkBox->setChecked( checked );
55 connect( _qt_checkBox, SIGNAL( stateChanged( int ) ),
56 this, SLOT ( stateChanged( int ) ) );
60 YQCheckBox::~YQCheckBox()
69 switch ( _qt_checkBox->checkState() )
71 case Qt::Checked: return YCheckBox_on;
72 case Qt::Unchecked: return YCheckBox_off;
73 case Qt::PartiallyChecked: return YCheckBox_dont_care;
81 YQCheckBox::setValue( YCheckBoxState newValue )
86 _qt_checkBox->setChecked( true );
87 _qt_checkBox->setTristate( false );
91 _qt_checkBox->setChecked( false );
92 _qt_checkBox->setTristate( false );
95 case YCheckBox_dont_care:
96 _qt_checkBox->setTristate( true );
97 _qt_checkBox->setNoChange();
103 void YQCheckBox::setLabel( const string & label )
105 _qt_checkBox->setText( fromUTF8( label ) );
106 YCheckBox::setLabel( label );
110 void YQCheckBox::setUseBoldFont( bool useBold )
112 _qt_checkBox->setFont( useBold ?
113 YQUI::yqApp()->boldFont() :
114 YQUI::yqApp()->currentFont() );
116 YCheckBox::setUseBoldFont( useBold );
120 void YQCheckBox::setEnabled( bool enabled )
122 _qt_checkBox->setEnabled( enabled );
123 YWidget::setEnabled( enabled );
127 int YQCheckBox::preferredWidth()
129 return 2*SPACING + _qt_checkBox->sizeHint().width();
133 int YQCheckBox::preferredHeight()
135 return _qt_checkBox->sizeHint().height();
139 void YQCheckBox::setSize( int newWidth, int newHeight )
141 _qt_checkBox->resize( newWidth - 2*SPACING, newHeight );
142 resize( newWidth, newHeight );
146 bool YQCheckBox::setKeyboardFocus()
148 _qt_checkBox->setFocus();
154 void YQCheckBox::stateChanged( int newState )
156 // y2milestone( "new state: %d", newState );
159 YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
163 #include "YQCheckBox.moc"