@ -56,6 +56,8 @@ RoomList::RoomList(QSharedPointer<UserSettings> userSettings, QWidget *parent)
scrollArea_ - > setWidget ( scrollAreaContents_ ) ;
scrollArea_ - > setWidget ( scrollAreaContents_ ) ;
topLayout_ - > addWidget ( scrollArea_ ) ;
topLayout_ - > addWidget ( scrollArea_ ) ;
qRegisterMetaType < std : : map < QString , bool > > ( ) ;
connect ( this , & RoomList : : updateRoomAvatarCb , this , & RoomList : : updateRoomAvatar ) ;
connect ( this , & RoomList : : updateRoomAvatarCb , this , & RoomList : : updateRoomAvatar ) ;
}
}
@ -340,10 +342,21 @@ RoomList::closeJoinRoomDialog(bool isJoining, QString roomAlias)
}
}
void
void
RoomList : : setFilterRooms ( bool isFilteringEnabled )
RoomList : : removeFilter ( )
{
for ( int i = 0 ; i < contentsLayout_ - > count ( ) ; i + + ) {
auto widget =
qobject_cast < RoomInfoListItem * > ( contentsLayout_ - > itemAt ( i ) - > widget ( ) ) ;
if ( widget )
widget - > show ( ) ;
}
}
void
RoomList : : applyFilter ( const std : : map < QString , bool > & filter )
{
{
for ( int i = 0 ; i < contentsLayout_ - > count ( ) ; i + + ) {
for ( int i = 0 ; i < contentsLayout_ - > count ( ) ; i + + ) {
// If roomFilter_ contains the room for the current RoomInfoListItem,
// If filter contains the room for the current RoomInfoListItem,
// show the list item, otherwise hide it
// show the list item, otherwise hide it
auto listitem =
auto listitem =
qobject_cast < RoomInfoListItem * > ( contentsLayout_ - > itemAt ( i ) - > widget ( ) ) ;
qobject_cast < RoomInfoListItem * > ( contentsLayout_ - > itemAt ( i ) - > widget ( ) ) ;
@ -351,28 +364,29 @@ RoomList::setFilterRooms(bool isFilteringEnabled)
if ( ! listitem )
if ( ! listitem )
continue ;
continue ;
if ( ! isFilteringEnabled | | filterItemExists ( listitem - > roomId ( ) ) )
if ( filter . find ( listitem - > roomId ( ) ) ! = filter . end ( ) )
listitem - > show ( ) ;
listitem - > show ( ) ;
else
else
listitem - > hide ( ) ;
listitem - > hide ( ) ;
}
}
if ( isFilteringEnabled & & ! filterItemExists ( selectedRoom_ ) ) {
// If the already selected room is part of the group, make sure it's visible.
RoomInfoListItem * firstVisibleRoom = nullptr ;
if ( ! selectedRoom_ . isEmpty ( ) & & ( filter . find ( selectedRoom_ ) ! = filter . end ( ) ) )
return ;
selectFirstVisibleRoom ( ) ;
}
for ( int i = 0 ; i < contentsLayout_ - > count ( ) ; i + + ) {
void
QWidget * item = contentsLayout_ - > itemAt ( i ) - > widget ( ) ;
RoomList : : selectFirstVisibleRoom ( )
{
for ( int i = 0 ; i < contentsLayout_ - > count ( ) ; i + + ) {
auto item = qobject_cast < RoomInfoListItem * > ( contentsLayout_ - > itemAt ( i ) - > widget ( ) ) ;
if ( item ! = nullptr & & item - > isVisible ( ) ) {
if ( item & & item - > isVisible ( ) ) {
firstVisibleRoom = qobject_cast < RoomInfoListItem * > ( item ) ;
highlightSelectedRoom ( item - > roomId ( ) ) ;
break ;
break ;
}
}
}
if ( firstVisibleRoom ! = nullptr )
highlightSelectedRoom ( firstVisibleRoom - > roomId ( ) ) ;
} else {
scrollArea_ - > ensureWidgetVisible ( rooms_ [ selectedRoom_ ] . data ( ) ) ;
}
}
}
}
@ -404,13 +418,6 @@ RoomList::updateRoom(const QString &room_id, const RoomInfo &info)
room - > update ( ) ;
room - > update ( ) ;
}
}
void
RoomList : : setRoomFilter ( std : : vector < QString > room_ids )
{
roomFilter_ = room_ids ;
setFilterRooms ( true ) ;
}
void
void
RoomList : : addInvitedRoom ( const QString & room_id , const RoomInfo & info )
RoomList : : addInvitedRoom ( const QString & room_id , const RoomInfo & info )
{
{