lib

coloredit.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
00003    Copyright (C) 2004  Alexander Dymo <cloudtemple@mskat.net>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019 */
00020 
00021 #include "coloredit.h"
00022 
00023 #include <qvariant.h>
00024 #include <qlayout.h>
00025 #include <qcolor.h>
00026 #include <qpainter.h>
00027 
00028 #include <kcolorcombo.h>
00029 
00030 using namespace KoProperty;
00031 
00032 ColorButton::ColorButton(Property *property, QWidget *parent, const char *name)
00033  : Widget(property, parent, name)
00034 {
00035     QHBoxLayout *l = new QHBoxLayout(this, 0, 0);
00036     m_edit = new KColorCombo(this);
00037     m_edit->setFocusPolicy(QWidget::NoFocus);
00038     connect(m_edit, SIGNAL(activated(int)), this, SLOT(slotValueChanged(int)));
00039     m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00040     m_edit->setMinimumHeight(5);
00041     l->addWidget(m_edit);
00042     setFocusWidget(m_edit);
00043 }
00044 
00045 ColorButton::~ColorButton()
00046 {}
00047 
00048 QVariant
00049 ColorButton::value() const
00050 {
00051     return m_edit->color();
00052 }
00053 
00054 void
00055 ColorButton::setValue(const QVariant &value, bool emitChange)
00056 {
00057     m_edit->blockSignals(true);
00058     m_edit->setColor(value.toColor());
00059     m_edit->blockSignals(false);
00060     if (emitChange)
00061         emit valueChanged(this);
00062 }
00063 
00064 void
00065 ColorButton::drawViewer(QPainter *p, const QColorGroup &, const QRect &r, const QVariant &value)
00066 {
00067     p->eraseRect(r);
00068 
00069     p->setBrush(value.toColor());
00070     p->setPen(Qt::SolidLine);
00071     QRect r2(r);
00072     r2.setTopLeft(r.topLeft() + QPoint(5,5));
00073     r2.setBottomRight(r.bottomRight() - QPoint(5,5));
00074     p->drawRect(r2);
00075 }
00076 
00077 void
00078 ColorButton::slotValueChanged(int)
00079 {
00080     emit valueChanged(this);
00081 }
00082 
00083 
00084 bool
00085 ColorButton::eventFilter(QObject* watched, QEvent* e)
00086 {
00087     return Widget::eventFilter(watched, e);
00088 }
00089 
00090 void
00091 ColorButton::setReadOnlyInternal(bool readOnly)
00092 {
00093     setVisibleFlag(!readOnly);
00094 }
00095 
00096 #include "coloredit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys