2014-07-07 00:19:45 +08:00
|
|
|
/*
|
2015-06-06 09:40:08 +08:00
|
|
|
Copyright © 2014-2015 by The qTox Project
|
|
|
|
|
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 "groupwidget.h"
|
2014-10-08 12:26:25 +08:00
|
|
|
#include "src/grouplist.h"
|
|
|
|
#include "src/group.h"
|
2015-06-06 07:44:47 +08:00
|
|
|
#include "src/persistence/settings.h"
|
2014-10-08 12:26:25 +08:00
|
|
|
#include "form/groupchatform.h"
|
|
|
|
#include "maskablepixmapwidget.h"
|
2015-06-06 07:44:47 +08:00
|
|
|
#include "src/widget/style.h"
|
2015-04-24 08:32:09 +08:00
|
|
|
#include "src/core/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"
|
|
|
|
|
2015-02-12 20:18:04 +08:00
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
GroupWidget::GroupWidget(int GroupId, QString Name)
|
|
|
|
: groupId{GroupId}
|
|
|
|
{
|
2015-02-12 20:18:04 +08:00
|
|
|
avatar->setPixmap(Style::scaleSvgImage(":img/group.svg", avatar->width(), avatar->height()), Qt::transparent);
|
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_online.svg"));
|
2015-03-18 07:51:22 +08:00
|
|
|
statusPic.setMargin(3);
|
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-11-23 23:22:29 +08:00
|
|
|
statusMessageLabel->setText(GroupWidget::tr("%1 users in chat").arg(g->getPeersCount()));
|
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);
|
2015-06-02 02:39:40 +08:00
|
|
|
|
2015-06-03 21:51:23 +08:00
|
|
|
connect(nameLabel, &CroppingLabel::textChanged, [this](const QString &newName, const QString &oldName)
|
2015-06-02 02:39:40 +08:00
|
|
|
{
|
2015-06-07 11:20:06 +08:00
|
|
|
Group* g = GroupList::findGroup(groupId);
|
2015-06-03 21:51:23 +08:00
|
|
|
if (newName != oldName)
|
2015-06-02 02:39:40 +08:00
|
|
|
{
|
2015-06-03 21:51:23 +08:00
|
|
|
nameLabel->setText(oldName);
|
|
|
|
emit renameRequested(newName);
|
2015-06-07 11:20:06 +08:00
|
|
|
emit g->getChatForm()->groupTitleChanged(groupId, newName.left(128));
|
2015-06-02 02:39:40 +08:00
|
|
|
}
|
|
|
|
/* according to agilob:
|
|
|
|
* “Moving mouse pointer over groupwidget results in CSS effect
|
|
|
|
* mouse-over(?). Changing group title repaints only changed
|
|
|
|
* element - title, the rest of the widget stays in the same CSS as it
|
|
|
|
* was on mouse over. Repainting whole widget fixes style problem.”
|
|
|
|
*/
|
|
|
|
this->repaint();
|
|
|
|
});
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupWidget::contextMenuEvent(QContextMenuEvent * event)
|
|
|
|
{
|
|
|
|
QPoint pos = event->globalPos();
|
|
|
|
QMenu menu;
|
2015-03-11 19:20:27 +08:00
|
|
|
QAction* setTitle = menu.addAction(tr("Set title..."));
|
2014-11-23 23:58:22 +08:00
|
|
|
QAction* quitGroup = menu.addAction(tr("Quit group","Menu to quit a groupchat"));
|
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)
|
2015-04-24 19:01:50 +08:00
|
|
|
{
|
2014-11-18 19:00:09 +08:00
|
|
|
emit removeGroup(groupId);
|
2015-04-24 19:01:50 +08:00
|
|
|
}
|
2015-03-11 19:20:27 +08:00
|
|
|
else if (selectedItem == setTitle)
|
2014-11-18 19:00:09 +08:00
|
|
|
{
|
2015-06-02 02:39:40 +08:00
|
|
|
nameLabel->editStart();
|
2014-11-18 19:00:09 +08:00
|
|
|
}
|
|
|
|
}
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupWidget::onUserListChanged()
|
|
|
|
{
|
|
|
|
Group* g = GroupList::findGroup(groupId);
|
|
|
|
if (g)
|
2014-11-23 23:22:29 +08:00
|
|
|
statusMessageLabel->setText(tr("%1 users in chat").arg(g->getPeersCount()));
|
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);
|
2015-02-12 20:18:04 +08:00
|
|
|
avatar->setPixmap(Style::scaleSvgImage(":img/group_dark.svg", avatar->width(), avatar->height()), Qt::transparent);
|
2014-06-27 09:47:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupWidget::setAsInactiveChatroom()
|
|
|
|
{
|
2014-10-01 02:10:42 +08:00
|
|
|
setActive(false);
|
2015-02-12 20:18:04 +08:00
|
|
|
avatar->setPixmap(Style::scaleSvgImage(":img/group.svg", avatar->width(), avatar->height()), 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-11-23 23:22:29 +08:00
|
|
|
if (!g->getEventFlag())
|
2015-03-18 07:51:22 +08:00
|
|
|
{
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_online.svg"));
|
2015-03-18 07:51:22 +08:00
|
|
|
statusPic.setMargin(3);
|
|
|
|
}
|
2014-10-04 16:54:50 +08:00
|
|
|
else
|
2015-03-18 07:51:22 +08:00
|
|
|
{
|
2015-02-12 20:18:04 +08:00
|
|
|
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.svg"));
|
2015-03-18 07:51:22 +08:00
|
|
|
statusPic.setMargin(0);
|
|
|
|
}
|
2014-09-02 00:20:28 +08:00
|
|
|
}
|
|
|
|
|
2015-03-26 03:08:46 +08:00
|
|
|
QString GroupWidget::getStatusString()
|
|
|
|
{
|
|
|
|
Group *g = GroupList::findGroup(groupId);
|
|
|
|
|
|
|
|
if (!g->getEventFlag())
|
|
|
|
return "Online";
|
|
|
|
else
|
|
|
|
return "New Message";
|
|
|
|
}
|
|
|
|
|
2015-06-07 11:20:06 +08:00
|
|
|
void GroupWidget::rename()
|
|
|
|
{
|
|
|
|
nameLabel->editStart();
|
|
|
|
}
|
|
|
|
|
2014-09-02 00:20:28 +08:00
|
|
|
void GroupWidget::setChatForm(Ui::MainWindow &ui)
|
|
|
|
{
|
|
|
|
Group* g = GroupList::findGroup(groupId);
|
2014-11-23 23:22:29 +08:00
|
|
|
g->getChatForm()->show(ui);
|
2014-09-02 00:20:28 +08:00
|
|
|
}
|
2014-09-01 23:02:26 +08:00
|
|
|
|
2014-09-02 00:20:28 +08:00
|
|
|
void GroupWidget::resetEventFlags()
|
|
|
|
{
|
|
|
|
Group* g = GroupList::findGroup(groupId);
|
2014-11-23 23:22:29 +08:00
|
|
|
g->setEventFlag(false);
|
|
|
|
g->setMentionedFlag(false);
|
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();
|
2015-05-28 22:28:11 +08:00
|
|
|
setAttribute(Qt::WA_UnderMouse, true); // Simulate hover.
|
|
|
|
Style::repolish(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GroupWidget::dragLeaveEvent(QDragLeaveEvent *)
|
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_UnderMouse, false);
|
|
|
|
Style::repolish(this);
|
2014-10-16 21:48:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GroupWidget::dropEvent(QDropEvent *ev)
|
|
|
|
{
|
|
|
|
if (ev->mimeData()->hasFormat("friend"))
|
|
|
|
{
|
|
|
|
int friendId = ev->mimeData()->data("friend").toInt();
|
|
|
|
Core::getInstance()->groupInviteFriend(friendId, groupId);
|
2015-05-28 22:28:11 +08:00
|
|
|
|
|
|
|
setAttribute(Qt::WA_UnderMouse, false);
|
|
|
|
Style::repolish(this);
|
2014-10-16 21:48:40 +08:00
|
|
|
}
|
|
|
|
}
|
2014-11-14 02:25:45 +08:00
|
|
|
|
2014-11-06 08:22:50 +08:00
|
|
|
void GroupWidget::setName(const QString& name)
|
|
|
|
{
|
|
|
|
nameLabel->setText(name);
|
|
|
|
}
|