mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Search optimizations and bug fixes, rename focus fix
This commit is contained in:
parent
ac2263b3e8
commit
167a8971ec
|
@ -246,7 +246,7 @@ public:
|
|||
void setAutoLogin(bool state);
|
||||
|
||||
int getCircleCount() const;
|
||||
int addCircle(const QString &name);
|
||||
int addCircle(const QString &name = QString());
|
||||
int removeCircle(int id);
|
||||
QString getCircleName(int id) const;
|
||||
void setCircleName(int id, const QString &name);
|
||||
|
|
|
@ -17,27 +17,20 @@
|
|||
#include "src/misc/settings.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "src/friend.h"
|
||||
#include "src/widget/friendwidget.h"
|
||||
#include "friendwidget.h"
|
||||
#include "friendlistlayout.h"
|
||||
#include "friendlistwidget.h"
|
||||
#include "croppinglabel.h"
|
||||
#include "widget.h"
|
||||
#include <QVariant>
|
||||
#include <QLabel>
|
||||
#include <QBoxLayout>
|
||||
#include <QMouseEvent>
|
||||
#include <QLineEdit>
|
||||
#include "src/misc/settings.h"
|
||||
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMimeData>
|
||||
#include <QMenu>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "friendlistlayout.h"
|
||||
#include "friendlistwidget.h"
|
||||
|
||||
#include "croppinglabel.h"
|
||||
|
||||
void maxCropLabel(CroppingLabel* label)
|
||||
{
|
||||
QFontMetrics metrics = label->fontMetrics();
|
||||
|
@ -62,9 +55,6 @@ CircleWidget::CircleWidget(FriendListWidget *parent, int id_)
|
|||
statusLabel->setObjectName("status");
|
||||
statusLabel->setTextFormat(Qt::PlainText);
|
||||
|
||||
// name text
|
||||
nameLabel->setText("Circle");
|
||||
|
||||
arrowLabel = new QLabel(this);
|
||||
arrowLabel->setPixmap(QPixmap(":/ui/chatArea/scrollBarRightArrow.svg"));
|
||||
|
||||
|
@ -90,7 +80,6 @@ CircleWidget::CircleWidget(FriendListWidget *parent, int id_)
|
|||
|
||||
if (id != -1)
|
||||
{
|
||||
// Set name before connecting text change.
|
||||
setName(Settings::getInstance().getCircleName(id));
|
||||
}
|
||||
|
||||
|
@ -110,10 +99,12 @@ CircleWidget::CircleWidget(FriendListWidget *parent, int id_)
|
|||
if (id == -1)
|
||||
{
|
||||
isNew = true;
|
||||
id = Settings::getInstance().addCircle("Circle");
|
||||
id = Settings::getInstance().addCircle();
|
||||
nameLabel->setText(tr("Circle #%1").arg(id + 1));
|
||||
Settings::getInstance().setCircleName(id, nameLabel->fullText());
|
||||
}
|
||||
}
|
||||
circleList.insert(id, this);
|
||||
circleList[id] = this;
|
||||
|
||||
if (isNew)
|
||||
renameCircle();
|
||||
|
@ -126,7 +117,6 @@ void CircleWidget::addFriendWidget(FriendWidget *w, Status s)
|
|||
listLayout->addFriendWidget(w, s);
|
||||
updateStatus();
|
||||
Settings::getInstance().setFriendCircleID(FriendList::findFriend(w->friendId)->getToxId(), id);
|
||||
qDebug() << Settings::getInstance().getFriendCircleID(FriendList::findFriend(w->friendId)->getToxId()) << " WITH " << id;
|
||||
}
|
||||
|
||||
void CircleWidget::setExpanded(bool isExpanded)
|
||||
|
@ -145,9 +135,14 @@ void CircleWidget::setExpanded(bool isExpanded)
|
|||
Settings::getInstance().setCircleExpanded(id, isExpanded);
|
||||
}
|
||||
|
||||
void CircleWidget::searchChatrooms(const QString &searchString, bool hideOnline, bool hideOffline)
|
||||
void CircleWidget::search(const QString &searchString, bool updateAll, bool hideOnline, bool hideOffline)
|
||||
{
|
||||
listLayout->searchChatrooms(searchString, hideOnline, hideOffline);
|
||||
if (updateAll)
|
||||
{
|
||||
listLayout->searchChatrooms(searchString, hideOnline, hideOffline);
|
||||
}
|
||||
bool inCategory = searchString.isEmpty() && !(hideOnline && hideOffline);
|
||||
setVisible(inCategory || listLayout->hasChatrooms());
|
||||
}
|
||||
|
||||
void CircleWidget::setName(const QString &name)
|
||||
|
@ -170,10 +165,8 @@ void emitChatroomWidget(QLayout* layout, int index)
|
|||
|
||||
bool CircleWidget::cycleContacts(bool forward)
|
||||
{
|
||||
qDebug() << "Cycling on contact: " << getName();
|
||||
if (listLayout->friendTotalCount() == 0)
|
||||
{
|
||||
qDebug() << "Empty";
|
||||
return false;
|
||||
}
|
||||
if (forward)
|
||||
|
@ -182,14 +175,12 @@ bool CircleWidget::cycleContacts(bool forward)
|
|||
{
|
||||
setExpanded(true);
|
||||
emitChatroomWidget(listLayout->getLayoutOnline(), 0);
|
||||
qDebug() << "emmited 1";
|
||||
return true;
|
||||
}
|
||||
else if (listLayout->getLayoutOffline()->count() != 0)
|
||||
{
|
||||
setExpanded(true);
|
||||
emitChatroomWidget(listLayout->getLayoutOffline(), 0);
|
||||
qDebug() << "emmited 2";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -199,14 +190,12 @@ bool CircleWidget::cycleContacts(bool forward)
|
|||
{
|
||||
setExpanded(true);
|
||||
emitChatroomWidget(listLayout->getLayoutOffline(), listLayout->getLayoutOffline()->count() - 1);
|
||||
qDebug() << "emmited 3";
|
||||
return true;
|
||||
}
|
||||
else if (listLayout->getLayoutOnline()->count() != 0)
|
||||
{
|
||||
setExpanded(true);
|
||||
emitChatroomWidget(listLayout->getLayoutOnline(), listLayout->getLayoutOnline()->count() - 1);
|
||||
qDebug() << "emmited 4";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -266,11 +255,6 @@ bool CircleWidget::cycleContacts(FriendWidget *activeChatroomWidget, bool forwar
|
|||
return false;
|
||||
}
|
||||
|
||||
bool CircleWidget::hasChatrooms() const
|
||||
{
|
||||
return listLayout->hasChatrooms();
|
||||
}
|
||||
|
||||
CircleWidget* CircleWidget::getFromID(int id)
|
||||
{
|
||||
auto circleIt = circleList.find(id);
|
||||
|
@ -402,8 +386,8 @@ void CircleWidget::dropEvent(QDropEvent *event)
|
|||
|
||||
if (circleWidget != nullptr)
|
||||
{
|
||||
// In case the status was changed while moving, update both.
|
||||
circleWidget->updateStatus();
|
||||
Widget::getInstance()->searchCircle(circleWidget);
|
||||
}
|
||||
|
||||
container->setAttribute(Qt::WA_UnderMouse, false);
|
||||
|
|
|
@ -33,7 +33,6 @@ public:
|
|||
|
||||
void addFriendWidget(FriendWidget* w, Status s);
|
||||
|
||||
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false);
|
||||
|
||||
void expand();
|
||||
void setExpanded(bool isExpanded);
|
||||
|
@ -45,8 +44,7 @@ public:
|
|||
|
||||
bool cycleContacts(bool forward);
|
||||
bool cycleContacts(FriendWidget* activeChatroomWidget, bool forward);
|
||||
|
||||
bool hasChatrooms() const;
|
||||
void search(const QString &searchString, bool updateAll = false, bool hideOnline = false, bool hideOffline = false);
|
||||
|
||||
static CircleWidget* getFromID(int id);
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ QLayout* FriendListLayout::getLayoutOffline() const
|
|||
return friendOfflineLayout.getLayout();
|
||||
}
|
||||
|
||||
QLayout* FriendListLayout::getFriendLayout(Status s)
|
||||
QLayout* FriendListLayout::getFriendLayout(Status s) const
|
||||
{
|
||||
return s == Status::Offline ? friendOfflineLayout.getLayout() : friendOnlineLayout.getLayout();
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public:
|
|||
QLayout* getLayoutOffline() const;
|
||||
|
||||
private:
|
||||
QLayout* getFriendLayout(Status s);
|
||||
QLayout* getFriendLayout(Status s) const;
|
||||
|
||||
GenericChatItemLayout friendOnlineLayout;
|
||||
GenericChatItemLayout friendOfflineLayout;
|
||||
|
|
|
@ -16,24 +16,25 @@
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "friendlistwidget.h"
|
||||
#include <QDebug>
|
||||
#include "friendlistlayout.h"
|
||||
#include "src/friend.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "src/misc/settings.h"
|
||||
#include "friendwidget.h"
|
||||
#include "groupwidget.h"
|
||||
#include "circlewidget.h"
|
||||
#include <QGridLayout>
|
||||
#include <QMimeData>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QDragLeaveEvent>
|
||||
#include "src/friend.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "src/widget/friendwidget.h"
|
||||
#include "groupwidget.h"
|
||||
#include "circlewidget.h"
|
||||
#include "friendlistlayout.h"
|
||||
#include "src/misc/settings.h"
|
||||
#include <cassert>
|
||||
|
||||
#include <QDebug>
|
||||
#include "widget.h"
|
||||
|
||||
FriendListWidget::FriendListWidget(QWidget *parent, bool groupsOnTop)
|
||||
FriendListWidget::FriendListWidget(Widget* parent, bool groupsOnTop)
|
||||
: QWidget(parent)
|
||||
, groupsOnTop(groupsOnTop)
|
||||
{
|
||||
|
@ -54,13 +55,17 @@ FriendListWidget::FriendListWidget(QWidget *parent, bool groupsOnTop)
|
|||
setAcceptDrops(true);
|
||||
}
|
||||
|
||||
void FriendListWidget::addGroupWidget(GroupWidget *widget)
|
||||
void FriendListWidget::addGroupWidget(GroupWidget* widget)
|
||||
{
|
||||
groupLayout.addSortedWidget(widget);
|
||||
connect(widget, &GroupWidget::renameRequested, this, &FriendListWidget::renameGroupWidget);
|
||||
|
||||
// Only rename group if groups are visible.
|
||||
if (Widget::getInstance()->groupsVisible())
|
||||
widget->rename();
|
||||
}
|
||||
|
||||
void FriendListWidget::addFriendWidget(FriendWidget *w, Status s, int circleIndex)
|
||||
void FriendListWidget::addFriendWidget(FriendWidget* w, Status s, int circleIndex)
|
||||
{
|
||||
CircleWidget* circleWidget = CircleWidget::getFromID(circleIndex);
|
||||
if (circleWidget == nullptr)
|
||||
|
@ -71,29 +76,27 @@ void FriendListWidget::addFriendWidget(FriendWidget *w, Status s, int circleInde
|
|||
|
||||
void FriendListWidget::addCircleWidget(int id)
|
||||
{
|
||||
CircleWidget *circleWidget = new CircleWidget(this, id);
|
||||
circleLayout.addSortedWidget(circleWidget);
|
||||
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);
|
||||
connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget);
|
||||
circleWidget->show(); // Avoid flickering.
|
||||
createCircleWidget(id);
|
||||
}
|
||||
|
||||
void FriendListWidget::addCircleWidget(FriendWidget *friendWidget)
|
||||
void FriendListWidget::addCircleWidget(FriendWidget* friendWidget)
|
||||
{
|
||||
CircleWidget *circleWidget = new CircleWidget(this);
|
||||
circleLayout.addSortedWidget(circleWidget);
|
||||
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);
|
||||
connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget);
|
||||
//circleLayout->addWidget(circleWidget);
|
||||
CircleWidget* circleWidget = createCircleWidget();
|
||||
if (friendWidget != nullptr)
|
||||
{
|
||||
CircleWidget* circleOriginal = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(FriendList::findFriend(friendWidget->friendId)->getToxId()));
|
||||
|
||||
circleWidget->addFriendWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus());
|
||||
circleWidget->setExpanded(true);
|
||||
|
||||
Widget::getInstance()->searchCircle(circleWidget);
|
||||
|
||||
if (circleOriginal != nullptr)
|
||||
Widget::getInstance()->searchCircle(circleOriginal);
|
||||
}
|
||||
circleWidget->show(); // Avoid flickering.
|
||||
}
|
||||
|
||||
void FriendListWidget::removeCircleWidget(CircleWidget *widget)
|
||||
void FriendListWidget::removeCircleWidget(CircleWidget* widget)
|
||||
{
|
||||
circleLayout.removeSortedWidget(widget);
|
||||
widget->deleteLater();
|
||||
|
@ -105,9 +108,8 @@ void FriendListWidget::searchChatrooms(const QString &searchString, bool hideOnl
|
|||
listLayout->searchChatrooms(searchString, hideOnline, hideOffline);
|
||||
for (int i = 0; i != circleLayout.getLayout()->count(); ++i)
|
||||
{
|
||||
CircleWidget *circleWidget = static_cast<CircleWidget*>(circleLayout.getLayout()->itemAt(i)->widget());
|
||||
circleWidget->searchChatrooms(searchString, hideOnline, hideOffline);
|
||||
circleWidget->setVisible(searchString.isEmpty() || (circleWidget->hasChatrooms() && !(hideOnline && hideOffline)));
|
||||
CircleWidget* circleWidget = static_cast<CircleWidget*>(circleLayout.getLayout()->itemAt(i)->widget());
|
||||
circleWidget->search(searchString, true, hideOnline, hideOffline);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -118,10 +120,10 @@ void FriendListWidget::renameGroupWidget(const QString &newName)
|
|||
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);
|
||||
reDraw(); // Prevent artifacts.
|
||||
}
|
||||
|
||||
void FriendListWidget::renameCircleWidget(const QString &newName)
|
||||
|
@ -202,7 +204,6 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
|||
index += forward ? 1 : -1;
|
||||
for (;;)
|
||||
{
|
||||
qDebug() << "CHECKING BOUNDS...............................";
|
||||
// Bounds checking.
|
||||
if (index < 0)
|
||||
{
|
||||
|
@ -257,25 +258,25 @@ QVector<CircleWidget*> FriendListWidget::getAllCircles()
|
|||
return vec;
|
||||
}
|
||||
|
||||
void FriendListWidget::dragEnterEvent(QDragEnterEvent *event)
|
||||
void FriendListWidget::dragEnterEvent(QDragEnterEvent* event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat("friend"))
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void FriendListWidget::dropEvent(QDropEvent *event)
|
||||
void FriendListWidget::dropEvent(QDropEvent* event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat("friend"))
|
||||
{
|
||||
int friendId = event->mimeData()->data("friend").toInt();
|
||||
Friend *f = FriendList::findFriend(friendId);
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
assert(f != nullptr);
|
||||
|
||||
FriendWidget *widget = f->getFriendWidget();
|
||||
FriendWidget* widget = f->getFriendWidget();
|
||||
assert(widget != nullptr);
|
||||
|
||||
// Update old circle after moved.
|
||||
CircleWidget *circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(f->getToxId()));
|
||||
CircleWidget* circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(f->getToxId()));
|
||||
|
||||
listLayout->addFriendWidget(widget, f->getStatus());
|
||||
|
||||
|
@ -287,10 +288,10 @@ void FriendListWidget::dropEvent(QDropEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
void FriendListWidget::moveWidget(FriendWidget *w, Status s, bool add)
|
||||
void FriendListWidget::moveWidget(FriendWidget* w, Status s, bool add)
|
||||
{
|
||||
int circleId = Settings::getInstance().getFriendCircleID(FriendList::findFriend(w->friendId)->getToxId());
|
||||
CircleWidget *circleWidget = CircleWidget::getFromID(circleId);
|
||||
CircleWidget* circleWidget = CircleWidget::getFromID(circleId);
|
||||
|
||||
if (circleWidget == nullptr || add)
|
||||
{
|
||||
|
@ -311,6 +312,16 @@ void FriendListWidget::reDraw()
|
|||
resize(QSize()); //lifehack
|
||||
}
|
||||
|
||||
CircleWidget* FriendListWidget::createCircleWidget(int id)
|
||||
{
|
||||
CircleWidget* circleWidget = new CircleWidget(this, id);
|
||||
circleLayout.addSortedWidget(circleWidget);
|
||||
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);
|
||||
connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget);
|
||||
circleWidget->show(); // Avoid flickering.
|
||||
return circleWidget;
|
||||
}
|
||||
|
||||
QLayout* FriendListWidget::nextLayout(QLayout* layout, bool forward) const
|
||||
{
|
||||
if (layout == groupLayout.getLayout())
|
||||
|
|
|
@ -21,38 +21,30 @@
|
|||
#define FRIENDLISTWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QHash>
|
||||
#include <QList>
|
||||
#include <QVector>
|
||||
#include "src/core/corestructs.h"
|
||||
#include "src/widget/genericchatroomwidget.h"
|
||||
|
||||
#include "genericchatitemlayout.h"
|
||||
|
||||
#include "circlewidget.h"
|
||||
#include "groupwidget.h"
|
||||
|
||||
class QVBoxLayout;
|
||||
class QGridLayout;
|
||||
class QPixmap;
|
||||
|
||||
class Widget;
|
||||
class FriendWidget;
|
||||
class GroupWidget;
|
||||
class CircleWidget;
|
||||
class FriendListLayout;
|
||||
class GenericChatroomWidget;
|
||||
|
||||
class FriendListWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit FriendListWidget(QWidget *parent = 0, bool groupsOnTop = true);
|
||||
explicit FriendListWidget(Widget* parent, bool groupsOnTop = true);
|
||||
|
||||
void addGroupWidget(GroupWidget *widget);
|
||||
void addFriendWidget(FriendWidget *w, Status s, int circleIndex);
|
||||
void addGroupWidget(GroupWidget* widget);
|
||||
void addFriendWidget(FriendWidget* w, Status s, int circleIndex);
|
||||
void addCircleWidget(int id);
|
||||
void addCircleWidget(FriendWidget *widget = nullptr);
|
||||
void removeCircleWidget(CircleWidget *widget);
|
||||
|
||||
void addCircleWidget(FriendWidget* widget = nullptr);
|
||||
void removeCircleWidget(CircleWidget* widget);
|
||||
void searchChatrooms(const QString &searchString, bool hideOnline = false, bool hideOffline = false, bool hideGroups = false);
|
||||
|
||||
void cycleContacts(GenericChatroomWidget* activeChatroomWidget, bool forward);
|
||||
|
@ -67,13 +59,14 @@ public slots:
|
|||
void renameGroupWidget(const QString& newName);
|
||||
void renameCircleWidget(const QString& newName);
|
||||
void onGroupchatPositionChanged(bool top);
|
||||
void moveWidget(FriendWidget *w, Status s, bool add = false);
|
||||
void moveWidget(FriendWidget* w, Status s, bool add = false);
|
||||
|
||||
protected:
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
void dropEvent(QDropEvent* event) override;
|
||||
|
||||
private:
|
||||
CircleWidget* createCircleWidget(int id = -1);
|
||||
QLayout* nextLayout(QLayout* layout, bool forward) const;
|
||||
|
||||
bool groupsOnTop;
|
||||
|
|
|
@ -91,6 +91,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
|||
friendList = dynamic_cast<FriendListWidget*>(circleWidget->parentWidget());
|
||||
|
||||
assert(friendList != nullptr);
|
||||
friendList->reDraw();
|
||||
|
||||
QVector<CircleWidget*> circleVec = friendList->getAllCircles();
|
||||
QMap<QAction*, CircleWidget*> circleActions;
|
||||
|
@ -162,15 +163,21 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
|||
else if (removeCircleAction != nullptr && selectedItem == removeCircleAction)
|
||||
{
|
||||
friendList->moveWidget(this, FriendList::findFriend(friendId)->getStatus(), true);
|
||||
circleWidget->updateStatus();
|
||||
Widget::getInstance()->searchCircle(circleWidget);
|
||||
}
|
||||
else if (circleActions.contains(selectedItem))
|
||||
{
|
||||
if (circleWidget != nullptr)
|
||||
circleWidget->updateStatus();
|
||||
|
||||
CircleWidget* circle = circleActions[selectedItem];
|
||||
circle->addFriendWidget(this, FriendList::findFriend(friendId)->getStatus());
|
||||
circle->setExpanded(true);
|
||||
Widget::getInstance()->searchCircle(circle);
|
||||
|
||||
if (circleWidget != nullptr)
|
||||
{
|
||||
circleWidget->updateStatus();
|
||||
Widget::getInstance()->searchCircle(circleWidget);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -244,6 +251,14 @@ QString FriendWidget::getStatusString()
|
|||
return QString::null;
|
||||
}
|
||||
|
||||
void FriendWidget::search(const QString &searchString, bool hide)
|
||||
{
|
||||
searchName(searchString, hide);
|
||||
CircleWidget* circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(FriendList::findFriend(friendId)->getToxId()));
|
||||
if (circleWidget != nullptr)
|
||||
circleWidget->search(searchString);
|
||||
}
|
||||
|
||||
void FriendWidget::setChatForm(Ui::MainWindow &ui)
|
||||
{
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
|
|
|
@ -35,6 +35,7 @@ public:
|
|||
virtual void setChatForm(Ui::MainWindow &) override;
|
||||
virtual void resetEventFlags() override;
|
||||
virtual QString getStatusString() override;
|
||||
void search(const QString &searchString, bool hide = false);
|
||||
|
||||
signals:
|
||||
void friendWidgetClicked(FriendWidget* widget);
|
||||
|
|
|
@ -83,7 +83,7 @@ void GenericChatItemLayout::search(const QString &searchString, bool hideAll)
|
|||
GenericChatItemWidget* widgetAt = dynamic_cast<GenericChatItemWidget*>(layout->itemAt(index)->widget());
|
||||
assert(widgetAt != nullptr);
|
||||
|
||||
widgetAt->setVisible(!hideAll && widgetAt->getName().contains(searchString, Qt::CaseInsensitive));
|
||||
widgetAt->searchName(searchString, hideAll);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ public:
|
|||
int indexOfSortedWidget(GenericChatItemWidget* widget) const;
|
||||
bool existsSortedWidget(GenericChatItemWidget* widget) const;
|
||||
void removeSortedWidget(GenericChatItemWidget* widget);
|
||||
void search(const QString &searchString, bool hideAll);
|
||||
void search(const QString &searchString, bool hideAll = false);
|
||||
|
||||
QLayout* getLayout() const;
|
||||
|
||||
|
|
|
@ -43,3 +43,8 @@ QString GenericChatItemWidget::getName() const
|
|||
{
|
||||
return nameLabel->fullText();
|
||||
}
|
||||
|
||||
void GenericChatItemWidget::searchName(const QString &searchString, bool hide)
|
||||
{
|
||||
setVisible(!hide && getName().contains(searchString, Qt::CaseInsensitive));
|
||||
}
|
||||
|
|
|
@ -23,6 +23,13 @@ class GenericChatItemWidget : public QFrame
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum ItemType
|
||||
{
|
||||
GroupItem,
|
||||
FriendOfflineItem,
|
||||
FriendOnlineItem
|
||||
};
|
||||
|
||||
GenericChatItemWidget(QWidget *parent = 0);
|
||||
|
||||
bool isCompact() const;
|
||||
|
@ -30,6 +37,8 @@ public:
|
|||
|
||||
QString getName() const;
|
||||
|
||||
void searchName(const QString &searchString, bool hideAll);
|
||||
|
||||
Q_PROPERTY(bool compact READ isCompact WRITE setCompact)
|
||||
|
||||
protected:
|
||||
|
|
|
@ -53,12 +53,12 @@ GroupWidget::GroupWidget(int GroupId, QString Name)
|
|||
|
||||
connect(nameLabel, &CroppingLabel::textChanged, [this](const QString &newName, const QString &oldName)
|
||||
{
|
||||
//Group* g = GroupList::findGroup(groupId);
|
||||
Group* g = GroupList::findGroup(groupId);
|
||||
if (newName != oldName)
|
||||
{
|
||||
nameLabel->setText(oldName);
|
||||
emit renameRequested(newName);
|
||||
//emit g->getChatForm()->groupTitleChanged(groupId, newText.left(128));
|
||||
emit g->getChatForm()->groupTitleChanged(groupId, newName.left(128));
|
||||
}
|
||||
/* according to agilob:
|
||||
* “Moving mouse pointer over groupwidget results in CSS effect
|
||||
|
@ -68,8 +68,6 @@ GroupWidget::GroupWidget(int GroupId, QString Name)
|
|||
*/
|
||||
this->repaint();
|
||||
});
|
||||
|
||||
nameLabel->editStart();
|
||||
}
|
||||
|
||||
void GroupWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||
|
@ -140,6 +138,11 @@ QString GroupWidget::getStatusString()
|
|||
return "New Message";
|
||||
}
|
||||
|
||||
void GroupWidget::rename()
|
||||
{
|
||||
nameLabel->editStart();
|
||||
}
|
||||
|
||||
void GroupWidget::setChatForm(Ui::MainWindow &ui)
|
||||
{
|
||||
Group* g = GroupList::findGroup(groupId);
|
||||
|
|
|
@ -36,6 +36,7 @@ public:
|
|||
virtual QString getStatusString() final override;
|
||||
void setName(const QString& name);
|
||||
void onUserListChanged();
|
||||
void rename();
|
||||
|
||||
signals:
|
||||
void groupWidgetClicked(GroupWidget* widget);
|
||||
|
@ -44,9 +45,9 @@ signals:
|
|||
|
||||
protected:
|
||||
// drag & drop
|
||||
virtual void dragEnterEvent(QDragEnterEvent* ev) final override;
|
||||
virtual void dragEnterEvent(QDragEnterEvent* ev) override;
|
||||
virtual void dragLeaveEvent(QDragLeaveEvent* ev);
|
||||
virtual void dropEvent(QDropEvent* ev) final override;
|
||||
virtual void dropEvent(QDropEvent* ev) override;
|
||||
virtual void keyPressEvent(QKeyEvent* ev);
|
||||
virtual void keyReleaseEvent(QKeyEvent* ev);
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <QLineEdit>
|
||||
|
||||
#include <QTimer>
|
||||
#include <QDebug>
|
||||
|
||||
CroppingLabel::CroppingLabel(QWidget* parent)
|
||||
: QLabel(parent)
|
||||
|
@ -39,10 +40,13 @@ CroppingLabel::CroppingLabel(QWidget* parent)
|
|||
|
||||
installEventFilter(this);
|
||||
textEdit->installEventFilter(this);
|
||||
connect(textEdit, &QLineEdit::editingFinished, this, &CroppingLabel::finishTextEdit);
|
||||
}
|
||||
|
||||
void CroppingLabel::editStart()
|
||||
{
|
||||
//if (!parentWidget()->isVisible())
|
||||
// return;
|
||||
showTextEdit();
|
||||
textEdit->selectAll();
|
||||
}
|
||||
|
@ -122,7 +126,9 @@ bool CroppingLabel::eventFilter(QObject *obj, QEvent *e)
|
|||
}
|
||||
|
||||
if (e->type() == QEvent::FocusOut)
|
||||
{
|
||||
hideTextEdit(true);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -168,3 +174,17 @@ QString CroppingLabel::fullText()
|
|||
{
|
||||
return origText;
|
||||
}
|
||||
|
||||
void CroppingLabel::finishTextEdit()
|
||||
{
|
||||
QString newText = textEdit->text().trimmed().remove(QRegExp("[\\t\\n\\v\\f\\r\\x0000]"));
|
||||
if (!newText.isEmpty() && origText != newText)
|
||||
{
|
||||
setText(textEdit->text()); // set before emitting so we don't override external reactions to signal
|
||||
emit textChanged(textEdit->text(), origText);
|
||||
emit editFinished(textEdit->text());
|
||||
}
|
||||
|
||||
textEdit->hide();
|
||||
blockPaintEvents = false;
|
||||
}
|
||||
|
|
|
@ -24,11 +24,11 @@
|
|||
|
||||
class QLineEdit;
|
||||
|
||||
class CroppingLabel final : public QLabel
|
||||
class CroppingLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit CroppingLabel(QWidget *parent = 0);
|
||||
explicit CroppingLabel(QWidget* parent = 0);
|
||||
|
||||
void editStart();
|
||||
void setEditable(bool editable);
|
||||
|
@ -52,6 +52,9 @@ protected:
|
|||
virtual void mouseReleaseEvent(QMouseEvent *e) final override;
|
||||
virtual bool eventFilter(QObject *obj, QEvent *e) final override;
|
||||
|
||||
private slots:
|
||||
void finishTextEdit();
|
||||
|
||||
private:
|
||||
QString origText;
|
||||
QLineEdit* textEdit;
|
||||
|
|
|
@ -153,7 +153,7 @@ void Widget::init()
|
|||
ui->statusPanel->setStyleSheet(Style::getStylesheet(":/ui/window/statusPanel.css"));
|
||||
#endif
|
||||
|
||||
contactListWidget = new FriendListWidget(0, Settings::getInstance().getGroupchatPosition());
|
||||
contactListWidget = new FriendListWidget(this, Settings::getInstance().getGroupchatPosition());
|
||||
ui->friendList->setWidget(contactListWidget);
|
||||
ui->friendList->setLayoutDirection(Qt::RightToLeft);
|
||||
ui->friendList->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
@ -631,7 +631,8 @@ void Widget::addFriend(int friendId, const QString &userId)
|
|||
newfriend->getFriendWidget()->onAvatarChange(friendId, avatar);
|
||||
}
|
||||
|
||||
searchContacts();
|
||||
int filter = ui->searchContactFilterCBox->currentIndex();
|
||||
newfriend->getFriendWidget()->search(ui->searchContactText->text(), filterOffline(filter));
|
||||
}
|
||||
|
||||
void Widget::addFriendFailed(const QString&, const QString& errorInfo)
|
||||
|
@ -719,7 +720,7 @@ void Widget::onFriendUsernameChanged(int friendId, const QString& username)
|
|||
QString str = username; str.replace('\n', ' ');
|
||||
str.remove('\r'); str.remove(QChar((char)0)); // null terminator...
|
||||
f->setName(str);
|
||||
searchContacts();
|
||||
|
||||
}
|
||||
|
||||
void Widget::onChatroomWidgetClicked(GenericChatroomWidget *widget)
|
||||
|
@ -996,7 +997,9 @@ void Widget::onGroupTitleChanged(int groupnumber, const QString& author, const Q
|
|||
g->setName(title);
|
||||
if (!author.isEmpty())
|
||||
g->getChatForm()->addSystemInfoMessage(tr("%1 has set the title to %2").arg(author, title), ChatMessage::INFO, QDateTime::currentDateTime());
|
||||
searchContacts();
|
||||
|
||||
int filter = ui->searchContactFilterCBox->currentIndex();
|
||||
g->getGroupWidget()->searchName(ui->searchContactText->text(), filterGroups(filter));
|
||||
}
|
||||
|
||||
void Widget::onGroupPeerAudioPlaying(int groupnumber, int peernumber)
|
||||
|
@ -1043,8 +1046,7 @@ Group *Widget::createGroup(int groupId)
|
|||
|
||||
QString groupName = QString("Groupchat #%1").arg(groupId);
|
||||
Group* newgroup = GroupList::addGroup(groupId, groupName, core->isGroupAvEnabled(groupId));
|
||||
//QLayout* layout = contactListWidget->getGroupLayout();
|
||||
//layout->addWidget(newgroup->getGroupWidget());
|
||||
|
||||
contactListWidget->addGroupWidget(newgroup->getGroupWidget());
|
||||
newgroup->getGroupWidget()->updateStatusLight();
|
||||
|
||||
|
@ -1055,7 +1057,10 @@ Group *Widget::createGroup(int groupId)
|
|||
connect(newgroup->getChatForm(), &GroupChatForm::sendMessage, core, &Core::sendGroupMessage);
|
||||
connect(newgroup->getChatForm(), &GroupChatForm::sendAction, core, &Core::sendGroupAction);
|
||||
connect(newgroup->getChatForm(), &GroupChatForm::groupTitleChanged, core, &Core::changeGroupTitle);
|
||||
searchContacts();
|
||||
|
||||
int filter = ui->searchContactFilterCBox->currentIndex();
|
||||
newgroup->getGroupWidget()->searchName(ui->searchContactText->text(), filterGroups(filter));
|
||||
|
||||
return newgroup;
|
||||
}
|
||||
|
||||
|
@ -1265,22 +1270,45 @@ void Widget::onSplitterMoved(int pos, int index)
|
|||
saveSplitterGeometry();
|
||||
}
|
||||
|
||||
void Widget::cycleContacts(int offset)
|
||||
void Widget::cycleContacts(bool forward)
|
||||
{
|
||||
contactListWidget->cycleContacts(activeChatroomWidget, offset == 1 ? true : false);
|
||||
/*if (!activeChatroomWidget)
|
||||
return;
|
||||
contactListWidget->cycleContacts(activeChatroomWidget, forward);
|
||||
}
|
||||
|
||||
FriendListWidget* friendList = static_cast<FriendListWidget*>(ui->friendList->widget());
|
||||
QList<GenericChatroomWidget*> friends = friendList->getAllFriends();
|
||||
bool Widget::filterGroups(int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case FilterCriteria::Offline:
|
||||
case FilterCriteria::Friends:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
int activeIndex = friends.indexOf(activeChatroomWidget);
|
||||
int bounded = (activeIndex + offset) % friends.length();
|
||||
bool Widget::filterOffline(int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case FilterCriteria::Online:
|
||||
case FilterCriteria::Groups:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if(bounded < 0)
|
||||
bounded += friends.length();
|
||||
|
||||
emit friends[bounded]->chatroomWidgetClicked(friends[bounded]);*/
|
||||
bool Widget::filterOnline(int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case FilterCriteria::Offline:
|
||||
case FilterCriteria::Groups:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::processOfflineMsgs()
|
||||
|
@ -1392,30 +1420,39 @@ void Widget::searchContacts()
|
|||
QString searchString = ui->searchContactText->text();
|
||||
int filter = ui->searchContactFilterCBox->currentIndex();
|
||||
|
||||
switch(filter)
|
||||
{
|
||||
case FilterCriteria::All:
|
||||
contactListWidget->searchChatrooms(searchString, false, false, false);
|
||||
break;
|
||||
case FilterCriteria::Online:
|
||||
contactListWidget->searchChatrooms(searchString, false, true, false);
|
||||
break;
|
||||
case FilterCriteria::Offline:
|
||||
contactListWidget->searchChatrooms(searchString, true, false, true);
|
||||
break;
|
||||
case FilterCriteria::Friends:
|
||||
contactListWidget->searchChatrooms(searchString, false, false, true);
|
||||
break;
|
||||
case FilterCriteria::Groups:
|
||||
contactListWidget->searchChatrooms(searchString, true, true, false);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
contactListWidget->searchChatrooms(searchString, filterOnline(filter), filterOffline(filter), filterGroups(filter));
|
||||
|
||||
contactListWidget->reDraw();
|
||||
}
|
||||
|
||||
void Widget::searchCircle(CircleWidget *circleWidget)
|
||||
{
|
||||
int filter = ui->searchContactFilterCBox->currentIndex();
|
||||
circleWidget->search(ui->searchContactText->text(), true, filterOnline(filter), filterOffline(filter));
|
||||
}
|
||||
|
||||
void Widget::searchItem(GenericChatItemWidget *chatItem, GenericChatItemWidget::ItemType type)
|
||||
{
|
||||
bool hide;
|
||||
int filter = ui->searchContactFilterCBox->currentIndex();
|
||||
switch (type)
|
||||
{
|
||||
case GenericChatItemWidget::GroupItem:
|
||||
hide = filterGroups(filter);
|
||||
break;
|
||||
default:
|
||||
hide = true;
|
||||
}
|
||||
|
||||
chatItem->searchName(ui->searchContactText->text(), hide);
|
||||
}
|
||||
|
||||
bool Widget::groupsVisible() const
|
||||
{
|
||||
int filter = ui->searchContactFilterCBox->currentIndex();
|
||||
return !filterGroups(filter);
|
||||
}
|
||||
|
||||
void Widget::friendListContextMenu(const QPoint &pos)
|
||||
{
|
||||
QMenu menu(this);
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <QSystemTrayIcon>
|
||||
#include <QFileInfo>
|
||||
#include "src/core/corestructs.h"
|
||||
#include "genericchatitemwidget.h"
|
||||
|
||||
#define PIXELS_TO_ACT 7
|
||||
|
||||
|
@ -47,6 +48,7 @@ class FilesForm;
|
|||
class ProfileForm;
|
||||
class SettingsWidget;
|
||||
class AddFriendForm;
|
||||
class CircleWidget;
|
||||
|
||||
class Widget final : public QMainWindow
|
||||
{
|
||||
|
@ -77,6 +79,10 @@ public:
|
|||
static QString getStatusTitle(Status status);
|
||||
static Status getStatusFromString(QString status);
|
||||
|
||||
void searchCircle(CircleWidget* circleWidget);
|
||||
void searchItem(GenericChatItemWidget* chatItem, GenericChatItemWidget::ItemType type);
|
||||
bool groupsVisible() const;
|
||||
|
||||
public slots:
|
||||
void onSettingsClicked();
|
||||
void setWindowTitle(const QString& title);
|
||||
|
@ -147,7 +153,6 @@ private slots:
|
|||
void onSetShowSystemTray(bool newValue);
|
||||
void onSplitterMoved(int pos, int index);
|
||||
void processOfflineMsgs();
|
||||
void searchContacts();
|
||||
void friendListContextMenu(const QPoint &pos);
|
||||
|
||||
private:
|
||||
|
@ -176,7 +181,11 @@ private:
|
|||
void removeGroup(Group* g, bool fake = false);
|
||||
void saveWindowGeometry();
|
||||
void saveSplitterGeometry();
|
||||
void cycleContacts(int offset);
|
||||
void cycleContacts(bool forward);
|
||||
void searchContacts();
|
||||
static bool filterGroups(int index);
|
||||
static bool filterOnline(int index);
|
||||
static bool filterOffline(int index);
|
||||
void retranslateUi();
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue
Block a user