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 #ifdef QT_ONLY
00031 // \todo
00032 #else
00033 #include <klocale.h>
00034 #include <kglobal.h>
00035 #endif
00036 
00037 using namespace KoProperty;
00038 
00039 DateEdit::DateEdit(Property *property, QWidget *parent, const char *name)
00040  : Widget(property, parent, name)
00041 {
00042     QHBoxLayout *l = new QHBoxLayout(this, 0, 0);
00043     m_edit = new QDateEdit(this);
00044     m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00045     m_edit->setMinimumHeight(5);
00046     l->addWidget(m_edit);
00047 
00048     setLeavesTheSpaceForRevertButton(true);
00049 
00050     setFocusWidget(m_edit);
00051     connect(m_edit, SIGNAL(valueChanged(const QDate&)), this, SLOT(slotValueChanged(const QDate&)));
00052 }
00053 
00054 DateEdit::~DateEdit()
00055 {}
00056 
00057 QVariant
00058 DateEdit::value() const
00059 {
00060     return m_edit->date();
00061 }
00062 
00063 void
00064 DateEdit::setValue(const QVariant &value, bool emitChange)
00065 {
00066     m_edit->blockSignals(true);
00067     m_edit->setDate(value.toDate());
00068     m_edit->blockSignals(false);
00069     if (emitChange)
00070         emit valueChanged(this);
00071 }
00072 
00073 void
00074 DateEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
00075 {
00076     p->eraseRect(r);
00077 #ifdef QT_ONLY
00078     Widget::drawViewer(p, cg, r, value.toTime().toString(Qt::LocalDate));
00079 //  p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, value.toTime().toString(Qt::LocalDate));
00080 #else
00081     Widget::drawViewer(p, cg, r, KGlobal::locale()->formatDate(value.toDate(), true /* use short format*/ ));
00082 //  p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, KGlobal::locale()->formatDate(value.toDate(), true /* use short format*/ ));
00083 #endif
00084 }
00085 
00086 void
00087 DateEdit::slotValueChanged(const QDate&)
00088 {
00089     emit valueChanged(this);
00090 }
00091 
00092 void
00093 DateEdit::setReadOnlyInternal(bool readOnly)
00094 {
00095     setVisibleFlag(!readOnly);
00096 }
00097 
00098 #include "dateedit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys