libyui-qt  2.46.1
 All Classes Functions Variables
YQDateField.cc
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YQDateField.cc
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 
26 #define YUILogComponent "qt-ui"
27 #include <yui/YUILog.h>
28 
29 #include <qdatetimeedit.h>
30 #include <QVBoxLayout>
31 
32 #include "utf8.h"
33 #include "YQUI.h"
34 #include "YQDateField.h"
35 #include "YQWidgetCaption.h"
36 
37 
38 YQDateField::YQDateField( YWidget * parent, const std::string & label )
39  : QFrame( (QWidget *) parent->widgetRep() )
40  , YDateField( parent, label )
41 {
42  QVBoxLayout* layout = new QVBoxLayout( this );
43  setLayout( layout );
44 
45  setWidgetRep( this );
46  layout->setSpacing( YQWidgetSpacing );
47  layout->setMargin ( YQWidgetMargin );
48 
49  _caption = new YQWidgetCaption( this, fromUTF8( label ) );
50  YUI_CHECK_NEW( _caption );
51  layout->addWidget( _caption );
52 
53  _qt_dateEdit = new QDateEdit( this );
54  YUI_CHECK_NEW( _qt_dateEdit );
55  layout->addWidget( _qt_dateEdit );
56 
57  //_qt_dateEdit->setAutoAdvance( true );
58  _qt_dateEdit->setDisplayFormat( "yyyy-MM-dd" );
59  _qt_dateEdit->setCalendarPopup(true);
60  _caption->setBuddy( _qt_dateEdit );
61 }
62 
63 
65 {
66  // NOP
67 }
68 
69 
71 {
72  return toUTF8( _qt_dateEdit->date().toString( Qt::ISODate ) );
73 }
74 
75 
76 void YQDateField::setValue( const std::string & newValue )
77 {
78  _qt_dateEdit->setDate( QDate::fromString( fromUTF8( newValue ), Qt::ISODate ) );
79 
80 }
81 
82 
83 void YQDateField::setLabel( const std::string & newLabel )
84 {
85  _caption->setText( fromUTF8( newLabel ) );
86  YDateField::setLabel( newLabel );
87 }
88 
89 
90 void YQDateField::setEnabled( bool enabled )
91 {
92  QFrame::setEnabled( enabled );
93  YWidget::setEnabled( enabled );
94 }
95 
96 
98 {
99  return sizeHint().width();
100 }
101 
102 
104 {
105  return sizeHint().height();
106 }
107 
108 
109 void YQDateField::setSize( int newWidth, int newHeight )
110 {
111  resize( newWidth, newHeight );
112 }
113 
114 
116 {
117  _qt_dateEdit->setFocus();
118 
119  return true;
120 }
121 
122 
123 
124 #include "YQDateField.moc"
virtual void setText(const std::string &newText)
virtual void setEnabled(bool enabled)
Definition: YQDateField.cc:90
YQDateField(YWidget *parent, const std::string &label)
Definition: YQDateField.cc:38
virtual void setValue(const std::string &newValue)
Definition: YQDateField.cc:76
virtual int preferredWidth()
Definition: YQDateField.cc:97
virtual void setSize(int newWidth, int newHeight)
Definition: YQDateField.cc:109
virtual bool setKeyboardFocus()
Definition: YQDateField.cc:115
virtual std::string value()
Definition: YQDateField.cc:70
virtual void setLabel(const std::string &label)
Definition: YQDateField.cc:83
virtual int preferredHeight()
Definition: YQDateField.cc:103
virtual ~YQDateField()
Definition: YQDateField.cc:64