(self, painter, option, index)
| 124 | self.model = parent.model() |
| 125 | |
| 126 | def paint(self, painter, option, index): |
| 127 | option.rect.setHeight(59+16) |
| 128 | option.rect.setWidth(self.parent.width()-20) |
| 129 | |
| 130 | #if option.state & QStyle.State_Selected: |
| 131 | # painter.fillRect(option.rect, option.palette.color(QPalette.Highlight)) |
| 132 | |
| 133 | packagename = index.data(OverviewModel.PackageName).toString() |
| 134 | partsf = index.data(OverviewModel.PartsFinished).toString() |
| 135 | parts = index.data(OverviewModel.Parts).toString() |
| 136 | eta = int(index.data(OverviewModel.ETA).toString()) |
| 137 | speed = index.data(OverviewModel.Speed).toString() or 0 |
| 138 | progress = int(index.data(OverviewModel.Progress).toString()) |
| 139 | currentSize = int(index.data(OverviewModel.CurrentSize).toString()) |
| 140 | maxSize = int(index.data(OverviewModel.MaxSize).toString()) |
| 141 | status = index.data(OverviewModel.Status).toString() |
| 142 | |
| 143 | def formatEta(seconds): #TODO add to utils |
| 144 | if seconds <= 0: return "" |
| 145 | hours, seconds = divmod(seconds, 3600) |
| 146 | minutes, seconds = divmod(seconds, 60) |
| 147 | return _("ETA: ") + "%.2i:%.2i:%.2i" % (hours, minutes, seconds) |
| 148 | |
| 149 | statusline = QString(_("Parts: ") + "%s/%s" % (partsf, parts)) |
| 150 | if partsf == parts: |
| 151 | speedline = _("Finished") |
| 152 | elif not status == _("Downloading"): |
| 153 | speedline = QString(status) |
| 154 | else: |
| 155 | speedline = QString(formatEta(eta) + " " + _("Speed: %s") % formatSpeed(speed)) |
| 156 | |
| 157 | if progress in (0,100): |
| 158 | sizeline = QString(_("Size:") + "%s" % formatSize(maxSize)) |
| 159 | else: |
| 160 | sizeline = QString(_("Size:") + "%s / %s" % (formatSize(currentSize), formatSize(maxSize))) |
| 161 | |
| 162 | f = painter.font() |
| 163 | f.setPointSize(12) |
| 164 | f.setBold(True) |
| 165 | painter.setFont(f) |
| 166 | |
| 167 | r = option.rect.adjusted(4, 4, -4, -4) |
| 168 | painter.drawText(r.left(), r.top(), r.width(), r.height(), Qt.AlignTop | Qt.AlignLeft, packagename) |
| 169 | newr = painter.boundingRect(r.left(), r.top(), r.width(), r.height(), Qt.AlignTop | Qt.AlignLeft, packagename) |
| 170 | |
| 171 | f.setPointSize(10) |
| 172 | f.setBold(False) |
| 173 | painter.setFont(f) |
| 174 | |
| 175 | painter.drawText(r.left(), newr.bottom()+5, r.width(), r.height(), Qt.AlignTop | Qt.AlignLeft, statusline) |
| 176 | painter.drawText(r.left(), newr.bottom()+5, r.width(), r.height(), Qt.AlignTop | Qt.AlignHCenter, sizeline) |
| 177 | painter.drawText(r.left(), newr.bottom()+5, r.width(), r.height(), Qt.AlignTop | Qt.AlignRight, speedline) |
| 178 | newr = painter.boundingRect(r.left(), newr.bottom()+2, r.width(), r.height(), Qt.AlignTop | Qt.AlignLeft, statusline) |
| 179 | newr.setTop(newr.bottom()+8) |
| 180 | newr.setBottom(newr.top()+20) |
| 181 | newr.setRight(self.parent.width()-25) |
| 182 | |
| 183 | f.setPointSize(10) |
nothing calls this directly
no test coverage detected