summaryrefslogtreecommitdiffstats
blob: c1a08f1a997509cf25b86fd70ee227f151e8370b (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
96
97
98
99
100
101
102
103
104
/*
 * Copyright (c) 2012 Tobias Markmann
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#include "QtVCardAddressField.h"
#include "ui_QtVCardAddressField.h"

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

#define GETTER_SETTER_LINEEDIT_IMPL( METHOD_NAME, UI_NAME ) \
	void QtVCardAddressField::set##METHOD_NAME(const QString METHOD_NAME) {	\
		ui->lineEdit##UI_NAME->setText(METHOD_NAME); \
	} \
	\
	QString QtVCardAddressField::get##METHOD_NAME() const {	\
		return ui->lineEdit##UI_NAME->text(); \
	}

namespace Swift {

QtVCardAddressField::QtVCardAddressField(QWidget* parent, bool editable) :
	QWidget(parent),
	ui(new Ui::QtVCardAddressField) {
	ui->setupUi(this);
	setEditable(editable);
}

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

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

void QtVCardAddressField::setEditable(bool editable) {
	this->editable = editable;
	QList<QCheckBox*> allCheckBoxes = findChildren<QCheckBox*>();
	foreach(QCheckBox* checkbox, allCheckBoxes) {
		if (editable) {
			checkbox->setEnabled(true);
		} else {
			checkbox->setEnabled(false);
		}
	}

	QList<QtResizableLineEdit*> allLineEdits = findChildren<QtResizableLineEdit*>();
	foreach(QtResizableLineEdit* lineEdit, allLineEdits) {
		if (editable) {
			lineEdit->show();
			lineEdit->setEditable(true);
		} else {
			lineEdit->setEditable(false);
			if (lineEdit->text().isEmpty()) {
				lineEdit->hide();
			} else {
				lineEdit->show();
			}
		}
	}

	if (editable) {
		ui->comboBoxDOM_INTL->setEnabled(true);
	} else {
		ui->comboBoxDOM_INTL->setEnabled(false);
	}
}

bool QtVCardAddressField::isEmpty() const {
	return false;
}

GETTER_SETTER_CHECKBOX_IMPL(Home, HOME)
GETTER_SETTER_CHECKBOX_IMPL(Work, WORK)
GETTER_SETTER_CHECKBOX_IMPL(Postal, POSTAL)
GETTER_SETTER_CHECKBOX_IMPL(Parcel, PARCEL)
GETTER_SETTER_CHECKBOX_IMPL(Preferred, PREF)

void QtVCardAddressField::setDeliveryType(DeliveryType type) {
	ui->comboBoxDOM_INTL->setCurrentIndex(type);
}

QtVCardAddressField::DeliveryType QtVCardAddressField::getDeliveryType() const {
	return ui->comboBoxDOM_INTL->currentIndex() == 1 ? InternationalDelivery : DomesticDelivery;
}

GETTER_SETTER_LINEEDIT_IMPL(POBox, POBOX)
GETTER_SETTER_LINEEDIT_IMPL(AddressExtension, EXTADD)
GETTER_SETTER_LINEEDIT_IMPL(Street, STREET)
GETTER_SETTER_LINEEDIT_IMPL(Locality, LOCALITY)
GETTER_SETTER_LINEEDIT_IMPL(Region, REGION)
GETTER_SETTER_LINEEDIT_IMPL(PostalCode, PCODE)
GETTER_SETTER_LINEEDIT_IMPL(Country, CTRY)

}