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);
|
||||
|
||||
onCompactChanged(isCompact());
|
||||
|
||||
setExpanded(true);
|
||||
updateStatus();
|
||||
}
|
||||
|
||||
bool CategoryWidget::isExpanded() const
|
||||
|
|
|
@ -1049,9 +1049,7 @@ void ChatForm::SendMessageStr(QString msg)
|
|||
|
||||
msgEdit->setLastMessage(msg); //set last message only when sending it
|
||||
|
||||
QDate date = Settings::getInstance().getFriendActivity(f->getToxId());
|
||||
if (date != QDate::currentDate())
|
||||
Settings::getInstance().setFriendActivity(f->getToxId(), QDate::currentDate());
|
||||
Widget::getInstance()->updateFriendActivity(f);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -118,9 +118,6 @@ FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)
|
|||
setLayout(listLayout);
|
||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
||||
|
||||
circleLayout.getLayout()->setSpacing(0);
|
||||
circleLayout.getLayout()->setMargin(0);
|
||||
|
||||
groupLayout.getLayout()->setSpacing(0);
|
||||
groupLayout.getLayout()->setMargin(0);
|
||||
|
||||
|
@ -136,12 +133,38 @@ void FriendListWidget::setMode(Mode mode)
|
|||
this->mode = mode;
|
||||
if (mode == Name)
|
||||
{
|
||||
circleLayout = new GenericChatItemLayout;
|
||||
circleLayout->getLayout()->setSpacing(0);
|
||||
circleLayout->getLayout()->setMargin(0);
|
||||
|
||||
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++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)
|
||||
{
|
||||
|
@ -215,13 +238,29 @@ void FriendListWidget::setMode(Mode mode)
|
|||
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->getLayoutOffline());
|
||||
listLayout->removeItem(circleLayout.getLayout());
|
||||
listLayout->insertLayout(0, activityLayout);
|
||||
listLayout->removeItem(circleLayout->getLayout());
|
||||
listLayout->insertLayout(1, activityLayout);
|
||||
|
||||
reDraw();
|
||||
|
||||
delete circleLayout;
|
||||
circleLayout = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
FriendListWidget::Mode FriendListWidget::getMode() const
|
||||
{
|
||||
return mode;
|
||||
}
|
||||
|
||||
void FriendListWidget::addGroupWidget(GroupWidget* widget)
|
||||
{
|
||||
groupLayout.addSortedWidget(widget);
|
||||
|
@ -265,7 +304,7 @@ void FriendListWidget::addCircleWidget(FriendWidget* friendWidget)
|
|||
|
||||
void FriendListWidget::removeCircleWidget(CircleWidget* widget)
|
||||
{
|
||||
circleLayout.removeSortedWidget(widget);
|
||||
circleLayout->removeSortedWidget(widget);
|
||||
widget->deleteLater();
|
||||
}
|
||||
|
||||
|
@ -273,9 +312,9 @@ void FriendListWidget::searchChatrooms(const QString &searchString, bool hideOnl
|
|||
{
|
||||
groupLayout.search(searchString, hideGroups);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -289,23 +328,26 @@ void FriendListWidget::renameGroupWidget(GroupWidget* groupWidget, const QString
|
|||
|
||||
void FriendListWidget::renameCircleWidget(CircleWidget* circleWidget, const QString &newName)
|
||||
{
|
||||
circleLayout.removeSortedWidget(circleWidget);
|
||||
circleLayout->removeSortedWidget(circleWidget);
|
||||
circleWidget->setName(newName);
|
||||
circleLayout.addSortedWidget(circleWidget);
|
||||
circleLayout->addSortedWidget(circleWidget);
|
||||
}
|
||||
|
||||
void FriendListWidget::onGroupchatPositionChanged(bool top)
|
||||
{
|
||||
groupsOnTop = top;
|
||||
|
||||
if (mode != Name)
|
||||
return;
|
||||
|
||||
listLayout->removeItem(groupLayout.getLayout());
|
||||
|
||||
if (top)
|
||||
{
|
||||
listLayout->insertLayout(0, groupLayout.getLayout());
|
||||
}
|
||||
else
|
||||
{
|
||||
listLayout->insertLayout(1, groupLayout.getLayout());
|
||||
}
|
||||
|
||||
reDraw();
|
||||
}
|
||||
|
||||
void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget, bool forward)
|
||||
|
@ -328,8 +370,8 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
|||
if (circleWidget->cycleContacts(friendWidget, forward))
|
||||
return;
|
||||
|
||||
index = circleLayout.indexOfSortedWidget(circleWidget);
|
||||
currentLayout = circleLayout.getLayout();
|
||||
index = circleLayout->indexOfSortedWidget(circleWidget);
|
||||
currentLayout = circleLayout->getLayout();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -381,7 +423,7 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
|||
emit chatWidget->chatroomWidgetClicked(chatWidget);
|
||||
return;
|
||||
}
|
||||
else if (currentLayout == circleLayout.getLayout())
|
||||
else if (currentLayout == circleLayout->getLayout())
|
||||
{
|
||||
circleWidget = dynamic_cast<CircleWidget*>(currentLayout->itemAt(index)->widget());
|
||||
if (circleWidget != nullptr)
|
||||
|
@ -405,10 +447,10 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
|||
QVector<CircleWidget*> FriendListWidget::getAllCircles()
|
||||
{
|
||||
QVector<CircleWidget*> vec;
|
||||
vec.reserve(circleLayout.getLayout()->count());
|
||||
for (int i = 0; i < circleLayout.getLayout()->count(); ++i)
|
||||
vec.reserve(circleLayout->getLayout()->count());
|
||||
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;
|
||||
}
|
||||
|
@ -487,7 +529,7 @@ CircleWidget* FriendListWidget::createCircleWidget(int id)
|
|||
return nullptr;
|
||||
|
||||
CircleWidget* circleWidget = new CircleWidget(this, id);
|
||||
circleLayout.addSortedWidget(circleWidget);
|
||||
circleLayout->addSortedWidget(circleWidget);
|
||||
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);
|
||||
connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget);
|
||||
circleWidget->show(); // Avoid flickering.
|
||||
|
@ -507,7 +549,7 @@ QLayout* FriendListWidget::nextLayout(QLayout* layout, bool forward) const
|
|||
else
|
||||
{
|
||||
if (groupsOnTop)
|
||||
return circleLayout.getLayout();
|
||||
return circleLayout->getLayout();
|
||||
return listLayout->getLayoutOnline();
|
||||
}
|
||||
}
|
||||
|
@ -523,18 +565,18 @@ QLayout* FriendListWidget::nextLayout(QLayout* layout, bool forward) const
|
|||
{
|
||||
if (groupsOnTop)
|
||||
return groupLayout.getLayout();
|
||||
return circleLayout.getLayout();
|
||||
return circleLayout->getLayout();
|
||||
}
|
||||
}
|
||||
else if (layout == listLayout->getLayoutOffline())
|
||||
{
|
||||
if (forward)
|
||||
return circleLayout.getLayout();
|
||||
return circleLayout->getLayout();
|
||||
else if (groupsOnTop)
|
||||
return listLayout->getLayoutOnline();
|
||||
return groupLayout.getLayout();
|
||||
}
|
||||
else if (layout == circleLayout.getLayout())
|
||||
else if (layout == circleLayout->getLayout())
|
||||
{
|
||||
if (forward)
|
||||
{
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
|
||||
explicit FriendListWidget(Widget* parent, bool groupsOnTop = true);
|
||||
void setMode(Mode mode);
|
||||
Mode getMode() const;
|
||||
|
||||
void addGroupWidget(GroupWidget* widget);
|
||||
void addFriendWidget(FriendWidget* w, Status s, int circleIndex);
|
||||
|
@ -79,9 +80,9 @@ private:
|
|||
Mode mode;
|
||||
bool groupsOnTop;
|
||||
FriendListLayout* listLayout;
|
||||
GenericChatItemLayout circleLayout;
|
||||
GenericChatItemLayout* circleLayout = nullptr;
|
||||
GenericChatItemLayout groupLayout;
|
||||
QVBoxLayout* activityLayout;
|
||||
QVBoxLayout* activityLayout = nullptr;
|
||||
};
|
||||
|
||||
#endif // FRIENDLISTWIDGET_H
|
||||
|
|
|
@ -771,10 +771,7 @@ void Widget::onFriendMessageReceived(int friendId, const QString& message, bool
|
|||
setWindowTitle(windowTitle);
|
||||
}
|
||||
|
||||
QDate activity = Settings::getInstance().getFriendActivity(f->getToxId());
|
||||
qDebug() << "YOLOOLOLOLO" << activity;
|
||||
if (activity != QDate::currentDate())
|
||||
Settings::getInstance().setFriendActivity(f->getToxId(), QDate::currentDate());
|
||||
updateFriendActivity(f);
|
||||
}
|
||||
|
||||
void Widget::onReceiptRecieved(int friendId, int receipt)
|
||||
|
@ -853,6 +850,16 @@ void Widget::onFriendRequestReceived(const QString& userId, const QString& messa
|
|||
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)
|
||||
{
|
||||
if (!fake)
|
||||
|
@ -1468,7 +1475,7 @@ void Widget::friendListContextMenu(const QPoint &pos)
|
|||
{
|
||||
QMenu menu(this);
|
||||
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));
|
||||
|
||||
if (chosenAction == addCircleAction)
|
||||
|
@ -1477,7 +1484,10 @@ void Widget::friendListContextMenu(const QPoint &pos)
|
|||
}
|
||||
else if (chosenAction == switchMode)
|
||||
{
|
||||
if (contactListWidget->getMode() == FriendListWidget::Name)
|
||||
contactListWidget->setMode(FriendListWidget::Activity);
|
||||
else
|
||||
contactListWidget->setMode(FriendListWidget::Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -104,6 +104,7 @@ public slots:
|
|||
void onFriendDisplayChanged(FriendWidget* friendWidget, Status s);
|
||||
void onFriendMessageReceived(int friendId, const QString& message, bool isAction);
|
||||
void onFriendRequestReceived(const QString& userId, const QString& message);
|
||||
void updateFriendActivity(Friend* frnd);
|
||||
void onMessageSendResult(uint32_t friendId, const QString& message, int messageId);
|
||||
void onReceiptRecieved(int friendId, int receipt);
|
||||
void onEmptyGroupCreated(int groupId);
|
||||
|
|
Loading…
Reference in New Issue
Block a user