lib

dateedit.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2004  Alexander Dymo <cloudtemple@mskat.net>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "dateedit.h"
00022 
00023 #include <qdatetimeedit.h>
00024 #include <qrangecontrol.h>
00025 #include <qobjectlist.h>
00026 #include <qlayout.h>
00027 #include <qvariant.h>
00028 #include <qpainter.h>
00029 
00030 #include <klocale.h>
00031 #include <kglobal.h>
00032 
00033 using namespace KoProperty;
00034 
00035 DateEdit::DateEdit(Property *property, QWidget *parent, const char *name)
00036  : Widget(property, parent, name)
00037 {
00038     QHBoxLayout *l = new QHBoxLayout(this, 0, 0);
00039     m_edit = new QDateEdit(this);
00040     m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00041     m_edit->setMinimumHeight(5);
00042     l->addWidget(m_edit);
00043 
00044     setLeavesTheSpaceForRevertButton(true);
00045 
00046     setFocusWidget(m_edit);
00047     connect(m_edit, SIGNAL(valueChanged(const QDate&)), this, SLOT(slotValueChanged(const QDate&)));
00048 }
00049 
00050 DateEdit::~DateEdit()
00051 {}
00052 
00053 QVariant
00054 DateEdit::value() const
00055 {
00056     return m_edit->date();
00057 }
00058 
00059 void
00060 DateEdit::setValue(const QVariant &value, bool emitChange)
00061 {
00062     m_edit->blockSignals(true);
00063     m_edit->setDate(value.toDate());
00064     m_edit->blockSignals(false);
00065     if (emitChange)
00066         emit valueChanged(this);
00067 }
00068 
00069 void
00070 DateEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
00071 {
00072     p->eraseRect(r);
00073     Widget::drawViewer(p, cg, r, KGlobal::locale()->formatDate(value.toDate(), true /* use short format*/ ));
00074 //  p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, KGlobal::locale()->formatDate(value.toDate(), true /* use short format*/ ));
00075 }
00076 
00077 void
00078 DateEdit::slotValueChanged(const QDate&)
00079 {
00080     emit valueChanged(this);
00081 }
00082 
00083 void
00084 DateEdit::setReadOnlyInternal(bool readOnly)
00085 {
00086     setVisibleFlag(!readOnly);
00087 }
00088 
00089 #include "dateedit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys