|
|
@ -32,8 +32,9 @@ |
|
|
|
#include <QDebug> |
|
|
|
#include <QDebug> |
|
|
|
#include "pieceavailabilitybar.h" |
|
|
|
#include "pieceavailabilitybar.h" |
|
|
|
|
|
|
|
|
|
|
|
PieceAvailabilityBar::PieceAvailabilityBar(QWidget *parent) : |
|
|
|
|
|
|
|
QWidget(parent) |
|
|
|
PieceAvailabilityBar::PieceAvailabilityBar(QWidget *parent) |
|
|
|
|
|
|
|
: QWidget(parent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
setFixedHeight(BAR_HEIGHT); |
|
|
|
setFixedHeight(BAR_HEIGHT); |
|
|
|
|
|
|
|
|
|
|
@ -66,7 +67,6 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &vecin, |
|
|
|
// image.x(1) = pieces.x(1.7 >= x < 3.4)
|
|
|
|
// image.x(1) = pieces.x(1.7 >= x < 3.4)
|
|
|
|
|
|
|
|
|
|
|
|
for (int x = 0; x < reqSize; ++x) { |
|
|
|
for (int x = 0; x < reqSize; ++x) { |
|
|
|
|
|
|
|
|
|
|
|
// don't use previously calculated value "ratio" here!!!
|
|
|
|
// don't use previously calculated value "ratio" here!!!
|
|
|
|
// float cannot save irrational number like 7/9, if this number will be rounded up by std::ceil
|
|
|
|
// float cannot save irrational number like 7/9, if this number will be rounded up by std::ceil
|
|
|
|
// give you x2 == pieces.size(), and index out of range: pieces[x2]
|
|
|
|
// give you x2 == pieces.size(), and index out of range: pieces[x2]
|
|
|
@ -94,33 +94,28 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &vecin, |
|
|
|
|
|
|
|
|
|
|
|
// case when calculated range is (15.2 >= x < 15.7)
|
|
|
|
// case when calculated range is (15.2 >= x < 15.7)
|
|
|
|
if (x2 == toCMinusOne) { |
|
|
|
if (x2 == toCMinusOne) { |
|
|
|
if (vecin[x2]) { |
|
|
|
if (vecin[x2]) |
|
|
|
value += (toR - fromR) * vecin[x2]; |
|
|
|
value += (toR - fromR) * vecin[x2]; |
|
|
|
} |
|
|
|
|
|
|
|
++x2; |
|
|
|
++x2; |
|
|
|
} |
|
|
|
} |
|
|
|
// case when (15.2 >= x < 17.8)
|
|
|
|
// case when (15.2 >= x < 17.8)
|
|
|
|
else { |
|
|
|
else { |
|
|
|
// subcase (15.2 >= x < 16)
|
|
|
|
// subcase (15.2 >= x < 16)
|
|
|
|
if (x2 != fromR) { |
|
|
|
if (x2 != fromR) { |
|
|
|
if (vecin[x2]) { |
|
|
|
if (vecin[x2]) |
|
|
|
value += (1.0 - (fromR - fromC)) * vecin[x2]; |
|
|
|
value += (1.0 - (fromR - fromC)) * vecin[x2]; |
|
|
|
} |
|
|
|
|
|
|
|
++x2; |
|
|
|
++x2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// subcase (16 >= x < 17)
|
|
|
|
// subcase (16 >= x < 17)
|
|
|
|
for (; x2 < toCMinusOne; ++x2) { |
|
|
|
for (; x2 < toCMinusOne; ++x2) |
|
|
|
if (vecin[x2]) { |
|
|
|
if (vecin[x2]) |
|
|
|
value += vecin[x2]; |
|
|
|
value += vecin[x2]; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// subcase (17 >= x < 17.8)
|
|
|
|
// subcase (17 >= x < 17.8)
|
|
|
|
if (x2 == toCMinusOne) { |
|
|
|
if (x2 == toCMinusOne) { |
|
|
|
if (vecin[x2]) { |
|
|
|
if (vecin[x2]) |
|
|
|
value += (1.0 - (toC - toR)) * vecin[x2]; |
|
|
|
value += (1.0 - (toC - toR)) * vecin[x2]; |
|
|
|
} |
|
|
|
|
|
|
|
++x2; |
|
|
|
++x2; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -173,8 +168,7 @@ void PieceAvailabilityBar::updateImage() |
|
|
|
QVector<float> scaled_pieces = intToFloatVector(m_pieces, image2.width()); |
|
|
|
QVector<float> scaled_pieces = intToFloatVector(m_pieces, image2.width()); |
|
|
|
|
|
|
|
|
|
|
|
// filling image
|
|
|
|
// filling image
|
|
|
|
for (int x = 0; x < scaled_pieces.size(); ++x) |
|
|
|
for (int x = 0; x < scaled_pieces.size(); ++x) { |
|
|
|
{ |
|
|
|
|
|
|
|
float pieces2_val = scaled_pieces.at(x); |
|
|
|
float pieces2_val = scaled_pieces.at(x); |
|
|
|
image2.setPixel(x, 0, m_pieceColors[pieces2_val * 255]); |
|
|
|
image2.setPixel(x, 0, m_pieceColors[pieces2_val * 255]); |
|
|
|
} |
|
|
|
} |
|
|
@ -208,13 +202,11 @@ void PieceAvailabilityBar::paintEvent(QPaintEvent *) |
|
|
|
{ |
|
|
|
{ |
|
|
|
QPainter painter(this); |
|
|
|
QPainter painter(this); |
|
|
|
QRect imageRect(1, 1, width() - 2, height() - 2); |
|
|
|
QRect imageRect(1, 1, width() - 2, height() - 2); |
|
|
|
if (m_image.isNull()) |
|
|
|
if (m_image.isNull()) { |
|
|
|
{ |
|
|
|
|
|
|
|
painter.setBrush(Qt::white); |
|
|
|
painter.setBrush(Qt::white); |
|
|
|
painter.drawRect(imageRect); |
|
|
|
painter.drawRect(imageRect); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else { |
|
|
|
{ |
|
|
|
|
|
|
|
if (m_image.width() != imageRect.width()) |
|
|
|
if (m_image.width() != imageRect.width()) |
|
|
|
updateImage(); |
|
|
|
updateImage(); |
|
|
|
painter.drawImage(imageRect, m_image); |
|
|
|
painter.drawImage(imageRect, m_image); |
|
|
@ -236,4 +228,3 @@ void PieceAvailabilityBar::setColors(int background, int border, int available) |
|
|
|
updateImage(); |
|
|
|
updateImage(); |
|
|
|
update(); |
|
|
|
update(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|