summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2012-03-14 21:36:10 (GMT)
committerKevin Smith <git@kismith.co.uk>2012-03-20 18:15:37 (GMT)
commit3d27d98ccc232ae7bfacfd5a3f85f44b6c2e9cc9 (patch)
treecae0589a1826560668683d2129fe024148d4e43d /Swift/QtUI/QtContactEditWidget.cpp
parent138223ab9ca917420d107d95a113e7628c27bac5 (diff)
downloadswift-contrib-3d27d98ccc232ae7bfacfd5a3f85f44b6c2e9cc9.zip
swift-contrib-3d27d98ccc232ae7bfacfd5a3f85f44b6c2e9cc9.tar.bz2
Naming suggestion for 'Add Contact'-dialog and "Edit Contact"-dialog based on vCards.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swift/QtUI/QtContactEditWidget.cpp')
-rw-r--r--Swift/QtUI/QtContactEditWidget.cpp71
1 files changed, 61 insertions, 10 deletions
diff --git a/Swift/QtUI/QtContactEditWidget.cpp b/Swift/QtUI/QtContactEditWidget.cpp
index a5134e4..a80eb38 100644
--- a/Swift/QtUI/QtContactEditWidget.cpp
+++ b/Swift/QtUI/QtContactEditWidget.cpp
@@ -8,28 +8,36 @@
#include <algorithm>
-#include <QScrollArea>
#include <QBoxLayout>
-#include <QLabel>
#include <QCheckBox>
+#include <QLabel>
#include <QLineEdit>
+#include <QMovie>
+#include <QScrollArea>
+#include <QRadioButton>
#include "Swift/QtUI/QtSwiftUtil.h"
namespace Swift {
-QtContactEditWidget::QtContactEditWidget(const std::set<std::string>& allGroups, QWidget* parent) : QWidget(parent), groups_(NULL) {
+QtContactEditWidget::QtContactEditWidget(const std::set<std::string>& allGroups, QWidget* parent) : QWidget(parent), nameRadioButton_(NULL), groups_(NULL) {
QBoxLayout* layout = new QVBoxLayout(this);
setContentsMargins(0,0,0,0);
layout->setContentsMargins(0,0,0,0);
- QHBoxLayout* nameLayout = new QHBoxLayout();
-
- QLabel* label = new QLabel(tr("Name:"), this);
- nameLayout->addWidget(label);
+ nameLayout_ = new QHBoxLayout();
+ suggestionsLayout_ = new QHBoxLayout();
+ nameLayout_->addLayout(suggestionsLayout_);
+
name_ = new QLineEdit(this);
- nameLayout->addWidget(name_);
- layout->addLayout(nameLayout);
+ nameLayout_->addWidget(name_);
+
+ throbberLabel_ = new QLabel(this);
+ throbberLabel_->setMovie(new QMovie(":/icons/throbber.gif", QByteArray(), this));
+ throbberLabel_->movie()->start();
+ nameLayout_->addWidget(throbberLabel_);
+
+ layout->addLayout(nameLayout_);
layout->addWidget(new QLabel(tr("Groups:"), this));
@@ -68,7 +76,19 @@ void QtContactEditWidget::setName(const std::string& name) {
}
std::string QtContactEditWidget::getName() const {
- return Q2PSTRING(name_->text());
+ std::string name;
+ QList<QRadioButton*> buttons = findChildren<QRadioButton*>();
+ foreach(const QRadioButton* button, buttons) {
+ if (button->isChecked()) {
+ if (button == nameRadioButton_) {
+ name = Q2PSTRING(name_->text());
+ } else {
+ name = Q2PSTRING(button->text());
+ }
+ break;
+ }
+ }
+ return name;
}
void QtContactEditWidget::setSelectedGroups(const std::vector<std::string>& groups) {
@@ -90,11 +110,42 @@ std::set<std::string> QtContactEditWidget::getSelectedGroups() const {
return groups;
}
+void QtContactEditWidget::setNameSuggestions(const std::vector<std::string>& suggestions) {
+ throbberLabel_->movie()->stop();
+ throbberLabel_->hide();
+
+ foreach(const std::string& name, suggestions) {
+ suggestionsLayout_->insertWidget(nameLayout_->count() - 2, new QRadioButton(P2QSTRING(name), this));
+ }
+
+ nameRadioButton_ = new QRadioButton(tr("Name:"), this);
+ suggestionsLayout_->insertWidget(nameLayout_->count(), nameRadioButton_);
+
+ if (name_->text().isEmpty()) {
+ QRadioButton* suggestedRadioButton = dynamic_cast<QRadioButton*>(suggestionsLayout_->itemAt(0)->widget());
+ if (suggestedRadioButton) {
+ suggestedRadioButton->setChecked(true);
+ }
+ } else {
+ nameRadioButton_->setChecked(true);
+ }
+}
+
void QtContactEditWidget::clear() {
name_->clear();
setSelectedGroups(std::vector<std::string>());
newGroup_->setChecked(false);
newGroupName_->clear();
+ throbberLabel_->movie()->start();
+ throbberLabel_->show();
+
+ // clear suggestions
+ while(suggestionsLayout_->count() != 0) {
+ QLayoutItem *layoutItem = suggestionsLayout_->takeAt(0);
+ delete layoutItem->widget();
+ delete layoutItem;
+ }
+ nameRadioButton_ = NULL;
}
}