mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Don't show empty circles while searching
This commit is contained in:
parent
d4acf29fc0
commit
24f75a6b43
@ -270,18 +270,9 @@ bool CircleWidget::cycleContacts(FriendWidget *activeChatroomWidget, bool forwar
|
||||
return false;
|
||||
}
|
||||
|
||||
void CircleWidget::init()
|
||||
bool CircleWidget::hasChatrooms() const
|
||||
{
|
||||
qDebug() << "EXPANDED? " << Settings::getInstance().getCircleExpanded(id);
|
||||
if (Settings::getInstance().getCircleExpanded(id))
|
||||
expand();
|
||||
else
|
||||
{
|
||||
if (expanded)
|
||||
{
|
||||
toggle();
|
||||
}
|
||||
}
|
||||
return listLayout->hasChatrooms();
|
||||
}
|
||||
|
||||
CircleWidget* CircleWidget::getFromID(int id)
|
||||
|
@ -24,16 +24,14 @@ class QLabel;
|
||||
class FriendListWidget;
|
||||
class FriendListLayout;
|
||||
class FriendWidget;
|
||||
class QLineEdit;
|
||||
class CroppingLabel;
|
||||
|
||||
class CircleWidget : public GenericChatItemWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CircleWidget(FriendListWidget *parent = 0, int id = -1);
|
||||
CircleWidget(FriendListWidget* parent = 0, int id = -1);
|
||||
|
||||
void addFriendWidget(FriendWidget *w, Status s);
|
||||
void addFriendWidget(FriendWidget* w, Status s);
|
||||
|
||||
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false);
|
||||
|
||||
@ -48,7 +46,7 @@ public:
|
||||
bool cycleContacts(bool forward);
|
||||
bool cycleContacts(FriendWidget* activeChatroomWidget, bool forward);
|
||||
|
||||
void init();
|
||||
bool hasChatrooms() const;
|
||||
|
||||
static CircleWidget* getFromID(int id);
|
||||
|
||||
@ -60,22 +58,17 @@ public slots:
|
||||
|
||||
protected:
|
||||
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
void contextMenuEvent(QContextMenuEvent* event);
|
||||
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
||||
void dragLeaveEvent(QDragLeaveEvent* event) override;
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
|
||||
private:
|
||||
void updateID(int index);
|
||||
static QHash<int, CircleWidget*> circleList;
|
||||
enum FriendLayoutType
|
||||
{
|
||||
Online = 0,
|
||||
Offline = 1
|
||||
};
|
||||
int id;
|
||||
bool expanded = false;
|
||||
FriendListLayout* listLayout;
|
||||
|
@ -16,14 +16,8 @@
|
||||
#include "src/friend.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "friendwidget.h"
|
||||
#include <cassert>
|
||||
|
||||
#include "groupwidget.h"
|
||||
#include "friendwidget.h"
|
||||
|
||||
#include "friendlistwidget.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <cassert>
|
||||
|
||||
FriendListLayout::FriendListLayout()
|
||||
{
|
||||
@ -40,15 +34,14 @@ FriendListLayout::FriendListLayout()
|
||||
addLayout(friendOfflineLayout.getLayout());
|
||||
}
|
||||
|
||||
FriendListLayout::FriendListLayout(QWidget *parent)
|
||||
FriendListLayout::FriendListLayout(QWidget* parent)
|
||||
: QVBoxLayout(parent)
|
||||
{
|
||||
FriendListLayout();
|
||||
}
|
||||
|
||||
void FriendListLayout::addFriendWidget(FriendWidget *w, Status s)
|
||||
void FriendListLayout::addFriendWidget(FriendWidget* w, Status s)
|
||||
{
|
||||
// bug somewhere here.
|
||||
friendOfflineLayout.getLayout()->removeWidget(w);
|
||||
friendOnlineLayout.getLayout()->removeWidget(w);
|
||||
if (s == Status::Offline)
|
||||
@ -59,7 +52,7 @@ void FriendListLayout::addFriendWidget(FriendWidget *w, Status s)
|
||||
friendOnlineLayout.addSortedWidget(w);
|
||||
}
|
||||
|
||||
int FriendListLayout::indexOfFriendWidget(FriendWidget *widget, bool online) const
|
||||
int FriendListLayout::indexOfFriendWidget(FriendWidget* widget, bool online) const
|
||||
{
|
||||
if (online)
|
||||
return friendOnlineLayout.indexOfSortedWidget(widget);
|
||||
@ -70,18 +63,18 @@ void FriendListLayout::moveFriendWidgets(FriendListWidget* listWidget)
|
||||
{
|
||||
while (friendOnlineLayout.getLayout()->count() != 0)
|
||||
{
|
||||
QWidget *getWidget = friendOnlineLayout.getLayout()->takeAt(0)->widget();
|
||||
QWidget* getWidget = friendOnlineLayout.getLayout()->takeAt(0)->widget();
|
||||
assert(getWidget != nullptr);
|
||||
|
||||
FriendWidget *friendWidget = dynamic_cast<FriendWidget*>(getWidget);
|
||||
FriendWidget* friendWidget = dynamic_cast<FriendWidget*>(getWidget);
|
||||
listWidget->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true);
|
||||
}
|
||||
while (friendOfflineLayout.getLayout()->count() != 0)
|
||||
{
|
||||
QWidget *getWidget = friendOfflineLayout.getLayout()->takeAt(0)->widget();
|
||||
QWidget* getWidget = friendOfflineLayout.getLayout()->takeAt(0)->widget();
|
||||
assert(getWidget != nullptr);
|
||||
|
||||
FriendWidget *friendWidget = dynamic_cast<FriendWidget*>(getWidget);
|
||||
FriendWidget* friendWidget = dynamic_cast<FriendWidget*>(getWidget);
|
||||
listWidget->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true);
|
||||
}
|
||||
}
|
||||
@ -98,13 +91,13 @@ int FriendListLayout::friendTotalCount() const
|
||||
|
||||
bool FriendListLayout::hasChatrooms() const
|
||||
{
|
||||
return false;
|
||||
return !(friendOfflineLayout.getLayout()->isEmpty() && friendOfflineLayout.getLayout()->isEmpty());
|
||||
}
|
||||
|
||||
void FriendListLayout::searchChatrooms(const QString& searchString, bool hideOnline, bool hideOffline)
|
||||
{
|
||||
searchLayout<FriendWidget>(searchString, friendOnlineLayout.getLayout(), hideOnline);
|
||||
searchLayout<FriendWidget>(searchString, friendOfflineLayout.getLayout(), hideOffline);
|
||||
friendOfflineLayout.search(searchString, hideOffline);
|
||||
friendOnlineLayout.search(searchString, hideOnline);
|
||||
}
|
||||
|
||||
QLayout* FriendListLayout::getLayoutOnline() const
|
||||
|
@ -12,16 +12,13 @@
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef GENERICFRIENDLISTWIDGET_H
|
||||
#define GENERICFRIENDLISTWIDGET_H
|
||||
#ifndef FRIENDLISTLAYOUT_H
|
||||
#define FRIENDLISTLAYOUT_H
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include "src/core/corestructs.h"
|
||||
#include "genericchatitemlayout.h"
|
||||
#include "friendwidget.h"
|
||||
|
||||
class GroupWidget;
|
||||
class CircleWidget;
|
||||
class FriendWidget;
|
||||
class FriendListWidget;
|
||||
|
||||
@ -41,9 +38,6 @@ public:
|
||||
bool hasChatrooms() const;
|
||||
void searchChatrooms(const QString& searchString, bool hideOnline = false, bool hideOffline = false);
|
||||
|
||||
template <typename WidgetType>
|
||||
static void searchLayout(const QString& searchString, QLayout* boxLayout, bool hideAll);
|
||||
|
||||
QLayout* getLayoutOnline() const;
|
||||
QLayout* getLayoutOffline() const;
|
||||
|
||||
@ -54,16 +48,4 @@ private:
|
||||
GenericChatItemLayout friendOfflineLayout;
|
||||
};
|
||||
|
||||
template <typename WidgetType>
|
||||
void FriendListLayout::searchLayout(const QString &searchString, QLayout *boxLayout, bool hideAll)
|
||||
{
|
||||
for (int index = 0; index < boxLayout->count(); ++index)
|
||||
{
|
||||
WidgetType* widgetAt = static_cast<WidgetType*>(boxLayout->itemAt(index)->widget());
|
||||
QString widgetName = widgetAt->getName();
|
||||
|
||||
widgetAt->setVisible(!hideAll && widgetName.contains(searchString, Qt::CaseInsensitive));
|
||||
}
|
||||
}
|
||||
|
||||
#endif // GENERICFRIENDLISTWIDGET_H
|
||||
#endif // FRIENDLISTLAYOUT_H
|
||||
|
@ -31,6 +31,8 @@
|
||||
#include "src/misc/settings.h"
|
||||
#include <cassert>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
FriendListWidget::FriendListWidget(QWidget *parent, bool groupsOnTop)
|
||||
: QWidget(parent)
|
||||
, groupsOnTop(groupsOnTop)
|
||||
@ -39,13 +41,13 @@ FriendListWidget::FriendListWidget(QWidget *parent, bool groupsOnTop)
|
||||
setLayout(listLayout);
|
||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
||||
|
||||
circleLayout2.getLayout()->setSpacing(0);
|
||||
circleLayout2.getLayout()->setMargin(0);
|
||||
circleLayout.getLayout()->setSpacing(0);
|
||||
circleLayout.getLayout()->setMargin(0);
|
||||
|
||||
groupLayout.getLayout()->setSpacing(0);
|
||||
groupLayout.getLayout()->setMargin(0);
|
||||
|
||||
listLayout->addLayout(circleLayout2.getLayout());
|
||||
listLayout->addLayout(circleLayout.getLayout());
|
||||
|
||||
onGroupchatPositionChanged(groupsOnTop);
|
||||
|
||||
@ -70,7 +72,7 @@ void FriendListWidget::addFriendWidget(FriendWidget *w, Status s, int circleInde
|
||||
void FriendListWidget::addCircleWidget(int id)
|
||||
{
|
||||
CircleWidget *circleWidget = new CircleWidget(this, id);
|
||||
circleLayout2.addSortedWidget(circleWidget);
|
||||
circleLayout.addSortedWidget(circleWidget);
|
||||
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);
|
||||
connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget);
|
||||
circleWidget->show(); // Avoid flickering.
|
||||
@ -79,7 +81,7 @@ void FriendListWidget::addCircleWidget(int id)
|
||||
void FriendListWidget::addCircleWidget(FriendWidget *friendWidget)
|
||||
{
|
||||
CircleWidget *circleWidget = new CircleWidget(this);
|
||||
circleLayout2.addSortedWidget(circleWidget);
|
||||
circleLayout.addSortedWidget(circleWidget);
|
||||
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);
|
||||
connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget);
|
||||
//circleLayout->addWidget(circleWidget);
|
||||
@ -93,28 +95,19 @@ void FriendListWidget::addCircleWidget(FriendWidget *friendWidget)
|
||||
|
||||
void FriendListWidget::removeCircleWidget(CircleWidget *widget)
|
||||
{
|
||||
circleLayout2.removeSortedWidget(widget);
|
||||
circleLayout.removeSortedWidget(widget);
|
||||
widget->deleteLater();
|
||||
}
|
||||
|
||||
void FriendListWidget::initCircles()
|
||||
{
|
||||
for (int i = 0; i != circleLayout2.getLayout()->count(); ++i)
|
||||
{
|
||||
CircleWidget* circleWidget = static_cast<CircleWidget*>(circleLayout2.getLayout()->itemAt(i)->widget());
|
||||
circleWidget->init();
|
||||
}
|
||||
}
|
||||
|
||||
void FriendListWidget::searchChatrooms(const QString &searchString, bool hideOnline, bool hideOffline, bool hideGroups)
|
||||
{
|
||||
qDebug() << "searching..................................................";
|
||||
FriendListLayout::searchLayout<GroupWidget>(searchString, groupLayout.getLayout(), hideGroups);
|
||||
groupLayout.search(searchString, hideGroups);
|
||||
listLayout->searchChatrooms(searchString, hideOnline, hideOffline);
|
||||
for (int i = 0; i != circleLayout2.getLayout()->count(); ++i)
|
||||
for (int i = 0; i != circleLayout.getLayout()->count(); ++i)
|
||||
{
|
||||
CircleWidget *circleWidget = static_cast<CircleWidget*>(circleLayout2.getLayout()->itemAt(i)->widget());
|
||||
CircleWidget *circleWidget = static_cast<CircleWidget*>(circleLayout.getLayout()->itemAt(i)->widget());
|
||||
circleWidget->searchChatrooms(searchString, hideOnline, hideOffline);
|
||||
circleWidget->setVisible(searchString.isEmpty() || (circleWidget->hasChatrooms() && !(hideOnline && hideOffline)));
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,9 +132,9 @@ void FriendListWidget::renameCircleWidget(const QString &newName)
|
||||
assert(circleWidget != nullptr);
|
||||
|
||||
// Rename before removing so you can find it successfully.
|
||||
circleLayout2.removeSortedWidget(circleWidget);
|
||||
circleLayout.removeSortedWidget(circleWidget);
|
||||
circleWidget->setName(newName);
|
||||
circleLayout2.addSortedWidget(circleWidget);
|
||||
circleLayout.addSortedWidget(circleWidget);
|
||||
}
|
||||
|
||||
void FriendListWidget::onGroupchatPositionChanged(bool top)
|
||||
@ -178,8 +171,8 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
||||
if (circleWidget->cycleContacts(friendWidget, forward))
|
||||
return;
|
||||
|
||||
index = circleLayout2.indexOfSortedWidget(circleWidget);
|
||||
currentLayout = circleLayout2.getLayout();
|
||||
index = circleLayout.indexOfSortedWidget(circleWidget);
|
||||
currentLayout = circleLayout.getLayout();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -211,6 +204,7 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
||||
index += forward ? 1 : -1;
|
||||
for (;;)
|
||||
{
|
||||
qDebug() << "CHECKING BOUNDS...............................";
|
||||
// Bounds checking.
|
||||
if (index < 0)
|
||||
{
|
||||
@ -233,7 +227,7 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
||||
emit chatWidget->chatroomWidgetClicked(chatWidget);
|
||||
return;
|
||||
}
|
||||
else if (currentLayout == circleLayout2.getLayout())
|
||||
else if (currentLayout == circleLayout.getLayout())
|
||||
{
|
||||
circleWidget = dynamic_cast<CircleWidget*>(currentLayout->itemAt(index)->widget());
|
||||
if (circleWidget != nullptr)
|
||||
@ -254,39 +248,13 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
||||
}
|
||||
}
|
||||
|
||||
QList<GenericChatroomWidget*> FriendListWidget::getAllFriends()
|
||||
{
|
||||
QList<GenericChatroomWidget*> friends;
|
||||
|
||||
for (int i = 0; i < listLayout->count(); ++i)
|
||||
{
|
||||
QLayout* subLayout = listLayout->itemAt(i)->layout();
|
||||
|
||||
if(!subLayout)
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < subLayout->count(); ++j)
|
||||
{
|
||||
GenericChatroomWidget* widget =
|
||||
dynamic_cast<GenericChatroomWidget*>(subLayout->itemAt(j)->widget());
|
||||
|
||||
if(!widget)
|
||||
continue;
|
||||
|
||||
friends.append(widget);
|
||||
}
|
||||
}
|
||||
|
||||
return friends;
|
||||
}
|
||||
|
||||
QVector<CircleWidget*> FriendListWidget::getAllCircles()
|
||||
{
|
||||
QVector<CircleWidget*> vec;
|
||||
vec.reserve(circleLayout2.getLayout()->count());
|
||||
for (int i = 0; i < circleLayout2.getLayout()->count(); ++i)
|
||||
vec.reserve(circleLayout.getLayout()->count());
|
||||
for (int i = 0; i < circleLayout.getLayout()->count(); ++i)
|
||||
{
|
||||
vec.push_back(dynamic_cast<CircleWidget*>(circleLayout2.getLayout()->itemAt(i)->widget()));
|
||||
vec.push_back(dynamic_cast<CircleWidget*>(circleLayout.getLayout()->itemAt(i)->widget()));
|
||||
}
|
||||
return vec;
|
||||
}
|
||||
@ -358,7 +326,7 @@ QLayout* FriendListWidget::nextLayout(QLayout* layout, bool forward) const
|
||||
else
|
||||
{
|
||||
if (groupsOnTop)
|
||||
return circleLayout2.getLayout();
|
||||
return circleLayout.getLayout();
|
||||
return listLayout->getLayoutOnline();
|
||||
}
|
||||
}
|
||||
@ -374,18 +342,18 @@ QLayout* FriendListWidget::nextLayout(QLayout* layout, bool forward) const
|
||||
{
|
||||
if (groupsOnTop)
|
||||
return groupLayout.getLayout();
|
||||
return circleLayout2.getLayout();
|
||||
return circleLayout.getLayout();
|
||||
}
|
||||
}
|
||||
else if (layout == listLayout->getLayoutOffline())
|
||||
{
|
||||
if (forward)
|
||||
return circleLayout2.getLayout();
|
||||
return circleLayout.getLayout();
|
||||
else if (groupsOnTop)
|
||||
return listLayout->getLayoutOnline();
|
||||
return groupLayout.getLayout();
|
||||
}
|
||||
else if (layout == circleLayout2.getLayout())
|
||||
else if (layout == circleLayout.getLayout())
|
||||
{
|
||||
if (forward)
|
||||
{
|
||||
|
@ -52,12 +52,10 @@ public:
|
||||
void addCircleWidget(int id);
|
||||
void addCircleWidget(FriendWidget *widget = nullptr);
|
||||
void removeCircleWidget(CircleWidget *widget);
|
||||
void initCircles();
|
||||
|
||||
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false);
|
||||
|
||||
void cycleContacts(GenericChatroomWidget* activeChatroomWidget, bool forward);
|
||||
QList<GenericChatroomWidget*> getAllFriends();
|
||||
QVector<CircleWidget*> getAllCircles();
|
||||
|
||||
void reDraw();
|
||||
|
@ -18,12 +18,8 @@
|
||||
#ifndef FRIENDWIDGET_H
|
||||
#define FRIENDWIDGET_H
|
||||
|
||||
#include <QLabel>
|
||||
|
||||
#include "genericchatroomwidget.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
class QPixmap;
|
||||
class MaskablePixmapWidget;
|
||||
|
||||
@ -54,10 +50,6 @@ protected:
|
||||
virtual void mousePressEvent(QMouseEvent* ev) override;
|
||||
virtual void mouseMoveEvent(QMouseEvent* ev) override;
|
||||
void setFriendAlias();
|
||||
void showEvent(QShowEvent *)
|
||||
{
|
||||
qDebug() << "EVENT";
|
||||
}
|
||||
|
||||
public:
|
||||
int friendId;
|
||||
|
@ -17,6 +17,11 @@
|
||||
#include <QBoxLayout>
|
||||
#include <cassert>
|
||||
|
||||
// As this layout sorts widget, extra care must be taken when inserting widgets.
|
||||
// Prefer using the build in add and remove functions for modifying widgets.
|
||||
// Inserting widgets other ways would cause this layout to be unable to sort.
|
||||
// As such, they are protected using asserts.
|
||||
|
||||
GenericChatItemLayout::GenericChatItemLayout()
|
||||
: layout(new QVBoxLayout())
|
||||
{
|
||||
@ -71,6 +76,17 @@ void GenericChatItemLayout::removeSortedWidget(GenericChatItemWidget* widget)
|
||||
layout->removeWidget(widget);
|
||||
}
|
||||
|
||||
void GenericChatItemLayout::search(const QString &searchString, bool hideAll)
|
||||
{
|
||||
for (int index = 0; index < layout->count(); ++index)
|
||||
{
|
||||
GenericChatItemWidget* widgetAt = dynamic_cast<GenericChatItemWidget*>(layout->itemAt(index)->widget());
|
||||
assert(widgetAt != nullptr);
|
||||
|
||||
widgetAt->setVisible(!hideAll && widgetAt->getName().contains(searchString, Qt::CaseInsensitive));
|
||||
}
|
||||
}
|
||||
|
||||
QLayout* GenericChatItemLayout::getLayout() const
|
||||
{
|
||||
return layout;
|
||||
|
@ -31,6 +31,7 @@ public:
|
||||
int indexOfSortedWidget(GenericChatItemWidget* widget) const;
|
||||
bool existsSortedWidget(GenericChatItemWidget* widget) const;
|
||||
void removeSortedWidget(GenericChatItemWidget* widget);
|
||||
void search(const QString &searchString, bool hideAll);
|
||||
|
||||
QLayout* getLayout() const;
|
||||
|
||||
|
@ -20,7 +20,6 @@
|
||||
#ifndef GROUPWIDGET_H
|
||||
#define GROUPWIDGET_H
|
||||
|
||||
#include <QLabel>
|
||||
#include "genericchatroomwidget.h"
|
||||
|
||||
class GroupWidget : public GenericChatroomWidget
|
||||
|
Loading…
x
Reference in New Issue
Block a user