Browse Source

- Display piece availability average next to the bar

adaptive-webui-19844
Christophe Dumez 15 years ago
parent
commit
cdce77962a
  1. 6
      src/pieceavailabilitybar.h
  2. 5
      src/propertieswidget.cpp
  3. 7
      src/ui/propertieswidget.ui

6
src/pieceavailabilitybar.h

@ -50,7 +50,8 @@ public: @@ -50,7 +50,8 @@ public:
setFixedHeight(BAR_HEIGHT);
}
void setAvailability(std::vector<int>& avail) {
double setAvailability(std::vector<int>& avail) {
double average = 0;
if(avail.empty()) {
// Empty bar
pixmap = QPixmap(1, 1);
@ -59,7 +60,7 @@ public: @@ -59,7 +60,7 @@ public:
painter.drawPoint(0,0);
} else {
// Look for maximum value
double average = std::accumulate(avail.begin(), avail.end(), 0)/(double)avail.size();
average = std::accumulate(avail.begin(), avail.end(), 0)/(double)avail.size();
uint nb_pieces = avail.size();
pixmap = QPixmap(nb_pieces, 1);
QPainter painter(&pixmap);
@ -70,6 +71,7 @@ public: @@ -70,6 +71,7 @@ public:
}
}
update();
return average;
}
void clear() {

5
src/propertieswidget.cpp

@ -139,6 +139,7 @@ void PropertiesWidget::showPieceBars(bool show) { @@ -139,6 +139,7 @@ void PropertiesWidget::showPieceBars(bool show) {
downloaded_pieces->setVisible(show);
progress_lbl->setVisible(show);
line_2->setVisible(show);
avail_average_lbl->setVisible(show);
}
void PropertiesWidget::reduce() {
@ -178,6 +179,7 @@ void PropertiesWidget::clear() { @@ -178,6 +179,7 @@ void PropertiesWidget::clear() {
trackerList->clear();
downloaded_pieces->clear();
pieces_availability->clear();
avail_average_lbl->clear();
wasted->clear();
upTotal->clear();
dlTotal->clear();
@ -329,7 +331,8 @@ void PropertiesWidget::loadDynamicData() { @@ -329,7 +331,8 @@ void PropertiesWidget::loadDynamicData() {
// Pieces availability
std::vector<int> avail;
h.piece_availability(avail);
pieces_availability->setAvailability(avail);
double avail_average = pieces_availability->setAvailability(avail);
avail_average_lbl->setText(QString::number(avail_average, 'f', 1));
// Progress
progress_lbl->setText(QString::number(h.progress()*100., 'f', 1)+"%");
}

7
src/ui/propertieswidget.ui

@ -135,7 +135,7 @@ @@ -135,7 +135,7 @@
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<widget class="QLabel" name="avail_average_lbl">
<property name="maximumSize">
<size>
<width>50</width>
@ -143,7 +143,10 @@ @@ -143,7 +143,10 @@
</size>
</property>
<property name="text">
<string notr="true"/>
<string notr="true">0.0</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>

Loading…
Cancel
Save