Browse Source

More easily accessible d/l viz.

cl-refactor
Gav Wood 10 years ago
parent
commit
b9e6d54a39
  1. 127
      alethzero/DownloadView.cpp
  2. 5
      alethzero/DownloadView.h

127
alethzero/DownloadView.cpp

@ -38,6 +38,8 @@ void SyncView::paintEvent(QPaintEvent*)
{ {
QPainter p(this); QPainter p(this);
p.fillRect(rect(), Qt::white); p.fillRect(rect(), Qt::white);
p.setRenderHint(QPainter::Antialiasing, true);
p.setRenderHint(QPainter::HighQualityAntialiasing, true);
if (!m_client) if (!m_client)
return; return;
@ -59,23 +61,47 @@ void SyncView::paintEvent(QPaintEvent*)
unsigned downloadCount = sync.blocksTotal; unsigned downloadCount = sync.blocksTotal;
DownloadMan::Overview overview = man->overview(); DownloadMan::Overview overview = man->overview();
unsigned downloadDone = downloadFrom + overview.total; unsigned downloadDone = downloadFrom + overview.total;
unsigned downloadFlank = downloadFrom + overview.firstIncomplete; // unsigned downloadFlank = downloadFrom + (sync.state == SyncState::Blocks ? overview.firstIncomplete : downloadCount);
unsigned downloadPoint = downloadFrom + overview.lastComplete; unsigned downloadPoint = downloadFrom + (sync.state == SyncState::Blocks ? overview.lastComplete : downloadCount);
unsigned hashFrom = sync.state == SyncState::Hashes ? m_client->numberFromHash(PendingBlockHash) : downloadFrom; unsigned hashFrom = sync.state == SyncState::Hashes ? m_client->numberFromHash(PendingBlockHash) : downloadFrom;
unsigned hashCount = sync.state == SyncState::Hashes ? sync.hashesTotal : downloadCount; unsigned hashCount = sync.state == SyncState::Hashes ? sync.hashesTotal : downloadCount;
unsigned hashDone = hashFrom + (sync.state == SyncState::Hashes ? sync.hashesReceived : hashCount); unsigned hashDone = hashFrom + (sync.state == SyncState::Hashes ? sync.hashesReceived : hashCount);
unsigned from = min(min(hashFrom, downloadFrom), syncFrom); QString labelText = QString("PV%1").arg(sync.protocolVersion);
unsigned count = max(max(hashFrom + hashCount, downloadFrom + downloadCount), syncFrom + syncCount) - from; QColor labelBack = QColor::fromHsv(sync.protocolVersion == 60 ? 30 : sync.protocolVersion == 61 ? 120 : 240, 15, 220);
QColor labelFore = labelBack.darker();
if (!count) switch (sync.state)
{ {
m_lastFrom = m_lastTo = (unsigned)-1; case SyncState::Hashes:
return; m_lastSyncFrom = hashFrom;
m_lastSyncCount = hashCount;
m_wasEstimate = sync.hashesEstimated;
break;
case SyncState::Blocks:
if (m_wasEstimate)
{
m_lastSyncFrom = downloadFrom;
m_lastSyncCount = downloadCount;
m_wasEstimate = false;
}
break;
case SyncState::Idle:
if (!syncCount)
{
m_lastSyncFrom = (unsigned)-1;
m_lastSyncCount = 0;
labelBack = QColor::fromHsv(0, 0, 200);
labelFore = Qt::white;
labelText = "Idle";
}
default: break;
} }
cnote << "Range " << from << "-" << (from + count) << "(" << hashFrom << "+" << hashCount << "," << downloadFrom << "+" << downloadCount << "," << syncFrom << "+" << syncCount << ")"; unsigned from = min(min(hashFrom, downloadFrom), min(syncFrom, m_lastSyncFrom));
unsigned count = max(max(hashFrom + hashCount, downloadFrom + downloadCount), max(syncFrom + syncCount, m_lastSyncFrom + m_lastSyncCount)) - from;
/* cnote << "Range " << from << "-" << (from + count) << "(" << hashFrom << "+" << hashCount << "," << downloadFrom << "+" << downloadCount << "," << syncFrom << "+" << syncCount << ")";
auto r = [&](unsigned u) { auto r = [&](unsigned u) {
return toString((u - from) * 100 / count) + "%"; return toString((u - from) * 100 / count) + "%";
}; };
@ -85,27 +111,22 @@ void SyncView::paintEvent(QPaintEvent*)
cnote << "Hashes:" << r(hashDone) << " Blocks:" << r(downloadFlank) << r(downloadDone) << r(downloadPoint); cnote << "Hashes:" << r(hashDone) << " Blocks:" << r(downloadFlank) << r(downloadDone) << r(downloadPoint);
cnote << "Importing:" << r(syncFrom) << r(syncImported) << r(syncImporting) << r(syncVerified) << r(syncVerifying) << r(syncUnverified); cnote << "Importing:" << r(syncFrom) << r(syncImported) << r(syncImporting) << r(syncVerified) << r(syncVerifying) << r(syncUnverified);
} }
*/
float squareSize = min(rect().width(), rect().height());
QPen pen; QPen pen;
pen.setCapStyle(Qt::FlatCap); pen.setCapStyle(Qt::FlatCap);
pen.setWidthF(squareSize / 20); float squareSize = min(rect().width(), rect().height());
auto middleRect = [&](float w, float h) {
return QRectF(squareSize / 2 - w / 2, squareSize / 2 - h / 2, w, h);
};
auto middle = [&](float x) { auto middle = [&](float x) {
return QRectF(squareSize / 2 - squareSize / 2 * x, 0 + squareSize / 2 - squareSize / 2 * x, squareSize * x, squareSize * x); return middleRect(squareSize * x, squareSize * x);
}; };
auto arcLen = [&](unsigned x) { auto arcLen = [&](unsigned x) {
return x * -5760.f / count; return x * -5760.f / count;
}; };
auto arcPos = [&](unsigned x) { auto arcPos = [&](unsigned x) {
return int(90 * 16.f + arcLen(x - from)) % 5760; return int(90 * 16.f + arcLen(x - from)) % 5760;
}; };
p.setPen(Qt::NoPen);
p.setBrush(QColor::fromHsv(0, 0, 210));
pen.setWidthF(0.f);
p.drawPie(middle(0.4f), arcPos(from), arcLen(hashDone - from));
auto progress = [&](unsigned h, unsigned s, unsigned v, float size, float thickness, unsigned nfrom, unsigned ncount) { auto progress = [&](unsigned h, unsigned s, unsigned v, float size, float thickness, unsigned nfrom, unsigned ncount) {
p.setBrush(Qt::NoBrush); p.setBrush(Qt::NoBrush);
pen.setColor(QColor::fromHsv(h, s, v)); pen.setColor(QColor::fromHsv(h, s, v));
@ -114,57 +135,25 @@ void SyncView::paintEvent(QPaintEvent*)
p.drawArc(middle(size), arcPos(nfrom), arcLen(ncount)); p.drawArc(middle(size), arcPos(nfrom), arcLen(ncount));
}; };
progress(0, 50, 170, 0.4f, 0.12f, downloadFlank, downloadPoint - downloadFlank); progress(0, 0, 220, 0.6f, 0.02f, from, hashDone); // Download rail
progress(0, 0, 150, 0.4f, 0.10f, from, downloadDone - from); progress(240, 25, 170, 0.6f, 0.02f, downloadDone, downloadPoint - downloadDone); // Latest download point
progress(240, 50, 120, 0.6f, 0.04f, from, downloadDone - from); // Downloaded
progress(0, 0, 230, 0.7f, 0.090f, from, syncUnverified - from);
progress(60, 25, 210, 0.7f, 0.08f, from, syncVerifying - from);
progress(120, 25, 190, 0.7f, 0.07f, from, syncVerified - from);
progress(0, 0, 220, 0.9f, 0.02f, from, count);
progress(0, 0, 100, 0.9f, 0.04f, from, syncFrom - from);
progress(0, 50, 100, 0.9f, 0.08f, syncFrom, syncImporting - syncFrom);
return; progress(0, 0, 220, 0.9f, 0.02f, from, count); // Sync rail
progress(0, 0, 170, 0.9f, 0.02f, from, syncUnverified - from); // Verification rail
progress(60, 25, 170, 0.9f, 0.02f, from, syncVerifying - from); // Verifying.
progress(120, 25, 170, 0.9f, 0.02f, from, syncVerified - from); // Verified.
progress(120, 50, 120, 0.9f, 0.04f, from, syncFrom - from); // Imported.
progress(240, 25, 170, 0.9f, 0.04f, syncFrom, syncImporting - syncFrom); // Importing.
double ratio = (double)rect().width() / rect().height(); if (sync.state != SyncState::Idle || !count)
if (ratio < 1)
ratio = 1 / ratio;
double n = min(16.0, min(rect().width(), rect().height()) / ceil(sqrt(man->chainSize() / ratio)));
// QSizeF area(rect().width() / floor(rect().width() / n), rect().height() / floor(rect().height() / n));
QSizeF area(n, n);
QPointF pos(0, 0);
auto bg = man->blocksGot();
unsigned subCount = man->subCount();
if (subCount == 0)
return;
unsigned dh = 360 / subCount;
for (unsigned i = bg.all().first, ei = bg.all().second; i < ei; ++i)
{ {
int s = -2; p.setBrush(QBrush(labelBack));
if (bg.contains(i)) p.setFont(QFont("Helvetica", 10, QFont::Bold));
s = -1; QRectF r = p.boundingRect(middle(1.f), Qt::AlignCenter, labelText);
else r.adjust(-r.width() / 8, -r.height() / 8, r.width() / 8, r.height() / 8);
{ p.setPen(QPen(labelFore, r.height() / 10));
unsigned h = 0; p.drawRoundedRect(r, r.height() / 4, r.height() / 4);
man->foreachSub([&](DownloadSub const& sub) p.drawText(r, Qt::AlignCenter, labelText);
{
if (sub.askedContains(i))
s = h;
h++;
});
}
if (s == -2)
p.fillRect(QRectF(QPointF(pos) + QPointF(3 * area.width() / 8, 3 * area.height() / 8), area / 4), Qt::black);
else if (s == -1)
p.fillRect(QRectF(QPointF(pos) + QPointF(1 * area.width() / 8, 1 * area.height() / 8), area * 3 / 4), Qt::black);
else
p.fillRect(QRectF(QPointF(pos) + QPointF(1 * area.width() / 8, 1 * area.height() / 8), area * 3 / 4), QColor::fromHsv(s * dh, 64, 128));
pos.setX(pos.x() + n);
if (pos.x() >= rect().width() - n)
pos = QPoint(0, pos.y() + n);
} }
} }

5
alethzero/DownloadView.h

@ -50,6 +50,7 @@ protected:
private: private:
dev::eth::Client const* m_client = nullptr; dev::eth::Client const* m_client = nullptr;
unsigned m_lastFrom = (unsigned)-1; unsigned m_lastSyncFrom = (unsigned)-1;
unsigned m_lastTo = (unsigned)-1; unsigned m_lastSyncCount = 0;
bool m_wasEstimate = false;
}; };

Loading…
Cancel
Save