sizeedit.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 "sizeedit.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 SIZEEDIT_MASK "%1x%2"
34
35using namespace KoProperty;
36
37SizeEdit::SizeEdit(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->setBackgroundMode(TQt::PaletteBase);
46// m_edit->setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding);
47 m_edit->setMinimumHeight(5);
48 setEditor(m_edit);
49// setFocusWidget(m_edit);
50}
51
52SizeEdit::~SizeEdit()
53{}
54
55TQVariant
56SizeEdit::value() const
57{
58 return m_value;
59}
60
61void
62SizeEdit::setValue(const TQVariant &value, bool emitChange)
63{
64 m_value = value;
65 m_edit->selectAll(false);
66 m_edit->setText(TQString(SIZEEDIT_MASK).arg(value.toSize().width()).arg(value.toSize().height()));
67 TQToolTip::add(this, TQString("%1 x %2").arg(value.toSize().width()).arg(value.toSize().height()));
68
69 if (emitChange)
70 emit valueChanged(this);
71}
72
73void
74SizeEdit::drawViewer(TQPainter *p, const TQColorGroup &cg, const TQRect &r, const TQVariant &value)
75{
76 TQRect rect(r);
77 rect.setBottom(r.bottom()+1);
78 Widget::drawViewer(p, cg, rect,
79 TQString(SIZEEDIT_MASK).arg(value.toSize().width()).arg(value.toSize().height()));
80// p->eraseRect(r);
81// p->drawText(r, TQt::AlignLeft | TQt::AlignVCenter | TQt::SingleLine,
82// TQString("[ %1, %2 ]").arg(value.toSize().width()).arg(value.toSize().height()));
83}
84
85void
86SizeEdit::setReadOnlyInternal(bool readOnly)
87{
88 Q_UNUSED(readOnly);
89}
90
91#include "sizeedit.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.