]> icculus.org git repositories - duncan/yast2-qt4.git/blob - src/YQDateField.cc
restart qt4 porting
[duncan/yast2-qt4.git] / src / YQDateField.cc
1 /*---------------------------------------------------------------------\
2 |                                                                      |
3 |                      __   __    ____ _____ ____                      |
4 |                      \ \ / /_ _/ ___|_   _|___ \                     |
5 |                       \ V / _` \___ \ | |   __) |                    |
6 |                        | | (_| |___) || |  / __/                     |
7 |                        |_|\__,_|____/ |_| |_____|                    |
8 |                                                                      |
9 |                               core system                            |
10 |                                                        (C) SuSE GmbH |
11 \----------------------------------------------------------------------/
12
13   File:         YQDateField.cc
14
15   Author:       Stefan Hundhammer <sh@suse.de>
16
17 /-*/
18
19
20 #define y2log_component "qt-ui"
21 #include <ycp/y2log.h>
22
23 #include <qdatetimeedit.h>
24
25 #include "utf8.h"
26 #include "YQUI.h"
27 #include "YQDateField.h"
28 #include "YQWidgetCaption.h"
29
30
31 YQDateField::YQDateField( YWidget * parent, const string & label )
32     : QVBox( (QWidget *) parent->widgetRep() )
33     , YDateField( parent, label )
34 {
35     setWidgetRep( this );
36     setSpacing( YQWidgetSpacing );
37     setMargin ( YQWidgetMargin  );
38
39     _caption = new YQWidgetCaption( this, fromUTF8( label ) );
40     YUI_CHECK_NEW( _caption );
41
42     _qt_dateEdit = new QDateEdit( this );
43     YUI_CHECK_NEW( _qt_dateEdit );
44
45     _qt_dateEdit->setAutoAdvance( true );
46     _qt_dateEdit->setOrder( QDateEdit::DMY );
47     _caption->setBuddy( _qt_dateEdit );
48 }
49
50
51 YQDateField::~YQDateField()
52 {
53     // NOP
54 }
55
56
57 string YQDateField::value()
58 {
59     return toUTF8( _qt_dateEdit->date().toString( Qt::ISODate ) );
60 }
61
62
63 void YQDateField::setValue( const string & newValue )
64 {
65     _qt_dateEdit->setDate( QDate::fromString( fromUTF8( newValue ), Qt::ISODate ) );
66
67 }
68
69
70 void YQDateField::setLabel( const string & newLabel )
71 {
72     _caption->setText( fromUTF8( newLabel ) );
73     YDateField::setLabel( newLabel );
74 }
75
76
77 void YQDateField::setEnabled( bool enabled )
78 {
79     QVBox::setEnabled( enabled );
80     YWidget::setEnabled( enabled );
81 }
82
83
84 int YQDateField::preferredWidth()
85 {
86     return sizeHint().width();
87 }
88
89
90 int YQDateField::preferredHeight()
91 {
92     return sizeHint().height();
93 }
94
95
96 void YQDateField::setSize( int newWidth, int newHeight )
97 {
98     resize( newWidth, newHeight );
99 }
100
101
102 bool YQDateField::setKeyboardFocus()
103 {
104     _qt_dateEdit->setFocus();
105
106     return true;
107 }
108
109
110
111 #include "YQDateField.moc"