lib

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