/*
	Copyright (c) 2002 Cornelius Schumacher <schumacher@kde.org>
	Copyright (c) 2002 David Jarvie <software@astrojar.org.uk>
	Copyright (c) 2004 Tobias Koenig <tokoe@kde.org>
	Coypright (c) 2010 Volker Lanz <vl@fidra.de>

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Library General Public
	License as published by the Free Software Foundation; either
	version 2 of the License, or (at your option) any later version.

	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Library General Public License for more details.

	You should have received a copy of the GNU Library General Public License
	along with this library; see the file COPYING.LIB.  If not, write to
	the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
	Boston, MA 02110-1301, USA.
*/

#ifndef KDEPIM_KDATEEDIT_H
#define KDEPIM_KDATEEDIT_H

#include "kdatepickerpopup.h"

#include <QComboBox>
#include <QDateTime>
#include <QEvent>
#include <QMap>
#include <QMouseEvent>

class QEvent;

class KDateEdit : public QComboBox
{
	Q_OBJECT

	public:
		explicit KDateEdit(QWidget* parent = NULL, const char* name = NULL);

	public:
		QDate date() const;
		void setReadOnly(bool readOnly);
		bool isReadOnly() const;
		virtual void showPopup();

	Q_SIGNALS:
		void dateEntered(const QDate& date);
		void dateChanged(const QDate& date);

	public Q_SLOTS:
		void setDate(const QDate& date);

	protected Q_SLOTS:
		void lineEnterPressed();
		void slotTextChanged(const QString&);
		void dateSelected(const QDate&);

	protected:
		virtual bool eventFilter(QObject*, QEvent*);
		virtual void mousePressEvent(QMouseEvent*);
		virtual void focusOutEvent(QFocusEvent*);
		virtual void keyPressEvent(QKeyEvent*);
		virtual bool assignDate(const QDate& date);

	private:
		QDate parseDate(bool* replaced = NULL) const;
		void updateView();

	private:
		KDatePickerPopup* mPopup;
		QDate mDate;
		bool mReadOnly;
		bool mTextChanged;
		bool mDiscardNextMousePress;
};

#endif
