2014-07-07 00:19:45 +08:00
|
|
|
/*
|
|
|
|
Copyright (C) 2014 by Project Tox <https://tox.im>
|
|
|
|
|
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
|
|
|
This program is libre software: you can redistribute it and/or modify
|
|
|
|
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.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the COPYING file for more details.
|
|
|
|
*/
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
#include "groupwidget.h"
|
2014-10-08 12:26:25 +08:00
|
|
|
#include "src/grouplist.h"
|
|
|
|
#include "src/group.h"
|
|
|
|
#include "src/misc/settings.h"
|
|
|
|
#include "form/groupchatform.h"
|
|
|
|
#include "maskablepixmapwidget.h"
|
|
|
|
#include "src/misc/style.h"
|
2014-10-16 21:48:40 +08:00
|
|
|
#include "src/core.h"
|
2014-06-25 04:11:11 +08:00
|
|
|
#include <QPalette>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QContextMenuEvent>
|
2014-10-16 21:48:40 +08:00
|
|
|
#include <QMimeData>
|
|
|
|
#include <QDragEnterEvent>
|
2014-11-18 19:00:09 +08:00
|
|
|
#include <QInputDialog>
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2014-09-02 00:20:28 +08:00
|
|
|
#include "ui_mainwindow.h"
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
GroupWidget::GroupWidget(int GroupId, QString Name)
|
|
|
|
: groupId{GroupId}
|
|
|
|
{
|
2014-10-01 02:10:42 +08:00
|
|
|
avatar->setPixmap(QPixmap(":img/group.png"), Qt::transparent);
|
2014-07-07 06:03:37 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
|
2014-10-01 17:13:49 +08:00
|
|
|
nameLabel->setText(Name);
|
2014-10-01 02:10:42 +08:00
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
Group* g = GroupList::findGroup(groupId);
|
|
|
|
if (g)
|
2014-10-01 17:13:49 +08:00
|
|
|
statusMessageLabel->setText(GroupWidget::tr("%1 users in chat").arg(g->peers.size()));
|
2014-06-25 04:11:11 +08:00
|
|
|
else
|
2014-10-01 17:13:49 +08:00
|
|
|
statusMessageLabel->setText(GroupWidget::tr("0 users in chat"));
|
2014-10-16 21:48:40 +08:00
|
|
|
|
|
|
|
setAcceptDrops(true);
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupWidget::contextMenuEvent(QContextMenuEvent * event)
|
|
|
|
{
|
|
|
|
QPoint pos = event->globalPos();
|
|
|
|
QMenu menu;
|
2014-07-04 22:41:29 +08:00
|
|
|
QAction* quitGroup = menu.addAction(tr("Quit group","Menu to quit a groupchat"));
|
2014-11-18 19:00:09 +08:00
|
|
|
QAction* setAlias = menu.addAction(tr("Set title..."));
|
2014-06-25 04:11:11 +08:00
|
|
|
|
|
|
|
QAction* selectedItem = menu.exec(pos);
|
2014-11-18 19:00:09 +08:00
|
|
|
if (selectedItem)
|
|
|
|
{
|
|
|
|
if (selectedItem == quitGroup)
|
|
|
|
emit removeGroup(groupId);
|
|
|
|
else if (selectedItem == setAlias)
|
|
|
|
{
|
|
|
|
bool ok;
|
|
|
|
Group* g = GroupList::findGroup(groupId);
|
|
|
|
|
|
|
|
QString alias = QInputDialog::getText(nullptr, tr("Group title"), tr("You can also set this by clicking the chat form name.\nTitle:"), QLineEdit::Normal,
|
|
|
|
nameLabel->fullText(), &ok);
|
|
|
|
|
|
|
|
if (ok && alias != nameLabel->fullText())
|
|
|
|
emit g->chatForm->groupTitleChanged(groupId, alias.left(128));
|
|
|
|
}
|
|
|
|
}
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupWidget::onUserListChanged()
|
|
|
|
{
|
|
|
|
Group* g = GroupList::findGroup(groupId);
|
|
|
|
if (g)
|
2014-10-01 17:13:49 +08:00
|
|
|
statusMessageLabel->setText(tr("%1 users in chat").arg(g->nPeers));
|
2014-06-25 04:11:11 +08:00
|
|
|
else
|
2014-10-01 17:13:49 +08:00
|
|
|
statusMessageLabel->setText(tr("0 users in chat"));
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
2014-06-27 09:47:16 +08:00
|
|
|
|
|
|
|
void GroupWidget::setAsActiveChatroom()
|
|
|
|
{
|
2014-10-01 02:10:42 +08:00
|
|
|
setActive(true);
|
|
|
|
avatar->setPixmap(QPixmap(":img/group_dark.png"), Qt::transparent);
|
2014-06-27 09:47:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupWidget::setAsInactiveChatroom()
|
|
|
|
{
|
2014-10-01 02:10:42 +08:00
|
|
|
setActive(false);
|
|
|
|
avatar->setPixmap(QPixmap(":img/group.png"), Qt::transparent);
|
2014-06-27 09:47:16 +08:00
|
|
|
}
|
2014-09-01 23:02:26 +08:00
|
|
|
|
|
|
|
void GroupWidget::updateStatusLight()
|
|
|
|
{
|
2014-09-02 00:20:28 +08:00
|
|
|
Group *g = GroupList::findGroup(groupId);
|
|
|
|
|
2014-10-04 16:54:50 +08:00
|
|
|
if (g->hasNewMessages == 0)
|
2014-09-02 00:20:28 +08:00
|
|
|
{
|
2014-10-04 17:08:14 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
|
2014-10-04 16:54:50 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (g->userWasMentioned == 0)
|
2014-10-04 17:08:14 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
|
2014-10-04 16:54:50 +08:00
|
|
|
else
|
2014-10-04 17:08:14 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
|
2014-09-02 00:20:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupWidget::setChatForm(Ui::MainWindow &ui)
|
|
|
|
{
|
|
|
|
Group* g = GroupList::findGroup(groupId);
|
|
|
|
g->chatForm->show(ui);
|
|
|
|
}
|
2014-09-01 23:02:26 +08:00
|
|
|
|
2014-09-02 00:20:28 +08:00
|
|
|
void GroupWidget::resetEventFlags()
|
|
|
|
{
|
|
|
|
Group* g = GroupList::findGroup(groupId);
|
|
|
|
g->hasNewMessages = 0;
|
|
|
|
g->userWasMentioned = 0;
|
2014-09-01 23:02:26 +08:00
|
|
|
}
|
2014-10-16 21:48:40 +08:00
|
|
|
|
|
|
|
void GroupWidget::dragEnterEvent(QDragEnterEvent *ev)
|
|
|
|
{
|
|
|
|
if (ev->mimeData()->hasFormat("friend"))
|
|
|
|
ev->acceptProposedAction();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupWidget::dropEvent(QDropEvent *ev)
|
|
|
|
{
|
|
|
|
if (ev->mimeData()->hasFormat("friend"))
|
|
|
|
{
|
|
|
|
int friendId = ev->mimeData()->data("friend").toInt();
|
|
|
|
Core::getInstance()->groupInviteFriend(friendId, groupId);
|
|
|
|
}
|
|
|
|
}
|
2014-11-14 02:25:45 +08:00
|
|
|
|
|
|
|
void GroupWidget::keyPressEvent(QKeyEvent* ev)
|
|
|
|
{
|
|
|
|
Group* g = GroupList::findGroup(groupId);
|
|
|
|
if (g)
|
|
|
|
g->chatForm->keyPressEvent(ev);
|
2014-11-14 03:32:09 +08:00
|
|
|
|
2014-11-14 02:25:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupWidget::keyReleaseEvent(QKeyEvent* ev)
|
|
|
|
{
|
|
|
|
Group* g = GroupList::findGroup(groupId);
|
|
|
|
if (g)
|
|
|
|
g->chatForm->keyReleaseEvent(ev);
|
|
|
|
}
|
2014-11-06 08:22:50 +08:00
|
|
|
|
|
|
|
void GroupWidget::setName(const QString& name)
|
|
|
|
{
|
|
|
|
nameLabel->setText(name);
|
|
|
|
}
|