17 #include <QMouseEvent>
20 #include <QToolButton>
28 : QDateTimeEdit( parent )
32 mClearButton =
new QToolButton(
this );
34 mClearButton->setCursor( Qt::ArrowCursor );
35 mClearButton->setStyleSheet(
"position: absolute; border: none; padding: 0px;" );
37 connect( mClearButton, SIGNAL( clicked() ),
this, SLOT(
clear() ) );
39 mNullLabel =
new QLineEdit( QSettings().value(
"qgis/nullValue",
"NULL" ).toString(),
this );
40 mNullLabel->setReadOnly(
true );
41 mNullLabel->setStyleSheet(
"position: absolute; border: none; font-style: italic; color: grey;" );
44 setStyleSheet( QString(
"padding-right: %1px;" ).arg( mClearButton->sizeHint().width() + spinButtonWidth() + frameWidth() + 1 ) );
46 QSize msz = minimumSizeHint();
47 setMinimumSize( qMax( msz.width(), mClearButton->sizeHint().height() + frameWidth() * 2 + 2 ),
48 qMax( msz.height(), mClearButton->sizeHint().height() + frameWidth() * 2 + 2 ) );
50 connect(
this, SIGNAL( dateTimeChanged( QDateTime ) ),
this, SLOT( changed( QDateTime ) ) );
60 mNullLabel->setVisible( mAllowNull && mIsNull );
61 mClearButton->setVisible( mAllowNull && !mIsNull );
62 lineEdit()->setVisible( !mAllowNull || !mIsNull );
68 changed( QDateTime() );
69 emit dateTimeChanged( QDateTime() );
74 QRect lerect = rect().adjusted( 0, 0, -spinButtonWidth(), 0 );
75 if ( mAllowNull && mIsNull && lerect.contains( event->pos() ) )
81 void QgsDateTimeEdit::changed(
const QDateTime & dateTime )
83 mIsNull = dateTime.isNull();
84 mNullLabel->setVisible( mAllowNull && mIsNull );
85 mClearButton->setVisible( mAllowNull && !mIsNull );
86 lineEdit()->setVisible( !mAllowNull || !mIsNull );
89 int QgsDateTimeEdit::spinButtonWidth()
const
91 return calendarPopup() ? 25 : 18;
94 int QgsDateTimeEdit::frameWidth()
const
96 return style()->pixelMetric( QStyle::PM_DefaultFrameWidth );
102 if ( !dateTime.isValid() || dateTime.isNull() )
114 if ( mAllowNull && mIsNull )
128 QSize sz = mClearButton->sizeHint();
131 mClearButton->move( rect().right() - frameWidth() - spinButtonWidth() - sz.width(),
132 ( rect().bottom() + 1 - sz.height() ) / 2 );
134 mNullLabel->move( 0, 0 );
135 mNullLabel->setMinimumSize( rect().adjusted( 0, 0, -spinButtonWidth(), 0 ).
size() );
136 mNullLabel->setMaximumSize( rect().adjusted( 0, 0, -spinButtonWidth(), 0 ).
size() );