kexi

kexicustompropertyfactory_p.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Jaroslaw Staniek <js@iidea.pl>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include "kexicustompropertyfactory_p.h"
21
22#include <tqlineedit.h>
23#include <kdebug.h>
24#include <koproperty/property.h>
25#include <kexiutils/identifier.h>
26
27using namespace KoProperty;
28
29KexiImagePropertyEdit::KexiImagePropertyEdit(
30 Property *property, TQWidget *parent, const char *name)
31 : PixmapEdit(property, parent, name)
32 , m_id(0)
33{
34}
35
36KexiImagePropertyEdit::~KexiImagePropertyEdit()
37{
38}
39
40void KexiImagePropertyEdit::selectPixmap()
41{
42 TQString fileName( PixmapEdit::selectPixmapFileName() );
43 if (fileName.isEmpty())
44 return;
45 KexiBLOBBuffer::Handle h(KexiBLOBBuffer::self()->insertPixmap( KURL(fileName) ));
46 setValue((uint)h.id());
47#if 0 //will be reenabled for new image collection
48 if(!m_manager->activeForm() || !property())
49 return;
50
51 ObjectTreeItem *item = m_manager->activeForm()->objectTree()->lookup(m_manager->activeForm()->selectedWidget()->name());
52 TQString name = item ? item->pixmapName(property()->name()) : "";
53 PixmapCollectionChooser dialog( m_manager->activeForm()->pixmapCollection(), name, topLevelWidget() );
54 if(dialog.exec() == TQDialog::Accepted) {
55 setValue(dialog.pixmap(), true);
56 item->setPixmapName(property()->name(), dialog.pixmapName());
57 }
58#endif
59}
60
61TQVariant KexiImagePropertyEdit::value() const
62{
63 return (uint)m_id;
64}
65
66void KexiImagePropertyEdit::setValue(const TQVariant &value, bool emitChange)
67{
68 m_id = value.toInt();
69 PixmapEdit::setValue(KexiBLOBBuffer::self()->objectForId(m_id).pixmap(), emitChange);
70}
71
72void KexiImagePropertyEdit::drawViewer(TQPainter *p, const TQColorGroup &cg, const TQRect &r,
73 const TQVariant &value)
74{
75 KexiBLOBBuffer::Handle h( KexiBLOBBuffer::self()->objectForId(value.toInt()) );
76 PixmapEdit::drawViewer(p, cg, r, h.pixmap());
77}
78
79//----------------------------------------------------------------
80
81KexiIdentifierPropertyEdit::KexiIdentifierPropertyEdit(
82 Property *property, TQWidget *parent, const char *name)
83 : StringEdit(property, parent, name)
84{
85 m_edit->setValidator(
86 new KexiUtils::IdentifierValidator(m_edit, "KexiIdentifierPropertyEdit Validator") );
87}
88
89KexiIdentifierPropertyEdit::~KexiIdentifierPropertyEdit()
90{
91}
92
93void KexiIdentifierPropertyEdit::setValue(const TQVariant &value, bool emitChange)
94{
95 TQString string(value.toString());
96 if (string.isEmpty()) {
97 kdWarning() << "KexiIdentifierPropertyEdit::setValue(): "
98 "Value cannot be empty. This call has no effect." << endl;
99 return;
100 }
101 TQString identifier( KexiUtils::string2Identifier(string) );
102 if (identifier!=string)
103 kdDebug() << TQString("KexiIdentifierPropertyEdit::setValue(): "
104 "String \"%1\" converted to identifier \"%2\".").arg(string).arg(identifier) << endl;
105 StringEdit::setValue( identifier, emitChange );
106}
107
108#include "kexicustompropertyfactory_p.moc"
Object handle used by KexiBLOBBuffer.
static KexiBLOBBuffer * self()
Access to KexiBLOBBuffer singleton.
Validates input for identifier name.
Definition identifier.h:49
A dialog to choose an icon in a PixmapCollection.
KEXIUTILS_EXPORT TQString string2Identifier(const TQString &s)