summaryrefslogtreecommitdiffstats
path: root/kfind/kdatecombo.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit4aed2c8219774f5d797760606b8489a92ddc5163 (patch)
tree3f8c130f7d269626bf6a9447407ef6c35954426a /kfind/kdatecombo.cpp
downloadtdebase-4aed2c8219774f5d797760606b8489a92ddc5163.tar.gz
tdebase-4aed2c8219774f5d797760606b8489a92ddc5163.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kfind/kdatecombo.cpp')
-rw-r--r--kfind/kdatecombo.cpp131
1 files changed, 131 insertions, 0 deletions
diff --git a/kfind/kdatecombo.cpp b/kfind/kdatecombo.cpp
new file mode 100644
index 000000000..c5f9e4553
--- /dev/null
+++ b/kfind/kdatecombo.cpp
@@ -0,0 +1,131 @@
+/***********************************************************************
+ *
+ * kdatecombo.cpp
+ *
+ ***********************************************************************/
+
+#include <qtimer.h>
+
+#include <kglobal.h>
+#include <klocale.h>
+#include <kdatepicker.h>
+#include <kdatetbl.h>
+#include <kdebug.h>
+
+#include "kdatecombo.h"
+
+#include "kdatecombo.moc"
+
+KDateCombo::KDateCombo(QWidget *parent, const char *name ) : QComboBox(FALSE, parent,name)
+{
+ QDate date = QDate::currentDate();
+ initObject(date, parent, name);
+}
+
+KDateCombo::KDateCombo(const QDate & date, QWidget *parent, const char *name) : QComboBox(FALSE, parent,name)
+{
+ initObject(date, parent, name);
+}
+
+void KDateCombo::initObject(const QDate & date, QWidget *, const char *)
+{
+ clearValidator();
+ popupFrame = new KPopupFrame(this, "popupFrame");
+ popupFrame->installEventFilter(this);
+ datePicker = new KDatePicker(popupFrame, date, "datePicker");
+ datePicker->setMinimumSize(datePicker->sizeHint());
+ datePicker->installEventFilter(this);
+ popupFrame->setMainWidget(datePicker);
+ setDate(date);
+
+ connect(datePicker, SIGNAL(dateSelected(QDate)), this, SLOT(dateEnteredEvent(QDate)));
+}
+
+KDateCombo::~KDateCombo()
+{
+ delete datePicker;
+ delete popupFrame;
+}
+
+QString KDateCombo::date2String(const QDate & date)
+{
+ return(KGlobal::locale()->formatDate(date, true));
+}
+
+QDate & KDateCombo::string2Date(const QString & str, QDate *qd)
+{
+ return *qd = KGlobal::locale()->readDate(str);
+}
+
+QDate & KDateCombo::getDate(QDate *currentDate)
+{
+ return string2Date(currentText(), currentDate);
+}
+
+bool KDateCombo::setDate(const QDate & newDate)
+{
+ if (newDate.isValid())
+ {
+ if (count())
+ clear();
+ insertItem(date2String(newDate));
+ return TRUE;
+ }
+ return FALSE;
+}
+
+void KDateCombo::dateEnteredEvent(QDate newDate)
+{
+ if (!newDate.isValid())
+ newDate = datePicker->date();
+ popupFrame->hide();
+ setDate(newDate);
+}
+
+void KDateCombo::mousePressEvent (QMouseEvent * e)
+{
+ if (e->button() & QMouseEvent::LeftButton)
+ {
+ if (rect().contains( e->pos()))
+ {
+ QDate tempDate;
+ getDate(& tempDate);
+ datePicker->setDate(tempDate);
+ popupFrame->popup(mapToGlobal(QPoint(0, height())));
+ //datePicker->setFocus();
+ }
+ }
+}
+
+bool KDateCombo::eventFilter (QObject*, QEvent* e)
+{
+ if ( e->type() == QEvent::MouseButtonPress )
+ {
+ QMouseEvent *me = (QMouseEvent *)e;
+ QPoint p = mapFromGlobal( me->globalPos() );
+ if (rect().contains( p ) )
+ {
+ QTimer::singleShot(10, this, SLOT(dateEnteredEvent()));
+ return true;
+ }
+ }
+ else if ( e->type() == QEvent::KeyRelease )
+ {
+ QKeyEvent *k = (QKeyEvent *)e;
+ //Press return == pick selected date and close the combo
+ if((k->key()==Qt::Key_Return)||(k->key()==Qt::Key_Enter))
+ {
+ dateEnteredEvent(datePicker->date());
+ return true;
+ }
+ else if (k->key()==Qt::Key_Escape)
+ {
+ popupFrame->hide();
+ return true;
+ }
+ else
+ return false;
+ }
+
+ return false;
+}