summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swift/QtUI')
-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
@@ -1,25 +1,31 @@
/*
* Copyright (c) 2012-2014 Tobias Markmann
* Licensed under the simplified BSD license.
* 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>
#include <QHBoxLayout>
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) {
}
QtVCardGeneralField::~QtVCardGeneralField() {
}
void QtVCardGeneralField::initialize() {
if (preferrable) {
@@ -69,28 +75,34 @@ void QtVCardGeneralField::setEditable(bool editable) {
if (taggable) {
tagLabel->setText(tagComboBox->itemText(0));
tagComboBox->setVisible(editable);
tagLabel->setVisible(!editable);
} else {
tagLabel->hide();
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 {
return preferredCheckBox ? preferredCheckBox->isChecked() : false;
}
void QtVCardGeneralField::customCleanup() {
}
@@ -105,10 +117,29 @@ QGridLayout* QtVCardGeneralField::getGridLayout() const {
void QtVCardGeneralField::handleCloseButtonClicked() {
customCleanup();
foreach(QWidget* widget, childWidgets) {
widget->hide();
layout->removeWidget(widget);
}
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
@@ -1,15 +1,21 @@
/*
* Copyright (c) 2012 Tobias Markmann
* Licensed under the simplified BSD license.
* 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>
#include <QGridLayout>
#include <QLabel>
#include <QWidget>
#include "QtCloseButton.h"
#include "QtTagComboBox.h"
@@ -34,18 +40,21 @@ class QtVCardGeneralField : public QWidget {
virtual ~QtVCardGeneralField();
void initialize();
virtual bool isEditable() const;
virtual void setEditable(bool);
virtual bool isEmpty() const = 0;
+ void setStarVisible(const bool isVisible);
+ bool getStarVisible() const;
+
void setPreferred(const bool preferred);
bool getPreferred() const;
protected:
virtual void setupContentWidgets() = 0;
virtual void customCleanup();
QtTagComboBox* getTagComboBox() const;
QGridLayout* getGridLayout() const;
@@ -55,20 +64,24 @@ class QtVCardGeneralField : public QWidget {
void deleteField(QtVCardGeneralField*);
public slots:
void handleCloseButtonClicked();
protected:
QList<QWidget*> childWidgets;
private:
+ void updatePreferredStarVisibility();
+
+ private:
bool editable;
bool preferrable;
+ bool starVisible;
bool taggable;
QGridLayout* layout;
int row;
QCheckBox* preferredCheckBox;
QLabel* label;
QString labelText;
QtTagComboBox* tagComboBox;
QLabel* tagLabel;
QtCloseButton* closeButton;
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
@@ -1,15 +1,21 @@
/*
* Copyright (c) 2012 Tobias Markmann
* Licensed under the simplified BSD license.
* 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>
#include <QLineEdit>
#include <QMenu>
#include <Swift/QtUI/QtVCardWidget/ui_QtVCardWidget.h>
#include <Swift/QtUI/QtVCardWidget/QtVCardAddressField.h>
#include <Swift/QtUI/QtVCardWidget/QtVCardAddressLabelField.h>
@@ -293,18 +299,31 @@ void QtVCardWidget::addField() {
if (newGeneralField) {
newGeneralField->initialize();
}
appendField(newGeneralField);
relayoutToolButton();
}
}
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;
}
void QtVCardWidget::addFieldType(QMenu* menu, boost::shared_ptr<QtVCardFieldInfo> fieldType) {
if (!fieldType->getMenuName().isEmpty()) {
QAction* action = new QAction(tr("Add ") + fieldType->getMenuName(), this);
actionFieldInfo[action] = fieldType;
connect(action, SIGNAL(triggered()), this, SLOT(addField()));
@@ -358,17 +377,31 @@ void QtVCardWidget::clearEmptyFields() {
}
foreach(QtVCardGeneralField* field, items_to_remove) {
fields.remove(field);
}
}
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);
}
void QtVCardWidget::relayoutToolButton() {
ui->cardFields->addWidget(toolButton, ui->cardFields->rowCount(), ui->cardFields->columnCount()-2, 1, 1, Qt::AlignRight);
}
}