diff options
| author | Kevin Smith <git@kismith.co.uk> | 2011-11-01 23:04:03 (GMT) |
|---|---|---|
| committer | Kevin Smith <git@kismith.co.uk> | 2011-11-01 23:04:03 (GMT) |
| commit | 16d50c0df983e96a28a6572da27b3633b40a41d7 (patch) | |
| tree | 9b7a74f074e33d00966b2e8bf71d31162fa619dc /Swift/QtUI/Roster/QtTreeWidget.cpp | |
| parent | a710cb325c7827679c35c61ab41b821a5bc77673 (diff) | |
| download | swift-contrib-16d50c0df983e96a28a6572da27b3633b40a41d7.zip swift-contrib-16d50c0df983e96a28a6572da27b3633b40a41d7.tar.bz2 | |
Having a play with a compact roster mode
Diffstat (limited to 'Swift/QtUI/Roster/QtTreeWidget.cpp')
| -rw-r--r-- | Swift/QtUI/Roster/QtTreeWidget.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp index 690515d..4382125 100644 --- a/Swift/QtUI/Roster/QtTreeWidget.cpp +++ b/Swift/QtUI/Roster/QtTreeWidget.cpp @@ -1,87 +1,95 @@ /* * Copyright (c) 2010 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include "Roster/QtTreeWidget.h" #include <boost/smart_ptr/make_shared.hpp> #include <QUrl> -#include "Swiften/Base/Platform.h" -#include "Swift/Controllers/Roster/ContactRosterItem.h" -#include "Swift/Controllers/Roster/GroupRosterItem.h" -#include "Swift/Controllers/UIEvents/UIEventStream.h" -#include "Swift/Controllers/UIEvents/RequestChatUIEvent.h" -#include "Swift/Controllers/UIEvents/SendFileUIEvent.h" -#include "QtSwiftUtil.h" +#include <Swiften/Base/Platform.h> +#include <Swift/Controllers/Roster/ContactRosterItem.h> +#include <Swift/Controllers/Roster/GroupRosterItem.h> +#include <Swift/Controllers/UIEvents/UIEventStream.h> +#include <Swift/Controllers/UIEvents/RequestChatUIEvent.h> +#include <Swift/Controllers/UIEvents/SendFileUIEvent.h> +#include <QtSwiftUtil.h> +#include <Swift/QtUI/QtUIPreferences.h> namespace Swift { -QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, QWidget* parent) : QTreeView(parent) { +QtTreeWidget::QtTreeWidget(UIEventStream* eventStream, QtUIPreferences* uiPreferences, QWidget* parent) : QTreeView(parent) { eventStream_ = eventStream; + uiPreferences_ = uiPreferences; model_ = new RosterModel(this); setModel(model_); - delegate_ = new RosterDelegate(this); + delegate_ = new RosterDelegate(this, uiPreferences_->getCompactRosters()); setItemDelegate(delegate_); setHeaderHidden(true); #ifdef SWIFT_PLATFORM_MACOSX setAlternatingRowColors(true); #endif setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); expandAll(); setAnimated(true); setIndentation(0); #ifdef SWIFT_EXPERIMENTAL_FT setAcceptDrops(true); #endif setRootIsDecorated(true); connect(this, SIGNAL(activated(const QModelIndex&)), this, SLOT(handleItemActivated(const QModelIndex&))); connect(model_, SIGNAL(itemExpanded(const QModelIndex&, bool)), this, SLOT(handleModelItemExpanded(const QModelIndex&, bool))); connect(this, SIGNAL(expanded(const QModelIndex&)), this, SLOT(handleExpanded(const QModelIndex&))); connect(this, SIGNAL(collapsed(const QModelIndex&)), this, SLOT(handleCollapsed(const QModelIndex&))); connect(this, SIGNAL(clicked(const QModelIndex&)), this, SLOT(handleClicked(const QModelIndex&))); + connect(uiPreferences_, SIGNAL(onCompactRostersChanged(bool)), this, SLOT(handleCompactRostersToggled(bool))); } QtTreeWidget::~QtTreeWidget() { delete model_; delete delegate_; } +void QtTreeWidget::handleCompactRostersToggled(bool compact) { + delegate_->setCompact(compact); + repaint(); +} + void QtTreeWidget::setRosterModel(Roster* roster) { roster_ = roster; model_->setRoster(roster); expandAll(); } QtTreeWidgetItem* QtTreeWidget::getRoot() { return treeRoot_; } void QtTreeWidget::handleClicked(const QModelIndex& index) { GroupRosterItem* item = dynamic_cast<GroupRosterItem*>(static_cast<RosterItem*>(index.internalPointer())); if (item) { setExpanded(index, !isExpanded(index)); } currentChanged(index, QModelIndex()); } QModelIndexList QtTreeWidget::getSelectedIndexes() const { // Not using selectedIndexes(), because this seems to cause a crash in Qt (4.7.0) in the // QModelIndexList destructor. // This is a workaround posted in http://www.qtcentre.org/threads/16933 (although this case // was resolved by linking against the debug libs, ours isn't, and we're not alone) QItemSelection ranges = selectionModel()->selection(); QModelIndexList selectedIndexList; for (int i = 0; i < ranges.count(); ++i) { QModelIndex parent = ranges.at(i).parent(); int right = ranges.at(i).model()->columnCount(parent) - 1; if (ranges.at(i).left() == 0 && ranges.at(i).right() == right) { for (int r = ranges.at(i).top(); r <= ranges.at(i).bottom(); ++r) { selectedIndexList.append(ranges.at(i).model()->index(r, 0, parent)); } } } return selectedIndexList; |
Swift