mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Added Timestamp class, moved output generation while saving to
GenericChatForm and changed the generated layout
This commit is contained in:
parent
6e05782fb7
commit
6719ebebae
6
qtox.pro
6
qtox.pro
|
@ -192,7 +192,8 @@ HEADERS += src/widget/form/addfriendform.h \
|
||||||
src/chatlog/customtextdocument.h \
|
src/chatlog/customtextdocument.h \
|
||||||
src/widget/form/settings/advancedform.h \
|
src/widget/form/settings/advancedform.h \
|
||||||
src/audio.h \
|
src/audio.h \
|
||||||
src/chatlog/content/notificationicon.h
|
src/chatlog/content/notificationicon.h \
|
||||||
|
src/chatlog/content/timestamp.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
src/widget/form/addfriendform.cpp \
|
src/widget/form/addfriendform.cpp \
|
||||||
|
@ -262,7 +263,8 @@ SOURCES += \
|
||||||
src/chatlog/customtextdocument.cpp\
|
src/chatlog/customtextdocument.cpp\
|
||||||
src/widget/form/settings/advancedform.cpp \
|
src/widget/form/settings/advancedform.cpp \
|
||||||
src/audio.cpp \
|
src/audio.cpp \
|
||||||
src/chatlog/content/notificationicon.cpp
|
src/chatlog/content/notificationicon.cpp \
|
||||||
|
src/chatlog/content/timestamp.cpp
|
||||||
|
|
||||||
contains(DEFINES, QTOX_FILTER_AUDIO) {
|
contains(DEFINES, QTOX_FILTER_AUDIO) {
|
||||||
HEADERS += src/audiofilterer.h
|
HEADERS += src/audiofilterer.h
|
||||||
|
|
|
@ -463,18 +463,6 @@ QString ChatLog::getSelectedText() const
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ChatLog::toPlainText() const
|
|
||||||
{
|
|
||||||
QString out;
|
|
||||||
|
|
||||||
for(ChatLine::Ptr l : lines)
|
|
||||||
{
|
|
||||||
out += QString("|%1 @%2|\n%3\n\n").arg(l->getContent(0)->getText(),l->getContent(2)->getText(),l->getContent(1)->getText());
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ChatLog::isEmpty() const
|
bool ChatLog::isEmpty() const
|
||||||
{
|
{
|
||||||
return lines.isEmpty();
|
return lines.isEmpty();
|
||||||
|
@ -490,6 +478,11 @@ ChatLine::Ptr ChatLog::getTypingNotification() const
|
||||||
return typingNotification;
|
return typingNotification;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<ChatLine::Ptr> ChatLog::getLines()
|
||||||
|
{
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
|
||||||
void ChatLog::clear()
|
void ChatLog::clear()
|
||||||
{
|
{
|
||||||
clearSelection();
|
clearSelection();
|
||||||
|
|
|
@ -48,12 +48,12 @@ public:
|
||||||
void setTypingNotificationVisible(bool visible);
|
void setTypingNotificationVisible(bool visible);
|
||||||
void scrollToLine(ChatLine::Ptr line);
|
void scrollToLine(ChatLine::Ptr line);
|
||||||
QString getSelectedText() const;
|
QString getSelectedText() const;
|
||||||
QString toPlainText() const;
|
|
||||||
|
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
bool hasTextToBeCopied() const;
|
bool hasTextToBeCopied() const;
|
||||||
|
|
||||||
ChatLine::Ptr getTypingNotification() const;
|
ChatLine::Ptr getTypingNotification() const;
|
||||||
|
QVector<ChatLine::Ptr> getLines();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QRectF calculateSceneRect() const;
|
QRectF calculateSceneRect() const;
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
#include "chatmessage.h"
|
#include "chatmessage.h"
|
||||||
#include "chatlinecontentproxy.h"
|
#include "chatlinecontentproxy.h"
|
||||||
#include "content/text.h"
|
#include "content/text.h"
|
||||||
|
#include "content/timestamp.h"
|
||||||
#include "content/spinner.h"
|
#include "content/spinner.h"
|
||||||
#include "content/filetransferwidget.h"
|
#include "content/filetransferwidget.h"
|
||||||
#include "content/image.h"
|
#include "content/image.h"
|
||||||
|
@ -81,7 +82,7 @@ ChatMessage::Ptr ChatMessage::createChatInfoMessage(const QString &rawMessage, S
|
||||||
|
|
||||||
msg->addColumn(new Image(QSizeF(18, 18), img), ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
msg->addColumn(new Image(QSizeF(18, 18), img), ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||||
msg->addColumn(new Text(rawMessage, Style::getFont(Style::Big), false, ""), ColumnFormat(1.0, ColumnFormat::VariableSize, ColumnFormat::Center));
|
msg->addColumn(new Text(rawMessage, Style::getFont(Style::Big), false, ""), ColumnFormat(1.0, ColumnFormat::VariableSize, ColumnFormat::Center));
|
||||||
msg->addColumn(new Text(date.toString(Settings::getInstance().getTimestampFormat()), Style::getFont(Style::Big)), ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
msg->addColumn(new Timestamp(date, Settings::getInstance().getTimestampFormat(), Style::getFont(Style::Big)), ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
@ -92,7 +93,7 @@ ChatMessage::Ptr ChatMessage::createFileTransferMessage(const QString& sender, T
|
||||||
|
|
||||||
msg->addColumn(new Text(sender, isMe ? Style::getFont(Style::BigBold) : Style::getFont(Style::Big), true), ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
msg->addColumn(new Text(sender, isMe ? Style::getFont(Style::BigBold) : Style::getFont(Style::Big), true), ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||||
msg->addColumn(new ChatLineContentProxy(new FileTransferWidget(0, file), 350, 0.6f), ColumnFormat(1.0, ColumnFormat::VariableSize));
|
msg->addColumn(new ChatLineContentProxy(new FileTransferWidget(0, file), 350, 0.6f), ColumnFormat(1.0, ColumnFormat::VariableSize));
|
||||||
msg->addColumn(new Text(date.toString(Settings::getInstance().getTimestampFormat()), Style::getFont(Style::Big)), ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
msg->addColumn(new Timestamp(date, Settings::getInstance().getTimestampFormat(), Style::getFont(Style::Big)), ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||||
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
@ -121,7 +122,7 @@ ChatMessage::Ptr ChatMessage::createBusyNotification()
|
||||||
void ChatMessage::markAsSent(const QDateTime &time)
|
void ChatMessage::markAsSent(const QDateTime &time)
|
||||||
{
|
{
|
||||||
// remove the spinner and replace it by $time
|
// remove the spinner and replace it by $time
|
||||||
replaceContent(2, new Text(time.toString(Settings::getInstance().getTimestampFormat())));
|
replaceContent(2, new Timestamp(time, Settings::getInstance().getTimestampFormat(), Style::getFont(Style::Big)));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ChatMessage::toString() const
|
QString ChatMessage::toString() const
|
||||||
|
|
28
src/chatlog/content/timestamp.cpp
Normal file
28
src/chatlog/content/timestamp.cpp
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2015 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 "timestamp.h"
|
||||||
|
|
||||||
|
Timestamp::Timestamp(const QDateTime &time, const QString &format, const QFont &font)
|
||||||
|
: Text(time.toString(format), font, false, time.toString(format))
|
||||||
|
{
|
||||||
|
this->time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDateTime Timestamp::getTime()
|
||||||
|
{
|
||||||
|
return time;
|
||||||
|
}
|
33
src/chatlog/content/timestamp.h
Normal file
33
src/chatlog/content/timestamp.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
Copyright (C) 2015 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 TIMESTAMP_H
|
||||||
|
#define TIMESTAMP_H
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
#include "text.h"
|
||||||
|
|
||||||
|
class Timestamp : public Text
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Timestamp(const QDateTime& time, const QString& format, const QFont& font);
|
||||||
|
QDateTime getTime();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QDateTime time;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // TIMESTAMP_H
|
|
@ -16,8 +16,11 @@
|
||||||
|
|
||||||
#include "genericchatform.h"
|
#include "genericchatform.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "src/misc/smileypack.h"
|
#include "src/misc/smileypack.h"
|
||||||
#include "src/widget/emoticonswidget.h"
|
#include "src/widget/emoticonswidget.h"
|
||||||
#include "src/misc/style.h"
|
#include "src/misc/style.h"
|
||||||
|
@ -31,6 +34,7 @@
|
||||||
#include "src/friendlist.h"
|
#include "src/friendlist.h"
|
||||||
#include "src/friend.h"
|
#include "src/friend.h"
|
||||||
#include "src/chatlog/chatlog.h"
|
#include "src/chatlog/chatlog.h"
|
||||||
|
#include "src/chatlog/content/timestamp.h"
|
||||||
|
|
||||||
GenericChatForm::GenericChatForm(QWidget *parent)
|
GenericChatForm::GenericChatForm(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
@ -271,7 +275,22 @@ void GenericChatForm::onSaveLogClicked()
|
||||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
file.write(chatWidget->toPlainText().toUtf8());
|
QString plainText;
|
||||||
|
auto lines = chatWidget->getLines();
|
||||||
|
for(ChatLine::Ptr l : lines)
|
||||||
|
{
|
||||||
|
Timestamp* rightCol = dynamic_cast<Timestamp*>(l->getContent(2));
|
||||||
|
ChatLineContent* middleCol = l->getContent(1);
|
||||||
|
ChatLineContent* leftCol = l->getContent(0);
|
||||||
|
|
||||||
|
QString timestamp = (!rightCol || rightCol->getTime().isNull()) ? tr("Not sent") : rightCol->getText();
|
||||||
|
QString nick = leftCol->getText();
|
||||||
|
QString msg = middleCol->getText();
|
||||||
|
|
||||||
|
plainText += QString("[%2] %1\n%3\n\n").arg(nick, timestamp, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
file.write(plainText.toUtf8());
|
||||||
file.close();
|
file.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user