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 <QBoxLayout>
|
||||
#include <QMouseEvent>
|
||||
#include <QLineEdit>
|
||||
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMimeData>
|
||||
#include <QMenu>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "friendlistlayout.h"
|
||||
#include "friendlistwidget.h"
|
||||
|
||||
CircleWidget::CircleWidget(QWidget *parent)
|
||||
CircleWidget::CircleWidget(FriendListWidget *parent)
|
||||
: GenericChatItemWidget(parent)
|
||||
{
|
||||
setStyleSheet(Style::getStylesheet(":/ui/chatroomWidgets/circleWidget.css"));
|
||||
|
@ -58,7 +61,7 @@ CircleWidget::CircleWidget(QWidget *parent)
|
|||
arrowLabel->setStyleSheet("color: white;");
|
||||
topLayout->addWidget(arrowLabel);
|
||||
topLayout->addSpacing(5);
|
||||
QLabel *nameLabel = new QLabel("Circle", container);
|
||||
nameLabel = new QLabel("Circle", container);
|
||||
nameLabel->setObjectName("name");
|
||||
topLayout->addWidget(nameLabel);
|
||||
QFrame *lineFrame = new QFrame(container);
|
||||
|
@ -74,9 +77,9 @@ CircleWidget::CircleWidget(QWidget *parent)
|
|||
|
||||
QHBoxLayout *statusLayout = new QHBoxLayout();
|
||||
|
||||
QLabel *onlineIconLabel = new QLabel(container);
|
||||
onlineIconLabel->setAlignment(Qt::AlignCenter);
|
||||
onlineIconLabel->setPixmap(QPixmap(":img/status/dot_online.svg"));
|
||||
//QLabel *onlineIconLabel = new QLabel(container);
|
||||
//onlineIconLabel->setAlignment(Qt::AlignCenter);
|
||||
//onlineIconLabel->setPixmap(QPixmap(":img/status/dot_online.svg"));
|
||||
onlineLabel = new QLabel("0", container);
|
||||
onlineLabel->setObjectName("status");
|
||||
|
||||
|
@ -86,23 +89,23 @@ CircleWidget::CircleWidget(QWidget *parent)
|
|||
QLabel *awayLabel = new QLabel("0", container);
|
||||
awayLabel->setObjectName("status");*/
|
||||
|
||||
QLabel *offlineIconLabel = new QLabel(container);
|
||||
offlineIconLabel->setAlignment(Qt::AlignCenter);
|
||||
offlineIconLabel->setPixmap(QPixmap(":img/status/dot_offline.svg"));
|
||||
offlineLabel = new QLabel("0", container);
|
||||
offlineLabel->setObjectName("status");
|
||||
//QLabel *offlineIconLabel = new QLabel(container);
|
||||
//offlineIconLabel->setAlignment(Qt::AlignCenter);
|
||||
//offlineIconLabel->setPixmap(QPixmap(":img/status/dot_offline.svg"));
|
||||
//offlineLabel = new QLabel("0", container);
|
||||
//offlineLabel->setObjectName("status");
|
||||
|
||||
statusLayout->addWidget(onlineIconLabel);
|
||||
statusLayout->addSpacing(5);
|
||||
//statusLayout->addWidget(onlineIconLabel);
|
||||
//statusLayout->addSpacing(2);
|
||||
statusLayout->addWidget(onlineLabel);
|
||||
statusLayout->addSpacing(10);
|
||||
//statusLayout->addSpacing(10);
|
||||
//statusLayout->addWidget(awayIconLabel);
|
||||
//statusLayout->addSpacing(5);
|
||||
//statusLayout->addWidget(awayLabel);
|
||||
//statusLayout->addSpacing(10);
|
||||
statusLayout->addWidget(offlineIconLabel);
|
||||
statusLayout->addSpacing(5);
|
||||
statusLayout->addWidget(offlineLabel);
|
||||
//statusLayout->addWidget(offlineIconLabel);
|
||||
//statusLayout->addSpacing(2);
|
||||
//statusLayout->addWidget(offlineLabel);
|
||||
//statusLayout->addStretch();
|
||||
|
||||
//midLayout->addLayout(statusLayout);
|
||||
|
@ -123,7 +126,6 @@ CircleWidget::CircleWidget(QWidget *parent)
|
|||
|
||||
void CircleWidget::addFriendWidget(FriendWidget *w, Status s)
|
||||
{
|
||||
qDebug() << "YOLO COMBO";
|
||||
listLayout->addFriendWidget(w, s);
|
||||
//if (s == Status::Offline)
|
||||
updateOffline();
|
||||
|
@ -151,6 +153,63 @@ void CircleWidget::searchChatrooms(const QString &searchString, bool hideOnline,
|
|||
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)
|
||||
{
|
||||
if (event->button() == Qt::LeftButton)
|
||||
|
@ -204,10 +263,10 @@ void CircleWidget::dropEvent(QDropEvent *event)
|
|||
|
||||
void CircleWidget::updateOnline()
|
||||
{
|
||||
onlineLabel->setText(QString::number(listLayout->friendOnlineCount()));
|
||||
onlineLabel->setText(QString::number(listLayout->friendOnlineCount()) + QStringLiteral(" / ") + QString::number(listLayout->friendOfflineCount()));
|
||||
}
|
||||
|
||||
void CircleWidget::updateOffline()
|
||||
{
|
||||
offlineLabel->setText(QString::number(listLayout->friendOfflineCount()));
|
||||
//offlineLabel->setText(QString::number(listLayout->friendOfflineCount()));
|
||||
}
|
||||
|
|
|
@ -21,14 +21,16 @@
|
|||
class QVBoxLayout;
|
||||
class QHBoxLayout;
|
||||
class QLabel;
|
||||
class FriendListWidget;
|
||||
class FriendListLayout;
|
||||
class FriendWidget;
|
||||
class QLineEdit;
|
||||
|
||||
class CircleWidget : public GenericChatItemWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CircleWidget(QWidget *parent = 0);
|
||||
CircleWidget(FriendListWidget *parent = 0);
|
||||
|
||||
void addFriendWidget(FriendWidget *w, Status s);
|
||||
|
||||
|
@ -39,8 +41,12 @@ public:
|
|||
void updateOnline();
|
||||
void updateOffline();
|
||||
|
||||
void renameCircle();
|
||||
|
||||
protected:
|
||||
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
|
||||
void mousePressEvent(QMouseEvent *event) override;
|
||||
|
||||
void dragEnterEvent(QDragEnterEvent* event) override;
|
||||
|
@ -60,6 +66,7 @@ private:
|
|||
QLabel *onlineLabel;
|
||||
QLabel *offlineLabel;
|
||||
QWidget *container;
|
||||
QLabel *nameLabel;
|
||||
};
|
||||
|
||||
#endif // CIRCLEWIDGET_H
|
||||
|
|
|
@ -90,7 +90,7 @@ int FriendListLayout::friendOnlineCount() const
|
|||
|
||||
int FriendListLayout::friendOfflineCount() const
|
||||
{
|
||||
return friendLayouts[Offline]->count();
|
||||
return friendLayouts[Offline]->count() + friendOnlineCount();
|
||||
}
|
||||
|
||||
template <typename WidgetType>
|
||||
|
|
|
@ -51,9 +51,21 @@ void FriendListWidget::addGroupWidget(GroupWidget *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)
|
||||
|
|
|
@ -43,7 +43,8 @@ public:
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
|||
QString dir = Settings::getInstance().getAutoAcceptDir(id);
|
||||
QMenu menu;
|
||||
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"));
|
||||
QMap<QAction*, Group*> groupActions;
|
||||
|
||||
|
@ -70,6 +71,10 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
|||
if (groupActions.isEmpty())
|
||||
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..."));
|
||||
|
||||
menu.addSeparator();
|
||||
|
|
|
@ -68,8 +68,6 @@
|
|||
#include <QProcess>
|
||||
#include <tox/tox.h>
|
||||
|
||||
#include "circlewidget.h"
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#define IS_ON_DESKTOP_GUI 0
|
||||
#else
|
||||
|
@ -1417,7 +1415,7 @@ void Widget::friendListContextMenu(const QPoint &pos)
|
|||
|
||||
if (chosenAction == addCircleAction)
|
||||
{
|
||||
contactListWidget->addCircleWidget(new CircleWidget);
|
||||
contactListWidget->addCircleWidget();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user