libyui-qt  2.43.5
/usr/src/RPM/BUILD/libyui-qt-2.43.5/src/YQIntField.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:       YQIntField.cc
00020 
00021   Author:     Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 
00026 #include <qspinbox.h>
00027 
00028 #define YUILogComponent "qt-ui"
00029 #include <yui/YUILog.h>
00030 
00031 #include "utf8.h"
00032 #include "YQUI.h"
00033 #include <yui/YEvent.h>
00034 #include "YQIntField.h"
00035 #include "YQSignalBlocker.h"
00036 #include "YQWidgetCaption.h"
00037 #include <QVBoxLayout>
00038 
00039 YQIntField::YQIntField( YWidget *       parent,
00040                         const std::string &     label,
00041                         int             minValue,
00042                         int             maxValue,
00043                         int             initialValue )
00044     : QFrame( (QWidget *) parent->widgetRep() )
00045     , YIntField( parent, label, minValue, maxValue )
00046 {
00047     QVBoxLayout* layout = new QVBoxLayout( this );
00048     setLayout( layout );
00049 
00050     setWidgetRep( this );
00051 
00052     layout->setSpacing( YQWidgetSpacing );
00053     layout->setMargin( YQWidgetMargin );
00054 
00055     _caption    = new YQWidgetCaption( this, label );
00056     YUI_CHECK_NEW( _caption );
00057     layout->addWidget( _caption );
00058 
00059     _qt_spinBox = new QSpinBox(this);
00060     _qt_spinBox->setMinimum(minValue);
00061     _qt_spinBox->setMaximum(maxValue);
00062     _qt_spinBox->setSingleStep(1);
00063 
00064     YUI_CHECK_NEW( _qt_spinBox );
00065     layout->addWidget( _qt_spinBox );
00066 
00067     _qt_spinBox->setValue( initialValue );
00068 
00069     _caption->setBuddy( _qt_spinBox );
00070 
00071     setValue( initialValue );
00072 
00073     connect( _qt_spinBox, SIGNAL( valueChanged    ( int ) ),
00074              this,        SLOT  ( valueChangedSlot( int ) ) );
00075 }
00076 
00077 
00078 YQIntField::~YQIntField()
00079 {
00080     // NOP
00081 }
00082 
00083 
00084 int
00085 YQIntField::value()
00086 {
00087     return _qt_spinBox->value();
00088 }
00089 
00090 
00091 void
00092 YQIntField::setValueInternal( int newValue )
00093 {
00094     YQSignalBlocker sigBlocker( _qt_spinBox );
00095     _qt_spinBox->setValue( newValue );
00096 }
00097 
00098 
00099 void
00100 YQIntField::valueChangedSlot( int newValue )
00101 {
00102     if ( notify() )
00103         YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
00104     emit valueChanged( newValue );
00105 }
00106 
00107 
00108 void
00109 YQIntField::setLabel( const std::string & newLabel )
00110 {
00111     YIntField::setLabel( newLabel );
00112     _caption->setText( newLabel );
00113 }
00114 
00115 
00116 void
00117 YQIntField::setEnabled( bool enabled )
00118 {
00119     _caption->setEnabled  ( enabled );
00120     _qt_spinBox->setEnabled( enabled );
00121     YWidget::setEnabled( enabled );
00122 }
00123 
00124 
00125 int
00126 YQIntField::preferredWidth()
00127 {
00128     return sizeHint().width();
00129 }
00130 
00131 
00132 int
00133 YQIntField::preferredHeight()
00134 {
00135     return sizeHint().height();
00136 }
00137 
00138 
00139 void
00140 YQIntField::setSize( int newWidth, int newHeight )
00141 {
00142     resize( newWidth, newHeight );
00143 }
00144 
00145 
00146 bool
00147 YQIntField::setKeyboardFocus()
00148 {
00149     _qt_spinBox->setFocus();
00150 
00151     return true;
00152 }
00153 
00154 
00155 #include "YQIntField.moc"
 All Classes Functions Variables