lib
coloredit.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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"
|