1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Fix circle white box glitch, circle cycling

This commit is contained in:
Daniel Hrabovcak 2015-06-03 09:51:23 -04:00 committed by tux3
parent 00022355e8
commit 10c7a745c5
15 changed files with 464 additions and 161 deletions

View File

@ -84,12 +84,12 @@ CircleWidget::CircleWidget(FriendListWidget *parent)
onCompactChanged(isCompact());
connect(nameLabel, &CroppingLabel::textChanged, [this](const QString &newString, const QString &oldString)
connect(nameLabel, &CroppingLabel::textChanged, [this](const QString &newName, const QString &oldName)
{
if (isCompact())
maxCropLabel(nameLabel);
nameLabel->setText(oldString);
emit renameRequested(newString);
nameLabel->setText(oldName);
emit renameRequested(newName);
});
renameCircle();
@ -123,14 +123,9 @@ void CircleWidget::toggle()
}
}
void CircleWidget::searchChatrooms(const QString &searchString, bool hideOnline, bool hideOffline, bool hideGroups)
void CircleWidget::searchChatrooms(const QString &searchString, bool hideOnline, bool hideOffline)
{
listLayout->searchChatrooms(searchString, hideOnline, hideOffline, hideGroups);
}
QString CircleWidget::getName() const
{
return nameLabel->text();
listLayout->searchChatrooms(searchString, hideOnline, hideOffline);
}
void CircleWidget::setName(const QString &name)
@ -144,6 +139,105 @@ void CircleWidget::renameCircle()
nameLabel->setMaximumWidth(QWIDGETSIZE_MAX);
}
void emitChatroomWidget(QLayout* layout, int index)
{
GenericChatroomWidget* chatWidget = dynamic_cast<GenericChatroomWidget*>(layout->itemAt(index)->widget());
if (chatWidget != nullptr)
emit chatWidget->chatroomWidgetClicked(chatWidget);
}
bool CircleWidget::cycleContacts(bool forward)
{
if (listLayout->friendTotalCount() == 0)
{
return false;
}
if (forward)
{
if (listLayout->getLayoutOnline()->count() != 0)
{
expand();
emitChatroomWidget(listLayout->getLayoutOnline(), 0);
return true;
}
else if (listLayout->getLayoutOffline()->count() != 0)
{
expand();
emitChatroomWidget(listLayout->getLayoutOffline(), 0);
return true;
}
}
else
{
if (listLayout->getLayoutOffline()->count() != 0)
{
expand();
emitChatroomWidget(listLayout->getLayoutOffline(), listLayout->getLayoutOffline()->count() - 1);
return true;
}
else if (listLayout->getLayoutOnline()->count() != 0)
{
expand();
emitChatroomWidget(listLayout->getLayoutOnline(), listLayout->getLayoutOnline()->count() - 1);
return true;
}
}
return false;
}
bool CircleWidget::cycleContacts(FriendWidget *activeChatroomWidget, bool forward)
{
int index = -1;
QLayout* currentLayout = nullptr;
FriendWidget* friendWidget = dynamic_cast<FriendWidget*>(activeChatroomWidget);
if (friendWidget != nullptr)
{
currentLayout = listLayout->getLayoutOnline();
index = listLayout->indexOfFriendWidget(friendWidget, true);
if (index == -1)
{
currentLayout = listLayout->getLayoutOffline();
index = listLayout->indexOfFriendWidget(friendWidget, false);
}
}
else
return false;
index += forward ? 1 : -1;
for (;;)
{
// Bounds checking.
if (index < 0)
{
if (currentLayout == listLayout->getLayoutOffline())
currentLayout = listLayout->getLayoutOnline();
else
return false;
index = currentLayout->count() - 1;
continue;
}
else if (index >= currentLayout->count())
{
if (currentLayout == listLayout->getLayoutOnline())
currentLayout = listLayout->getLayoutOffline();
else
return false;
index = 0;
continue;
}
GenericChatroomWidget* chatWidget = dynamic_cast<GenericChatroomWidget*>(currentLayout->itemAt(index)->widget());
if (chatWidget != nullptr)
emit chatWidget->chatroomWidgetClicked(chatWidget);
return true;
}
return false;
}
bool CircleWidget::operator<(const CircleWidget& other) const
{
int compareValue = nameLabel->text().localeAwareCompare(other.nameLabel->text());
@ -222,22 +316,7 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent *event)
else if (selectedItem == removeAction)
{
FriendListWidget *friendList = static_cast<FriendListWidget*>(parentWidget());
while (listLayout->friendLayouts[Online]->count() != 0)
{
QWidget *getWidget = listLayout->friendLayouts[Online]->takeAt(0)->widget();
assert(getWidget != nullptr);
FriendWidget *friendWidget = dynamic_cast<FriendWidget*>(getWidget);
friendList->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true);
}
while (listLayout->friendLayouts[Offline]->count() != 0)
{
QWidget *getWidget = listLayout->friendLayouts[Offline]->takeAt(0)->widget();
assert(getWidget != nullptr);
FriendWidget *friendWidget = dynamic_cast<FriendWidget*>(getWidget);
friendList->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true);
}
listLayout->moveFriendWidgets(friendList);
friendList->removeCircleWidget(this);
}

View File

@ -35,17 +35,19 @@ public:
void addFriendWidget(FriendWidget *w, Status s);
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false);
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false);
void expand();
void toggle();
void updateStatus();
QString getName() const;
void setName(const QString &name);
void renameCircle();
bool cycleContacts(bool forward);
bool cycleContacts(FriendWidget* activeChatroomWidget, bool forward);
bool operator<(const CircleWidget& other) const;
signals:
@ -75,7 +77,6 @@ private:
QVBoxLayout* fullLayout;
QVBoxLayout* mainLayout = nullptr;
QLabel* arrowLabel;
CroppingLabel* nameLabel;
QLabel* statusLabel;
QFrame* lineFrame;
QWidget* container;

View File

@ -21,103 +21,97 @@
#include "groupwidget.h"
#include "friendwidget.h"
#include "friendlistwidget.h"
#include <QDebug>
FriendListLayout::FriendListLayout(bool groupsOnTop)
FriendListLayout::FriendListLayout()
{
setSpacing(0);
setMargin(0);
groupLayout = new QVBoxLayout();
groupLayout->setSpacing(0);
groupLayout->setMargin(0);
friendOnlineLayout.getLayout()->setSpacing(0);
friendOnlineLayout.getLayout()->setMargin(0);
friendLayouts[Online] = new QVBoxLayout();
friendLayouts[Online]->setSpacing(0);
friendLayouts[Online]->setMargin(0);
friendOfflineLayout.getLayout()->setSpacing(0);
friendOfflineLayout.getLayout()->setMargin(0);
friendLayouts[Offline] = new QVBoxLayout();
friendLayouts[Offline]->setSpacing(0);
friendLayouts[Offline]->setMargin(0);
if (groupsOnTop)
{
QVBoxLayout::addLayout(groupLayout);
QVBoxLayout::addLayout(friendLayouts[Online]);
QVBoxLayout::addLayout(friendLayouts[Offline]);
}
else
{
QVBoxLayout::addLayout(friendLayouts[Online]);
QVBoxLayout::addLayout(groupLayout);
QVBoxLayout::addLayout(friendLayouts[Offline]);
}
addLayout(friendOnlineLayout.getLayout());
addLayout(friendOfflineLayout.getLayout());
}
void FriendListLayout::addFriendWidget(FriendWidget *w, Status s)
{
QVBoxLayout* l = getFriendLayout(s);
l->removeWidget(w); // In case the widget is already in this layout.
Friend* g = FriendList::findFriend(w->friendId);
// Binary search.
int min = 0, max = l->count(), mid;
while (min < max)
// bug somewhere here.
friendOfflineLayout.removeSortedWidget(w);
friendOnlineLayout.removeSortedWidget(w);
if (s == Status::Offline)
{
mid = (max - min) / 2 + min;
FriendWidget* w1 = dynamic_cast<FriendWidget*>(l->itemAt(mid)->widget());
assert(w1 != nullptr);
Friend* f = FriendList::findFriend(w1->friendId);
int compareValue = f->getDisplayedName().localeAwareCompare(g->getDisplayedName());
if (compareValue > 0)
{
max = mid;
}
else
{
min = mid + 1;
}
friendOfflineLayout.addSortedWidget(w);
return;
}
friendOnlineLayout.addSortedWidget(w);
}
l->insertWidget(min, w);
int FriendListLayout::indexOfFriendWidget(FriendWidget *widget, bool online) const
{
if (online)
return friendOnlineLayout.indexOfSortedWidget(widget);
return friendOfflineLayout.indexOfSortedWidget(widget);
}
void FriendListLayout::moveFriendWidgets(FriendListWidget* listWidget)
{
while (friendOnlineLayout.getLayout()->count() != 0)
{
QWidget *getWidget = friendOnlineLayout.getLayout()->takeAt(0)->widget();
assert(getWidget != nullptr);
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();
assert(getWidget != nullptr);
FriendWidget *friendWidget = dynamic_cast<FriendWidget*>(getWidget);
listWidget->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true);
}
}
int FriendListLayout::friendOnlineCount() const
{
return friendLayouts[Online]->count();
return friendOnlineLayout.getLayout()->count();
}
int FriendListLayout::friendTotalCount() const
{
return friendLayouts[Offline]->count() + friendOnlineCount();
}
template <typename WidgetType>
void searchHelper(const QString &searchString, QBoxLayout *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));
}
}
void FriendListLayout::searchChatrooms(const QString &searchString, bool hideOnline, bool hideOffline, bool hideGroups)
{
searchHelper<GroupWidget>(searchString, groupLayout, hideGroups);
searchHelper<FriendWidget>(searchString, friendLayouts[Online], hideOnline);
searchHelper<FriendWidget>(searchString, friendLayouts[Offline], hideOffline);
return friendOfflineLayout.getLayout()->count() + friendOnlineCount();
}
bool FriendListLayout::hasChatrooms() const
{
return !groupLayout->isEmpty() || !friendLayouts[Online]->isEmpty() || !friendLayouts[Offline]->isEmpty();
return false;
}
QVBoxLayout* FriendListLayout::getFriendLayout(Status s)
void FriendListLayout::searchChatrooms(const QString& searchString, bool hideOnline, bool hideOffline)
{
return s == Status::Offline ? friendLayouts[Offline] : friendLayouts[Online];
searchLayout<FriendWidget>(searchString, friendOnlineLayout.getLayout(), hideOnline);
searchLayout<FriendWidget>(searchString, friendOfflineLayout.getLayout(), hideOffline);
}
QLayout* FriendListLayout::getLayoutOnline() const
{
return friendOnlineLayout.getLayout();
}
QLayout* FriendListLayout::getLayoutOffline() const
{
return friendOfflineLayout.getLayout();
}
QLayout* FriendListLayout::getFriendLayout(Status s)
{
return s == Status::Offline ? friendOfflineLayout.getLayout() : friendOnlineLayout.getLayout();
}

View File

@ -17,35 +17,52 @@
#include <QBoxLayout>
#include "src/core/corestructs.h"
#include "sortingboxlayout.h"
#include "friendwidget.h"
class GroupWidget;
class CircleWidget;
class FriendWidget;
class FriendListWidget;
class FriendListLayout : public QVBoxLayout
{
Q_OBJECT
public:
explicit FriendListLayout(bool groupsOnTop = true);
explicit FriendListLayout();
void addGroupWidget(GroupWidget *widget);
void addFriendWidget(FriendWidget *widget, Status s);
void addFriendWidget(FriendWidget* widget, Status s);
int indexOfFriendWidget(FriendWidget* widget, bool online) const;
void moveFriendWidgets(FriendListWidget* listWidget);
int friendOnlineCount() const;
int friendTotalCount() const;
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false);
bool hasChatrooms() const;
void searchChatrooms(const QString& searchString, bool hideOnline = false, bool hideOffline = false);
public:
QVBoxLayout* getFriendLayout(Status s);
template <typename WidgetType>
static void searchLayout(const QString& searchString, QLayout* boxLayout, bool hideAll);
enum FriendLayoutType
{
Online = 0,
Offline = 1
};
QVBoxLayout *friendLayouts[2];
QVBoxLayout *groupLayout;
QLayout* getLayoutOnline() const;
QLayout* getLayoutOffline() const;
private:
QLayout* getFriendLayout(Status s);
VSortingBoxLayout<FriendWidget> friendOnlineLayout;
VSortingBoxLayout<FriendWidget> 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

View File

@ -30,34 +30,36 @@
#include "friendlistlayout.h"
#include <cassert>
FriendListWidget::FriendListWidget(QWidget *parent, bool groupsOnTop) :
QWidget(parent)
FriendListWidget::FriendListWidget(QWidget *parent, bool groupsOnTop)
: QWidget(parent)
, groupsOnTop(groupsOnTop)
{
listLayout = new FriendListLayout(groupsOnTop);
listLayout = new FriendListLayout();
setLayout(listLayout);
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
circleLayout = new QVBoxLayout();
circleLayout->setSpacing(0);
circleLayout->setMargin(0);
circleLayout2.getLayout()->setSpacing(0);
circleLayout2.getLayout()->setMargin(0);
groupLayout.getLayout()->setSpacing(0);
groupLayout.getLayout()->setMargin(0);
listLayout->addLayout(circleLayout2.getLayout());
onGroupchatPositionChanged(groupsOnTop);
setAcceptDrops(true);
}
void FriendListWidget::addGroupWidget(GroupWidget *widget)
{
listLayout->groupLayout->addWidget(widget);
groupLayout.addSortedWidget(widget);
connect(widget, &GroupWidget::renameRequested, this, &FriendListWidget::renameGroupWidget);
}
void FriendListWidget::addFriendWidget(FriendWidget *w, Status s, int circleIndex)
{
CircleWidget *circleWidget = nullptr;
qDebug() << circleIndex;
if (circleIndex >= 0 && circleIndex < circleLayout2.getLayout()->count())
circleWidget = dynamic_cast<CircleWidget*>(circleLayout2.getLayout()->itemAt(circleIndex)->widget());
@ -77,7 +79,6 @@ void FriendListWidget::addCircleWidget(const QString &name)
circleLayout2.addSortedWidget(circleWidget);
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);
connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget);
//circleLayout->addWidget(circleWidget);
}
void FriendListWidget::addCircleWidget(FriendWidget *friendWidget)
@ -103,17 +104,26 @@ void FriendListWidget::removeCircleWidget(CircleWidget *widget)
void FriendListWidget::searchChatrooms(const QString &searchString, bool hideOnline, bool hideOffline, bool hideGroups)
{
listLayout->searchChatrooms(searchString, hideOnline, hideOffline, hideGroups);
FriendListLayout::searchLayout<GroupWidget>(searchString, groupLayout.getLayout(), hideGroups);
listLayout->searchChatrooms(searchString, hideOnline, hideOffline);
for (int i = 0; i != circleLayout2.getLayout()->count(); ++i)
{
CircleWidget *circleWidget = static_cast<CircleWidget*>(circleLayout2.getLayout()->itemAt(i)->widget());
circleWidget->searchChatrooms(searchString, hideOnline, hideOffline, hideGroups);
circleWidget->searchChatrooms(searchString, hideOnline, hideOffline);
}
}
QVBoxLayout* FriendListWidget::getFriendLayout(Status s)
void FriendListWidget::renameGroupWidget(const QString &newName)
{
return s == Status::Offline ? listLayout->friendLayouts[Offline] : listLayout->friendLayouts[Online];
assert(sender() != nullptr);
GroupWidget* groupWidget = dynamic_cast<GroupWidget*>(sender());
assert(groupWidget != nullptr);
// Rename before removing so you can find it successfully.
groupLayout.removeSortedWidget(groupWidget);
groupWidget->setName(newName);
groupLayout.addSortedWidget(groupWidget);
}
void FriendListWidget::renameCircleWidget(const QString &newName)
@ -131,20 +141,112 @@ void FriendListWidget::renameCircleWidget(const QString &newName)
void FriendListWidget::onGroupchatPositionChanged(bool top)
{
listLayout->removeItem(circleLayout2.getLayout());
listLayout->removeItem(listLayout->groupLayout);
listLayout->removeItem(listLayout->friendLayouts[Online]);
groupsOnTop = top;
listLayout->removeItem(groupLayout.getLayout());
if (top)
{
listLayout->addLayout(listLayout->groupLayout);
listLayout->addLayout(listLayout->friendLayouts[Online]);
listLayout->insertLayout(0, groupLayout.getLayout());
}
else
{
listLayout->addLayout(listLayout->friendLayouts[Online]);
listLayout->addLayout(listLayout->groupLayout);
listLayout->insertLayout(1, groupLayout.getLayout());
}
}
void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget, bool forward)
{
if (activeChatroomWidget == nullptr)
return;
CircleWidget* circleWidget = dynamic_cast<CircleWidget*>(activeChatroomWidget->parentWidget());
int index = -1;
QLayout* currentLayout = nullptr;
FriendWidget* friendWidget = dynamic_cast<FriendWidget*>(activeChatroomWidget);
if (circleWidget != nullptr)
{
if (friendWidget == nullptr)
{
return;
}
if (circleWidget->cycleContacts(friendWidget, forward))
return;
index = circleLayout2.indexOfSortedWidget(circleWidget);
currentLayout = circleLayout2.getLayout();
}
else
{
if (friendWidget != nullptr)
{
currentLayout = listLayout->getLayoutOnline();
index = listLayout->indexOfFriendWidget(friendWidget, true);
if (index == -1)
{
currentLayout = listLayout->getLayoutOffline();
index = listLayout->indexOfFriendWidget(friendWidget, false);
}
}
else
{
GroupWidget* groupWidget = dynamic_cast<GroupWidget*>(activeChatroomWidget);
if (groupWidget != nullptr)
{
currentLayout = groupLayout.getLayout();
index = groupLayout.indexOfSortedWidget(groupWidget);
}
else
{
return;
};
}
}
index += forward ? 1 : -1;
for (;;)
{
// Bounds checking.
if (index < 0)
{
currentLayout = nextLayout(currentLayout, forward);
index = currentLayout->count() - 1;
continue;
}
else if (index >= currentLayout->count())
{
currentLayout = nextLayout(currentLayout, forward);
index = 0;
continue;
}
// Go to the actual next index.
if (currentLayout == listLayout->getLayoutOnline() || currentLayout == listLayout->getLayoutOffline() || currentLayout == groupLayout.getLayout())
{
GenericChatroomWidget* chatWidget = dynamic_cast<GenericChatroomWidget*>(currentLayout->itemAt(index)->widget());
if (chatWidget != nullptr)
emit chatWidget->chatroomWidgetClicked(chatWidget);
return;
}
else if (currentLayout == circleLayout2.getLayout())
{
circleWidget = dynamic_cast<CircleWidget*>(currentLayout->itemAt(index)->widget());
if (circleWidget != nullptr)
{
if (!circleWidget->cycleContacts(forward))
{
// Skip empty or finished circles.
index += forward ? 1 : -1;
continue;
}
}
return;
}
else
{
return;
}
}
listLayout->addLayout(circleLayout2.getLayout());
}
QList<GenericChatroomWidget*> FriendListWidget::getAllFriends()
@ -234,3 +336,57 @@ void FriendListWidget::reDraw()
show();
resize(QSize()); //lifehack
}
QLayout* FriendListWidget::nextLayout(QLayout* layout, bool forward) const
{
if (layout == groupLayout.getLayout())
{
if (forward)
{
if (groupsOnTop)
return listLayout->getLayoutOnline();
return listLayout->getLayoutOffline();
}
else
{
if (groupsOnTop)
return circleLayout2.getLayout();
return listLayout->getLayoutOnline();
}
}
else if (layout == listLayout->getLayoutOnline())
{
if (forward)
{
if (groupsOnTop)
return listLayout->getLayoutOffline();
return groupLayout.getLayout();
}
else
{
if (groupsOnTop)
return groupLayout.getLayout();
return circleLayout2.getLayout();
}
}
else if (layout == listLayout->getLayoutOffline())
{
if (forward)
return circleLayout2.getLayout();
else if (groupsOnTop)
return listLayout->getLayoutOnline();
return groupLayout.getLayout();
}
else if (layout == circleLayout2.getLayout())
{
if (forward)
{
if (groupsOnTop)
return groupLayout.getLayout();
return listLayout->getLayoutOnline();
}
else
return listLayout->getLayoutOffline();
}
return nullptr;
}

View File

@ -30,6 +30,7 @@
#include "sortingboxlayout.h"
#include "circlewidget.h"
#include "groupwidget.h"
class QVBoxLayout;
class QGridLayout;
@ -54,7 +55,7 @@ public:
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false);
void cycleContacts(int index);
void cycleContacts(GenericChatroomWidget* activeChatroomWidget, bool forward);
QList<GenericChatroomWidget*> getAllFriends();
QVector<CircleWidget*> getAllCircles();
@ -64,7 +65,8 @@ signals:
void onCompactChanged(bool compact);
public slots:
void renameCircleWidget(const QString &newName);
void renameGroupWidget(const QString& newName);
void renameCircleWidget(const QString& newName);
void onGroupchatPositionChanged(bool top);
void moveWidget(FriendWidget *w, Status s, bool add = false);
@ -73,15 +75,12 @@ protected:
void dropEvent(QDropEvent* event) override;
private:
QVBoxLayout* getFriendLayout(Status s);
enum FriendLayoutType
{
Online = 0,
Offline = 1
};
FriendListLayout *listLayout;
QVBoxLayout *circleLayout;
QLayout* nextLayout(QLayout* layout, bool forward) const;
bool groupsOnTop;
FriendListLayout* listLayout;
VSortingBoxLayout<CircleWidget> circleLayout2;
VSortingBoxLayout<GroupWidget> groupLayout;
};
#endif // FRIENDLISTWIDGET_H

View File

@ -149,7 +149,9 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
}
else if (selectedItem == newCircleAction)
{
qDebug() << friendList->parentWidget();
if (circleWidget != nullptr)
circleWidget->updateStatus();
friendList->addCircleWidget(this);
}
else if (groupActions.contains(selectedItem))
@ -211,6 +213,13 @@ void FriendWidget::updateStatusLight()
else if (status == Status::Offline && f->getEventFlag() == 1)
statusPic.setPixmap(QPixmap(":img/status/dot_offline_notification.svg"));
if (f->getEventFlag())
{
CircleWidget* circleWidget = dynamic_cast<CircleWidget*>(parentWidget());
if (circleWidget != nullptr)
circleWidget->expand();
}
if (!f->getEventFlag())
statusPic.setMargin(3);
else

View File

@ -15,6 +15,7 @@
#include "genericchatitemwidget.h"
#include "src/misc/style.h"
#include "src/misc/settings.h"
#include "croppinglabel.h"
#include <QVariant>
GenericChatItemWidget::GenericChatItemWidget(QWidget *parent)
@ -33,3 +34,16 @@ void GenericChatItemWidget::setCompact(bool compact)
this->compact = compact;
Style::repolish(this);
}
QString GenericChatItemWidget::getName() const
{
return nameLabel->fullText();
}
bool GenericChatItemWidget::operator<(const GenericChatItemWidget& other) const
{
int compareValue = getName().localeAwareCompare(other.getName());
if (compareValue == 0)
return this < &other; // Consistent ordering.
return compareValue > 0;
}

View File

@ -17,6 +17,8 @@
#include <QFrame>
class CroppingLabel;
class GenericChatItemWidget : public QFrame
{
Q_OBJECT
@ -26,8 +28,15 @@ public:
bool isCompact() const;
void setCompact(bool compact);
QString getName() const;
bool operator<(const GenericChatItemWidget& other) const;
Q_PROPERTY(bool compact READ isCompact WRITE setCompact)
protected:
CroppingLabel* nameLabel;
private:
bool compact;
};

View File

@ -138,11 +138,6 @@ void GenericChatroomWidget::setStatusMsg(const QString &status)
statusMessageLabel->setText(status);
}
QString GenericChatroomWidget::getName() const
{
return nameLabel->fullText();
}
QString GenericChatroomWidget::getStatusMsg() const
{
return statusMessageLabel->text();

View File

@ -77,7 +77,7 @@ protected:
QVBoxLayout* textLayout = nullptr;
MaskablePixmapWidget* avatar;
QLabel statusPic;
CroppingLabel* nameLabel, *statusMessageLabel;
CroppingLabel* statusMessageLabel;
bool compact, active;
};

View File

@ -51,12 +51,14 @@ GroupWidget::GroupWidget(int GroupId, QString Name)
setAcceptDrops(true);
connect(nameLabel, &CroppingLabel::textChanged, [this](const QString &newText, const QString &oldText)
connect(nameLabel, &CroppingLabel::textChanged, [this](const QString &newName, const QString &oldName)
{
Group* g = GroupList::findGroup(groupId);
if (newText != oldText)
//Group* g = GroupList::findGroup(groupId);
if (newName != oldName)
{
emit g->getChatForm()->groupTitleChanged(groupId, newText.left(128));
nameLabel->setText(oldName);
emit renameRequested(newName);
//emit g->getChatForm()->groupTitleChanged(groupId, newText.left(128));
}
/* according to agilob:
* Moving mouse pointer over groupwidget results in CSS effect
@ -136,6 +138,14 @@ QString GroupWidget::getStatusString()
return "New Message";
}
bool GroupWidget::operator<(const GroupWidget& other) const
{
int compareValue = nameLabel->text().localeAwareCompare(other.nameLabel->text());
if (compareValue == 0)
return this < &other; // Consistent ordering.
return compareValue > 0;
}
void GroupWidget::setChatForm(Ui::MainWindow &ui)
{
Group* g = GroupList::findGroup(groupId);

View File

@ -38,8 +38,11 @@ public:
void setName(const QString& name);
void onUserListChanged();
bool operator<(const GroupWidget& other) const;
signals:
void groupWidgetClicked(GroupWidget* widget);
void renameRequested(const QString& newName);
void removeGroup(int groupId);
protected:

View File

@ -30,13 +30,14 @@ public:
~SortingBoxLayout();
void addSortedWidget(T* widget);
int indexOfSortedWidget(T* widget) const;
bool existsSortedWidget(T* widget) const;
void removeSortedWidget(T* widget);
QLayout* getLayout() const;
private:
int indexOfClosestSortedWidget(T* widget);
int indexOfClosestSortedWidget(T* widget) const;
QBoxLayout* layout;
};
@ -61,15 +62,27 @@ void SortingBoxLayout<T, Dir>::addSortedWidget(T* widget)
}
template <typename T, QBoxLayout::Direction Dir>
bool SortingBoxLayout<T, Dir>::existsSortedWidget(T* widget) const
int SortingBoxLayout<T, Dir>::indexOfSortedWidget(T* widget) const
{
if (layout->count() == 0)
return -1;
int index = indexOfClosestSortedWidget(widget);
if (index >= layout->count())
return -1;
T* atMid = dynamic_cast<T*>(layout->itemAt(index)->widget());
assert(atMid != nullptr);
if (atMid == widget)
return true;
return false;
return index;
return -1;
}
template <typename T, QBoxLayout::Direction Dir>
bool SortingBoxLayout<T, Dir>::existsSortedWidget(T* widget) const
{
return indexOfSortedWidget(widget) != -1;
}
template <typename T, QBoxLayout::Direction Dir>
@ -96,11 +109,13 @@ QLayout* SortingBoxLayout<T, Dir>::getLayout() const
}
template <typename T, QBoxLayout::Direction Dir>
int SortingBoxLayout<T, Dir>::indexOfClosestSortedWidget(T* widget)
int SortingBoxLayout<T, Dir>::indexOfClosestSortedWidget(T* widget) const
{
// Binary search: Deferred test of equality.
int min = 0, max = layout->count(), mid;
while (min < max)
{
qDebug() << "min";
mid = (max - min) / 2 + min;
T* atMid = dynamic_cast<T*>(layout->itemAt(mid)->widget());
assert(atMid != nullptr);
@ -113,6 +128,7 @@ int SortingBoxLayout<T, Dir>::indexOfClosestSortedWidget(T* widget)
return min;
}
template <typename T>
using VSortingBoxLayout = SortingBoxLayout<T, QBoxLayout::TopToBottom>;

View File

@ -1264,7 +1264,8 @@ void Widget::onSplitterMoved(int pos, int index)
void Widget::cycleContacts(int offset)
{
if (!activeChatroomWidget)
contactListWidget->cycleContacts(activeChatroomWidget, offset == 1 ? true : false);
/*if (!activeChatroomWidget)
return;
FriendListWidget* friendList = static_cast<FriendListWidget*>(ui->friendList->widget());
@ -1276,7 +1277,7 @@ void Widget::cycleContacts(int offset)
if(bounded < 0)
bounded += friends.length();
emit friends[bounded]->chatroomWidgetClicked(friends[bounded]);
emit friends[bounded]->chatroomWidgetClicked(friends[bounded]);*/
}
void Widget::processOfflineMsgs()