mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Switch between recent and alphabetical layouts
This commit is contained in:
parent
15f10c2f34
commit
c24a508c38
|
@ -67,6 +67,9 @@ CategoryWidget::CategoryWidget(QWidget* parent)
|
||||||
setAcceptDrops(true);
|
setAcceptDrops(true);
|
||||||
|
|
||||||
onCompactChanged(isCompact());
|
onCompactChanged(isCompact());
|
||||||
|
|
||||||
|
setExpanded(true);
|
||||||
|
updateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CategoryWidget::isExpanded() const
|
bool CategoryWidget::isExpanded() const
|
||||||
|
|
|
@ -1049,9 +1049,7 @@ void ChatForm::SendMessageStr(QString msg)
|
||||||
|
|
||||||
msgEdit->setLastMessage(msg); //set last message only when sending it
|
msgEdit->setLastMessage(msg); //set last message only when sending it
|
||||||
|
|
||||||
QDate date = Settings::getInstance().getFriendActivity(f->getToxId());
|
Widget::getInstance()->updateFriendActivity(f);
|
||||||
if (date != QDate::currentDate())
|
|
||||||
Settings::getInstance().setFriendActivity(f->getToxId(), QDate::currentDate());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -118,9 +118,6 @@ FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)
|
||||||
setLayout(listLayout);
|
setLayout(listLayout);
|
||||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
||||||
|
|
||||||
circleLayout.getLayout()->setSpacing(0);
|
|
||||||
circleLayout.getLayout()->setMargin(0);
|
|
||||||
|
|
||||||
groupLayout.getLayout()->setSpacing(0);
|
groupLayout.getLayout()->setSpacing(0);
|
||||||
groupLayout.getLayout()->setMargin(0);
|
groupLayout.getLayout()->setMargin(0);
|
||||||
|
|
||||||
|
@ -136,12 +133,38 @@ void FriendListWidget::setMode(Mode mode)
|
||||||
this->mode = mode;
|
this->mode = mode;
|
||||||
if (mode == Name)
|
if (mode == Name)
|
||||||
{
|
{
|
||||||
|
circleLayout = new GenericChatItemLayout;
|
||||||
|
circleLayout->getLayout()->setSpacing(0);
|
||||||
|
circleLayout->getLayout()->setMargin(0);
|
||||||
|
|
||||||
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
|
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
|
||||||
{
|
{
|
||||||
addCircleWidget(i);
|
addCircleWidget(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
listLayout->addLayout(circleLayout.getLayout());
|
QList<Friend*> friendList = FriendList::getAllFriends();
|
||||||
|
for (Friend* contact : friendList)
|
||||||
|
{
|
||||||
|
int circleId = Settings::getInstance().getFriendCircleID(contact->getToxId());
|
||||||
|
addFriendWidget(contact->getFriendWidget(), contact->getStatus(), circleId);
|
||||||
|
}
|
||||||
|
|
||||||
|
listLayout->removeItem(activityLayout);
|
||||||
|
listLayout->addLayout(listLayout->getLayoutOnline());
|
||||||
|
listLayout->addLayout(listLayout->getLayoutOffline());
|
||||||
|
listLayout->addLayout(circleLayout->getLayout());
|
||||||
|
onGroupchatPositionChanged(groupsOnTop);
|
||||||
|
|
||||||
|
if (activityLayout != nullptr)
|
||||||
|
{
|
||||||
|
while (activityLayout->count() > 0)
|
||||||
|
delete activityLayout->takeAt(0)->widget();
|
||||||
|
}
|
||||||
|
|
||||||
|
delete activityLayout;
|
||||||
|
activityLayout = nullptr;
|
||||||
|
|
||||||
|
reDraw();
|
||||||
}
|
}
|
||||||
else if (mode == Activity)
|
else if (mode == Activity)
|
||||||
{
|
{
|
||||||
|
@ -215,13 +238,29 @@ void FriendListWidget::setMode(Mode mode)
|
||||||
categoryWidget->setVisible(categoryWidget->hasChatrooms());
|
categoryWidget->setVisible(categoryWidget->hasChatrooms());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (circleLayout != nullptr)
|
||||||
|
{
|
||||||
|
while (circleLayout->getLayout()->count() > 0)
|
||||||
|
delete circleLayout->getLayout()->takeAt(0)->widget();
|
||||||
|
}
|
||||||
|
|
||||||
listLayout->removeItem(listLayout->getLayoutOnline());
|
listLayout->removeItem(listLayout->getLayoutOnline());
|
||||||
listLayout->removeItem(listLayout->getLayoutOffline());
|
listLayout->removeItem(listLayout->getLayoutOffline());
|
||||||
listLayout->removeItem(circleLayout.getLayout());
|
listLayout->removeItem(circleLayout->getLayout());
|
||||||
listLayout->insertLayout(0, activityLayout);
|
listLayout->insertLayout(1, activityLayout);
|
||||||
|
|
||||||
|
reDraw();
|
||||||
|
|
||||||
|
delete circleLayout;
|
||||||
|
circleLayout = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FriendListWidget::Mode FriendListWidget::getMode() const
|
||||||
|
{
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
|
||||||
void FriendListWidget::addGroupWidget(GroupWidget* widget)
|
void FriendListWidget::addGroupWidget(GroupWidget* widget)
|
||||||
{
|
{
|
||||||
groupLayout.addSortedWidget(widget);
|
groupLayout.addSortedWidget(widget);
|
||||||
|
@ -265,7 +304,7 @@ void FriendListWidget::addCircleWidget(FriendWidget* friendWidget)
|
||||||
|
|
||||||
void FriendListWidget::removeCircleWidget(CircleWidget* widget)
|
void FriendListWidget::removeCircleWidget(CircleWidget* widget)
|
||||||
{
|
{
|
||||||
circleLayout.removeSortedWidget(widget);
|
circleLayout->removeSortedWidget(widget);
|
||||||
widget->deleteLater();
|
widget->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,9 +312,9 @@ void FriendListWidget::searchChatrooms(const QString &searchString, bool hideOnl
|
||||||
{
|
{
|
||||||
groupLayout.search(searchString, hideGroups);
|
groupLayout.search(searchString, hideGroups);
|
||||||
listLayout->searchChatrooms(searchString, hideOnline, hideOffline);
|
listLayout->searchChatrooms(searchString, hideOnline, hideOffline);
|
||||||
for (int i = 0; i != circleLayout.getLayout()->count(); ++i)
|
for (int i = 0; i != circleLayout->getLayout()->count(); ++i)
|
||||||
{
|
{
|
||||||
CircleWidget* circleWidget = static_cast<CircleWidget*>(circleLayout.getLayout()->itemAt(i)->widget());
|
CircleWidget* circleWidget = static_cast<CircleWidget*>(circleLayout->getLayout()->itemAt(i)->widget());
|
||||||
circleWidget->search(searchString, true, hideOnline, hideOffline);
|
circleWidget->search(searchString, true, hideOnline, hideOffline);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,23 +328,26 @@ void FriendListWidget::renameGroupWidget(GroupWidget* groupWidget, const QString
|
||||||
|
|
||||||
void FriendListWidget::renameCircleWidget(CircleWidget* circleWidget, const QString &newName)
|
void FriendListWidget::renameCircleWidget(CircleWidget* circleWidget, const QString &newName)
|
||||||
{
|
{
|
||||||
circleLayout.removeSortedWidget(circleWidget);
|
circleLayout->removeSortedWidget(circleWidget);
|
||||||
circleWidget->setName(newName);
|
circleWidget->setName(newName);
|
||||||
circleLayout.addSortedWidget(circleWidget);
|
circleLayout->addSortedWidget(circleWidget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendListWidget::onGroupchatPositionChanged(bool top)
|
void FriendListWidget::onGroupchatPositionChanged(bool top)
|
||||||
{
|
{
|
||||||
groupsOnTop = top;
|
groupsOnTop = top;
|
||||||
|
|
||||||
|
if (mode != Name)
|
||||||
|
return;
|
||||||
|
|
||||||
listLayout->removeItem(groupLayout.getLayout());
|
listLayout->removeItem(groupLayout.getLayout());
|
||||||
|
|
||||||
if (top)
|
if (top)
|
||||||
{
|
|
||||||
listLayout->insertLayout(0, groupLayout.getLayout());
|
listLayout->insertLayout(0, groupLayout.getLayout());
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
listLayout->insertLayout(1, groupLayout.getLayout());
|
listLayout->insertLayout(1, groupLayout.getLayout());
|
||||||
}
|
|
||||||
|
reDraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget, bool forward)
|
void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget, bool forward)
|
||||||
|
@ -328,8 +370,8 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
||||||
if (circleWidget->cycleContacts(friendWidget, forward))
|
if (circleWidget->cycleContacts(friendWidget, forward))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
index = circleLayout.indexOfSortedWidget(circleWidget);
|
index = circleLayout->indexOfSortedWidget(circleWidget);
|
||||||
currentLayout = circleLayout.getLayout();
|
currentLayout = circleLayout->getLayout();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -381,7 +423,7 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
||||||
emit chatWidget->chatroomWidgetClicked(chatWidget);
|
emit chatWidget->chatroomWidgetClicked(chatWidget);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (currentLayout == circleLayout.getLayout())
|
else if (currentLayout == circleLayout->getLayout())
|
||||||
{
|
{
|
||||||
circleWidget = dynamic_cast<CircleWidget*>(currentLayout->itemAt(index)->widget());
|
circleWidget = dynamic_cast<CircleWidget*>(currentLayout->itemAt(index)->widget());
|
||||||
if (circleWidget != nullptr)
|
if (circleWidget != nullptr)
|
||||||
|
@ -405,10 +447,10 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
||||||
QVector<CircleWidget*> FriendListWidget::getAllCircles()
|
QVector<CircleWidget*> FriendListWidget::getAllCircles()
|
||||||
{
|
{
|
||||||
QVector<CircleWidget*> vec;
|
QVector<CircleWidget*> vec;
|
||||||
vec.reserve(circleLayout.getLayout()->count());
|
vec.reserve(circleLayout->getLayout()->count());
|
||||||
for (int i = 0; i < circleLayout.getLayout()->count(); ++i)
|
for (int i = 0; i < circleLayout->getLayout()->count(); ++i)
|
||||||
{
|
{
|
||||||
vec.push_back(dynamic_cast<CircleWidget*>(circleLayout.getLayout()->itemAt(i)->widget()));
|
vec.push_back(dynamic_cast<CircleWidget*>(circleLayout->getLayout()->itemAt(i)->widget()));
|
||||||
}
|
}
|
||||||
return vec;
|
return vec;
|
||||||
}
|
}
|
||||||
|
@ -487,7 +529,7 @@ CircleWidget* FriendListWidget::createCircleWidget(int id)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
CircleWidget* circleWidget = new CircleWidget(this, id);
|
CircleWidget* circleWidget = new CircleWidget(this, id);
|
||||||
circleLayout.addSortedWidget(circleWidget);
|
circleLayout->addSortedWidget(circleWidget);
|
||||||
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);
|
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);
|
||||||
connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget);
|
connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget);
|
||||||
circleWidget->show(); // Avoid flickering.
|
circleWidget->show(); // Avoid flickering.
|
||||||
|
@ -507,7 +549,7 @@ QLayout* FriendListWidget::nextLayout(QLayout* layout, bool forward) const
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (groupsOnTop)
|
if (groupsOnTop)
|
||||||
return circleLayout.getLayout();
|
return circleLayout->getLayout();
|
||||||
return listLayout->getLayoutOnline();
|
return listLayout->getLayoutOnline();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -523,18 +565,18 @@ QLayout* FriendListWidget::nextLayout(QLayout* layout, bool forward) const
|
||||||
{
|
{
|
||||||
if (groupsOnTop)
|
if (groupsOnTop)
|
||||||
return groupLayout.getLayout();
|
return groupLayout.getLayout();
|
||||||
return circleLayout.getLayout();
|
return circleLayout->getLayout();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (layout == listLayout->getLayoutOffline())
|
else if (layout == listLayout->getLayoutOffline())
|
||||||
{
|
{
|
||||||
if (forward)
|
if (forward)
|
||||||
return circleLayout.getLayout();
|
return circleLayout->getLayout();
|
||||||
else if (groupsOnTop)
|
else if (groupsOnTop)
|
||||||
return listLayout->getLayoutOnline();
|
return listLayout->getLayoutOnline();
|
||||||
return groupLayout.getLayout();
|
return groupLayout.getLayout();
|
||||||
}
|
}
|
||||||
else if (layout == circleLayout.getLayout())
|
else if (layout == circleLayout->getLayout())
|
||||||
{
|
{
|
||||||
if (forward)
|
if (forward)
|
||||||
{
|
{
|
||||||
|
|
|
@ -46,6 +46,7 @@ public:
|
||||||
|
|
||||||
explicit FriendListWidget(Widget* parent, bool groupsOnTop = true);
|
explicit FriendListWidget(Widget* parent, bool groupsOnTop = true);
|
||||||
void setMode(Mode mode);
|
void setMode(Mode mode);
|
||||||
|
Mode getMode() const;
|
||||||
|
|
||||||
void addGroupWidget(GroupWidget* widget);
|
void addGroupWidget(GroupWidget* widget);
|
||||||
void addFriendWidget(FriendWidget* w, Status s, int circleIndex);
|
void addFriendWidget(FriendWidget* w, Status s, int circleIndex);
|
||||||
|
@ -79,9 +80,9 @@ private:
|
||||||
Mode mode;
|
Mode mode;
|
||||||
bool groupsOnTop;
|
bool groupsOnTop;
|
||||||
FriendListLayout* listLayout;
|
FriendListLayout* listLayout;
|
||||||
GenericChatItemLayout circleLayout;
|
GenericChatItemLayout* circleLayout = nullptr;
|
||||||
GenericChatItemLayout groupLayout;
|
GenericChatItemLayout groupLayout;
|
||||||
QVBoxLayout* activityLayout;
|
QVBoxLayout* activityLayout = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FRIENDLISTWIDGET_H
|
#endif // FRIENDLISTWIDGET_H
|
||||||
|
|
|
@ -771,10 +771,7 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message, bool
|
||||||
setWindowTitle(windowTitle);
|
setWindowTitle(windowTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
QDate activity = Settings::getInstance().getFriendActivity(f->getToxId());
|
updateFriendActivity(f);
|
||||||
qDebug() << "YOLOOLOLOLO" << activity;
|
|
||||||
if (activity != QDate::currentDate())
|
|
||||||
Settings::getInstance().setFriendActivity(f->getToxId(), QDate::currentDate());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::onReceiptRecieved(int friendId, int receipt)
|
void Widget::onReceiptRecieved(int friendId, int receipt)
|
||||||
|
@ -853,6 +850,16 @@ void Widget::onFriendRequestReceived(const QString& userId, const QString& messa
|
||||||
emit friendRequestAccepted(userId);
|
emit friendRequestAccepted(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Widget::updateFriendActivity(Friend *frnd)
|
||||||
|
{
|
||||||
|
QDate date = Settings::getInstance().getFriendActivity(frnd->getToxId());
|
||||||
|
if (date != QDate::currentDate())
|
||||||
|
{
|
||||||
|
Settings::getInstance().setFriendActivity(frnd->getToxId(), QDate::currentDate());
|
||||||
|
contactListWidget->moveWidget(frnd->getFriendWidget(), frnd->getStatus());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Widget::removeFriend(Friend* f, bool fake)
|
void Widget::removeFriend(Friend* f, bool fake)
|
||||||
{
|
{
|
||||||
if (!fake)
|
if (!fake)
|
||||||
|
@ -1468,7 +1475,7 @@ void Widget::friendListContextMenu(const QPoint &pos)
|
||||||
{
|
{
|
||||||
QMenu menu(this);
|
QMenu menu(this);
|
||||||
QAction *addCircleAction = menu.addAction(tr("Add new circle..."));
|
QAction *addCircleAction = menu.addAction(tr("Add new circle..."));
|
||||||
QAction *switchMode = menu.addAction("Switch to Recent (BETA)");
|
QAction *switchMode = menu.addAction("Switch between Recent and Name (BETA)");
|
||||||
QAction *chosenAction = menu.exec(ui->friendList->mapToGlobal(pos));
|
QAction *chosenAction = menu.exec(ui->friendList->mapToGlobal(pos));
|
||||||
|
|
||||||
if (chosenAction == addCircleAction)
|
if (chosenAction == addCircleAction)
|
||||||
|
@ -1477,7 +1484,10 @@ void Widget::friendListContextMenu(const QPoint &pos)
|
||||||
}
|
}
|
||||||
else if (chosenAction == switchMode)
|
else if (chosenAction == switchMode)
|
||||||
{
|
{
|
||||||
|
if (contactListWidget->getMode() == FriendListWidget::Name)
|
||||||
contactListWidget->setMode(FriendListWidget::Activity);
|
contactListWidget->setMode(FriendListWidget::Activity);
|
||||||
|
else
|
||||||
|
contactListWidget->setMode(FriendListWidget::Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,7 @@ public slots:
|
||||||
void onFriendDisplayChanged(FriendWidget* friendWidget, Status s);
|
void onFriendDisplayChanged(FriendWidget* friendWidget, Status s);
|
||||||
void onFriendMessageReceived(int friendId, const QString& message, bool isAction);
|
void onFriendMessageReceived(int friendId, const QString& message, bool isAction);
|
||||||
void onFriendRequestReceived(const QString& userId, const QString& message);
|
void onFriendRequestReceived(const QString& userId, const QString& message);
|
||||||
|
void updateFriendActivity(Friend* frnd);
|
||||||
void onMessageSendResult(uint32_t friendId, const QString& message, int messageId);
|
void onMessageSendResult(uint32_t friendId, const QString& message, int messageId);
|
||||||
void onReceiptRecieved(int friendId, int receipt);
|
void onReceiptRecieved(int friendId, int receipt);
|
||||||
void onEmptyGroupCreated(int groupId);
|
void onEmptyGroupCreated(int groupId);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user