summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Smith <git@kismith.co.uk>2011-11-01 23:04:03 (GMT)
committerKevin Smith <git@kismith.co.uk>2011-11-01 23:04:03 (GMT)
commit16d50c0df983e96a28a6572da27b3633b40a41d7 (patch)
tree9b7a74f074e33d00966b2e8bf71d31162fa619dc /Swift/QtUI/Roster
parenta710cb325c7827679c35c61ab41b821a5bc77673 (diff)
downloadswift-contrib-16d50c0df983e96a28a6572da27b3633b40a41d7.zip
swift-contrib-16d50c0df983e96a28a6572da27b3633b40a41d7.tar.bz2
Having a play with a compact roster mode
Diffstat (limited to 'Swift/QtUI/Roster')
-rw-r--r--Swift/QtUI/Roster/DelegateCommons.cpp29
-rw-r--r--Swift/QtUI/Roster/DelegateCommons.h4
-rw-r--r--Swift/QtUI/Roster/QtOccupantListWidget.cpp2
-rw-r--r--Swift/QtUI/Roster/QtOccupantListWidget.h3
-rw-r--r--Swift/QtUI/Roster/QtRosterWidget.cpp2
-rw-r--r--Swift/QtUI/Roster/QtRosterWidget.h4
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.cpp26
-rw-r--r--Swift/QtUI/Roster/QtTreeWidget.h5
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.cpp10
-rw-r--r--Swift/QtUI/Roster/RosterDelegate.h5
10 files changed, 57 insertions, 33 deletions
diff --git a/Swift/QtUI/Roster/DelegateCommons.cpp b/Swift/QtUI/Roster/DelegateCommons.cpp
index 290794d..0dc8a52 100644
--- a/Swift/QtUI/Roster/DelegateCommons.cpp
+++ b/Swift/QtUI/Roster/DelegateCommons.cpp
@@ -1,108 +1,111 @@
/*
* Copyright (c) 2010 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include "DelegateCommons.h"
#include <QtScaledAvatarCache.h>
#include <QFileInfo>
namespace Swift {
void DelegateCommons::drawElidedText(QPainter* painter, const QRect& region, const QString& text, int flags) {
QString adjustedText(painter->fontMetrics().elidedText(text, Qt::ElideRight, region.width(), Qt::TextShowMnemonic));
painter->drawText(region, flags, adjustedText);
}
-void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, int unreadCount) const {
+void DelegateCommons::paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, int unreadCount, bool compact) const {
painter->save();
QRect fullRegion(option.rect);
if ( option.state & QStyle::State_Selected ) {
painter->fillRect(fullRegion, option.palette.highlight());
painter->setPen(option.palette.highlightedText().color());
} else {
painter->setPen(QPen(nameColor));
}
QRect presenceIconRegion(QPoint(farLeftMargin, fullRegion.top()), QSize(presenceIconWidth, fullRegion.height() - verticalMargin));
int calculatedAvatarSize = presenceIconRegion.height();
//This overlaps the presenceIcon, so must be painted first
QRect avatarRegion(QPoint(presenceIconRegion.right() - presenceIconWidth / 2, presenceIconRegion.top()), QSize(calculatedAvatarSize, calculatedAvatarSize));
QPixmap avatarPixmap;
- if (!avatarPath.isEmpty()) {
+ if (!compact && !avatarPath.isEmpty()) {
QString scaledAvatarPath = QtScaledAvatarCache(avatarRegion.height()).getScaledAvatarPath(avatarPath);
if (QFileInfo(scaledAvatarPath).exists()) {
avatarPixmap.load(scaledAvatarPath);
}
}
- if (avatarPixmap.isNull()) {
+ if (!compact && avatarPixmap.isNull()) {
avatarPixmap = QPixmap(":/icons/avatar.png").scaled(avatarRegion.height(), avatarRegion.width(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
- painter->drawPixmap(avatarRegion.topLeft() + QPoint(((avatarRegion.width() - avatarPixmap.width()) / 2), (avatarRegion.height() - avatarPixmap.height()) / 2), avatarPixmap);
+ if (!compact) {
+ painter->drawPixmap(avatarRegion.topLeft() + QPoint(((avatarRegion.width() - avatarPixmap.width()) / 2), (avatarRegion.height() - avatarPixmap.height()) / 2), avatarPixmap);
+ }
//Paint the presence icon over the top of the avatar
presenceIcon.paint(painter, presenceIconRegion, Qt::AlignBottom | Qt::AlignHCenter);
QFontMetrics nameMetrics(nameFont);
painter->setFont(nameFont);
int extraFontWidth = nameMetrics.width("H");
- int leftOffset = avatarRegion.right() + horizontalMargin * 2 + extraFontWidth / 2;
+ int leftOffset = (compact ? presenceIconRegion : avatarRegion).right() + horizontalMargin * 2 + extraFontWidth / 2;
QRect textRegion(fullRegion.adjusted(leftOffset, 0, 0/*-leftOffset*/, 0));
int nameHeight = nameMetrics.height() + verticalMargin;
QRect nameRegion(textRegion.adjusted(0, verticalMargin, 0, 0));
DelegateCommons::drawElidedText(painter, nameRegion, name);
+ if (!compact) {
+ painter->setFont(detailFont);
+ painter->setPen(QPen(QColor(160,160,160)));
- painter->setFont(detailFont);
- painter->setPen(QPen(QColor(160,160,160)));
-
- QRect statusTextRegion(textRegion.adjusted(0, nameHeight, 0, 0));
- DelegateCommons::drawElidedText(painter, statusTextRegion, statusText);
+ QRect statusTextRegion(textRegion.adjusted(0, nameHeight, 0, 0));
+ DelegateCommons::drawElidedText(painter, statusTextRegion, statusText);
+ }
if (unreadCount > 0) {
QRect unreadRect(fullRegion.right() - unreadCountSize - horizontalMargin, fullRegion.top() + (fullRegion.height() - unreadCountSize) / 2, unreadCountSize, unreadCountSize);
QPen pen(QColor("black"));
pen.setWidth(1);
painter->setRenderHint(QPainter::Antialiasing, true);
painter->setPen(pen);
painter->setBrush(QBrush(QColor("red"), Qt::SolidPattern));
//painter->setBackgroundMode(Qt::OpaqueMode);
painter->drawEllipse(unreadRect);
painter->setBackgroundMode(Qt::TransparentMode);
painter->setPen(QColor("white"));
drawElidedText(painter, unreadRect, QString("%1").arg(unreadCount), Qt::AlignCenter);
}
painter->restore();
}
-QSize DelegateCommons::contactSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/ ) const {
- int heightByAvatar = avatarSize + verticalMargin * 2;
+QSize DelegateCommons::contactSizeHint(const QStyleOptionViewItem& /*option*/, const QModelIndex& /*index*/, bool compact ) const {
+ int heightByAvatar = (compact ? presenceIconHeight : avatarSize) + verticalMargin * 2;
QFontMetrics nameMetrics(nameFont);
QFontMetrics statusMetrics(detailFont);
- int sizeByText = 2 * verticalMargin + nameMetrics.height() + statusMetrics.height();
+ int sizeByText = 2 * verticalMargin + nameMetrics.height() + (compact ? 0 : statusMetrics.height());
//Doesn't work, yay! FIXME: why?
//QSize size = (option.state & QStyle::State_Selected) ? QSize(150, 80) : QSize(150, avatarSize_ + margin_ * 2);
//qDebug() << "Returning size" << size;
return QSize(150, sizeByText > heightByAvatar ? sizeByText : heightByAvatar);
}
const int DelegateCommons::horizontalMargin = 2;
const int DelegateCommons::verticalMargin = 2;
const int DelegateCommons::farLeftMargin = 2;
const int DelegateCommons::avatarSize = 20;
const int DelegateCommons::presenceIconHeight = 16;
const int DelegateCommons::presenceIconWidth = 16;
const int DelegateCommons::unreadCountSize = 16;
}
diff --git a/Swift/QtUI/Roster/DelegateCommons.h b/Swift/QtUI/Roster/DelegateCommons.h
index e5e4ff9..8732598 100644
--- a/Swift/QtUI/Roster/DelegateCommons.h
+++ b/Swift/QtUI/Roster/DelegateCommons.h
@@ -1,42 +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 <QApplication>
#include <QFont>
#include <QPainter>
#include <QRect>
#include <QString>
#include <QIcon>
#include <QStyleOptionViewItem>
namespace Swift {
class DelegateCommons {
public:
DelegateCommons() : nameFont(QApplication::font()), detailFont(QApplication::font()) {
detailFontSizeDrop = nameFont.pointSize() >= 10 ? 2 : 0;
detailFont.setStyle(QFont::StyleItalic);
detailFont.setPointSize(nameFont.pointSize() - detailFontSizeDrop);
}
static void drawElidedText(QPainter* painter, const QRect& region, const QString& text, int flags = Qt::AlignTop);
- QSize contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
- void paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, int unreadCount) const;
+ QSize contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index, bool compact) const;
+ void paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QColor& nameColor, const QString& avatarPath, const QIcon& presenceIcon, const QString& name, const QString& statusText, int unreadCount, bool compact) const;
int detailFontSizeDrop;
QFont nameFont;
QFont detailFont;
static const int horizontalMargin;
static const int verticalMargin;
static const int farLeftMargin;
static const int avatarSize;
static const int presenceIconHeight;
static const int presenceIconWidth;
static const int unreadCountSize;
};
}
diff --git a/Swift/QtUI/Roster/QtOccupantListWidget.cpp b/Swift/QtUI/Roster/QtOccupantListWidget.cpp
index d7bb875..f864919 100644
--- a/Swift/QtUI/Roster/QtOccupantListWidget.cpp
+++ b/Swift/QtUI/Roster/QtOccupantListWidget.cpp
@@ -1,57 +1,57 @@
/*
* Copyright (c) 2011 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include "Roster/QtOccupantListWidget.h"
#include <QContextMenuEvent>
#include <QMenu>
#include <QAction>
#include <QInputDialog>
#include "Swift/Controllers/Roster/ContactRosterItem.h"
#include "Swift/Controllers/Roster/GroupRosterItem.h"
#include "Swift/Controllers/UIEvents/UIEventStream.h"
#include "QtSwiftUtil.h"
namespace Swift {
-QtOccupantListWidget::QtOccupantListWidget(UIEventStream* eventStream, QWidget* parent) : QtTreeWidget(eventStream, parent) {
+QtOccupantListWidget::QtOccupantListWidget(UIEventStream* eventStream, QtUIPreferences* uiPreferences, QWidget* parent) : QtTreeWidget(eventStream, uiPreferences, parent) {
}
QtOccupantListWidget::~QtOccupantListWidget() {
}
void QtOccupantListWidget::setAvailableOccupantActions(const std::vector<ChatWindow::OccupantAction>& actions) {
availableOccupantActions_ = actions;
}
void QtOccupantListWidget::contextMenuEvent(QContextMenuEvent* event) {
QModelIndex index = indexAt(event->pos());
if (!index.isValid()) {
return;
}
RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item);
if (contact) {
onSomethingSelectedChanged(contact);
QMenu contextMenu;
if (availableOccupantActions_.empty()) {
QAction* noAction = contextMenu.addAction(tr("No actions for this user"));
noAction->setEnabled(false);
contextMenu.exec(event->globalPos());
}
else {
std::map<QAction*, ChatWindow::OccupantAction> actions;
foreach (ChatWindow::OccupantAction availableAction, availableOccupantActions_) {
QString text = "Error: missing string";
switch (availableAction) {
case ChatWindow::Kick: text = tr("Kick user"); break;
case ChatWindow::Ban: text = tr("Kick and ban user"); break;
case ChatWindow::MakeModerator: text = tr("Make moderator"); break;
diff --git a/Swift/QtUI/Roster/QtOccupantListWidget.h b/Swift/QtUI/Roster/QtOccupantListWidget.h
index ef29c00..da7c463 100644
--- a/Swift/QtUI/Roster/QtOccupantListWidget.h
+++ b/Swift/QtUI/Roster/QtOccupantListWidget.h
@@ -1,30 +1,31 @@
/*
* Copyright (c) 2011 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
#include "Swift/QtUI/Roster/QtTreeWidget.h"
#include "Swiften/Base/boost_bsignals.h"
#include "Swift/Controllers/UIInterfaces/ChatWindow.h"
namespace Swift {
+class QtUIPreferences;
class QtOccupantListWidget : public QtTreeWidget {
Q_OBJECT
public:
- QtOccupantListWidget(UIEventStream* eventStream, QWidget* parent = 0);
+ QtOccupantListWidget(UIEventStream* eventStream, QtUIPreferences* uiPreferences, QWidget* parent = 0);
virtual ~QtOccupantListWidget();
void setAvailableOccupantActions(const std::vector<ChatWindow::OccupantAction>& actions);
boost::signal<void (ChatWindow::OccupantAction, ContactRosterItem*)> onOccupantActionSelected;
protected:
void contextMenuEvent(QContextMenuEvent* event);
private:
std::vector<ChatWindow::OccupantAction> availableOccupantActions_;
};
}
diff --git a/Swift/QtUI/Roster/QtRosterWidget.cpp b/Swift/QtUI/Roster/QtRosterWidget.cpp
index 4c96695..ac4b500 100644
--- a/Swift/QtUI/Roster/QtRosterWidget.cpp
+++ b/Swift/QtUI/Roster/QtRosterWidget.cpp
@@ -1,61 +1,61 @@
/*
* Copyright (c) 2011 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include "Roster/QtRosterWidget.h"
#include <QContextMenuEvent>
#include <QMenu>
#include <QInputDialog>
#include <QFileDialog>
#include "Swift/Controllers/UIEvents/RequestContactEditorUIEvent.h"
#include "Swift/Controllers/UIEvents/RemoveRosterItemUIEvent.h"
#include "Swift/Controllers/UIEvents/RenameGroupUIEvent.h"
#include "Swift/Controllers/UIEvents/SendFileUIEvent.h"
#include "QtContactEditWindow.h"
#include "Swift/Controllers/Roster/ContactRosterItem.h"
#include "Swift/Controllers/Roster/GroupRosterItem.h"
#include "Swift/Controllers/UIEvents/UIEventStream.h"
#include "QtSwiftUtil.h"
namespace Swift {
-QtRosterWidget::QtRosterWidget(UIEventStream* eventStream, QWidget* parent) : QtTreeWidget(eventStream, parent) {
+QtRosterWidget::QtRosterWidget(UIEventStream* eventStream, QtUIPreferences* uiPreferences, QWidget* parent) : QtTreeWidget(eventStream, uiPreferences, parent) {
}
QtRosterWidget::~QtRosterWidget() {
}
void QtRosterWidget::handleEditUserActionTriggered(bool /*checked*/) {
QModelIndexList selectedIndexList = getSelectedIndexes();
if (selectedIndexList.empty()) {
return;
}
QModelIndex index = selectedIndexList[0];
if (!index.isValid()) {
return;
}
RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) {
eventStream_->send(boost::make_shared<RequestContactEditorUIEvent>(contact->getJID()));
}
}
void QtRosterWidget::contextMenuEvent(QContextMenuEvent* event) {
QModelIndex index = indexAt(event->pos());
if (!index.isValid()) {
return;
}
RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
QMenu contextMenu;
if (ContactRosterItem* contact = dynamic_cast<ContactRosterItem*>(item)) {
QAction* editContact = contextMenu.addAction(tr("Edit"));
QAction* removeContact = contextMenu.addAction(tr("Remove"));
#ifdef SWIFT_EXPERIMENTAL_FT
QAction* sendFile = NULL;
if (contact->supportsFeature(ContactRosterItem::FileTransferFeature)) {
diff --git a/Swift/QtUI/Roster/QtRosterWidget.h b/Swift/QtUI/Roster/QtRosterWidget.h
index f870237..01f4726 100644
--- a/Swift/QtUI/Roster/QtRosterWidget.h
+++ b/Swift/QtUI/Roster/QtRosterWidget.h
@@ -1,25 +1,27 @@
/*
* Copyright (c) 2011 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
#include "Swift/QtUI/Roster/QtTreeWidget.h"
namespace Swift {
+class QtUIPreferences;
+
class QtRosterWidget : public QtTreeWidget {
Q_OBJECT
public:
- QtRosterWidget(UIEventStream* eventStream, QWidget* parent = 0);
+ QtRosterWidget(UIEventStream* eventStream, QtUIPreferences* uiPreferences, QWidget* parent = 0);
virtual ~QtRosterWidget();
public slots:
void handleEditUserActionTriggered(bool checked);
protected:
void contextMenuEvent(QContextMenuEvent* event);
private:
void renameGroup(GroupRosterItem* group);
};
}
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;
diff --git a/Swift/QtUI/Roster/QtTreeWidget.h b/Swift/QtUI/Roster/QtTreeWidget.h
index 271fbd5..705c039 100644
--- a/Swift/QtUI/Roster/QtTreeWidget.h
+++ b/Swift/QtUI/Roster/QtTreeWidget.h
@@ -1,58 +1,61 @@
/*
* Copyright (c) 2010 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
#include <QTreeView>
#include <QModelIndex>
#include <QDragEnterEvent>
#include <QDropEvent>
#include <QDragMoveEvent>
#include "Swift/QtUI/Roster/RosterModel.h"
#include "Swift/QtUI/Roster/RosterDelegate.h"
namespace Swift {
class UIEventStream;
+class QtUIPreferences;
class QtTreeWidget : public QTreeView{
Q_OBJECT
public:
- QtTreeWidget(UIEventStream* eventStream, QWidget* parent = 0);
+ QtTreeWidget(UIEventStream* eventStream, QtUIPreferences* uiPreferences, QWidget* parent = 0);
~QtTreeWidget();
void show();
QtTreeWidgetItem* getRoot();
void setRosterModel(Roster* roster);
Roster* getRoster() {return roster_;}
boost::signal<void (RosterItem*)> onSomethingSelectedChanged;
private slots:
void handleItemActivated(const QModelIndex&);
void handleModelItemExpanded(const QModelIndex&, bool expanded);
void handleExpanded(const QModelIndex&);
void handleCollapsed(const QModelIndex&);
void handleClicked(const QModelIndex&);
+ void handleCompactRostersToggled(bool compact);
protected:
void dragEnterEvent(QDragEnterEvent* event);
void dropEvent(QDropEvent* event);
void dragMoveEvent(QDragMoveEvent* event);
protected:
QModelIndexList getSelectedIndexes() const;
private:
void drawBranches(QPainter*, const QRect&, const QModelIndex&) const;
protected slots:
virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
protected:
UIEventStream* eventStream_;
private:
RosterModel* model_;
Roster* roster_;
RosterDelegate* delegate_;
QtTreeWidgetItem* treeRoot_;
+ QtUIPreferences* uiPreferences_;
};
}
diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp
index e40907a..7e6428b 100644
--- a/Swift/QtUI/Roster/RosterDelegate.cpp
+++ b/Swift/QtUI/Roster/RosterDelegate.cpp
@@ -1,78 +1,82 @@
/*
* Copyright (c) 2010 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include "RosterDelegate.h"
#include <QApplication>
#include <QPainter>
#include <QColor>
#include <QBrush>
#include <QFontMetrics>
#include <QPainterPath>
#include <QPolygon>
#include <qdebug.h>
#include <QBitmap>
#include "Swift/Controllers/Roster/ContactRosterItem.h"
#include "Swift/Controllers/Roster/GroupRosterItem.h"
#include "QtTreeWidget.h"
#include "RosterModel.h"
namespace Swift {
-RosterDelegate::RosterDelegate(QtTreeWidget* tree) {
+RosterDelegate::RosterDelegate(QtTreeWidget* tree, bool compact) : compact_(compact) {
tree_ = tree;
groupDelegate_ = new GroupItemDelegate();
}
RosterDelegate::~RosterDelegate() {
delete groupDelegate_;
}
+
+void RosterDelegate::setCompact(bool compact) {
+ compact_ = compact;
+}
QSize RosterDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const {
RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
if (dynamic_cast<GroupRosterItem*>(item)) {
return groupDelegate_->sizeHint(option, index);
}
return contactSizeHint(option, index);
}
QSize RosterDelegate::contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const {
- return common_.contactSizeHint(option, index);
+ return common_.contactSizeHint(option, index, compact_);
}
void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
RosterItem* item = static_cast<RosterItem*>(index.internalPointer());
if (dynamic_cast<GroupRosterItem*>(item)) {
paintGroup(painter, option, index);
} else {
paintContact(painter, option, index);
}
}
void RosterDelegate::paintGroup(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
if (index.isValid()) {
groupDelegate_->paint(painter, option, index.data(Qt::DisplayRole).toString(), index.data(ChildCountRole).toInt(), tree_->isExpanded(index));
}
}
void RosterDelegate::paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const {
QColor nameColor = index.data(Qt::TextColorRole).value<QColor>();
QString avatarPath;
if (index.data(AvatarRole).isValid() && !index.data(AvatarRole).value<QString>().isNull()) {
avatarPath = index.data(AvatarRole).value<QString>();
}
QIcon presenceIcon = index.data(PresenceIconRole).isValid() && !index.data(PresenceIconRole).value<QIcon>().isNull()
? index.data(PresenceIconRole).value<QIcon>()
: QIcon(":/icons/offline.png");
QString name = index.data(Qt::DisplayRole).toString();
QString statusText = index.data(StatusTextRole).toString();
- common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, 0);
+ common_.paintContact(painter, option, nameColor, avatarPath, presenceIcon, name, statusText, 0, compact_);
}
}
diff --git a/Swift/QtUI/Roster/RosterDelegate.h b/Swift/QtUI/Roster/RosterDelegate.h
index 253c11a..c5db7ef 100644
--- a/Swift/QtUI/Roster/RosterDelegate.h
+++ b/Swift/QtUI/Roster/RosterDelegate.h
@@ -1,32 +1,35 @@
/*
* Copyright (c) 2010 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#pragma once
#include <QStyledItemDelegate>
#include <QColor>
#include <QFont>
#include "GroupItemDelegate.h"
#include "DelegateCommons.h"
namespace Swift {
class QtTreeWidget;
class RosterDelegate : public QStyledItemDelegate {
public:
- RosterDelegate(QtTreeWidget* tree);
+ RosterDelegate(QtTreeWidget* tree, bool compact);
~RosterDelegate();
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ public slots:
+ void setCompact(bool compact);
private:
QSize contactSizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
void paintGroup(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
void paintContact(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
+ bool compact_;
DelegateCommons common_;
GroupItemDelegate* groupDelegate_;
QtTreeWidget* tree_;
};
}