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