trafficgraphwidget.h raw
1 // Copyright (c) 2011-2022 The Limenka developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5 #ifndef LIMENKA_QT_TRAFFICGRAPHWIDGET_H
6 #define LIMENKA_QT_TRAFFICGRAPHWIDGET_H
7
8 #include <QWidget>
9 #include <QQueue>
10
11 #include <chrono>
12
13 class ClientModel;
14
15 QT_BEGIN_NAMESPACE
16 class QPaintEvent;
17 class QTimer;
18 QT_END_NAMESPACE
19
20 class TrafficGraphWidget : public QWidget
21 {
22 Q_OBJECT
23
24 public:
25 explicit TrafficGraphWidget(QWidget *parent = nullptr);
26 void setClientModel(ClientModel *model);
27 std::chrono::minutes getGraphRange() const;
28
29 protected:
30 void paintEvent(QPaintEvent *) override;
31 int y_value(float value);
32 void mousePressEvent(QMouseEvent *event) override;
33 bool fToggle = true;
34 void mouseMoveEvent(QMouseEvent *event) override;
35 int ttpoint = -1;
36 int x_offset = 0;
37 int y_offset = 0;
38 int64_t tt_time = 0;
39
40 public Q_SLOTS:
41 void updateRates();
42 void updateToolTip();
43 void setGraphRange(std::chrono::minutes new_range);
44 void clear();
45
46 private:
47 void paintPath(QPainterPath &path, QQueue<float> &samples);
48
49 QTimer* timer{nullptr};
50 QTimer* tt_timer{nullptr};
51 float fMax{0.0f};
52 std::chrono::minutes m_range{0};
53 QQueue<float> vSamplesIn;
54 QQueue<float> vSamplesOut;
55 QQueue<int64_t> vTimeStamp;
56 quint64 nLastBytesIn{0};
57 quint64 nLastBytesOut{0};
58 ClientModel* clientModel{nullptr};
59 };
60
61 #endif // LIMENKA_QT_TRAFFICGRAPHWIDGET_H
62