lib

datetimeedit.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 "datetimeedit.h"
22
23#include <tqdatetimeedit.h>
24#include <tqrangecontrol.h>
25#include <tqobjectlist.h>
26#include <tqlayout.h>
27#include <tqpainter.h>
28#include <tqvariant.h>
29
30#include <tdelocale.h>
31#include <tdeglobal.h>
32
33using namespace KoProperty;
34
35DateTimeEdit::DateTimeEdit(Property *property, TQWidget *parent, const char *name)
36 : Widget(property, parent, name)
37{
38 TQHBoxLayout *l = new TQHBoxLayout(this, 0, 0);
39 m_edit = new TQDateTimeEdit(this);
40 m_edit->setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding);
41 m_edit->setMinimumHeight(5);
42 l->addWidget(m_edit);
43
44 setLeavesTheSpaceForRevertButton(true);
45 setFocusWidget(m_edit);
46 connect(m_edit, TQ_SIGNAL(valueChanged(const TQDateTime&)), this, TQ_SLOT(slotValueChanged(const TQDateTime&)));
47}
48
49DateTimeEdit::~DateTimeEdit()
50{}
51
52TQVariant
54{
55 return m_edit->dateTime();
56}
57
58void
59DateTimeEdit::setValue(const TQVariant &value, bool emitChange)
60{
61 m_edit->blockSignals(true);
62 m_edit->setDateTime(value.toDateTime());
63 m_edit->blockSignals(false);
64 if (emitChange)
65 emit valueChanged(this);
66}
67
68void
69DateTimeEdit::drawViewer(TQPainter *p, const TQColorGroup &cg, const TQRect &r, const TQVariant &value)
70{
71 p->eraseRect(r);
72 Widget::drawViewer(p, cg, r, TDEGlobal::locale()->formatDateTime(value.toDateTime(), true /* use short format*/, false /*no sec */ ));
73// p->drawText(r, TQt::AlignLeft | TQt::AlignVCenter | TQt::SingleLine,
74// TDEGlobal::locale()->formatDateTime(value.toDateTime(), true /* use short format*/, false /*no sec */ ));
75}
76
77void
78DateTimeEdit::slotValueChanged(const TQDateTime&)
79{
80 emit valueChanged(this);
81}
82
83void
84DateTimeEdit::setReadOnlyInternal(bool readOnly)
85{
86 setVisibleFlag(!readOnly);
87}
88
89#include "datetimeedit.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
void setVisibleFlag(bool visible)
Definition widget.cpp:227
virtual TQVariant value() const =0
const char * name(StdAction id)
Namespace for a set of classes implementing generic properties framework.