summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2012-02-26 14:32:39 (GMT)
committerSwift Review <review@swift.im>2013-01-12 09:38:51 (GMT)
commit25b10f8d2b77bc5b3a40aac8d2edd5d42e1b6585 (patch)
treedb398f92b820ff03cb301c91ada51b226f212065 /Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp
parent4ed137080a3d80d20a2cead47f741e3dd2f2d42e (diff)
downloadswift-25b10f8d2b77bc5b3a40aac8d2edd5d42e1b6585.zip
swift-25b10f8d2b77bc5b3a40aac8d2edd5d42e1b6585.tar.bz2
Adding basic vCard edit/show support.
Change-Id: I3104efcb9d56cfcaafda45eac2a51d2702f5245b License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Diffstat (limited to 'Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp')
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp80
1 files changed, 80 insertions, 0 deletions
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp
new file mode 100644
index 0000000..46f253f
--- /dev/null
+++ b/Swift/QtUI/QtVCardWidget/QtVCardInternetEMailField.cpp
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2012 Tobias Markmann
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "QtVCardInternetEMailField.h"
+
+#include <QGridLayout>
+#include <QHBoxLayout>
+#include <QTextDocument>
+#include <Swiften/Base/Log.h>
+
+#include <Swift/QtUI/QtSwiftUtil.h>
+
+namespace Swift {
+
+QtVCardInternetEMailField::QtVCardInternetEMailField(QWidget* parent, QGridLayout *layout, bool editable) :
+ QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("E-Mail")) {
+ connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool)));
+}
+
+QtVCardInternetEMailField::~QtVCardInternetEMailField() {
+ disconnect(this, SLOT(handleEditibleChanged(bool)));
+}
+
+void QtVCardInternetEMailField::setupContentWidgets() {
+ emailLabel = new QLabel(this);
+ emailLabel->setOpenExternalLinks(true);
+ emailLabel->setTextInteractionFlags(Qt::LinksAccessibleByMouse | Qt::LinksAccessibleByKeyboard);
+ emailLineEdit = new QtResizableLineEdit(this);
+#if QT_VERSION >= 0x040700
+ emailLineEdit->setPlaceholderText(tr("alice@wonderland.lit"));
+#endif
+ QHBoxLayout* emailLayout = new QHBoxLayout();
+ emailLayout->addWidget(emailLabel);
+ emailLayout->addWidget(emailLineEdit);
+ getGridLayout()->addLayout(emailLayout, getGridLayout()->rowCount()-1, 2, 1, 2, Qt::AlignVCenter);
+ setTabOrder(emailLineEdit, getTagComboBox());
+ QtVCardHomeWork::setTagComboBox(getTagComboBox());
+ emailLabel->hide();
+ childWidgets << emailLabel << emailLineEdit;
+}
+
+bool QtVCardInternetEMailField::isEmpty() const {
+ return emailLineEdit->text().isEmpty();
+}
+
+void QtVCardInternetEMailField::setInternetEMailAddress(const VCard::EMailAddress& address) {
+ assert(address.isInternet);
+ setPreferred(address.isPreferred);
+ setHome(address.isHome);
+ setWork(address.isWork);
+ emailLineEdit->setText(P2QSTRING(address.address));
+}
+
+VCard::EMailAddress QtVCardInternetEMailField::getInternetEMailAddress() const {
+ VCard::EMailAddress address;
+ address.isInternet = true;
+ address.isPreferred = getPreferred();
+ address.isHome = getHome();
+ address.isWork = getWork();
+ address.address = Q2PSTRING(emailLineEdit->text());
+ return address;
+}
+
+void QtVCardInternetEMailField::handleEditibleChanged(bool isEditable) {
+ if (isEditable) {
+ if (emailLineEdit) emailLineEdit->show();
+ if (emailLabel) emailLabel->hide();
+ } else {
+ if (emailLineEdit) emailLineEdit->hide();
+ if (emailLabel) {
+ emailLabel->setText(QString("<a href=\"mailto:%1\">%1</a>").arg(Qt::escape(emailLineEdit->text())));
+ emailLabel->show();
+ }
+ }
+}
+
+}