diff options
author | Remko Tronçon <git@el-tramo.be> | 2011-02-07 20:21:28 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2011-02-07 20:21:28 (GMT) |
commit | 4636fb155afcb2d7084e7a0debfa093780488f22 (patch) | |
tree | d5c5f26b4e0377c3e44732d8ad019bfbde17f422 /Swift/QtUI | |
parent | a21d013c029bdeef960dad9327a3d07dfdcdaa30 (diff) | |
download | swift-4636fb155afcb2d7084e7a0debfa093780488f22.zip swift-4636fb155afcb2d7084e7a0debfa093780488f22.tar.bz2 |
Split contact editing out into separate widget.
Diffstat (limited to 'Swift/QtUI')
-rw-r--r-- | Swift/QtUI/QtContactEditWidget.cpp | 92 | ||||
-rw-r--r-- | Swift/QtUI/QtContactEditWidget.h | 42 |
2 files changed, 134 insertions, 0 deletions
diff --git a/Swift/QtUI/QtContactEditWidget.cpp b/Swift/QtUI/QtContactEditWidget.cpp new file mode 100644 index 0000000..50d964b --- /dev/null +++ b/Swift/QtUI/QtContactEditWidget.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#include "QtContactEditWidget.h" + +#include <algorithm> + +#include <QScrollArea> +#include <QBoxLayout> +#include <QLabel> +#include <QCheckBox> +#include <QLineEdit> + +#include "Swift/QtUI/QtSwiftUtil.h" + +namespace Swift { + +QtContactEditWidget::QtContactEditWidget(const std::set<String>& allGroups, QWidget* parent) : QWidget(parent), groups_(NULL) { + QBoxLayout* layout = new QVBoxLayout(this); + setContentsMargins(0,0,0,0); + + QHBoxLayout* nameLayout = new QHBoxLayout(); + + QLabel* label = new QLabel("Name:", this); + nameLayout->addWidget(label); + name_ = new QLineEdit(this); + nameLayout->addWidget(name_); + layout->addLayout(nameLayout); + + layout->addWidget(new QLabel("Groups:", this)); + + QScrollArea* groupsArea = new QScrollArea(this); + layout->addWidget(groupsArea); + groupsArea->setWidgetResizable(true); + groupsArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); + groupsArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); + + QWidget* groups = new QWidget(groupsArea); + groupsArea->setWidget(groups); + QVBoxLayout* scrollLayout = new QVBoxLayout(groups); + + foreach (String group, allGroups) { + QCheckBox* check = new QCheckBox(groups); + check->setText(P2QSTRING(group)); + check->setCheckState(Qt::Unchecked); + checkBoxes_[group] = check; + scrollLayout->addWidget(check); + } + + QHBoxLayout* newGroupLayout = new QHBoxLayout(); + newGroup_ = new QCheckBox(groups); + newGroup_->setText("New Group:"); + newGroup_->setCheckState(Qt::Unchecked); + newGroupLayout->addWidget(newGroup_); + newGroupName_ = new QLineEdit(groups); + newGroupLayout->addWidget(newGroupName_); + scrollLayout->addLayout(newGroupLayout); + + scrollLayout->addItem(new QSpacerItem(20, 73, QSizePolicy::Minimum, QSizePolicy::Expanding)); +} + +void QtContactEditWidget::setName(const String& name) { + name_->setText(P2QSTRING(name)); +} + +String QtContactEditWidget::getName() const { + return Q2PSTRING(name_->text()); +} + +void QtContactEditWidget::setSelectedGroups(const std::vector<String>& groups) { + foreach (String group, groups) { + checkBoxes_[group]->setCheckState(Qt::Checked); + } +} + +std::set<String> QtContactEditWidget::getSelectedGroups() const { + std::set<String> groups; + foreach(const CheckBoxMap::value_type& group, checkBoxes_) { + if (group.second->checkState() == Qt::Checked) { + groups.insert(group.first); + } + } + if (newGroup_->checkState() == Qt::Checked && !newGroupName_->text().isEmpty()) { + groups.insert(Q2PSTRING(newGroupName_->text())); + } + return groups; +} + +} diff --git a/Swift/QtUI/QtContactEditWidget.h b/Swift/QtUI/QtContactEditWidget.h new file mode 100644 index 0000000..b855b6c --- /dev/null +++ b/Swift/QtUI/QtContactEditWidget.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2010 Kevin Smith + * Licensed under the GNU General Public License v3. + * See Documentation/Licenses/GPLv3.txt for more information. + */ + +#pragma once + +#include <map> +#include <set> +#include <boost/shared_ptr.hpp> + +#include <QWidget> + +#include <Swiften/Base/String.h> + +class QLineEdit; +class QCheckBox; + +namespace Swift { + class QtContactEditWidget : public QWidget { + Q_OBJECT + + public: + QtContactEditWidget(const std::set<String>& allGroups, QWidget* parent); + + void setName(const String&); + String getName() const; + + void setSelectedGroups(const std::vector<String>& groups); + std::set<String> getSelectedGroups() const; + + private: + typedef std::map<String, QCheckBox*> CheckBoxMap; + CheckBoxMap checkBoxes_; + QLineEdit* name_; + QWidget* groups_; + QCheckBox* newGroup_; + QLineEdit* newGroupName_; + }; +} + |