summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI/QtVCardWidget')
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp43
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h13
-rw-r--r--Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp33
3 files changed, 83 insertions, 6 deletions
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp
index afe5d88..21e794e 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.cpp
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
#include <Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h>
#include <cassert>
@@ -13,7 +19,7 @@
namespace Swift {
QtVCardGeneralField::QtVCardGeneralField(QWidget* parent, QGridLayout* layout, bool editable, int row, QString label, bool preferrable, bool taggable) :
- QWidget(parent), editable(editable), preferrable(preferrable), taggable(taggable), layout(layout), row(row), preferredCheckBox(0), label(0), labelText(label),
+ QWidget(parent), editable(editable), preferrable(preferrable), taggable(taggable), starVisible(false), layout(layout), row(row), preferredCheckBox(0), label(0), labelText(label),
tagComboBox(0), tagLabel(NULL), closeButton(0) {
}
@@ -75,16 +81,22 @@ void QtVCardGeneralField::setEditable(bool editable) {
tagComboBox->hide();
}
closeButton->setVisible(editable);
- if (preferrable) {
- assert(preferredCheckBox);
- preferredCheckBox->setVisible(editable ? true : preferredCheckBox->isChecked());
- preferredCheckBox->setEnabled(editable);
- }
+ updatePreferredStarVisibility();
editableChanged(this->editable);
}
+void QtVCardGeneralField::setStarVisible(const bool isVisible) {
+ starVisible = isVisible;
+ updatePreferredStarVisibility();
+}
+
+bool QtVCardGeneralField::getStarVisible() const {
+ return starVisible;
+}
+
void QtVCardGeneralField::setPreferred(const bool preferred) {
if (preferredCheckBox) preferredCheckBox->setChecked(preferred);
+ updatePreferredStarVisibility();
}
bool QtVCardGeneralField::getPreferred() const {
@@ -111,4 +123,23 @@ void QtVCardGeneralField::handleCloseButtonClicked() {
deleteField(this);
}
+void QtVCardGeneralField::updatePreferredStarVisibility() {
+ if (preferredCheckBox) {
+ bool showStar = false;
+ if (editable) {
+ if (starVisible) {
+ showStar = true;
+ }
+ else {
+ showStar = preferredCheckBox->isChecked();
+ }
+ }
+ else {
+ showStar = preferredCheckBox->isChecked();
+ }
+ preferredCheckBox->setVisible(showStar);
+ preferredCheckBox->setEnabled(editable);
+ }
+}
+
}
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h
index 4afe692..93d326b 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h
+++ b/Swift/QtUI/QtVCardWidget/QtVCardGeneralField.h
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
#pragma once
#include <QCheckBox>
@@ -40,6 +46,9 @@ class QtVCardGeneralField : public QWidget {
virtual bool isEmpty() const = 0;
+ void setStarVisible(const bool isVisible);
+ bool getStarVisible() const;
+
void setPreferred(const bool preferred);
bool getPreferred() const;
@@ -61,8 +70,12 @@ class QtVCardGeneralField : public QWidget {
QList<QWidget*> childWidgets;
private:
+ void updatePreferredStarVisibility();
+
+ private:
bool editable;
bool preferrable;
+ bool starVisible;
bool taggable;
QGridLayout* layout;
int row;
diff --git a/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp b/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp
index d681fe9..7dfc06a 100644
--- a/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp
+++ b/Swift/QtUI/QtVCardWidget/QtVCardWidget.cpp
@@ -4,6 +4,12 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
#include <Swift/QtUI/QtVCardWidget/QtVCardWidget.h>
#include <QDebug>
@@ -299,6 +305,19 @@ void QtVCardWidget::addField() {
}
void QtVCardWidget::removeField(QtVCardGeneralField *field) {
+ int sameFields = 0;
+ QtVCardGeneralField* fieldToChange = NULL;
+ foreach (QtVCardGeneralField* vcardField, fields) {
+ if ((vcardField != field) && (typeid(*vcardField) == typeid(*field))) {
+ sameFields++;
+ fieldToChange = vcardField;
+ }
+ }
+
+ if ((sameFields == 1) && fieldToChange) {
+ fieldToChange->setStarVisible(false);
+ }
+
fields.remove(field);
delete field;
}
@@ -364,6 +383,20 @@ void QtVCardWidget::clearEmptyFields() {
void QtVCardWidget::appendField(QtVCardGeneralField *field) {
connect(field, SIGNAL(deleteField(QtVCardGeneralField*)), SLOT(removeField(QtVCardGeneralField*)));
+
+ QtVCardGeneralField* fieldToChange = NULL;
+ foreach (QtVCardGeneralField* vcardField, fields) {
+ if (typeid(*vcardField) == typeid(*field)) {
+ fieldToChange = vcardField;
+ break;
+ }
+ }
+
+ if (fieldToChange) {
+ fieldToChange->setStarVisible(true);
+ field->setStarVisible(true);
+ }
+
fields.push_back(field);
}