mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Contact grouping deleting and renaming
This commit is contained in:
parent
1e2bad8611
commit
ff37812a53
|
@ -22,17 +22,20 @@
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QBoxLayout>
|
#include <QBoxLayout>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
|
#include <QLineEdit>
|
||||||
|
|
||||||
#include <QDragEnterEvent>
|
#include <QDragEnterEvent>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
|
#include <QMenu>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "friendlistlayout.h"
|
#include "friendlistlayout.h"
|
||||||
|
#include "friendlistwidget.h"
|
||||||
|
|
||||||
CircleWidget::CircleWidget(QWidget *parent)
|
CircleWidget::CircleWidget(FriendListWidget *parent)
|
||||||
: GenericChatItemWidget(parent)
|
: GenericChatItemWidget(parent)
|
||||||
{
|
{
|
||||||
setStyleSheet(Style::getStylesheet(":/ui/chatroomWidgets/circleWidget.css"));
|
setStyleSheet(Style::getStylesheet(":/ui/chatroomWidgets/circleWidget.css"));
|
||||||
|
@ -58,7 +61,7 @@ CircleWidget::CircleWidget(QWidget *parent)
|
||||||
arrowLabel->setStyleSheet("color: white;");
|
arrowLabel->setStyleSheet("color: white;");
|
||||||
topLayout->addWidget(arrowLabel);
|
topLayout->addWidget(arrowLabel);
|
||||||
topLayout->addSpacing(5);
|
topLayout->addSpacing(5);
|
||||||
QLabel *nameLabel = new QLabel("Circle", container);
|
nameLabel = new QLabel("Circle", container);
|
||||||
nameLabel->setObjectName("name");
|
nameLabel->setObjectName("name");
|
||||||
topLayout->addWidget(nameLabel);
|
topLayout->addWidget(nameLabel);
|
||||||
QFrame *lineFrame = new QFrame(container);
|
QFrame *lineFrame = new QFrame(container);
|
||||||
|
@ -74,9 +77,9 @@ CircleWidget::CircleWidget(QWidget *parent)
|
||||||
|
|
||||||
QHBoxLayout *statusLayout = new QHBoxLayout();
|
QHBoxLayout *statusLayout = new QHBoxLayout();
|
||||||
|
|
||||||
QLabel *onlineIconLabel = new QLabel(container);
|
//QLabel *onlineIconLabel = new QLabel(container);
|
||||||
onlineIconLabel->setAlignment(Qt::AlignCenter);
|
//onlineIconLabel->setAlignment(Qt::AlignCenter);
|
||||||
onlineIconLabel->setPixmap(QPixmap(":img/status/dot_online.svg"));
|
//onlineIconLabel->setPixmap(QPixmap(":img/status/dot_online.svg"));
|
||||||
onlineLabel = new QLabel("0", container);
|
onlineLabel = new QLabel("0", container);
|
||||||
onlineLabel->setObjectName("status");
|
onlineLabel->setObjectName("status");
|
||||||
|
|
||||||
|
@ -86,23 +89,23 @@ CircleWidget::CircleWidget(QWidget *parent)
|
||||||
QLabel *awayLabel = new QLabel("0", container);
|
QLabel *awayLabel = new QLabel("0", container);
|
||||||
awayLabel->setObjectName("status");*/
|
awayLabel->setObjectName("status");*/
|
||||||
|
|
||||||
QLabel *offlineIconLabel = new QLabel(container);
|
//QLabel *offlineIconLabel = new QLabel(container);
|
||||||
offlineIconLabel->setAlignment(Qt::AlignCenter);
|
//offlineIconLabel->setAlignment(Qt::AlignCenter);
|
||||||
offlineIconLabel->setPixmap(QPixmap(":img/status/dot_offline.svg"));
|
//offlineIconLabel->setPixmap(QPixmap(":img/status/dot_offline.svg"));
|
||||||
offlineLabel = new QLabel("0", container);
|
//offlineLabel = new QLabel("0", container);
|
||||||
offlineLabel->setObjectName("status");
|
//offlineLabel->setObjectName("status");
|
||||||
|
|
||||||
statusLayout->addWidget(onlineIconLabel);
|
//statusLayout->addWidget(onlineIconLabel);
|
||||||
statusLayout->addSpacing(5);
|
//statusLayout->addSpacing(2);
|
||||||
statusLayout->addWidget(onlineLabel);
|
statusLayout->addWidget(onlineLabel);
|
||||||
statusLayout->addSpacing(10);
|
//statusLayout->addSpacing(10);
|
||||||
//statusLayout->addWidget(awayIconLabel);
|
//statusLayout->addWidget(awayIconLabel);
|
||||||
//statusLayout->addSpacing(5);
|
//statusLayout->addSpacing(5);
|
||||||
//statusLayout->addWidget(awayLabel);
|
//statusLayout->addWidget(awayLabel);
|
||||||
//statusLayout->addSpacing(10);
|
//statusLayout->addSpacing(10);
|
||||||
statusLayout->addWidget(offlineIconLabel);
|
//statusLayout->addWidget(offlineIconLabel);
|
||||||
statusLayout->addSpacing(5);
|
//statusLayout->addSpacing(2);
|
||||||
statusLayout->addWidget(offlineLabel);
|
//statusLayout->addWidget(offlineLabel);
|
||||||
//statusLayout->addStretch();
|
//statusLayout->addStretch();
|
||||||
|
|
||||||
//midLayout->addLayout(statusLayout);
|
//midLayout->addLayout(statusLayout);
|
||||||
|
@ -123,7 +126,6 @@ CircleWidget::CircleWidget(QWidget *parent)
|
||||||
|
|
||||||
void CircleWidget::addFriendWidget(FriendWidget *w, Status s)
|
void CircleWidget::addFriendWidget(FriendWidget *w, Status s)
|
||||||
{
|
{
|
||||||
qDebug() << "YOLO COMBO";
|
|
||||||
listLayout->addFriendWidget(w, s);
|
listLayout->addFriendWidget(w, s);
|
||||||
//if (s == Status::Offline)
|
//if (s == Status::Offline)
|
||||||
updateOffline();
|
updateOffline();
|
||||||
|
@ -151,6 +153,63 @@ void CircleWidget::searchChatrooms(const QString &searchString, bool hideOnline,
|
||||||
listLayout->searchChatrooms(searchString, hideOnline, hideOffline, hideGroups);
|
listLayout->searchChatrooms(searchString, hideOnline, hideOffline, hideGroups);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CircleWidget::renameCircle()
|
||||||
|
{
|
||||||
|
qDebug() << nameLabel->parentWidget()->layout();
|
||||||
|
QLineEdit *lineEdit = new QLineEdit(nameLabel->text());
|
||||||
|
lineEdit->show();
|
||||||
|
//nameLabel->parentWidget()->layout()
|
||||||
|
//static_cast<QBoxLayout*>(nameLabel->parentWidget()->layout())->insertWidget(nameLabel->parentWidget()->layout()->indexOf(nameLabel) - 1, lineEdit);
|
||||||
|
//nameLabel->parentWidget()->layout()->replaceWidget(nameLabel, lineEdit);
|
||||||
|
nameLabel->setVisible(false);
|
||||||
|
lineEdit->selectAll();
|
||||||
|
lineEdit->setFocus();
|
||||||
|
connect(lineEdit, &QLineEdit::editingFinished, [this, lineEdit]()
|
||||||
|
{
|
||||||
|
nameLabel->setVisible(true);
|
||||||
|
//lineEdit->parentWidget()->layout()->replaceWidget(lineEdit, nameLabel);
|
||||||
|
nameLabel->setText(lineEdit->text());
|
||||||
|
lineEdit->deleteLater();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void CircleWidget::contextMenuEvent(QContextMenuEvent *event)
|
||||||
|
{
|
||||||
|
QMenu menu;
|
||||||
|
QAction *renameAction = menu.addAction(tr("Rename circle", "Menu for renaming a circle"));
|
||||||
|
QAction *removeAction = menu.addAction(tr("Remove circle", "Menu for removing a circle"));
|
||||||
|
|
||||||
|
QAction *selectedItem = menu.exec(mapToGlobal(event->pos()));
|
||||||
|
if (selectedItem == renameAction)
|
||||||
|
renameCircle();
|
||||||
|
else if (selectedItem == removeAction)
|
||||||
|
{
|
||||||
|
FriendListWidget *friendList = static_cast<FriendListWidget*>(parentWidget());
|
||||||
|
while (listLayout->friendLayouts[Online]->count() != 0)
|
||||||
|
{
|
||||||
|
QWidget *getWidget = listLayout->friendLayouts[Online]->takeAt(0)->widget();
|
||||||
|
qDebug() << getWidget;
|
||||||
|
assert(getWidget != nullptr);
|
||||||
|
|
||||||
|
FriendWidget *friendWidget = dynamic_cast<FriendWidget*>(getWidget);
|
||||||
|
qDebug() << friendWidget;
|
||||||
|
friendList->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true);
|
||||||
|
}
|
||||||
|
while (listLayout->friendLayouts[Offline]->count() != 0)
|
||||||
|
{
|
||||||
|
QWidget *getWidget = listLayout->friendLayouts[Offline]->takeAt(0)->widget();
|
||||||
|
qDebug() << getWidget;
|
||||||
|
assert(getWidget != nullptr);
|
||||||
|
|
||||||
|
FriendWidget *friendWidget = dynamic_cast<FriendWidget*>(getWidget);
|
||||||
|
qDebug() << friendWidget;
|
||||||
|
friendList->moveWidget(friendWidget, FriendList::findFriend(friendWidget->friendId)->getStatus(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
friendList->removeCircleWidget(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CircleWidget::mousePressEvent(QMouseEvent *event)
|
void CircleWidget::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
if (event->button() == Qt::LeftButton)
|
if (event->button() == Qt::LeftButton)
|
||||||
|
@ -204,10 +263,10 @@ void CircleWidget::dropEvent(QDropEvent *event)
|
||||||
|
|
||||||
void CircleWidget::updateOnline()
|
void CircleWidget::updateOnline()
|
||||||
{
|
{
|
||||||
onlineLabel->setText(QString::number(listLayout->friendOnlineCount()));
|
onlineLabel->setText(QString::number(listLayout->friendOnlineCount()) + QStringLiteral(" / ") + QString::number(listLayout->friendOfflineCount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CircleWidget::updateOffline()
|
void CircleWidget::updateOffline()
|
||||||
{
|
{
|
||||||
offlineLabel->setText(QString::number(listLayout->friendOfflineCount()));
|
//offlineLabel->setText(QString::number(listLayout->friendOfflineCount()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,14 +21,16 @@
|
||||||
class QVBoxLayout;
|
class QVBoxLayout;
|
||||||
class QHBoxLayout;
|
class QHBoxLayout;
|
||||||
class QLabel;
|
class QLabel;
|
||||||
|
class FriendListWidget;
|
||||||
class FriendListLayout;
|
class FriendListLayout;
|
||||||
class FriendWidget;
|
class FriendWidget;
|
||||||
|
class QLineEdit;
|
||||||
|
|
||||||
class CircleWidget : public GenericChatItemWidget
|
class CircleWidget : public GenericChatItemWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CircleWidget(QWidget *parent = 0);
|
CircleWidget(FriendListWidget *parent = 0);
|
||||||
|
|
||||||
void addFriendWidget(FriendWidget *w, Status s);
|
void addFriendWidget(FriendWidget *w, Status s);
|
||||||
|
|
||||||
|
@ -39,8 +41,12 @@ public:
|
||||||
void updateOnline();
|
void updateOnline();
|
||||||
void updateOffline();
|
void updateOffline();
|
||||||
|
|
||||||
|
void renameCircle();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
void contextMenuEvent(QContextMenuEvent *event);
|
||||||
|
|
||||||
void mousePressEvent(QMouseEvent *event) override;
|
void mousePressEvent(QMouseEvent *event) override;
|
||||||
|
|
||||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||||
|
@ -60,6 +66,7 @@ private:
|
||||||
QLabel *onlineLabel;
|
QLabel *onlineLabel;
|
||||||
QLabel *offlineLabel;
|
QLabel *offlineLabel;
|
||||||
QWidget *container;
|
QWidget *container;
|
||||||
|
QLabel *nameLabel;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CIRCLEWIDGET_H
|
#endif // CIRCLEWIDGET_H
|
||||||
|
|
|
@ -90,7 +90,7 @@ int FriendListLayout::friendOnlineCount() const
|
||||||
|
|
||||||
int FriendListLayout::friendOfflineCount() const
|
int FriendListLayout::friendOfflineCount() const
|
||||||
{
|
{
|
||||||
return friendLayouts[Offline]->count();
|
return friendLayouts[Offline]->count() + friendOnlineCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename WidgetType>
|
template <typename WidgetType>
|
||||||
|
|
|
@ -51,9 +51,21 @@ void FriendListWidget::addGroupWidget(GroupWidget *widget)
|
||||||
listLayout->groupLayout->addWidget(widget);
|
listLayout->groupLayout->addWidget(widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendListWidget::addCircleWidget(CircleWidget *widget)
|
void FriendListWidget::addCircleWidget()
|
||||||
{
|
{
|
||||||
circleLayout->addWidget(widget);
|
CircleWidget *circleWidget = new CircleWidget(this);
|
||||||
|
circleLayout->addWidget(circleWidget);
|
||||||
|
circleWidget->show(); // Avoid flickering.
|
||||||
|
}
|
||||||
|
|
||||||
|
void FriendListWidget::removeCircleWidget(CircleWidget *widget)
|
||||||
|
{
|
||||||
|
//setUpdatesEnabled(false);
|
||||||
|
//widget->setVisible(false);
|
||||||
|
//circleLayout->removeWidget(widget);
|
||||||
|
widget->deleteLater();
|
||||||
|
//setUpdatesEnabled(true);
|
||||||
|
//widget->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FriendListWidget::searchChatrooms(const QString &searchString, bool hideOnline, bool hideOffline, bool hideGroups)
|
void FriendListWidget::searchChatrooms(const QString &searchString, bool hideOnline, bool hideOffline, bool hideGroups)
|
||||||
|
|
|
@ -43,7 +43,8 @@ public:
|
||||||
|
|
||||||
void addGroupWidget(GroupWidget *widget);
|
void addGroupWidget(GroupWidget *widget);
|
||||||
|
|
||||||
void addCircleWidget(CircleWidget *widget);
|
void addCircleWidget();
|
||||||
|
void removeCircleWidget(CircleWidget *widget);
|
||||||
|
|
||||||
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, bool hideGroups = false);
|
||||||
|
|
||||||
|
|
|
@ -58,18 +58,23 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
QString dir = Settings::getInstance().getAutoAcceptDir(id);
|
QString dir = Settings::getInstance().getAutoAcceptDir(id);
|
||||||
QMenu menu;
|
QMenu menu;
|
||||||
QMenu* inviteMenu = menu.addMenu(tr("Invite to group","Menu to invite a friend to a groupchat"));
|
QMenu* inviteMenu = menu.addMenu(tr("Invite to group","Menu to invite a friend to a groupchat"));
|
||||||
|
QMenu* circleMenu = menu.addMenu(tr("Move to circle", "Menu to move a friend into a different circle"));
|
||||||
QAction* copyId = menu.addAction(tr("Copy friend ID","Menu to copy the Tox ID of that friend"));
|
QAction* copyId = menu.addAction(tr("Copy friend ID","Menu to copy the Tox ID of that friend"));
|
||||||
QMap<QAction*, Group*> groupActions;
|
QMap<QAction*, Group*> groupActions;
|
||||||
|
|
||||||
for (Group* group : GroupList::getAllGroups())
|
for (Group* group : GroupList::getAllGroups())
|
||||||
{
|
{
|
||||||
QAction* groupAction = inviteMenu->addAction(group->getGroupWidget()->getName());
|
QAction* groupAction = inviteMenu->addAction(group->getGroupWidget()->getName());
|
||||||
groupActions[groupAction] = group;
|
groupActions[groupAction] = group;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (groupActions.isEmpty())
|
if (groupActions.isEmpty())
|
||||||
inviteMenu->setEnabled(false);
|
inviteMenu->setEnabled(false);
|
||||||
|
|
||||||
|
circleMenu->addAction(tr("To new circle"));
|
||||||
|
circleMenu->addAction(tr("Remove from this circle"));
|
||||||
|
circleMenu->addSeparator();
|
||||||
|
|
||||||
QAction* setAlias = menu.addAction(tr("Set alias..."));
|
QAction* setAlias = menu.addAction(tr("Set alias..."));
|
||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
@ -77,7 +82,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
autoAccept->setCheckable(true);
|
autoAccept->setCheckable(true);
|
||||||
autoAccept->setChecked(!dir.isEmpty());
|
autoAccept->setChecked(!dir.isEmpty());
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
|
||||||
QAction* removeFriendAction = menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist"));
|
QAction* removeFriendAction = menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist"));
|
||||||
|
|
||||||
QAction* selectedItem = menu.exec(pos);
|
QAction* selectedItem = menu.exec(pos);
|
||||||
|
@ -105,7 +110,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
||||||
autoAccept->setChecked(false);
|
autoAccept->setChecked(false);
|
||||||
Settings::getInstance().setAutoAcceptDir(id, "");
|
Settings::getInstance().setAutoAcceptDir(id, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autoAccept->isChecked())
|
if (autoAccept->isChecked())
|
||||||
{
|
{
|
||||||
dir = QFileDialog::getExistingDirectory(0, tr("Choose an auto accept directory","popup title"), dir);
|
dir = QFileDialog::getExistingDirectory(0, tr("Choose an auto accept directory","popup title"), dir);
|
||||||
|
|
|
@ -68,8 +68,6 @@
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
#include <tox/tox.h>
|
#include <tox/tox.h>
|
||||||
|
|
||||||
#include "circlewidget.h"
|
|
||||||
|
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
#define IS_ON_DESKTOP_GUI 0
|
#define IS_ON_DESKTOP_GUI 0
|
||||||
#else
|
#else
|
||||||
|
@ -1417,7 +1415,7 @@ void Widget::friendListContextMenu(const QPoint &pos)
|
||||||
|
|
||||||
if (chosenAction == addCircleAction)
|
if (chosenAction == addCircleAction)
|
||||||
{
|
{
|
||||||
contactListWidget->addCircleWidget(new CircleWidget);
|
contactListWidget->addCircleWidget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user