urledit.cpp 3.43 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* This file is part of the KDE project
   Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>
   Copyright (C) 2004  Alexander Dymo <cloudtemple@mskat.net>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include "urledit.h"

23
24
#include <QLayout>
#include <QVariant>
25
26
27
28
29
30
31
//Added by qt3to4:
#include <Q3HBoxLayout>

#ifndef QT_ONLY
#include <kurlrequester.h>
#include <klineedit.h>
#else
32
33
#include <QPushButton>
#include <QLineEdit>
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <q3filedialog.h>
#endif

#include "property.h"


using namespace KoProperty;

URLEdit::URLEdit(Property *property, QWidget *parent, const char *name)
 : Widget(property, parent, name)
{
	Q3HBoxLayout *l = new Q3HBoxLayout(this, 0, 0);
#ifndef QT_ONLY
	m_edit = new KUrlRequester(this);
	m_edit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
	m_edit->setMinimumHeight(5);
	l->addWidget(m_edit);

	setProperty(property);

	connect(m_edit, SIGNAL(textChanged(const QString&)), this, SLOT(slotValueChanged(const QString&)));
#else
	m_edit = new QLineEdit(this);
	m_select = new QPushButton("...",this);
	l->addWidget(m_edit);
	l->addWidget(m_select);
	connect( m_select, SIGNAL(clicked()),this,SLOT(selectFile()));
	connect(m_edit, SLOT(textChanged(const QString&)), this, slotValueChanged(const QString&));
#endif
	m_edit->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
}

URLEdit::~URLEdit()
{}

QVariant
URLEdit::value() const
{
#ifdef QT_ONLY
	return m_edit->text();
#else
	return m_edit->url();
#endif
}

void
URLEdit::setValue(const QVariant &value, bool emitChange)
{
	m_edit->blockSignals(true);
#ifdef QT_ONLY
	m_edit->setText(value.toString());
#else
Laurent Montel's avatar
Laurent Montel committed
86
	m_edit->setUrl(value.toString());
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#endif
	m_edit->blockSignals(false);
	if (emitChange)
		emit valueChanged(this);
}

void
URLEdit::slotValueChanged(const QString&)
{
	emit valueChanged(this);
}

void
URLEdit::setProperty(Property *property)
{
#ifndef QT_ONLY
	int  mode;
	if(property) {
		switch(property->type()) {
			case DirectoryURL:  mode = KFile::Directory|KFile::ExistingOnly;  break;
			case FileURL: case PictureFileURL: default: mode = KFile::File|KFile::ExistingOnly;
		}
		m_edit->setMode(mode);
	}
#endif

	Widget::setProperty(property);
}

void
URLEdit::selectFile()
{
#ifdef QT_ONLY
	QString path;
	if(m_property->type() == DirectoryURL)
		path = Q3FileDialog::getExistingDirectory(path,this);
	else if(m_property->type() == FileURL)
		path = Q3FileDialog::getOpenFileName(path, QString::null, this);
	//slotValueChanged(m_url);
	m_edit->setText(path);
#endif
}

void
URLEdit::setReadOnlyInternal(bool readOnly)
{
#ifndef QT_ONLY
	m_edit->lineEdit()->setReadOnly(readOnly);
	m_edit->button()->setEnabled(!readOnly);
#else
	m_edit->setReadOnly(readOnly);
	m_select->setEnabled(!readOnly);
#endif
}

#include "urledit.moc"