-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #336 from ioriayane/add_jetstream_status_display
リアルタイムフィードの状態を表示する機能の追加
- Loading branch information
Showing
19 changed files
with
802 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import QtQuick 2.15 | ||
import QtQuick.Controls 2.15 | ||
import QtQuick.Layouts 1.15 | ||
import QtQuick.Controls.Material 2.15 | ||
|
||
import tech.relog.hagoromo.realtime.realtimefeedstatuslistmodel 1.0 | ||
import tech.relog.hagoromo.realtime.realtimefeedstatusgraph 1.0 | ||
import tech.relog.hagoromo.singleton 1.0 | ||
|
||
Frame { | ||
id: realtimeFeedStatusFrame | ||
property int theme: 0 | ||
|
||
background: Rectangle { | ||
radius: 3 | ||
border.width: 1 | ||
border.color: Material.frameColor | ||
color: Material.backgroundColor | ||
} | ||
|
||
RowLayout { | ||
spacing: 10 | ||
RealtimeFeedStatusGraph { | ||
Layout.preferredWidth: paramLayout.implicitWidth * 1.5 | ||
Layout.preferredHeight: paramLayout.implicitHeight | ||
visible: graphControlLabel.checked | ||
theme: realtimeFeedStatusFrame.theme | ||
} | ||
ColumnLayout { | ||
id: paramLayout | ||
Repeater { | ||
model: RealtimeFeedStatusListModel { | ||
theme: realtimeFeedStatusFrame.theme | ||
} | ||
RowLayout { | ||
Label { | ||
Layout.minimumWidth: 100 * AdjustedValues.ratio | ||
font.pointSize: AdjustedValues.f8 | ||
text: model.name | ||
color: model.useColor ? model.color : Material.foreground | ||
} | ||
Label { | ||
Layout.fillWidth: true | ||
horizontalAlignment: Text.AlignRight | ||
font.pointSize: AdjustedValues.f8 | ||
text: model.value | ||
} | ||
Label { | ||
font.pointSize: AdjustedValues.f6 | ||
text: model.unit | ||
} | ||
} | ||
} | ||
Label { | ||
id: graphControlLabel | ||
Layout.fillWidth: true | ||
horizontalAlignment: Text.AlignRight | ||
font.pointSize: AdjustedValues.f8 | ||
text: (checked ? "■" : "□")+"History" | ||
color: Material.color(Material.Blue) | ||
property bool checked: false | ||
MouseArea { | ||
anchors.fill: parent | ||
onClicked: graphControlLabel.checked = !graphControlLabel.checked | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
#include "realtimefeedstatusgraph.h" | ||
|
||
#include "realtime/firehosereceiver.h" | ||
|
||
#include <QPainter> | ||
#include <QPainterPath> | ||
|
||
using namespace RealtimeFeed; | ||
|
||
constexpr int GRAPH_POINT_COUNT = 60; // 2以上にすること | ||
|
||
RealtimeFeedStatusGraph::RealtimeFeedStatusGraph(QQuickPaintedItem *parent) | ||
: QQuickPaintedItem(parent), m_maxValue { 0 }, m_theme { 0 } | ||
{ | ||
appendGraphData("app.bsky.feed.post", QColor(255, 255, 0)); | ||
appendGraphData("app.bsky.feed.repost", QColor(255, 0, 255)); | ||
appendGraphData("app.bsky.feed.like", QColor(0, 255, 255)); | ||
appendGraphData("app.bsky.graph.follow", QColor(255, 0, 0)); | ||
appendGraphData("app.bsky.graph.listitem", QColor(0, 255, 0)); | ||
|
||
updateColorByTheme(); | ||
|
||
FirehoseReceiver *receiver = FirehoseReceiver::getInstance(); | ||
connect(receiver, &FirehoseReceiver::analysisChanged, this, | ||
&RealtimeFeedStatusGraph::receiverAnalysisChanged); | ||
} | ||
|
||
RealtimeFeedStatusGraph::~RealtimeFeedStatusGraph() | ||
{ | ||
FirehoseReceiver *receiver = FirehoseReceiver::getInstance(); | ||
disconnect(receiver, &FirehoseReceiver::analysisChanged, this, | ||
&RealtimeFeedStatusGraph::receiverAnalysisChanged); | ||
} | ||
|
||
void RealtimeFeedStatusGraph::paint(QPainter *painter) | ||
{ | ||
QElapsedTimer timer; | ||
timer.start(); | ||
|
||
qreal d = boundingRect().width() / static_cast<qreal>(GRAPH_POINT_COUNT - 1); | ||
|
||
painter->setPen(QColor(128, 128, 128)); | ||
painter->drawRect(boundingRect()); | ||
|
||
QHashIterator<QString, QList<int>> i(m_graphData); | ||
int max_value = m_maxValue + 1; | ||
int height = boundingRect().height(); | ||
while (i.hasNext()) { | ||
i.next(); | ||
painter->setPen(m_graphColor.value(i.key(), QColor(128, 128, 128))); | ||
|
||
QPainterPath path; | ||
qreal x = 0; | ||
for (const auto &value : i.value()) { | ||
if (x == 0) { | ||
path.moveTo(x, height - height * value / max_value); | ||
} else { | ||
path.lineTo(x, height - height * value / max_value); | ||
} | ||
x += d; | ||
} | ||
painter->drawPath(path); | ||
} | ||
} | ||
|
||
void RealtimeFeedStatusGraph::receiverAnalysisChanged() | ||
{ | ||
|
||
FirehoseReceiver *receiver = FirehoseReceiver::getInstance(); | ||
const QHash<QString, QString> nsids_rps = receiver->nsidsReceivePerSecond(); | ||
|
||
QHashIterator<QString, QString> i(nsids_rps); | ||
m_maxValue = 0; | ||
int max = 0; | ||
while (i.hasNext()) { | ||
i.next(); | ||
const int value = i.value().toInt(); | ||
max = updateGraphData(i.key(), value); | ||
m_maxValue = qMax(max, m_maxValue); | ||
} | ||
|
||
// 再描画 | ||
update(); | ||
} | ||
|
||
void RealtimeFeedStatusGraph::appendGraphData(const QString &id, const QColor &color) | ||
{ | ||
m_graphColor[id] = color; | ||
m_graphData[id].clear(); | ||
for (int i = 0; i < GRAPH_POINT_COUNT; i++) { | ||
m_graphData[id].append(0); | ||
} | ||
} | ||
|
||
int RealtimeFeedStatusGraph::updateGraphData(const QString &id, const int value) | ||
{ | ||
if (m_graphData[id].isEmpty()) { | ||
m_graphData[id].append(value); | ||
} else { | ||
m_graphData[id].pop_front(); | ||
m_graphData[id].push_back(value); | ||
} | ||
int max = 0; | ||
if (!id.startsWith("_")) { | ||
for (const auto &v : m_graphData[id]) { | ||
max = qMax(v, max); | ||
} | ||
} | ||
return max; | ||
} | ||
|
||
void RealtimeFeedStatusGraph::updateColorByTheme() | ||
{ | ||
if (theme() == 0) { | ||
// Light | ||
m_graphColor["app.bsky.feed.post"] = QColor(0x3F, 0x51, 0xB5); // Indigo | ||
m_graphColor["app.bsky.feed.repost"] = QColor(0x4C, 0xAF, 0x50); // Green | ||
m_graphColor["app.bsky.feed.like"] = QColor(0xE9, 0x1E, 0x63); // Pink | ||
m_graphColor["app.bsky.graph.follow"] = QColor(0x03, 0xA9, 0xF4); // LightBlue | ||
m_graphColor["app.bsky.graph.listitem"] = QColor(0xFF, 0x98, 0x0); // Orange | ||
} else { | ||
// Dark | ||
m_graphColor["app.bsky.feed.post"] = QColor(0x9F, 0xA8, 0xDA); | ||
m_graphColor["app.bsky.feed.repost"] = QColor(0xA5, 0xD6, 0xA7); | ||
m_graphColor["app.bsky.feed.like"] = QColor(0xF4, 0x8F, 0xB1); | ||
m_graphColor["app.bsky.graph.follow"] = QColor(0x81, 0xD4, 0xFA); | ||
m_graphColor["app.bsky.graph.listitem"] = QColor(0xFF, 0xCC, 0x80); | ||
} | ||
} | ||
|
||
int RealtimeFeedStatusGraph::theme() const | ||
{ | ||
return m_theme; | ||
} | ||
|
||
void RealtimeFeedStatusGraph::setTheme(int newTheme) | ||
{ | ||
if (m_theme == newTheme) | ||
return; | ||
m_theme = newTheme; | ||
emit themeChanged(); | ||
|
||
updateColorByTheme(); | ||
} |
Oops, something went wrong.