mirror of
https://github.com/wownero/wowlet.git
synced 2026-11-21 07:34:14 +01:00
wowlet: pixel-art mining tab — port mining.qml (Qt6) + 25 assets, MiningWidget/MiningBackend hosting QQuickWidget, wired to embedded-node solo miner (hashrate/sync feedback); adds Qt6 Quick
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
// SPDX-FileCopyrightText: The Monero Project
|
||||
|
||||
#include "MiningWidget.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QQmlContext>
|
||||
#include <QThread>
|
||||
|
||||
MiningWidget::MiningWidget(Wallet *wallet, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_wallet(wallet)
|
||||
, m_quickWidget(new QQuickWidget(this))
|
||||
, m_backend(new MiningBackend(this))
|
||||
, m_timer(new QTimer(this))
|
||||
{
|
||||
auto *layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(m_quickWidget);
|
||||
|
||||
m_quickWidget->rootContext()->setContextProperty("mining", m_backend);
|
||||
m_quickWidget->setResizeMode(QQuickWidget::SizeRootObjectToView);
|
||||
m_quickWidget->setSource(QUrl("qrc:/qml/mining.qml"));
|
||||
|
||||
if (auto *root = m_quickWidget->rootObject()) {
|
||||
connect(root, SIGNAL(startMining()), this, SLOT(onStartMining()));
|
||||
connect(root, SIGNAL(stopMining()), this, SLOT(onStopMining()));
|
||||
}
|
||||
|
||||
connect(m_timer, &QTimer::timeout, this, &MiningWidget::poll);
|
||||
m_timer->start(2000);
|
||||
}
|
||||
|
||||
void MiningWidget::onStartMining() {
|
||||
int threads = std::max(1, QThread::idealThreadCount() / 2);
|
||||
if (m_wallet->startMining(threads))
|
||||
m_backend->setState(3);
|
||||
}
|
||||
|
||||
void MiningWidget::onStopMining() {
|
||||
m_wallet->stopMining();
|
||||
m_backend->setState(0);
|
||||
}
|
||||
|
||||
void MiningWidget::poll() {
|
||||
bool mining = m_wallet->isMining();
|
||||
m_backend->setState(mining ? 3 : 0);
|
||||
|
||||
if (mining) {
|
||||
double hr = m_wallet->miningHashRate();
|
||||
QString hrStr = hr >= 1000 ? QString("%1 kH/s").arg(hr / 1000.0, 0, 'f', 2)
|
||||
: QString("%1 H/s").arg(hr, 0, 'f', 0);
|
||||
emit m_backend->hashrate(hrStr);
|
||||
}
|
||||
|
||||
quint64 from = m_wallet->blockChainHeight();
|
||||
quint64 to = m_wallet->daemonBlockChainTargetHeight();
|
||||
if (to > 0) {
|
||||
int pct = static_cast<int>(100.0 * static_cast<double>(from) / static_cast<double>(to));
|
||||
emit m_backend->syncStatus(static_cast<int>(from), static_cast<int>(to), pct);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
// SPDX-FileCopyrightText: The Monero Project
|
||||
|
||||
#ifndef WOWLET_MININGWIDGET_H
|
||||
#define WOWLET_MININGWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QTimer>
|
||||
#include <QQuickWidget>
|
||||
|
||||
#include "libwalletqt/Wallet.h"
|
||||
|
||||
// Context object exposed to mining.qml as `mining`. The QML reads daemonMiningState and reacts to
|
||||
// the hashrate/syncStatus/uptimeChanged/daemonOutput signals.
|
||||
class MiningBackend : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int daemonMiningState READ daemonMiningState NOTIFY daemonMiningStateChanged)
|
||||
public:
|
||||
explicit MiningBackend(QObject *parent = nullptr) : QObject(parent) {}
|
||||
int daemonMiningState() const { return m_state; }
|
||||
void setState(int s) { if (m_state != s) { m_state = s; emit daemonMiningStateChanged(); } }
|
||||
|
||||
signals:
|
||||
void daemonMiningStateChanged();
|
||||
void daemonOutput(const QString &line);
|
||||
void syncStatus(int from, int to, int pct);
|
||||
void uptimeChanged(const QString &uptime);
|
||||
void hashrate(const QString &hashrate);
|
||||
|
||||
private:
|
||||
int m_state = 0; // 0:idle 1:startup 2:syncing 3:mining
|
||||
};
|
||||
|
||||
// wowlet: the pixel-art mining tab. Hosts mining.qml and wires its pick-axe to the wallet's solo
|
||||
// miner (RandomWOW via the embedded node), feeding back hashrate + sync status.
|
||||
class MiningWidget : public QWidget {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MiningWidget(Wallet *wallet, QWidget *parent = nullptr);
|
||||
|
||||
private slots:
|
||||
void onStartMining();
|
||||
void onStopMining();
|
||||
void poll();
|
||||
|
||||
private:
|
||||
Wallet *m_wallet;
|
||||
QQuickWidget *m_quickWidget;
|
||||
MiningBackend *m_backend;
|
||||
QTimer *m_timer;
|
||||
};
|
||||
|
||||
#endif //WOWLET_MININGWIDGET_H
|
||||
Reference in New Issue
Block a user