2014-06-25 04:11:11 +08:00
|
|
|
#include "friendwidget.h"
|
2014-06-28 16:53:38 +08:00
|
|
|
#include "group.h"
|
|
|
|
#include "grouplist.h"
|
|
|
|
#include "groupwidget.h"
|
|
|
|
#include "widget.h"
|
2014-06-25 04:11:11 +08:00
|
|
|
#include <QContextMenuEvent>
|
|
|
|
#include <QMenu>
|
|
|
|
|
|
|
|
FriendWidget::FriendWidget(int FriendId, QString id)
|
|
|
|
: friendId(FriendId)
|
|
|
|
{
|
2014-07-01 10:12:17 +08:00
|
|
|
this->setMouseTracking(true);
|
2014-06-27 07:35:30 +08:00
|
|
|
this->setAutoFillBackground(true);
|
2014-06-25 04:11:11 +08:00
|
|
|
this->setLayout(&layout);
|
|
|
|
this->setFixedWidth(225);
|
|
|
|
this->setFixedHeight(55);
|
|
|
|
layout.setSpacing(0);
|
|
|
|
layout.setMargin(0);
|
|
|
|
textLayout.setSpacing(0);
|
|
|
|
textLayout.setMargin(0);
|
|
|
|
|
2014-07-01 10:12:17 +08:00
|
|
|
avatar.setPixmap(QPixmap(":img/contact.png"));
|
2014-06-25 04:11:11 +08:00
|
|
|
name.setText(id);
|
2014-06-28 02:11:32 +08:00
|
|
|
//statusPic.setAlignment(Qt::AlignHCenter);
|
2014-07-01 10:12:17 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_away.png"));
|
2014-06-25 04:11:11 +08:00
|
|
|
QFont small;
|
|
|
|
small.setPixelSize(10);
|
|
|
|
statusMessage.setFont(small);
|
|
|
|
QPalette pal;
|
|
|
|
pal.setColor(QPalette::WindowText,Qt::gray);
|
|
|
|
statusMessage.setPalette(pal);
|
2014-07-01 10:12:17 +08:00
|
|
|
QPalette pal2;
|
|
|
|
pal2.setColor(QPalette::WindowText,Qt::white);
|
|
|
|
name.setPalette(pal2);
|
|
|
|
QPalette pal3;
|
|
|
|
pal3.setColor(QPalette::Background, QColor(65,65,65,255));
|
|
|
|
this->setPalette(pal3);
|
2014-06-25 04:11:11 +08:00
|
|
|
|
|
|
|
textLayout.addStretch();
|
|
|
|
textLayout.addWidget(&name);
|
|
|
|
textLayout.addWidget(&statusMessage);
|
|
|
|
textLayout.addStretch();
|
|
|
|
|
|
|
|
layout.addSpacing(20);
|
|
|
|
layout.addWidget(&avatar);
|
|
|
|
layout.addSpacing(5);
|
|
|
|
layout.addLayout(&textLayout);
|
|
|
|
layout.addStretch();
|
|
|
|
layout.addSpacing(5);
|
|
|
|
layout.addWidget(&statusPic);
|
|
|
|
layout.addSpacing(5);
|
2014-06-28 02:11:32 +08:00
|
|
|
|
2014-06-28 02:22:53 +08:00
|
|
|
isActiveWidget = 0;
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FriendWidget::mouseReleaseEvent (QMouseEvent*)
|
|
|
|
{
|
|
|
|
emit friendWidgetClicked(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FriendWidget::contextMenuEvent(QContextMenuEvent * event)
|
|
|
|
{
|
|
|
|
QPoint pos = event->globalPos();
|
|
|
|
QMenu menu;
|
2014-07-04 03:42:23 +08:00
|
|
|
menu.addAction(tr("Copy friend ID","Menu to copy the Tox ID of that friend"));
|
|
|
|
QMenu* inviteMenu = menu.addMenu(tr("Invite in group","Menu to invite a friend in a groupchat"));
|
2014-06-28 16:53:38 +08:00
|
|
|
QMap<QAction*, Group*> groupActions;
|
|
|
|
for (Group* group : GroupList::groupList)
|
|
|
|
{
|
|
|
|
QAction* groupAction = inviteMenu->addAction(group->widget->name.text());
|
|
|
|
groupActions[groupAction] = group;
|
|
|
|
}
|
|
|
|
if (groupActions.isEmpty())
|
|
|
|
inviteMenu->setEnabled(false);
|
2014-07-02 05:58:26 +08:00
|
|
|
menu.addSeparator();
|
2014-07-04 03:42:23 +08:00
|
|
|
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);
|
|
|
|
if (selectedItem)
|
|
|
|
{
|
2014-07-02 05:50:07 +08:00
|
|
|
if (selectedItem->text() == "Copy friend ID")
|
|
|
|
{
|
|
|
|
emit copyFriendIdToClipboard(friendId);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (selectedItem->text() == "Remove friend")
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
|
|
|
hide();
|
|
|
|
emit removeFriend(friendId);
|
|
|
|
return;
|
|
|
|
}
|
2014-06-28 16:53:38 +08:00
|
|
|
else if (groupActions.contains(selectedItem))
|
|
|
|
{
|
|
|
|
Group* group = groupActions[selectedItem];
|
|
|
|
Widget::getInstance()->getCore()->groupInviteFriend(friendId, group->groupId);
|
|
|
|
}
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
}
|
2014-06-27 07:35:30 +08:00
|
|
|
|
2014-06-28 02:11:32 +08:00
|
|
|
void FriendWidget::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
if ((event->buttons() & Qt::LeftButton) == Qt::LeftButton)
|
|
|
|
{
|
2014-06-28 02:22:53 +08:00
|
|
|
if (isActiveWidget)
|
|
|
|
{
|
|
|
|
QPalette pal;
|
|
|
|
pal.setColor(QPalette::Background, QColor(250,250,250,255));
|
|
|
|
this->setPalette(pal);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
QPalette pal;
|
|
|
|
pal.setColor(QPalette::Background, QColor(85,85,85,255));
|
|
|
|
this->setPalette(pal);
|
|
|
|
}
|
2014-06-28 02:11:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FriendWidget::enterEvent(QEvent*)
|
|
|
|
{
|
|
|
|
if (isActiveWidget != 1)
|
|
|
|
{
|
|
|
|
QPalette pal;
|
|
|
|
pal.setColor(QPalette::Background, QColor(75,75,75,255));
|
|
|
|
lastColor = this->palette().background().color();
|
|
|
|
this->setPalette(pal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FriendWidget::leaveEvent(QEvent*)
|
|
|
|
{
|
|
|
|
if (isActiveWidget != 1)
|
|
|
|
{
|
|
|
|
QPalette pal;
|
|
|
|
pal.setColor(QPalette::Background, lastColor);
|
|
|
|
this->setPalette(pal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-27 09:47:16 +08:00
|
|
|
void FriendWidget::setAsActiveChatroom()
|
2014-06-27 07:35:30 +08:00
|
|
|
{
|
2014-06-28 02:11:32 +08:00
|
|
|
isActiveWidget = 1;
|
|
|
|
|
2014-06-27 07:35:30 +08:00
|
|
|
QFont small;
|
|
|
|
small.setPixelSize(10);
|
|
|
|
statusMessage.setFont(small);
|
|
|
|
QPalette pal;
|
|
|
|
pal.setColor(QPalette::WindowText,Qt::darkGray);
|
|
|
|
statusMessage.setPalette(pal);
|
|
|
|
QPalette pal2;
|
|
|
|
pal2.setColor(QPalette::WindowText,Qt::black);
|
|
|
|
name.setPalette(pal2);
|
|
|
|
QPalette pal3;
|
|
|
|
pal3.setColor(QPalette::Background, Qt::white);
|
|
|
|
this->setPalette(pal3);
|
2014-07-01 10:12:17 +08:00
|
|
|
avatar.setPixmap(QPixmap(":img/contact_dark.png"));
|
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-06-28 02:11:32 +08:00
|
|
|
isActiveWidget = 0;
|
|
|
|
|
2014-06-27 07:35:30 +08:00
|
|
|
QFont small;
|
|
|
|
small.setPixelSize(10);
|
|
|
|
statusMessage.setFont(small);
|
|
|
|
QPalette pal;
|
|
|
|
pal.setColor(QPalette::WindowText,Qt::gray);
|
|
|
|
statusMessage.setPalette(pal);
|
|
|
|
QPalette pal2;
|
|
|
|
pal2.setColor(QPalette::WindowText,Qt::white);
|
|
|
|
name.setPalette(pal2);
|
|
|
|
QPalette pal3;
|
2014-06-28 01:34:58 +08:00
|
|
|
pal3.setColor(QPalette::Background, QColor(65,65,65,255));
|
2014-06-27 07:35:30 +08:00
|
|
|
this->setPalette(pal3);
|
2014-07-01 10:12:17 +08:00
|
|
|
avatar.setPixmap(QPixmap(":img/contact.png"));
|
2014-06-27 07:35:30 +08:00
|
|
|
}
|