diff --git a/retroshare-gui/src/RetroShare.pro b/retroshare-gui/src/RetroShare.pro index 3151162be..ce04384e3 100644 --- a/retroshare-gui/src/RetroShare.pro +++ b/retroshare-gui/src/RetroShare.pro @@ -159,6 +159,7 @@ HEADERS += rshare.h \ gui/ShareManager.h \ gui/StatisticDialog.h \ gui/SoundManager.h \ + gui/taskGraphPainterWidget.h \ gui/HelpDialog.h \ gui/InfoDialog.h \ gui/LogoBar.h \ @@ -376,6 +377,7 @@ SOURCES += main.cpp \ gui/StatisticDialog.cpp \ gui/SoundManager.cpp \ gui/MessagesDialog.cpp \ + gui/taskGraphPainterWidget.cpp \ gui/MessagesPopupDialog.cpp \ gui/im_history/IMHistoryKeeper.cpp \ gui/im_history/IMHistoryReader.cpp \ diff --git a/retroshare-gui/src/gui/TransfersDialog.cpp b/retroshare-gui/src/gui/TransfersDialog.cpp index f090ae37c..20655fc4d 100644 --- a/retroshare-gui/src/gui/TransfersDialog.cpp +++ b/retroshare-gui/src/gui/TransfersDialog.cpp @@ -174,9 +174,19 @@ TransfersDialog::TransfersDialog(QWidget *parent) connect(upheader, SIGNAL(sortIndicatorChanged(int, Qt::SortOrder)), this, SLOT(saveSortIndicatorUpl(int, Qt::SortOrder))); - // set default column and sort order for upload - _sortColUpl = 0; - _sortOrderUpl = Qt::AscendingOrder; + // set default column and sort order for upload + _sortColUpl = 0; + _sortOrderUpl = Qt::AscendingOrder; + + createTaskGraphPainterWidget(); + + /* + taskGraphDetailLayout = new QHBoxLayout(); + taskGraphDetailLayout->addWidget(taskGraphWidget); + ui.tab_2->setLayout(taskGraphDetailLayout); + taskGraphDetailLayout->setSpacing( 0 ); + taskGraphDetailLayout->setMargin( 0 );*/ + /* Hide platform specific features */ @@ -1295,6 +1305,36 @@ void TransfersDialog::saveSortIndicatorUpl(int logicalIndex, Qt::SortOrder order _sortOrderUpl = order; } +void TransfersDialog::createTaskGraphPainterWidget() +{ + taskGraphPainterWidget = new TaskGraphPainterWidget(); + //taskGraphWidget = new QScrollArea(); + ui.taskGraphWidget->setWidget(taskGraphPainterWidget); + ui.taskGraphWidget->setWidgetResizable(true); + ui.taskGraphWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + ui.taskGraphWidget->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); + ui.taskGraphWidget->viewport()->setBackgroundRole(QPalette::NoRole); + ui.taskGraphWidget->setFrameStyle(QFrame::NoFrame); + ui.taskGraphWidget->setFocusPolicy(Qt::NoFocus); +} + +/*void TransfersDialog::setTaskGraphPainterWidget (const QModelIndex& index) +{ + Download *dl = (Download *) (index.model ()-> + data (index.model ()->index (index.row (), DLListDelegate::PTR)).value ()); + + if (!dl) + return; + + // call takeWidget before setWidget to avoid destruction of the widget + QWidget* lastWidget = taskGraphWidget->takeWidget (); + + QWidget* currentWidget = dl->getTaskGraphicWidget (); + taskGraphWidget->setWidget (currentWidget); + + taskGraphWidget->show (); +}*/ + double TransfersDialog::getProgress(int row, QStandardItemModel *model) { return model->data(model->index(row, PROGRESS), Qt::DisplayRole).toDouble(); diff --git a/retroshare-gui/src/gui/TransfersDialog.h b/retroshare-gui/src/gui/TransfersDialog.h index 518e8ef73..8474a5676 100644 --- a/retroshare-gui/src/gui/TransfersDialog.h +++ b/retroshare-gui/src/gui/TransfersDialog.h @@ -31,6 +31,8 @@ #include #include "mainpage.h" +#include "taskGraphPainterWidget.h" + #include "ui_TransfersDialog.h" @@ -90,6 +92,8 @@ class TransfersDialog : public MainPage /** save sort indicators for next transfers display */ void saveSortIndicatorDwl(int logicalIndex, Qt::SortOrder order); void saveSortIndicatorUpl(int logicalIndex, Qt::SortOrder order); + + //void setTaskGraphPainterWidget (const QModelIndex& index); signals: void playFiles(QStringList files); @@ -112,6 +116,11 @@ class TransfersDialog : public MainPage int _sortColDwl, _sortColUpl; Qt::SortOrder _sortOrderDwl, _sortOrderUpl; + + void createTaskGraphPainterWidget(); + /*QHBoxLayout *taskGraphDetailLayout; + QScrollArea *taskGraphWidget;*/ + TaskGraphPainterWidget *taskGraphPainterWidget; /** Create the actions on the tray menu or menubar */ @@ -153,8 +162,8 @@ class TransfersDialog : public MainPage Ui::TransfersDialog ui; public slots: - int addItem(QString symbol, QString name, QString coreID, qlonglong size, double progress, double dlspeed, QString sources, QString status, QString priority, qlonglong completed, qlonglong remaining); - bool addPeerToItem(int row, QString symbol, QString name, QString coreID, qlonglong fileSize, double progress, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining); + int addItem(QString symbol, QString name, QString coreID, qlonglong size, double progress, double dlspeed, QString sources, QString status, QString priority, qlonglong completed, qlonglong remaining); + bool addPeerToItem(int row, QString symbol, QString name, QString coreID, qlonglong fileSize, double progress, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining); void delItem(int row); int addUploadItem(QString symbol, QString name, QString coreID, qlonglong size, double progress, double dlspeed, QString sources, QString status, qlonglong completed, qlonglong remaining); diff --git a/retroshare-gui/src/gui/TransfersDialog.ui b/retroshare-gui/src/gui/TransfersDialog.ui index 8f9436014..55c741a48 100644 --- a/retroshare-gui/src/gui/TransfersDialog.ui +++ b/retroshare-gui/src/gui/TransfersDialog.ui @@ -6,8 +6,8 @@ 0 0 - 590 - 314 + 620 + 353 @@ -502,23 +502,8 @@ Qt::PreventContextMenu - - - 6 - - - 6 - - - 6 - - - 1 - - - 1 - - + + Qt::Vertical @@ -625,71 +610,169 @@ p, li { white-space: pre-wrap; } - - - - 0 - - - 0 - - - - - - Arial - 9 - - - - true - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - 0 - - - 6 - - - - - - - - :/images/up.png + + + + 75 + true + + + + 0 + + + + + :/images/up.png:/images/up.png + + + Uploads + + + + 0 + + + 0 + + + + + + Arial + 9 + + + + true + + + + + + + + + :/images/blockdevice.png:/images/blockdevice.png + + + File Chunks + + + + 0 + + + 6 + + + + + QFrame::NoFrame + + + Qt::ScrollBarAlwaysOff + + + true + + + + + 0 + 0 + 596 + 104 + - - - - - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Arial'; font-size:8pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:9pt; font-weight:600;">Uploads:</span></p></body></html> - - - - - - + + + + + + 6 + + + + + + + + + + :/images/graph-downloaded.png + + + + + + + Done + + + + + + + + + + + + + + :/images/graph-downloading.png + + + + + + + Active + + + + + + + + + + + + + + :/images/graph-notdownload.png + + + + + + + Outstanding + + + + + + + + + Qt::Horizontal + + + + 368 + 13 + + + + + + + + diff --git a/retroshare-gui/src/gui/images.qrc b/retroshare-gui/src/gui/images.qrc index 954b47723..5d2a8c97e 100644 --- a/retroshare-gui/src/gui/images.qrc +++ b/retroshare-gui/src/gui/images.qrc @@ -63,6 +63,9 @@ images/folder16.png images/folderopen.png images/fileopen.png + images/graph-downloaded.png + images/graph-downloading.png + images/graph-notdownload.png images/add-friend24.png images/add-share24.png images/add_24x24.png diff --git a/retroshare-gui/src/gui/images/graph-downloaded.png b/retroshare-gui/src/gui/images/graph-downloaded.png new file mode 100644 index 000000000..9bb2bc347 Binary files /dev/null and b/retroshare-gui/src/gui/images/graph-downloaded.png differ diff --git a/retroshare-gui/src/gui/images/graph-downloading.png b/retroshare-gui/src/gui/images/graph-downloading.png new file mode 100644 index 000000000..0aacd599c Binary files /dev/null and b/retroshare-gui/src/gui/images/graph-downloading.png differ diff --git a/retroshare-gui/src/gui/images/graph-notdownload.png b/retroshare-gui/src/gui/images/graph-notdownload.png new file mode 100644 index 000000000..9414f771a Binary files /dev/null and b/retroshare-gui/src/gui/images/graph-notdownload.png differ diff --git a/retroshare-gui/src/gui/taskGraphPainterWidget.cpp b/retroshare-gui/src/gui/taskGraphPainterWidget.cpp new file mode 100644 index 000000000..c94679e8c --- /dev/null +++ b/retroshare-gui/src/gui/taskGraphPainterWidget.cpp @@ -0,0 +1,296 @@ +/**************************************************************** + * This file is distributed under the following license: + * + * Copyright (c) 2009, defnax + * Copyright (c) 2009, lsn752 + * + * This program is free 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 2 + * 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 + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#include +#include +#include "taskGraphPainterWidget.h" + +TaskGraphPainterWidget::TaskGraphPainterWidget(QWidget * parent, Qt::WFlags f ) +{ + this->fileSize = 0; + this->blockSize = 100*1024; + notDownloadList.clear(); + + QRect TaskGraphRect = geometry(); + maxWidth = TaskGraphRect.width(); + pixmap = QPixmap(size()); + pixmap.fill(this, 0, 0); + + downloadedPixmap.load(":images/graph-downloaded.png"); + downloadingPixmap.load(":images/graph-downloading.png"); + notDownloadPixmap.load(":images/graph-notdownload.png"); + + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); +} +void TaskGraphPainterWidget::setData( qint64 fileSize, qint64 blockSize ) +{ + this->fileSize = fileSize; + this->blockSize = blockSize; + + int blocks = fileSize/blockSize; + if (fileSize%blockSize == 0) blocks--; +#ifdef WIN32 + if (blocks>=5000) + { + this->blockSize=this->fileSize/5000; + } +#else + if (blocks>=3000) + { + this->blockSize=this->fileSize/3000; + } +#endif +} +void TaskGraphPainterWidget::setBlockSizeData( qint64 blockSize ) +{ + this->blockSize = blockSize; + + int blocks = fileSize/blockSize; + if (fileSize%blockSize == 0) blocks--; +#ifdef WIN32 + if (blocks>=5000) + { + this->blockSize=this->fileSize/5000; + } +#else + if (blocks>=3000) + { + this->blockSize=this->fileSize/3000; + } +#endif + refreshAll(); +} +void TaskGraphPainterWidget::setNotDownloadListClear() +{ + notDownloadList.clear(); +} +void TaskGraphPainterWidget::setNotDownloadList( int taskThreadListId, qint64 startPosition, qint64 endPosition) +{ + NotDownload notDownload; + notDownload.taskThreadListId = taskThreadListId; + notDownload.startPosition = startPosition; + notDownload.endPosition = endPosition; + notDownloadList.append(notDownload); +} +void TaskGraphPainterWidget::newReceivedListClear() +{ + newTaskReceivedList.clear(); +} +void TaskGraphPainterWidget::setNewReceived(int taskThreadListId, QList newReceivedList) +{ + NewReceived newReceived; + newReceived.taskThreadListId = taskThreadListId; + newReceived.newThreadReceivedList = newReceivedList; + newTaskReceivedList.append(newReceived); +} +void TaskGraphPainterWidget::resizeEvent(QResizeEvent *event) +{ + QRect TaskGraphRect = geometry(); + maxWidth = TaskGraphRect.width(); + + refreshAll(); +} +void TaskGraphPainterWidget::refreshAll() +{ + int blocks = fileSize/blockSize; + if (fileSize%blockSize >0) blocks++; + int columns = maxWidth/13; + y = blocks/columns*13; + x = blocks%columns*13; + maxHeight = y+15; + pixmap = QPixmap(size()); + pixmap.fill(this, 0, 0); + pixmap = QPixmap(maxWidth, maxHeight); + pixmap.fill(this, 0, 0); + setFixedHeight(maxHeight); + + QPainter painter(&pixmap); + painter.initFrom(this); + if (fileSize>0) + { + drawDownloaded(&painter); + drawNotDownload(&painter); + } + else + { + drawNoSizeFile(&painter); + } + + pixmap2 = pixmap; + update(); +} +void TaskGraphPainterWidget::refreshPixmap() +{ + pixmap2 = pixmap; + QPainter painter(&pixmap2); + + drawNewReceivedData(&painter); + + update(); +} +void TaskGraphPainterWidget::refreshThreadLastBlock(int newThreadReceivedListId) +{ + pixmap2 = pixmap; + QPainter painter(&pixmap2); + + drawThreadLastBlock(&painter, newThreadReceivedListId); + + repaint (); +} +void TaskGraphPainterWidget::paintEvent(QPaintEvent *event) +{ + QStylePainter painter(this); + + painter.drawPixmap(0, 0, pixmap2); + pixmap = pixmap2; +} +void TaskGraphPainterWidget::drawNotDownload(QPainter *painter) +{ + if (this->fileSize == 0) return; + int columns = maxWidth/13; + int blocks = fileSize/blockSize; + if (fileSize%blockSize == 0) blocks--; + + QRectF source(0.0, 0.0, 12.0, 12.0); + for (int taskThreadListId=0;taskThreadListId 0) startPositionBlocks++; + int endPositionBlocks = endPosition/blockSize; + if (endPositionBlocks != blocks) endPositionBlocks--; + + for (int block=startPositionBlocks;block<=endPositionBlocks;block++) + { + y = block/columns*13; + x = block%columns*13; + QRectF target(x, y, 12.0, 12.0); + painter->drawPixmap(target, notDownloadPixmap, source); + } + } +} +void TaskGraphPainterWidget::drawDownloaded(QPainter *painter) +{ + x=0; + y=0; + int blocks = fileSize/blockSize; + if (fileSize%blockSize == 0) blocks--; + QRectF source(0.0, 0.0, 12.0, 12.0); + + for (int i=0;i<=blocks;i++) + { + if (x > maxWidth - 13) + { + x = 0; + y += 13; + } + QRectF target(x, y, 12.0, 12.0); + painter->drawPixmap(target, downloadedPixmap, source); + x += 13; + } + maxHeight = y+15; +} +void TaskGraphPainterWidget::drawNoSizeFile(QPainter *painter) +{ + x=0; + y=0; + QList newThreadReceivedList; + if (newTaskReceivedList.isEmpty()) return; + newThreadReceivedList = newTaskReceivedList.at(0).newThreadReceivedList; + if (newThreadReceivedList.isEmpty()) return; + qint64 startPosition = newThreadReceivedList.at(newThreadReceivedList.size()-1); + int blocks = startPosition/blockSize; + if (fileSize%blockSize == 0) blocks--; + QRectF source(0.0, 0.0, 12.0, 12.0); + + for (int i=0;i<=blocks;i++) + { + if (x > maxWidth - 13) + { + x = 0; + y += 13; + } + QRectF target(x, y, 12.0, 12.0); + painter->drawPixmap(target, downloadedPixmap, source); + x += 13; + } + + maxHeight = y+15; +} +void TaskGraphPainterWidget::drawNewReceivedData(QPainter *painter) +{ + for (int newTaskReceivedListId=0;newTaskReceivedListId newThreadReceivedList; + newThreadReceivedList = newTaskReceivedList.at(newTaskReceivedListId).newThreadReceivedList; + if (newThreadReceivedList.size() < 1) continue; + + int columns = maxWidth/13; + QRectF source(0.0, 0.0, 12.0, 12.0); + + qint64 startPosition = newThreadReceivedList.at(0); + qint64 endPosition = newThreadReceivedList.at(newThreadReceivedList.size()-1); + int startPositionBlocks = startPosition/blockSize; + int endPositionBlocks = endPosition/blockSize; + if (endPosition%blockSize == 0) endPositionBlocks--; + + for (int block=startPositionBlocks;block<=endPositionBlocks;block++) + { + y = block/columns*13; + x = block%columns*13; + QRectF target(x, y, 12.0, 12.0); + if (block==endPositionBlocks) + { + if (newTaskReceivedList.at(newTaskReceivedListId).taskThreadListId>=0) + painter->drawPixmap(target, downloadingPixmap, source); + else + painter->drawPixmap(target, downloadedPixmap, source); + } + else + painter->drawPixmap(target, downloadedPixmap, source); + } + } +} +void TaskGraphPainterWidget::drawThreadLastBlock(QPainter *painter, int newThreadReceivedListId) +{ + QList newThreadReceivedList; + newThreadReceivedList = newTaskReceivedList.at(newThreadReceivedListId).newThreadReceivedList; + if (newThreadReceivedList.size() < 1) return; + + int columns = maxWidth/13; + QRectF source(0.0, 0.0, 12.0, 12.0); + + qint64 startPosition = newThreadReceivedList.at(0); + qint64 endPosition = newThreadReceivedList.at(newThreadReceivedList.size()-1); + int startPositionBlocks = startPosition/blockSize; + int endPositionBlocks = endPosition/blockSize; + if (endPosition%blockSize == 0) endPositionBlocks--; + + for (int block=startPositionBlocks;block<=endPositionBlocks;block++) + { + y = block/columns*13; + x = block%columns*13; + QRectF target(x, y, 12.0, 12.0); + painter->drawPixmap(target, downloadedPixmap, source); + } +} diff --git a/retroshare-gui/src/gui/taskGraphPainterWidget.h b/retroshare-gui/src/gui/taskGraphPainterWidget.h new file mode 100644 index 000000000..7af0415b7 --- /dev/null +++ b/retroshare-gui/src/gui/taskGraphPainterWidget.h @@ -0,0 +1,88 @@ +/**************************************************************** + * This file is distributed under the following license: + * + * Copyright (c) 2009, defnax + * Copyright (c) 2009, lsn752 + * + * This program is free 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 2 + * 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 + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + ****************************************************************/ + +#ifndef __TASKGRAPHPAINTERWIDGET_H__ +#define __TASKGRAPHPAINTERWIDGET_H__ + +#include +#include +#include + +class TaskGraphPainterWidget : public QWidget +{ + Q_OBJECT + +public: + TaskGraphPainterWidget(QWidget * parent = 0, Qt::WFlags f = 0 ); + + void setData( qint64 fileSize, qint64 blockSize ); + void setBlockSizeData( qint64 blockSize ); + void setNotDownloadListClear(); + void setNotDownloadList( int taskThreadListId, qint64 startPosition, qint64 endPosition); + void newReceivedListClear(); + void setNewReceived(int taskThreadListId, QList newReceivedList); + void refreshAll(); + void refreshPixmap(); + void refreshThreadLastBlock(int newThreadReceivedListId); + + qint64 fileSize; + qint64 blockSize; + +protected: + void paintEvent(QPaintEvent *); + void resizeEvent(QResizeEvent *event); + +private: + void drawNotDownload(QPainter *painter); + void drawDownloaded(QPainter *painter); + void drawNoSizeFile(QPainter *painter); + void drawNewReceivedData(QPainter *painter); + void drawThreadLastBlock(QPainter *painter, int newThreadReceivedListId); + + + int x; + int y; + int maxWidth; + int maxHeight; + QPixmap pixmap; + QPixmap pixmap2; + QPixmap downloadedPixmap; + QPixmap downloadingPixmap; + QPixmap notDownloadPixmap; + int taskThreadListId; + struct _NotDownload + { + int taskThreadListId; + qint64 startPosition; + qint64 endPosition; + }; + typedef struct _NotDownload NotDownload; + QList notDownloadList; + struct _NewReceived + { + int taskThreadListId; + QList newThreadReceivedList; + }; + typedef struct _NewReceived NewReceived; + QList newTaskReceivedList; +}; +#endif // __TASKGRAPHPAINTERWIDGET_H__