1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

more work on filetransferwidget

This commit is contained in:
krepa098 2014-11-17 20:08:55 +01:00
parent 27cb075dbb
commit 3a567d962e
9 changed files with 196 additions and 39 deletions

View File

@ -21,6 +21,10 @@
#include "src/misc/style.h"
#include <QMouseEvent>
#include <QFileDialog>
#include <QDir>
#include <QFileInfo>
#include <QMessageBox>
#include <QDebug>
FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file)
@ -31,6 +35,10 @@ FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file)
{
ui->setupUi(this);
// hide the QWidget background (background-color: transparent doesn't seem to work)
setAttribute(Qt::WA_TranslucentBackground, true);
ui->previewLabel->hide();
ui->filenameLabel->setText(file.fileName);
ui->progressBar->setValue(0);
ui->fileSizeLabel->setText(getHumanReadableSize(file.filesize));
@ -48,6 +56,10 @@ FileTransferWidget::FileTransferWidget(QWidget *parent, ToxFile file)
setupButtons();
//preview
if(fileInfo.direction == ToxFile::SENDING)
showPreview(fileInfo.filePath);
setFixedHeight(85);
}
@ -123,7 +135,7 @@ void FileTransferWidget::onFileTransferCancelled(ToxFile file)
setupButtons();
hideWidgets();
disconnect(Core::getInstance());
disconnect(Core::getInstance(), 0, this, 0);
}
void FileTransferWidget::onFileTransferPaused(ToxFile file)
@ -152,7 +164,11 @@ void FileTransferWidget::onFileTransferFinished(ToxFile file)
setupButtons();
hideWidgets();
disconnect(Core::getInstance());
// preview
if(fileInfo.direction == ToxFile::RECEIVING)
showPreview(fileInfo.filePath);
disconnect(Core::getInstance(), 0, this, 0);
}
QString FileTransferWidget::getHumanReadableSize(qint64 size)
@ -194,6 +210,19 @@ void FileTransferWidget::setupButtons()
break;
case ToxFile::STOPPED:
case ToxFile::BROKEN: //TODO: ?
ui->topButton->setIcon(QIcon(":/ui/fileTransferInstance/no_2x.png"));
ui->topButton->setObjectName("cancel");
if(fileInfo.direction == ToxFile::SENDING)
{
ui->bottomButton->setIcon(QIcon(":/ui/fileTransferInstance/pause_2x.png"));
ui->bottomButton->setObjectName("pause");
}
else
{
ui->bottomButton->setIcon(QIcon(":/ui/fileTransferInstance/yes_2x.png"));
ui->bottomButton->setObjectName("accept");
}
break;
}
}
@ -217,9 +246,33 @@ void FileTransferWidget::handleButton(QPushButton *btn)
Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum);
if(btn->objectName() == "resume")
Core::getInstance()->pauseResumeFileRecv(fileInfo.friendId, fileInfo.fileNum);
if(btn->objectName() == "accept")
{
QString path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(fileInfo.fileName));
if(!QFileInfo(QDir(path).path()).isWritable())
{
QMessageBox::warning(0,
tr("Location not writable","Title of permissions popup"),
tr("You do not have permission to write that location. Choose another, or cancel the save dialog.", "text of permissions popup"));
return;
}
if(!path.isEmpty())
Core::getInstance()->acceptFileRecvRequest(fileInfo.friendId, fileInfo.fileNum, path);
}
}
}
void FileTransferWidget::showPreview(const QString &filename)
{
//QPixmap pmap = QPixmap(filename).scaled(QSize(ui->previewLabel->maximumWidth(), maximumHeight()), Qt::KeepAspectRatio, Qt::SmoothTransformation);
QPixmap pmap = QPixmap(filename).scaledToWidth(ui->previewLabel->maximumWidth(), Qt::SmoothTransformation);
ui->previewLabel->setPixmap(pmap);
ui->previewLabel->show();
}
void FileTransferWidget::on_topButton_clicked()
{
handleButton(ui->topButton);

View File

@ -48,6 +48,7 @@ protected:
void hideWidgets();
void setupButtons();
void handleButton(QPushButton* btn);
void showPreview(const QString& filename);
private slots:
void on_topButton_clicked();

View File

@ -13,12 +13,7 @@
<property name="windowTitle">
<string>Form</string>
</property>
<property name="styleSheet">
<string notr="true">#FileTransferWidget {
background-color:transparent;
}</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<layout class="QHBoxLayout" name="mainHorizontalLayout">
<item>
<widget class="QFrame" name="frame_3">
<property name="sizePolicy">
@ -40,6 +35,31 @@
<number>0</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<item>
<widget class="QLabel" name="previewLabel">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>80</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>[preview]</string>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="topMargin">

View File

@ -14,7 +14,7 @@ ToxFile::ToxFile(int FileNum, int FriendId, QByteArray FileName, QString FilePat
bool ToxFile::operator==(const ToxFile &other) const
{
return fileNum == other.fileNum && friendId && other.friendId;
return (fileNum == other.fileNum) && (friendId == other.friendId) && (direction == other.direction);
}
bool ToxFile::operator!=(const ToxFile &other) const

View File

@ -164,19 +164,6 @@ 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)));
QString name;
if (!previousId.isMine())
{
@ -194,17 +181,6 @@ void ChatForm::onFileRecvRequest(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)));
Widget* w = Widget::getInstance();
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
{
@ -221,12 +197,11 @@ void ChatForm::onFileRecvRequest(ToxFile file)
previousId = friendId;
}
//TODO: chatWidget->insertMessage(ChatActionPtr(new FileTransferAction(fileTrans, getElidedName(name),
// QTime::currentTime().toString("hh:mm"), false)));
if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())).isEmpty()
|| Settings::getInstance().getAutoSaveEnabled())
fileTrans->pressFromHtml("btnB");
chatWidget->addFileTransferMessage(name, file, QDateTime::currentDateTime(), false);
//TODO:
// if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())).isEmpty()
// || Settings::getInstance().getAutoSaveEnabled())
// fileTrans->pressFromHtml("btnB");
}
void ChatForm::onAvInvite(int FriendId, int CallId, bool video)

View File

@ -0,0 +1,27 @@
QFrame {
border-image: url(:/ui/fileTransferInstance/background_green.png);
border-left:25;padding-top:-30;
border-top:28;
border-right:25; padding-right:-28;
border-bottom:28;padding-bottom:-30;
}
QLabel {
color:white;
}
QPushButton {
margin:0;
}
QProgressBar {
border: 2px solid black;
border-radius: 0px;
color: white;
background-color:white;
}
QProgressBar::chunk {
background-color: black;
width: 20px;
}

View File

@ -0,0 +1,27 @@
QFrame {
border-image: url(:/ui/fileTransferInstance/background_grey.png);
border-left:25;padding-top:-30;
border-top:28;
border-right:25; padding-right:-28;
border-bottom:28;padding-bottom:-30;
}
QLabel {
color:black;
}
QPushButton {
margin:0;
}
QProgressBar {
border: 2px solid black;
border-radius: 0px;
color: white;
background-color:white;
}
QProgressBar::chunk {
background-color: black;
width: 20px;
}

View File

@ -0,0 +1,27 @@
QFrame {
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;
}
QLabel {
color:white;
}
QPushButton {
margin:0;
}
QProgressBar {
border: 2px solid black;
border-radius: 0px;
color: white;
background-color:white;
}
QProgressBar::chunk {
background-color: black;
width: 20px;
}

View File

@ -0,0 +1,27 @@
QFrame {
border-image: url(:/ui/fileTransferInstance/background_yellow.png);
border-left:25;padding-top:-30;
border-top:28;
border-right:25; padding-right:-28;
border-bottom:28;padding-bottom:-30;
}
QLabel {
color:black;
}
QPushButton {
margin:0;
}
QProgressBar {
border: 2px solid black;
border-radius: 0px;
color: white;
background-color:white;
}
QProgressBar::chunk {
background-color: black;
width: 20px;
}