urledit.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
3 Copyright (C) 2004 Alexander Dymo <cloudtemple@mskat.net>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19*/
20
21#include "urledit.h"
22
23#include <tqlayout.h>
24#include <tqvariant.h>
25
26#include <kurlrequester.h>
27#include <klineedit.h>
28
29#include "property.h"
30
31
32using namespace KoProperty;
33
34URLEdit::URLEdit(Property *property, TQWidget *parent, const char *name)
35 : Widget(property, parent, name)
36{
37 TQHBoxLayout *l = new TQHBoxLayout(this, 0, 0);
38 m_edit = new KURLRequester(this);
39 m_edit->setSizePolicy(TQSizePolicy::Expanding, TQSizePolicy::Expanding);
40 m_edit->setMinimumHeight(5);
41 l->addWidget(m_edit);
42
43 setProperty(property);
44
45 connect(m_edit, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(slotValueChanged(const TQString&)));
46 m_edit->setSizePolicy(TQSizePolicy::MinimumExpanding, TQSizePolicy::MinimumExpanding);
47}
48
49URLEdit::~URLEdit()
50{}
51
52TQVariant
53URLEdit::value() const
54{
55 return m_edit->url();
56}
57
58void
59URLEdit::setValue(const TQVariant &value, bool emitChange)
60{
61 m_edit->blockSignals(true);
62 m_edit->setURL(value.toString());
63 m_edit->blockSignals(false);
64 if (emitChange)
65 emit valueChanged(this);
66}
67
68void
69URLEdit::slotValueChanged(const TQString&)
70{
71 emit valueChanged(this);
72}
73
74void
75URLEdit::setProperty(Property *property)
76{
77 int mode;
78 if(property) {
79 switch(property->type()) {
80 case DirectoryURL: mode = KFile::Directory|KFile::ExistingOnly; break;
81 case FileURL: case PictureFileURL: default: mode = KFile::File|KFile::ExistingOnly;
82 }
83 m_edit->setMode(mode);
84 }
85
86 Widget::setProperty(property);
87}
88
89void
90URLEdit::setReadOnlyInternal(bool readOnly)
91{
92 m_edit->lineEdit()->setReadOnly(readOnly);
93 m_edit->button()->setEnabled(!readOnly);
94}
95
96#include "urledit.moc"
The base class representing a single property.
Definition property.h:177
The base class for all item editors used in Editor.
Definition widget.h:37
virtual void setProperty(Property *property)
Definition widget.cpp:78
const char * name(StdAction id)
Namespace for a set of classes implementing generic properties framework.
@ DirectoryURL
url of a directory
Definition property.h:111
@ FileURL
url of a file
Definition property.h:109
@ PictureFileURL
url of a pixmap
Definition property.h:110