summaryrefslogtreecommitdiffstats
blob: cbc16bde33352c8d558b5f3ae81b48a43489ef27 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * Copyright (c) 2012 Tobias Markmann
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#include "QtVCardTelephoneField.h"
#include "ui_QtVCardTelephoneField.h"

#define GETTER_SETTER_IMPL( METHOD_NAME, UI_NAME ) \
	void QtVCardTelephoneField::set##METHOD_NAME(const bool METHOD_NAME) { \
		ui->checkBox##UI_NAME->setChecked(METHOD_NAME);	\
	} \
	\
	bool QtVCardTelephoneField::get##METHOD_NAME() const { \
		return ui->checkBox##UI_NAME->checkState() == Qt::Checked; \
	}

namespace Swift {

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

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

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

void QtVCardTelephoneField::setEditable(bool editable) {
	this->editable = editable;
	if (this->editable) {
		ui->lineEditTEL->show();
		ui->labelTEL->hide();
	} else {
		ui->lineEditTEL->hide();
		ui->labelTEL->show();
	}

	foreach(QObject *widget, children()) {
		if (!dynamic_cast<QWidget*>(widget)) continue;
		if (widget->property("editable").isValid()) {
			widget->setProperty("editable", QVariant(editable));
		}

		if (widget->property("readOnly").isValid()) {
			widget->setProperty("readOnly", QVariant(!editable));
			widget->setProperty("frame", QVariant(editable));
		}

		QCheckBox* checkbox;
		if ((checkbox = dynamic_cast<QCheckBox*>(widget))) {
			checkbox->setProperty("enabled", QVariant(editable));
		}
	}
}

bool QtVCardTelephoneField::isEmpty() const {
	return ui->lineEditTEL->text().isEmpty();
}

void QtVCardTelephoneField::setNumber(const QString number) {
	ui->lineEditTEL->setText(number);
}

QString QtVCardTelephoneField::getNumber() const {
	return ui->lineEditTEL->text();
}

GETTER_SETTER_IMPL(Preferred, PREF)
GETTER_SETTER_IMPL(Home, HOME)
GETTER_SETTER_IMPL(Work, WORK)
GETTER_SETTER_IMPL(Voice, VOICE)
GETTER_SETTER_IMPL(Fax, FAX)
GETTER_SETTER_IMPL(Pager, PAGER)
GETTER_SETTER_IMPL(MSG, MSG)
GETTER_SETTER_IMPL(Cell, CELL)
GETTER_SETTER_IMPL(Video, VIDEO)
GETTER_SETTER_IMPL(BBS, BBS)
GETTER_SETTER_IMPL(Modem, MODEM)
GETTER_SETTER_IMPL(ISDN, ISDN)
GETTER_SETTER_IMPL(PCS, PCS)

void QtVCardTelephoneField::onTextChanged(const QString& text) {
	ui->labelTEL->setText(text);
}

}