2014-07-07 00:19:45 +08:00
|
|
|
/*
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
qTox is libre software: you can redistribute it and/or modify
|
2014-07-07 00:19:45 +08:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
qTox is distributed in the hope that it will be useful,
|
2014-07-07 00:19:45 +08:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-06-06 09:40:08 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2014-07-07 00:19:45 +08:00
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
2014-07-07 00:19:45 +08:00
|
|
|
*/
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
#include "friendwidget.h"
|
2014-10-08 12:26:25 +08:00
|
|
|
#include "src/group.h"
|
|
|
|
#include "src/grouplist.h"
|
2014-06-28 16:53:38 +08:00
|
|
|
#include "groupwidget.h"
|
2015-06-10 01:40:45 +08:00
|
|
|
#include "circlewidget.h"
|
|
|
|
#include "friendlistwidget.h"
|
2014-10-08 12:26:25 +08:00
|
|
|
#include "src/friendlist.h"
|
|
|
|
#include "src/friend.h"
|
2015-04-24 08:32:09 +08:00
|
|
|
#include "src/core/core.h"
|
2014-10-08 12:26:25 +08:00
|
|
|
#include "form/chatform.h"
|
|
|
|
#include "maskablepixmapwidget.h"
|
2015-06-19 22:58:48 +08:00
|
|
|
#include "contentdialog.h"
|
2015-06-06 07:44:47 +08:00
|
|
|
#include "src/widget/tool/croppinglabel.h"
|
|
|
|
#include "src/widget/style.h"
|
|
|
|
#include "src/persistence/settings.h"
|
2014-11-08 00:50:39 +08:00
|
|
|
#include "src/widget/widget.h"
|
2014-06-25 04:11:11 +08:00
|
|
|
#include <QContextMenuEvent>
|
|
|
|
#include <QMenu>
|
2014-09-26 00:03:25 +08:00
|
|
|
#include <QDrag>
|
|
|
|
#include <QMimeData>
|
|
|
|
#include <QApplication>
|
2014-09-26 22:39:29 +08:00
|
|
|
#include <QBitmap>
|
2014-10-18 11:59:59 +08:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QDebug>
|
2014-11-08 00:02:10 +08:00
|
|
|
#include <QInputDialog>
|
2015-06-24 02:58:30 +08:00
|
|
|
#include <QCollator>
|
2015-05-29 21:26:43 +08:00
|
|
|
#include <cassert>
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
FriendWidget::FriendWidget(int FriendId, QString id)
|
2014-10-01 02:10:42 +08:00
|
|
|
: friendId(FriendId)
|
|
|
|
, isDefaultAvatar{true}
|
2015-01-07 20:16:09 +08:00
|
|
|
, historyLoaded{false}
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
2015-02-12 20:18:04 +08:00
|
|
|
avatar->setPixmap(QPixmap(":img/contact.svg"), Qt::transparent);
|
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_offline.svg"));
|
2015-03-18 07:45:57 +08:00
|
|
|
statusPic.setMargin(3);
|
2014-10-01 17:13:49 +08:00
|
|
|
nameLabel->setText(id);
|
2015-02-27 22:05:03 +08:00
|
|
|
nameLabel->setTextFormat(Qt::PlainText);
|
2015-06-02 02:39:40 +08:00
|
|
|
connect(nameLabel, &CroppingLabel::editFinished, this, &FriendWidget::setAlias);
|
2015-02-27 22:05:03 +08:00
|
|
|
statusMessageLabel->setTextFormat(Qt::PlainText);
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
|
|
|
{
|
2015-06-11 00:11:50 +08:00
|
|
|
if (!active)
|
|
|
|
setBackgroundRole(QPalette::Highlight);
|
|
|
|
|
|
|
|
installEventFilter(this); // Disable leave event.
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
QPoint pos = event->globalPos();
|
2015-05-24 02:58:41 +08:00
|
|
|
ToxId id = FriendList::findFriend(friendId)->getToxId();
|
2014-10-18 11:59:59 +08:00
|
|
|
QString dir = Settings::getInstance().getAutoAcceptDir(id);
|
2014-06-25 04:11:11 +08:00
|
|
|
QMenu menu;
|
2015-06-23 02:01:50 +08:00
|
|
|
QAction* openChatWindow = nullptr;
|
|
|
|
QAction* removeChatWindow = nullptr;
|
|
|
|
|
2015-06-27 04:13:20 +08:00
|
|
|
ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId);
|
|
|
|
bool notAlone = contentDialog != nullptr && contentDialog->chatroomWidgetCount() > 1;
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2015-06-27 04:13:20 +08:00
|
|
|
if (contentDialog == nullptr || notAlone)
|
|
|
|
openChatWindow = menu.addAction(tr("Open chat in new window"));
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2015-06-27 04:13:20 +08:00
|
|
|
if (contentDialog->hasFriendWidget(friendId, this))
|
|
|
|
removeChatWindow = menu.addAction(tr("Remove chat from this window"));
|
2015-06-23 02:01:50 +08:00
|
|
|
|
2015-06-19 22:58:48 +08:00
|
|
|
menu.addSeparator();
|
2014-10-20 12:25:52 +08:00
|
|
|
QMenu* inviteMenu = menu.addMenu(tr("Invite to group","Menu to invite a friend to a groupchat"));
|
2014-06-28 16:53:38 +08:00
|
|
|
QMap<QAction*, Group*> groupActions;
|
2015-05-29 06:36:21 +08:00
|
|
|
|
2014-11-20 17:13:13 +08:00
|
|
|
for (Group* group : GroupList::getAllGroups())
|
2014-06-28 16:53:38 +08:00
|
|
|
{
|
2015-08-31 04:23:05 +08:00
|
|
|
QAction* groupAction = inviteMenu->addAction(group->getGroupWidget()->getName());
|
2014-06-28 16:53:38 +08:00
|
|
|
groupActions[groupAction] = group;
|
|
|
|
}
|
2015-05-29 06:36:21 +08:00
|
|
|
|
2015-08-31 04:23:05 +08:00
|
|
|
if (groupActions.isEmpty())
|
|
|
|
inviteMenu->setEnabled(false);
|
|
|
|
|
2015-06-13 02:52:05 +08:00
|
|
|
int circleId = Settings::getInstance().getFriendCircleID(FriendList::findFriend(friendId)->getToxId());
|
|
|
|
CircleWidget *circleWidget = CircleWidget::getFromID(circleId);
|
2015-05-29 21:26:43 +08:00
|
|
|
|
2015-06-13 02:52:05 +08:00
|
|
|
QMenu* circleMenu = nullptr;
|
|
|
|
QAction* newCircleAction = nullptr;
|
|
|
|
QAction *removeCircleAction = nullptr;
|
|
|
|
QMap<QAction*, int> circleActions;
|
2015-05-29 06:36:21 +08:00
|
|
|
|
2015-05-29 21:26:43 +08:00
|
|
|
FriendListWidget *friendList;
|
2015-06-13 02:52:05 +08:00
|
|
|
|
2015-05-29 21:26:43 +08:00
|
|
|
if (circleWidget == nullptr)
|
2015-07-20 20:13:51 +08:00
|
|
|
friendList = dynamic_cast<FriendListWidget*>(FriendList::findFriend(friendId)->getFriendWidget()->parentWidget());
|
2015-05-29 21:26:43 +08:00
|
|
|
else
|
|
|
|
friendList = dynamic_cast<FriendListWidget*>(circleWidget->parentWidget());
|
|
|
|
|
2015-06-24 02:58:30 +08:00
|
|
|
circleMenu = menu.addMenu(tr("Move to circle...", "Menu to move a friend into a different circle"));
|
2015-05-29 21:26:43 +08:00
|
|
|
|
2015-06-24 02:58:30 +08:00
|
|
|
newCircleAction = circleMenu->addAction(tr("To new circle"));
|
2015-06-18 03:45:03 +08:00
|
|
|
|
2015-06-24 02:58:30 +08:00
|
|
|
if (circleId != -1)
|
|
|
|
removeCircleAction = circleMenu->addAction(tr("Remove from circle '%1'").arg(Settings::getInstance().getCircleName(circleId)));
|
2015-06-18 03:45:03 +08:00
|
|
|
|
2015-06-24 02:58:30 +08:00
|
|
|
circleMenu->addSeparator();
|
2015-06-13 02:52:05 +08:00
|
|
|
|
2015-06-24 02:58:30 +08:00
|
|
|
QList<QAction*> circleActionList;
|
|
|
|
|
|
|
|
for (int i = 0; i < Settings::getInstance().getCircleCount(); ++i)
|
|
|
|
{
|
|
|
|
if (i != circleId)
|
2015-05-31 03:10:43 +08:00
|
|
|
{
|
2015-06-24 02:58:30 +08:00
|
|
|
circleActionList.push_back(new QAction(tr("Move to circle \"%1\"").arg(Settings::getInstance().getCircleName(i)), circleMenu));
|
|
|
|
circleActions[circleActionList.back()] = i;
|
2015-05-31 03:10:43 +08:00
|
|
|
}
|
2015-06-24 02:58:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::sort(circleActionList.begin(), circleActionList.end(), [](const QAction* lhs, const QAction* rhs) -> bool
|
|
|
|
{
|
|
|
|
QCollator collator;
|
|
|
|
collator.setNumericMode(true);
|
|
|
|
return collator.compare(lhs->text(), rhs->text()) < 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
circleMenu->addActions(circleActionList);
|
2015-05-29 21:26:43 +08:00
|
|
|
|
2014-11-08 00:02:10 +08:00
|
|
|
QAction* setAlias = menu.addAction(tr("Set alias..."));
|
|
|
|
|
2014-10-20 12:25:52 +08:00
|
|
|
menu.addSeparator();
|
2014-10-18 11:59:59 +08:00
|
|
|
QAction* autoAccept = menu.addAction(tr("Auto accept files from this friend", "context menu entry"));
|
2014-11-06 06:34:28 +08:00
|
|
|
autoAccept->setCheckable(true);
|
|
|
|
autoAccept->setChecked(!dir.isEmpty());
|
2014-07-02 05:58:26 +08:00
|
|
|
menu.addSeparator();
|
2015-05-29 06:36:21 +08:00
|
|
|
|
2015-07-03 02:38:18 +08:00
|
|
|
QAction* removeFriendAction = nullptr;
|
|
|
|
|
|
|
|
if (contentDialog == nullptr || !contentDialog->hasFriendWidget(friendId, this))
|
|
|
|
removeFriendAction = menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist"));
|
2014-06-25 04:11:11 +08:00
|
|
|
|
|
|
|
QAction* selectedItem = menu.exec(pos);
|
2015-06-11 00:11:50 +08:00
|
|
|
|
|
|
|
removeEventFilter(this);
|
|
|
|
|
|
|
|
if (!active)
|
|
|
|
setBackgroundRole(QPalette::Window);
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
if (selectedItem)
|
|
|
|
{
|
2015-09-15 23:58:46 +08:00
|
|
|
if (selectedItem == setAlias)
|
2014-11-08 00:02:10 +08:00
|
|
|
{
|
2015-06-11 00:11:50 +08:00
|
|
|
nameLabel->editBegin();
|
2014-07-02 05:50:07 +08:00
|
|
|
}
|
2014-07-04 22:41:29 +08:00
|
|
|
else if (selectedItem == removeFriendAction)
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
|
|
|
emit removeFriend(friendId);
|
|
|
|
return;
|
|
|
|
}
|
2015-06-23 02:01:50 +08:00
|
|
|
else if (selectedItem == openChatWindow)
|
|
|
|
{
|
|
|
|
emit chatroomWidgetClicked(this, true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (selectedItem == removeChatWindow)
|
|
|
|
{
|
|
|
|
ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId);
|
|
|
|
contentDialog->removeFriend(friendId);
|
|
|
|
return;
|
|
|
|
}
|
2014-10-18 11:59:59 +08:00
|
|
|
else if (selectedItem == autoAccept)
|
|
|
|
{
|
2014-11-06 06:34:28 +08:00
|
|
|
if (!autoAccept->isChecked())
|
|
|
|
{
|
|
|
|
qDebug() << "not checked";
|
2014-10-18 11:59:59 +08:00
|
|
|
dir = QDir::homePath();
|
2014-11-06 06:34:28 +08:00
|
|
|
autoAccept->setChecked(false);
|
|
|
|
Settings::getInstance().setAutoAcceptDir(id, "");
|
|
|
|
}
|
2015-05-29 06:36:21 +08:00
|
|
|
|
2014-11-06 06:34:28 +08:00
|
|
|
if (autoAccept->isChecked())
|
2014-10-18 11:59:59 +08:00
|
|
|
{
|
2014-11-06 06:34:28 +08:00
|
|
|
dir = QFileDialog::getExistingDirectory(0, tr("Choose an auto accept directory","popup title"), dir);
|
|
|
|
autoAccept->setChecked(true);
|
2015-05-11 20:54:03 +08:00
|
|
|
qDebug() << "setting auto accept dir for" << friendId << "to" << dir;
|
2014-10-18 11:59:59 +08:00
|
|
|
Settings::getInstance().setAutoAcceptDir(id, dir);
|
|
|
|
}
|
|
|
|
}
|
2015-05-29 21:26:43 +08:00
|
|
|
else if (selectedItem == newCircleAction)
|
|
|
|
{
|
2015-06-03 21:51:23 +08:00
|
|
|
if (circleWidget != nullptr)
|
|
|
|
circleWidget->updateStatus();
|
|
|
|
|
2015-06-13 02:52:05 +08:00
|
|
|
if (friendList != nullptr)
|
2015-07-20 20:13:51 +08:00
|
|
|
friendList->addCircleWidget(FriendList::findFriend(friendId)->getFriendWidget());
|
2015-06-13 02:52:05 +08:00
|
|
|
else
|
|
|
|
Settings::getInstance().setFriendCircleID(id, Settings::getInstance().addCircle());
|
2015-05-29 21:26:43 +08:00
|
|
|
}
|
2014-06-28 16:53:38 +08:00
|
|
|
else if (groupActions.contains(selectedItem))
|
|
|
|
{
|
|
|
|
Group* group = groupActions[selectedItem];
|
2014-11-23 23:22:29 +08:00
|
|
|
Core::getInstance()->groupInviteFriend(friendId, group->getGroupId());
|
2014-06-28 16:53:38 +08:00
|
|
|
}
|
2015-05-29 21:26:43 +08:00
|
|
|
else if (removeCircleAction != nullptr && selectedItem == removeCircleAction)
|
|
|
|
{
|
2015-06-13 02:52:05 +08:00
|
|
|
if (friendList != nullptr)
|
2015-07-20 20:13:51 +08:00
|
|
|
friendList->moveWidget(FriendList::findFriend(friendId)->getFriendWidget(), FriendList::findFriend(friendId)->getStatus(), true);
|
2015-06-13 02:52:05 +08:00
|
|
|
else
|
|
|
|
Settings::getInstance().setFriendCircleID(id, -1);
|
|
|
|
|
|
|
|
if (circleWidget)
|
|
|
|
{
|
|
|
|
circleWidget->updateStatus();
|
|
|
|
Widget::getInstance()->searchCircle(circleWidget);
|
|
|
|
}
|
2015-05-29 21:26:43 +08:00
|
|
|
}
|
|
|
|
else if (circleActions.contains(selectedItem))
|
|
|
|
{
|
2015-06-13 02:52:05 +08:00
|
|
|
CircleWidget* circle = CircleWidget::getFromID(circleActions[selectedItem]);
|
|
|
|
|
|
|
|
if (circle != nullptr)
|
|
|
|
{
|
2015-07-20 20:13:51 +08:00
|
|
|
circle->addFriendWidget(FriendList::findFriend(friendId)->getFriendWidget(), FriendList::findFriend(friendId)->getStatus());
|
2015-06-13 02:52:05 +08:00
|
|
|
circle->setExpanded(true);
|
|
|
|
Widget::getInstance()->searchCircle(circle);
|
2015-06-17 20:40:14 +08:00
|
|
|
Settings::getInstance().savePersonal();
|
2015-06-13 02:52:05 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
Settings::getInstance().setFriendCircleID(id, circleActions[selectedItem]);
|
2015-06-07 11:20:06 +08:00
|
|
|
|
|
|
|
if (circleWidget != nullptr)
|
|
|
|
{
|
|
|
|
circleWidget->updateStatus();
|
|
|
|
Widget::getInstance()->searchCircle(circleWidget);
|
|
|
|
}
|
2015-05-29 21:26:43 +08:00
|
|
|
}
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
}
|
2014-06-27 07:35:30 +08:00
|
|
|
|
2014-06-27 09:47:16 +08:00
|
|
|
void FriendWidget::setAsActiveChatroom()
|
2014-06-27 07:35:30 +08:00
|
|
|
{
|
2014-10-01 02:10:42 +08:00
|
|
|
setActive(true);
|
2014-06-28 02:11:32 +08:00
|
|
|
|
2014-10-01 02:10:42 +08:00
|
|
|
if (isDefaultAvatar)
|
2015-02-12 20:18:04 +08:00
|
|
|
avatar->setPixmap(QPixmap(":img/contact_dark.svg"), Qt::transparent);
|
2014-06-27 07:35:30 +08:00
|
|
|
}
|
|
|
|
|
2014-06-27 09:47:16 +08:00
|
|
|
void FriendWidget::setAsInactiveChatroom()
|
2014-06-27 07:35:30 +08:00
|
|
|
{
|
2014-10-01 02:10:42 +08:00
|
|
|
setActive(false);
|
2014-06-28 02:11:32 +08:00
|
|
|
|
2014-10-01 02:10:42 +08:00
|
|
|
if (isDefaultAvatar)
|
2015-02-12 20:18:04 +08:00
|
|
|
avatar->setPixmap(QPixmap(":img/contact.svg"), Qt::transparent);
|
2014-06-27 07:35:30 +08:00
|
|
|
}
|
2014-08-22 23:19:16 +08:00
|
|
|
|
2014-08-31 22:19:16 +08:00
|
|
|
void FriendWidget::updateStatusLight()
|
|
|
|
{
|
|
|
|
Friend* f = FriendList::findFriend(friendId);
|
2014-11-06 23:26:22 +08:00
|
|
|
Status status = f->getStatus();
|
2014-08-31 22:19:16 +08:00
|
|
|
|
2014-11-06 23:26:22 +08:00
|
|
|
if (status == Status::Online && f->getEventFlag() == 0)
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_online.svg"));
|
2014-11-06 23:26:22 +08:00
|
|
|
else if (status == Status::Online && f->getEventFlag() == 1)
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.svg"));
|
2014-11-06 23:26:22 +08:00
|
|
|
else if (status == Status::Away && f->getEventFlag() == 0)
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_away.svg"));
|
2014-11-06 23:26:22 +08:00
|
|
|
else if (status == Status::Away && f->getEventFlag() == 1)
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_away_notification.svg"));
|
2014-11-06 23:26:22 +08:00
|
|
|
else if (status == Status::Busy && f->getEventFlag() == 0)
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_busy.svg"));
|
2014-11-06 23:26:22 +08:00
|
|
|
else if (status == Status::Busy && f->getEventFlag() == 1)
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_busy_notification.svg"));
|
2014-11-06 23:26:22 +08:00
|
|
|
else if (status == Status::Offline && f->getEventFlag() == 0)
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_offline.svg"));
|
2014-11-06 23:26:22 +08:00
|
|
|
else if (status == Status::Offline && f->getEventFlag() == 1)
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_offline_notification.svg"));
|
2015-03-18 07:45:57 +08:00
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
if (f->getEventFlag())
|
|
|
|
{
|
2015-06-06 03:34:32 +08:00
|
|
|
CircleWidget* circleWidget = CircleWidget::getFromID(Settings::getInstance().getFriendCircleID(FriendList::findFriend(friendId)->getToxId()));
|
2015-06-03 21:51:23 +08:00
|
|
|
if (circleWidget != nullptr)
|
2015-06-06 03:34:32 +08:00
|
|
|
circleWidget->setExpanded(true);
|
2015-06-13 00:52:41 +08:00
|
|
|
|
|
|
|
Widget::getInstance()->updateFriendActivity(FriendList::findFriend(friendId));
|
2015-06-03 21:51:23 +08:00
|
|
|
}
|
|
|
|
|
2015-03-18 07:51:22 +08:00
|
|
|
if (!f->getEventFlag())
|
2015-03-18 07:45:57 +08:00
|
|
|
statusPic.setMargin(3);
|
|
|
|
else
|
|
|
|
statusPic.setMargin(0);
|
2014-08-31 22:19:16 +08:00
|
|
|
}
|
2014-09-02 00:20:28 +08:00
|
|
|
|
2015-06-23 02:01:50 +08:00
|
|
|
QString FriendWidget::getStatusString() const
|
2015-03-26 03:08:46 +08:00
|
|
|
{
|
|
|
|
Friend* f = FriendList::findFriend(friendId);
|
|
|
|
Status status = f->getStatus();
|
|
|
|
|
|
|
|
if (f->getEventFlag() == 1)
|
|
|
|
return tr("New message");
|
|
|
|
else if (status == Status::Online)
|
|
|
|
return tr("Online");
|
|
|
|
else if (status == Status::Away)
|
|
|
|
return tr("Away");
|
|
|
|
else if (status == Status::Busy)
|
|
|
|
return tr("Busy");
|
|
|
|
else if (status == Status::Offline)
|
|
|
|
return tr("Offline");
|
|
|
|
return QString::null;
|
|
|
|
}
|
|
|
|
|
2015-06-19 22:58:48 +08:00
|
|
|
Friend* FriendWidget::getFriend() const
|
|
|
|
{
|
|
|
|
return FriendList::findFriend(friendId);
|
|
|
|
}
|
|
|
|
|
2015-06-07 11:20:06 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-06-23 02:01:50 +08:00
|
|
|
bool FriendWidget::chatFormIsSet(bool focus) const
|
2014-09-02 00:20:28 +08:00
|
|
|
{
|
|
|
|
Friend* f = FriendList::findFriend(friendId);
|
2015-06-23 02:01:50 +08:00
|
|
|
return ContentDialog::existsFriendWidget(friendId, focus) || f->getChatForm()->isVisible();
|
2015-06-17 02:25:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FriendWidget::setChatForm(ContentLayout* contentLayout)
|
|
|
|
{
|
|
|
|
Friend* f = FriendList::findFriend(friendId);
|
|
|
|
f->getChatForm()->show(contentLayout);
|
2014-09-02 00:20:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FriendWidget::resetEventFlags()
|
|
|
|
{
|
|
|
|
Friend* f = FriendList::findFriend(friendId);
|
2014-11-06 23:26:22 +08:00
|
|
|
f->setEventFlag(false);
|
2014-09-02 00:20:28 +08:00
|
|
|
}
|
2014-09-24 23:28:38 +08:00
|
|
|
|
|
|
|
void FriendWidget::onAvatarChange(int FriendId, const QPixmap& pic)
|
|
|
|
{
|
|
|
|
if (FriendId != friendId)
|
|
|
|
return;
|
|
|
|
|
2014-09-24 23:35:24 +08:00
|
|
|
isDefaultAvatar = false;
|
2014-09-26 22:39:29 +08:00
|
|
|
avatar->setPixmap(pic);
|
2014-09-30 02:18:03 +08:00
|
|
|
avatar->autopickBackground();
|
2014-09-24 23:28:38 +08:00
|
|
|
}
|
2014-09-26 00:03:25 +08:00
|
|
|
|
2014-09-27 03:23:20 +08:00
|
|
|
void FriendWidget::onAvatarRemoved(int FriendId)
|
|
|
|
{
|
|
|
|
if (FriendId != friendId)
|
|
|
|
return;
|
|
|
|
|
|
|
|
isDefaultAvatar = true;
|
2014-10-05 20:22:28 +08:00
|
|
|
|
|
|
|
if (isActive())
|
2015-02-12 20:18:04 +08:00
|
|
|
avatar->setPixmap(QPixmap(":img/contact_dark.svg"), Qt::transparent);
|
2014-10-05 20:22:28 +08:00
|
|
|
else
|
2015-02-12 20:18:04 +08:00
|
|
|
avatar->setPixmap(QPixmap(":img/contact.svg"), Qt::transparent);
|
2014-09-27 03:23:20 +08:00
|
|
|
}
|
|
|
|
|
2014-09-26 00:03:25 +08:00
|
|
|
void FriendWidget::mousePressEvent(QMouseEvent *ev)
|
|
|
|
{
|
|
|
|
if (ev->button() == Qt::LeftButton)
|
|
|
|
dragStartPos = ev->pos();
|
2015-06-07 06:33:03 +08:00
|
|
|
|
|
|
|
GenericChatroomWidget::mousePressEvent(ev);
|
2014-09-26 00:03:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FriendWidget::mouseMoveEvent(QMouseEvent *ev)
|
|
|
|
{
|
|
|
|
if (!(ev->buttons() & Qt::LeftButton))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((dragStartPos - ev->pos()).manhattanLength() > QApplication::startDragDistance())
|
|
|
|
{
|
|
|
|
QDrag* drag = new QDrag(this);
|
|
|
|
QMimeData* mdata = new QMimeData;
|
|
|
|
mdata->setData("friend", QString::number(friendId).toLatin1());
|
|
|
|
|
|
|
|
drag->setMimeData(mdata);
|
2014-09-26 22:39:29 +08:00
|
|
|
drag->setPixmap(avatar->getPixmap());
|
2014-09-26 00:03:25 +08:00
|
|
|
|
|
|
|
drag->exec(Qt::CopyAction | Qt::MoveAction);
|
|
|
|
}
|
|
|
|
}
|
2014-11-07 22:55:32 +08:00
|
|
|
|
2014-11-18 10:15:44 +08:00
|
|
|
void FriendWidget::setAlias(const QString& _alias)
|
|
|
|
{
|
2015-06-02 02:39:40 +08:00
|
|
|
QString alias = _alias.left(128); // same as TOX_MAX_NAME_LENGTH
|
2014-11-18 10:15:44 +08:00
|
|
|
Friend* f = FriendList::findFriend(friendId);
|
|
|
|
f->setAlias(alias);
|
2015-05-24 02:58:41 +08:00
|
|
|
Settings::getInstance().setFriendAlias(f->getToxId(), alias);
|
2015-06-06 21:54:58 +08:00
|
|
|
Settings::getInstance().savePersonal();
|
2014-11-18 10:15:44 +08:00
|
|
|
}
|