diff --git a/retroshare-gui/src/gui/ChatLobbyWidget.cpp b/retroshare-gui/src/gui/ChatLobbyWidget.cpp index b8547cb1c..5324a8124 100644 --- a/retroshare-gui/src/gui/ChatLobbyWidget.cpp +++ b/retroshare-gui/src/gui/ChatLobbyWidget.cpp @@ -56,7 +56,9 @@ ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WFlags flags) QObject::connect(lobbyTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), this, SLOT(itemDoubleClicked(QTreeWidgetItem*,int))); QObject::connect(lobbyTreeWidget, SIGNAL(itemSelectionChanged()), this, SLOT(updateCurrentLobby())); - //QObject::connect(newlobbytoolButton, SIGNAL(clicked()), this, SLOT(createChatLobby())); + QObject::connect( filterLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(filterItems(QString))); + QObject::connect( filterLineEdit, SIGNAL(filterChanged(int)), this, SLOT(filterColumnChanged(int))); + QObject::connect( createlobbytoolButton, SIGNAL(clicked()), this, SLOT(createChatLobby())); compareRole = new RSTreeWidgetItemCompareRole; compareRole->setRole(COLUMN_NAME, ROLE_SORT); @@ -71,7 +73,7 @@ ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WFlags flags) headerItem->setText(COLUMN_USER_COUNT, tr("Count")); headerItem->setText(COLUMN_TOPIC, tr("Topic")); headerItem->setTextAlignment(COLUMN_NAME, Qt::AlignHCenter | Qt::AlignVCenter); - headerItem->setTextAlignment(COLUMN_TOPIC, Qt::AlignHCenter | Qt::AlignVCenter); + headerItem->setTextAlignment(COLUMN_TOPIC, Qt::AlignHCenter | Qt::AlignVCenter); headerItem->setTextAlignment(COLUMN_USER_COUNT, Qt::AlignHCenter | Qt::AlignVCenter); QHeaderView *header = lobbyTreeWidget->header(); @@ -117,6 +119,10 @@ ChatLobbyWidget::ChatLobbyWidget(QWidget *parent, Qt::WFlags flags) lobbyChanged(); showBlankPage(0) ; + + /* add filter actions */ + filterLineEdit->addFilter(QIcon(), tr("Name"), COLUMN_NAME, tr("Search Name")); + filterLineEdit->setCurrentFilter(COLUMN_NAME); QString help_str = tr( "

  Chat Lobbies

\ @@ -432,7 +438,7 @@ void ChatLobbyWidget::createChatLobby() void ChatLobbyWidget::showLobby(QTreeWidgetItem *item) { - if (item == NULL || item->type() != TYPE_LOBBY) { + if (item == NULL || item->type() != TYPE_LOBBY) { showBlankPage(0) ; return; } @@ -648,6 +654,10 @@ void ChatLobbyWidget::updateCurrentLobby() item->setIcon(COLUMN_NAME, icon) ; } } + + if (filterLineEdit->text().isEmpty() == false) { + filterItems(filterLineEdit->text()); + } } void ChatLobbyWidget::updateMessageChanged(ChatLobbyId id) { @@ -705,3 +715,45 @@ void ChatLobbyWidget::readChatLobbyInvites() } } } + +void ChatLobbyWidget::filterColumnChanged(int) +{ + filterItems(filterLineEdit->text()); +} + +void ChatLobbyWidget::filterItems(const QString &text) +{ + int filterColumn = filterLineEdit->currentFilter(); + + int count = lobbyTreeWidget->topLevelItemCount (); + for (int index = 0; index < count; index++) { + filterItem(lobbyTreeWidget->topLevelItem(index), text, filterColumn); + } +} + +bool ChatLobbyWidget::filterItem(QTreeWidgetItem *item, const QString &text, int filterColumn) +{ + bool visible = true; + + if (text.isEmpty() == false) { + if (item->text(filterColumn).contains(text, Qt::CaseInsensitive) == false) { + visible = false; + } + } + + int visibleChildCount = 0; + int count = item->childCount(); + for (int index = 0; index < count; index++) { + if (filterItem(item->child(index), text, filterColumn)) { + visibleChildCount++; + } + } + + if (visible || visibleChildCount) { + item->setHidden(false); + } else { + item->setHidden(true); + } + + return (visible || visibleChildCount); +} diff --git a/retroshare-gui/src/gui/ChatLobbyWidget.h b/retroshare-gui/src/gui/ChatLobbyWidget.h index 78cf784c9..706bdad8c 100644 --- a/retroshare-gui/src/gui/ChatLobbyWidget.h +++ b/retroshare-gui/src/gui/ChatLobbyWidget.h @@ -51,10 +51,16 @@ protected slots: void updateMessageChanged(ChatLobbyId); void updatePeerEntering(ChatLobbyId); void updatePeerLeaving(ChatLobbyId); - void autoSubscribeItem(); + void autoSubscribeItem(); +private slots: + void filterColumnChanged(int); + void filterItems(const QString &text); + private: - void autoSubscribeLobby(QTreeWidgetItem *item); + void autoSubscribeLobby(QTreeWidgetItem *item); + + bool filterItem(QTreeWidgetItem *item, const QString &text, int filterColumn); RSTreeWidgetItemCompareRole *compareRole; QTreeWidgetItem *privateLobbyItem; diff --git a/retroshare-gui/src/gui/ChatLobbyWidget.ui b/retroshare-gui/src/gui/ChatLobbyWidget.ui index 067d3f92b..4f66ee59d 100644 --- a/retroshare-gui/src/gui/ChatLobbyWidget.ui +++ b/retroshare-gui/src/gui/ChatLobbyWidget.ui @@ -10,8 +10,8 @@ 381 - - + + @@ -89,34 +89,100 @@ - + - - - 0 - 0 - - Qt::Horizontal - - - - 9 - - - - - 16 - 16 - - - - - 1 + + + + 0 - + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 2 + + + 1 + + + 2 + + + 1 + + + 6 + + + 0 + + + + + Search Chat lobbies + + + + + + + Create chat lobby + + + + + + + :/images/add_chat24.png:/images/add_chat24.png + + + + 24 + 24 + + + + true + + + + + + + + + + + 9 + + + + + 16 + 16 + + + + + 1 + + + + + @@ -134,6 +200,13 @@ + + + LineEditClear + QLineEdit +
gui/common/LineEditClear.h
+
+
diff --git a/retroshare-gui/src/gui/images.qrc b/retroshare-gui/src/gui/images.qrc index 0fd6f04b9..521f08f20 100644 --- a/retroshare-gui/src/gui/images.qrc +++ b/retroshare-gui/src/gui/images.qrc @@ -1,5 +1,6 @@ + images/add_chat24.png images/blue_lock.png images/stock_signature_bad.png images/stock_signature_ok.png diff --git a/retroshare-gui/src/gui/images/add_chat24.png b/retroshare-gui/src/gui/images/add_chat24.png new file mode 100644 index 000000000..95585c957 Binary files /dev/null and b/retroshare-gui/src/gui/images/add_chat24.png differ