mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-25 07:57:19 +00:00
move gihelper to own class from namespace
This action will allow to store data in the helper class. Also notification for high memory usage has been changed from 90 to 80.
This commit is contained in:
parent
8cae273ffb
commit
50f3ef5bba
@ -264,7 +264,7 @@ void AWDataAggregator::setData(const QVariantHash &values)
|
|||||||
// usual case
|
// usual case
|
||||||
setData(QString("cpuTooltip"), values[QString("cpu")].toFloat(), 90.0);
|
setData(QString("cpuTooltip"), values[QString("cpu")].toFloat(), 90.0);
|
||||||
setData(QString("cpuclTooltip"), values[QString("cpucl")].toFloat());
|
setData(QString("cpuclTooltip"), values[QString("cpucl")].toFloat());
|
||||||
setData(QString("memTooltip"), values[QString("mem")].toFloat(), 90.0);
|
setData(QString("memTooltip"), values[QString("mem")].toFloat(), 80.0);
|
||||||
setData(QString("swapTooltip"), values[QString("swap")].toFloat(), 0.0);
|
setData(QString("swapTooltip"), values[QString("swap")].toFloat(), 0.0);
|
||||||
setData(QString("downkbTooltip"), values[QString("downkb")].toFloat());
|
setData(QString("downkbTooltip"), values[QString("downkb")].toFloat());
|
||||||
setData(QString("upkbTooltip"), values[QString("upkb")].toFloat());
|
setData(QString("upkbTooltip"), values[QString("upkb")].toFloat());
|
||||||
|
@ -44,7 +44,7 @@ signals:
|
|||||||
void updateData(const QVariantHash &values);
|
void updateData(const QVariantHash &values);
|
||||||
void toolTipPainted(const QString image) const;
|
void toolTipPainted(const QString image) const;
|
||||||
|
|
||||||
public slots:
|
private slots:
|
||||||
void dataUpdate(const QVariantHash &values);
|
void dataUpdate(const QVariantHash &values);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -60,6 +60,7 @@ GraphicalItem::~GraphicalItem()
|
|||||||
|
|
||||||
delete m_scene;
|
delete m_scene;
|
||||||
delete ui;
|
delete ui;
|
||||||
|
delete m_helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -89,6 +90,7 @@ GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number)
|
|||||||
QString GraphicalItem::image(const QVariant &value)
|
QString GraphicalItem::image(const QVariant &value)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Value" << value;
|
qCDebug(LOG_LIB) << "Value" << value;
|
||||||
|
qDebug() << "Value" << value;
|
||||||
|
|
||||||
m_scene->clear();
|
m_scene->clear();
|
||||||
int scale[2] = {1, 1};
|
int scale[2] = {1, 1};
|
||||||
@ -96,33 +98,25 @@ QString GraphicalItem::image(const QVariant &value)
|
|||||||
// paint
|
// paint
|
||||||
switch (m_type) {
|
switch (m_type) {
|
||||||
case Vertical:
|
case Vertical:
|
||||||
GraphicalItemHelper::paintVertical(
|
m_helper->paintVertical(
|
||||||
GraphicalItemHelper::getPercents(value.toFloat(), m_minValue,
|
m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue));
|
||||||
m_maxValue),
|
|
||||||
m_inactiveColor, m_activeColor, m_width, m_height, m_scene);
|
|
||||||
// scale
|
// scale
|
||||||
scale[1] = -2 * static_cast<int>(m_direction) + 1;
|
scale[1] = -2 * static_cast<int>(m_direction) + 1;
|
||||||
break;
|
break;
|
||||||
case Circle:
|
case Circle:
|
||||||
GraphicalItemHelper::paintCircle(
|
m_helper->paintCircle(
|
||||||
GraphicalItemHelper::getPercents(value.toFloat(), m_minValue,
|
m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue));
|
||||||
m_maxValue),
|
|
||||||
m_inactiveColor, m_activeColor, m_width, m_height, m_scene);
|
|
||||||
// scale
|
// scale
|
||||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
||||||
break;
|
break;
|
||||||
case Graph:
|
case Graph:
|
||||||
GraphicalItemHelper::paintGraph(value.value<QList<float>>(),
|
m_helper->paintGraph(value.value<QList<float>>());
|
||||||
m_activeColor, m_width, m_height,
|
|
||||||
m_scene);
|
|
||||||
// direction option is not recognized by this GI type
|
// direction option is not recognized by this GI type
|
||||||
break;
|
break;
|
||||||
case Horizontal:
|
case Horizontal:
|
||||||
default:
|
default:
|
||||||
GraphicalItemHelper::paintHorizontal(
|
m_helper->paintHorizontal(
|
||||||
GraphicalItemHelper::getPercents(value.toFloat(), m_minValue,
|
m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue));
|
||||||
m_maxValue),
|
|
||||||
m_inactiveColor, m_activeColor, m_width, m_height, m_scene);
|
|
||||||
// scale
|
// scale
|
||||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
||||||
break;
|
break;
|
||||||
@ -137,6 +131,7 @@ QString GraphicalItem::image(const QVariant &value)
|
|||||||
QString url = QString("<img src=\"data:image/png;base64,%1\"/>")
|
QString url = QString("<img src=\"data:image/png;base64,%1\"/>")
|
||||||
.arg(QString(byteArray.toBase64()));
|
.arg(QString(byteArray.toBase64()));
|
||||||
|
|
||||||
|
qDebug() << url;
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,13 +144,13 @@ QString GraphicalItem::bar() const
|
|||||||
|
|
||||||
QString GraphicalItem::activeColor() const
|
QString GraphicalItem::activeColor() const
|
||||||
{
|
{
|
||||||
return GraphicalItemHelper::colorToString(m_activeColor);
|
return m_helper->colorToString(m_activeColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString GraphicalItem::inactiveColor() const
|
QString GraphicalItem::inactiveColor() const
|
||||||
{
|
{
|
||||||
return GraphicalItemHelper::colorToString(m_inactiveColor);
|
return m_helper->colorToString(m_inactiveColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -265,7 +260,7 @@ void GraphicalItem::setActiveColor(const QString _color)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Color" << _color;
|
qCDebug(LOG_LIB) << "Color" << _color;
|
||||||
|
|
||||||
m_activeColor = GraphicalItemHelper::stringToColor(_color);
|
m_activeColor = m_helper->stringToColor(_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -281,7 +276,7 @@ void GraphicalItem::setInactiveColor(const QString _color)
|
|||||||
{
|
{
|
||||||
qCDebug(LOG_LIB) << "Color" << _color;
|
qCDebug(LOG_LIB) << "Color" << _color;
|
||||||
|
|
||||||
m_inactiveColor = GraphicalItemHelper::stringToColor(_color);
|
m_inactiveColor = m_helper->stringToColor(_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -500,7 +495,7 @@ void GraphicalItem::writeConfiguration() const
|
|||||||
|
|
||||||
void GraphicalItem::changeColor()
|
void GraphicalItem::changeColor()
|
||||||
{
|
{
|
||||||
QColor color = GraphicalItemHelper::stringToColor(
|
QColor color = m_helper->stringToColor(
|
||||||
(static_cast<QPushButton *>(sender()))->text());
|
(static_cast<QPushButton *>(sender()))->text());
|
||||||
QColor newColor = QColorDialog::getColor(color, this, tr("Select color"),
|
QColor newColor = QColorDialog::getColor(color, this, tr("Select color"),
|
||||||
QColorDialog::ShowAlphaChannel);
|
QColorDialog::ShowAlphaChannel);
|
||||||
@ -544,6 +539,10 @@ void GraphicalItem::initScene()
|
|||||||
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||||
m_view->resize(m_width + 5, m_height + 5);
|
m_view->resize(m_width + 5, m_height + 5);
|
||||||
|
|
||||||
|
// init helper
|
||||||
|
m_helper = new GraphicalItemHelper(this, m_scene);
|
||||||
|
m_helper->setParameters(m_activeColor, m_inactiveColor, m_width, m_height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include "abstractextitem.h"
|
#include "abstractextitem.h"
|
||||||
|
|
||||||
|
|
||||||
|
class GraphicalItemHelper;
|
||||||
class QGraphicsScene;
|
class QGraphicsScene;
|
||||||
class QGraphicsView;
|
class QGraphicsView;
|
||||||
|
|
||||||
@ -97,6 +98,7 @@ private slots:
|
|||||||
void changeValue(const int state);
|
void changeValue(const int state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
GraphicalItemHelper *m_helper = nullptr;
|
||||||
QGraphicsScene *m_scene = nullptr;
|
QGraphicsScene *m_scene = nullptr;
|
||||||
QGraphicsView *m_view = nullptr;
|
QGraphicsView *m_view = nullptr;
|
||||||
Ui::GraphicalItem *ui;
|
Ui::GraphicalItem *ui;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
#include "graphicalitemhelper.h"
|
#include "graphicalitemhelper.h"
|
||||||
|
|
||||||
|
#include <QColor>
|
||||||
#include <QGraphicsEllipseItem>
|
#include <QGraphicsEllipseItem>
|
||||||
#include <QGraphicsScene>
|
#include <QGraphicsScene>
|
||||||
|
|
||||||
@ -25,40 +26,68 @@
|
|||||||
#include "awdebug.h"
|
#include "awdebug.h"
|
||||||
|
|
||||||
|
|
||||||
void GraphicalItemHelper::paintCircle(const float &percent,
|
GraphicalItemHelper::GraphicalItemHelper(QObject *parent, QGraphicsScene *scene)
|
||||||
const QColor &inactive,
|
: QObject(parent)
|
||||||
const QColor &active, const int &width,
|
, m_scene(scene)
|
||||||
const int &height, QGraphicsScene *scene)
|
|
||||||
{
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
GraphicalItemHelper::~GraphicalItemHelper()
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GraphicalItemHelper::setParameters(const QColor active,
|
||||||
|
const QColor inactive, const int width,
|
||||||
|
const int height)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Use active color" << active << ", inactive" << inactive
|
||||||
|
<< ", width" << width << ", height" << height;
|
||||||
|
|
||||||
|
m_activeColor = active;
|
||||||
|
m_inactiveColor = inactive;
|
||||||
|
m_width = width;
|
||||||
|
m_height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void GraphicalItemHelper::paintCircle(const float &percent)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Paint with percent" << percent;
|
||||||
|
|
||||||
QPen pen;
|
QPen pen;
|
||||||
pen.setWidth(1);
|
pen.setWidth(1);
|
||||||
QGraphicsEllipseItem *circle;
|
QGraphicsEllipseItem *circle;
|
||||||
|
|
||||||
// inactive
|
// inactive
|
||||||
pen.setColor(inactive);
|
pen.setColor(m_inactiveColor);
|
||||||
circle = scene->addEllipse(0.0, 0.0, width, height, pen,
|
circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, pen,
|
||||||
QBrush(inactive, Qt::SolidPattern));
|
QBrush(m_inactiveColor, Qt::SolidPattern));
|
||||||
circle->setSpanAngle(-(1.0f - percent) * 360.0f * 16.0f);
|
circle->setSpanAngle(-(1.0f - percent) * 360.0f * 16.0f);
|
||||||
circle->setStartAngle(90.0f * 16.0f - percent * 360.0f * 16.0f);
|
circle->setStartAngle(90.0f * 16.0f - percent * 360.0f * 16.0f);
|
||||||
// active
|
// active
|
||||||
pen.setColor(active);
|
pen.setColor(m_activeColor);
|
||||||
circle = scene->addEllipse(0.0, 0.0, width, height, pen,
|
circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, pen,
|
||||||
QBrush(active, Qt::SolidPattern));
|
QBrush(m_activeColor, Qt::SolidPattern));
|
||||||
circle->setSpanAngle(-percent * 360.0f * 16.0f);
|
circle->setSpanAngle(-percent * 360.0f * 16.0f);
|
||||||
circle->setStartAngle(90.0f * 16.0f);
|
circle->setStartAngle(90.0f * 16.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GraphicalItemHelper::paintGraph(const QList<float> &value,
|
void GraphicalItemHelper::paintGraph(const QList<float> &value)
|
||||||
const QColor &active, const int &width,
|
|
||||||
const int &height, QGraphicsScene *scene)
|
|
||||||
{
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Paint with value" << value;
|
||||||
|
|
||||||
QPen pen;
|
QPen pen;
|
||||||
pen.setColor(active);
|
pen.setColor(m_activeColor);
|
||||||
|
|
||||||
// default norms
|
// default norms
|
||||||
float normX = static_cast<float>(width) / static_cast<float>(value.count());
|
float normX
|
||||||
float normY = static_cast<float>(height) / (1.5f * 100.0f);
|
= static_cast<float>(m_width) / static_cast<float>(value.count());
|
||||||
|
float normY = static_cast<float>(m_height) / (1.5f * 100.0f);
|
||||||
// paint graph
|
// paint graph
|
||||||
for (int i = 0; i < value.count() - 1; i++) {
|
for (int i = 0; i < value.count() - 1; i++) {
|
||||||
// some magic here
|
// some magic here
|
||||||
@ -66,46 +95,42 @@ void GraphicalItemHelper::paintGraph(const QList<float> &value,
|
|||||||
float y1 = -fabs(value.at(i)) * normY + 5.0f;
|
float y1 = -fabs(value.at(i)) * normY + 5.0f;
|
||||||
float x2 = (i + 1) * normX;
|
float x2 = (i + 1) * normX;
|
||||||
float y2 = -fabs(value.at(i + 1)) * normY + 5.0f;
|
float y2 = -fabs(value.at(i + 1)) * normY + 5.0f;
|
||||||
scene->addLine(x1, y1, x2, y2, pen);
|
m_scene->addLine(x1, y1, x2, y2, pen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GraphicalItemHelper::paintHorizontal(const float &percent,
|
void GraphicalItemHelper::paintHorizontal(const float &percent)
|
||||||
const QColor &inactive,
|
|
||||||
const QColor &active,
|
|
||||||
const int &width, const int &height,
|
|
||||||
QGraphicsScene *scene)
|
|
||||||
{
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Paint with percent" << percent;
|
||||||
|
|
||||||
QPen pen;
|
QPen pen;
|
||||||
pen.setWidth(height);
|
pen.setWidth(m_height);
|
||||||
// inactive
|
// inactive
|
||||||
pen.setColor(inactive);
|
pen.setColor(m_inactiveColor);
|
||||||
scene->addLine(percent * width + 0.5 * height, 0.5 * height,
|
m_scene->addLine(percent * m_width + 0.5 * m_height, 0.5 * m_height,
|
||||||
width + 0.5 * height, 0.5 * height, pen);
|
m_width + 0.5 * m_height, 0.5 * m_height, pen);
|
||||||
// active
|
// active
|
||||||
pen.setColor(active);
|
pen.setColor(m_activeColor);
|
||||||
scene->addLine(-0.5 * height, 0.5 * height, percent * width - 0.5 * height,
|
m_scene->addLine(-0.5 * m_height, 0.5 * m_height,
|
||||||
0.5 * height, pen);
|
percent * m_width - 0.5 * m_height, 0.5 * m_height, pen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void GraphicalItemHelper::paintVertical(const float &percent,
|
void GraphicalItemHelper::paintVertical(const float &percent)
|
||||||
const QColor &inactive,
|
|
||||||
const QColor &active, const int &width,
|
|
||||||
const int &height,
|
|
||||||
QGraphicsScene *scene)
|
|
||||||
{
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Paint with percent" << percent;
|
||||||
|
|
||||||
QPen pen;
|
QPen pen;
|
||||||
pen.setWidth(width);
|
pen.setWidth(m_width);
|
||||||
// inactive
|
// inactive
|
||||||
pen.setColor(inactive);
|
pen.setColor(m_inactiveColor);
|
||||||
scene->addLine(0.5 * width, -0.5 * width, 0.5 * width,
|
m_scene->addLine(0.5 * m_width, -0.5 * m_width, 0.5 * m_width,
|
||||||
(1.0 - percent) * height - 0.5 * width, pen);
|
(1.0 - percent) * m_height - 0.5 * m_width, pen);
|
||||||
// active
|
// active
|
||||||
pen.setColor(active);
|
pen.setColor(m_activeColor);
|
||||||
scene->addLine(0.5 * width, (1.0 - percent) * height + 0.5 * width,
|
m_scene->addLine(0.5 * m_width, (1.0 - percent) * m_height + 0.5 * m_width,
|
||||||
0.5 * width, height + 0.5 * width, pen);
|
0.5 * m_width, m_height + 0.5 * m_width, pen);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,28 +19,36 @@
|
|||||||
#define GRAPHICALITEMHELPER_H
|
#define GRAPHICALITEMHELPER_H
|
||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
|
||||||
class QGraphicsScene;
|
class QGraphicsScene;
|
||||||
|
|
||||||
namespace GraphicalItemHelper
|
class GraphicalItemHelper : public QObject
|
||||||
{
|
{
|
||||||
// paint methods
|
public:
|
||||||
void paintCircle(const float &percent, const QColor &inactive,
|
explicit GraphicalItemHelper(QObject *parent = nullptr,
|
||||||
const QColor &active, const int &width, const int &height,
|
QGraphicsScene *scene = nullptr);
|
||||||
QGraphicsScene *scene);
|
virtual ~GraphicalItemHelper();
|
||||||
void paintGraph(const QList<float> &value, const QColor &active,
|
// parameters
|
||||||
const int &width, const int &height, QGraphicsScene *scene);
|
void setParameters(const QColor active, const QColor inactive,
|
||||||
void paintHorizontal(const float &percent, const QColor &inactive,
|
const int width, const int height);
|
||||||
const QColor &active, const int &width, const int &height,
|
// paint methods
|
||||||
QGraphicsScene *scene);
|
void paintCircle(const float &percent);
|
||||||
void paintVertical(const float &percent, const QColor &inactive,
|
void paintGraph(const QList<float> &value);
|
||||||
const QColor &active, const int &width, const int &height,
|
void paintHorizontal(const float &percent);
|
||||||
QGraphicsScene *scene);
|
void paintVertical(const float &percent);
|
||||||
// additional conversion methods
|
// additional conversion methods
|
||||||
QString colorToString(const QColor &color);
|
QString colorToString(const QColor &color);
|
||||||
float getPercents(const float &value, const float &min, const float &max);
|
float getPercents(const float &value, const float &min, const float &max);
|
||||||
QColor stringToColor(const QString &color);
|
QColor stringToColor(const QString &color);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QGraphicsScene *m_scene = nullptr;
|
||||||
|
QColor m_activeColor;
|
||||||
|
QColor m_inactiveColor;
|
||||||
|
int m_width;
|
||||||
|
int m_height;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user