summaryrefslogtreecommitdiffstats
path: root/lib/widgets/propeditor/pcolorbutton.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit114a878c64ce6f8223cfd22d76a20eb16d177e5e (patch)
treeacaf47eb0fa12142d3896416a69e74cbf5a72242 /lib/widgets/propeditor/pcolorbutton.cpp
downloadtdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.tar.gz
tdevelop-114a878c64ce6f8223cfd22d76a20eb16d177e5e.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdevelop@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'lib/widgets/propeditor/pcolorbutton.cpp')
-rw-r--r--lib/widgets/propeditor/pcolorbutton.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/lib/widgets/propeditor/pcolorbutton.cpp b/lib/widgets/propeditor/pcolorbutton.cpp
new file mode 100644
index 00000000..7404e1de
--- /dev/null
+++ b/lib/widgets/propeditor/pcolorbutton.cpp
@@ -0,0 +1,120 @@
+/***************************************************************************
+ * Copyright (C) 2004 by Alexander Dymo *
+ * cloudtemple@mskat.net *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU Library General Public License as *
+ * published by the Free Software Foundation; either version 2 of the *
+ * License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Library General Public *
+ * License along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+#include "pcolorbutton.h"
+
+#include <qlayout.h>
+#include <qpainter.h>
+
+#ifndef PURE_QT
+#include <kcolorbutton.h>
+#else
+#include <qpushbutton.h>
+#include <qpixmap.h>
+#include <qiconset.h>
+#endif
+#include <qcolordialog.h>
+
+namespace PropertyLib {
+
+PColorButton::PColorButton(MultiProperty* property, QWidget* parent, const char* name)
+ :PropertyWidget(property, parent, name)
+{
+ QHBoxLayout *l = new QHBoxLayout(this, 0, 0);
+#ifndef PURE_QT
+ m_edit = new KColorButton(this);
+ connect(m_edit, SIGNAL(changed(const QColor&)), this, SLOT(updateProperty(const QColor&)));
+#else
+ m_edit = new QPushButton(this);
+ connect(m_edit, SIGNAL(clicked()), this, SLOT(changeColor()));
+#endif
+
+ m_edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
+ l->addWidget(m_edit);
+}
+
+QVariant PColorButton::value() const
+{
+#ifndef PURE_QT
+ return QVariant(m_edit->color());
+#else
+ return QVariant(m_color);
+#endif
+}
+
+void PColorButton::drawViewer(QPainter* p, const QColorGroup& cg, const QRect& r, const QVariant& value)
+{
+/* p->setBrush(value.toColor());
+ p->setPen(Qt::NoPen);
+ p->drawRect(r);*/
+ p->setPen(Qt::NoPen);
+ p->setBrush(cg.background());
+ p->drawRect(r);
+
+ p->setBrush(value.toColor());
+ p->setPen(Qt::SolidLine);
+ QRect r2(r);
+ r2.setTopLeft(r.topLeft() + QPoint(5,5));
+ r2.setBottomRight(r.bottomRight() - QPoint(5,5));
+ p->drawRect(r2);
+}
+
+void PColorButton::setValue(const QVariant& value, bool emitChange)
+{
+#ifndef PURE_QT
+ disconnect(m_edit, SIGNAL(changed(const QColor&)), this, SLOT(updateProperty(const QColor&)));
+ m_edit->setColor(value.toColor());
+ connect(m_edit, SIGNAL(changed(const QColor&)), this, SLOT(updateProperty(const QColor&)));
+#else
+ m_color = value.toColor();
+ m_edit->setText(m_color.name());
+ QPixmap px;
+ px.resize(14,14);
+ px.fill(m_color);
+ m_edit->setIconSet(px);
+#endif
+ if (emitChange)
+ emit propertyChanged(m_property, value);
+
+}
+
+void PColorButton::updateProperty(const QColor &// color
+ )
+{
+ emit propertyChanged(m_property, value());
+}
+
+void PColorButton::changeColor()
+{
+#ifdef PURE_QT
+ m_color = QColorDialog::getColor(m_color,this);
+ updateProperty(m_color);
+ m_edit->setText(m_color.name());
+ QPixmap px;
+ px.resize(14,14);
+ px.fill(m_color);
+ m_edit->setIconSet(px);
+
+#endif
+}
+
+}
+#ifndef PURE_QT
+#include "pcolorbutton.moc"
+#endif