libyui-qt
2.43.5
|
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: YQDateField.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 #include <QVBoxLayout> 00031 00032 #include "utf8.h" 00033 #include "YQUI.h" 00034 #include "YQDateField.h" 00035 #include "YQWidgetCaption.h" 00036 00037 00038 YQDateField::YQDateField( YWidget * parent, const std::string & label ) 00039 : QFrame( (QWidget *) parent->widgetRep() ) 00040 , YDateField( parent, label ) 00041 { 00042 QVBoxLayout* layout = new QVBoxLayout( this ); 00043 setLayout( layout ); 00044 00045 setWidgetRep( this ); 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_dateEdit = new QDateEdit( this ); 00054 YUI_CHECK_NEW( _qt_dateEdit ); 00055 layout->addWidget( _qt_dateEdit ); 00056 00057 //_qt_dateEdit->setAutoAdvance( true ); 00058 _qt_dateEdit->setDisplayFormat( "yyyy-MM-dd" ); 00059 _qt_dateEdit->setCalendarPopup(true); 00060 _caption->setBuddy( _qt_dateEdit ); 00061 } 00062 00063 00064 YQDateField::~YQDateField() 00065 { 00066 // NOP 00067 } 00068 00069 00070 string YQDateField::value() 00071 { 00072 return toUTF8( _qt_dateEdit->date().toString( Qt::ISODate ) ); 00073 } 00074 00075 00076 void YQDateField::setValue( const std::string & newValue ) 00077 { 00078 _qt_dateEdit->setDate( QDate::fromString( fromUTF8( newValue ), Qt::ISODate ) ); 00079 00080 } 00081 00082 00083 void YQDateField::setLabel( const std::string & newLabel ) 00084 { 00085 _caption->setText( fromUTF8( newLabel ) ); 00086 YDateField::setLabel( newLabel ); 00087 } 00088 00089 00090 void YQDateField::setEnabled( bool enabled ) 00091 { 00092 QFrame::setEnabled( enabled ); 00093 YWidget::setEnabled( enabled ); 00094 } 00095 00096 00097 int YQDateField::preferredWidth() 00098 { 00099 return sizeHint().width(); 00100 } 00101 00102 00103 int YQDateField::preferredHeight() 00104 { 00105 return sizeHint().height(); 00106 } 00107 00108 00109 void YQDateField::setSize( int newWidth, int newHeight ) 00110 { 00111 resize( newWidth, newHeight ); 00112 } 00113 00114 00115 bool YQDateField::setKeyboardFocus() 00116 { 00117 _qt_dateEdit->setFocus(); 00118 00119 return true; 00120 } 00121 00122 00123 00124 #include "YQDateField.moc"