libyui-qt  2.43.5
/usr/src/RPM/BUILD/libyui-qt-2.43.5/src/YQTimeField.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:         YQTimeField.cc
00020 
00021   Author:       Stefan Hundhammer <sh@suse.de>
00022 
00023 /-*/
00024 
00025 
00026 #define YUILogComponent "qt-ui"
00027 #include <yui/YUILog.h>
00028 
00029 #include <qdatetimeedit.h>
00030 
00031 #include "utf8.h"
00032 #include "YQUI.h"
00033 #include "YQTimeField.h"
00034 #include "YQWidgetCaption.h"
00035 #include <QVBoxLayout>
00036 
00037 
00038 YQTimeField::YQTimeField( YWidget * parent, const std::string & label )
00039     : QFrame( (QWidget *) parent->widgetRep() )
00040     , YTimeField( parent, label )
00041 {
00042     setWidgetRep( this );
00043     QVBoxLayout* layout = new QVBoxLayout( this );
00044     setLayout( layout );
00045 
00046     layout->setSpacing( YQWidgetSpacing );
00047     layout->setMargin ( YQWidgetMargin );
00048 
00049     _caption = new YQWidgetCaption( this, fromUTF8( label ) );
00050     YUI_CHECK_NEW( _caption );
00051     layout->addWidget( _caption );
00052 
00053     _qt_timeEdit = new QTimeEdit( this );
00054     YUI_CHECK_NEW( _qt_timeEdit );
00055     _qt_timeEdit->setDisplayFormat( "hh:mm:ss");
00056     layout->addWidget( _qt_timeEdit );
00057 
00058     _caption->setBuddy( _qt_timeEdit );
00059 }
00060 
00061 
00062 YQTimeField::~YQTimeField()
00063 {
00064     // NOP
00065 }
00066 
00067 
00068 string YQTimeField::value()
00069 {
00070     return toUTF8( _qt_timeEdit->time().toString( Qt::ISODate ) );
00071 }
00072 
00073 
00074 void YQTimeField::setValue( const std::string & newValue )
00075 {
00076     _qt_timeEdit->setTime(  QTime::fromString( fromUTF8( newValue ), Qt::ISODate ) );
00077 }
00078 
00079 
00080 void YQTimeField::setLabel( const std::string & newLabel )
00081 {
00082     _caption->setText( fromUTF8( newLabel ) );
00083     YTimeField::setLabel( newLabel );
00084 }
00085 
00086 
00087 void YQTimeField::setEnabled( bool enabled )
00088 {
00089     QFrame::setEnabled( enabled );
00090     YWidget::setEnabled( enabled );
00091 }
00092 
00093 
00094 int YQTimeField::preferredWidth()
00095 {
00096     return sizeHint().width();
00097 }
00098 
00099 
00100 int YQTimeField::preferredHeight()
00101 {
00102     return sizeHint().height();
00103 }
00104 
00105 
00106 void YQTimeField::setSize( int newWidth, int newHeight )
00107 {
00108     resize( newWidth, newHeight );
00109 }
00110 
00111 
00112 bool YQTimeField::setKeyboardFocus()
00113 {
00114     _qt_timeEdit->setFocus();
00115 
00116     return true;
00117 }
00118 
00119 
00120 #include "YQTimeField.moc"
 All Classes Functions Variables