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

98 lines
2.8 KiB
C
Raw Normal View History

2014-11-16 19:58:43 +08:00
/*
Copyright © 2014-2015 by The qTox Project Contributors
2014-11-16 19:58:43 +08:00
This file is part of qTox, a Qt-based graphical interface for Tox.
qTox is libre software: you can redistribute it and/or modify
2014-11-16 19:58:43 +08:00
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.
qTox is distributed in the hope that it will be useful,
2014-11-16 19:58:43 +08:00
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
2014-11-16 19:58:43 +08:00
You should have received a copy of the GNU General Public License
along with qTox. If not, see <http://www.gnu.org/licenses/>.
2014-11-16 19:58:43 +08:00
*/
2014-11-12 21:11:25 +08:00
#ifndef FILETRANSFERWIDGET_H
#define FILETRANSFERWIDGET_H
2014-11-17 23:05:14 +08:00
#include <QTime>
#include <QWidget>
2015-02-05 00:21:56 +08:00
#include "src/chatlog/chatlinecontent.h"
#include "src/core/corestructs.h"
2014-11-12 21:11:25 +08:00
2015-01-18 01:17:40 +08:00
2014-11-12 21:11:25 +08:00
namespace Ui {
class FileTransferWidget;
}
class QVariantAnimation;
2014-11-17 23:05:14 +08:00
class QPushButton;
2014-11-12 21:11:25 +08:00
class FileTransferWidget : public QWidget
{
Q_OBJECT
public:
2017-01-06 19:02:54 +08:00
explicit FileTransferWidget(QWidget* parent, ToxFile file);
2014-11-12 21:11:25 +08:00
virtual ~FileTransferWidget();
2015-01-11 18:57:33 +08:00
void autoAcceptTransfer(const QString& path);
bool isActive() const;
2014-12-14 04:11:03 +08:00
2014-11-17 03:01:37 +08:00
protected slots:
2014-11-17 23:05:14 +08:00
void onFileTransferInfo(ToxFile file);
void onFileTransferAccepted(ToxFile file);
void onFileTransferCancelled(ToxFile file);
void onFileTransferPaused(ToxFile file);
void onFileTransferResumed(ToxFile file);
2014-11-17 23:05:14 +08:00
void onFileTransferFinished(ToxFile file);
void fileTransferRemotePausedUnpaused(ToxFile file, bool paused);
2015-04-26 01:18:46 +08:00
void fileTransferBrokenUnbroken(ToxFile file, bool broken);
2014-11-17 23:05:14 +08:00
protected:
QString getHumanReadableSize(qint64 size);
void hideWidgets();
void setupButtons();
void handleButton(QPushButton* btn);
2014-11-18 03:08:55 +08:00
void showPreview(const QString& filename);
2015-01-11 18:57:33 +08:00
void acceptTransfer(const QString& filepath);
2015-02-14 19:14:09 +08:00
void setBackgroundColor(const QColor& c, bool whiteFont);
void setButtonColor(const QColor& c);
2015-01-11 18:57:33 +08:00
2015-02-14 19:14:09 +08:00
bool drawButtonAreaNeeded() const;
2014-11-17 23:05:14 +08:00
virtual void paintEvent(QPaintEvent*) final override;
2014-11-17 23:05:14 +08:00
private slots:
void onLeftButtonClicked();
void onRightButtonClicked();
void onPreviewButtonClicked();
2014-11-17 03:01:37 +08:00
private:
static QPixmap scaleCropIntoSquare(const QPixmap& source, int targetSize);
2014-11-12 21:11:25 +08:00
private:
Ui::FileTransferWidget* ui;
2014-11-17 03:01:37 +08:00
ToxFile fileInfo;
2014-11-17 23:05:14 +08:00
QTime lastTick;
quint64 lastBytesSent = 0;
2015-02-13 23:46:59 +08:00
QVariantAnimation* backgroundColorAnimation = nullptr;
2015-02-14 19:14:09 +08:00
QVariantAnimation* buttonColorAnimation = nullptr;
2015-02-13 23:46:59 +08:00
QColor backgroundColor;
QColor buttonColor;
QColor buttonBackgroundColor;
2014-11-12 21:11:25 +08:00
2015-01-19 03:57:51 +08:00
static const uint8_t TRANSFER_ROLLING_AVG_COUNT = 4;
uint8_t meanIndex = 0;
qreal meanData[TRANSFER_ROLLING_AVG_COUNT] = {0.0};
bool active;
2014-11-12 21:11:25 +08:00
};
#endif // FILETRANSFERWIDGET_H