mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 23:47:20 +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
|
||||
setData(QString("cpuTooltip"), values[QString("cpu")].toFloat(), 90.0);
|
||||
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("downkbTooltip"), values[QString("downkb")].toFloat());
|
||||
setData(QString("upkbTooltip"), values[QString("upkb")].toFloat());
|
||||
|
@ -44,7 +44,7 @@ signals:
|
||||
void updateData(const QVariantHash &values);
|
||||
void toolTipPainted(const QString image) const;
|
||||
|
||||
public slots:
|
||||
private slots:
|
||||
void dataUpdate(const QVariantHash &values);
|
||||
|
||||
private:
|
||||
|
@ -60,6 +60,7 @@ GraphicalItem::~GraphicalItem()
|
||||
|
||||
delete m_scene;
|
||||
delete ui;
|
||||
delete m_helper;
|
||||
}
|
||||
|
||||
|
||||
@ -89,6 +90,7 @@ GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number)
|
||||
QString GraphicalItem::image(const QVariant &value)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Value" << value;
|
||||
qDebug() << "Value" << value;
|
||||
|
||||
m_scene->clear();
|
||||
int scale[2] = {1, 1};
|
||||
@ -96,33 +98,25 @@ QString GraphicalItem::image(const QVariant &value)
|
||||
// paint
|
||||
switch (m_type) {
|
||||
case Vertical:
|
||||
GraphicalItemHelper::paintVertical(
|
||||
GraphicalItemHelper::getPercents(value.toFloat(), m_minValue,
|
||||
m_maxValue),
|
||||
m_inactiveColor, m_activeColor, m_width, m_height, m_scene);
|
||||
m_helper->paintVertical(
|
||||
m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue));
|
||||
// scale
|
||||
scale[1] = -2 * static_cast<int>(m_direction) + 1;
|
||||
break;
|
||||
case Circle:
|
||||
GraphicalItemHelper::paintCircle(
|
||||
GraphicalItemHelper::getPercents(value.toFloat(), m_minValue,
|
||||
m_maxValue),
|
||||
m_inactiveColor, m_activeColor, m_width, m_height, m_scene);
|
||||
m_helper->paintCircle(
|
||||
m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue));
|
||||
// scale
|
||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
||||
break;
|
||||
case Graph:
|
||||
GraphicalItemHelper::paintGraph(value.value<QList<float>>(),
|
||||
m_activeColor, m_width, m_height,
|
||||
m_scene);
|
||||
m_helper->paintGraph(value.value<QList<float>>());
|
||||
// direction option is not recognized by this GI type
|
||||
break;
|
||||
case Horizontal:
|
||||
default:
|
||||
GraphicalItemHelper::paintHorizontal(
|
||||
GraphicalItemHelper::getPercents(value.toFloat(), m_minValue,
|
||||
m_maxValue),
|
||||
m_inactiveColor, m_activeColor, m_width, m_height, m_scene);
|
||||
m_helper->paintHorizontal(
|
||||
m_helper->getPercents(value.toFloat(), m_minValue, m_maxValue));
|
||||
// scale
|
||||
scale[0] = -2 * static_cast<int>(m_direction) + 1;
|
||||
break;
|
||||
@ -137,6 +131,7 @@ QString GraphicalItem::image(const QVariant &value)
|
||||
QString url = QString("<img src=\"data:image/png;base64,%1\"/>")
|
||||
.arg(QString(byteArray.toBase64()));
|
||||
|
||||
qDebug() << url;
|
||||
return url;
|
||||
}
|
||||
|
||||
@ -149,13 +144,13 @@ QString GraphicalItem::bar() const
|
||||
|
||||
QString GraphicalItem::activeColor() const
|
||||
{
|
||||
return GraphicalItemHelper::colorToString(m_activeColor);
|
||||
return m_helper->colorToString(m_activeColor);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
m_inactiveColor = GraphicalItemHelper::stringToColor(_color);
|
||||
m_inactiveColor = m_helper->stringToColor(_color);
|
||||
}
|
||||
|
||||
|
||||
@ -500,7 +495,7 @@ void GraphicalItem::writeConfiguration() const
|
||||
|
||||
void GraphicalItem::changeColor()
|
||||
{
|
||||
QColor color = GraphicalItemHelper::stringToColor(
|
||||
QColor color = m_helper->stringToColor(
|
||||
(static_cast<QPushButton *>(sender()))->text());
|
||||
QColor newColor = QColorDialog::getColor(color, this, tr("Select color"),
|
||||
QColorDialog::ShowAlphaChannel);
|
||||
@ -544,6 +539,10 @@ void GraphicalItem::initScene()
|
||||
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
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"
|
||||
|
||||
|
||||
class GraphicalItemHelper;
|
||||
class QGraphicsScene;
|
||||
class QGraphicsView;
|
||||
|
||||
@ -97,6 +98,7 @@ private slots:
|
||||
void changeValue(const int state);
|
||||
|
||||
private:
|
||||
GraphicalItemHelper *m_helper = nullptr;
|
||||
QGraphicsScene *m_scene = nullptr;
|
||||
QGraphicsView *m_view = nullptr;
|
||||
Ui::GraphicalItem *ui;
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "graphicalitemhelper.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QGraphicsEllipseItem>
|
||||
#include <QGraphicsScene>
|
||||
|
||||
@ -25,40 +26,68 @@
|
||||
#include "awdebug.h"
|
||||
|
||||
|
||||
void GraphicalItemHelper::paintCircle(const float &percent,
|
||||
const QColor &inactive,
|
||||
const QColor &active, const int &width,
|
||||
const int &height, QGraphicsScene *scene)
|
||||
GraphicalItemHelper::GraphicalItemHelper(QObject *parent, QGraphicsScene *scene)
|
||||
: QObject(parent)
|
||||
, m_scene(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;
|
||||
pen.setWidth(1);
|
||||
QGraphicsEllipseItem *circle;
|
||||
|
||||
// inactive
|
||||
pen.setColor(inactive);
|
||||
circle = scene->addEllipse(0.0, 0.0, width, height, pen,
|
||||
QBrush(inactive, Qt::SolidPattern));
|
||||
pen.setColor(m_inactiveColor);
|
||||
circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, pen,
|
||||
QBrush(m_inactiveColor, Qt::SolidPattern));
|
||||
circle->setSpanAngle(-(1.0f - percent) * 360.0f * 16.0f);
|
||||
circle->setStartAngle(90.0f * 16.0f - percent * 360.0f * 16.0f);
|
||||
// active
|
||||
pen.setColor(active);
|
||||
circle = scene->addEllipse(0.0, 0.0, width, height, pen,
|
||||
QBrush(active, Qt::SolidPattern));
|
||||
pen.setColor(m_activeColor);
|
||||
circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, pen,
|
||||
QBrush(m_activeColor, Qt::SolidPattern));
|
||||
circle->setSpanAngle(-percent * 360.0f * 16.0f);
|
||||
circle->setStartAngle(90.0f * 16.0f);
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItemHelper::paintGraph(const QList<float> &value,
|
||||
const QColor &active, const int &width,
|
||||
const int &height, QGraphicsScene *scene)
|
||||
void GraphicalItemHelper::paintGraph(const QList<float> &value)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Paint with value" << value;
|
||||
|
||||
QPen pen;
|
||||
pen.setColor(active);
|
||||
pen.setColor(m_activeColor);
|
||||
|
||||
// default norms
|
||||
float normX = static_cast<float>(width) / static_cast<float>(value.count());
|
||||
float normY = static_cast<float>(height) / (1.5f * 100.0f);
|
||||
float normX
|
||||
= static_cast<float>(m_width) / static_cast<float>(value.count());
|
||||
float normY = static_cast<float>(m_height) / (1.5f * 100.0f);
|
||||
// paint graph
|
||||
for (int i = 0; i < value.count() - 1; i++) {
|
||||
// some magic here
|
||||
@ -66,46 +95,42 @@ void GraphicalItemHelper::paintGraph(const QList<float> &value,
|
||||
float y1 = -fabs(value.at(i)) * normY + 5.0f;
|
||||
float x2 = (i + 1) * normX;
|
||||
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,
|
||||
const QColor &inactive,
|
||||
const QColor &active,
|
||||
const int &width, const int &height,
|
||||
QGraphicsScene *scene)
|
||||
void GraphicalItemHelper::paintHorizontal(const float &percent)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Paint with percent" << percent;
|
||||
|
||||
QPen pen;
|
||||
pen.setWidth(height);
|
||||
pen.setWidth(m_height);
|
||||
// inactive
|
||||
pen.setColor(inactive);
|
||||
scene->addLine(percent * width + 0.5 * height, 0.5 * height,
|
||||
width + 0.5 * height, 0.5 * height, pen);
|
||||
pen.setColor(m_inactiveColor);
|
||||
m_scene->addLine(percent * m_width + 0.5 * m_height, 0.5 * m_height,
|
||||
m_width + 0.5 * m_height, 0.5 * m_height, pen);
|
||||
// active
|
||||
pen.setColor(active);
|
||||
scene->addLine(-0.5 * height, 0.5 * height, percent * width - 0.5 * height,
|
||||
0.5 * height, pen);
|
||||
pen.setColor(m_activeColor);
|
||||
m_scene->addLine(-0.5 * m_height, 0.5 * m_height,
|
||||
percent * m_width - 0.5 * m_height, 0.5 * m_height, pen);
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItemHelper::paintVertical(const float &percent,
|
||||
const QColor &inactive,
|
||||
const QColor &active, const int &width,
|
||||
const int &height,
|
||||
QGraphicsScene *scene)
|
||||
void GraphicalItemHelper::paintVertical(const float &percent)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Paint with percent" << percent;
|
||||
|
||||
QPen pen;
|
||||
pen.setWidth(width);
|
||||
pen.setWidth(m_width);
|
||||
// inactive
|
||||
pen.setColor(inactive);
|
||||
scene->addLine(0.5 * width, -0.5 * width, 0.5 * width,
|
||||
(1.0 - percent) * height - 0.5 * width, pen);
|
||||
pen.setColor(m_inactiveColor);
|
||||
m_scene->addLine(0.5 * m_width, -0.5 * m_width, 0.5 * m_width,
|
||||
(1.0 - percent) * m_height - 0.5 * m_width, pen);
|
||||
// active
|
||||
pen.setColor(active);
|
||||
scene->addLine(0.5 * width, (1.0 - percent) * height + 0.5 * width,
|
||||
0.5 * width, height + 0.5 * width, pen);
|
||||
pen.setColor(m_activeColor);
|
||||
m_scene->addLine(0.5 * m_width, (1.0 - percent) * m_height + 0.5 * m_width,
|
||||
0.5 * m_width, m_height + 0.5 * m_width, pen);
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,28 +19,36 @@
|
||||
#define GRAPHICALITEMHELPER_H
|
||||
|
||||
#include <QColor>
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class QGraphicsScene;
|
||||
|
||||
namespace GraphicalItemHelper
|
||||
class GraphicalItemHelper : public QObject
|
||||
{
|
||||
// paint methods
|
||||
void paintCircle(const float &percent, const QColor &inactive,
|
||||
const QColor &active, const int &width, const int &height,
|
||||
QGraphicsScene *scene);
|
||||
void paintGraph(const QList<float> &value, const QColor &active,
|
||||
const int &width, const int &height, QGraphicsScene *scene);
|
||||
void paintHorizontal(const float &percent, const QColor &inactive,
|
||||
const QColor &active, const int &width, const int &height,
|
||||
QGraphicsScene *scene);
|
||||
void paintVertical(const float &percent, const QColor &inactive,
|
||||
const QColor &active, const int &width, const int &height,
|
||||
QGraphicsScene *scene);
|
||||
// additional conversion methods
|
||||
QString colorToString(const QColor &color);
|
||||
float getPercents(const float &value, const float &min, const float &max);
|
||||
QColor stringToColor(const QString &color);
|
||||
public:
|
||||
explicit GraphicalItemHelper(QObject *parent = nullptr,
|
||||
QGraphicsScene *scene = nullptr);
|
||||
virtual ~GraphicalItemHelper();
|
||||
// parameters
|
||||
void setParameters(const QColor active, const QColor inactive,
|
||||
const int width, const int height);
|
||||
// paint methods
|
||||
void paintCircle(const float &percent);
|
||||
void paintGraph(const QList<float> &value);
|
||||
void paintHorizontal(const float &percent);
|
||||
void paintVertical(const float &percent);
|
||||
// additional conversion methods
|
||||
QString colorToString(const QColor &color);
|
||||
float getPercents(const float &value, const float &min, const float &max);
|
||||
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