diff --git a/res.qrc b/res.qrc index dc829079a..249642bfb 100644 --- a/res.qrc +++ b/res.qrc @@ -94,6 +94,11 @@ translations/fr.qm translations/ru.qm ui/fileTransferWidget/fileTransferWidget.css + ui/fileTransferInstance/background_red.png + ui/fileTransferInstance/pause_2x.png + ui/fileTransferInstance/no_2x.png + ui/fileTransferInstance/yes_2x.png + ui/fileTransferInstance/arrow_white_2x.png ui/statusButton/dot_away.png ui/statusButton/dot_busy.png ui/statusButton/dot_idle.png diff --git a/src/chatlog/chatlog.cpp b/src/chatlog/chatlog.cpp index 8d47ebeae..9fdcc4621 100644 --- a/src/chatlog/chatlog.cpp +++ b/src/chatlog/chatlog.cpp @@ -103,6 +103,17 @@ ChatMessage *ChatLog::addSystemMessage(const QString &msg, const QDateTime& time return line; } +ChatMessage *ChatLog::addFileTransferMessage(const QString &sender, const ToxFile &file, const QDateTime& timestamp, bool self) +{ + ChatMessage* line = new ChatMessage(scene, QString()); + line->addColumn(new Text(sender, self ? Style::getFont(Style::MediumBold) : Style::getFont(Style::Medium), true), ColumnFormat(75.0, ColumnFormat::FixedSize, 1, ColumnFormat::Right)); + line->addColumn(new ChatLineContentProxy(new FileTransferWidget(0, file)), ColumnFormat(1.0, ColumnFormat::VariableSize)); + line->addColumn(new Text(timestamp.toString("hh:mm")), ColumnFormat(50.0, ColumnFormat::FixedSize, 1, ColumnFormat::Right)); + + insertChatline(line); + return line; +} + void ChatLog::clearSelection() { if(selStartRow >= 0) diff --git a/src/chatlog/chatlog.h b/src/chatlog/chatlog.h index 6177819a0..3a0e0baae 100644 --- a/src/chatlog/chatlog.h +++ b/src/chatlog/chatlog.h @@ -24,6 +24,7 @@ class QGraphicsScene; class ChatLine; class ChatLineContent; class ChatMessage; +class ToxFile; class ChatLog : public QGraphicsView { @@ -36,6 +37,7 @@ public: ChatMessage* addChatMessage(const QString& sender, const QString& msg, bool self); ChatMessage* addSystemMessage(const QString& msg, const QDateTime& timestamp); + ChatMessage* addFileTransferMessage(const QString& sender, const ToxFile& file, const QDateTime ×tamp, bool self); void insertChatline(ChatLine* l); diff --git a/src/chatlog/content/filetransferwidget.cpp b/src/chatlog/content/filetransferwidget.cpp index ca81bdbcf..3b66f14ff 100644 --- a/src/chatlog/content/filetransferwidget.cpp +++ b/src/chatlog/content/filetransferwidget.cpp @@ -17,15 +17,23 @@ #include "filetransferwidget.h" #include "ui_filetransferwidget.h" +#include "src/core.h" + #include #include -FileTransferWidget::FileTransferWidget(QWidget *parent) : - QWidget(parent), - ui(new Ui::FileTransferWidget) +FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file) + : QWidget(parent) + , ui(new Ui::FileTransferWidget) + , fileInfo(file) { ui->setupUi(this); + ui->filenameLabel->setText(file.fileName); + ui->progressBar->setValue(0); + + connect(Core::getInstance(), &Core::fileTransferInfo, this, &FileTransferWidget::onFileTransferInfo); + setFixedHeight(100); } @@ -34,17 +42,12 @@ FileTransferWidget::~FileTransferWidget() delete ui; } -void FileTransferWidget::on_pushButton_2_clicked() +void FileTransferWidget::onFileTransferInfo(int FriendId, int FileNum, int64_t Filesize, int64_t BytesSent, ToxFile::FileDirection direction) { - qDebug() << "Button Cancel Clicked"; -} + if(FileNum != fileInfo.fileNum) + return; -void FileTransferWidget::on_pushButton_clicked() -{ - qDebug() << "Button Resume Clicked"; -} - -void FileTransferWidget::on_pushButton_2_pressed() -{ - qDebug() << "Button Resume Clicked"; + // update progress + qreal progress = static_cast(Filesize)/static_cast(BytesSent); + ui->progressBar->setValue(static_cast(progress * 100.0)); } diff --git a/src/chatlog/content/filetransferwidget.h b/src/chatlog/content/filetransferwidget.h index e5158caf3..e25a280b5 100644 --- a/src/chatlog/content/filetransferwidget.h +++ b/src/chatlog/content/filetransferwidget.h @@ -19,6 +19,7 @@ #include #include "../chatlinecontent.h" +#include "../../corestructs.h" namespace Ui { class FileTransferWidget; @@ -29,16 +30,15 @@ class FileTransferWidget : public QWidget Q_OBJECT public: - explicit FileTransferWidget(QWidget *parent = 0); + explicit FileTransferWidget(QWidget *parent, ToxFile file); virtual ~FileTransferWidget(); +protected slots: + void onFileTransferInfo(int FriendId, int FileNum, int64_t Filesize, int64_t BytesSent, ToxFile::FileDirection direction); + private: Ui::FileTransferWidget *ui; - -private slots: - void on_pushButton_2_clicked(); - void on_pushButton_clicked(); - void on_pushButton_2_pressed(); + ToxFile fileInfo; }; diff --git a/src/chatlog/content/filetransferwidget.ui b/src/chatlog/content/filetransferwidget.ui index 4e2cca60d..11a0a63b0 100644 --- a/src/chatlog/content/filetransferwidget.ui +++ b/src/chatlog/content/filetransferwidget.ui @@ -6,8 +6,8 @@ 0 0 - 729 - 124 + 619 + 86 @@ -19,99 +19,181 @@ background-color:transparent; - + - + QFrame { -border-radius:10; -background-color:green; + border-image: url(:/ui/fileTransferInstance/background_red.png); + border-left:25;padding-top:-30; + border-top:28; + border-right:25; padding-right:-28; + border-bottom:28;padding-bottom:-30; + color:white; +} + +QPushButton { + margin:0; } - QFrame::StyledPanel + QFrame::NoFrame - QFrame::Raised + QFrame::Plain - + + 0 + + - - - color:white; - + - SomeRandomFile.7z + Filename - - - color:white; - - - 142/1742 YiB - - + + + + + 10Mb + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + 24% + + + Qt::AlignCenter + + + + + + + ETA:10:10 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 16777215 + 14 + + - color:white; + QProgressBar { + border: 2px solid black; + border-radius: 0px; + color: white; + background-color:white; +} + +QProgressBar::chunk { + background-color: black; + width: 20px; +} 24 + + Qt::Horizontal + + + false + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + 0 + - - - - 0 - 0 - + + + - + + + :/ui/fileTransferInstance/pause_2x.png:/ui/fileTransferInstance/pause_2x.png + + - 50 - 50 + 25 + 28 - - background-color:red; - - - Cancel + + true - - - - 0 - 0 - + + + Qt::Vertical - + - 50 - 50 + 20 + 40 - - background-color:rgb(0, 255, 0); - + + + + - Resume + + + + + :/ui/fileTransferInstance/arrow_white_2x.png:/ui/fileTransferInstance/arrow_white_2x.png + + + + 25 + 28 + + + + true @@ -122,6 +204,8 @@ background-color:green; - + + + diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index f7fc7829c..2d81700e1 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -164,16 +164,18 @@ void ChatForm::startFileSend(ToxFile file) if (file.friendId != f->getFriendID()) return; + + FileTransferInstance* fileTrans = new FileTransferInstance(file); ftransWidgets.insert(fileTrans->getId(), fileTrans); - connect(Core::getInstance(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo); - connect(Core::getInstance(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled); - connect(Core::getInstance(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished); - connect(Core::getInstance(), SIGNAL(fileTransferAccepted(ToxFile)), fileTrans, SLOT(onFileTransferAccepted(ToxFile))); - connect(Core::getInstance(), SIGNAL(fileTransferPaused(int,int,ToxFile::FileDirection)), fileTrans, SLOT(onFileTransferPaused(int,int,ToxFile::FileDirection))); - connect(Core::getInstance(), SIGNAL(fileTransferRemotePausedUnpaused(ToxFile,bool)), fileTrans, SLOT(onFileTransferRemotePausedUnpaused(ToxFile,bool))); - connect(Core::getInstance(), SIGNAL(fileTransferBrokenUnbroken(ToxFile, bool)), fileTrans, SLOT(onFileTransferBrokenUnbroken(ToxFile, bool))); +// connect(Core::getInstance(), &Core::fileTransferInfo, fileTrans, &FileTransferInstance::onFileTransferInfo); +// connect(Core::getInstance(), &Core::fileTransferCancelled, fileTrans, &FileTransferInstance::onFileTransferCancelled); +// connect(Core::getInstance(), &Core::fileTransferFinished, fileTrans, &FileTransferInstance::onFileTransferFinished); +// connect(Core::getInstance(), SIGNAL(fileTransferAccepted(ToxFile)), fileTrans, SLOT(onFileTransferAccepted(ToxFile))); +// connect(Core::getInstance(), SIGNAL(fileTransferPaused(int,int,ToxFile::FileDirection)), fileTrans, SLOT(onFileTransferPaused(int,int,ToxFile::FileDirection))); +// connect(Core::getInstance(), SIGNAL(fileTransferRemotePausedUnpaused(ToxFile,bool)), fileTrans, SLOT(onFileTransferRemotePausedUnpaused(ToxFile,bool))); +// connect(Core::getInstance(), SIGNAL(fileTransferBrokenUnbroken(ToxFile, bool)), fileTrans, SLOT(onFileTransferBrokenUnbroken(ToxFile, bool))); QString name; if (!previousId.isMine()) @@ -183,9 +185,8 @@ void ChatForm::startFileSend(ToxFile file) previousId = core->getSelfId(); } - //TODO: -// chatWidget->insertMessage(ChatActionPtr(new FileTransferAction(fileTrans, getElidedName(name), -// QTime::currentTime().toString("hh:mm"), true))); + + chatWidget->addFileTransferMessage(name, file, QDateTime::currentDateTime(), true); } void ChatForm::onFileRecvRequest(ToxFile file) diff --git a/ui/fileTransferInstance/arrow_white_2x.png b/ui/fileTransferInstance/arrow_white_2x.png new file mode 100644 index 000000000..646dd5ad8 Binary files /dev/null and b/ui/fileTransferInstance/arrow_white_2x.png differ diff --git a/ui/fileTransferInstance/background_red.png b/ui/fileTransferInstance/background_red.png new file mode 100644 index 000000000..0ac042954 Binary files /dev/null and b/ui/fileTransferInstance/background_red.png differ diff --git a/ui/fileTransferInstance/no_2x.png b/ui/fileTransferInstance/no_2x.png new file mode 100644 index 000000000..86c05eb5a Binary files /dev/null and b/ui/fileTransferInstance/no_2x.png differ diff --git a/ui/fileTransferInstance/pause_2x.png b/ui/fileTransferInstance/pause_2x.png new file mode 100644 index 000000000..6ee39a91e Binary files /dev/null and b/ui/fileTransferInstance/pause_2x.png differ diff --git a/ui/fileTransferInstance/yes_2x.png b/ui/fileTransferInstance/yes_2x.png new file mode 100644 index 000000000..a4de22444 Binary files /dev/null and b/ui/fileTransferInstance/yes_2x.png differ