2014-09-05 02:09:55 +08:00
|
|
|
/*
|
2016-11-28 21:33:38 +08:00
|
|
|
Copyright © 2014-2015 by The qTox Project Contributors
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2014-09-05 02:09:55 +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-09-05 02:09:55 +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-09-05 02:09:55 +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-09-05 02:09:55 +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-09-05 02:09:55 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "genericchatform.h"
|
2015-01-25 21:34:36 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
#include <QClipboard>
|
2016-06-30 18:29:30 +08:00
|
|
|
#include <QDebug>
|
2014-09-05 02:09:55 +08:00
|
|
|
#include <QFileDialog>
|
2014-11-02 17:41:58 +08:00
|
|
|
#include <QHBoxLayout>
|
2015-06-06 04:08:29 +08:00
|
|
|
#include <QKeyEvent>
|
2016-06-30 18:29:30 +08:00
|
|
|
#include <QPushButton>
|
|
|
|
#include <QShortcut>
|
2015-07-21 05:57:46 +08:00
|
|
|
#include <QSplitter>
|
2016-12-25 18:55:23 +08:00
|
|
|
#include <QToolButton>
|
2015-01-25 21:34:36 +08:00
|
|
|
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/chatlog/chatlog.h"
|
|
|
|
#include "src/chatlog/content/timestamp.h"
|
|
|
|
#include "src/core/core.h"
|
|
|
|
#include "src/friend.h"
|
|
|
|
#include "src/friendlist.h"
|
|
|
|
#include "src/group.h"
|
|
|
|
#include "src/grouplist.h"
|
|
|
|
#include "src/persistence/settings.h"
|
|
|
|
#include "src/persistence/smileypack.h"
|
|
|
|
#include "src/video/genericnetcamview.h"
|
|
|
|
#include "src/widget/contentdialog.h"
|
|
|
|
#include "src/widget/contentlayout.h"
|
|
|
|
#include "src/widget/emoticonswidget.h"
|
|
|
|
#include "src/widget/maskablepixmapwidget.h"
|
|
|
|
#include "src/widget/style.h"
|
|
|
|
#include "src/widget/tool/chattextedit.h"
|
|
|
|
#include "src/widget/tool/croppinglabel.h"
|
|
|
|
#include "src/widget/tool/flyoutoverlaywidget.h"
|
|
|
|
#include "src/widget/translator.h"
|
|
|
|
#include "src/widget/widget.h"
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2016-12-13 04:00:51 +08:00
|
|
|
/**
|
|
|
|
* @class GenericChatForm
|
|
|
|
* @brief Parent class for all chatforms. It's provide the minimum required UI
|
|
|
|
* elements and methods to work with chat messages.
|
|
|
|
*
|
|
|
|
* TODO: reword
|
|
|
|
* @var GenericChatForm::historyBaselineDate
|
|
|
|
* @brief Used by HistoryKeeper to load messages from t to historyBaselineDate
|
|
|
|
* (excluded)
|
|
|
|
*/
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
GenericChatForm::GenericChatForm(QWidget* parent)
|
|
|
|
: QWidget(parent, Qt::Window)
|
|
|
|
, audioInputFlag(false)
|
|
|
|
, audioOutputFlag(false)
|
2014-09-05 02:09:55 +08:00
|
|
|
{
|
|
|
|
curRow = 0;
|
2014-09-26 00:03:25 +08:00
|
|
|
headWidget = new QWidget();
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2014-09-10 00:28:07 +08:00
|
|
|
nameLabel = new CroppingLabel();
|
2014-10-10 03:20:06 +08:00
|
|
|
nameLabel->setObjectName("nameLabel");
|
2014-10-24 03:53:45 +08:00
|
|
|
nameLabel->setMinimumHeight(Style::getFont(Style::Medium).pixelSize());
|
2014-11-18 10:15:44 +08:00
|
|
|
nameLabel->setEditable(true);
|
2015-03-10 01:32:30 +08:00
|
|
|
nameLabel->setTextFormat(Qt::PlainText);
|
2014-10-01 02:10:42 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
avatar = new MaskablePixmapWidget(this, QSize(40, 40), ":/img/avatar_mask.svg");
|
|
|
|
QHBoxLayout *mainFootLayout = new QHBoxLayout(), *headLayout = new QHBoxLayout();
|
2015-03-10 01:32:30 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
QVBoxLayout *mainLayout = new QVBoxLayout(), *footButtonsSmall = new QVBoxLayout(),
|
2015-01-06 22:36:03 +08:00
|
|
|
*micButtonsLayout = new QVBoxLayout();
|
2017-02-26 19:52:45 +08:00
|
|
|
headTextLayout = new QVBoxLayout();
|
2015-03-10 01:32:30 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
QGridLayout* buttonsLayout = new QGridLayout();
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2014-11-12 21:11:25 +08:00
|
|
|
chatWidget = new ChatLog(this);
|
2015-01-25 21:06:06 +08:00
|
|
|
chatWidget->setBusyNotification(ChatMessage::createBusyNotification());
|
2014-09-06 03:27:26 +08:00
|
|
|
|
2016-08-08 19:40:55 +08:00
|
|
|
// settings
|
|
|
|
const Settings& s = Settings::getInstance();
|
2017-02-26 19:52:45 +08:00
|
|
|
connect(&s, &Settings::emojiFontPointSizeChanged, chatWidget, &ChatLog::forceRelayout);
|
|
|
|
connect(&s, &Settings::chatMessageFontChanged, this, &GenericChatForm::onChatMessageFontChanged);
|
2015-02-15 18:43:01 +08:00
|
|
|
|
2014-09-05 02:09:55 +08:00
|
|
|
msgEdit = new ChatTextEdit();
|
|
|
|
|
|
|
|
sendButton = new QPushButton();
|
|
|
|
emoteButton = new QPushButton();
|
|
|
|
|
2014-10-24 03:53:45 +08:00
|
|
|
// Setting the sizes in the CSS doesn't work (glitch with high DPIs)
|
2014-09-05 02:09:55 +08:00
|
|
|
fileButton = new QPushButton();
|
2015-03-25 09:48:26 +08:00
|
|
|
screenshotButton = new QPushButton;
|
2014-09-05 02:09:55 +08:00
|
|
|
callButton = new QPushButton();
|
2017-02-26 19:52:45 +08:00
|
|
|
callButton->setFixedSize(50, 40);
|
2016-08-29 21:48:38 +08:00
|
|
|
|
2014-09-05 02:09:55 +08:00
|
|
|
videoButton = new QPushButton();
|
2017-02-26 19:52:45 +08:00
|
|
|
videoButton->setFixedSize(50, 40);
|
2016-08-29 21:48:38 +08:00
|
|
|
|
2016-12-25 18:55:23 +08:00
|
|
|
volButton = new QToolButton();
|
2016-08-29 21:48:38 +08:00
|
|
|
volButton->setFixedSize(22, 18);
|
|
|
|
|
2016-12-25 18:55:23 +08:00
|
|
|
micButton = new QToolButton();
|
2016-08-29 21:48:38 +08:00
|
|
|
micButton->setFixedSize(22, 18);
|
|
|
|
// TODO: Make updateCallButtons (see ChatForm) abstract
|
|
|
|
// and call here to set tooltips.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
fileFlyout = new FlyoutOverlayWidget;
|
2017-02-26 19:52:45 +08:00
|
|
|
QHBoxLayout* fileLayout = new QHBoxLayout(fileFlyout);
|
2015-03-25 09:48:26 +08:00
|
|
|
fileLayout->addWidget(screenshotButton);
|
|
|
|
fileLayout->setContentsMargins(0, 0, 0, 0);
|
2015-03-10 01:32:30 +08:00
|
|
|
|
2014-09-05 02:09:55 +08:00
|
|
|
footButtonsSmall->setSpacing(2);
|
2015-03-25 09:48:26 +08:00
|
|
|
fileLayout->setSpacing(0);
|
|
|
|
fileLayout->setMargin(0);
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2017-02-03 11:35:45 +08:00
|
|
|
msgEdit->setStyleSheet(Style::getStylesheet(":/ui/msgEdit/msgEdit.css")
|
2017-02-26 19:52:45 +08:00
|
|
|
+ fontToCss(s.getChatMessageFont(), "QTextEdit"));
|
2014-09-05 02:09:55 +08:00
|
|
|
msgEdit->setFixedHeight(50);
|
|
|
|
msgEdit->setFrameStyle(QFrame::NoFrame);
|
|
|
|
|
2014-10-01 02:10:42 +08:00
|
|
|
sendButton->setStyleSheet(Style::getStylesheet(":/ui/sendButton/sendButton.css"));
|
|
|
|
fileButton->setStyleSheet(Style::getStylesheet(":/ui/fileButton/fileButton.css"));
|
2017-02-26 19:52:45 +08:00
|
|
|
screenshotButton->setStyleSheet(
|
|
|
|
Style::getStylesheet(":/ui/screenshotButton/screenshotButton.css"));
|
2014-10-01 02:10:42 +08:00
|
|
|
emoteButton->setStyleSheet(Style::getStylesheet(":/ui/emoteButton/emoteButton.css"));
|
2014-09-05 02:09:55 +08:00
|
|
|
|
|
|
|
callButton->setObjectName("green");
|
2014-10-01 02:10:42 +08:00
|
|
|
callButton->setStyleSheet(Style::getStylesheet(":/ui/callButton/callButton.css"));
|
2014-09-05 02:09:55 +08:00
|
|
|
|
|
|
|
videoButton->setObjectName("green");
|
2014-10-01 02:10:42 +08:00
|
|
|
videoButton->setStyleSheet(Style::getStylesheet(":/ui/videoButton/videoButton.css"));
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2014-10-01 02:10:42 +08:00
|
|
|
QString volButtonStylesheet = Style::getStylesheet(":/ui/volButton/volButton.css");
|
2015-02-23 03:37:00 +08:00
|
|
|
volButton->setObjectName("grey");
|
2014-09-05 02:09:55 +08:00
|
|
|
volButton->setStyleSheet(volButtonStylesheet);
|
|
|
|
|
2014-10-01 02:10:42 +08:00
|
|
|
QString micButtonStylesheet = Style::getStylesheet(":/ui/micButton/micButton.css");
|
2015-02-23 03:37:00 +08:00
|
|
|
micButton->setObjectName("grey");
|
2014-09-05 02:09:55 +08:00
|
|
|
micButton->setStyleSheet(micButtonStylesheet);
|
|
|
|
|
2014-09-26 00:03:25 +08:00
|
|
|
setLayout(mainLayout);
|
2015-07-21 05:57:46 +08:00
|
|
|
|
|
|
|
bodySplitter = new QSplitter(Qt::Vertical, this);
|
2015-08-19 01:40:11 +08:00
|
|
|
connect(bodySplitter, &QSplitter::splitterMoved, this, &GenericChatForm::onSplitterMoved);
|
2015-07-23 02:50:39 +08:00
|
|
|
|
|
|
|
QWidget* contentWidget = new QWidget(this);
|
|
|
|
QVBoxLayout* contentLayout = new QVBoxLayout(contentWidget);
|
|
|
|
contentLayout->addWidget(chatWidget);
|
|
|
|
contentLayout->addLayout(mainFootLayout);
|
|
|
|
bodySplitter->addWidget(contentWidget);
|
2015-07-21 05:57:46 +08:00
|
|
|
|
|
|
|
mainLayout->addWidget(bodySplitter);
|
2014-09-05 02:09:55 +08:00
|
|
|
mainLayout->setMargin(0);
|
|
|
|
|
|
|
|
footButtonsSmall->addWidget(emoteButton);
|
|
|
|
footButtonsSmall->addWidget(fileButton);
|
|
|
|
|
|
|
|
mainFootLayout->addWidget(msgEdit);
|
|
|
|
mainFootLayout->addLayout(footButtonsSmall);
|
|
|
|
mainFootLayout->addSpacing(5);
|
|
|
|
mainFootLayout->addWidget(sendButton);
|
|
|
|
mainFootLayout->setSpacing(0);
|
2015-03-10 01:32:30 +08:00
|
|
|
|
|
|
|
headTextLayout->addStretch();
|
2014-12-17 19:36:34 +08:00
|
|
|
headTextLayout->addWidget(nameLabel);
|
2015-01-06 22:36:03 +08:00
|
|
|
headTextLayout->addStretch();
|
2015-03-10 01:32:30 +08:00
|
|
|
|
2016-08-29 21:48:38 +08:00
|
|
|
micButtonsLayout->setSpacing(4);
|
2015-01-06 22:36:03 +08:00
|
|
|
micButtonsLayout->addWidget(micButton, Qt::AlignTop | Qt::AlignRight);
|
|
|
|
micButtonsLayout->addWidget(volButton, Qt::AlignTop | Qt::AlignRight);
|
2015-03-10 01:32:30 +08:00
|
|
|
|
2015-01-26 00:18:20 +08:00
|
|
|
buttonsLayout->addLayout(micButtonsLayout, 0, 0, 2, 1, Qt::AlignTop | Qt::AlignRight);
|
2015-01-06 22:36:03 +08:00
|
|
|
buttonsLayout->addWidget(callButton, 0, 1, 2, 1, Qt::AlignTop);
|
|
|
|
buttonsLayout->addWidget(videoButton, 0, 2, 2, 1, Qt::AlignTop);
|
2015-01-26 00:18:20 +08:00
|
|
|
buttonsLayout->setVerticalSpacing(0);
|
|
|
|
buttonsLayout->setHorizontalSpacing(4);
|
2015-03-10 01:32:30 +08:00
|
|
|
|
2015-02-25 02:39:44 +08:00
|
|
|
headLayout->addWidget(avatar);
|
2014-11-02 17:41:58 +08:00
|
|
|
headLayout->addSpacing(5);
|
2015-02-25 02:39:44 +08:00
|
|
|
headLayout->addLayout(headTextLayout);
|
|
|
|
headLayout->addLayout(buttonsLayout);
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2015-01-06 22:36:03 +08:00
|
|
|
headWidget->setLayout(headLayout);
|
2015-03-10 01:32:30 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
// Fix for incorrect layouts on OS X as per
|
|
|
|
// https://bugreports.qt-project.org/browse/QTBUG-14591
|
2014-09-05 02:09:55 +08:00
|
|
|
sendButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
|
|
|
fileButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
2015-03-25 09:48:26 +08:00
|
|
|
screenshotButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
2014-09-05 02:09:55 +08:00
|
|
|
emoteButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
2015-01-15 15:45:42 +08:00
|
|
|
micButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
|
|
|
volButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
|
|
|
callButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
|
|
|
videoButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
2014-09-05 02:09:55 +08:00
|
|
|
|
2015-01-27 02:32:33 +08:00
|
|
|
menu.addActions(chatWidget->actions());
|
2015-01-04 21:21:05 +08:00
|
|
|
menu.addSeparator();
|
2017-02-26 19:52:45 +08:00
|
|
|
saveChatAction =
|
|
|
|
menu.addAction(QIcon::fromTheme("document-save"), QString(), this, SLOT(onSaveLogClicked()));
|
|
|
|
clearAction =
|
|
|
|
menu.addAction(QIcon::fromTheme("edit-clear"), QString(), this, SLOT(clearChatArea(bool)));
|
2016-06-07 02:46:18 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
quoteAction = menu.addAction(QIcon(), QString(), this, SLOT(quoteSelectedText()));
|
2016-06-07 02:46:18 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
copyLinkAction = menu.addAction(QIcon(), QString(), this, SLOT(copyLink()));
|
2016-12-07 08:59:07 +08:00
|
|
|
|
2015-01-04 21:21:05 +08:00
|
|
|
menu.addSeparator();
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
connect(emoteButton, &QPushButton::clicked, this, &GenericChatForm::onEmoteButtonClicked);
|
|
|
|
connect(chatWidget, &ChatLog::customContextMenuRequested, this,
|
|
|
|
&GenericChatForm::onChatContextMenuRequested);
|
2014-10-10 03:20:06 +08:00
|
|
|
|
2015-02-28 02:25:27 +08:00
|
|
|
new QShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_L, this, SLOT(clearChatArea()));
|
2016-06-07 02:46:18 +08:00
|
|
|
new QShortcut(Qt::ALT + Qt::Key_Q, this, SLOT(quoteSelectedText()));
|
2015-02-28 02:25:27 +08:00
|
|
|
|
2015-01-02 20:04:59 +08:00
|
|
|
chatWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatArea.css"));
|
2014-10-10 03:20:06 +08:00
|
|
|
headWidget->setStyleSheet(Style::getStylesheet(":/ui/chatArea/chatHead.css"));
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
fileFlyout->setFixedSize(24, 24);
|
|
|
|
fileFlyout->setParent(this);
|
|
|
|
fileButton->installEventFilter(this);
|
2015-03-25 21:51:14 +08:00
|
|
|
fileFlyout->installEventFilter(this);
|
2015-06-06 03:37:01 +08:00
|
|
|
|
|
|
|
retranslateUi();
|
|
|
|
Translator::registerHandler(std::bind(&GenericChatForm::retranslateUi, this), this);
|
2015-08-19 01:40:11 +08:00
|
|
|
|
|
|
|
netcam = nullptr;
|
2015-06-06 03:37:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GenericChatForm::~GenericChatForm()
|
|
|
|
{
|
|
|
|
Translator::unregister(this);
|
2015-03-25 09:48:26 +08:00
|
|
|
}
|
|
|
|
|
2015-04-05 05:22:03 +08:00
|
|
|
void GenericChatForm::adjustFileMenuPosition()
|
|
|
|
{
|
2016-06-29 21:05:53 +08:00
|
|
|
QPoint pos = fileButton->mapTo(bodySplitter, QPoint());
|
2015-04-05 05:22:03 +08:00
|
|
|
QSize size = fileFlyout->size();
|
|
|
|
fileFlyout->move(pos.x() - size.width(), pos.y());
|
|
|
|
}
|
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
void GenericChatForm::showFileMenu()
|
|
|
|
{
|
2015-04-02 22:56:16 +08:00
|
|
|
if (!fileFlyout->isShown() && !fileFlyout->isBeingShown()) {
|
2015-04-05 05:22:03 +08:00
|
|
|
adjustFileMenuPosition();
|
2015-03-25 09:48:26 +08:00
|
|
|
}
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-04-02 22:56:16 +08:00
|
|
|
fileFlyout->animateShow();
|
2015-03-25 09:48:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GenericChatForm::hideFileMenu()
|
|
|
|
{
|
2016-07-07 17:55:53 +08:00
|
|
|
if (fileFlyout->isShown() || fileFlyout->isBeingShown())
|
2015-03-25 09:48:26 +08:00
|
|
|
fileFlyout->animateHide();
|
2014-09-05 02:09:55 +08:00
|
|
|
}
|
|
|
|
|
2014-11-08 21:46:26 +08:00
|
|
|
bool GenericChatForm::isEmpty()
|
2014-10-11 18:48:45 +08:00
|
|
|
{
|
2014-12-14 04:11:03 +08:00
|
|
|
return chatWidget->isEmpty();
|
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
ChatLog* GenericChatForm::getChatLog() const
|
2014-12-14 04:11:03 +08:00
|
|
|
{
|
|
|
|
return chatWidget;
|
2014-10-11 18:48:45 +08:00
|
|
|
}
|
|
|
|
|
2015-06-24 02:58:30 +08:00
|
|
|
QDate GenericChatForm::getLatestDate() const
|
|
|
|
{
|
|
|
|
ChatLine::Ptr chatLine = chatWidget->getLatestLine();
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
if (chatLine) {
|
2016-09-23 10:06:20 +08:00
|
|
|
Timestamp* timestamp = qobject_cast<Timestamp*>(chatLine->getContent(2));
|
2015-06-24 02:58:30 +08:00
|
|
|
|
|
|
|
if (timestamp)
|
|
|
|
return timestamp->getTime().date();
|
|
|
|
else
|
|
|
|
return QDate::currentDate();
|
|
|
|
}
|
|
|
|
|
|
|
|
return QDate();
|
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void GenericChatForm::setName(const QString& newName)
|
2014-09-05 02:09:55 +08:00
|
|
|
{
|
|
|
|
nameLabel->setText(newName);
|
2017-02-26 19:52:45 +08:00
|
|
|
nameLabel->setToolTip(
|
|
|
|
Qt::convertFromPlainText(newName, Qt::WhiteSpaceNormal)); // for overlength names
|
2014-09-05 02:09:55 +08:00
|
|
|
}
|
|
|
|
|
2015-06-17 02:25:19 +08:00
|
|
|
void GenericChatForm::show(ContentLayout* contentLayout)
|
2014-09-05 02:09:55 +08:00
|
|
|
{
|
2015-06-17 02:25:19 +08:00
|
|
|
contentLayout->mainContent->layout()->addWidget(this);
|
|
|
|
contentLayout->mainHead->layout()->addWidget(headWidget);
|
2014-09-05 02:09:55 +08:00
|
|
|
headWidget->show();
|
2014-09-26 00:03:25 +08:00
|
|
|
QWidget::show();
|
2014-09-05 02:09:55 +08:00
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void GenericChatForm::showEvent(QShowEvent*)
|
2015-06-06 04:08:29 +08:00
|
|
|
{
|
|
|
|
msgEdit->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GenericChatForm::event(QEvent* e)
|
|
|
|
{
|
|
|
|
// If the user accidentally starts typing outside of the msgEdit, focus it automatically
|
2017-02-26 19:52:45 +08:00
|
|
|
if (e->type() == QEvent::KeyRelease && !msgEdit->hasFocus()) {
|
2015-06-06 04:08:29 +08:00
|
|
|
QKeyEvent* ke = static_cast<QKeyEvent*>(e);
|
2015-06-07 23:05:55 +08:00
|
|
|
if ((ke->modifiers() == Qt::NoModifier || ke->modifiers() == Qt::ShiftModifier)
|
2017-02-26 19:52:45 +08:00
|
|
|
&& !ke->text().isEmpty())
|
2015-06-06 04:08:29 +08:00
|
|
|
msgEdit->setFocus();
|
|
|
|
}
|
|
|
|
return QWidget::event(e);
|
|
|
|
}
|
|
|
|
|
2014-09-05 02:09:55 +08:00
|
|
|
void GenericChatForm::onChatContextMenuRequested(QPoint pos)
|
|
|
|
{
|
2016-04-14 06:51:34 +08:00
|
|
|
QWidget* sender = static_cast<QWidget*>(QObject::sender());
|
2014-09-05 02:09:55 +08:00
|
|
|
pos = sender->mapToGlobal(pos);
|
2015-01-04 21:21:05 +08:00
|
|
|
|
2016-12-07 08:59:07 +08:00
|
|
|
// If we right-clicked on a link, give the option to copy it
|
|
|
|
bool clickedOnLink = false;
|
|
|
|
Text* clickedText = qobject_cast<Text*>(chatWidget->getContentFromGlobalPos(pos));
|
2017-02-26 19:52:45 +08:00
|
|
|
if (clickedText) {
|
2016-12-07 08:59:07 +08:00
|
|
|
QPointF scenePos = chatWidget->mapToScene(chatWidget->mapFromGlobal(pos));
|
|
|
|
QString linkTarget = clickedText->getLinkAt(scenePos);
|
2017-02-26 19:52:45 +08:00
|
|
|
if (!linkTarget.isEmpty()) {
|
2016-12-07 08:59:07 +08:00
|
|
|
clickedOnLink = true;
|
|
|
|
copyLinkAction->setData(linkTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
copyLinkAction->setVisible(clickedOnLink);
|
|
|
|
|
2014-09-05 02:09:55 +08:00
|
|
|
menu.exec(pos);
|
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
ChatMessage::Ptr GenericChatForm::addMessage(const ToxPk& author, const QString& message,
|
|
|
|
bool isAction, const QDateTime& datetime, bool isSent)
|
2014-11-12 23:45:24 +08:00
|
|
|
{
|
2016-11-09 05:21:08 +08:00
|
|
|
const Core* core = Core::getInstance();
|
2016-12-30 06:14:48 +08:00
|
|
|
bool authorIsActiveProfile = author == core->getSelfId().getPublicKey();
|
2016-11-09 05:21:08 +08:00
|
|
|
QString authorStr = authorIsActiveProfile ? core->getUsername() : resolveToxId(author);
|
|
|
|
|
2014-12-14 04:11:03 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
if (getLatestDate() != QDate::currentDate()) {
|
2016-11-09 05:21:08 +08:00
|
|
|
const Settings& s = Settings::getInstance();
|
|
|
|
QString dateText = QDate::currentDate().toString(s.getDateFormat());
|
|
|
|
addSystemInfoMessage(dateText, ChatMessage::INFO, QDateTime());
|
|
|
|
}
|
2016-04-23 08:37:38 +08:00
|
|
|
|
2015-01-04 20:29:14 +08:00
|
|
|
ChatMessage::Ptr msg;
|
2017-02-26 19:52:45 +08:00
|
|
|
if (isAction) {
|
|
|
|
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ACTION,
|
|
|
|
authorIsActiveProfile);
|
2016-12-30 06:14:48 +08:00
|
|
|
previousId = ToxPk();
|
2017-02-26 19:52:45 +08:00
|
|
|
} else {
|
|
|
|
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL,
|
|
|
|
authorIsActiveProfile);
|
|
|
|
if ((author == previousId)
|
|
|
|
&& (prevMsgDateTime.secsTo(QDateTime::currentDateTime()) < getChatLog()->repNameAfter))
|
2015-01-05 01:21:35 +08:00
|
|
|
msg->hideSender();
|
2015-02-08 05:55:42 +08:00
|
|
|
|
|
|
|
previousId = author;
|
2015-03-26 05:31:39 +08:00
|
|
|
prevMsgDateTime = QDateTime::currentDateTime();
|
2015-01-05 01:21:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
insertChatMessage(msg);
|
2014-11-16 19:40:44 +08:00
|
|
|
|
2015-03-21 02:38:10 +08:00
|
|
|
if (isSent)
|
2014-11-14 01:27:32 +08:00
|
|
|
msg->markAsSent(datetime);
|
|
|
|
|
|
|
|
return msg;
|
2014-11-12 23:45:24 +08:00
|
|
|
}
|
2014-11-12 21:11:25 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
ChatMessage::Ptr GenericChatForm::addSelfMessage(const QString& message, bool isAction,
|
|
|
|
const QDateTime& datetime, bool isSent)
|
2014-11-12 23:45:24 +08:00
|
|
|
{
|
2017-02-26 19:52:45 +08:00
|
|
|
return addMessage(Core::getInstance()->getSelfId().getPublicKey(), message, isAction, datetime,
|
|
|
|
isSent);
|
2014-11-12 23:45:24 +08:00
|
|
|
}
|
2014-11-03 01:36:27 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void GenericChatForm::addAlertMessage(const ToxPk& author, QString message, QDateTime datetime)
|
2014-11-16 19:40:44 +08:00
|
|
|
{
|
2015-05-24 02:58:41 +08:00
|
|
|
QString authorStr = resolveToxId(author);
|
2016-12-30 06:14:48 +08:00
|
|
|
bool isSelf = author == Core::getInstance()->getSelfId().getPublicKey();
|
2017-02-26 19:52:45 +08:00
|
|
|
ChatMessage::Ptr msg =
|
|
|
|
ChatMessage::createChatMessage(authorStr, message, ChatMessage::ALERT, isSelf, datetime);
|
2015-01-05 01:21:35 +08:00
|
|
|
insertChatMessage(msg);
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
if ((author == previousId)
|
|
|
|
&& (prevMsgDateTime.secsTo(QDateTime::currentDateTime()) < getChatLog()->repNameAfter))
|
2015-01-05 01:21:35 +08:00
|
|
|
msg->hideSender();
|
2015-01-03 17:17:53 +08:00
|
|
|
|
2014-12-31 20:42:06 +08:00
|
|
|
previousId = author;
|
2015-03-26 05:31:39 +08:00
|
|
|
prevMsgDateTime = QDateTime::currentDateTime();
|
2014-11-16 19:40:44 +08:00
|
|
|
}
|
2014-10-20 19:05:45 +08:00
|
|
|
|
2014-09-05 23:05:57 +08:00
|
|
|
void GenericChatForm::onEmoteButtonClicked()
|
|
|
|
{
|
|
|
|
// don't show the smiley selection widget if there are no smileys available
|
|
|
|
if (SmileyPack::getInstance().getEmoticons().empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
EmoticonsWidget widget;
|
|
|
|
connect(&widget, SIGNAL(insertEmoticon(QString)), this, SLOT(onEmoteInsertRequested(QString)));
|
2016-04-23 18:44:19 +08:00
|
|
|
widget.installEventFilter(this);
|
2014-09-05 23:05:57 +08:00
|
|
|
|
|
|
|
QWidget* sender = qobject_cast<QWidget*>(QObject::sender());
|
2017-02-26 19:52:45 +08:00
|
|
|
if (sender) {
|
|
|
|
QPoint pos =
|
|
|
|
-QPoint(widget.sizeHint().width() / 2, widget.sizeHint().height()) - QPoint(0, 10);
|
2014-09-05 23:05:57 +08:00
|
|
|
widget.exec(sender->mapToGlobal(pos));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenericChatForm::onEmoteInsertRequested(QString str)
|
|
|
|
{
|
|
|
|
// insert the emoticon
|
|
|
|
QWidget* sender = qobject_cast<QWidget*>(QObject::sender());
|
|
|
|
if (sender)
|
|
|
|
msgEdit->insertPlainText(str);
|
|
|
|
|
|
|
|
msgEdit->setFocus(); // refocus so that we can continue typing
|
|
|
|
}
|
2014-09-11 05:00:45 +08:00
|
|
|
|
2015-01-04 21:21:05 +08:00
|
|
|
void GenericChatForm::onSaveLogClicked()
|
|
|
|
{
|
|
|
|
QString path = QFileDialog::getSaveFileName(0, tr("Save chat log"));
|
|
|
|
if (path.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QFile file(path);
|
|
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
|
|
|
return;
|
|
|
|
|
2015-01-25 21:34:36 +08:00
|
|
|
QString plainText;
|
|
|
|
auto lines = chatWidget->getLines();
|
2017-02-26 19:52:45 +08:00
|
|
|
for (ChatLine::Ptr l : lines) {
|
2016-09-23 10:06:20 +08:00
|
|
|
Timestamp* rightCol = qobject_cast<Timestamp*>(l->getContent(2));
|
2015-06-24 02:58:30 +08:00
|
|
|
|
|
|
|
if (!rightCol)
|
2016-07-31 22:17:11 +08:00
|
|
|
break;
|
2015-06-24 02:58:30 +08:00
|
|
|
|
2015-01-25 21:34:36 +08:00
|
|
|
ChatLineContent* middleCol = l->getContent(1);
|
|
|
|
ChatLineContent* leftCol = l->getContent(0);
|
|
|
|
|
2016-07-31 22:17:11 +08:00
|
|
|
QString timestamp = rightCol->getTime().isNull() ? tr("Not sent") : rightCol->getText();
|
2015-01-25 21:34:36 +08:00
|
|
|
QString nick = leftCol->getText();
|
|
|
|
QString msg = middleCol->getText();
|
|
|
|
|
|
|
|
plainText += QString("[%2] %1\n%3\n\n").arg(nick, timestamp, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
file.write(plainText.toUtf8());
|
2015-01-04 21:21:05 +08:00
|
|
|
file.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenericChatForm::onCopyLogClicked()
|
|
|
|
{
|
|
|
|
chatWidget->copySelectedText();
|
|
|
|
}
|
|
|
|
|
2014-09-11 05:00:45 +08:00
|
|
|
void GenericChatForm::focusInput()
|
|
|
|
{
|
|
|
|
msgEdit->setFocus();
|
|
|
|
}
|
2014-09-24 00:35:06 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void GenericChatForm::onChatMessageFontChanged(const QFont& font)
|
|
|
|
{
|
2017-02-05 11:10:27 +08:00
|
|
|
// chat log
|
|
|
|
chatWidget->fontChanged(font);
|
|
|
|
chatWidget->forceRelayout();
|
|
|
|
// message editor
|
|
|
|
msgEdit->setStyleSheet(Style::getStylesheet(":/ui/msgEdit/msgEdit.css")
|
2017-02-26 19:52:45 +08:00
|
|
|
+ fontToCss(font, "QTextEdit"));
|
2017-02-05 11:10:27 +08:00
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void GenericChatForm::addSystemInfoMessage(const QString& message, ChatMessage::SystemMessageType type,
|
|
|
|
const QDateTime& datetime)
|
2014-11-16 19:40:44 +08:00
|
|
|
{
|
2016-12-30 06:14:48 +08:00
|
|
|
previousId = ToxPk();
|
2015-01-05 01:21:35 +08:00
|
|
|
insertChatMessage(ChatMessage::createChatInfoMessage(message, type, datetime));
|
2014-11-16 19:40:44 +08:00
|
|
|
}
|
2014-09-29 00:39:26 +08:00
|
|
|
|
2015-02-28 02:25:27 +08:00
|
|
|
void GenericChatForm::clearChatArea()
|
|
|
|
{
|
|
|
|
clearChatArea(true);
|
|
|
|
}
|
|
|
|
|
2014-10-11 01:32:10 +08:00
|
|
|
void GenericChatForm::clearChatArea(bool notinform)
|
2014-10-11 00:54:21 +08:00
|
|
|
{
|
2014-11-16 19:40:44 +08:00
|
|
|
chatWidget->clear();
|
2016-12-30 06:14:48 +08:00
|
|
|
previousId = ToxPk();
|
2014-10-11 01:32:10 +08:00
|
|
|
|
2014-11-16 19:40:44 +08:00
|
|
|
if (!notinform)
|
2015-01-05 01:21:35 +08:00
|
|
|
addSystemInfoMessage(tr("Cleared"), ChatMessage::INFO, QDateTime::currentDateTime());
|
2014-10-11 01:32:10 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
earliestMessage = QDateTime(); // null
|
2015-02-16 23:48:22 +08:00
|
|
|
historyBaselineDate = QDateTime::currentDateTime();
|
2014-11-10 21:06:35 +08:00
|
|
|
|
2014-11-16 19:40:44 +08:00
|
|
|
emit chatAreaCleared();
|
2014-10-11 01:32:10 +08:00
|
|
|
}
|
|
|
|
|
2015-01-27 02:32:33 +08:00
|
|
|
void GenericChatForm::onSelectAllClicked()
|
|
|
|
{
|
|
|
|
chatWidget->selectAll();
|
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
QString GenericChatForm::resolveToxId(const ToxPk& id)
|
2014-11-23 23:55:49 +08:00
|
|
|
{
|
2017-01-06 19:02:54 +08:00
|
|
|
Friend* f = FriendList::findFriend(id);
|
2014-11-23 23:55:49 +08:00
|
|
|
if (f)
|
|
|
|
return f->getDisplayedName();
|
2016-07-07 17:55:53 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
for (Group* it : GroupList::getAllGroups()) {
|
2016-07-07 17:55:53 +08:00
|
|
|
QString res = it->resolveToxId(id);
|
|
|
|
if (res.size())
|
|
|
|
return res;
|
2014-11-23 23:55:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return QString();
|
|
|
|
}
|
2015-01-05 01:21:35 +08:00
|
|
|
|
|
|
|
void GenericChatForm::insertChatMessage(ChatMessage::Ptr msg)
|
|
|
|
{
|
2016-10-25 17:59:00 +08:00
|
|
|
chatWidget->insertChatlineAtBottom(std::static_pointer_cast<ChatLine>(msg));
|
2015-07-23 02:50:39 +08:00
|
|
|
emit messageInserted();
|
2015-01-05 01:21:35 +08:00
|
|
|
}
|
2015-03-26 05:31:39 +08:00
|
|
|
|
2015-04-05 05:06:06 +08:00
|
|
|
void GenericChatForm::hideEvent(QHideEvent* event)
|
|
|
|
{
|
|
|
|
hideFileMenu();
|
|
|
|
QWidget::hideEvent(event);
|
|
|
|
}
|
|
|
|
|
2015-04-05 05:22:03 +08:00
|
|
|
void GenericChatForm::resizeEvent(QResizeEvent* event)
|
|
|
|
{
|
|
|
|
adjustFileMenuPosition();
|
|
|
|
QWidget::resizeEvent(event);
|
|
|
|
}
|
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
bool GenericChatForm::eventFilter(QObject* object, QEvent* event)
|
|
|
|
{
|
2016-06-29 21:05:53 +08:00
|
|
|
EmoticonsWidget* ev = qobject_cast<EmoticonsWidget*>(object);
|
2017-02-26 19:52:45 +08:00
|
|
|
if (ev && event->type() == QEvent::KeyPress) {
|
2016-04-23 18:44:19 +08:00
|
|
|
QKeyEvent* key = static_cast<QKeyEvent*>(event);
|
|
|
|
msgEdit->sendKeyEvent(key);
|
|
|
|
msgEdit->setFocus();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-03-25 21:51:14 +08:00
|
|
|
if (object != this->fileButton && object != this->fileFlyout)
|
2015-03-25 09:48:26 +08:00
|
|
|
return false;
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-04-02 22:29:27 +08:00
|
|
|
if (!qobject_cast<QWidget*>(object)->isEnabled())
|
|
|
|
return false;
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
switch (event->type()) {
|
2015-03-25 09:48:26 +08:00
|
|
|
case QEvent::Enter:
|
|
|
|
showFileMenu();
|
|
|
|
break;
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
case QEvent::Leave: {
|
2016-06-29 21:05:53 +08:00
|
|
|
QPoint flyPos = fileFlyout->mapToGlobal(QPoint());
|
|
|
|
QSize flySize = fileFlyout->size();
|
|
|
|
|
|
|
|
QPoint filePos = fileButton->mapToGlobal(QPoint());
|
|
|
|
QSize fileSize = fileButton->size();
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2016-06-29 21:05:53 +08:00
|
|
|
QRect region = QRect(flyPos, flySize).united(QRect(filePos, fileSize));
|
|
|
|
|
|
|
|
if (!region.contains(QCursor::pos()))
|
2015-03-25 09:48:26 +08:00
|
|
|
hideFileMenu();
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2016-06-29 21:05:53 +08:00
|
|
|
break;
|
|
|
|
}
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
hideFileMenu();
|
|
|
|
break;
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2015-03-25 09:48:26 +08:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-06 03:37:01 +08:00
|
|
|
|
2015-08-19 01:40:11 +08:00
|
|
|
void GenericChatForm::onSplitterMoved(int, int)
|
|
|
|
{
|
|
|
|
if (netcam)
|
|
|
|
netcam->setShowMessages(bodySplitter->sizes()[1] == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenericChatForm::onShowMessagesClicked()
|
|
|
|
{
|
2017-02-26 19:52:45 +08:00
|
|
|
if (netcam) {
|
2015-08-19 01:40:11 +08:00
|
|
|
if (bodySplitter->sizes()[1] == 0)
|
|
|
|
bodySplitter->setSizes({1, 1});
|
|
|
|
else
|
|
|
|
bodySplitter->setSizes({1, 0});
|
|
|
|
|
|
|
|
onSplitterMoved(0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-07 02:46:18 +08:00
|
|
|
void GenericChatForm::quoteSelectedText()
|
|
|
|
{
|
|
|
|
QString selectedText = chatWidget->getSelectedText();
|
|
|
|
|
|
|
|
if (selectedText.isEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// forming pretty quote text
|
|
|
|
// 1. insert "> " to the begining of quote;
|
|
|
|
// 2. replace all possible line terminators with "\n> ";
|
|
|
|
// 3. append new line to the end of quote.
|
|
|
|
QString quote = selectedText;
|
|
|
|
|
|
|
|
quote.insert(0, "> ");
|
|
|
|
quote.replace(QRegExp(QString("\r\n|[\r\n\u2028\u2029]")), QString("\n> "));
|
|
|
|
quote.append("\n");
|
|
|
|
|
|
|
|
msgEdit->append(quote);
|
|
|
|
}
|
|
|
|
|
2016-12-07 08:59:07 +08:00
|
|
|
/**
|
|
|
|
* @brief Callback of GenericChatForm::copyLinkAction
|
|
|
|
*/
|
|
|
|
void GenericChatForm::copyLink()
|
|
|
|
{
|
|
|
|
QString linkText = copyLinkAction->data().toString();
|
|
|
|
QApplication::clipboard()->setText(linkText);
|
|
|
|
}
|
|
|
|
|
2015-06-06 03:37:01 +08:00
|
|
|
void GenericChatForm::retranslateUi()
|
|
|
|
{
|
2015-10-03 19:22:34 +08:00
|
|
|
QString callObjectName = callButton->objectName();
|
|
|
|
QString videoObjectName = videoButton->objectName();
|
|
|
|
|
|
|
|
if (callObjectName == QStringLiteral("green"))
|
|
|
|
callButton->setToolTip(tr("Start audio call"));
|
|
|
|
else if (callObjectName == QStringLiteral("yellow"))
|
|
|
|
callButton->setToolTip(tr("Accept audio call"));
|
|
|
|
else if (callObjectName == QStringLiteral("red"))
|
|
|
|
callButton->setToolTip(tr("End audio call"));
|
|
|
|
|
|
|
|
if (videoObjectName == QStringLiteral("green"))
|
|
|
|
videoButton->setToolTip(tr("Start video call"));
|
|
|
|
else if (videoObjectName == QStringLiteral("yellow"))
|
|
|
|
videoButton->setToolTip(tr("Accept video call"));
|
|
|
|
else if (videoObjectName == QStringLiteral("red"))
|
|
|
|
videoButton->setToolTip(tr("End video call"));
|
|
|
|
|
2015-06-06 03:37:01 +08:00
|
|
|
sendButton->setToolTip(tr("Send message"));
|
|
|
|
emoteButton->setToolTip(tr("Smileys"));
|
|
|
|
fileButton->setToolTip(tr("Send file(s)"));
|
|
|
|
screenshotButton->setToolTip(tr("Send a screenshot"));
|
|
|
|
saveChatAction->setText(tr("Save chat log"));
|
|
|
|
clearAction->setText(tr("Clear displayed messages"));
|
2016-06-07 02:46:18 +08:00
|
|
|
quoteAction->setText(tr("Quote selected text"));
|
2016-12-07 08:59:07 +08:00
|
|
|
copyLinkAction->setText(tr("Copy link address"));
|
2015-06-06 03:37:01 +08:00
|
|
|
}
|
2015-08-19 01:40:11 +08:00
|
|
|
|
2017-02-03 11:35:45 +08:00
|
|
|
QString GenericChatForm::fontToCss(const QFont& font, const char* name)
|
|
|
|
{
|
2017-03-28 00:35:55 +08:00
|
|
|
return QString("%1{font-family: \"%2\"; font-size: %3px; font-style: \"%4\"; font-weight: normal;}")
|
2017-02-03 11:35:45 +08:00
|
|
|
.arg(name)
|
|
|
|
.arg(font.family())
|
|
|
|
.arg(font.pixelSize())
|
2017-02-26 19:52:45 +08:00
|
|
|
.arg(font.style() == QFont::StyleNormal ? "normal" : font.style() == QFont::StyleItalic
|
|
|
|
? "italic"
|
2017-03-28 00:35:55 +08:00
|
|
|
: "oblique");
|
2017-02-03 11:35:45 +08:00
|
|
|
}
|
|
|
|
|
2015-08-19 01:40:11 +08:00
|
|
|
void GenericChatForm::showNetcam()
|
|
|
|
{
|
|
|
|
if (!netcam)
|
|
|
|
netcam = createNetcam();
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
connect(netcam, &GenericNetCamView::showMessageClicked, this,
|
|
|
|
&GenericChatForm::onShowMessagesClicked);
|
2015-08-19 01:40:11 +08:00
|
|
|
|
|
|
|
bodySplitter->insertWidget(0, netcam);
|
|
|
|
bodySplitter->setCollapsible(0, false);
|
2016-06-30 18:29:30 +08:00
|
|
|
|
|
|
|
QSize minSize = netcam->getSurfaceMinSize();
|
|
|
|
ContentDialog* current = ContentDialog::current();
|
|
|
|
if (current)
|
|
|
|
current->onVideoShow(minSize);
|
2015-08-19 01:40:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void GenericChatForm::hideNetcam()
|
|
|
|
{
|
|
|
|
if (!netcam)
|
|
|
|
return;
|
2015-10-11 14:38:44 +08:00
|
|
|
|
2016-06-30 18:29:30 +08:00
|
|
|
ContentDialog* current = ContentDialog::current();
|
|
|
|
if (current)
|
|
|
|
current->onVideoHide();
|
|
|
|
|
2015-10-11 14:38:44 +08:00
|
|
|
netcam->close();
|
2015-08-19 01:40:11 +08:00
|
|
|
netcam->hide();
|
|
|
|
delete netcam;
|
|
|
|
netcam = nullptr;
|
|
|
|
}
|