libyui-qt  2.47.1.1
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 "YEvent.h"
35 #include "YQWidgetCaption.h"
36 #include <QVBoxLayout>
37 
38 
39 YQTimeField::YQTimeField( YWidget * parent, const std::string & label )
40  : QFrame( (QWidget *) parent->widgetRep() )
41  , YTimeField( parent, label )
42 {
43  setWidgetRep( this );
44  QVBoxLayout* layout = new QVBoxLayout( this );
45  setLayout( layout );
46 
47  layout->setSpacing( YQWidgetSpacing );
48  layout->setMargin ( YQWidgetMargin );
49 
50  _caption = new YQWidgetCaption( this, fromUTF8( label ) );
51  YUI_CHECK_NEW( _caption );
52  layout->addWidget( _caption );
53 
54  _qt_timeEdit = new QTimeEdit( this );
55  YUI_CHECK_NEW( _qt_timeEdit );
56  _qt_timeEdit->setDisplayFormat( "hh:mm:ss");
57  layout->addWidget( _qt_timeEdit );
58 
59  _caption->setBuddy( _qt_timeEdit );
60 
61  connect( _qt_timeEdit, &QTimeEdit::timeChanged,
62  this, &YQTimeField::changed);
63 }
64 
65 
67 {
68  // NOP
69 }
70 
71 
73 {
74  return toUTF8( _qt_timeEdit->time().toString( Qt::ISODate ) );
75 }
76 
77 
78 void YQTimeField::setValue( const std::string & newValue )
79 {
80  _qt_timeEdit->blockSignals(true);
81  _qt_timeEdit->setTime( QTime::fromString( fromUTF8( newValue ), Qt::ISODate ) );
82  _qt_timeEdit->blockSignals(false);
83 }
84 
85 
86 void YQTimeField::setLabel( const std::string & newLabel )
87 {
88  _caption->setText( fromUTF8( newLabel ) );
89  YTimeField::setLabel( newLabel );
90 }
91 
92 
93 void YQTimeField::setEnabled( bool enabled )
94 {
95  QFrame::setEnabled( enabled );
96  YWidget::setEnabled( enabled );
97 }
98 
99 
101 {
102  return sizeHint().width();
103 }
104 
105 
107 {
108  return sizeHint().height();
109 }
110 
111 
112 void YQTimeField::setSize( int newWidth, int newHeight )
113 {
114  resize( newWidth, newHeight );
115 }
116 
117 
119 {
120  _qt_timeEdit->setFocus();
121 
122  return true;
123 }
124 
125 void YQTimeField::changed ( const QTime& )
126 {
127  if ( notify() )
128  YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
129 }
130 
131 
132 #include "YQTimeField.moc"
virtual void setValue(const std::string &newValue)
Set the current value (the text entered by the user or set from the outside) of this input field...
Definition: YQTimeField.cc:78
virtual void setText(const std::string &newText)
Change the text and handle visibility: If the new text is empty, hide this widget.
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQTimeField.cc:118
YQTimeField(YWidget *parent, const std::string &label)
Constructor.
Definition: YQTimeField.cc:39
virtual ~YQTimeField()
Destructor.
Definition: YQTimeField.cc:66
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQTimeField.cc:106
void sendEvent(YEvent *event)
Widget event handlers (slots) call this when an event occured that should be the answer to a UserInpu...
Definition: YQUI.cc:494
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQTimeField.cc:100
virtual std::string value()
Get the current value (the text entered by the user or set from the outside) of this input field...
Definition: YQTimeField.cc:72
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQTimeField.cc:112
Helper class for captions (labels) above a widget: Takes care of hiding itself when its text is empty...
virtual void setLabel(const std::string &label)
Set the label (the caption above the input field).
Definition: YQTimeField.cc:86
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQTimeField.cc:93
static YQUI * ui()
Access the global Qt-UI.
Definition: YQUI.h:80