mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
initial merging common parts of chatforms' widget
This commit is contained in:
parent
22d792b5dc
commit
02da6803f1
6
qtox.pro
6
qtox.pro
@ -101,7 +101,8 @@ HEADERS += widget/form/addfriendform.h \
|
||||
widget/adjustingscrollarea.h \
|
||||
widget/croppinglabel.h \
|
||||
widget/friendlistwidget.h \
|
||||
widget/genericchatroomwidget.h
|
||||
widget/genericchatroomwidget.h \
|
||||
widget/form/genericchatform.h
|
||||
|
||||
SOURCES += \
|
||||
widget/form/addfriendform.cpp \
|
||||
@ -134,4 +135,5 @@ SOURCES += \
|
||||
widget/croppinglabel.cpp \
|
||||
widget/friendlistwidget.cpp \
|
||||
coreav.cpp \
|
||||
widget/genericchatroomwidget.cpp
|
||||
widget/genericchatroomwidget.cpp \
|
||||
widget/form/genericchatform.cpp
|
||||
|
@ -32,124 +32,16 @@
|
||||
#include <QMessageBox>
|
||||
|
||||
ChatForm::ChatForm(Friend* chatFriend)
|
||||
: f(chatFriend), curRow{0}, lockSliderToBottom{true}
|
||||
: f(chatFriend)
|
||||
{
|
||||
main = new QWidget(), head = new QWidget(), chatAreaWidget = new QWidget();
|
||||
name = new QLabel(), avatar = new QLabel(), statusMessage = new QLabel();
|
||||
headLayout = new QHBoxLayout(), mainFootLayout = new QHBoxLayout();
|
||||
headTextLayout = new QVBoxLayout(), mainLayout = new QVBoxLayout(),
|
||||
footButtonsSmall = new QVBoxLayout(), volMicLayout = new QVBoxLayout();
|
||||
mainChatLayout = new QGridLayout();
|
||||
msgEdit = new ChatTextEdit();
|
||||
sendButton = new QPushButton(), fileButton = new QPushButton(), emoteButton = new QPushButton(),
|
||||
callButton = new QPushButton(), videoButton = new QPushButton(),
|
||||
volButton = new QPushButton(), micButton = new QPushButton();
|
||||
chatArea = new QScrollArea();
|
||||
nameLabel->setText(f->getName());
|
||||
avatarLabel->setPixmap(QPixmap(":/img/contact_dark.png"));
|
||||
|
||||
statusMessageLabel = new QLabel();
|
||||
netcam = new NetCamView();
|
||||
audioInputFlag = false;
|
||||
|
||||
QFont bold;
|
||||
bold.setBold(true);
|
||||
name->setText(chatFriend->widget->name.text());
|
||||
name->setFont(bold);
|
||||
statusMessage->setText(chatFriend->widget->statusMessage.text());
|
||||
|
||||
// No real avatar support in toxcore, better draw a pretty picture
|
||||
//avatar->setPixmap(*chatFriend->widget->avatar.pixmap());
|
||||
avatar->setPixmap(QPixmap(":/img/contact_dark.png"));
|
||||
|
||||
chatAreaWidget->setLayout(mainChatLayout);
|
||||
chatAreaWidget->setStyleSheet(Style::get(":/ui/chatArea/chatArea.css"));
|
||||
|
||||
chatArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
chatArea->setWidgetResizable(true);
|
||||
chatArea->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
chatArea->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
mainChatLayout->setColumnStretch(1,1);
|
||||
mainChatLayout->setSpacing(5);
|
||||
|
||||
footButtonsSmall->setSpacing(2);
|
||||
|
||||
msgEdit->setStyleSheet(Style::get(":/ui/msgEdit/msgEdit.css"));
|
||||
msgEdit->setFixedHeight(50);
|
||||
msgEdit->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
sendButton->setStyleSheet(Style::get(":/ui/sendButton/sendButton.css"));
|
||||
fileButton->setStyleSheet(Style::get(":/ui/fileButton/fileButton.css"));
|
||||
emoteButton->setStyleSheet(Style::get(":/ui/emoteButton/emoteButton.css"));
|
||||
|
||||
callButton->setObjectName("green");
|
||||
callButton->setStyleSheet(Style::get(":/ui/callButton/callButton.css"));
|
||||
|
||||
videoButton->setObjectName("green");
|
||||
videoButton->setStyleSheet(Style::get(":/ui/videoButton/videoButton.css"));
|
||||
|
||||
QString volButtonStylesheet = "";
|
||||
try
|
||||
{
|
||||
QFile f(":/ui/volButton/volButton.css");
|
||||
f.open(QFile::ReadOnly | QFile::Text);
|
||||
QTextStream volButtonStylesheetStream(&f);
|
||||
volButtonStylesheet = volButtonStylesheetStream.readAll();
|
||||
}
|
||||
catch (int e) {}
|
||||
volButton->setObjectName("green");
|
||||
volButton->setStyleSheet(volButtonStylesheet);
|
||||
|
||||
QString micButtonStylesheet = "";
|
||||
try
|
||||
{
|
||||
QFile f(":/ui/micButton/micButton.css");
|
||||
f.open(QFile::ReadOnly | QFile::Text);
|
||||
QTextStream micButtonStylesheetStream(&f);
|
||||
micButtonStylesheet = micButtonStylesheetStream.readAll();
|
||||
}
|
||||
catch (int e) {}
|
||||
micButton->setObjectName("green");
|
||||
micButton->setStyleSheet(micButtonStylesheet);
|
||||
|
||||
main->setLayout(mainLayout);
|
||||
mainLayout->addWidget(chatArea);
|
||||
mainLayout->addLayout(mainFootLayout);
|
||||
mainLayout->setMargin(0);
|
||||
|
||||
footButtonsSmall->addWidget(emoteButton);
|
||||
footButtonsSmall->addWidget(fileButton);
|
||||
|
||||
mainFootLayout->addWidget(msgEdit);
|
||||
mainFootLayout->addLayout(footButtonsSmall);
|
||||
mainFootLayout->addSpacing(5);
|
||||
mainFootLayout->addWidget(sendButton);
|
||||
mainFootLayout->setSpacing(0);
|
||||
|
||||
head->setLayout(headLayout);
|
||||
headLayout->addWidget(avatar);
|
||||
headLayout->addLayout(headTextLayout);
|
||||
headLayout->addStretch();
|
||||
headLayout->addLayout(volMicLayout);
|
||||
headLayout->addWidget(callButton);
|
||||
headLayout->addWidget(videoButton);
|
||||
|
||||
volMicLayout->addWidget(micButton);
|
||||
volMicLayout->addWidget(volButton);
|
||||
|
||||
headTextLayout->addWidget(statusMessageLabel);
|
||||
headTextLayout->addStretch();
|
||||
headTextLayout->addWidget(name);
|
||||
headTextLayout->addWidget(statusMessage);
|
||||
headTextLayout->addStretch();
|
||||
|
||||
chatArea->setWidget(chatAreaWidget);
|
||||
|
||||
//Fix for incorrect layouts on OS X as per
|
||||
//https://bugreports.qt-project.org/browse/QTBUG-14591
|
||||
sendButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
fileButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
emoteButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
// callButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
// videoButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
// msgEdit->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
// chatArea->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
|
||||
connect(Widget::getInstance()->getCore(), &Core::fileSendStarted, this, &ChatForm::startFileSend);
|
||||
connect(Widget::getInstance()->getCore(), &Core::videoFrameReceived, netcam, &NetCamView::updateDisplay);
|
||||
@ -166,29 +58,13 @@ ChatForm::ChatForm(Friend* chatFriend)
|
||||
|
||||
ChatForm::~ChatForm()
|
||||
{
|
||||
delete main;
|
||||
delete head;
|
||||
delete netcam;
|
||||
}
|
||||
|
||||
void ChatForm::show(Ui::MainWindow &ui)
|
||||
{
|
||||
ui.mainContent->layout()->addWidget(main);
|
||||
ui.mainHead->layout()->addWidget(head);
|
||||
main->show();
|
||||
head->show();
|
||||
}
|
||||
|
||||
void ChatForm::setName(QString newName)
|
||||
{
|
||||
name->setText(newName);
|
||||
name->setToolTip(newName); // for overlength names
|
||||
}
|
||||
|
||||
void ChatForm::setStatusMessage(QString newMessage)
|
||||
{
|
||||
statusMessage->setText(newMessage);
|
||||
statusMessage->setToolTip(newMessage); // for overlength messsages
|
||||
statusMessageLabel->setText(newMessage);
|
||||
statusMessageLabel->setToolTip(newMessage); // for overlength messsages
|
||||
}
|
||||
|
||||
void ChatForm::onSendTriggered()
|
||||
@ -204,7 +80,7 @@ void ChatForm::onSendTriggered()
|
||||
|
||||
void ChatForm::addFriendMessage(QString message)
|
||||
{
|
||||
QLabel *msgAuthor = new QLabel(name->text());
|
||||
QLabel *msgAuthor = new QLabel(nameLabel->text());
|
||||
QLabel *msgText = new QLabel(message);
|
||||
QLabel *msgDate = new QLabel(QTime::currentTime().toString("hh:mm"));
|
||||
|
||||
@ -299,13 +175,6 @@ void ChatForm::onAttachClicked()
|
||||
emit sendFile(f->friendId, fi.fileName(), path, filesize);
|
||||
}
|
||||
|
||||
void ChatForm::onSliderRangeChanged()
|
||||
{
|
||||
QScrollBar* scroll = chatArea->verticalScrollBar();
|
||||
if (lockSliderToBottom)
|
||||
scroll->setValue(scroll->maximum());
|
||||
}
|
||||
|
||||
void ChatForm::startFileSend(ToxFile file)
|
||||
{
|
||||
if (file.friendId != f->friendId)
|
||||
@ -661,47 +530,6 @@ void ChatForm::onCancelCallTriggered()
|
||||
emit cancelCall(callId, f->friendId);
|
||||
}
|
||||
|
||||
void ChatForm::onChatContextMenuRequested(QPoint pos)
|
||||
{
|
||||
QWidget* sender = (QWidget*)QObject::sender();
|
||||
pos = sender->mapToGlobal(pos);
|
||||
QMenu menu;
|
||||
menu.addAction(tr("Save chat log"), this, SLOT(onSaveLogClicked()));
|
||||
menu.exec(pos);
|
||||
}
|
||||
|
||||
void ChatForm::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;
|
||||
|
||||
QString log;
|
||||
QList<QLabel*> labels = chatAreaWidget->findChildren<QLabel*>();
|
||||
int i=0;
|
||||
for (QLabel* label : labels)
|
||||
{
|
||||
log += label->text();
|
||||
if (i==2)
|
||||
{
|
||||
i=0;
|
||||
log += '\n';
|
||||
}
|
||||
else
|
||||
{
|
||||
log += '\t';
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
file.write(log.toUtf8());
|
||||
file.close();
|
||||
}
|
||||
|
||||
void ChatForm::onEmoteButtonClicked()
|
||||
{
|
||||
// don't show the smiley selection widget if there are no smileys available
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include <QTime>
|
||||
#include <QPoint>
|
||||
|
||||
#include "genericchatform.h"
|
||||
#include "widget/tool/chattextedit.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "core.h"
|
||||
@ -37,21 +38,18 @@
|
||||
|
||||
struct Friend;
|
||||
|
||||
class ChatForm : public QObject
|
||||
class ChatForm : public GenericChatForm
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ChatForm(Friend* chatFriend);
|
||||
~ChatForm();
|
||||
void show(Ui::MainWindow &ui);
|
||||
void setName(QString newName);
|
||||
void setStatusMessage(QString newMessage);
|
||||
void addFriendMessage(QString message);
|
||||
void addMessage(QString author, QString message, QString date=QTime::currentTime().toString("hh:mm"));
|
||||
void addMessage(QLabel* author, QLabel* message, QLabel* date);
|
||||
|
||||
signals:
|
||||
void sendMessage(int, QString);
|
||||
void sendFile(int32_t friendId, QString, QString, long long);
|
||||
void startCall(int friendId);
|
||||
void startVideoCall(int friendId, bool video);
|
||||
@ -78,31 +76,19 @@ public slots:
|
||||
private slots:
|
||||
void onSendTriggered();
|
||||
void onAttachClicked();
|
||||
void onSliderRangeChanged();
|
||||
void onCallTriggered();
|
||||
void onVideoCallTriggered();
|
||||
void onAnswerCallTriggered();
|
||||
void onHangupCallTriggered();
|
||||
void onCancelCallTriggered();
|
||||
void onChatContextMenuRequested(QPoint pos);
|
||||
void onSaveLogClicked();
|
||||
void onEmoteButtonClicked();
|
||||
void onEmoteInsertRequested(QString str);
|
||||
|
||||
private:
|
||||
Friend* f;
|
||||
QHBoxLayout *headLayout, *mainFootLayout;
|
||||
QVBoxLayout *headTextLayout, *mainLayout, *footButtonsSmall, *volMicLayout;
|
||||
QGridLayout *mainChatLayout;
|
||||
QLabel *avatar, *name, *statusMessage;
|
||||
ChatTextEdit *msgEdit;
|
||||
QPushButton *sendButton, *fileButton, *emoteButton, *callButton, *videoButton, *volButton, *micButton;
|
||||
QScrollArea *chatArea;
|
||||
QWidget *main, *head, *chatAreaWidget;
|
||||
QString previousName;
|
||||
QLabel *statusMessageLabel;
|
||||
NetCamView* netcam;
|
||||
int curRow;
|
||||
bool lockSliderToBottom, audioInputFlag;
|
||||
bool audioInputFlag;
|
||||
int callId;
|
||||
};
|
||||
|
||||
|
232
widget/form/genericchatform.cpp
Normal file
232
widget/form/genericchatform.cpp
Normal file
@ -0,0 +1,232 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#include "genericchatform.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QScrollBar>
|
||||
#include <QFileDialog>
|
||||
#include <QTextStream>
|
||||
#include "style.h"
|
||||
|
||||
GenericChatForm::GenericChatForm(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
lockSliderToBottom = true;
|
||||
curRow = 0;
|
||||
|
||||
mainWidget = new QWidget(); headWidget = new QWidget(); chatAreaWidget = new QWidget();
|
||||
|
||||
nameLabel = new QLabel();
|
||||
avatarLabel = new QLabel();
|
||||
QHBoxLayout *headLayout = new QHBoxLayout(), *mainFootLayout = new QHBoxLayout();
|
||||
headTextLayout = new QVBoxLayout();
|
||||
QVBoxLayout *mainLayout = new QVBoxLayout();
|
||||
QVBoxLayout *footButtonsSmall = new QVBoxLayout(), *volMicLayout = new QVBoxLayout();
|
||||
mainChatLayout = new QGridLayout();
|
||||
|
||||
msgEdit = new ChatTextEdit();
|
||||
|
||||
sendButton = new QPushButton();
|
||||
emoteButton = new QPushButton();
|
||||
|
||||
fileButton = new QPushButton();
|
||||
callButton = new QPushButton();
|
||||
videoButton = new QPushButton();
|
||||
volButton = new QPushButton();
|
||||
micButton = new QPushButton();
|
||||
|
||||
chatArea = new QScrollArea();
|
||||
|
||||
QFont bold;
|
||||
bold.setBold(true);
|
||||
nameLabel->setFont(bold);
|
||||
|
||||
chatAreaWidget->setLayout(mainChatLayout);
|
||||
chatAreaWidget->setStyleSheet(Style::get(":/ui/chatArea/chatArea.css"));
|
||||
|
||||
chatArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
chatArea->setWidgetResizable(true);
|
||||
chatArea->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
chatArea->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
mainChatLayout->setColumnStretch(1,1);
|
||||
mainChatLayout->setSpacing(5);
|
||||
|
||||
footButtonsSmall->setSpacing(2);
|
||||
|
||||
msgEdit->setStyleSheet(Style::get(":/ui/msgEdit/msgEdit.css"));
|
||||
msgEdit->setFixedHeight(50);
|
||||
msgEdit->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
sendButton->setStyleSheet(Style::get(":/ui/sendButton/sendButton.css"));
|
||||
fileButton->setStyleSheet(Style::get(":/ui/fileButton/fileButton.css"));
|
||||
emoteButton->setStyleSheet(Style::get(":/ui/emoteButton/emoteButton.css"));
|
||||
|
||||
callButton->setObjectName("green");
|
||||
callButton->setStyleSheet(Style::get(":/ui/callButton/callButton.css"));
|
||||
|
||||
videoButton->setObjectName("green");
|
||||
videoButton->setStyleSheet(Style::get(":/ui/videoButton/videoButton.css"));
|
||||
|
||||
QString volButtonStylesheet = "";
|
||||
try
|
||||
{
|
||||
QFile f(":/ui/volButton/volButton.css");
|
||||
f.open(QFile::ReadOnly | QFile::Text);
|
||||
QTextStream volButtonStylesheetStream(&f);
|
||||
volButtonStylesheet = volButtonStylesheetStream.readAll();
|
||||
}
|
||||
catch (int e) {}
|
||||
|
||||
volButton->setObjectName("green");
|
||||
volButton->setStyleSheet(volButtonStylesheet);
|
||||
|
||||
QString micButtonStylesheet = "";
|
||||
try
|
||||
{
|
||||
QFile f(":/ui/micButton/micButton.css");
|
||||
f.open(QFile::ReadOnly | QFile::Text);
|
||||
QTextStream micButtonStylesheetStream(&f);
|
||||
micButtonStylesheet = micButtonStylesheetStream.readAll();
|
||||
}
|
||||
catch (int e) {}
|
||||
|
||||
micButton->setObjectName("green");
|
||||
micButton->setStyleSheet(micButtonStylesheet);
|
||||
|
||||
mainWidget->setLayout(mainLayout);
|
||||
mainLayout->addWidget(chatArea);
|
||||
mainLayout->addLayout(mainFootLayout);
|
||||
mainLayout->setMargin(0);
|
||||
|
||||
footButtonsSmall->addWidget(emoteButton);
|
||||
footButtonsSmall->addWidget(fileButton);
|
||||
|
||||
mainFootLayout->addWidget(msgEdit);
|
||||
mainFootLayout->addLayout(footButtonsSmall);
|
||||
mainFootLayout->addSpacing(5);
|
||||
mainFootLayout->addWidget(sendButton);
|
||||
mainFootLayout->setSpacing(0);
|
||||
|
||||
headWidget->setLayout(headLayout);
|
||||
headLayout->addWidget(avatarLabel);
|
||||
headLayout->addLayout(headTextLayout);
|
||||
headLayout->addStretch();
|
||||
headLayout->addLayout(volMicLayout);
|
||||
headLayout->addWidget(callButton);
|
||||
headLayout->addWidget(videoButton);
|
||||
|
||||
volMicLayout->addWidget(micButton);
|
||||
volMicLayout->addWidget(volButton);
|
||||
|
||||
headTextLayout->addStretch();
|
||||
headTextLayout->addWidget(nameLabel);
|
||||
// headTextLayout->addWidget(statusMessage);
|
||||
// headTextLayout->addStretch();
|
||||
|
||||
chatArea->setWidget(chatAreaWidget);
|
||||
|
||||
//Fix for incorrect layouts on OS X as per
|
||||
//https://bugreports.qt-project.org/browse/QTBUG-14591
|
||||
sendButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
fileButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
emoteButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
|
||||
// connect(Widget::getInstance()->getCore(), &Core::fileSendStarted, this, &ChatForm::startFileSend);
|
||||
// connect(Widget::getInstance()->getCore(), &Core::videoFrameReceived, netcam, &NetCamView::updateDisplay);
|
||||
// connect(sendButton, &QPushButton::clicked, this, &ChatForm::onSendTriggered);
|
||||
// connect(fileButton, &QPushButton::clicked, this, &ChatForm::onAttachClicked);
|
||||
// connect(callButton, &QPushButton::clicked, this, &ChatForm::onCallTriggered);
|
||||
// connect(videoButton, &QPushButton::clicked, this, &ChatForm::onVideoCallTriggered);
|
||||
// connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered);
|
||||
// connect(chatArea->verticalScrollBar(), &QScrollBar::rangeChanged, this, &ChatForm::onSliderRangeChanged);
|
||||
// connect(chatArea, &QScrollArea::customContextMenuRequested, this, &ChatForm::onChatContextMenuRequested);
|
||||
// connect(emoteButton, &QPushButton::clicked, this, &ChatForm::onEmoteButtonClicked);
|
||||
// connect(micButton, SIGNAL(clicked()), this, SLOT(onMicMuteToggle()));
|
||||
}
|
||||
|
||||
void GenericChatForm::setName(const QString &newName)
|
||||
{
|
||||
nameLabel->setText(newName);
|
||||
nameLabel->setToolTip(newName); // for overlength names
|
||||
}
|
||||
|
||||
void GenericChatForm::show(Ui::MainWindow &ui)
|
||||
{
|
||||
ui.mainContent->layout()->addWidget(mainWidget);
|
||||
ui.mainHead->layout()->addWidget(headWidget);
|
||||
mainWidget->show();
|
||||
headWidget->show();
|
||||
}
|
||||
|
||||
void GenericChatForm::onChatContextMenuRequested(QPoint pos)
|
||||
{
|
||||
QWidget* sender = (QWidget*)QObject::sender();
|
||||
pos = sender->mapToGlobal(pos);
|
||||
QMenu menu;
|
||||
menu.addAction(tr("Save chat log"), this, SLOT(onSaveLogClicked()));
|
||||
menu.exec(pos);
|
||||
}
|
||||
|
||||
void GenericChatForm::onSliderRangeChanged()
|
||||
{
|
||||
QScrollBar* scroll = chatArea->verticalScrollBar();
|
||||
if (lockSliderToBottom)
|
||||
scroll->setValue(scroll->maximum());
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
QString log;
|
||||
QList<QLabel*> labels = chatAreaWidget->findChildren<QLabel*>();
|
||||
int i=0;
|
||||
for (QLabel* label : labels)
|
||||
{
|
||||
log += label->text();
|
||||
if (i==2)
|
||||
{
|
||||
i=0;
|
||||
log += '\n';
|
||||
}
|
||||
else
|
||||
{
|
||||
log += '\t';
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
file.write(log.toUtf8());
|
||||
file.close();
|
||||
}
|
||||
|
||||
void GenericChatForm::addMessage(QString author, QString message, QString date)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
GenericChatForm::~GenericChatForm()
|
||||
{
|
||||
delete mainWidget;
|
||||
delete headWidget;
|
||||
}
|
72
widget/form/genericchatform.h
Normal file
72
widget/form/genericchatform.h
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef GENERICCHATFORM_H
|
||||
#define GENERICCHATFORM_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QLabel>
|
||||
#include <QPoint>
|
||||
#include <QScrollArea>
|
||||
#include <QTime>
|
||||
#include <QLabel>
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPushButton>
|
||||
#include <QGridLayout>
|
||||
|
||||
#include "widget/tool/chattextedit.h"
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
class GenericChatForm : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GenericChatForm(QObject *parent = 0);
|
||||
virtual ~GenericChatForm();
|
||||
|
||||
virtual void setName(const QString &newName);
|
||||
virtual void show(Ui::MainWindow &ui);
|
||||
virtual void addMessage(QString author, QString message, QString date=QTime::currentTime().toString("hh:mm"));
|
||||
|
||||
signals:
|
||||
void sendMessage(int, QString);
|
||||
|
||||
public slots:
|
||||
|
||||
protected slots:
|
||||
void onChatContextMenuRequested(QPoint pos);
|
||||
void onSliderRangeChanged();
|
||||
void onSaveLogClicked();
|
||||
|
||||
protected:
|
||||
QLabel *nameLabel, *avatarLabel;
|
||||
QWidget *mainWidget, *headWidget, *chatAreaWidget;
|
||||
QScrollArea *chatArea;
|
||||
QPushButton *fileButton, *emoteButton, *callButton, *videoButton, *volButton, *micButton;
|
||||
QGridLayout *mainChatLayout;
|
||||
QVBoxLayout *headTextLayout;
|
||||
ChatTextEdit *msgEdit;
|
||||
QPushButton *sendButton;
|
||||
QString previousName;
|
||||
int curRow;
|
||||
bool lockSliderToBottom;
|
||||
};
|
||||
|
||||
#endif // GENERICCHATFORM_H
|
@ -29,25 +29,25 @@
|
||||
#include <QFileDialog>
|
||||
|
||||
GroupChatForm::GroupChatForm(Group* chatGroup)
|
||||
: group(chatGroup), curRow{0}, lockSliderToBottom{true}
|
||||
: group(chatGroup)
|
||||
{
|
||||
main = new QWidget(), head = new QWidget(), chatAreaWidget = new QWidget();
|
||||
headLayout = new QHBoxLayout(), mainFootLayout = new QHBoxLayout();
|
||||
headTextLayout = new QVBoxLayout(), mainLayout = new QVBoxLayout();
|
||||
mainChatLayout = new QGridLayout();
|
||||
avatar = new QLabel(), name = new QLabel(), nusers = new QLabel(), namesList = new QLabel();
|
||||
msgEdit = new ChatTextEdit();
|
||||
sendButton = new QPushButton();
|
||||
chatArea = new QScrollArea();
|
||||
QFont bold;
|
||||
bold.setBold(true);
|
||||
nusers = new QLabel();
|
||||
namesList = new QLabel();
|
||||
|
||||
fileButton->setEnabled(false);
|
||||
callButton->setVisible(false);
|
||||
videoButton->setVisible(false);
|
||||
volButton->setVisible(false);
|
||||
micButton->setVisible(false);
|
||||
|
||||
QFont small;
|
||||
small.setPixelSize(10);
|
||||
name->setText(group->widget->name.text());
|
||||
name->setFont(bold);
|
||||
|
||||
nameLabel->setText(group->widget->name.text());
|
||||
nusers->setFont(small);
|
||||
nusers->setText(GroupChatForm::tr("%1 users in chat","Number of users in chat").arg(group->peers.size()));
|
||||
avatar->setPixmap(QPixmap(":/img/group.png"));
|
||||
avatarLabel->setPixmap(QPixmap(":/img/group_dark.png"));
|
||||
|
||||
QString names;
|
||||
for (QString& s : group->peers)
|
||||
names.append(s+", ");
|
||||
@ -55,54 +55,17 @@ GroupChatForm::GroupChatForm(Group* chatGroup)
|
||||
namesList->setText(names);
|
||||
namesList->setFont(small);
|
||||
|
||||
chatAreaWidget->setLayout(mainChatLayout);
|
||||
|
||||
chatArea->setStyleSheet(Style::get(":/ui/chatArea/chatArea.css"));
|
||||
chatArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
chatArea->setWidgetResizable(true);
|
||||
chatArea->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
chatArea->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
mainChatLayout->setColumnStretch(1,1);
|
||||
mainChatLayout->setSpacing(10);
|
||||
|
||||
msgEdit->setObjectName("group");
|
||||
msgEdit->setStyleSheet(Style::get(":/ui/msgEdit/msgEdit.css"));
|
||||
msgEdit->setFixedHeight(50);
|
||||
msgEdit->setFrameStyle(QFrame::NoFrame);
|
||||
|
||||
mainChatLayout->setColumnStretch(1,1);
|
||||
mainChatLayout->setHorizontalSpacing(10);
|
||||
|
||||
sendButton->setStyleSheet(Style::get(":/ui/sendButton/sendButton.css"));
|
||||
sendButton->setFixedSize(50, 50);
|
||||
|
||||
main->setLayout(mainLayout);
|
||||
mainLayout->addWidget(chatArea);
|
||||
mainLayout->addLayout(mainFootLayout);
|
||||
mainLayout->setMargin(0);
|
||||
|
||||
mainFootLayout->addWidget(msgEdit);
|
||||
mainFootLayout->addWidget(sendButton);
|
||||
|
||||
head->setLayout(headLayout);
|
||||
headLayout->addWidget(avatar);
|
||||
headLayout->addLayout(headTextLayout);
|
||||
headLayout->addStretch();
|
||||
headLayout->setMargin(0);
|
||||
|
||||
headTextLayout->addStretch();
|
||||
headTextLayout->addWidget(name);
|
||||
headTextLayout->addWidget(nusers);
|
||||
headTextLayout->addWidget(namesList);
|
||||
headTextLayout->setMargin(0);
|
||||
headTextLayout->setSpacing(0);
|
||||
headTextLayout->addStretch();
|
||||
|
||||
chatArea->setWidget(chatAreaWidget);
|
||||
|
||||
sendButton->setAttribute(Qt::WA_LayoutUsesWidgetRect);
|
||||
|
||||
connect(sendButton, SIGNAL(clicked()), this, SLOT(onSendTriggered()));
|
||||
connect(msgEdit, SIGNAL(enterPressed()), this, SLOT(onSendTriggered()));
|
||||
connect(chatArea->verticalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(onSliderRangeChanged()));
|
||||
@ -111,21 +74,7 @@ GroupChatForm::GroupChatForm(Group* chatGroup)
|
||||
|
||||
GroupChatForm::~GroupChatForm()
|
||||
{
|
||||
delete head;
|
||||
delete main;
|
||||
}
|
||||
|
||||
void GroupChatForm::show(Ui::MainWindow &ui)
|
||||
{
|
||||
ui.mainContent->layout()->addWidget(main);
|
||||
ui.mainHead->layout()->addWidget(head);
|
||||
main->show();
|
||||
head->show();
|
||||
}
|
||||
|
||||
void GroupChatForm::setName(QString newName)
|
||||
{
|
||||
name->setText(newName);
|
||||
}
|
||||
|
||||
void GroupChatForm::onSendTriggered()
|
||||
@ -203,13 +152,6 @@ void GroupChatForm::addMessage(QLabel* author, QLabel* message, QLabel* date)
|
||||
connect(date, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(onChatContextMenuRequested(QPoint)));
|
||||
}
|
||||
|
||||
void GroupChatForm::onSliderRangeChanged()
|
||||
{
|
||||
QScrollBar* scroll = chatArea->verticalScrollBar();
|
||||
if (lockSliderToBottom)
|
||||
scroll->setValue(scroll->maximum());
|
||||
}
|
||||
|
||||
void GroupChatForm::onUserListChanged()
|
||||
{
|
||||
nusers->setText(tr("%1 users in chat").arg(group->nPeers));
|
||||
@ -219,44 +161,3 @@ void GroupChatForm::onUserListChanged()
|
||||
names.chop(2);
|
||||
namesList->setText(names);
|
||||
}
|
||||
|
||||
void GroupChatForm::onChatContextMenuRequested(QPoint pos)
|
||||
{
|
||||
QWidget* sender = (QWidget*)QObject::sender();
|
||||
pos = sender->mapToGlobal(pos);
|
||||
QMenu menu;
|
||||
menu.addAction("Save chat log", this, SLOT(onSaveLogClicked()));
|
||||
menu.exec(pos);
|
||||
}
|
||||
|
||||
void GroupChatForm::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;
|
||||
|
||||
QString log;
|
||||
QList<QLabel*> labels = chatAreaWidget->findChildren<QLabel*>();
|
||||
int i=0;
|
||||
for (QLabel* label : labels)
|
||||
{
|
||||
log += label->text();
|
||||
if (i==2)
|
||||
{
|
||||
i=0;
|
||||
log += '\n';
|
||||
}
|
||||
else
|
||||
{
|
||||
log += '\t';
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
file.write(log.toUtf8());
|
||||
file.close();
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <QScrollArea>
|
||||
#include <QTime>
|
||||
|
||||
#include "genericchatform.h"
|
||||
#include "widget/tool/chattextedit.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
@ -34,41 +35,23 @@
|
||||
|
||||
class Group;
|
||||
|
||||
class GroupChatForm : public QObject
|
||||
class GroupChatForm : public GenericChatForm
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GroupChatForm(Group* chatGroup);
|
||||
~GroupChatForm();
|
||||
void show(Ui::MainWindow &ui);
|
||||
void setName(QString newName);
|
||||
void addGroupMessage(QString message, int peerId);
|
||||
void addMessage(QString author, QString message, QString date=QTime::currentTime().toString("hh:mm"));
|
||||
void addMessage(QLabel* author, QLabel* message, QLabel* date);
|
||||
void onUserListChanged();
|
||||
|
||||
signals:
|
||||
void sendMessage(int, QString);
|
||||
|
||||
private slots:
|
||||
void onSendTriggered();
|
||||
void onSliderRangeChanged();
|
||||
void onChatContextMenuRequested(QPoint pos);
|
||||
void onSaveLogClicked();
|
||||
|
||||
private:
|
||||
Group* group;
|
||||
QHBoxLayout *headLayout, *mainFootLayout;
|
||||
QVBoxLayout *headTextLayout, *mainLayout;
|
||||
QGridLayout *mainChatLayout;
|
||||
QLabel *avatar, *name, *nusers, *namesList;
|
||||
ChatTextEdit *msgEdit;
|
||||
QPushButton *sendButton;
|
||||
QScrollArea *chatArea;
|
||||
QWidget *main, *head, *chatAreaWidget;
|
||||
QString previousName;
|
||||
int curRow;
|
||||
bool lockSliderToBottom;
|
||||
QLabel *nusers, *namesList;
|
||||
};
|
||||
|
||||
#endif // GROUPCHATFORM_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user