1
0
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:
krepa098 2015-01-25 14:34:36 +01:00
parent 6e05782fb7
commit 6719ebebae
7 changed files with 95 additions and 19 deletions

View File

@ -192,7 +192,8 @@ HEADERS += src/widget/form/addfriendform.h \
src/chatlog/customtextdocument.h \
src/widget/form/settings/advancedform.h \
src/audio.h \
src/chatlog/content/notificationicon.h
src/chatlog/content/notificationicon.h \
src/chatlog/content/timestamp.h
SOURCES += \
src/widget/form/addfriendform.cpp \
@ -262,7 +263,8 @@ SOURCES += \
src/chatlog/customtextdocument.cpp\
src/widget/form/settings/advancedform.cpp \
src/audio.cpp \
src/chatlog/content/notificationicon.cpp
src/chatlog/content/notificationicon.cpp \
src/chatlog/content/timestamp.cpp
contains(DEFINES, QTOX_FILTER_AUDIO) {
HEADERS += src/audiofilterer.h

View File

@ -463,18 +463,6 @@ QString ChatLog::getSelectedText() const
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
{
return lines.isEmpty();
@ -490,6 +478,11 @@ ChatLine::Ptr ChatLog::getTypingNotification() const
return typingNotification;
}
QVector<ChatLine::Ptr> ChatLog::getLines()
{
return lines;
}
void ChatLog::clear()
{
clearSelection();

View File

@ -48,12 +48,12 @@ public:
void setTypingNotificationVisible(bool visible);
void scrollToLine(ChatLine::Ptr line);
QString getSelectedText() const;
QString toPlainText() const;
bool isEmpty() const;
bool hasTextToBeCopied() const;
ChatLine::Ptr getTypingNotification() const;
QVector<ChatLine::Ptr> getLines();
protected:
QRectF calculateSceneRect() const;

View File

@ -17,6 +17,7 @@
#include "chatmessage.h"
#include "chatlinecontentproxy.h"
#include "content/text.h"
#include "content/timestamp.h"
#include "content/spinner.h"
#include "content/filetransferwidget.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 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;
}
@ -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 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;
}
@ -121,7 +122,7 @@ ChatMessage::Ptr ChatMessage::createBusyNotification()
void ChatMessage::markAsSent(const QDateTime &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

View 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;
}

View 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

View File

@ -16,8 +16,11 @@
#include "genericchatform.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QHBoxLayout>
#include <QDebug>
#include "src/misc/smileypack.h"
#include "src/widget/emoticonswidget.h"
#include "src/misc/style.h"
@ -31,6 +34,7 @@
#include "src/friendlist.h"
#include "src/friend.h"
#include "src/chatlog/chatlog.h"
#include "src/chatlog/content/timestamp.h"
GenericChatForm::GenericChatForm(QWidget *parent)
: QWidget(parent)
@ -271,7 +275,22 @@ void GenericChatForm::onSaveLogClicked()
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
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();
}