22 #include "dateeditwidget.h"
24 #include "kdatepickerpopup_p.h"
26 #include <kdatepicker.h>
29 #include <klocalizedstring.h>
31 #include <QContextMenuEvent>
32 #include <QHBoxLayout>
34 #include <QToolButton>
36 DateView::DateView( QWidget *parent )
39 setTextInteractionFlags( Qt::TextSelectableByMouse );
40 setFrameShape( QFrame::StyledPanel );
41 setFrameShadow( QFrame::Sunken );
44 void DateView::contextMenuEvent( QContextMenuEvent *event )
46 if ( text().isEmpty() ) {
51 menu.addAction( i18n(
"Remove" ),
this, SLOT(emitSignal()) );
53 menu.exec( event->globalPos() );
56 void DateView::emitSignal()
61 DateEditWidget::DateEditWidget( Type type, QWidget *parent )
62 : QWidget( parent ), mReadOnly( false )
64 QHBoxLayout *layout =
new QHBoxLayout(
this );
65 layout->setMargin( 0 );
68 layout->addWidget( mView );
70 mClearButton =
new QToolButton;
71 if ( layoutDirection() == Qt::LeftToRight ) {
72 mClearButton->setIcon( KIcon( QLatin1String(
"edit-clear-locationbar-rtl" ) ) );
74 mClearButton->setIcon( KIcon( QLatin1String(
"edit-clear-locationbar-ltr" ) ) );
76 layout->addWidget( mClearButton );
78 mSelectButton =
new QToolButton;
79 mSelectButton->setPopupMode( QToolButton::InstantPopup );
81 case General: mSelectButton->setIcon( KIcon( QLatin1String(
"view-calendar-day" ) ) );
break;
82 case Birthday: mSelectButton->setIcon( KIcon( QLatin1String(
"view-calendar-birthday" ) ) );
break;
83 case Anniversary: mSelectButton->setIcon( KIcon( QLatin1String(
"view-calendar-wedding-anniversary" ) ) );
break;
86 layout->addWidget( mSelectButton );
87 setFocusProxy( mSelectButton );
88 setFocusPolicy( Qt::StrongFocus );
91 mSelectButton->setMenu( mMenu );
93 connect( mClearButton, SIGNAL(clicked()), SLOT(resetDate()) );
94 connect( mMenu, SIGNAL(dateChanged(QDate)), SLOT(dateSelected(QDate)) );
95 connect( mView, SIGNAL(resetDate()), SLOT(resetDate()) );
100 DateEditWidget::~DateEditWidget()
104 void DateEditWidget::setDate(
const QDate &date )
107 mMenu->setDate( mDate );
111 QDate DateEditWidget::date()
const
116 void DateEditWidget::setReadOnly(
bool readOnly )
118 mReadOnly = readOnly;
120 mSelectButton->setEnabled( !readOnly );
121 mClearButton->setEnabled( !readOnly );
124 void DateEditWidget::dateSelected(
const QDate &date)
130 void DateEditWidget::resetDate()
136 void DateEditWidget::updateView()
138 if ( mDate.isValid() ) {
139 mView->setText( KGlobal::locale()->formatDate( mDate ) );
140 mClearButton->show();
142 mView->setText( QString() );
143 mClearButton->hide();