|
@ -36,12 +36,12 @@ SyncView::SyncView(QWidget* _p): QWidget(_p) |
|
|
|
|
|
|
|
|
void SyncView::paintEvent(QPaintEvent*) |
|
|
void SyncView::paintEvent(QPaintEvent*) |
|
|
{ |
|
|
{ |
|
|
QPainter p(this); |
|
|
QPainter painter(this); |
|
|
p.fillRect(rect(), Qt::white); |
|
|
painter.fillRect(rect(), Qt::white); |
|
|
p.setRenderHint(QPainter::Antialiasing, true); |
|
|
painter.setRenderHint(QPainter::Antialiasing, true); |
|
|
p.setRenderHint(QPainter::HighQualityAntialiasing, true); |
|
|
painter.setRenderHint(QPainter::HighQualityAntialiasing, true); |
|
|
|
|
|
|
|
|
if (!m_client) |
|
|
if (!m_client || !isVisible()) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
|
DownloadMan const* man = m_client->downloadMan(); |
|
|
DownloadMan const* man = m_client->downloadMan(); |
|
@ -57,19 +57,17 @@ void SyncView::paintEvent(QPaintEvent*) |
|
|
unsigned syncCount = syncUnverified + bqs.unknown - syncFrom; |
|
|
unsigned syncCount = syncUnverified + bqs.unknown - syncFrom; |
|
|
|
|
|
|
|
|
// best effort guess. assumes there's no forks.
|
|
|
// best effort guess. assumes there's no forks.
|
|
|
unsigned downloadFrom = m_client->numberFromHash(m_client->isKnown(man->firstBlock()) ? man->firstBlock() : PendingBlockHash); |
|
|
unsigned downloadFrom = sync.state == SyncState::Idle ? m_lastSyncFrom : m_client->numberFromHash(m_client->isKnown(man->firstBlock()) ? man->firstBlock() : PendingBlockHash); |
|
|
unsigned downloadCount = sync.blocksTotal; |
|
|
unsigned downloadCount = sync.state == SyncState::Idle ? m_lastSyncCount : sync.blocksTotal; |
|
|
DownloadMan::Overview overview = man->overview(); |
|
|
unsigned downloadDone = downloadFrom + (sync.state == SyncState::Idle ? m_lastSyncCount : sync.blocksReceived); |
|
|
unsigned downloadDone = downloadFrom + overview.total; |
|
|
unsigned downloadPoint = downloadFrom + (sync.state == SyncState::Idle ? m_lastSyncCount : man->overview().lastComplete); |
|
|
// unsigned downloadFlank = downloadFrom + (sync.state == SyncState::Blocks ? overview.firstIncomplete : downloadCount);
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
|
QString labelText = QString("PV%1").arg(sync.protocolVersion); |
|
|
QString labelText = QString("PV%1").arg(sync.protocolVersion); |
|
|
QColor labelBack = QColor::fromHsv(sync.protocolVersion == 60 ? 30 : sync.protocolVersion == 61 ? 120 : 240, 15, 220); |
|
|
QColor labelBack = QColor::fromHsv(sync.protocolVersion == 60 ? 30 : sync.protocolVersion == 61 ? 120 : 240, 25, 200); |
|
|
QColor labelFore = labelBack.darker(); |
|
|
QColor labelFore = labelBack.darker(); |
|
|
switch (sync.state) |
|
|
switch (sync.state) |
|
|
{ |
|
|
{ |
|
@ -112,48 +110,56 @@ void SyncView::paintEvent(QPaintEvent*) |
|
|
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); |
|
|
} |
|
|
} |
|
|
*/ |
|
|
*/ |
|
|
QPen pen; |
|
|
float const squareSize = min(rect().width(), rect().height()); |
|
|
pen.setCapStyle(Qt::FlatCap); |
|
|
|
|
|
float squareSize = min(rect().width(), rect().height()); |
|
|
|
|
|
auto middleRect = [&](float w, float h) { |
|
|
auto middleRect = [&](float w, float h) { |
|
|
return QRectF(squareSize / 2 - w / 2, squareSize / 2 - h / 2, w, h); |
|
|
return QRectF(rect().width() / 2 - w / 2, rect().height() / 2 - h / 2, w, h); |
|
|
}; |
|
|
}; |
|
|
auto middle = [&](float x) { |
|
|
auto middle = [&](float x) { |
|
|
return middleRect(squareSize * x, squareSize * x); |
|
|
return middleRect(squareSize * x, squareSize * x); |
|
|
}; |
|
|
}; |
|
|
auto arcLen = [&](unsigned x) { |
|
|
auto pieProgress = [&](unsigned h, unsigned s, unsigned v, float size, float thickness, unsigned nfrom, unsigned ncount) { |
|
|
return x * -5760.f / count; |
|
|
auto arcLen = [&](unsigned x) { |
|
|
|
|
|
return x * -5760.f / count; |
|
|
|
|
|
}; |
|
|
|
|
|
auto arcPos = [&](unsigned x) { |
|
|
|
|
|
return int(90 * 16.f + arcLen(x - from)) % 5760; |
|
|
|
|
|
}; |
|
|
|
|
|
painter.setPen(QPen(QColor::fromHsv(h, s, v), squareSize * thickness, Qt::SolidLine, Qt::FlatCap)); |
|
|
|
|
|
painter.setBrush(Qt::NoBrush); |
|
|
|
|
|
painter.drawArc(middle(size), arcPos(nfrom), arcLen(ncount)); |
|
|
}; |
|
|
}; |
|
|
auto arcPos = [&](unsigned x) { |
|
|
auto pieProgress2 = [&](unsigned h, unsigned s, unsigned v, float size, float orbit, float thickness, unsigned nfrom, unsigned ncount) { |
|
|
return int(90 * 16.f + arcLen(x - from)) % 5760; |
|
|
pieProgress(h, s, v, size - orbit, thickness, nfrom, ncount); |
|
|
|
|
|
pieProgress(h, s, v, size + orbit, thickness, nfrom, ncount); |
|
|
}; |
|
|
}; |
|
|
auto progress = [&](unsigned h, unsigned s, unsigned v, float size, float thickness, unsigned nfrom, unsigned ncount) { |
|
|
auto pieLabel = [&](QString text, float points, QColor fore, QColor back) { |
|
|
p.setBrush(Qt::NoBrush); |
|
|
painter.setBrush(QBrush(back)); |
|
|
pen.setColor(QColor::fromHsv(h, s, v)); |
|
|
painter.setFont(QFont("Helvetica", points, QFont::Bold)); |
|
|
pen.setWidthF(squareSize * thickness); |
|
|
QRectF r = painter.boundingRect(middle(1.f), Qt::AlignCenter, text); |
|
|
p.setPen(pen); |
|
|
r.adjust(-r.width() / 4, -r.height() / 8, r.width() / 4, r.height() / 8); |
|
|
p.drawArc(middle(size), arcPos(nfrom), arcLen(ncount)); |
|
|
painter.setPen(QPen(fore, r.height() / 20)); |
|
|
|
|
|
painter.drawRoundedRect(r, r.height() / 4, r.height() / 4); |
|
|
|
|
|
painter.drawText(r, Qt::AlignCenter, text); |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
progress(0, 0, 220, 0.6f, 0.02f, from, hashDone); // Download rail
|
|
|
function<void(unsigned h, unsigned s, unsigned v, float size, float thickness, unsigned nfrom, unsigned ncount)> progress = pieProgress; |
|
|
progress(240, 25, 170, 0.6f, 0.02f, downloadDone, downloadPoint - downloadDone); // Latest download point
|
|
|
function<void(unsigned h, unsigned s, unsigned v, float size, float orbit, float thickness, unsigned nfrom, unsigned ncount)> progress2 = pieProgress2; |
|
|
progress(240, 50, 120, 0.6f, 0.04f, from, downloadDone - from); // Downloaded
|
|
|
function<void(QString text, float points, QColor fore, QColor back, )> label = pieLabel; |
|
|
|
|
|
|
|
|
|
|
|
if (sync.state != SyncState::Idle) |
|
|
|
|
|
{ |
|
|
|
|
|
progress(0, 0, 220, 0.6f, 0.02f, from, hashDone - from); // Download rail
|
|
|
|
|
|
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, 220, 0.9f, 0.02f, from, count); // Sync rail
|
|
|
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(0, 0, 170, 0.9f, 0.02f, from, syncUnverified - from); // Verification rail
|
|
|
progress(60, 25, 170, 0.9f, 0.02f, from, syncVerifying - from); // Verifying.
|
|
|
progress2(60, 25, 170, 0.9f, 0.04f, 0.01f, from, syncVerifying - from); // Verifying.
|
|
|
progress(120, 25, 170, 0.9f, 0.02f, from, syncVerified - from); // Verified.
|
|
|
progress2(120, 25, 170, 0.9f, 0.04f, 0.01f, from, syncVerified - from); // Verified.
|
|
|
progress(120, 50, 120, 0.9f, 0.04f, from, syncFrom - from); // Imported.
|
|
|
progress(120, 50, 120, 0.9f, 0.05f, from, syncFrom - from); // Imported.
|
|
|
progress(240, 25, 170, 0.9f, 0.04f, syncFrom, syncImporting - syncFrom); // Importing.
|
|
|
progress(0, 0, 120, 0.9f, 0.02f, syncFrom, syncImporting - syncFrom); // Importing.
|
|
|
|
|
|
|
|
|
if (sync.state != SyncState::Idle || !count) |
|
|
if (sync.state != SyncState::Idle || (sync.state == SyncState::Idle && !syncCount)) |
|
|
{ |
|
|
label(labelText, 11, labelFore, labelBack); |
|
|
p.setBrush(QBrush(labelBack)); |
|
|
|
|
|
p.setFont(QFont("Helvetica", 10, QFont::Bold)); |
|
|
|
|
|
QRectF r = p.boundingRect(middle(1.f), Qt::AlignCenter, labelText); |
|
|
|
|
|
r.adjust(-r.width() / 8, -r.height() / 8, r.width() / 8, r.height() / 8); |
|
|
|
|
|
p.setPen(QPen(labelFore, r.height() / 10)); |
|
|
|
|
|
p.drawRoundedRect(r, r.height() / 4, r.height() / 4); |
|
|
|
|
|
p.drawText(r, Qt::AlignCenter, labelText); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|