00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "Qt.h"
00024 #include "DownloadProgressBar.h"
00025
00026 using UIs::DownloadProgressBar;
00027
00028 DownloadProgressBar::DownloadProgressBar ()
00029 : fileSize (0), requestedRanges (new QList<Range>),
00030 downloadedRanges (new QList<Range>), verifiedRanges (new QList<Range>)
00031 {
00032 }
00033
00034 void DownloadProgressBar::setFileSize (int size)
00035 {
00036 fileSize = size;
00037 }
00038
00039 void DownloadProgressBar::addRequestedRange (int start, int end)
00040 {
00041 Range newRequestedRange (start, end);
00042 requestedRanges->append (newRequestedRange);
00043 }
00044
00045 void DownloadProgressBar::addDownloadedRange (int start, int end)
00046 {
00047 Range newDownloadedRange (start, end);
00048 downloadedRanges->append (newDownloadedRange);
00049 }
00050
00051 void DownloadProgressBar::addVerifiedRange (int start, int end)
00052 {
00053 Range newVerifiedRange (start, end);
00054 verifiedRanges->append (newVerifiedRange);
00055 }
00056
00057 void DownloadProgressBar::removeRequestedRange (int, int)
00058 {
00059
00060 }
00061
00062 void DownloadProgressBar::removeDownloadedRange (int, int)
00063 {
00064
00065 }
00066
00067 void DownloadProgressBar::removeVerifiedRange (int, int)
00068 {
00069
00070 }
00071
00072 void DownloadProgressBar::paint (QPainter *painter, const QRect *rect, const QStyleOptionViewItem & option)
00073 {
00074
00075
00076
00077 int height = rect->height();
00078 QBrush brush = painter->brush();
00079 brush.setStyle (Qt::SolidPattern);
00080
00081 if (option.state & QStyle::State_Selected) {
00082 QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
00083 ? QPalette::Normal : QPalette::Disabled;
00084 painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight));
00085 painter->fillRect(option.rect.adjusted (2, 2, -2, -2) , QBrush (QColor (255,255,255)));
00086 }
00087
00088 brush.setColor (QColor (0,0,0));
00089 QPoint p1 = rect->topLeft() + QPoint (1, 1);
00090 QPoint p2 = rect->topRight() + QPoint (-1, 1);
00091 QPoint p4 = rect->bottomLeft() + QPoint (1, -1);
00092 QPoint p3 = rect->bottomRight() + QPoint (-1, -1);
00093
00094 painter->drawLine (p1, p2);
00095 painter->drawLine (p2, p3);
00096 painter->drawLine (p3, p4);
00097 painter->drawLine (p4, p1);
00098
00099
00100 brush.setColor (QColor (218, 117, 0));
00101 painter->setBrush (brush);
00102 paintRanges (painter, rect->adjusted (2, 2, -2, -(3*height/4 )), requestedRanges);
00103
00104
00105 brush.setColor (QColor (47, 53, 81));
00106 painter->setBrush (brush);
00107
00108 paintRanges (painter, rect->adjusted (2, 2, -2, -2), downloadedRanges);
00109
00110 brush.setColor (QColor (37, 223, 5));
00111 painter->setBrush (brush);
00112 paintRanges (painter, rect->adjusted (2, 3*height/4,-2, -2), verifiedRanges);
00113
00114 }
00115
00116 void DownloadProgressBar::paintRanges (QPainter *painter, const QRect &rect, QList<Range> *ranges)
00117 {
00118 int width = rect.width();
00119 Range range(0,0);
00120 int start, end;
00121
00122 for (int i=0; i<ranges->count(); i++){
00123 range = ranges->at(i);
00124 start = range.start()*width/fileSize;
00125 end = range.end()*width/fileSize;
00126
00127 QRect fillRect (rect.left() + start, rect.top(), end-start, rect.height());
00128 painter->fillRect (fillRect, painter->brush());
00129 }
00130 }