lib

sizeedit.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 "sizeedit.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 SIZEEDIT_MASK "%1x%2"
00034 
00035 using namespace KoProperty;
00036 
00037 SizeEdit::SizeEdit(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->setBackgroundMode(Qt::PaletteBase);
00046 //  m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
00047     m_edit->setMinimumHeight(5);
00048     setEditor(m_edit);
00049 //  setFocusWidget(m_edit);
00050 }
00051 
00052 SizeEdit::~SizeEdit()
00053 {}
00054 
00055 QVariant
00056 SizeEdit::value() const
00057 {
00058     return m_value;
00059 }
00060 
00061 void
00062 SizeEdit::setValue(const QVariant &value, bool emitChange)
00063 {
00064     m_value = value;
00065     m_edit->selectAll(false);
00066     m_edit->setText(QString(SIZEEDIT_MASK).arg(value.toSize().width()).arg(value.toSize().height()));
00067     QToolTip::add(this, QString("%1 x %2").arg(value.toSize().width()).arg(value.toSize().height()));
00068 
00069     if (emitChange)
00070         emit valueChanged(this);
00071 }
00072 
00073 void
00074 SizeEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, const QVariant &value)
00075 {
00076     QRect rect(r);
00077     rect.setBottom(r.bottom()+1);
00078     Widget::drawViewer(p, cg, rect, 
00079         QString(SIZEEDIT_MASK).arg(value.toSize().width()).arg(value.toSize().height()));
00080 //  p->eraseRect(r);
00081 //  p->drawText(r, Qt::AlignLeft | Qt::AlignVCenter | Qt::SingleLine,
00082 //      QString("[ %1, %2 ]").arg(value.toSize().width()).arg(value.toSize().height()));
00083 }
00084 
00085 void
00086 SizeEdit::setReadOnlyInternal(bool readOnly)
00087 {
00088     Q_UNUSED(readOnly);
00089 }
00090 
00091 #include "sizeedit.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys