/* * 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(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(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); } }