lib

pointedit.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 "pointedit.h"
00022 #include "editoritem.h"
00023 
00024 #include <qlabel.h>
00025 #include <qlayout.h>
00026 #include <qpainter.h>
00027 #include <qtooltip.h>
00028 
00029 #include <kactivelabel.h>
00030 #include <klocale.h>
00031 
00032 //"[ %1, %2 ]"
00033 #define POINTEDIT_MASK "%1,%2"
00034 
00035 using namespace KoProperty;
00036 
00037 PointEdit::PointEdit(Property *property, QWidget *parent, const char *name)
00038  : Widget(property, parent, name)
00039 {
00040     setHasBorders(false);
00041     m_edit = new KActiveLabel(this);
00042     m_edit->setFocusPolicy(NoFocus);
00043 //  m_edit->setIndent(KPROPEDITOR_ITEM_MARGIN);
00044     m_edit->setPaletteBackgroundColor(palette().active().base());
00045     m_edit->setWordWrap( QTextEdit::NoWrap );
00046 //  m_edit->setBackgroundMode(Qt::PaletteBase);
00047 //  m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00048     m_edit->setMinimumHeight(5);
00049     setEditor(m_edit);
00050 //  setFocusWidget(m_edit);
00051 }
00052 
00053 PointEdit::~PointEdit()
00054 {}
00055 
00056 QVariant
00057 PointEdit::value() const
00058 {
00059     return m_value;
00060 }
00061 
00062 void
00063 PointEdit::setValue(const QVariant &value, bool emitChange)
00064 {
00065     m_value = value;
00066     m_edit->selectAll(false);
00067     m_edit->setText(QString(POINTEDIT_MASK).arg(value.toPoint().x()).arg(value.toPoint().y()));
00068     QToolTip::add(this, QString("%1, %2").arg(value.toPoint().x()).arg(value.toPoint().y()));
00069 
00070     if (emitChange)
00071         emit valueChanged(this);
00072 }
00073 
00074 void
00075 PointEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
00076 {
00077     QRect rect(r);
00078     rect.setBottom(r.bottom()+1);
00079     Widget::drawViewer(p, cg, rect, QString(POINTEDIT_MASK).arg(value.toPoint().x()).arg(value.toPoint().y()));
00080 //  p->eraseRect(r);
00081 //  p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine,
00082 //      QString("[ %1, %2 ]").arg(value.toPoint().x()).arg(value.toPoint().y()));
00083 }
00084 
00085 void
00086 PointEdit::setReadOnlyInternal(bool readOnly)
00087 {
00088     Q_UNUSED(readOnly);
00089 }
00090 
00091 #include "pointedit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys