diff options
Diffstat (limited to 'Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp')
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp new file mode 100644 index 0000000..c1a08f1 --- /dev/null +++ b/Swift/QtUI/QtVCardWidget/QtVCardAddressField.cpp @@ -0,0 +1,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) + +} |