kexi

kexicustompropertyfactory_p.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include "kexicustompropertyfactory_p.h"
00021 
00022 #include <qlineedit.h>
00023 #include <kdebug.h>
00024 #include <koproperty/property.h>
00025 #include <kexiutils/identifier.h>
00026 
00027 using namespace KoProperty;
00028 
00029 KexiImagePropertyEdit::KexiImagePropertyEdit(
00030     Property *property, QWidget *parent, const char *name)
00031  : PixmapEdit(property, parent, name)
00032  , m_id(0)
00033 {
00034 }
00035 
00036 KexiImagePropertyEdit::~KexiImagePropertyEdit()
00037 {
00038 }
00039 
00040 void KexiImagePropertyEdit::selectPixmap()
00041 {
00042     QString fileName( PixmapEdit::selectPixmapFileName() );
00043     if (fileName.isEmpty())
00044         return;
00045     KexiBLOBBuffer::Handle h(KexiBLOBBuffer::self()->insertPixmap( KURL(fileName) ));
00046     setValue((uint)h.id());
00047 #if 0 //will be reenabled for new image collection
00048     if(!m_manager->activeForm() || !property())
00049         return;
00050 
00051     ObjectTreeItem *item = m_manager->activeForm()->objectTree()->lookup(m_manager->activeForm()->selectedWidget()->name());
00052     QString name = item ? item->pixmapName(property()->name()) : "";
00053     PixmapCollectionChooser dialog( m_manager->activeForm()->pixmapCollection(), name, topLevelWidget() );
00054     if(dialog.exec() == QDialog::Accepted) {
00055         setValue(dialog.pixmap(), true);
00056         item->setPixmapName(property()->name(), dialog.pixmapName());
00057     }
00058 #endif
00059 }
00060 
00061 QVariant KexiImagePropertyEdit::value() const
00062 {
00063     return (uint)m_id;
00064 }
00065 
00066 void KexiImagePropertyEdit::setValue(const QVariant &value, bool emitChange)
00067 {
00068     m_id = value.toInt();
00069     PixmapEdit::setValue(KexiBLOBBuffer::self()->objectForId(m_id).pixmap(), emitChange);
00070 }
00071 
00072 void KexiImagePropertyEdit::drawViewer(QPainter *p, const QColorGroup &cg, const QRect &r, 
00073     const QVariant &value)
00074 {
00075     KexiBLOBBuffer::Handle h( KexiBLOBBuffer::self()->objectForId(value.toInt()) );
00076     PixmapEdit::drawViewer(p, cg, r, h.pixmap());
00077 }
00078 
00079 //----------------------------------------------------------------
00080 
00081 KexiIdentifierPropertyEdit::KexiIdentifierPropertyEdit(
00082     Property *property, QWidget *parent, const char *name)
00083  : StringEdit(property, parent, name)
00084 {
00085     m_edit->setValidator( 
00086         new KexiUtils::IdentifierValidator(m_edit, "KexiIdentifierPropertyEdit Validator") );
00087 }
00088 
00089 KexiIdentifierPropertyEdit::~KexiIdentifierPropertyEdit()
00090 {
00091 }
00092 
00093 void KexiIdentifierPropertyEdit::setValue(const QVariant &value, bool emitChange)
00094 {
00095     QString string(value.toString());
00096     if (string.isEmpty()) {
00097         kdWarning() << "KexiIdentifierPropertyEdit::setValue(): "
00098             "Value cannot be empty. This call has no effect." << endl;
00099         return;
00100     }
00101     QString identifier( KexiUtils::string2Identifier(string) );
00102     if (identifier!=string)
00103         kdDebug() << QString("KexiIdentifierPropertyEdit::setValue(): "
00104             "String \"%1\" converted to identifier \"%2\".").arg(string).arg(identifier) << endl;
00105     StringEdit::setValue( identifier, emitChange );
00106 }
00107 
00108 #include "kexicustompropertyfactory_p.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys