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