timeedit.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "timeedit.h"
22
23#include <tqdatetimeedit.h>
24#include <tqrangecontrol.h>
25#include <tqobjectlist.h>
26#include <tqpainter.h>
27#include <tqlayout.h>
28#include <tqvariant.h>
29#include <tqdatetime.h>
30
31#include <tdelocale.h>
32#include <tdeglobal.h>
33
34using namespace KoProperty;
35
36TimeEdit::TimeEdit(Property *property, TQWidget *parent, const char *name)
37 : Widget(property, parent, name)
38{
39 TQHBoxLayout *l = new TQHBoxLayout(this, 0, 0);
40 m_edit = new TQTimeEdit(this);
41 m_edit->setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding);
42 m_edit->setMinimumHeight(5);
43 l->addWidget(m_edit);
44
45 setLeavesTheSpaceForRevertButton(true);
46 connect(m_edit, TQ_SIGNAL(valueChanged(const TQTime&)), this, TQ_SLOT(slotValueChanged(const TQTime&)));
47}
48
49TimeEdit::~TimeEdit()
50{}
51
52TQVariant
53TimeEdit::value() const
54{
55 return m_edit->time();
56}
57
58void
59TimeEdit::setValue(const TQVariant &value, bool emitChange)
60{
61 m_edit->blockSignals(true);
62 m_edit->setTime(value.toTime());
63 m_edit->blockSignals(false);
64 if (emitChange)
65 emit valueChanged(this);
66}
67
68void
69TimeEdit::drawViewer(TQPainter *p, const TQColorGroup &cg, const TQRect &r, const TQVariant &value)
70{
71 Widget::drawViewer(p, cg, r, TDEGlobal::locale()->formatTime(value.toTime(), true /* include sec*/));
72// p->drawText(r, TQt::AlignLeft | TQt::AlignVCenter | TQt::SingleLine, TDEGlobal::locale()->formatTime(value.toTime(), true /* include sec*/));
73}
74
75void
76TimeEdit::slotValueChanged(const TQTime&)
77{
78 emit valueChanged(this);
79}
80
81void
82TimeEdit::setReadOnlyInternal(bool readOnly)
83{
84 setVisibleFlag(!readOnly);
85}
86
87#include "timeedit.moc"
The base class representing a single property.
Definition property.h:177
The base class for all item editors used in Editor.
Definition widget.h:37
virtual void drawViewer(TQPainter *p, const TQColorGroup &cg, const TQRect &r, const TQVariant &value)
Definition widget.cpp:88
const char * name(StdAction id)
Namespace for a set of classes implementing generic properties framework.