Refine Framework graph legends and history keyboard controls
This commit is contained in:
1 parent
535ac5b480
commit
851e0d1d24
4 files changed
+47
-11
No files matched your search
@@ -39,7 +39,7 @@ void Legend::refresh()
|
||||
const auto text = enabled ? palette().color(QPalette::WindowText) : gray;
|
||||
const auto dot = enabled ? m_chart->color(sensor.id) : gray;
|
||||
links.append(QString("<a href=\"%1\" style=\"color:%2;text-decoration:none\"><span style=\"color:%4\">●</span> <span style=\"text-decoration:%3\">%5</span></a>")
|
||||
.arg(i).arg(text.name(), enabled ? "none" : "line-through", dot.name(), sensor.name.toHtmlEscaped().replace(' ', " ")));
|
||||
.arg(i).arg(text.name(), enabled ? "none" : "line-through", dot.name(), sensor.name.toHtmlEscaped().replace(' ', " ").replace('-', "‑")));
|
||||
}
|
||||
if (!m_extraLink.isEmpty()) links.append(QString("<a href=\"extra\" style=\"color:%1;text-decoration:none\">%2</a>")
|
||||
.arg(palette().color(QPalette::WindowText).name(), m_extraLink.toHtmlEscaped().replace(' ', " ")));
|
||||
|
||||
@@ -151,10 +151,21 @@ QWidget *Window::monitorPage()
|
||||
auto *page = new QWidget; auto *layout = new QVBoxLayout(page);
|
||||
auto *historyRow = new QHBoxLayout;
|
||||
auto *history = new JumpSlider(Qt::Horizontal); history->setObjectName("monitorHistory");
|
||||
// Logarithmic spacing, rounded to whole minutes for a readable selection.
|
||||
history->setRange(0, 1000);
|
||||
// Enough logarithmic positions to represent every whole minute up to 24 hours.
|
||||
history->setRange(0, 10000); history->setSingleStep(10); history->setPageStep(100);
|
||||
const auto historyMinutes = [history] {
|
||||
return qRound(5 * std::pow(288., double(history->value()) / history->maximum()));
|
||||
};
|
||||
const auto historyPosition = [history](int minutes) {
|
||||
return qRound(history->maximum() * std::log(minutes / 5.) / std::log(288.));
|
||||
};
|
||||
const auto savedMinutes = std::clamp(m_settings.value("monitor/historyMinutes", 1440).toInt(), 5, 1440);
|
||||
history->setValue(qRound(1000 * std::log(savedMinutes / 5.) / std::log(288.)));
|
||||
history->setValue(historyPosition(savedMinutes));
|
||||
connect(history, &QSlider::actionTriggered, this, [history, historyMinutes, historyPosition](int action) {
|
||||
if (action != QSlider::SliderSingleStepAdd && action != QSlider::SliderSingleStepSub) return;
|
||||
const int step = action == QSlider::SliderSingleStepAdd ? 1 : -1;
|
||||
history->setSliderPosition(historyPosition(std::clamp(historyMinutes() + step, 5, 1440)));
|
||||
});
|
||||
auto *span = new QLabel; span->setMinimumWidth(fontMetrics().horizontalAdvance("24 h 59 min"));
|
||||
auto *stretch = new QCheckBox("Stretch available data"); stretch->setObjectName("monitorStretch");
|
||||
stretch->setChecked(m_settings.value("monitor/stretch", true).toBool());
|
||||
@@ -173,8 +184,8 @@ QWidget *Window::monitorPage()
|
||||
{{"battery", "Charge level", {}, "%"}, {"battery-rate", "Charge / discharge rate", {}, "W"}}, false);
|
||||
layout->addWidget(batteryGroup);
|
||||
const QList<Chart *> charts{m_frequencyChart, m_powerChart, m_fanChart, m_temperatureChart, m_batteryChart};
|
||||
auto updateHistory = [this, charts, history, stretch, span] {
|
||||
const int minutes = qRound(5 * std::pow(288., history->value() / 1000.));
|
||||
auto updateHistory = [this, charts, historyMinutes, stretch, span] {
|
||||
const int minutes = historyMinutes();
|
||||
span->setText(minutes < 60 ? QString("%1 min").arg(minutes)
|
||||
: minutes % 60 ? QString("%1 h %2 min").arg(minutes / 60).arg(minutes % 60)
|
||||
: QString("%1 h").arg(minutes / 60));
|
||||
|
||||
Reference in new issue
Block a user