diff options
24 files changed, 480 insertions, 133 deletions
diff --git a/Swift/QtUI/QtChatWindow.cpp b/Swift/QtUI/QtChatWindow.cpp index 6328156..2e08adb 100644 --- a/Swift/QtUI/QtChatWindow.cpp +++ b/Swift/QtUI/QtChatWindow.cpp @@ -1,7 +1,7 @@ #include "QtChatWindow.h" #include "QtSwiftUtil.h" -#include "QtTreeWidget.h" -#include "QtTreeWidgetFactory.h" +#include "Roster/QtTreeWidget.h" +#include "Roster/QtTreeWidgetFactory.h" #include "QtChatView.h" #include "MessageSnippet.h" #include "SystemMessageSnippet.h" diff --git a/Swift/QtUI/QtChatWindowFactory.cpp b/Swift/QtUI/QtChatWindowFactory.cpp index 927447c..47c943f 100644 --- a/Swift/QtUI/QtChatWindowFactory.cpp +++ b/Swift/QtUI/QtChatWindowFactory.cpp @@ -3,7 +3,7 @@ #include "QtChatTabs.h" #include "QtChatWindow.h" #include "QtSwiftUtil.h" -#include "QtTreeWidgetFactory.h" +#include "Roster/QtTreeWidgetFactory.h" namespace Swift { diff --git a/Swift/QtUI/QtMainWindow.cpp b/Swift/QtUI/QtMainWindow.cpp index a9ffc51..fffd478 100644 --- a/Swift/QtUI/QtMainWindow.cpp +++ b/Swift/QtUI/QtMainWindow.cpp @@ -2,8 +2,8 @@ #include "QtJoinMUCDialog.h" #include "QtSwiftUtil.h" -#include "QtTreeWidgetFactory.h" -#include "QtTreeWidget.h" +#include "Roster/QtTreeWidgetFactory.h" +#include "Roster/QtTreeWidget.h" #include "QtStatusWidget.h" #include <QBoxLayout> diff --git a/Swift/QtUI/QtMainWindowFactory.cpp b/Swift/QtUI/QtMainWindowFactory.cpp index 288d182..9594ade 100644 --- a/Swift/QtUI/QtMainWindowFactory.cpp +++ b/Swift/QtUI/QtMainWindowFactory.cpp @@ -1,6 +1,6 @@ #include "QtMainWindowFactory.h" #include "QtMainWindow.h" -#include "QtTreeWidgetFactory.h" +#include "Roster/QtTreeWidgetFactory.h" namespace Swift { diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp index e1fac9c..00efc17 100644 --- a/Swift/QtUI/QtSwift.cpp +++ b/Swift/QtUI/QtSwift.cpp @@ -3,7 +3,7 @@ #include "QtLoginWindowFactory.h" #include "QtChatWindowFactory.h" #include "QtMainWindowFactory.h" -#include "QtTreeWidgetFactory.h" +#include "Roster/QtTreeWidgetFactory.h" #include "QtSystemTray.h" #include "QtSoundPlayer.h" diff --git a/Swift/QtUI/QtTreeWidget.cpp b/Swift/QtUI/QtTreeWidget.cpp deleted file mode 100644 index 66c653e..0000000 --- a/Swift/QtUI/QtTreeWidget.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include "QtTreeWidget.h" - -#include "Swiften/Base/Platform.h" -#include "Swiften/Roster/OpenChatRosterAction.h" - -namespace Swift { - -QtTreeWidget::QtTreeWidget(QWidget* parent) : QTreeWidget(parent) { - setHeaderHidden(true); -#ifdef SWIFT_PLATFORM_MACOSX - setAlternatingRowColors(true); -#endif - setAnimated(true); - setIndentation(0); - setRootIsDecorated(true); - connect(this, SIGNAL(itemActivated(QTreeWidgetItem*, int)), this, SLOT(handleItemActivated(QTreeWidgetItem*, int))); -} - -void QtTreeWidget::handleItemActivated(QTreeWidgetItem* item, int column) { - QtTreeWidgetItem* qtItem = dynamic_cast<QtTreeWidgetItem*>(item); - if (qtItem) { - qtItem->performUserAction(boost::shared_ptr<UserRosterAction>(new OpenChatRosterAction())); - } -} - -void QtTreeWidget::drawBranches(QPainter*, const QRect&, const QModelIndex&) const { -} - -} diff --git a/Swift/QtUI/QtTreeWidget.h b/Swift/QtUI/QtTreeWidget.h deleted file mode 100644 index e1d83de..0000000 --- a/Swift/QtUI/QtTreeWidget.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef SWIFT_QtTreeWidget_H -#define SWIFT_QtTreeWidget_H - -#include <QTreeWidget> - -#include "Swiften/Roster/TreeWidgetFactory.h" -#include "Swiften/Roster/TreeWidget.h" -#include "Swiften/Roster/TreeWidgetItem.h" -#include "Swift/QtUI/QtTreeWidgetItem.h" -#include "Swift/QtUI/QtTreeWidget.h" - -namespace Swift { - -class QtTreeWidget : public QTreeWidget, public TreeWidget { - Q_OBJECT - public: - QtTreeWidget(QWidget* parent = 0); - - private slots: - void handleItemActivated(QTreeWidgetItem*, int); - - private: - void drawBranches(QPainter*, const QRect&, const QModelIndex&) const; -}; - -} -#endif - diff --git a/Swift/QtUI/QtTreeWidgetItem.cpp b/Swift/QtUI/QtTreeWidgetItem.cpp deleted file mode 100644 index e69de29..0000000 --- a/Swift/QtUI/QtTreeWidgetItem.cpp +++ /dev/null diff --git a/Swift/QtUI/QtTreeWidgetItem.h b/Swift/QtUI/QtTreeWidgetItem.h deleted file mode 100644 index 34ad93c..0000000 --- a/Swift/QtUI/QtTreeWidgetItem.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef SWIFT_QtTreeWidgetItem_H -#define SWIFT_QtTreeWidgetItem_H - -#include <QColor> - -#include "Swiften/Base/String.h" -#include "Swiften/Roster/TreeWidgetFactory.h" -#include "Swiften/Roster/TreeWidget.h" -#include "Swiften/Roster/TreeWidgetItem.h" -#include "Swift/QtUI/QtTreeWidgetItem.h" -#include "Swift/QtUI/QtTreeWidget.h" -#include "Swift/QtUI/QtSwiftUtil.h" - -namespace Swift { - -class QtTreeWidgetItem : public QTreeWidgetItem, public TreeWidgetItem { - public: - QtTreeWidgetItem(QTreeWidget* parent) : QTreeWidgetItem(parent) { - } - - QtTreeWidgetItem(QTreeWidgetItem* parent) : QTreeWidgetItem(parent) { - } - - void setText(const String& text) { - QTreeWidgetItem::setText(0, P2QSTRING(text)); - } - - void setTextColor(unsigned long color) { - QTreeWidgetItem::setTextColor(0, QColor( - ((color & 0xFF0000)>>16), - ((color & 0xFF00)>>8), - (color & 0xFF))); - } - - void setBackgroundColor(unsigned long color) { - QTreeWidgetItem::setBackgroundColor(0, QColor( - ((color & 0xFF0000)>>16), - ((color & 0xFF00)>>8), - (color & 0xFF))); - } - - void setExpanded(bool b) { - treeWidget()->setItemExpanded(this, b); - } - - void hide() { - setHidden(true); - } - - void show() { - setHidden(false); - } -}; - -} -#endif - diff --git a/Swift/QtUI/Roster/QtTreeWidget.cpp b/Swift/QtUI/Roster/QtTreeWidget.cpp new file mode 100644 index 0000000..714beb2 --- /dev/null +++ b/Swift/QtUI/Roster/QtTreeWidget.cpp @@ -0,0 +1,48 @@ +#include "Roster/QtTreeWidget.h" + +#include "Swiften/Base/Platform.h" +#include "Swiften/Roster/OpenChatRosterAction.h" + +namespace Swift { + +QtTreeWidget::QtTreeWidget(QWidget* parent) : QTreeView(parent) { + treeRoot_ = new QtTreeWidgetItem(NULL); + model_ = new RosterModel(); + model_->setRoot(treeRoot_); + setModel(model_); + delegate_ = new RosterDelegate(); + setItemDelegate(delegate_); + setHeaderHidden(true); +#ifdef SWIFT_PLATFORM_MACOSX + setAlternatingRowColors(true); +#endif + setAnimated(true); + setIndentation(0); + setRootIsDecorated(true); + //connect(this, SIGNAL(itemActivated(QTreeWidgetItem*, int)), this, SLOT(handleItemActivated(QTreeWidgetItem*, int))); +} + +QtTreeWidget::~QtTreeWidget() { + delete model_; + delete delegate_; +} + +QtTreeWidgetItem* QtTreeWidget::getRoot() { + return treeRoot_; +} + +// void QtTreeWidget::handleItemActivated(QTreeWidgetItem* item, int column) { +// QtTreeWidgetItem* qtItem = dynamic_cast<QtTreeWidgetItem*>(item); +// if (qtItem) { +// qtItem->performUserAction(boost::shared_ptr<UserRosterAction>(new OpenChatRosterAction())); +// } +// } + +void QtTreeWidget::drawBranches(QPainter*, const QRect&, const QModelIndex&) const { +} + +void QtTreeWidget::show() { + QWidget::show(); +} + +} diff --git a/Swift/QtUI/Roster/QtTreeWidget.h b/Swift/QtUI/Roster/QtTreeWidget.h new file mode 100644 index 0000000..b8d3c23 --- /dev/null +++ b/Swift/QtUI/Roster/QtTreeWidget.h @@ -0,0 +1,35 @@ +#ifndef SWIFT_QtTreeWidget_H +#define SWIFT_QtTreeWidget_H + +#include <QTreeView> + +#include "Swiften/Roster/TreeWidgetFactory.h" +#include "Swiften/Roster/TreeWidget.h" +#include "Swiften/Roster/TreeWidgetItem.h" +#include "Swift/QtUI/Roster/QtTreeWidgetItem.h" +#include "Swift/QtUI/Roster/QtTreeWidget.h" +#include "Swift/QtUI/Roster/RosterModel.h" +#include "Swift/QtUI/Roster/RosterDelegate.h" + +namespace Swift { + +class QtTreeWidget : public QTreeView, public TreeWidget { + Q_OBJECT + public: + QtTreeWidget(QWidget* parent = 0); + ~QtTreeWidget(); + void show(); + QtTreeWidgetItem* getRoot(); + //private slots: + // void handleItemActivated(QTreeWidgetItem*, int); + private: + void drawBranches(QPainter*, const QRect&, const QModelIndex&) const; + RosterModel* model_; + RosterDelegate* delegate_; + QtTreeWidgetItem* treeRoot_; + +}; + +} +#endif + diff --git a/Swift/QtUI/QtTreeWidgetFactory.cpp b/Swift/QtUI/Roster/QtTreeWidgetFactory.cpp index e69de29..e69de29 100644 --- a/Swift/QtUI/QtTreeWidgetFactory.cpp +++ b/Swift/QtUI/Roster/QtTreeWidgetFactory.cpp diff --git a/Swift/QtUI/QtTreeWidgetFactory.h b/Swift/QtUI/Roster/QtTreeWidgetFactory.h index e0140d2..2ca1e21 100644 --- a/Swift/QtUI/QtTreeWidgetFactory.h +++ b/Swift/QtUI/Roster/QtTreeWidgetFactory.h @@ -4,8 +4,8 @@ #include "Swiften/Roster/TreeWidgetFactory.h" #include "Swiften/Roster/TreeWidget.h" #include "Swiften/Roster/TreeWidgetItem.h" -#include "Swift/QtUI/QtTreeWidgetItem.h" -#include "Swift/QtUI/QtTreeWidget.h" +#include "Swift/QtUI/Roster/QtTreeWidgetItem.h" +#include "Swift/QtUI/Roster/QtTreeWidget.h" namespace Swift { @@ -21,13 +21,19 @@ class QtTreeWidgetFactory : public TreeWidgetFactory { TreeWidgetItem* createTreeWidgetItem(TreeWidgetItem* item) { QtTreeWidgetItem* qtItem = dynamic_cast<QtTreeWidgetItem*>(item); assert(qtItem); - return new QtTreeWidgetItem(qtItem); + QtTreeWidgetItem* newItem = new QtTreeWidgetItem(qtItem); + qtItem->addChild(newItem); + return newItem; } TreeWidgetItem* createTreeWidgetItem(TreeWidget* item) { - QtTreeWidget* qtItem = dynamic_cast<QtTreeWidget*>(item); - assert(qtItem); - return new QtTreeWidgetItem(qtItem); + QtTreeWidget* treeItem = dynamic_cast<QtTreeWidget*>(item); + assert(treeItem); + QtTreeWidgetItem* qtItem = treeItem->getRoot(); + QtTreeWidgetItem* newItem = new QtTreeWidgetItem(qtItem); + //qtItem->setItemWidget(newItem, 0, newItem->getCollapsedRosterWidget()); + qtItem->addChild(newItem); + return newItem; } }; diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp new file mode 100644 index 0000000..e70983f --- /dev/null +++ b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp @@ -0,0 +1,105 @@ +#include "Swift/QtUI/Roster/QtTreeWidgetItem.h" +#include "Swift/QtUI/Roster/QtTreeWidget.h" + +#include <qdebug.h> + +namespace Swift { + +QtTreeWidgetItem::QtTreeWidgetItem(QtTreeWidgetItem* parentItem) : QObject() { + parent_ = parentItem; +} + +void QtTreeWidgetItem::setText(const String& text) { + displayName_ = P2QSTRING(text); + statusText_ = displayName_ + " went away"; +} + +void QtTreeWidgetItem::setStatusText(const String& text) { + statusText_ = P2QSTRING(text); +} + +void QtTreeWidgetItem::setTextColor(unsigned long color) { + textColor_ = QColor( + ((color & 0xFF0000)>>16), + ((color & 0xFF00)>>8), + (color & 0xFF)); +} + +void QtTreeWidgetItem::setBackgroundColor(unsigned long color) { + backgroundColor_ = QColor( + ((color & 0xFF0000)>>16), + ((color & 0xFF00)>>8), + (color & 0xFF)); +} + +void QtTreeWidgetItem::setExpanded(bool b) { + //treeWidget()->setItemExpanded(this, b); +} + +void QtTreeWidgetItem::hide() { + //setHidden(true); +} + +void QtTreeWidgetItem::show() { + //setHidden(false); +} + + +QWidget* QtTreeWidgetItem::getCollapsedRosterWidget() { + QWidget* widget = new QWidget(); + + return widget; +} + +QWidget* QtTreeWidgetItem::getExpandedRosterWidget() { + QWidget* widget = new QWidget(); + + return widget; +} + +QtTreeWidgetItem::~QtTreeWidgetItem() { + qDeleteAll(children_); +} + +QtTreeWidgetItem* QtTreeWidgetItem::getParentItem() { + return parent_; +} + +void QtTreeWidgetItem::addChild(QtTreeWidgetItem* child) { + printf("Boing\n"); + children_.append(child); + connect(child, SIGNAL(changed()), this, SIGNAL(changed())); + emit changed(); +} + +int QtTreeWidgetItem::rowCount() { + qDebug() << "Returning size of " << children_.size() << " for item " << displayName_; + return children_.size(); +} + +int QtTreeWidgetItem::rowOf(QtTreeWidgetItem* item) { + return children_.indexOf(item); +} + +int QtTreeWidgetItem::row() { + return parent_ ? parent_->rowOf(this) : 0; +} + +QtTreeWidgetItem* QtTreeWidgetItem::getItem(int row) { + qDebug() << "Returning row " << row << " from item " << displayName_; + return children_[row]; +} + +QVariant QtTreeWidgetItem::data(int role) { + switch (role) { + case Qt::DisplayRole: return displayName_; + case StatusTextRole: return statusText_; + default: return QVariant(); + } +} + +bool QtTreeWidgetItem::isContact() { + return children_.size() == 0; +} + +}
\ No newline at end of file diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.h b/Swift/QtUI/Roster/QtTreeWidgetItem.h new file mode 100644 index 0000000..2dac2fc --- /dev/null +++ b/Swift/QtUI/Roster/QtTreeWidgetItem.h @@ -0,0 +1,60 @@ +#ifndef SWIFT_QtTreeWidgetItem_H +#define SWIFT_QtTreeWidgetItem_H + +#include <QColor> + +#include "Swiften/Base/String.h" +#include "Swiften/Roster/TreeWidgetFactory.h" +#include "Swiften/Roster/TreeWidget.h" +#include "Swiften/Roster/TreeWidgetItem.h" +#include "Swift/QtUI/Roster/QtTreeWidgetItem.h" + + +#include "Swift/QtUI/QtSwiftUtil.h" + + +namespace Swift { + enum RosterRoles { + StatusTextRole = Qt::UserRole, + AvatarRole = Qt::UserRole + 1 + }; + +class QtTreeWidget; +class QtTreeWidgetItem : public QObject, public TreeWidgetItem { + Q_OBJECT + public: + ~QtTreeWidgetItem(); + void addChild(QtTreeWidgetItem* child); + QtTreeWidgetItem* getParentItem(); + int rowCount(); + int rowOf(QtTreeWidgetItem* item); + int row(); + QtTreeWidgetItem* getItem(int row); + QVariant data(int role); + QtTreeWidgetItem(QtTreeWidgetItem* parentItem); + void setText(const String& text); + void setStatusText(const String& text); + void setTextColor(unsigned long color); + void setBackgroundColor(unsigned long color); + void setExpanded(bool b); + void hide(); + void show(); + bool isContact(); + + QWidget* getCollapsedRosterWidget(); + QWidget* getExpandedRosterWidget(); + + signals: + void changed(); + private: + QList<QtTreeWidgetItem*> children_; + QtTreeWidgetItem* parent_; + QString displayName_; + QString statusText_; + QColor textColor_; + QColor backgroundColor_; +}; + +} +#endif + diff --git a/Swift/QtUI/Roster/Roster.pri b/Swift/QtUI/Roster/Roster.pri new file mode 100644 index 0000000..bc14889 --- /dev/null +++ b/Swift/QtUI/Roster/Roster.pri @@ -0,0 +1,12 @@ +SOURCES += $$PWD/RosterDelegate.cpp \ +# $$PWD/RosterItem.cpp \ + $$PWD/RosterModel.cpp \ + $$PWD/QtTreeWidget.cpp \ + $$PWD/QtTreeWidgetItem.cpp + +HEADERS += $$PWD/RosterDelegate.h \ +# $$PWD/RosterItem.h \ + $$PWD/RosterModel.h \ + $$PWD/QtTreeWidget.h \ + $$PWD/QtTreeWidgetFactory.h \ + $$PWD/QtTreeWidgetItem.h diff --git a/Swift/QtUI/Roster/Roster.pro b/Swift/QtUI/Roster/Roster.pro new file mode 100644 index 0000000..be0cff3 --- /dev/null +++ b/Swift/QtUI/Roster/Roster.pro @@ -0,0 +1,18 @@ +include(Roster.pri) +SOURCES += main.cpp + +DEPENDPATH += ../. ../../.. ../../../3rdParty/Boost +INCLUDEPATH += ../. ../../.. ../../../3rdParty/Boost + +DEFINES += BOOST_SIGNALS_NAMESPACE=bsignals BOOST_ALL_NO_LIB + +exists(../config.pri) { + LIBS += ../../Controllers/Controllers.a ../../../Swiften/Swiften.a + include(../config.pri) +} + +mac { + DEFINES += SWIFT_PLATFORM_MACOSX +} + +RESOURCES += ../Swift.qrc
\ No newline at end of file diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp new file mode 100644 index 0000000..b6b9ded --- /dev/null +++ b/Swift/QtUI/Roster/RosterDelegate.cpp @@ -0,0 +1,48 @@ +#include "RosterDelegate.h" + +#include <QPainter> +#include <qdebug.h> + +#include "QtTreeWidgetItem.h" + +namespace Swift { +QSize RosterDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index ) const { + QtTreeWidgetItem* item = static_cast<QtTreeWidgetItem*>(index.internalPointer()); + if (item && !item->isContact()) { + return QStyledItemDelegate::sizeHint(option, index); + } + //Doesn't work, yay! FIXME: why? + QSize size = (option.state & QStyle::State_Selected) ? QSize(200, 50) : QSize(100,50); + qDebug() << "Returning size" << size; + return size; +} + +void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const { + QtTreeWidgetItem* item = static_cast<QtTreeWidgetItem*>(index.internalPointer()); + if (item && !item->isContact()) { + QStyledItemDelegate::paint(painter, option, index); + return; + } + qDebug() << "painting" << index.data(Qt::DisplayRole).toString(); + painter->save(); + //QStyledItemDelegate::paint(painter, option, index); + //initStyleOption(option, index); + QRect fullRegion(option.rect); + + QRect avatarRegion(QPoint(0, fullRegion.top()), QSize(32, 32)); + QIcon icon = index.data(AvatarRole).isValid() && !index.data(AvatarRole).value<QIcon>().isNull() + ? index.data(AvatarRole).value<QIcon>() + : QIcon(":/icons/avatar.png"); + icon.paint(painter, avatarRegion, Qt::AlignVCenter | Qt::AlignHCenter); + + QRect textRegion(fullRegion.adjusted(avatarRegion.width(), 0, 0, 0)); + QRect nameRegion(textRegion.adjusted(0,0,0,-25)); + painter->drawText(nameRegion, Qt::AlignVCenter, index.data(Qt::DisplayRole).toString()); + + QRect statusTextRegion(textRegion.adjusted(0, 25, 0, 0)); + painter->drawText(statusTextRegion, Qt::AlignVCenter, index.data(StatusTextRole).toString()); + + painter->restore(); +} + +}
\ No newline at end of file diff --git a/Swift/QtUI/Roster/RosterDelegate.h b/Swift/QtUI/Roster/RosterDelegate.h new file mode 100644 index 0000000..a48b30f --- /dev/null +++ b/Swift/QtUI/Roster/RosterDelegate.h @@ -0,0 +1,11 @@ +#pragma once + +#import <QStyledItemDelegate> + +namespace Swift { + class RosterDelegate : public QStyledItemDelegate { + public: + QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; + void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; + }; +}
\ No newline at end of file diff --git a/Swift/QtUI/Roster/RosterModel.cpp b/Swift/QtUI/Roster/RosterModel.cpp new file mode 100644 index 0000000..147aa67 --- /dev/null +++ b/Swift/QtUI/Roster/RosterModel.cpp @@ -0,0 +1,63 @@ +#include "RosterModel.h" + +namespace Swift { + +RosterModel::RosterModel() { +} + +RosterModel::~RosterModel() { + delete tree_; +} + +void RosterModel::setRoot(QtTreeWidgetItem* root) { + tree_ = root; + connect(tree_, SIGNAL(changed()), this, SLOT(handleItemChanged())); +} + + +void RosterModel::handleItemChanged() { + //FIXME: This is just a lazy hack to cause the view to refresh until it works. + // Then I'll replace it with the proper implementation. + printf("Changed\n"); + reset(); + emit layoutChanged(); +} + +int RosterModel::columnCount(const QModelIndex& parent) const { + Q_UNUSED(parent); + return 1; +} + +QVariant RosterModel::data(const QModelIndex& index, int role) const { + QtTreeWidgetItem* item = index.isValid() ? static_cast<QtTreeWidgetItem*>(index.internalPointer()) : NULL; + return item ? item->data(role) : QVariant(); +} + +QModelIndex RosterModel::index(int row, int column, const QModelIndex& parent) const { + QtTreeWidgetItem* parentItem = parent.isValid() ? static_cast<QtTreeWidgetItem*>(parent.internalPointer()) : tree_; + Q_ASSERT(parentItem); + + return row < parentItem->rowCount() ? createIndex(row, column, parentItem->getItem(row)) : QModelIndex(); +} + +QModelIndex RosterModel::parent(const QModelIndex& index) const { + if (!index.isValid()) { + return QModelIndex(); + } + + QtTreeWidgetItem* item = static_cast<QtTreeWidgetItem*>(index.internalPointer()); + Q_ASSERT(item); + + QtTreeWidgetItem* parentItem = item->getParentItem(); + return parentItem == tree_ ? QModelIndex() : createIndex(parentItem->row(), 0, parentItem); + +} + +int RosterModel::rowCount(const QModelIndex& parent) const { + QtTreeWidgetItem* item = parent.isValid() ? static_cast<QtTreeWidgetItem*>(parent.internalPointer()) : tree_; + Q_ASSERT(item); + + return item->rowCount(); +} + +}
\ No newline at end of file diff --git a/Swift/QtUI/Roster/RosterModel.h b/Swift/QtUI/Roster/RosterModel.h new file mode 100644 index 0000000..e75bc2f --- /dev/null +++ b/Swift/QtUI/Roster/RosterModel.h @@ -0,0 +1,26 @@ +#pragma once + +#include "Swift/QtUI/Roster/QtTreeWidgetItem.h" + +#include <QAbstractItemModel> +#include <QList> + +namespace Swift { +class RosterModel : public QAbstractItemModel { +Q_OBJECT +public: + RosterModel(); + ~RosterModel(); + void setRoot(QtTreeWidgetItem* tree); + int columnCount(const QModelIndex& parent = QModelIndex()) const; + QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; + QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; + QModelIndex parent(const QModelIndex& index) const; + int rowCount(const QModelIndex& parent = QModelIndex()) const; +private slots: + void handleItemChanged(); +private: + QtTreeWidgetItem* tree_; +}; + +}
\ No newline at end of file diff --git a/Swift/QtUI/Roster/main.cpp b/Swift/QtUI/Roster/main.cpp new file mode 100644 index 0000000..f3623ac --- /dev/null +++ b/Swift/QtUI/Roster/main.cpp @@ -0,0 +1,31 @@ +#include <QtGui> +#include "QtTreeWidget.h" +#include "QtTreeWidgetFactory.h" + +int main(int argc, char *argv[]) +{ + QApplication app(argc, argv); + + //Swift::RosterModel model; + + //QTreeView view; + //view.setModel(&model); + //view.setWindowTitle("A roster"); + //view.show(); + + Swift::QtTreeWidgetFactory treeWidgetFactory; + Swift::QtTreeWidget* tree = dynamic_cast<Swift::QtTreeWidget*>(treeWidgetFactory.createTreeWidget()); + Swift::QtTreeWidgetItem* group = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(tree)); + group->setText("People"); + group->setBackgroundColor(0xBBBBBB); + Swift::QtTreeWidgetItem* item1 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group)); + Swift::QtTreeWidgetItem* item2 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group)); + Swift::QtTreeWidgetItem* item3 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group)); + Swift::QtTreeWidgetItem* item4 = dynamic_cast<Swift::QtTreeWidgetItem*>(treeWidgetFactory.createTreeWidgetItem(group)); + item1->setText("Remko"); + item2->setText("Kevin"); + item3->setText("Cath"); + item4->setText("Kim"); + tree->show(); + return app.exec(); +}
\ No newline at end of file diff --git a/Swift/QtUI/Swift.pro b/Swift/QtUI/Swift.pro index 0af8216..7c36c07 100644 --- a/Swift/QtUI/Swift.pro +++ b/Swift/QtUI/Swift.pro @@ -55,9 +55,6 @@ HEADERS += \ QtSettingsProvider.h \ QtStatusWidget.h \ QtSwift.h \ - QtTreeWidget.h \ - QtTreeWidgetFactory.h \ - QtTreeWidgetItem.h \ QtChatView.h \ QtChatTabs.h \ QtSoundPlayer.h \ @@ -79,7 +76,6 @@ SOURCES += \ QtSettingsProvider.cpp \ QtStatusWidget.cpp \ QtSwift.cpp \ - QtTreeWidget.cpp \ QtChatView.cpp \ QtChatTabs.cpp \ QtSoundPlayer.cpp \ @@ -91,6 +87,8 @@ SOURCES += \ FORMS += QtJoinMUCDialog.ui +include(Roster/Roster.pri) + RESOURCES += Swift.qrc DefaultTheme.qrc win32 { diff --git a/Swiften/Roster/Roster.cpp b/Swiften/Roster/Roster.cpp index 61c0286..b51d8eb 100644 --- a/Swiften/Roster/Roster.cpp +++ b/Swiften/Roster/Roster.cpp @@ -39,7 +39,7 @@ GroupRosterItem* Roster::getGroup(const String& groupName) { } GroupRosterItem* group = new GroupRosterItem(groupName, treeWidget_, widgetFactory_); children_.push_back(group); - items_.push_back(group); + items_.push_back(group); return group; } @@ -49,7 +49,7 @@ void Roster::handleUserAction(boost::shared_ptr<UserRosterAction> action) { void Roster::addContact(const JID& jid, const String& name, const String& group) { ContactRosterItem *item = new ContactRosterItem(jid, name, getGroup(group), widgetFactory_); - items_.push_back(item); + items_.push_back(item); item->onUserAction.connect(boost::bind(&Roster::handleUserAction, this, _1)); filterItem(item); |