libyui-qt  2.42.4
 All Classes Functions Variables
YQTimeField.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: YQTimeField.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 
31 #include "utf8.h"
32 #include "YQUI.h"
33 #include "YQTimeField.h"
34 #include "YQWidgetCaption.h"
35 #include <QVBoxLayout>
36 
37 
38 YQTimeField::YQTimeField( YWidget * parent, const std::string & label )
39  : QFrame( (QWidget *) parent->widgetRep() )
40  , YTimeField( parent, label )
41 {
42  setWidgetRep( this );
43  QVBoxLayout* layout = new QVBoxLayout( this );
44  setLayout( layout );
45 
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_timeEdit = new QTimeEdit( this );
54  YUI_CHECK_NEW( _qt_timeEdit );
55  _qt_timeEdit->setDisplayFormat( "hh:mm:ss");
56  layout->addWidget( _qt_timeEdit );
57 
58  _caption->setBuddy( _qt_timeEdit );
59 }
60 
61 
63 {
64  // NOP
65 }
66 
67 
69 {
70  return toUTF8( _qt_timeEdit->time().toString( Qt::ISODate ) );
71 }
72 
73 
74 void YQTimeField::setValue( const std::string & newValue )
75 {
76  _qt_timeEdit->setTime( QTime::fromString( fromUTF8( newValue ), Qt::ISODate ) );
77 }
78 
79 
80 void YQTimeField::setLabel( const std::string & newLabel )
81 {
82  _caption->setText( fromUTF8( newLabel ) );
83  YTimeField::setLabel( newLabel );
84 }
85 
86 
87 void YQTimeField::setEnabled( bool enabled )
88 {
89  QFrame::setEnabled( enabled );
90  YWidget::setEnabled( enabled );
91 }
92 
93 
95 {
96  return sizeHint().width();
97 }
98 
99 
101 {
102  return sizeHint().height();
103 }
104 
105 
106 void YQTimeField::setSize( int newWidth, int newHeight )
107 {
108  resize( newWidth, newHeight );
109 }
110 
111 
113 {
114  _qt_timeEdit->setFocus();
115 
116  return true;
117 }
118 
119 
120 #include "YQTimeField.moc"