libyui-qt  2.46.13
YQDateField.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: YQDateField.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 #include <QVBoxLayout>
31 
32 #include "utf8.h"
33 #include "YQUI.h"
34 #include "YQDateField.h"
35 #include "YEvent.h"
36 #include "YQWidgetCaption.h"
37 
38 
39 YQDateField::YQDateField( YWidget * parent, const std::string & label )
40  : QFrame( (QWidget *) parent->widgetRep() )
41  , YDateField( parent, label )
42 {
43  QVBoxLayout* layout = new QVBoxLayout( this );
44  setLayout( layout );
45 
46  setWidgetRep( this );
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_dateEdit = new QDateEdit( this );
55  YUI_CHECK_NEW( _qt_dateEdit );
56  layout->addWidget( _qt_dateEdit );
57 
58  //_qt_dateEdit->setAutoAdvance( true );
59  _qt_dateEdit->setDisplayFormat( "yyyy-MM-dd" );
60  _qt_dateEdit->setCalendarPopup(true);
61  _caption->setBuddy( _qt_dateEdit );
62 
63  connect( _qt_dateEdit, &QDateEdit::dateChanged,
64  this, &YQDateField::changed);
65 }
66 
67 
69 {
70  // NOP
71 }
72 
73 
75 {
76  return toUTF8( _qt_dateEdit->date().toString( Qt::ISODate ) );
77 }
78 
79 
80 void YQDateField::setValue( const std::string & newValue )
81 {
82  _qt_dateEdit->blockSignals(true);
83  _qt_dateEdit->setDate( QDate::fromString( fromUTF8( newValue ), Qt::ISODate ) );
84  _qt_dateEdit->blockSignals(false);
85 }
86 
87 
88 void YQDateField::setLabel( const std::string & newLabel )
89 {
90  _caption->setText( fromUTF8( newLabel ) );
91  YDateField::setLabel( newLabel );
92 }
93 
94 
95 void YQDateField::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 YQDateField::setSize( int newWidth, int newHeight )
115 {
116  resize( newWidth, newHeight );
117 }
118 
119 
121 {
122  _qt_dateEdit->setFocus();
123 
124  return true;
125 }
126 
127 void YQDateField::changed ( const QDate& )
128 {
129  if ( notify() )
130  YQUI::ui()->sendEvent( new YWidgetEvent( this, YEvent::ValueChanged ) );
131 }
132 
133 #include "YQDateField.moc"
virtual void setText(const std::string &newText)
Change the text and handle visibility: If the new text is empty, hide this widget.
virtual void setEnabled(bool enabled)
Set enabled/disabled state.
Definition: YQDateField.cc:95
YQDateField(YWidget *parent, const std::string &label)
Constructor.
Definition: YQDateField.cc:39
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: YQDateField.cc:80
virtual int preferredWidth()
Preferred width of the widget.
Definition: YQDateField.cc:102
virtual void setSize(int newWidth, int newHeight)
Set the new size of the widget.
Definition: YQDateField.cc:114
virtual bool setKeyboardFocus()
Accept the keyboard focus.
Definition: YQDateField.cc:120
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:486
virtual std::string value()
Get the current value (the text entered by the user or set from the outside) of this input field...
Definition: YQDateField.cc:74
virtual void setLabel(const std::string &label)
Set the label (the caption above the input field).
Definition: YQDateField.cc:88
virtual int preferredHeight()
Preferred height of the widget.
Definition: YQDateField.cc:108
Helper class for captions (labels) above a widget: Takes care of hiding itself when its text is empty...
virtual ~YQDateField()
Destructor.
Definition: YQDateField.cc:68
static YQUI * ui()
Access the global Qt-UI.
Definition: YQUI.h:81