coloredit.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 "coloredit.h"
22
23#include <tqvariant.h>
24#include <tqlayout.h>
25#include <tqcolor.h>
26#include <tqpainter.h>
27
28#include <kcolorcombo.h>
29
30using namespace KoProperty;
31
32ColorButton::ColorButton(Property *property, TQWidget *parent, const char *name)
33 : Widget(property, parent, name)
34{
35 TQHBoxLayout *l = new TQHBoxLayout(this, 0, 0);
36 m_edit = new KColorCombo(this);
37 m_edit->setFocusPolicy(TQWidget::NoFocus);
38 connect(m_edit, TQ_SIGNAL(activated(int)), this, TQ_SLOT(slotValueChanged(int)));
39 m_edit->setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding);
40 m_edit->setMinimumHeight(5);
41 l->addWidget(m_edit);
42 setFocusWidget(m_edit);
43}
44
45ColorButton::~ColorButton()
46{}
47
48TQVariant
49ColorButton::value() const
50{
51 return m_edit->color();
52}
53
54void
55ColorButton::setValue(const TQVariant &value, bool emitChange)
56{
57 m_edit->blockSignals(true);
58 m_edit->setColor(value.toColor());
59 m_edit->blockSignals(false);
60 if (emitChange)
61 emit valueChanged(this);
62}
63
64void
65ColorButton::drawViewer(TQPainter *p, const TQColorGroup &, const TQRect &r, const TQVariant &value)
66{
67 p->eraseRect(r);
68
69 p->setBrush(value.toColor());
70 p->setPen(TQt::SolidLine);
71 TQRect r2(r);
72 r2.setTopLeft(r.topLeft() + TQPoint(5,5));
73 r2.setBottomRight(r.bottomRight() - TQPoint(5,5));
74 p->drawRect(r2);
75}
76
77void
78ColorButton::slotValueChanged(int)
79{
80 emit valueChanged(this);
81}
82
83
84bool
85ColorButton::eventFilter(TQObject* watched, TQEvent* e)
86{
87 return Widget::eventFilter(watched, e);
88}
89
90void
91ColorButton::setReadOnlyInternal(bool readOnly)
92{
93 setVisibleFlag(!readOnly);
94}
95
96#include "coloredit.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 bool eventFilter(TQObject *watched, TQEvent *e)
Definition widget.cpp:108
const char * name(StdAction id)
Namespace for a set of classes implementing generic properties framework.