Old:
New:
Project Diff from QtCreator:
Code: Select all
Index: src/properties/propertieswidget.cpp
===================================================================
--- src/properties/propertieswidget.cpp (wersja 5198)
+++ src/properties/propertieswidget.cpp (kopia robocza)
@@ -365,7 +365,7 @@
std::vector<int> avail;
h.piece_availability(avail);
pieces_availability->setAvailability(avail);
- avail_average_lbl->setText(QString::number(h.status().distributed_copies, 'f', 1));
+ avail_average_lbl->setText(QString::number(h.status().distributed_copies, 'f', 3));
} else {
showPiecesAvailability(false);
}
Index: src/properties/downloadedpiecesbar.h
===================================================================
--- src/properties/downloadedpiecesbar.h (wersja 5198)
+++ src/properties/downloadedpiecesbar.h (kopia robocza)
@@ -61,65 +61,25 @@
pixmap = pix;
} else {
const qulonglong nb_pieces = pieces.size();
- // Reduce the number of pieces before creating the pixmap
- // otherwise it can crash when there are too many pieces
- const uint w = width();
- if(nb_pieces > w) {
- const uint ratio = floor(nb_pieces/(double)w);
- libtorrent::bitfield scaled_pieces(ceil(nb_pieces/(double)ratio), false);
- libtorrent::bitfield scaled_downloading(ceil(nb_pieces/(double)ratio), false);
- uint scaled_index = 0;
- for(qulonglong i=0; i<nb_pieces; i+= ratio) {
- bool have = true;
- for(qulonglong j=i; j<qMin(i+ratio, nb_pieces); ++j) {
- if(!pieces[i]) { have = false; break; }
- }
- if(have) {
- scaled_pieces.set_bit(scaled_index);
+ QPixmap pix = QPixmap(nb_pieces, 1);
+ //pix.fill();
+ QPainter painter(&pix);
+ QPen penDownloaded(QColor(0x2b, 0x2b, 0xff));
+ for(uint i=0; i<nb_pieces; ++i) {
+ if(pieces[i]) {
+ painter.setPen(penDownloaded);
+ } else {
+ if(downloading_pieces[i]) {
+ // really hard to see yellow
+ painter.setPen(Qt::green);
} else {
- bool downloading = false;
- for(qulonglong j=i; j<qMin(i+ratio, nb_pieces); ++j) {
- if(downloading_pieces[i]) { downloading = true; break; }
- }
- if(downloading)
- scaled_downloading.set_bit(scaled_index);
+ painter.setPen(Qt::white);
}
- ++scaled_index;
}
- QPixmap pix = QPixmap(scaled_pieces.size(), 1);
- //pix.fill();
- QPainter painter(&pix);
- for(uint i=0; i<scaled_pieces.size(); ++i) {
- if(scaled_pieces[i]) {
- painter.setPen(Qt::blue);
- } else {
- if(scaled_downloading[i]) {
- painter.setPen(Qt::yellow);
- } else {
- painter.setPen(Qt::white);
- }
- }
- painter.drawPoint(i,0);
- }
- pixmap = pix;
- } else {
- QPixmap pix = QPixmap(pieces.size(), 1);
- //pix.fill();
- QPainter painter(&pix);
- for(uint i=0; i<pieces.size(); ++i) {
- if(pieces[i]) {
- painter.setPen(Qt::blue);
- } else {
- if(downloading_pieces[i]) {
- painter.setPen(Qt::yellow);
- } else {
- painter.setPen(Qt::white);
- }
- }
- painter.drawPoint(i,0);
- }
- pixmap = pix;
+ painter.drawPoint(i,0);
}
+ // Qt::SmoothTransformation looks bad, TODO: write better SmoothTransformation loop
+ pixmap = pix.scaledToWidth(width(), Qt::FastTransformation);
}
update();
}
Index: src/properties/pieceavailabilitybar.h
===================================================================
--- src/properties/pieceavailabilitybar.h (wersja 5198)
+++ src/properties/pieceavailabilitybar.h (kopia robocza)
@@ -37,6 +37,7 @@
#include <QColor>
#include <numeric>
#include <math.h>
+#include <algorithm>
#define BAR_HEIGHT 18
@@ -53,50 +54,26 @@
}
void setAvailability(const std::vector<int>& avail) {
- qreal average = 0;
if(avail.empty()) {
// Empty bar
QPixmap pix = QPixmap(1, 1);
pix.fill();
pixmap = pix;
} else {
- // Look for maximum value
const qulonglong nb_pieces = avail.size();
- average = std::accumulate(avail.begin(), avail.end(), 0)/(double)nb_pieces;
- // Reduce the number of pieces before creating the pixmap
- // otherwise it can crash when there are too many pieces
- const uint w = width();
- if(nb_pieces > w) {
- const qulonglong ratio = floor(nb_pieces/(double)w);
- std::vector<int> scaled_avail;
- scaled_avail.reserve(ceil(nb_pieces/(double)ratio));
- for(qulonglong i=0; i<nb_pieces; i+= ratio) {
- /*qulonglong j = i;
- qulonglong sum = avail[i];
- for(j=i+1; j<qMin(i+ratio, nb_pieces); ++j) {
- sum += avail[j];
- }
- scaled_avail.push_back(sum/(qMin(ratio, nb_pieces-i)));*/
- // XXX: Do not compute the average to save cpu
- scaled_avail.push_back(avail[i]);
- }
- QPixmap pix = QPixmap(scaled_avail.size(), 1);
- //pix.fill();
+ // Look for maximum value
+ int max = *std::max_element(avail.begin(), avail.end());
+ QPixmap pix = QPixmap(nb_pieces, 1);
+ if(max == 0) {
+ pix.fill();
+ } else{
QPainter painter(&pix);
- for(qulonglong i=0; i < scaled_avail.size(); ++i) {
- painter.setPen(getPieceColor(scaled_avail[i], average));
- painter.drawPoint(i,0);
- }
- pixmap = pix;
- } else {
- QPixmap pix = QPixmap(nb_pieces, 1);
- //pix.fill();
- QPainter painter(&pix);
for(qulonglong i=0; i < nb_pieces; ++i) {
- painter.setPen(getPieceColor(avail[i], average));
- painter.drawPoint(i,0);
+ uint rg = 0xff - (0xff * avail[i]/max);
+ painter.setPen(QColor(rg, rg, 0xff));
+ painter.drawPoint(i, 0);
}
- pixmap = pix;
+ pixmap = pix.scaledToWidth(width(), Qt::FastTransformation);
}
}
update();
@@ -113,17 +90,6 @@
QPainter painter(this);
painter.drawPixmap(rect(), pixmap);
}
-
- QColor getPieceColor(int avail, qreal average) {
- if(!avail) return Qt::white;
- //qDebug("avail: %d/%d", avail, max_avail);
- qreal fraction = 100.*average/avail;
- if(fraction < 100)
- fraction *= 0.8;
- else
- fraction *= 1.2;
- return QColor(Qt::blue).lighter(fraction);
- }
};
#endif // PIECEAVAILABILITYBAR_H
Index: src/properties/proptabbar.cpp
===================================================================
--- src/properties/proptabbar.cpp (wersja 5198)
+++ src/properties/proptabbar.cpp (kopia robocza)
@@ -32,6 +32,7 @@
#include <QPushButton>
#include <QSpacerItem>
#include <QKeySequence>
+#include <QPalette>
#include "proptabbar.h"
#include "iconprovider.h"
@@ -40,8 +41,10 @@
#define DEFAULT_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px; margin-left: 8px; margin-right: 8px;}"
#define SELECTED_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px;background-color: rgb(255, 208, 105); margin-left: 8px; margin-right: 8px;}"
#else
-#define DEFAULT_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px; margin-left: 3px; margin-right: 3px;}"
-#define SELECTED_BUTTON_CSS "QPushButton {border: 1px solid rgb(85, 81, 91);border-radius: 3px;padding: 2px;background-color: rgb(255, 208, 105); margin-left: 3px; margin-right: 3px;}"
+#define DEFAULT_BUTTON_CSS "QPushButton {border: 1px solid #888;border-radius: 2px;padding: 4px; margin-left: 0px; margin-right: 3px;}"
+#define SELECTED_BUTTON_CSS "QPushButton {border: 1px solid #888;border-radius: 2px;padding: 4px;background-color: rgb(112, 168, 222); margin-left: 0px; margin-right: 3px;}"
+#define SELECTED_BUTTON_CSS2a "QPushButton {border: 1px solid #888;border-radius: 2px;padding: 4px;background-color: rgb("
+#define SELECTED_BUTTON_CSS2b "); margin-left: 0px; margin-right: 3px;}"
#endif
const int BTN_ICON_SIZE = 16;
@@ -50,7 +53,7 @@
QHBoxLayout(parent), m_currentIndex(-1)
{
m_btnGroup = new QButtonGroup(this);
- setContentsMargins(5, 4, 5, 2);
+ setContentsMargins(0, 4, 5, 7);
// General tab
QPushButton *main_infos_button = new QPushButton(IconProvider::instance()->getIcon("document-properties"), tr("General"), parent);
main_infos_button->setShortcut(QKeySequence(QString::fromUtf8("Alt+P")));
@@ -118,7 +121,10 @@
emit visibilityToggled(true);
}
// Select the new button
- m_btnGroup->button(index)->setStyleSheet(SELECTED_BUTTON_CSS);
+// m_btnGroup->button(index)->setStyleSheet(SELECTED_BUTTON_CSS);
+ QColor hC = m_btnGroup->button(index)->palette().highlight().color();
+ QString b = QString(SELECTED_BUTTON_CSS2a) + QString::number(hC.red()) + QString(", ") + QString::number(hC.green()) + QString(", ") + QString::number(hC.blue()) + QString(SELECTED_BUTTON_CSS2b);
+ m_btnGroup->button(index)->setStyleSheet(b);
m_currentIndex = index;
// Emit the signal
emit tabChanged(index);