first modifications to improve BW graph

This commit is contained in:
csoler 2021-01-30 00:03:10 +01:00
parent e0ed60ee6f
commit 60893e2344
7 changed files with 385 additions and 462 deletions

View File

@ -180,6 +180,7 @@ public:
void setFiltering(bool b) ;
uint32_t getFlags() const { return _flags ; }
void setFlags(uint32_t flag) { _flags |= flag ; }
void resetFlags(uint32_t flag) { _flags &= ~flag ; }
protected:

View File

@ -181,6 +181,7 @@
<file>images/go-bottom.png</file>
<file>images/graph-area.png</file>
<file>images/graph-line.png</file>
<file>images/graph-line-inverted.png</file>
<file>images/gpgp_key_generate.png</file>
<file>images/hide_toolbox_frame.png</file>
<file>images/hide_frame.png</file>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -48,7 +48,7 @@ public:
enum { SELECTOR_TYPE_FRIEND=0x00, SELECTOR_TYPE_SERVICE=0x01 };
enum { GRAPH_TYPE_SINGLE=0x00, GRAPH_TYPE_ALL=0x01, GRAPH_TYPE_SUM=0x02 };
enum { UNIT_KILOBYTES=0x00, UNIT_COUNT=0x01 };
enum { DIRECTION_UP=0x00, DIRECTION_DOWN=0x01 };
enum { DIRECTION_UP=0x02, DIRECTION_DOWN=0x01 };
// re-derived from RSGraphSource

View File

@ -19,11 +19,13 @@
* *
*******************************************************************************/
#include <rshare.h>
#include <control/bandwidthevent.h>
#include <gui/statistics/BandwidthGraphWindow.h>
#include <retroshare-gui/RsAutoUpdatePage.h>
#include <retroshare/rsconfig.h>
#include "rshare.h"
#include "control/bandwidthevent.h"
#include "gui/statistics/BandwidthGraphWindow.h"
#include "gui/common/FilesDefs.h"
#include "util/misc.h"
#include "retroshare-gui/RsAutoUpdatePage.h"
#include "retroshare/rsconfig.h"
#include <iomanip>
#include <unistd.h>
@ -51,6 +53,12 @@
/* Images used in the graph style drop-down */
#define IMG_AREA_GRAPH ":/images/16x16/graph-area.png"
#define IMG_LINE_GRAPH ":/images/16x16/graph-line.png"
#define IMG_SETTINGS ":/icons/system_128.png"
#define IMG_CLEANUP ":/images/global_switch_off.png"
#define IMG_SEND ":/images/go-up.png"
#define IMG_RECEIVE ":/images/go-down.png"
#define IMG_GRAPH_DARK ":/images/graph-line.png"
#define IMG_GRAPH_LIGHT ":/images/graph-line-inverted.png"
/** Default constructor */
@ -65,9 +73,6 @@ BandwidthGraph::BandwidthGraph(QWidget *parent, Qt::WindowFlags flags)
setShortcut("Ctrl+W", SLOT(close()));
#endif
/* Bind events to actions */
createActions();
/* Ask RetroShare core to notify us about bandwidth updates */
//_rsControl = RetroShare::rsControl();
//_rsControl->setEvent(REvents::Bandwidth, this, true);
@ -77,7 +82,6 @@ BandwidthGraph::BandwidthGraph(QWidget *parent, Qt::WindowFlags flags)
/* Hide Bandwidth Graph Settings frame */
showSettingsFrame(false);
/* Load the previously saved settings */
loadSettings();
/* Turn off opacity group on unsupported platforms */
#if defined(Q_OS_WIN)
@ -88,18 +92,63 @@ BandwidthGraph::BandwidthGraph(QWidget *parent, Qt::WindowFlags flags)
#if defined(Q_OS_LINUX)
ui.frmOpacity->setVisible(false);
ui.chkAlwaysOnTop->setVisible(false);
ui.btnToggleSettings->setVisible(false); // this is only windows settings anyway
#endif
ui.btnToggleSettings->setIcon(FilesDefs::getIconFromQtResourcePath(IMG_SETTINGS));
ui.btnToggleSettings->setText("");
ui.btnReset->setIcon(FilesDefs::getIconFromQtResourcePath(IMG_CLEANUP));
ui.btnReset->setText("");
ui.chkSendRate->setIcon(FilesDefs::getIconFromQtResourcePath(IMG_SEND));
ui.chkSendRate->setText("");
ui.chkReceiveRate->setIcon(FilesDefs::getIconFromQtResourcePath(IMG_RECEIVE));
ui.chkReceiveRate->setText("");
ui.frmGraph->setToolTip("Use Ctrl+mouse wheel to change line width, Shift+wheel to time-filter the curve.");
loadSettings();
connect(ui.btnToggleSettings,SIGNAL(toggled(bool)),this,SLOT(showSettingsFrame(bool)));
connect(ui.btnReset, SIGNAL(clicked()), this, SLOT(reset()));
connect(ui.sldrOpacity, SIGNAL(valueChanged(int)), this, SLOT(setOpacity(int)));
connect(ui.btnGraphColor, SIGNAL(clicked()), this, SLOT(switchGraphColor()));
connect(ui.chkSendRate, SIGNAL(toggled(bool)), this, SLOT(toggleSendRate(bool)));
connect(ui.chkReceiveRate, SIGNAL(toggled(bool)), this, SLOT(toggleReceiveRate(bool)));
}
/** Binds events to actions. */
void
BandwidthGraph::createActions()
void BandwidthGraph::toggleSendRate(bool b)
{
connect(ui.btnToggleSettings, SIGNAL(toggled(bool)), this, SLOT(showSettingsFrame(bool)));
connect(ui.btnReset, SIGNAL(clicked()), this, SLOT(reset()));
connect(ui.btnSaveSettings, SIGNAL(clicked()), this, SLOT(saveChanges()));
connect(ui.btnCancelSettings, SIGNAL(clicked()), this, SLOT(cancelChanges()));
connect(ui.sldrOpacity, SIGNAL(valueChanged(int)), this, SLOT(setOpacity(int)));
whileBlocking(ui.chkReceiveRate)->setChecked(!b);
if(b)
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_UP) ;
else
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_DOWN) ;
}
void BandwidthGraph::toggleReceiveRate(bool b)
{
whileBlocking(ui.chkSendRate)->setChecked(!b);
if(b)
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_DOWN) ;
else
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_UP) ;
}
void BandwidthGraph::switchGraphColor()
{
if(ui.frmGraph->getFlags() & RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE)
{
ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
ui.btnGraphColor->setIcon(FilesDefs::getIconFromQtResourcePath(IMG_GRAPH_LIGHT));
}
else
{
ui.frmGraph->setFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
ui.btnGraphColor->setIcon(FilesDefs::getIconFromQtResourcePath(IMG_GRAPH_DARK));
}
}
/** Loads the saved Bandwidth Graph settings. */
@ -110,15 +159,6 @@ BandwidthGraph::loadSettings()
ui.sldrOpacity->setValue(getSetting(SETTING_OPACITY, DEFAULT_OPACITY).toInt());
setOpacity(ui.sldrOpacity->value());
/* Set whether the window appears on top. */
ui.chkAlwaysOnTop->setChecked(getSetting(SETTING_ALWAYS_ON_TOP, DEFAULT_ALWAYS_ON_TOP).toBool());
if (ui.chkAlwaysOnTop->isChecked()) {
setWindowFlags(windowFlags() | Qt::WindowStaysOnTopHint);
} else {
setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
}
/* Set the line filter checkboxes accordingly */
uint filter = getSetting(SETTING_FILTER, DEFAULT_FILTER).toUInt();
ui.chkReceiveRate->setChecked(filter & BWGRAPH_LINE_RECV);
@ -127,10 +167,10 @@ BandwidthGraph::loadSettings()
/* Set whether we are plotting bandwidth as area graphs or not */
int graphStyle = getSetting(SETTING_STYLE, DEFAULT_STYLE).toInt();
if (graphStyle < 0 || graphStyle >= ui.cmbGraphStyle->count()) {
graphStyle = DEFAULT_STYLE;
}
ui.cmbGraphStyle->setCurrentIndex(graphStyle);
// if (graphStyle < 0 || graphStyle >= ui.cmbGraphStyle->count()) {
// graphStyle = DEFAULT_STYLE;
// }
// ui.cmbGraphStyle->setCurrentIndex(graphStyle);
if(graphStyle==0)
ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_PLAIN);
@ -140,28 +180,37 @@ BandwidthGraph::loadSettings()
/* Set whether we are plotting bandwidth as area graphs or not */
int graphColor = getSetting(SETTING_GRAPHCOLOR, DEFAULT_GRAPHCOLOR).toInt();
if (graphColor < 0 || graphColor >= ui.cmbGraphColor->count()) {
graphColor = DEFAULT_GRAPHCOLOR;
}
ui.cmbGraphColor->setCurrentIndex(graphColor);
if(graphColor==0)
if(graphColor>0)
{
ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
ui.btnGraphColor->setIcon(FilesDefs::getIconFromQtResourcePath(IMG_GRAPH_DARK));
}
else
{
ui.btnGraphColor->setIcon(FilesDefs::getIconFromQtResourcePath(IMG_GRAPH_LIGHT));
ui.frmGraph->setFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
}
/* Download & Upload */
int defaultdirection = getSetting(SETTING_DIRECTION, DEFAULT_DIRECTION).toInt();
if (defaultdirection < 0 || defaultdirection >= ui.cmbDownUp->count()) {
defaultdirection = DEFAULT_DIRECTION;
}
ui.cmbDownUp->setCurrentIndex(graphColor);
// if (defaultdirection < 0 || defaultdirection >= ui.cmbDownUp->count()) {
// defaultdirection = DEFAULT_DIRECTION;
// }
// ui.cmbDownUp->setCurrentIndex(graphColor);
if(defaultdirection==0)
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_UP) ;
else
if(defaultdirection>0)
{
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_DOWN) ;
whileBlocking(ui.chkSendRate)->setChecked(false);
whileBlocking(ui.chkReceiveRate)->setChecked(true);
}
else
{
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_UP) ;
whileBlocking(ui.chkSendRate)->setChecked(true);
whileBlocking(ui.chkReceiveRate)->setChecked(false);
}
/* Default Settings for the Graph */
ui.frmGraph->setSelector(BWGraphSource::SELECTOR_TYPE_FRIEND,BWGraphSource::GRAPH_TYPE_SUM) ;
@ -172,13 +221,11 @@ BandwidthGraph::loadSettings()
ui.frmGraph->setShowEntry(1,ui.chkSendRate->isChecked()) ;
}
/** Resets the log start time. */
void BandwidthGraph::reset()
{
/* Set to current time */
ui.statusbar->showMessage(tr("Since:") + " " + QDateTime::currentDateTime() .toString(DATETIME_FMT));
ui.displayTime_LB->setText(tr("Since:") + " " + QDateTime::currentDateTime() .toString(DATETIME_FMT));
/* Reset the graph */
ui.frmGraph->resetGraph();
}
@ -191,8 +238,8 @@ void BandwidthGraph::saveChanges()
/* Save the opacity and graph style */
saveSetting(SETTING_OPACITY, ui.sldrOpacity->value());
saveSetting(SETTING_STYLE, ui.cmbGraphStyle->currentIndex());
saveSetting(SETTING_GRAPHCOLOR, ui.cmbGraphColor->currentIndex());
// saveSetting(SETTING_STYLE, ui.cmbGraphStyle->currentIndex());
saveSetting(SETTING_GRAPHCOLOR, ui.btnGraphColor->isChecked());
/* Save the Always On Top setting */
saveSetting(SETTING_ALWAYS_ON_TOP, ui.chkAlwaysOnTop->isChecked());
@ -213,21 +260,22 @@ void BandwidthGraph::saveChanges()
/* Update the graph frame settings */
ui.frmGraph->setShowEntry(0,ui.chkReceiveRate->isChecked()) ;
ui.frmGraph->setShowEntry(1,ui.chkSendRate->isChecked()) ;
if(ui.cmbGraphStyle->currentIndex()==0)
ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_PLAIN);
else
ui.frmGraph->setFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_PLAIN);
if(ui.cmbGraphColor->currentIndex()==0)
// if(ui.cmbGraphStyle->currentIndex()==0)
// ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_PLAIN);
// else
// ui.frmGraph->setFlags(RSGraphWidget::RSGRAPH_FLAGS_PAINT_STYLE_PLAIN);
if(ui.btnGraphColor->isChecked()==0)
ui.frmGraph->resetFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
else
ui.frmGraph->setFlags(RSGraphWidget::RSGRAPH_FLAGS_DARK_STYLE);
if(ui.cmbDownUp->currentIndex()==0)
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_UP) ;
else
ui.frmGraph->setDirection(BWGraphSource::DIRECTION_DOWN) ;
// if(ui.cmbDownUp->currentIndex()==0)
// ui.frmGraph->setDirection(BWGraphSource::DIRECTION_UP) ;
// else
// ui.frmGraph->setDirection(BWGraphSource::DIRECTION_DOWN) ;
/* A change in window flags causes the window to disappear, so make sure
* it's still visible. */
@ -255,16 +303,16 @@ BandwidthGraph::showSettingsFrame(bool show)
if (show) {
/* Extend the bottom of the bandwidth graph and show the settings */
ui.frmSettings->setVisible(true);
ui.btnToggleSettings->setChecked(true);
ui.btnToggleSettings->setText(tr("Hide Settings"));
// ui.btnToggleSettings->setChecked(true);
// ui.btnToggleSettings->setText(tr("Hide Settings"));
/* 6 = vertical spacing between the settings frame and graph frame */
newSize.setHeight(newSize.height() + ui.frmSettings->height() + 6);
} else {
/* Shrink the height of the bandwidth graph and hide the settings */
ui.frmSettings->setVisible(false);
ui.btnToggleSettings->setChecked(false);
ui.btnToggleSettings->setText(tr("Show Settings"));
// ui.btnToggleSettings->setChecked(false);
// ui.btnToggleSettings->setText(tr("Show Settings"));
/* 6 = vertical spacing between the settings frame and graph frame */
newSize.setHeight(newSize.height() - ui.frmSettings->height() - 6);

View File

@ -51,6 +51,10 @@ public slots:
void showWindow();
private slots:
void switchGraphColor();
void toggleReceiveRate(bool b);
void toggleSendRate(bool b);
/** Called when settings button is toggled */
void showSettingsFrame(bool show);
/** Called when the settings button is toggled */

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>418</width>
<height>305</height>
<width>620</width>
<height>432</height>
</rect>
</property>
<property name="windowTitle">
@ -18,8 +18,27 @@
<normaloff>:/images/logo/logo_16.png</normaloff>:/images/logo/logo_16.png</iconset>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="BWGraph" name="frmGraph" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>120</width>
<height>80</height>
</size>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="_8">
<property name="spacing">
<number>6</number>
@ -36,6 +55,70 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QToolButton" name="btnGraphColor">
<property name="text">
<string>PushButton</string>
</property>
<property name="checkable">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="chkSendRate">
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="toolTip">
<string/>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Up</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="chkReceiveRate">
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="toolTip">
<string/>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Down</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnReset">
<property name="toolTip">
<string>Clears the graph</string>
</property>
<property name="text">
<string>Reset</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnToggleSettings">
<property name="text">
@ -60,15 +143,15 @@
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnReset">
<widget class="QLabel" name="displayTime_LB">
<property name="text">
<string>Reset</string>
<string>TextLabel</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0">
<item>
<widget class="QFrame" name="frmSettings">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
@ -97,146 +180,7 @@
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>9</number>
</property>
<property name="topMargin">
<number>9</number>
</property>
<property name="rightMargin">
<number>9</number>
</property>
<property name="bottomMargin">
<number>9</number>
</property>
<item row="0" column="0" rowspan="2">
<layout class="QVBoxLayout" name="_2">
<property name="spacing">
<number>6</number>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<widget class="QCheckBox" name="chkReceiveRate">
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="toolTip">
<string/>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Receive Rate</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkSendRate">
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
<property name="toolTip">
<string/>
</property>
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Send Rate</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkAlwaysOnTop">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Always on Top</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>21</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="0" column="4" rowspan="2">
<layout class="QVBoxLayout" name="_7">
<property name="spacing">
<number>1</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="btnSaveSettings">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCancelSettings">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="3">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>21</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="0" column="1" rowspan="2" colspan="2">
<widget class="QWidget" name="">
<layout class="QVBoxLayout" name="_3">
<property name="spacing">
<number>1</number>
@ -270,76 +214,6 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Style</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cmbGraphStyle">
<item>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/graph-line.png</normaloff>:/images/graph-line.png</iconset>
</property>
</item>
<item>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../images.qrc">
<normaloff>:/images/graph-area.png</normaloff>:/images/graph-area.png</iconset>
</property>
</item>
</widget>
</item>
<item>
<widget class="QComboBox" name="cmbGraphColor">
<item>
<property name="text">
<string>Default</string>
</property>
</item>
<item>
<property name="text">
<string>Dark</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QComboBox" name="cmbDownUp">
<item>
<property name="text">
<string>Upload</string>
</property>
</item>
<item>
<property name="text">
<string>Download</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
@ -491,6 +365,16 @@
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="chkAlwaysOnTop">
<property name="layoutDirection">
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Always on Top</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
@ -510,26 +394,11 @@
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item row="0" column="0">
<widget class="BWGraph" name="frmGraph" native="true">
<property name="minimumSize">
<size>
<width>120</width>
<height>80</height>
</size>
</property>
<property name="contextMenuPolicy">
<enum>Qt::NoContextMenu</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<customwidgets>
<customwidget>