summaryrefslogtreecommitdiffstats
blob: 028d7295835b39c5b52930acbcf7dd183623bb3b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
/*
 * Copyright (c) 2012 Tobias Markmann
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#include "QtVCardURLField.h"
#include "ui_QtVCardURLField.h"

#include <QUrl>

namespace Swift {

QtVCardURLField::QtVCardURLField(QWidget* parent, bool editable) :
	QWidget(parent),
	ui(new Ui::QtVCardURLField) {
	ui->setupUi(this);
	connect(ui->lineEditURL, SIGNAL(textChanged(QString)), SLOT(onTextChanged(QString)));
	setEditable(editable);
}

QtVCardURLField::~QtVCardURLField() {
	delete ui;
}

bool QtVCardURLField::isEditable() const {
	return editable;
}

void QtVCardURLField::setEditable(bool editable) {
	this->editable = editable;
	if (this->editable) {
		ui->lineEditURL->show();
		ui->labelURL->hide();
	} else {
		ui->lineEditURL->hide();
		ui->labelURL->show();
	}
}

bool QtVCardURLField::isEmpty() const {
	return ui->lineEditURL->text().isEmpty();
}

void QtVCardURLField::setURL(const QString url) {
	ui->lineEditURL->setText(url);
}

QString QtVCardURLField::getURL() const {
	return ui->lineEditURL->text();
}

void QtVCardURLField::onTextChanged(const QString& text) {
	if (text.isEmpty()) {
		ui->labelURL->setText("");
	} else {
		if (QUrl(text).isValid()) {
			ui->labelURL->setText(QString("<a href=\"%1\">%1</a>").arg(text));
		} else {
			ui->labelURL->setText(text);
		}
	}
}

}