From ff37812a5353f9324e07fb22ae764ff0aa93bfb0 Mon Sep 17 00:00:00 2001 From: Daniel Hrabovcak Date: Thu, 28 May 2015 18:36:21 -0400 Subject: [PATCH] Contact grouping deleting and renaming --- src/widget/circlewidget.cpp | 97 ++++++++++++++++++++++++++------- src/widget/circlewidget.h | 9 ++- src/widget/friendlistlayout.cpp | 2 +- src/widget/friendlistwidget.cpp | 16 +++++- src/widget/friendlistwidget.h | 3 +- src/widget/friendwidget.cpp | 15 +++-- src/widget/widget.cpp | 4 +- 7 files changed, 114 insertions(+), 32 deletions(-) diff --git a/src/widget/circlewidget.cpp b/src/widget/circlewidget.cpp index 71de7fc44..e249cbc96 100644 --- a/src/widget/circlewidget.cpp +++ b/src/widget/circlewidget.cpp @@ -22,17 +22,20 @@ #include #include #include +#include #include #include +#include #include #include #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(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(parentWidget()); + while (listLayout->friendLayouts[Online]->count() != 0) + { + QWidget *getWidget = listLayout->friendLayouts[Online]->takeAt(0)->widget(); + qDebug() << getWidget; + assert(getWidget != nullptr); + + FriendWidget *friendWidget = dynamic_cast(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(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())); } diff --git a/src/widget/circlewidget.h b/src/widget/circlewidget.h index f59ba502e..6ee2c0ecd 100644 --- a/src/widget/circlewidget.h +++ b/src/widget/circlewidget.h @@ -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 diff --git a/src/widget/friendlistlayout.cpp b/src/widget/friendlistlayout.cpp index 19bc22296..4fa84d445 100644 --- a/src/widget/friendlistlayout.cpp +++ b/src/widget/friendlistlayout.cpp @@ -90,7 +90,7 @@ int FriendListLayout::friendOnlineCount() const int FriendListLayout::friendOfflineCount() const { - return friendLayouts[Offline]->count(); + return friendLayouts[Offline]->count() + friendOnlineCount(); } template diff --git a/src/widget/friendlistwidget.cpp b/src/widget/friendlistwidget.cpp index ed3240ca2..e24890460 100644 --- a/src/widget/friendlistwidget.cpp +++ b/src/widget/friendlistwidget.cpp @@ -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) diff --git a/src/widget/friendlistwidget.h b/src/widget/friendlistwidget.h index d1fa148ac..e02e33b0d 100644 --- a/src/widget/friendlistwidget.h +++ b/src/widget/friendlistwidget.h @@ -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); diff --git a/src/widget/friendwidget.cpp b/src/widget/friendwidget.cpp index 7540b91e4..9e2a31dea 100644 --- a/src/widget/friendwidget.cpp +++ b/src/widget/friendwidget.cpp @@ -58,18 +58,23 @@ 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 groupActions; - + for (Group* group : GroupList::getAllGroups()) { QAction* groupAction = inviteMenu->addAction(group->getGroupWidget()->getName()); groupActions[groupAction] = group; } - + 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(); @@ -77,7 +82,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event) autoAccept->setCheckable(true); autoAccept->setChecked(!dir.isEmpty()); menu.addSeparator(); - + QAction* removeFriendAction = menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist")); QAction* selectedItem = menu.exec(pos); @@ -105,7 +110,7 @@ void FriendWidget::contextMenuEvent(QContextMenuEvent * event) autoAccept->setChecked(false); Settings::getInstance().setAutoAcceptDir(id, ""); } - + if (autoAccept->isChecked()) { dir = QFileDialog::getExistingDirectory(0, tr("Choose an auto accept directory","popup title"), dir); diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 4d163c497..2cc4cbe9e 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -68,8 +68,6 @@ #include #include -#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(); } }