lib

pointedit.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 "pointedit.h"
22#include "editoritem.h"
23
24#include <tqlabel.h>
25#include <tqlayout.h>
26#include <tqpainter.h>
27#include <tqtooltip.h>
28
29#include <kactivelabel.h>
30#include <tdelocale.h>
31
32//"[ %1, %2 ]"
33#define POINTEDIT_MASK "%1,%2"
34
35using namespace KoProperty;
36
37PointEdit::PointEdit(Property *property, TQWidget *parent, const char *name)
38 : Widget(property, parent, name)
39{
40 setHasBorders(false);
41 m_edit = new KActiveLabel(this);
42 m_edit->setFocusPolicy(TQWidget::NoFocus);
43// m_edit->setIndent(KPROPEDITOR_ITEM_MARGIN);
44 m_edit->setPaletteBackgroundColor(palette().active().base());
45 m_edit->setWordWrap( TQTextEdit::NoWrap );
46// m_edit->setBackgroundMode(TQt::PaletteBase);
47// m_edit->setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding);
48 m_edit->setMinimumHeight(5);
49 setEditor(m_edit);
50// setFocusWidget(m_edit);
51}
52
53PointEdit::~PointEdit()
54{}
55
56TQVariant
57PointEdit::value() const
58{
59 return m_value;
60}
61
62void
63PointEdit::setValue(const TQVariant &value, bool emitChange)
64{
65 m_value = value;
66 m_edit->selectAll(false);
67 m_edit->setText(TQString(POINTEDIT_MASK).arg(value.toPoint().x()).arg(value.toPoint().y()));
68 TQToolTip::add(this, TQString("%1, %2").arg(value.toPoint().x()).arg(value.toPoint().y()));
69
70 if (emitChange)
71 emit valueChanged(this);
72}
73
74void
75PointEdit::drawViewer(TQPainter *p, const TQColorGroup &cg, const TQRect &r, const TQVariant &value)
76{
77 TQRect rect(r);
78 rect.setBottom(r.bottom()+1);
79 Widget::drawViewer(p, cg, rect, TQString(POINTEDIT_MASK).arg(value.toPoint().x()).arg(value.toPoint().y()));
80// p->eraseRect(r);
81// p->drawText(r, TQt::AlignLeft | TQt::AlignVCenter | TQt::SingleLine,
82// TQString("[ %1, %2 ]").arg(value.toPoint().x()).arg(value.toPoint().y()));
83}
84
85void
86PointEdit::setReadOnlyInternal(bool readOnly)
87{
88 Q_UNUSED(readOnly);
89}
90
91#include "pointedit.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
virtual TQVariant value() const =0
const char * name(StdAction id)
Namespace for a set of classes implementing generic properties framework.