1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
qTox/widget/groupwidget.cpp

173 lines
4.8 KiB
C++
Raw Normal View History

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"
#include "grouplist.h"
#include "group.h"
2014-09-30 02:28:59 +08:00
#include "misc/settings.h"
#include "widget/form/groupchatform.h"
#include "widget/maskablepixmapwidget.h"
#include "style.h"
2014-06-25 04:11:11 +08:00
#include <QPalette>
#include <QMenu>
#include <QContextMenuEvent>
#include "ui_mainwindow.h"
2014-06-25 04:11:11 +08:00
GroupWidget::GroupWidget(int GroupId, QString Name)
: groupId{GroupId}
{
avatar = new MaskablePixmapWidget(this, QSize(40,40), ":/img/avatar_mask.png");
avatar->setPixmap(QPixmap(":img/group.png"), Qt::transparent);
statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
// name
QPalette pal2;
pal2.setColor(QPalette::WindowText, Style::getColor(Style::White));
name.setPalette(pal2);
2014-06-25 04:11:11 +08:00
name.setText(Name);
name.setFont(Style::getFont(Style::Big));
// status
2014-06-25 04:11:11 +08:00
QPalette pal;
pal.setColor(QPalette::WindowText, Style::getColor(Style::LightGrey));
2014-06-25 04:11:11 +08:00
nusers.setPalette(pal);
nusers.setFont(Style::getFont(Style::Medium));
2014-06-25 04:11:11 +08:00
Group* g = GroupList::findGroup(groupId);
if (g)
nusers.setText(GroupWidget::tr("%1 users in chat").arg(g->peers.size()));
2014-06-25 04:11:11 +08:00
else
nusers.setText(GroupWidget::tr("0 users in chat"));
2014-06-25 04:11:11 +08:00
textLayout.addStretch();
textLayout.addWidget(&name);
textLayout.addWidget(&nusers);
textLayout.addStretch();
layout.addSpacing(20);
layout.addWidget(avatar);
layout.addSpacing(10);
2014-06-25 04:11:11 +08:00
layout.addLayout(&textLayout);
layout.addStretch();
layout.addSpacing(10);
2014-06-28 07:10:02 +08:00
layout.addWidget(&statusPic);
layout.addSpacing(10);
2014-10-01 05:45:33 +08:00
layout.activate();
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-06-25 04:11:11 +08:00
QAction* selectedItem = menu.exec(pos);
2014-07-04 22:41:29 +08:00
if (selectedItem == quitGroup)
2014-06-25 04:11:11 +08:00
{
hide();
show(); //Toggle visibility to work around bug of repaintEvent() not being fired on parent widget when this is hidden
2014-07-04 22:41:29 +08:00
hide();
emit removeGroup(groupId);
return;
2014-06-25 04:11:11 +08:00
}
}
void GroupWidget::onUserListChanged()
{
Group* g = GroupList::findGroup(groupId);
if (g)
2014-07-04 03:42:23 +08:00
nusers.setText(tr("%1 users in chat").arg(g->nPeers));
2014-06-25 04:11:11 +08:00
else
2014-07-04 03:42:23 +08:00
nusers.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()
{
setActive(true);
2014-06-28 02:22:53 +08:00
// status
2014-06-27 09:47:16 +08:00
QPalette pal;
pal.setColor(QPalette::WindowText, Style::getColor(Style::MediumGrey));
2014-06-27 09:47:16 +08:00
nusers.setPalette(pal);
// name
2014-06-27 09:47:16 +08:00
QPalette pal2;
pal2.setColor(QPalette::WindowText, Style::getColor(Style::DarkGrey));
2014-06-27 09:47:16 +08:00
name.setPalette(pal2);
avatar->setPixmap(QPixmap(":img/group_dark.png"), Qt::transparent);
2014-06-27 09:47:16 +08:00
}
void GroupWidget::setAsInactiveChatroom()
{
setActive(false);
2014-06-28 02:22:53 +08:00
// status
2014-06-27 09:47:16 +08:00
QPalette pal;
pal.setColor(QPalette::WindowText, Style::getColor(Style::LightGrey));
2014-06-27 09:47:16 +08:00
nusers.setPalette(pal);
// name
2014-06-27 09:47:16 +08:00
QPalette pal2;
pal2.setColor(QPalette::WindowText, Style::getColor(Style::White));
2014-06-27 09:47:16 +08:00
name.setPalette(pal2);
avatar->setPixmap(QPixmap(":img/group.png"), Qt::transparent);
2014-06-27 09:47:16 +08:00
}
void GroupWidget::updateStatusLight()
{
Group *g = GroupList::findGroup(groupId);
if (Settings::getInstance().getUseNativeDecoration())
{
if (g->hasNewMessages == 0)
{
statusPic.setPixmap(QPixmap(":img/status/dot_online.png"));
} else {
2014-10-01 05:45:33 +08:00
if (g->userWasMentioned == 0)
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
else
statusPic.setPixmap(QPixmap(":img/status/dot_online_notification.png"));
}
} else {
if (g->hasNewMessages == 0)
{
statusPic.setPixmap(QPixmap(":img/status/dot_groupchat.png"));
} else {
2014-10-01 05:45:33 +08:00
if (g->userWasMentioned == 0)
statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_newmessages.png"));
else
statusPic.setPixmap(QPixmap(":img/status/dot_groupchat_notification.png"));
}
}
}
void GroupWidget::setChatForm(Ui::MainWindow &ui)
{
Group* g = GroupList::findGroup(groupId);
g->chatForm->show(ui);
}
void GroupWidget::resetEventFlags()
{
Group* g = GroupList::findGroup(groupId);
g->hasNewMessages = 0;
g->userWasMentioned = 0;
}