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 #include <klocale.h>
00032 #include <kglobal.h>
00033 
00034 using namespace KoProperty;
00035 
00036 TimeEdit::TimeEdit(Property *property, QWidget *parent, const char *name)
00037  : Widget(property, parent, name)
00038 {
00039     QHBoxLayout *l = new QHBoxLayout(this, 0, 0);
00040     m_edit = new QTimeEdit(this);
00041     m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00042     m_edit->setMinimumHeight(5);
00043     l->addWidget(m_edit);
00044 
00045     setLeavesTheSpaceForRevertButton(true);
00046     connect(m_edit, SIGNAL(valueChanged(const QTime&)), this, SLOT(slotValueChanged(const QTime&)));
00047 }
00048 
00049 TimeEdit::~TimeEdit()
00050 {}
00051 
00052 QVariant
00053 TimeEdit::value() const
00054 {
00055     return m_edit->time();
00056 }
00057 
00058 void
00059 TimeEdit::setValue(const QVariant &value, bool emitChange)
00060 {
00061     m_edit->blockSignals(true);
00062     m_edit->setTime(value.toTime());
00063     m_edit->blockSignals(false);
00064     if (emitChange)
00065         emit valueChanged(this);
00066 }
00067 
00068 void
00069 TimeEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
00070 {
00071     Widget::drawViewer(p, cg, r, KGlobal::locale()->formatTime(value.toTime(), true /* include sec*/));
00072 //  p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine, KGlobal::locale()->formatTime(value.toTime(), true /* include sec*/));
00073 }
00074 
00075 void
00076 TimeEdit::slotValueChanged(const QTime&)
00077 {
00078     emit valueChanged(this);
00079 }
00080 
00081 void
00082 TimeEdit::setReadOnlyInternal(bool readOnly)
00083 {
00084     setVisibleFlag(!readOnly);
00085 }
00086 
00087 #include "timeedit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys