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 #include <klocale.h>
00031 #include <kglobal.h>
00032 
00033 using namespace KoProperty;
00034 
00035 DateTimeEdit::DateTimeEdit(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 QDateTimeEdit(this);
00040     m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00041     m_edit->setMinimumHeight(5);
00042     l->addWidget(m_edit);
00043 
00044     setLeavesTheSpaceForRevertButton(true);
00045     setFocusWidget(m_edit);
00046     connect(m_edit, SIGNAL(valueChanged(const QDateTime&)), this, SLOT(slotValueChanged(const QDateTime&)));
00047 }
00048 
00049 DateTimeEdit::~DateTimeEdit()
00050 {}
00051 
00052 QVariant
00053 DateTimeEdit::value() const
00054 {
00055     return m_edit->dateTime();
00056 }
00057 
00058 void
00059 DateTimeEdit::setValue(const QVariant &value, bool emitChange)
00060 {
00061     m_edit->blockSignals(true);
00062     m_edit->setDateTime(value.toDateTime());
00063     m_edit->blockSignals(false);
00064     if (emitChange)
00065         emit valueChanged(this);
00066 }
00067 
00068 void
00069 DateTimeEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
00070 {
00071     p->eraseRect(r);
00072     Widget::drawViewer(p, cg, r, KGlobal::locale()->formatDateTime(value.toDateTime(), true /* use short format*/, false /*no sec */ ));
00073 //  p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine,
00074 //      KGlobal::locale()->formatDateTime(value.toDateTime(), true /* use short format*/, false /*no sec */ ));
00075 }
00076 
00077 void
00078 DateTimeEdit::slotValueChanged(const QDateTime&)
00079 {
00080     emit valueChanged(this);
00081 }
00082 
00083 void
00084 DateTimeEdit::setReadOnlyInternal(bool readOnly)
00085 {
00086     setVisibleFlag(!readOnly);
00087 }
00088 
00089 #include "datetimeedit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys