lib

dateedit.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 "dateedit.h"
22
23#include <tqdatetimeedit.h>
24#include <tqrangecontrol.h>
25#include <tqobjectlist.h>
26#include <tqlayout.h>
27#include <tqvariant.h>
28#include <tqpainter.h>
29
30#include <tdelocale.h>
31#include <tdeglobal.h>
32
33using namespace KoProperty;
34
35DateEdit::DateEdit(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 TQDateEdit(this);
40 m_edit->setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding);
41 m_edit->setMinimumHeight(5);
42 l->addWidget(m_edit);
43
44 setLeavesTheSpaceForRevertButton(true);
45
46 setFocusWidget(m_edit);
47 connect(m_edit, TQ_SIGNAL(valueChanged(const TQDate&)), this, TQ_SLOT(slotValueChanged(const TQDate&)));
48}
49
50DateEdit::~DateEdit()
51{}
52
53TQVariant
54DateEdit::value() const
55{
56 return m_edit->date();
57}
58
59void
60DateEdit::setValue(const TQVariant &value, bool emitChange)
61{
62 m_edit->blockSignals(true);
63 m_edit->setDate(value.toDate());
64 m_edit->blockSignals(false);
65 if (emitChange)
66 emit valueChanged(this);
67}
68
69void
70DateEdit::drawViewer(TQPainter *p, const TQColorGroup &cg, const TQRect &r, const TQVariant &value)
71{
72 p->eraseRect(r);
73 Widget::drawViewer(p, cg, r, TDEGlobal::locale()->formatDate(value.toDate(), true /* use short format*/ ));
74// p->drawText(r, TQt::AlignLeft | TQt::AlignVCenter | TQt::SingleLine, TDEGlobal::locale()->formatDate(value.toDate(), true /* use short format*/ ));
75}
76
77void
78DateEdit::slotValueChanged(const TQDate&)
79{
80 emit valueChanged(this);
81}
82
83void
84DateEdit::setReadOnlyInternal(bool readOnly)
85{
86 setVisibleFlag(!readOnly);
87}
88
89#include "dateedit.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.