Added Search Filter to the ChatLobbyWidget

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6669 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2013-09-02 00:08:38 +00:00
parent 4559b48a9d
commit 0416a0d888
5 changed files with 162 additions and 30 deletions

View File

@ -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(
" <h1><img width=\"32\" src=\":/images/64px_help.png\">&nbsp;&nbsp;Chat Lobbies</h1> \
@ -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);
}

View File

@ -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;

View File

@ -10,8 +10,8 @@
<height>381</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QFrame" name="titleBarFrame">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
@ -89,34 +89,100 @@
</layout>
</widget>
</item>
<item>
<item row="1" column="0">
<widget class="QSplitter" name="splitter">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QTreeWidget" name="lobbyTreeWidget">
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<column>
<property name="text">
<string notr="true">1</string>
<widget class="QWidget" name="layoutWidget">
<layout class="QGridLayout" name="gridLayout_2">
<property name="spacing">
<number>0</number>
</property>
</column>
<item row="0" column="0">
<widget class="QFrame" name="toolBarFrame">
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>1</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>1</number>
</property>
<property name="horizontalSpacing">
<number>6</number>
</property>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="LineEditClear" name="filterLineEdit">
<property name="toolTip">
<string>Search Chat lobbies</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QToolButton" name="createlobbytoolButton">
<property name="toolTip">
<string>Create chat lobby</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="images.qrc">
<normaloff>:/images/add_chat24.png</normaloff>:/images/add_chat24.png</iconset>
</property>
<property name="iconSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QTreeWidget" name="lobbyTreeWidget">
<property name="font">
<font>
<pointsize>9</pointsize>
</font>
</property>
<property name="iconSize">
<size>
<width>16</width>
<height>16</height>
</size>
</property>
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<widget class="QStackedWidget" name="stackedWidget">
<property name="sizePolicy">
@ -134,6 +200,13 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LineEditClear</class>
<extends>QLineEdit</extends>
<header location="global">gui/common/LineEditClear.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="images.qrc"/>
</resources>

View File

@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/" >
<file>images/add_chat24.png</file>
<file>images/blue_lock.png</file>
<file>images/stock_signature_bad.png</file>
<file>images/stock_signature_ok.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB