diff options
author | Tobias Markmann <tm@ayena.de> | 2013-04-30 20:10:12 (GMT) |
---|---|---|
committer | Swift Review <review@swift.im> | 2013-10-01 14:48:44 (GMT) |
commit | fd47dd7d5cec5155b9985959d2f0e0f3b386cd98 (patch) | |
tree | d4da57ce3f1c90f56701cab8757d75e089473c9e /Swift/QtUI/UserSearch/QtContactListWidget.cpp | |
parent | a3781c5b770c03ff32c5cf8f1280b21c2a8e2626 (diff) | |
download | swift-contrib-fd47dd7d5cec5155b9985959d2f0e0f3b386cd98.zip swift-contrib-fd47dd7d5cec5155b9985959d2f0e0f3b386cd98.tar.bz2 |
Adding support for impromptu MUCs.
Change-Id: I363e9d740bbec311454827645f4ea6df8bb60bed
License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Diffstat (limited to 'Swift/QtUI/UserSearch/QtContactListWidget.cpp')
-rw-r--r-- | Swift/QtUI/UserSearch/QtContactListWidget.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/Swift/QtUI/UserSearch/QtContactListWidget.cpp b/Swift/QtUI/UserSearch/QtContactListWidget.cpp new file mode 100644 index 0000000..899c592 --- /dev/null +++ b/Swift/QtUI/UserSearch/QtContactListWidget.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2013 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swift/QtUI/UserSearch/QtContactListWidget.h> + +#include <Swift/QtUI/UserSearch/ContactListModel.h> +#include <Swift/QtUI/UserSearch/ContactListDelegate.h> +#include <Swift/QtUI/QtUISettingConstants.h> +#include <Swift/Controllers/Settings/SettingsProvider.h> +#include <Swift/QtUI/QtVCardWidget/QtRemovableItemDelegate.h> + +#include <QHeaderView> + +namespace Swift { + +QtContactListWidget::QtContactListWidget(QWidget* parent, SettingsProvider* settings) : QTreeView(parent), settings_(settings), limited_(false) { + contactListModel_ = new ContactListModel(true); + setModel(contactListModel_); + + connect(contactListModel_, SIGNAL(onListChanged(std::vector<Contact>)), this, SLOT(handleListChanged(std::vector<Contact>))); + connect(contactListModel_, SIGNAL(onListChanged(std::vector<Contact>)), this, SIGNAL(onListChanged(std::vector<Contact>))); + connect(contactListModel_, SIGNAL(onJIDsDropped(std::vector<JID>)), this, SIGNAL(onJIDsAdded(std::vector<JID>))); + + setSelectionMode(QAbstractItemView::SingleSelection); + setSelectionBehavior(QAbstractItemView::SelectRows); + setDragEnabled(true); + setAcceptDrops(true); + setDropIndicatorShown(true); + setUniformRowHeights(true); + + setAlternatingRowColors(true); + setIndentation(0); + setHeaderHidden(true); + setExpandsOnDoubleClick(false); + setItemsExpandable(false); + setEditTriggers(QAbstractItemView::DoubleClicked); + + contactListDelegate_ = new ContactListDelegate(settings->getSetting(QtUISettingConstants::COMPACT_ROSTER)); + removableItemDelegate_ = new QtRemovableItemDelegate(style()); + + setItemDelegateForColumn(0, contactListDelegate_); + setItemDelegateForColumn(1, removableItemDelegate_); + + int closeIconWidth = fontMetrics().height(); + header()->resizeSection(1, closeIconWidth); + + header()->setStretchLastSection(false); +#if QT_VERSION >= 0x050000 + header()->setSectionResizeMode(0, QHeaderView::Stretch); +#else + header()->setResizeMode(0, QHeaderView::Stretch); +#endif +} + +QtContactListWidget::~QtContactListWidget() { + delete contactListDelegate_; + delete removableItemDelegate_; +} + +void QtContactListWidget::setList(const std::vector<Contact>& list) { + contactListModel_->setList(list); +} + +std::vector<Contact> QtContactListWidget::getList() const { + return contactListModel_->getList(); +} + +void QtContactListWidget::setMaximumNoOfContactsToOne(bool limited) { + limited_ = limited; + if (limited) { + handleListChanged(getList()); + } else { + setAcceptDrops(true); + setDropIndicatorShown(true); + } +} + +void QtContactListWidget::updateContacts(const std::vector<Contact>& contactUpdates) { + std::vector<Contact> contacts = contactListModel_->getList(); + foreach(const Contact& contactUpdate, contactUpdates) { + for(size_t n = 0; n < contacts.size(); n++) { + if (contactUpdate.jid == contacts[n].jid) { + contacts[n] = contactUpdate; + break; + } + } + } + contactListModel_->setList(contacts); +} + +void QtContactListWidget::handleListChanged(std::vector<Contact> list) { + if (limited_) { + setAcceptDrops(list.size() <= 1); + setDropIndicatorShown(list.size() <= 1); + } +} + +void QtContactListWidget::handleSettingsChanged(const std::string&) { + contactListDelegate_->setCompact(settings_->getSetting(QtUISettingConstants::COMPACT_ROSTER)); +} + +} |