From c3b4fc7dcf8475e4dcf7b42b496e332df4a4f7b1 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Sat, 1 Aug 2009 15:46:37 +0100 Subject: Resize avatars to 32pix in Roster, change alignments to be relative, do item hiding. diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp index e70983f..bbb5e98 100644 --- a/Swift/QtUI/Roster/QtTreeWidgetItem.cpp +++ b/Swift/QtUI/Roster/QtTreeWidgetItem.cpp @@ -7,6 +7,7 @@ namespace Swift { QtTreeWidgetItem::QtTreeWidgetItem(QtTreeWidgetItem* parentItem) : QObject() { parent_ = parentItem; + shown_ = true; } void QtTreeWidgetItem::setText(const String& text) { @@ -37,13 +38,18 @@ void QtTreeWidgetItem::setExpanded(bool b) { } void QtTreeWidgetItem::hide() { - //setHidden(true); + shown_ = false; + emit changed(); } void QtTreeWidgetItem::show() { - //setHidden(false); + shown_ = true; + emit changed(); } +bool QtTreeWidgetItem::isShown() { + return shown_; +} QWidget* QtTreeWidgetItem::getCollapsedRosterWidget() { QWidget* widget = new QWidget(); @@ -66,19 +72,28 @@ QtTreeWidgetItem* QtTreeWidgetItem::getParentItem() { } void QtTreeWidgetItem::addChild(QtTreeWidgetItem* child) { - printf("Boing\n"); children_.append(child); - connect(child, SIGNAL(changed()), this, SIGNAL(changed())); + connect(child, SIGNAL(changed()), this, SLOT(handleChanged())); + handleChanged(); +} + +void QtTreeWidgetItem::handleChanged() { + shownChildren_.clear(); + for (int i = 0; i < children_.size(); i++) { + if (children_[i]->isShown()) { + shownChildren_.append(children_[i]); + } + } emit changed(); } int QtTreeWidgetItem::rowCount() { qDebug() << "Returning size of " << children_.size() << " for item " << displayName_; - return children_.size(); + return shownChildren_.size(); } int QtTreeWidgetItem::rowOf(QtTreeWidgetItem* item) { - return children_.indexOf(item); + return shownChildren_.indexOf(item); } int QtTreeWidgetItem::row() { @@ -87,7 +102,7 @@ int QtTreeWidgetItem::row() { QtTreeWidgetItem* QtTreeWidgetItem::getItem(int row) { qDebug() << "Returning row " << row << " from item " << displayName_; - return children_[row]; + return shownChildren_[row]; } QVariant QtTreeWidgetItem::data(int role) { diff --git a/Swift/QtUI/Roster/QtTreeWidgetItem.h b/Swift/QtUI/Roster/QtTreeWidgetItem.h index 2dac2fc..e3bfff3 100644 --- a/Swift/QtUI/Roster/QtTreeWidgetItem.h +++ b/Swift/QtUI/Roster/QtTreeWidgetItem.h @@ -39,6 +39,7 @@ class QtTreeWidgetItem : public QObject, public TreeWidgetItem { void setExpanded(bool b); void hide(); void show(); + bool isShown(); bool isContact(); QWidget* getCollapsedRosterWidget(); @@ -46,13 +47,17 @@ class QtTreeWidgetItem : public QObject, public TreeWidgetItem { signals: void changed(); + private slots: + void handleChanged(); private: QList children_; + QList shownChildren_; QtTreeWidgetItem* parent_; QString displayName_; QString statusText_; QColor textColor_; QColor backgroundColor_; + bool shown_; }; } diff --git a/Swift/QtUI/Roster/RosterDelegate.cpp b/Swift/QtUI/Roster/RosterDelegate.cpp index 3b3d6fe..2447e8f 100644 --- a/Swift/QtUI/Roster/RosterDelegate.cpp +++ b/Swift/QtUI/Roster/RosterDelegate.cpp @@ -15,7 +15,7 @@ QSize RosterDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelI return QStyledItemDelegate::sizeHint(option, index); } //Doesn't work, yay! FIXME: why? - QSize size = (option.state & QStyle::State_Selected) ? QSize(150, 80) : QSize(150,56); + QSize size = (option.state & QStyle::State_Selected) ? QSize(150, 80) : QSize(150, avatarSize_ + margin_ * 2); qDebug() << "Returning size" << size; return size; } @@ -35,7 +35,7 @@ void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option painter->fillRect(fullRegion, option.palette.highlight()); painter->setPen(option.palette.highlightedText().color()); } - QRect avatarRegion(QPoint(4, fullRegion.top() + 4), QSize(48, 48)); + QRect avatarRegion(QPoint(margin_, fullRegion.top() + margin_), QSize(avatarSize_, avatarSize_)); QIcon icon = index.data(AvatarRole).isValid() && !index.data(AvatarRole).value().isNull() ? index.data(AvatarRole).value() : QIcon(":/icons/avatar.png"); @@ -45,11 +45,11 @@ void RosterDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option QFont statusFont = painter->font(); painter->setFont(nameFont); - QRect textRegion(fullRegion.adjusted(56, 0, 0, 0)); + QRect textRegion(fullRegion.adjusted(avatarSize_ + margin_ * 2, 0, 0, 0)); QFontMetrics nameMetrics(nameFont); - int nameHeight = nameMetrics.height() + 8; - QRect nameRegion(textRegion.adjusted(0, 4, 0, -1 * nameHeight)); + int nameHeight = nameMetrics.height() + margin_ * 2; + QRect nameRegion(textRegion.adjusted(0, margin_, 0, 0)); painter->drawText(nameRegion, Qt::AlignTop, index.data(Qt::DisplayRole).toString()); statusFont.setStyle(QFont::StyleItalic); diff --git a/Swift/QtUI/Roster/RosterDelegate.h b/Swift/QtUI/Roster/RosterDelegate.h index a48b30f..4a4ad6b 100644 --- a/Swift/QtUI/Roster/RosterDelegate.h +++ b/Swift/QtUI/Roster/RosterDelegate.h @@ -7,5 +7,8 @@ namespace Swift { public: QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const; void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const; + private: + static const int avatarSize_ = 32; + static const int margin_ = 4; }; } \ No newline at end of file -- cgit v0.10.2-6-g49f6