mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(drag&drop): Remove FriendWidget dependency
This commit is contained in:
parent
89138bb52b
commit
2da9de096f
|
@ -137,7 +137,10 @@ void CategoryWidget::removeFriendWidget(FriendWidget* w, Status s)
|
|||
|
||||
void CategoryWidget::updateStatus()
|
||||
{
|
||||
statusLabel->setText(QString::number(listLayout->friendOnlineCount()) + QStringLiteral(" / ") + QString::number(listLayout->friendTotalCount()));
|
||||
QString online = QString::number(listLayout->friendOnlineCount());
|
||||
QString offline = QString::number(listLayout->friendTotalCount());
|
||||
QString text = online + QStringLiteral(" / ") + offline;
|
||||
statusLabel->setText(text);
|
||||
}
|
||||
|
||||
bool CategoryWidget::hasChatrooms() const
|
||||
|
|
|
@ -17,23 +17,26 @@
|
|||
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "circlewidget.h"
|
||||
#include "friendwidget.h"
|
||||
#include "friendlistwidget.h"
|
||||
#include "tool/croppinglabel.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "src/friend.h"
|
||||
#include "src/widget/contentdialog.h"
|
||||
#include "widget.h"
|
||||
#include <QVariant>
|
||||
#include <QBoxLayout>
|
||||
#include <QMouseEvent>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMimeData>
|
||||
#include <QMenu>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include "circlewidget.h"
|
||||
#include "contentdialog.h"
|
||||
#include "friendwidget.h"
|
||||
#include "friendlistwidget.h"
|
||||
#include "tool/croppinglabel.h"
|
||||
#include "widget.h"
|
||||
|
||||
#include "src/friend.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "src/persistence/settings.h"
|
||||
|
||||
QHash<int, CircleWidget*> CircleWidget::circleList;
|
||||
|
||||
CircleWidget::CircleWidget(FriendListWidget* parent, int id)
|
||||
|
@ -150,7 +153,9 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event)
|
|||
|
||||
void CircleWidget::dragEnterEvent(QDragEnterEvent* event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat("friend"))
|
||||
ToxId toxId(event->mimeData()->text());
|
||||
Friend *f = FriendList::findFriend(toxId);
|
||||
if (f != nullptr)
|
||||
event->acceptProposedAction();
|
||||
|
||||
setContainerAttribute(Qt::WA_UnderMouse, true); // Simulate hover.
|
||||
|
@ -163,31 +168,34 @@ void CircleWidget::dragLeaveEvent(QDragLeaveEvent* )
|
|||
|
||||
void CircleWidget::dropEvent(QDropEvent* event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat("friend"))
|
||||
setExpanded(true, false);
|
||||
|
||||
// Check, that the element is dropped from qTox
|
||||
QObject *o = event->source();
|
||||
FriendWidget *widget = qobject_cast<FriendWidget*>(o);
|
||||
if (!widget)
|
||||
return;
|
||||
|
||||
// Check, that the user has a friend with the same ToxId
|
||||
ToxId toxId(event->mimeData()->text());
|
||||
Friend *f = FriendList::findFriend(toxId);
|
||||
if (!f)
|
||||
return;
|
||||
|
||||
// Save CircleWidget before changing the Id
|
||||
int circleId = Settings::getInstance().getFriendCircleID(toxId);
|
||||
CircleWidget* circleWidget = getFromID(circleId);
|
||||
|
||||
addFriendWidget(widget, f->getStatus());
|
||||
Settings::getInstance().savePersonal();
|
||||
|
||||
if (circleWidget != nullptr)
|
||||
{
|
||||
setExpanded(true, false);
|
||||
|
||||
int friendId = event->mimeData()->data("friend").toInt();
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
assert(f != nullptr);
|
||||
|
||||
FriendWidget* widget = f->getFriendWidget();
|
||||
assert(widget != nullptr);
|
||||
|
||||
// Update old circle after moved.
|
||||
CircleWidget* circleWidget = getFromID(Settings::getInstance().getFriendCircleID(f->getToxId()));
|
||||
|
||||
addFriendWidget(widget, f->getStatus());
|
||||
Settings::getInstance().savePersonal();
|
||||
|
||||
if (circleWidget != nullptr)
|
||||
{
|
||||
circleWidget->updateStatus();
|
||||
Widget::getInstance()->searchCircle(circleWidget);
|
||||
}
|
||||
|
||||
setContainerAttribute(Qt::WA_UnderMouse, false);
|
||||
circleWidget->updateStatus();
|
||||
Widget::getInstance()->searchCircle(circleWidget);
|
||||
}
|
||||
|
||||
setContainerAttribute(Qt::WA_UnderMouse, false);
|
||||
}
|
||||
|
||||
void CircleWidget::onSetName()
|
||||
|
@ -203,7 +211,9 @@ void CircleWidget::onExpand()
|
|||
|
||||
void CircleWidget::onAddFriendWidget(FriendWidget* w)
|
||||
{
|
||||
Settings::getInstance().setFriendCircleID(FriendList::findFriend(w->friendId)->getToxId(), id);
|
||||
Friend* f = FriendList::findFriend(w->friendId);
|
||||
ToxId toxId = f->getToxId();
|
||||
Settings::getInstance().setFriendCircleID(toxId, id);
|
||||
}
|
||||
|
||||
void CircleWidget::updateID(int index)
|
||||
|
|
|
@ -543,20 +543,34 @@ bool ContentDialog::event(QEvent* event)
|
|||
|
||||
void ContentDialog::dragEnterEvent(QDragEnterEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat("friend"))
|
||||
QObject *o = event->source();
|
||||
FriendWidget *frnd = qobject_cast<FriendWidget*>(o);
|
||||
GroupWidget *group = qobject_cast<GroupWidget*>(o);
|
||||
if (frnd)
|
||||
{
|
||||
int friendId = event->mimeData()->data("friend").toInt();
|
||||
ToxId toxId(event->mimeData()->text());
|
||||
Friend *contact = FriendList::findFriend(toxId);
|
||||
if (!contact)
|
||||
return;
|
||||
|
||||
int friendId = contact->getFriendID();
|
||||
auto iter = friendList.find(friendId);
|
||||
|
||||
// If friend is already in a dialog then you can't drop friend where it already is.
|
||||
if (iter == friendList.end() || std::get<0>(iter.value()) != this)
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
else if (event->mimeData()->hasFormat("group"))
|
||||
else if (group)
|
||||
{
|
||||
int groupId = event->mimeData()->data("group").toInt();
|
||||
auto iter = groupList.find(groupId);
|
||||
if (!event->mimeData()->hasFormat("groupId"))
|
||||
return;
|
||||
|
||||
int groupId = event->mimeData()->data("groupId").toInt();
|
||||
Group *contact = GroupList::findGroup(groupId);
|
||||
if (!contact)
|
||||
return;
|
||||
|
||||
auto iter = groupList.find(groupId);
|
||||
if (iter == groupList.end() || std::get<0>(iter.value()) != this)
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
@ -564,27 +578,38 @@ void ContentDialog::dragEnterEvent(QDragEnterEvent *event)
|
|||
|
||||
void ContentDialog::dropEvent(QDropEvent *event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat("friend"))
|
||||
QObject *o = event->source();
|
||||
FriendWidget *frnd = qobject_cast<FriendWidget*>(o);
|
||||
GroupWidget *group = qobject_cast<GroupWidget*>(o);
|
||||
if (frnd)
|
||||
{
|
||||
int friendId = event->mimeData()->data("friend").toInt();
|
||||
auto iter = friendList.find(friendId);
|
||||
ToxId toxId(event->mimeData()->text());
|
||||
Friend *contact = FriendList::findFriend(toxId);
|
||||
if (!contact)
|
||||
return;
|
||||
|
||||
int friendId = contact->getFriendID();
|
||||
auto iter = friendList.find(friendId);
|
||||
if (iter != friendList.end())
|
||||
std::get<0>(iter.value())->removeFriend(friendId);
|
||||
|
||||
Friend* contact = FriendList::findFriend(friendId);
|
||||
Widget::getInstance()->addFriendDialog(contact, this);
|
||||
ensureSplitterVisible();
|
||||
}
|
||||
else if (event->mimeData()->hasFormat("group"))
|
||||
else if (group)
|
||||
{
|
||||
int groupId = event->mimeData()->data("group").toInt();
|
||||
auto iter = friendList.find(groupId);
|
||||
if (!event->mimeData()->hasFormat("groupId"))
|
||||
return;
|
||||
|
||||
int groupId = event->mimeData()->data("groupId").toInt();
|
||||
Group *contact = GroupList::findGroup(groupId);
|
||||
if (!contact)
|
||||
return;
|
||||
|
||||
auto iter = friendList.find(groupId);
|
||||
if (iter != friendList.end())
|
||||
std::get<0>(iter.value())->removeGroup(groupId);
|
||||
|
||||
Group* contact = GroupList::findGroup(groupId);
|
||||
Widget::getInstance()->addGroupDialog(contact, this);
|
||||
ensureSplitterVisible();
|
||||
}
|
||||
|
|
|
@ -18,10 +18,16 @@
|
|||
*/
|
||||
|
||||
#include "groupchatform.h"
|
||||
|
||||
#include <QDragEnterEvent>
|
||||
#include <QMimeData>
|
||||
#include <QTimer>
|
||||
|
||||
#include "tabcompleter.h"
|
||||
#include "src/group.h"
|
||||
#include "src/friend.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "src/widget/groupwidget.h"
|
||||
#include "src/widget/tool/chattextedit.h"
|
||||
#include "src/widget/tool/croppinglabel.h"
|
||||
#include "src/widget/maskablepixmapwidget.h"
|
||||
#include "src/core/core.h"
|
||||
|
@ -31,12 +37,6 @@
|
|||
#include "src/widget/translator.h"
|
||||
#include "src/widget/form/chatform.h"
|
||||
#include "src/video/groupnetcamview.h"
|
||||
#include <QDebug>
|
||||
#include <QTimer>
|
||||
#include <QPushButton>
|
||||
#include <QMimeData>
|
||||
#include <QDragEnterEvent>
|
||||
#include <QtAlgorithms>
|
||||
|
||||
/**
|
||||
* @var QList<QLabel*> GroupChatForm::peerLabels
|
||||
|
@ -279,17 +279,22 @@ void GroupChatForm::peerAudioPlaying(int peer)
|
|||
|
||||
void GroupChatForm::dragEnterEvent(QDragEnterEvent *ev)
|
||||
{
|
||||
if (ev->mimeData()->hasFormat("friend"))
|
||||
ToxId toxId = ToxId(ev->mimeData()->text());
|
||||
Friend *frnd = FriendList::findFriend(toxId);
|
||||
if (frnd)
|
||||
ev->acceptProposedAction();
|
||||
}
|
||||
|
||||
void GroupChatForm::dropEvent(QDropEvent *ev)
|
||||
{
|
||||
if (ev->mimeData()->hasFormat("friend"))
|
||||
{
|
||||
int friendId = ev->mimeData()->data("friend").toInt();
|
||||
Core::getInstance()->groupInviteFriend(friendId, group->getGroupId());
|
||||
}
|
||||
ToxId toxId = ToxId(ev->mimeData()->text());
|
||||
Friend *frnd = FriendList::findFriend(toxId);
|
||||
if (!frnd)
|
||||
return;
|
||||
|
||||
int friendId = frnd->getFriendID();
|
||||
int groupId = group->getGroupId();
|
||||
Core::getInstance()->groupInviteFriend(friendId, groupId);
|
||||
}
|
||||
|
||||
void GroupChatForm::onMicMuteToggle()
|
||||
|
|
|
@ -607,29 +607,34 @@ void FriendListWidget::cycleContacts(GenericChatroomWidget* activeChatroomWidget
|
|||
|
||||
void FriendListWidget::dragEnterEvent(QDragEnterEvent* event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat("friend"))
|
||||
ToxId toxId(event->mimeData()->text());
|
||||
Friend *frnd = FriendList::findFriend(toxId);
|
||||
if (frnd)
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
||||
void FriendListWidget::dropEvent(QDropEvent* event)
|
||||
{
|
||||
if (event->mimeData()->hasFormat("friend"))
|
||||
{
|
||||
int friendId = event->mimeData()->data("friend").toInt();
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
assert(f != nullptr);
|
||||
// Check, that the element is dropped from qTox
|
||||
QObject *o = event->source();
|
||||
FriendWidget *widget = qobject_cast<FriendWidget*>(o);
|
||||
if (!widget)
|
||||
return;
|
||||
|
||||
FriendWidget* widget = f->getFriendWidget();
|
||||
assert(widget != nullptr);
|
||||
// Check, that the user has a friend with the same ToxId
|
||||
ToxId toxId(event->mimeData()->text());
|
||||
Friend *f = FriendList::findFriend(toxId);
|
||||
if (!f)
|
||||
return;
|
||||
|
||||
// Update old circle after moved.
|
||||
CircleWidget* circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(f->getToxId()));
|
||||
// Save CircleWidget before changing the Id
|
||||
int circleId = Settings::getInstance().getFriendCircleID(f->getToxId());
|
||||
CircleWidget* circleWidget = CircleWidget::getFromID(circleId);
|
||||
|
||||
moveWidget(widget, f->getStatus(), true);
|
||||
moveWidget(widget, f->getStatus(), true);
|
||||
|
||||
if (circleWidget != nullptr)
|
||||
circleWidget->updateStatus();
|
||||
}
|
||||
if (circleWidget)
|
||||
circleWidget->updateStatus();
|
||||
}
|
||||
|
||||
void FriendListWidget::dayTimeout()
|
||||
|
|
|
@ -409,13 +409,12 @@ void FriendWidget::mouseMoveEvent(QMouseEvent *ev)
|
|||
|
||||
if ((dragStartPos - ev->pos()).manhattanLength() > QApplication::startDragDistance())
|
||||
{
|
||||
QDrag* drag = new QDrag(this);
|
||||
QMimeData* mdata = new QMimeData;
|
||||
mdata->setData("friend", QString::number(friendId).toLatin1());
|
||||
mdata->setText(getFriend()->getToxId().toString());
|
||||
|
||||
QDrag* drag = new QDrag(this);
|
||||
drag->setMimeData(mdata);
|
||||
drag->setPixmap(avatar->getPixmap());
|
||||
|
||||
drag->exec(Qt::CopyAction | Qt::MoveAction);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,16 +18,7 @@
|
|||
*/
|
||||
|
||||
#include "groupwidget.h"
|
||||
#include "maskablepixmapwidget.h"
|
||||
#include "contentdialog.h"
|
||||
#include "src/grouplist.h"
|
||||
#include "src/group.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "form/groupchatform.h"
|
||||
#include "src/widget/style.h"
|
||||
#include "src/core/core.h"
|
||||
#include "tool/croppinglabel.h"
|
||||
#include "src/widget/translator.h"
|
||||
|
||||
#include <QPalette>
|
||||
#include <QMenu>
|
||||
#include <QContextMenuEvent>
|
||||
|
@ -36,6 +27,20 @@
|
|||
#include <QApplication>
|
||||
#include <QDrag>
|
||||
|
||||
#include "contentdialog.h"
|
||||
#include "form/groupchatform.h"
|
||||
#include "maskablepixmapwidget.h"
|
||||
#include "src/core/core.h"
|
||||
#include "src/friend.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "src/group.h"
|
||||
#include "src/grouplist.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/widget/friendwidget.h"
|
||||
#include "src/widget/style.h"
|
||||
#include "src/widget/translator.h"
|
||||
#include "tool/croppinglabel.h"
|
||||
|
||||
GroupWidget::GroupWidget(int GroupId, QString Name)
|
||||
: groupId{GroupId}
|
||||
{
|
||||
|
@ -137,13 +142,12 @@ void GroupWidget::mouseMoveEvent(QMouseEvent *ev)
|
|||
|
||||
if ((dragStartPos - ev->pos()).manhattanLength() > QApplication::startDragDistance())
|
||||
{
|
||||
QDrag* drag = new QDrag(this);
|
||||
QMimeData* mdata = new QMimeData;
|
||||
mdata->setData("group", QString::number(groupId).toLatin1());
|
||||
mdata->setText(getGroup()->getName());
|
||||
|
||||
QDrag* drag = new QDrag(this);
|
||||
drag->setMimeData(mdata);
|
||||
drag->setPixmap(avatar->getPixmap());
|
||||
|
||||
drag->exec(Qt::CopyAction | Qt::MoveAction);
|
||||
}
|
||||
}
|
||||
|
@ -231,7 +235,9 @@ void GroupWidget::resetEventFlags()
|
|||
|
||||
void GroupWidget::dragEnterEvent(QDragEnterEvent *ev)
|
||||
{
|
||||
if (ev->mimeData()->hasFormat("friend"))
|
||||
ToxId toxId = ToxId(ev->mimeData()->text());
|
||||
Friend *frnd = FriendList::findFriend(toxId);
|
||||
if (frnd)
|
||||
ev->acceptProposedAction();
|
||||
|
||||
if (!active)
|
||||
|
@ -246,14 +252,16 @@ void GroupWidget::dragLeaveEvent(QDragLeaveEvent *)
|
|||
|
||||
void GroupWidget::dropEvent(QDropEvent *ev)
|
||||
{
|
||||
if (ev->mimeData()->hasFormat("friend"))
|
||||
{
|
||||
int friendId = ev->mimeData()->data("friend").toInt();
|
||||
Core::getInstance()->groupInviteFriend(friendId, groupId);
|
||||
ToxId toxId = ToxId(ev->mimeData()->text());
|
||||
Friend *frnd = FriendList::findFriend(toxId);
|
||||
if (!frnd)
|
||||
return;
|
||||
|
||||
if (!active)
|
||||
setBackgroundRole(QPalette::Window);
|
||||
}
|
||||
int friendId = frnd->getFriendID();
|
||||
Core::getInstance()->groupInviteFriend(friendId, groupId);
|
||||
|
||||
if (!active)
|
||||
setBackgroundRole(QPalette::Window);
|
||||
}
|
||||
|
||||
void GroupWidget::setName(const QString& name)
|
||||
|
|
Loading…
Reference in New Issue
Block a user