libyui-qt  2.43.5
/usr/src/RPM/BUILD/libyui-qt-2.43.5/src/YQCheckBox.cc
00001 /*
00002   Copyright (C) 2000-2012 Novell, Inc
00003   This library is free software; you can redistribute it and/or modify
00004   it under the terms of the GNU Lesser General Public License as
00005   published by the Free Software Foundation; either version 2.1 of the
00006   License, or (at your option) version 3.0 of the License. This library
00007   is distributed in the hope that it will be useful, but WITHOUT ANY
00008   WARRANTY; without even the implied warranty of MERCHANTABILITY or
00009   FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00010   License for more details. You should have received a copy of the GNU
00011   Lesser General Public License along with this library; if not, write
00012   to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
00013   Floor, Boston, MA 02110-1301 USA
00014 */
00015 
00016 
00017 /*-/
00018 
00019   File:       YQCheckBox.cc
00020 
00021   Author:     Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 
00026 #include <qcheckbox.h>
00027 #include <QBoxLayout>
00028 #define YUILogComponent "qt-ui"
00029 #include <yui/YUILog.h>
00030 
00031 #include "utf8.h"
00032 #include "YQApplication.h"
00033 #include "YQUI.h"
00034 #include <yui/YEvent.h>
00035 #include "YQCheckBox.h"
00036 
00037 
00038 #define SPACING 8
00039 
00040 
00041 YQCheckBox::YQCheckBox( YWidget *       parent,
00042                         const std::string &     label,
00043                         bool            checked )
00044     : QCheckBox( fromUTF8( label ), (QWidget *) parent->widgetRep() )
00045     , YCheckBox( parent, label )
00046 {
00047     setWidgetRep( this );
00048 
00049     QCheckBox::setChecked( checked );
00050 
00051     connect( this,      SIGNAL( stateChanged( int ) ),
00052              this,              SLOT  ( stateChanged( int ) ) );
00053 }
00054 
00055 
00056 YQCheckBox::~YQCheckBox()
00057 {
00058     // NOP
00059 }
00060 
00061 
00062 YCheckBoxState
00063 YQCheckBox::value()
00064 {
00065     switch ( checkState() )
00066     {
00067         case Qt::Checked:          return YCheckBox_on;
00068         case Qt::Unchecked:        return YCheckBox_off;
00069         case Qt::PartiallyChecked: return YCheckBox_dont_care;
00070     }
00071 
00072     return YCheckBox_off;
00073 }
00074 
00075 
00076 void
00077 YQCheckBox::setValue( YCheckBoxState newValue )
00078 {
00079     switch ( newValue )
00080     {
00081         case YCheckBox_on:
00082             QCheckBox::setChecked( true );
00083             setTristate( false );
00084             break;
00085 
00086         case YCheckBox_off:
00087             QCheckBox::setChecked( false );
00088             setTristate( false );
00089             break;
00090 
00091         case YCheckBox_dont_care:
00092             QCheckBox::setTristate( true );
00093             setCheckState(Qt::PartiallyChecked);
00094             break;
00095     }
00096 }
00097 
00098 
00099 void YQCheckBox::setLabel( const std::string & label )
00100 {
00101     setText( fromUTF8( label ) );
00102     YCheckBox::setLabel( label );
00103 }
00104 
00105 
00106 void YQCheckBox::setUseBoldFont( bool useBold )
00107 {
00108     setFont( useBold ?
00109                            YQUI::yqApp()->boldFont() :
00110                            YQUI::yqApp()->currentFont() );
00111 
00112     YCheckBox::setUseBoldFont( useBold );
00113 }
00114 
00115 
00116 void YQCheckBox::setEnabled( bool enabled )
00117 {
00118     QCheckBox::setEnabled( enabled );
00119     YWidget::setEnabled( enabled );
00120 }
00121 
00122 
00123 int YQCheckBox::preferredWidth()
00124 {
00125     return 2*SPACING + sizeHint().width();
00126 }
00127 
00128 
00129 int YQCheckBox::preferredHeight()
00130 {
00131     return sizeHint().height();
00132 }
00133 
00134 
00135 void YQCheckBox::setSize( int newWidth, int newHeight )
00136 {
00137     resize( newWidth, newHeight );
00138 }
00139 
00140 
00141 bool YQCheckBox::setKeyboardFocus()
00142 {
00143     setFocus();
00144 
00145     return true;
00146 }
00147 
00148 
00149 void YQCheckBox::stateChanged( int newState )
00150 {
00151     // yuiMilestone() << "new state: " << newState << std::endl;
00152 
00153     if ( notify() )
00154         YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
00155 }
00156 
00157 
00158 #include "YQCheckBox.moc"
 All Classes Functions Variables