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