lib

timeedit.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 "timeedit.h"
00022 
00023 #include <qdatetimeedit.h>
00024 #include <qrangecontrol.h>
00025 #include <qobjectlist.h>
00026 #include <qpainter.h>
00027 #include <qlayout.h>
00028 #include <qvariant.h>
00029 #include <qdatetime.h>
00030 
00031 #ifdef QT_ONLY
00032 // \todo
00033 #else
00034 #include <klocale.h>
00035 #include <kglobal.h>
00036 #endif
00037 
00038 using namespace KoProperty;
00039 
00040 TimeEdit::TimeEdit(Property *property, QWidget *parent, const char *name)
00041  : Widget(property, parent, name)
00042 {
00043     QHBoxLayout *l = new QHBoxLayout(this, 0, 0);
00044     m_edit = new QTimeEdit(this);
00045     m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00046     m_edit->setMinimumHeight(5);
00047     l->addWidget(m_edit);
00048 
00049     setLeavesTheSpaceForRevertButton(true);
00050     connect(m_edit, SIGNAL(valueChanged(const QTime&)), this, SLOT(slotValueChanged(const QTime&)));
00051 }
00052 
00053 TimeEdit::~TimeEdit()
00054 {}
00055 
00056 QVariant
00057 TimeEdit::value() const
00058 {
00059     return m_edit->time();
00060 }
00061 
00062 void
00063 TimeEdit::setValue(const QVariant &value, bool emitChange)
00064 {
00065     m_edit->blockSignals(true);
00066     m_edit->setTime(value.toTime());
00067     m_edit->blockSignals(false);
00068     if (emitChange)
00069         emit valueChanged(this);
00070 }
00071 
00072 void
00073 TimeEdit::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.toDate().toString(Qt::LocalDate));
00078 //  p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, value.toDate().toString(Qt::LocalDate));
00079 #else
00080     Widget::drawViewer(p, cg, r, KGlobal::locale()->formatTime(value.toTime(), true /* include sec*/));
00081 //  p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, KGlobal::locale()->formatTime(value.toTime(), true /* include sec*/));
00082 #endif
00083 }
00084 
00085 void
00086 TimeEdit::slotValueChanged(const QTime&)
00087 {
00088     emit valueChanged(this);
00089 }
00090 
00091 void
00092 TimeEdit::setReadOnlyInternal(bool readOnly)
00093 {
00094     setVisibleFlag(!readOnly);
00095 }
00096 
00097 #include "timeedit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys