diff options
Diffstat (limited to 'Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp')
-rw-r--r-- | Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp index 183e64d..2a8e1c9 100644 --- a/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp +++ b/Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.cpp @@ -4,9 +4,16 @@ * See Documentation/Licenses/BSD-simplified.txt for more information. */ -#include "QtVCardDescriptionField.h" +/* + * Copyright (c) 2016 Isode Limited. + * All rights reserved. + * See the COPYING file for more information. + */ + +#include <Swift/QtUI/QtVCardWidget/QtVCardDescriptionField.h> #include <boost/algorithm/string.hpp> + #include <QFontMetrics> #include <QGridLayout> @@ -15,50 +22,50 @@ namespace Swift { QtVCardDescriptionField::QtVCardDescriptionField(QWidget* parent, QGridLayout *layout, bool editable) : - QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Description"), false, false), descriptionPlainTextEdit(NULL) { - connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool))); + QtVCardGeneralField(parent, layout, editable, layout->rowCount(), tr("Description"), false, false), descriptionPlainTextEdit(nullptr) { + connect(this, SIGNAL(editableChanged(bool)), SLOT(handleEditibleChanged(bool))); } QtVCardDescriptionField::~QtVCardDescriptionField() { - disconnect(this, SLOT(handleEditibleChanged(bool))); + disconnect(this, SLOT(handleEditibleChanged(bool))); } void QtVCardDescriptionField::setupContentWidgets() { - descriptionPlainTextEdit = new QPlainTextEdit(this); - descriptionPlainTextEdit->setMinimumHeight(70); - getGridLayout()->addWidget(descriptionPlainTextEdit, getGridLayout()->rowCount()-1, 2, 2, 2, Qt::AlignVCenter); - getTagComboBox()->hide(); - childWidgets << descriptionPlainTextEdit; + descriptionPlainTextEdit = new QPlainTextEdit(this); + descriptionPlainTextEdit->setMinimumHeight(70); + getGridLayout()->addWidget(descriptionPlainTextEdit, getGridLayout()->rowCount()-1, 2, 2, 2, Qt::AlignVCenter); + getTagComboBox()->hide(); + childWidgets << descriptionPlainTextEdit; } bool QtVCardDescriptionField::isEmpty() const { - return descriptionPlainTextEdit->toPlainText().isEmpty(); + return descriptionPlainTextEdit->toPlainText().isEmpty(); } void QtVCardDescriptionField::setDescription(const std::string& description) { - descriptionPlainTextEdit->setPlainText(P2QSTRING(description)); + descriptionPlainTextEdit->setPlainText(P2QSTRING(description)); } std::string QtVCardDescriptionField::getDescription() const { - return Q2PSTRING(descriptionPlainTextEdit->toPlainText()); + return Q2PSTRING(descriptionPlainTextEdit->toPlainText()); } void QtVCardDescriptionField::handleEditibleChanged(bool isEditable) { - assert(descriptionPlainTextEdit); + assert(descriptionPlainTextEdit); - if (isEditable) { - descriptionPlainTextEdit->setMinimumHeight(70); - } else { - QFontMetrics inputMetrics(descriptionPlainTextEdit->document()->defaultFont()); - QRect horizontalBounds = contentsRect().adjusted(0,0,0,9999); - QRect boundingRect = inputMetrics.boundingRect(horizontalBounds, Qt::TextWordWrap, descriptionPlainTextEdit->toPlainText() + "A"); - int left, top, right, bottom; - getContentsMargins(&left, &top, &right, &bottom); - int height = boundingRect.height() + top + bottom + inputMetrics.height(); - descriptionPlainTextEdit->setMinimumHeight(height > 70 ? 70 : height); - } - descriptionPlainTextEdit->setReadOnly(!isEditable); - descriptionPlainTextEdit->setStyleSheet(isEditable ? "" : "QPlainTextEdit { background: transparent; }"); + if (isEditable) { + descriptionPlainTextEdit->setMinimumHeight(70); + } else { + QFontMetrics inputMetrics(descriptionPlainTextEdit->document()->defaultFont()); + QRect horizontalBounds = contentsRect().adjusted(0,0,0,9999); + QRect boundingRect = inputMetrics.boundingRect(horizontalBounds, Qt::TextWordWrap, descriptionPlainTextEdit->toPlainText() + "A"); + int left, top, right, bottom; + getContentsMargins(&left, &top, &right, &bottom); + int height = boundingRect.height() + top + bottom + inputMetrics.height(); + descriptionPlainTextEdit->setMinimumHeight(height > 70 ? 70 : height); + } + descriptionPlainTextEdit->setReadOnly(!isEditable); + descriptionPlainTextEdit->setStyleSheet(isEditable ? "" : "QPlainTextEdit { background: transparent; }"); } } |