1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00
This commit is contained in:
Dubslow 2014-09-10 17:37:39 -05:00
commit ca77520736
12 changed files with 114 additions and 78 deletions

BIN
audio/notification.pcm Normal file

Binary file not shown.

Binary file not shown.

View File

@ -28,7 +28,6 @@
#include <QFile>
#include <QSaveFile>
#include <QStandardPaths>
#include <QtEndian>
#include <QThread>
#include <QtConcurrent/QtConcurrent>
@ -781,7 +780,7 @@ void Core::bootstrapDht()
{
const Settings::DhtServer& dhtServer = dhtServerList[j % listSize];
if (tox_bootstrap_from_address(tox, dhtServer.address.toLatin1().data(),
qToBigEndian(dhtServer.port), CUserId(dhtServer.userId).data()) == 1)
dhtServer.port, CUserId(dhtServer.userId).data()) == 1)
qDebug() << QString("Core: Bootstraping from ")+dhtServer.name+QString(", addr ")+dhtServer.address.toLatin1().data()
+QString(", port ")+QString().setNum(dhtServer.port);
else

View File

@ -6,7 +6,6 @@
<file alias="DejaVuSans.ttf">res/DejaVuSans.ttf</file>
</qresource>
<qresource prefix="/">
<file>audio/notification.wav</file>
<file>img/icon.png</file>
<file>img/contact.png</file>
<file>img/contact_dark.png</file>
@ -134,5 +133,6 @@
<file>ui/fileTransferInstance/emptyLRedFileButton.png</file>
<file>ui/fileTransferInstance/emptyRGreenFileButton.png</file>
<file>ui/fileTransferInstance/emptyRRedFileButton.png</file>
<file>audio/notification.pcm</file>
</qresource>
</RCC>

View File

@ -33,7 +33,24 @@ ChatAreaWidget::ChatAreaWidget(QWidget *parent) :
setOpenLinks(false);
setAcceptRichText(false);
chatTextTable = textCursor().insertTable(1,3);
QTextTableFormat tableFormat;
tableFormat.setColumnWidthConstraints({QTextLength(QTextLength::VariableLength,0),
QTextLength(QTextLength::PercentageLength,100),
QTextLength(QTextLength::VariableLength,0)});
tableFormat.setBorderStyle(QTextFrameFormat::BorderStyle_None);
chatTextTable->setFormat(tableFormat);
chatTextTable->format().setCellSpacing(2);
chatTextTable->format().setWidth(QTextLength(QTextLength::PercentageLength,100));
nameFormat.setAlignment(Qt::AlignRight);
nameFormat.setNonBreakableLines(true);
dateFormat.setAlignment(Qt::AlignLeft);
dateFormat.setNonBreakableLines(true);
connect(this, &ChatAreaWidget::anchorClicked, this, &ChatAreaWidget::onAnchorClicked);
connect(verticalScrollBar(), SIGNAL(rangeChanged(int,int)), this, SLOT(onSliderRangeChanged()));
}
ChatAreaWidget::~ChatAreaWidget()
@ -84,13 +101,33 @@ void ChatAreaWidget::insertMessage(ChatAction *msgAction)
if (msgAction == nullptr)
return;
moveCursor(QTextCursor::End);
moveCursor(QTextCursor::PreviousCell);
QTextCursor cur = textCursor();
checkSlider();
int row = chatTextTable->rows() - 1;
chatTextTable->cellAt(row,0).firstCursorPosition().setBlockFormat(nameFormat);
chatTextTable->cellAt(row,2).firstCursorPosition().setBlockFormat(dateFormat);
QTextCursor cur = chatTextTable->cellAt(row,1).firstCursorPosition();
cur.clearSelection();
cur.setKeepPositionOnInsert(true);
insertHtml(msgAction->getHtml());
chatTextTable->cellAt(row,0).firstCursorPosition().insertHtml(msgAction->getName());
chatTextTable->cellAt(row,1).firstCursorPosition().insertHtml(msgAction->getMessage());
chatTextTable->cellAt(row,2).firstCursorPosition().insertHtml(msgAction->getDate());
chatTextTable->appendRows(1);
msgAction->setTextCursor(cur);
messages.append(msgAction);
}
void ChatAreaWidget::onSliderRangeChanged()
{
QScrollBar* scroll = verticalScrollBar();
if (lockSliderToBottom)
scroll->setValue(scroll->maximum());
}
void ChatAreaWidget::checkSlider()
{
QScrollBar* scroll = verticalScrollBar();
lockSliderToBottom = scroll && scroll->value() == scroll->maximum();
}

View File

@ -19,6 +19,7 @@
#include <QTextBrowser>
#include <QList>
#include <QTextTable>
class ChatAction;
@ -36,13 +37,18 @@ signals:
protected:
void mouseReleaseEvent(QMouseEvent * event);
public slots:
private slots:
void onAnchorClicked(const QUrl& url);
void onSliderRangeChanged();
private:
void checkSlider();
QList<ChatAction*> messages;
bool lockSliderToBottom;
int sliderPosition;
QTextTable *chatTextTable;
QTextBlockFormat nameFormat, dateFormat;
};
#endif // CHATAREAWIDGET_H

View File

@ -201,3 +201,8 @@ void GenericChatForm::onEmoteInsertRequested(QString str)
msgEdit->setFocus(); // refocus so that we can continue typing
}
void GenericChatForm::focusInput()
{
msgEdit->setFocus();
}

View File

@ -51,6 +51,7 @@ signals:
void sendMessage(int, QString);
public slots:
void focusInput();
protected slots:
void onChatContextMenuRequested(QPoint pos);

View File

@ -31,6 +31,7 @@ SettingsForm::SettingsForm()
QFont bold, small;
bold.setBold(true);
small.setPixelSize(13);
small.setKerning(false);
headLabel.setText(tr("User Settings","\"Headline\" of the window"));
headLabel.setFont(bold);
@ -42,7 +43,7 @@ SettingsForm::SettingsForm()
id.setReadOnly(true);
id.setFrameStyle(QFrame::NoFrame);
id.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
id.setFixedHeight(id.document()->size().height());
id.setFixedHeight(id.document()->size().height()*2);
videoTest.setText(tr("Test video","Text on a button to test the video/webcam"));
enableIPv6.setText(tr("Enable IPv6 (recommended)","Text on a checkbox to enable IPv6"));
@ -90,7 +91,9 @@ SettingsForm::~SettingsForm()
void SettingsForm::setFriendAddress(const QString& friendAddress)
{
id.setText(friendAddress);
QString txt{friendAddress};
txt.insert(38,'\n');
id.setText(txt);
}
void SettingsForm::show(Ui::MainWindow &ui)
@ -115,8 +118,10 @@ void SettingsForm::onEnableIPv6Updated()
void SettingsForm::copyIdClicked()
{
id.selectAll();;
QApplication::clipboard()->setText(id.toPlainText());
id.selectAll();
QString txt = id.toPlainText();
txt.replace('\n',"");
QApplication::clipboard()->setText(txt);
}
void SettingsForm::onUseTranslationUpdated()

View File

@ -40,34 +40,42 @@ QString ChatAction::QImage2base64(const QImage &img)
return ba.toBase64();
}
QString ChatAction::wrapName(const QString &name)
QString ChatAction::getName()
{
if (isMe)
return QString("<td><div class=name_me>" + name + "</div></td>\n");
return QString("<div class=name_me>" + toHtmlChars(name) + "</div>");
else
return QString("<td><div class=name>" + name + "</div></td>\n");
return QString("<div class=name>" + toHtmlChars(name) + "</div>");
}
QString ChatAction::wrapDate(const QString &date)
QString ChatAction::getDate()
{
QString res = "<td align=right><div class=date>" + date + "</div></td>\n";
return res;
}
QString ChatAction::wrapMessage(const QString &message)
{
QString res = "<td width=100%><div class=message>" + message + "</div></td>\n";
return res;
}
QString ChatAction::wrapWholeLine(const QString &line)
{
QString res = "<tr>\n" + line + "</tr>\n";
QString res = "<div class=date>" + date + "</div>";
return res;
}
MessageAction::MessageAction(const QString &author, const QString &message, const QString &date, const bool &me) :
ChatAction(me)
ChatAction(me, author, date),
message(message)
{
}
void MessageAction::setTextCursor(QTextCursor cursor)
{
// When this function is called, we're supposed to only update ourselve when needed
// Nobody should ask us to do anything with our content, we're on our own
// Except we never udpate on our own, so we can safely free our resources
(void) cursor;
message.clear();
message.squeeze();
name.clear();
name.squeeze();
date.clear();
date.squeeze();
}
QString MessageAction::getMessage()
{
QString message_ = SmileyPack::getInstance().smileyfied(toHtmlChars(message));
@ -100,29 +108,11 @@ MessageAction::MessageAction(const QString &author, const QString &message, cons
}
message_ = message_.left(message_.length()-4);
content = wrapWholeLine(wrapName(author) + wrapMessage(message_) + wrapDate(date));
}
void MessageAction::setTextCursor(QTextCursor cursor)
{
// When this function is called, we're supposed to only update ourselve when needed
// Nobody should ask us to do anything with our content, we're on our own
// Except we never udpate on our own, so we can safely free our resources
(void) cursor;
content.clear();
content.squeeze();
}
QString MessageAction::getHtml()
{
return content;
return QString("<div class=message>" + message_ + "</div>");
}
FileTransferAction::FileTransferAction(FileTransferInstance *widget, const QString &author, const QString &date, const bool &me) :
ChatAction(me),
sender(author),
timestamp(date)
ChatAction(me, author, date)
{
w = widget;
@ -133,22 +123,16 @@ FileTransferAction::~FileTransferAction()
{
}
QString FileTransferAction::getHtml()
QString FileTransferAction::getMessage()
{
QString widgetHtml;
if (w != nullptr)
widgetHtml = w->getHtmlImage();
else
widgetHtml = "<div class=quote>EMPTY CONTENT</div>";
QString res = wrapWholeLine(wrapName(sender) + wrapMessage(widgetHtml) + wrapDate(timestamp));
return res;
return widgetHtml;
}
QString FileTransferAction::wrapMessage(const QString &message)
{
QString res = "<td width=100%>" + message + "</td>\n";
return res;
}
void FileTransferAction::setTextCursor(QTextCursor cursor)
{
cur = cursor;
@ -166,7 +150,7 @@ void FileTransferAction::updateHtml()
int pos = cur.selectionStart();
cur.removeSelectedText();
cur.setKeepPositionOnInsert(false);
cur.insertHtml(getHtml());
cur.insertHtml(getMessage());
cur.setKeepPositionOnInsert(true);
int end = cur.position();
cur.setPosition(pos);
@ -176,10 +160,10 @@ void FileTransferAction::updateHtml()
if (w->getState() == FileTransferInstance::TransfState::tsCanceled
|| w->getState() == FileTransferInstance::TransfState::tsFinished)
{
sender.clear();
sender.squeeze();
timestamp.clear();
timestamp.squeeze();
name.clear();
name.squeeze();
date.clear();
date.squeeze();
cur = QTextCursor();
}
}

View File

@ -25,22 +25,21 @@ class FileTransferInstance;
class ChatAction : public QObject
{
public:
ChatAction(const bool &me) : isMe(me) {;}
ChatAction(const bool &me, const QString &author, const QString &date) : isMe(me), name(author), date(date) {;}
virtual ~ChatAction(){;}
virtual QString getHtml() = 0;
virtual void setTextCursor(QTextCursor cursor){(void)cursor;} ///< Call once, and then you MUST let the object update itself
virtual QString getName();
virtual QString getMessage() = 0;
virtual QString getDate();
protected:
QString toHtmlChars(const QString &str);
QString QImage2base64(const QImage &img);
virtual QString wrapName(const QString &name);
virtual QString wrapDate(const QString &date);
virtual QString wrapMessage(const QString &message);
virtual QString wrapWholeLine(const QString &line);
private:
protected:
bool isMe;
QString name, date;
};
class MessageAction : public ChatAction
@ -48,11 +47,11 @@ class MessageAction : public ChatAction
public:
MessageAction(const QString &author, const QString &message, const QString &date, const bool &me);
virtual ~MessageAction(){;}
virtual QString getHtml();
virtual QString getMessage();
virtual void setTextCursor(QTextCursor cursor) final;
private:
QString content;
QString message;
};
class FileTransferAction : public ChatAction
@ -61,8 +60,7 @@ class FileTransferAction : public ChatAction
public:
FileTransferAction(FileTransferInstance *widget, const QString &author, const QString &date, const bool &me);
virtual ~FileTransferAction();
virtual QString getHtml();
virtual QString wrapMessage(const QString &message);
virtual QString getMessage();
virtual void setTextCursor(QTextCursor cursor) final;
private slots:
@ -70,7 +68,6 @@ private slots:
private:
FileTransferInstance *w;
QString sender, timestamp;
QTextCursor cur;
};

View File

@ -411,6 +411,7 @@ void Widget::addFriend(int friendId, const QString &userId)
connect(newfriend->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
connect(newfriend->widget, SIGNAL(removeFriend(int)), this, SLOT(removeFriend(int)));
connect(newfriend->widget, SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int)));
connect(newfriend->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newfriend->chatForm, SLOT(focusInput()));
connect(newfriend->chatForm, SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString)));
connect(newfriend->chatForm, SIGNAL(sendFile(int32_t, QString, QString, long long)), core, SLOT(sendFile(int32_t, QString, QString, long long)));
connect(newfriend->chatForm, SIGNAL(answerCall(int)), core, SLOT(answerCall(int)));
@ -532,7 +533,7 @@ void Widget::newMessageAlert()
{
QApplication::alert(this);
static QFile sndFile(":audio/notification.wav");
static QFile sndFile(":audio/notification.pcm");
static QByteArray sndData;
if (sndData.isEmpty())
{
@ -543,7 +544,7 @@ void Widget::newMessageAlert()
ALuint buffer;
alGenBuffers(1, &buffer);
alBufferData(buffer, AL_FORMAT_STEREO16, sndData.data(), sndData.size(), 44100);
alBufferData(buffer, AL_FORMAT_MONO16, sndData.data(), sndData.size(), 44100);
alSourcei(core->alMainSource, AL_BUFFER, buffer);
alSourcePlay(core->alMainSource);
}
@ -662,6 +663,7 @@ Group *Widget::createGroup(int groupId)
connect(newgroup->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), this, SLOT(onChatroomWidgetClicked(GenericChatroomWidget*)));
connect(newgroup->widget, SIGNAL(removeGroup(int)), this, SLOT(removeGroup(int)));
connect(newgroup->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newgroup->chatForm, SLOT(focusInput()));
connect(newgroup->chatForm, SIGNAL(sendMessage(int,QString)), core, SLOT(sendGroupMessage(int,QString)));
return newgroup;
}