lib

datetimeedit.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 "datetimeedit.h"
00022 
00023 #include <qdatetimeedit.h>
00024 #include <qrangecontrol.h>
00025 #include <qobjectlist.h>
00026 #include <qlayout.h>
00027 #include <qpainter.h>
00028 #include <qvariant.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 DateTimeEdit::DateTimeEdit(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 QDateTimeEdit(this);
00044     m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00045     m_edit->setMinimumHeight(5);
00046     l->addWidget(m_edit);
00047 
00048     setLeavesTheSpaceForRevertButton(true);
00049     setFocusWidget(m_edit);
00050     connect(m_edit, SIGNAL(valueChanged(const QDateTime&)), this, SLOT(slotValueChanged(const QDateTime&)));
00051 }
00052 
00053 DateTimeEdit::~DateTimeEdit()
00054 {}
00055 
00056 QVariant
00057 DateTimeEdit::value() const
00058 {
00059     return m_edit->dateTime();
00060 }
00061 
00062 void
00063 DateTimeEdit::setValue(const QVariant &value, bool emitChange)
00064 {
00065     m_edit->blockSignals(true);
00066     m_edit->setDateTime(value.toDateTime());
00067     m_edit->blockSignals(false);
00068     if (emitChange)
00069         emit valueChanged(this);
00070 }
00071 
00072 void
00073 DateTimeEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
00074 {
00075     p->eraseRect(r);
00076 #ifdef QT_ONLY
00077     Widget::drawViewer(p, cg, r, value.toDateTime().toString(Qt::LocalDate));
00078 //  p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, value.toDateTime().toString(Qt::LocalDate));
00079 #else
00080     Widget::drawViewer(p, cg, r, KGlobal::locale()->formatDateTime(value.toDateTime(), true /* use short format*/, false /*no sec */ ));
00081 //  p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine,
00082 //      KGlobal::locale()->formatDateTime(value.toDateTime(), true /* use short format*/, false /*no sec */ ));
00083 #endif
00084 }
00085 
00086 void
00087 DateTimeEdit::slotValueChanged(const QDateTime&)
00088 {
00089     emit valueChanged(this);
00090 }
00091 
00092 void
00093 DateTimeEdit::setReadOnlyInternal(bool readOnly)
00094 {
00095     setVisibleFlag(!readOnly);
00096 }
00097 
00098 #include "datetimeedit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys