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