From 0416a0d888836f7f407e0585edb70b0d1b333934 Mon Sep 17 00:00:00 2001 From: defnax Date: Mon, 2 Sep 2013 00:08:38 +0000 Subject: [PATCH] Added Search Filter to the ChatLobbyWidget git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6669 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- retroshare-gui/src/gui/ChatLobbyWidget.cpp | 58 ++++++++- retroshare-gui/src/gui/ChatLobbyWidget.h | 10 +- retroshare-gui/src/gui/ChatLobbyWidget.ui | 123 +++++++++++++++---- retroshare-gui/src/gui/images.qrc | 1 + retroshare-gui/src/gui/images/add_chat24.png | Bin 0 -> 1514 bytes 5 files changed, 162 insertions(+), 30 deletions(-) create mode 100644 retroshare-gui/src/gui/images/add_chat24.png 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 0000000000000000000000000000000000000000..95585c957efa33b94b8c4bf32ed70e530536d51e GIT binary patch literal 1514 zcmVN2bPDNB8 zb~7$DE-^7j^FlWO00m}AL_t(YOWl=uP}F4@$6xXYOXW((kSwJU-C((NWZ8>#K}hbE zdl8l!TrQDdO)Ulx5RpK^RYaC!xrRdlMZp7eRD!IL;ZPCC88NfcG=YX=_uCJw2_{VH z&)%8uJiqsu_kBLU=Xrnc^CRScJyrn5-gOCQD{$YMQG0pA+YB zO)Ze5ih%za~!tJjZWXaaLzCuugu8L z`9^zw>JzlLC~>Cr^AJk?2u99 zMvb8;eFBvQN>rC)rpjKG5o3hVfSGlFM>;AFkF*D;kefinTH&yUb*;1nRiT7Q_bUOi91a(EuDc^_SmKG6b@^>T9yp zZpjpcxs$Vo8P3(`I!5ml`&<}Jj_HLY{tEohh>(C-_&pZDN$w17yYny!>Ve(9d+hmpGxR+rfjUUoyog)oGj z2}bCk2%-@OIP`GgUhjf!QYQ!t-Qip8ji6Hhse|W8d|)P_zCNmK@$zwKd;SV_+h_%3(l>U5Oz2qpwkV} zJpu44b;afcKd{rs5LrHfqH7A!B1iDP?+a);JjZ;axiHVMsxmduOFsa!jSjm9YG^k%BSp9SnIQ5&b%qlYAegBp&*SyEbygrVa z+dxx4(9lb@jaxwCRlvVaiIqN=o)CIG?H}7WX9tf)J4u5^E5W*94e-vI!#tQnBWi0G z5qj*_CH&m1^}^ET4MCM{>pWyFYrQL5tdcv1tq*?>X2y@u^uGRxSmbkGoxvoaU_CUx zBv><{3XA4V6o5P1TdDjJM1{_U=V$=fEdU56O;I0qNclORtPJSt8aS16z`U6 z;G^bMU>!9BGn}LU+P~IZ7f`obmmx9lHc2q)+?c$f(|ixJd(t=8{nOX|4tdSLC)Rxm QTL1t607*qoM6N<$f`AXZ0RR91 literal 0 HcmV?d00001