- Don't create layouts with parent. Qt 4.x automatically reparents
[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 #include <QVBoxLayout>
25
26 #include "utf8.h"
27 #include "YQUI.h"
28 #include "YQDateField.h"
29 #include "YQWidgetCaption.h"
30
31
32 YQDateField::YQDateField( YWidget * parent, const string & label )
33     : QFrame( (QWidget *) parent->widgetRep() )
34     , YDateField( parent, label )
35 {
36     QVBoxLayout* layout = new QVBoxLayout( this );
37     setLayout( layout );
38
39     setWidgetRep( this );
40     layout->setSpacing( YQWidgetSpacing );
41     layout->setMargin ( YQWidgetMargin  );
42
43     _caption = new YQWidgetCaption( this, fromUTF8( label ) );
44     YUI_CHECK_NEW( _caption );
45     layout->addWidget( _caption );
46
47     _qt_dateEdit = new QDateEdit( this );
48     YUI_CHECK_NEW( _qt_dateEdit );
49     layout->addWidget( _qt_dateEdit );
50
51     //_qt_dateEdit->setAutoAdvance( true );
52     _qt_dateEdit->setDisplayFormat( "dd.MM.yyyy" );
53     _caption->setBuddy( _qt_dateEdit );
54 }
55
56
57 YQDateField::~YQDateField()
58 {
59     // NOP
60 }
61
62
63 string YQDateField::value()
64 {
65     return toUTF8( _qt_dateEdit->date().toString( Qt::ISODate ) );
66 }
67
68
69 void YQDateField::setValue( const string & newValue )
70 {
71     _qt_dateEdit->setDate( QDate::fromString( fromUTF8( newValue ), Qt::ISODate ) );
72
73 }
74
75
76 void YQDateField::setLabel( const string & newLabel )
77 {
78     _caption->setText( fromUTF8( newLabel ) );
79     YDateField::setLabel( newLabel );
80 }
81
82
83 void YQDateField::setEnabled( bool enabled )
84 {
85     QFrame::setEnabled( enabled );
86     YWidget::setEnabled( enabled );
87 }
88
89
90 int YQDateField::preferredWidth()
91 {
92     return sizeHint().width();
93 }
94
95
96 int YQDateField::preferredHeight()
97 {
98     return sizeHint().height();
99 }
100
101
102 void YQDateField::setSize( int newWidth, int newHeight )
103 {
104     resize( newWidth, newHeight );
105 }
106
107
108 bool YQDateField::setKeyboardFocus()
109 {
110     _qt_dateEdit->setFocus();
111
112     return true;
113 }
114
115
116
117 #include "YQDateField.moc"