mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
prepare to move to generic bars
This commits series introduces bars which may be calculated from any custom formula. For a start I've renamed $bar*tag to $bar* and add new configuration parameters to graphical items.
This commit is contained in:
parent
5c474e822b
commit
362f1fd87e
@ -91,11 +91,7 @@ QStringList AWKeyCache::getRequiredKeys(const QStringList &keys,
|
||||
|
||||
// initial copy
|
||||
QSet<QString> used = QSet<QString>::fromList(keys);
|
||||
// insert bars
|
||||
for (auto bar : bars) {
|
||||
bar.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
||||
used << bar;
|
||||
}
|
||||
used.unite(QSet<QString>::fromList(bars));
|
||||
// insert keys from tooltip
|
||||
for (auto key : tooltip.keys()) {
|
||||
if ((key.endsWith(QString("Tooltip"))) && (tooltip[key].toBool())) {
|
||||
|
@ -226,12 +226,8 @@ QStringList AWKeyOperations::dictKeys() const
|
||||
allKeys.append(QString("la5"));
|
||||
allKeys.append(QString("la1"));
|
||||
// bars
|
||||
QStringList graphicalItemsKeys;
|
||||
for (auto item : graphicalItems->items())
|
||||
graphicalItemsKeys.append(item->tag());
|
||||
graphicalItemsKeys.sort();
|
||||
for (int i = graphicalItemsKeys.count() - 1; i >= 0; i--)
|
||||
allKeys.append(graphicalItemsKeys.at(i));
|
||||
for (int i = graphicalItems->activeItems().count() -1; i >= 0; i--)
|
||||
allKeys.append(graphicalItems->activeItems().at(i)->tag(QString("bar")));
|
||||
|
||||
return allKeys;
|
||||
}
|
||||
@ -243,7 +239,7 @@ GraphicalItem *AWKeyOperations::giByKey(const QString key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Looking for item" << key;
|
||||
|
||||
return graphicalItems->itemByTag(key);
|
||||
return graphicalItems->itemByTag(key, QString("bar"));
|
||||
}
|
||||
|
||||
|
||||
@ -251,11 +247,10 @@ QString AWKeyOperations::infoByKey(QString key) const
|
||||
{
|
||||
qCDebug(LOG_AW) << "Requested key" << key;
|
||||
|
||||
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
||||
if (key.startsWith(QString("custom")))
|
||||
return extScripts->itemByTagNumber(
|
||||
key.remove(QString("custom")).toInt())
|
||||
->uniq();
|
||||
if (key.startsWith(QString("bar")))
|
||||
return graphicalItems->itemByTag(key, QString("bar"))->uniq();
|
||||
else if (key.startsWith(QString("custom")))
|
||||
return extScripts->itemByTag(key, QString("custom"))->uniq();
|
||||
else if (key.contains(QRegExp(QString("^hdd[rw]"))))
|
||||
return QString("%1").arg(m_devices[QString(
|
||||
"disk")][key.remove(QRegExp(QString("hdd[rw]"))).toInt()]);
|
||||
@ -273,24 +268,12 @@ QString AWKeyOperations::infoByKey(QString key) const
|
||||
return QString("%1").arg(m_devices[QString(
|
||||
"net")][key.remove(QRegExp(QString("^(down|up)"))).toInt()]);
|
||||
else if (key.startsWith(QString("pkgcount")))
|
||||
return extUpgrade->itemByTagNumber(
|
||||
key.remove(QString("pkgcount")).toInt())
|
||||
->uniq();
|
||||
return extUpgrade->itemByTag(key, QString("pkgcount"))->uniq();
|
||||
else if (key.contains(QRegExp(QString("(^|perc)(ask|bid|price)(chg|)"))))
|
||||
return extQuotes->itemByTagNumber(
|
||||
key.remove(QRegExp(QString(
|
||||
"(^|perc)(ask|bid|price)(chg|)")))
|
||||
.toInt())
|
||||
->uniq();
|
||||
return extQuotes->itemByTag(key, QString("ask"))->uniq();
|
||||
else if (key.contains(QRegExp(
|
||||
QString("(weather|weatherId|humidity|pressure|temperature)"))))
|
||||
return extWeather
|
||||
->itemByTagNumber(
|
||||
key
|
||||
.remove(QRegExp(QString(
|
||||
"(weather|weatherId|humidity|pressure|temperature)")))
|
||||
.toInt())
|
||||
->uniq();
|
||||
return extWeather->itemByTag(key, QString("weather"))->uniq();
|
||||
else if (key.startsWith(QString("temp")))
|
||||
return QString("%1").arg(
|
||||
m_devices[QString("temp")][key.remove(QString("temp")).toInt()]);
|
||||
|
@ -205,9 +205,19 @@ void AWKeys::reinitKeys(const QStringList currentKeys)
|
||||
m_foundKeys
|
||||
= AWPatternFunctions::findKeys(keyOperator->pattern(), currentKeys);
|
||||
m_foundLambdas = AWPatternFunctions::findLambdas(keyOperator->pattern());
|
||||
// generate list of required keys for bars
|
||||
QStringList barKeys;
|
||||
for (auto bar : m_foundBars) {
|
||||
GraphicalItem *item = keyOperator->giByKey(bar);
|
||||
if (item->isCustom())
|
||||
item->setUsedKeys(AWPatternFunctions::findKeys(item->bar(), currentKeys));
|
||||
else
|
||||
item->setUsedKeys(QStringList() << item->bar());
|
||||
barKeys.append(item->usedKeys());
|
||||
}
|
||||
// get required keys
|
||||
m_requiredKeys
|
||||
= m_optimize ? AWKeyCache::getRequiredKeys(m_foundKeys, m_foundBars,
|
||||
= m_optimize ? AWKeyCache::getRequiredKeys(m_foundKeys, barKeys,
|
||||
m_tooltipParams, currentKeys)
|
||||
: QStringList();
|
||||
|
||||
@ -318,16 +328,29 @@ QString AWKeys::parsePattern(QString pattern) const
|
||||
// bars
|
||||
for (auto bar : m_foundBars) {
|
||||
GraphicalItem *item = keyOperator->giByKey(bar);
|
||||
QString key = bar;
|
||||
key.remove(QRegExp(QString("^bar[0-9]{1,}")));
|
||||
if (item->type() == GraphicalItem::Graph)
|
||||
pattern.replace(QString("$%1").arg(bar),
|
||||
item->image([](const QList<float> data) {
|
||||
return QVariant::fromValue<QList<float>>(data);
|
||||
}(dataAggregator->getData(key))));
|
||||
else
|
||||
pattern.replace(QString("$%1").arg(bar),
|
||||
item->image(values[key].toFloat()));
|
||||
item->image(QVariant::fromValue<QList<float>>(dataAggregator->getData(item->bar()))));
|
||||
else {
|
||||
if (item->isCustom())
|
||||
pattern.replace(QString("$%1").arg(bar),item->image([this, item](QString bar ){
|
||||
QJSEngine engine;
|
||||
for (auto key : item->usedKeys())
|
||||
bar.replace(QString("$%1").arg(key), aggregator->formater(values[key], key));
|
||||
qCInfo(LOG_AW) << "Expression" << bar;
|
||||
QJSValue result = engine.evaluate(bar);
|
||||
if (result.isError()) {
|
||||
qCWarning(LOG_AW) << "Uncaught exception at line"
|
||||
<< result.property("lineNumber").toInt()
|
||||
<< ":" << result.toString();
|
||||
return QString();
|
||||
} else {
|
||||
return result.toString();
|
||||
}
|
||||
}(item->bar())));
|
||||
else
|
||||
pattern.replace(QString("$%1").arg(bar),item->image(values[item->bar()]));
|
||||
}
|
||||
}
|
||||
|
||||
// prepare strings
|
||||
|
@ -539,7 +539,8 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
|
||||
// drop key from dictionary if no one user requested key required it
|
||||
QStringList foundKeys = keysFromSource(source);
|
||||
qCInfo(LOG_AW) << "Looking for keys" << foundKeys << "in" << keys;
|
||||
// let required if key list is empty no one use it
|
||||
// this source is required if list is empty (which means skip checking)
|
||||
// or if key in required key list
|
||||
bool required
|
||||
= keys.isEmpty() || std::any_of(foundKeys.cbegin(), foundKeys.cend(),
|
||||
[&keys](const QString &key) {
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
#include "awdebug.h"
|
||||
#include "version.h"
|
||||
#include "abstractextitemaggregator.h"
|
||||
|
||||
|
||||
AbstractExtItem::AbstractExtItem(QWidget *parent, const QString desktopName,
|
||||
@ -47,10 +48,13 @@ AbstractExtItem::~AbstractExtItem()
|
||||
}
|
||||
|
||||
|
||||
template <class T> T *AbstractExtItem::copy(const QString, const int)
|
||||
void AbstractExtItem::copyDefaults(AbstractExtItem *_other) const
|
||||
{
|
||||
// an analog of pure virtual method
|
||||
return new T();
|
||||
_other->setActive(m_active);
|
||||
_other->setApiVersion(m_apiVersion);
|
||||
_other->setComment(m_comment);
|
||||
_other->setInterval(m_interval);
|
||||
_other->setName(m_name);
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,7 +40,8 @@ public:
|
||||
const QString desktopName = QString(),
|
||||
const QStringList directories = QStringList());
|
||||
virtual ~AbstractExtItem();
|
||||
template <class T> T *copy(const QString, const int);
|
||||
virtual AbstractExtItem *copy(const QString _fileName, const int _number) = 0;
|
||||
void copyDefaults(AbstractExtItem *_other) const;
|
||||
// get methods
|
||||
int apiVersion() const;
|
||||
QString comment() const;
|
||||
|
@ -62,13 +62,13 @@ public:
|
||||
qCInfo(LOG_LIB) << "Dialog returns" << ret;
|
||||
};
|
||||
|
||||
T *itemByTag(const QString _tag) const
|
||||
T *itemByTag(const QString _tag, const QString _type) const
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Tag" << _tag;
|
||||
qCDebug(LOG_LIB) << "Tag" << _tag << "with used type" << _type;
|
||||
|
||||
T *found = nullptr;
|
||||
for (auto item : m_items) {
|
||||
if (item->tag() != _tag)
|
||||
if (item->tag(_type) != _tag)
|
||||
continue;
|
||||
found = item;
|
||||
break;
|
||||
@ -211,7 +211,7 @@ private:
|
||||
return;
|
||||
}
|
||||
|
||||
T *newItem = source->copy(fileName, number);
|
||||
T *newItem = static_cast<T *>(source->copy(fileName, number));
|
||||
if (newItem->showConfiguration(configArgs()) == 1) {
|
||||
initItems();
|
||||
repaint();
|
||||
|
@ -81,11 +81,7 @@ ExtQuotes *ExtQuotes::copy(const QString _fileName, const int _number)
|
||||
|
||||
ExtQuotes *item = new ExtQuotes(static_cast<QWidget *>(parent()), _fileName,
|
||||
directories());
|
||||
item->setActive(isActive());
|
||||
item->setApiVersion(apiVersion());
|
||||
item->setComment(comment());
|
||||
item->setInterval(interval());
|
||||
item->setName(name());
|
||||
copyDefaults(item);
|
||||
item->setNumber(_number);
|
||||
item->setTicker(ticker());
|
||||
|
||||
|
@ -68,12 +68,8 @@ ExtScript *ExtScript::copy(const QString _fileName, const int _number)
|
||||
|
||||
ExtScript *item = new ExtScript(static_cast<QWidget *>(parent()), _fileName,
|
||||
directories());
|
||||
item->setActive(isActive());
|
||||
item->setApiVersion(apiVersion());
|
||||
item->setComment(comment());
|
||||
copyDefaults(item);
|
||||
item->setExecutable(executable());
|
||||
item->setInterval(interval());
|
||||
item->setName(name());
|
||||
item->setNumber(_number);
|
||||
item->setPrefix(prefix());
|
||||
item->setRedirect(redirect());
|
||||
|
@ -64,13 +64,9 @@ ExtUpgrade *ExtUpgrade::copy(const QString _fileName, const int _number)
|
||||
|
||||
ExtUpgrade *item = new ExtUpgrade(static_cast<QWidget *>(parent()),
|
||||
_fileName, directories());
|
||||
item->setActive(isActive());
|
||||
item->setApiVersion(apiVersion());
|
||||
item->setComment(comment());
|
||||
copyDefaults(item);
|
||||
item->setExecutable(executable());
|
||||
item->setFilter(filter());
|
||||
item->setInterval(interval());
|
||||
item->setName(name());
|
||||
item->setNumber(_number);
|
||||
item->setNull(null());
|
||||
|
||||
|
@ -78,14 +78,10 @@ ExtWeather *ExtWeather::copy(const QString _fileName, const int _number)
|
||||
|
||||
ExtWeather *item = new ExtWeather(static_cast<QWidget *>(parent()),
|
||||
_fileName, directories());
|
||||
item->setActive(isActive());
|
||||
item->setApiVersion(apiVersion());
|
||||
copyDefaults(item);
|
||||
item->setCity(city());
|
||||
item->setComment(comment());
|
||||
item->setCountry(country());
|
||||
item->setInterval(interval());
|
||||
item->setImage(image());
|
||||
item->setName(name());
|
||||
item->setNumber(_number);
|
||||
item->setTs(ts());
|
||||
|
||||
|
@ -47,6 +47,8 @@ GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName,
|
||||
|
||||
initScene();
|
||||
|
||||
connect(ui->checkBox_custom, SIGNAL(stateChanged(int)), this,
|
||||
SLOT(changeValue(int)));
|
||||
connect(ui->pushButton_activeColor, SIGNAL(clicked()), this,
|
||||
SLOT(changeColor()));
|
||||
connect(ui->pushButton_inactiveColor, SIGNAL(clicked()), this,
|
||||
@ -69,29 +71,26 @@ GraphicalItem *GraphicalItem::copy(const QString _fileName, const int _number)
|
||||
|
||||
GraphicalItem *item = new GraphicalItem(static_cast<QWidget *>(parent()),
|
||||
_fileName, directories());
|
||||
item->setActive(isActive());
|
||||
item->setActiveColor(activeColor());
|
||||
item->setApiVersion(apiVersion());
|
||||
item->setBar(bar());
|
||||
item->setComment(comment());
|
||||
item->setDirection(direction());
|
||||
item->setHeight(height());
|
||||
item->setInactiveColor(inactiveColor());
|
||||
item->setInterval(interval());
|
||||
item->setName(QString("bar%1").arg(_number));
|
||||
copyDefaults(item);
|
||||
item->setActiveColor(m_activeColor);
|
||||
item->setBar(m_bar);
|
||||
item->setCustom(m_custom);
|
||||
item->setDirection(m_direction);
|
||||
item->setHeight(m_height);
|
||||
item->setInactiveColor(m_inactiveColor);
|
||||
item->setMaxValue(m_maxValue);
|
||||
item->setMinValue(m_minValue);
|
||||
item->setNumber(_number);
|
||||
item->setType(type());
|
||||
item->setWidth(width());
|
||||
item->setType(m_type);
|
||||
item->setWidth(m_width);
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
|
||||
QString GraphicalItem::image(const QVariant value)
|
||||
QString GraphicalItem::image(const QVariant &value)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Value" << value;
|
||||
if (m_bar == QString("none"))
|
||||
return QString("");
|
||||
|
||||
m_scene->clear();
|
||||
int scale[2] = {1, 1};
|
||||
@ -151,9 +150,21 @@ QString GraphicalItem::inactiveColor() const
|
||||
}
|
||||
|
||||
|
||||
QString GraphicalItem::tag() const
|
||||
bool GraphicalItem::isCustom() const
|
||||
{
|
||||
return QString("bar%1%2").arg(number()).arg(m_bar);
|
||||
return m_custom;
|
||||
}
|
||||
|
||||
|
||||
float GraphicalItem::maxValue() const
|
||||
{
|
||||
return m_maxValue;
|
||||
}
|
||||
|
||||
|
||||
float GraphicalItem::minValue() const
|
||||
{
|
||||
return m_minValue;
|
||||
}
|
||||
|
||||
|
||||
@ -215,6 +226,12 @@ int GraphicalItem::height() const
|
||||
}
|
||||
|
||||
|
||||
QStringList GraphicalItem::usedKeys() const
|
||||
{
|
||||
return m_usedKeys;
|
||||
}
|
||||
|
||||
|
||||
int GraphicalItem::width() const
|
||||
{
|
||||
return m_width;
|
||||
@ -231,13 +248,7 @@ void GraphicalItem::setBar(const QString _bar)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Bar" << _bar;
|
||||
|
||||
if (!_bar.contains(QRegExp(
|
||||
QString("^(cpu(?!cl).*|gpu$|mem$|swap$|hdd[0-9].*|bat.*)")))) {
|
||||
qCWarning(LOG_LIB) << "Unsupported bar type" << _bar;
|
||||
m_bar = QString("none");
|
||||
} else {
|
||||
m_bar = _bar;
|
||||
}
|
||||
m_bar = _bar;
|
||||
}
|
||||
|
||||
|
||||
@ -249,6 +260,14 @@ void GraphicalItem::setActiveColor(const QString _color)
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setCustom(const bool _custom)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Use custom tag" << _custom;
|
||||
|
||||
m_custom = _custom;
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setInactiveColor(const QString _color)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Color" << _color;
|
||||
@ -257,6 +276,22 @@ void GraphicalItem::setInactiveColor(const QString _color)
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setMaxValue(const float _value)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Max value" << _value;
|
||||
|
||||
m_maxValue = _value;
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setMinValue(const float _value)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Min value" << _value;
|
||||
|
||||
m_minValue = _value;
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setType(const Type _type)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Type" << _type;
|
||||
@ -309,6 +344,15 @@ void GraphicalItem::setHeight(const int _height)
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setUsedKeys(const QStringList _usedKeys)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Used keys" << _usedKeys;
|
||||
|
||||
// remove dubs
|
||||
m_usedKeys = QSet<QString>::fromList(_usedKeys).toList();
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::setWidth(const int _width)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Width" << _width;
|
||||
@ -333,7 +377,10 @@ void GraphicalItem::readConfiguration()
|
||||
QSettings::IniFormat);
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
setCustom(settings.value(QString("X-AW-Custom"), m_custom).toBool());
|
||||
setBar(settings.value(QString("X-AW-Value"), m_bar).toString());
|
||||
setMaxValue(settings.value(QString("X-AW-Max"), m_maxValue).toFloat());
|
||||
setMinValue(settings.value(QString("X-AW-Min"), m_minValue).toFloat());
|
||||
setActiveColor(
|
||||
settings.value(QString("X-AW-ActiveColor"), m_activeColor)
|
||||
.toString());
|
||||
@ -374,11 +421,18 @@ int GraphicalItem::showConfiguration(const QVariant args)
|
||||
qCDebug(LOG_LIB) << "Combobox arguments" << args;
|
||||
QStringList tags = args.toStringList();
|
||||
|
||||
ui->label_nameValue->setText(name());
|
||||
ui->lineEdit_name->setText(name());
|
||||
ui->lineEdit_comment->setText(comment());
|
||||
ui->checkBox_custom->setChecked(m_custom);
|
||||
ui->comboBox_value->addItems(tags);
|
||||
ui->comboBox_value->addItem(m_bar);
|
||||
ui->comboBox_value->setCurrentIndex(ui->comboBox_value->count() - 1);
|
||||
if (m_custom) {
|
||||
ui->lineEdit_customValue->setText(m_bar);
|
||||
} else {
|
||||
ui->comboBox_value->addItem(m_bar);
|
||||
ui->comboBox_value->setCurrentIndex(ui->comboBox_value->count() - 1);
|
||||
}
|
||||
ui->doubleSpinBox_max->setValue(m_maxValue);
|
||||
ui->doubleSpinBox_min->setValue(m_minValue);
|
||||
ui->pushButton_activeColor->setText(m_activeColor);
|
||||
ui->pushButton_inactiveColor->setText(m_inactiveColor);
|
||||
ui->comboBox_type->setCurrentIndex(static_cast<int>(m_type));
|
||||
@ -389,10 +443,13 @@ int GraphicalItem::showConfiguration(const QVariant args)
|
||||
int ret = exec();
|
||||
if (ret != 1)
|
||||
return ret;
|
||||
setName(ui->label_nameValue->text());
|
||||
setName(ui->lineEdit_name->text());
|
||||
setComment(ui->lineEdit_comment->text());
|
||||
setApiVersion(AWGIAPI);
|
||||
setBar(ui->comboBox_value->currentText());
|
||||
setCustom(ui->checkBox_custom->isChecked());
|
||||
setBar(m_custom ? ui->lineEdit_customValue->text() : ui->comboBox_value->currentText());
|
||||
setMaxValue(ui->doubleSpinBox_max->value());
|
||||
setMinValue(ui->doubleSpinBox_min->value());
|
||||
setActiveColor(ui->pushButton_activeColor->text().remove(QChar('&')));
|
||||
setInactiveColor(ui->pushButton_inactiveColor->text().remove(QChar('&')));
|
||||
setStrType(ui->comboBox_type->currentText());
|
||||
@ -416,6 +473,9 @@ void GraphicalItem::writeConfiguration() const
|
||||
|
||||
settings.beginGroup(QString("Desktop Entry"));
|
||||
settings.setValue(QString("X-AW-Value"), m_bar);
|
||||
settings.setValue(QString("X-AW-Custom"), m_custom);
|
||||
settings.setValue(QString("X-AW-Max"), m_maxValue);
|
||||
settings.setValue(QString("X-AW-Min"), m_minValue);
|
||||
settings.setValue(QString("X-AW-ActiveColor"), m_activeColor);
|
||||
settings.setValue(QString("X-AW-InactiveColor"), m_inactiveColor);
|
||||
settings.setValue(QString("X-AW-Type"), strType());
|
||||
@ -449,6 +509,15 @@ void GraphicalItem::changeColor()
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::changeValue(const int state)
|
||||
{
|
||||
qCDebug(LOG_LIB) << "Current state is" << state;
|
||||
|
||||
ui->widget_value->setHidden(state == Qt::Unchecked);
|
||||
ui->widget_customValue->setHidden(state != Qt::Unchecked);
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::initScene()
|
||||
{
|
||||
// init scene
|
||||
@ -464,15 +533,15 @@ void GraphicalItem::initScene()
|
||||
m_view->setFrameShape(QFrame::NoFrame);
|
||||
m_view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_view->resize(m_width + 5.0, m_height + 5.0);
|
||||
m_view->resize(m_width + 5, m_height + 5);
|
||||
}
|
||||
|
||||
|
||||
void GraphicalItem::paintCircle(const float value)
|
||||
{
|
||||
QPen pen;
|
||||
pen.setWidth(1.0);
|
||||
float percent = value / 100.0;
|
||||
pen.setWidth(1);
|
||||
float percent = (value - m_minValue) / (m_maxValue - m_minValue);
|
||||
QGraphicsEllipseItem *circle;
|
||||
|
||||
QColor inactive = stringToColor(m_inactiveColor);
|
||||
@ -482,14 +551,14 @@ void GraphicalItem::paintCircle(const float value)
|
||||
pen.setColor(inactive);
|
||||
circle = m_scene->addEllipse(0.0, 0.0, m_width, m_height, pen,
|
||||
QBrush(inactive, Qt::SolidPattern));
|
||||
circle->setSpanAngle(-(1.0 - percent) * 360.0 * 16.0);
|
||||
circle->setStartAngle(90.0 * 16.0 - percent * 360.0 * 16.0);
|
||||
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 = m_scene->addEllipse(0.0, 0.0, m_width, m_height, pen,
|
||||
QBrush(active, Qt::SolidPattern));
|
||||
circle->setSpanAngle(-percent * 360.0 * 16.0);
|
||||
circle->setStartAngle(90.0 * 16.0);
|
||||
circle->setSpanAngle(-percent * 360.0f * 16.0f);
|
||||
circle->setStartAngle(90.0f * 16.0f);
|
||||
}
|
||||
|
||||
|
||||
@ -501,14 +570,14 @@ void GraphicalItem::paintGraph(const QList<float> value)
|
||||
// default norms
|
||||
float normX
|
||||
= static_cast<float>(m_width) / static_cast<float>(value.count());
|
||||
float normY = static_cast<float>(m_height) / (1.5 * 100.0);
|
||||
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
|
||||
float x1 = i * normX;
|
||||
float y1 = -fabs(value.at(i)) * normY + 5.0;
|
||||
float y1 = -fabs(value.at(i)) * normY + 5.0f;
|
||||
float x2 = (i + 1) * normX;
|
||||
float y2 = -fabs(value.at(i + 1)) * normY + 5.0;
|
||||
float y2 = -fabs(value.at(i + 1)) * normY + 5.0f;
|
||||
m_scene->addLine(x1, y1, x2, y2, pen);
|
||||
}
|
||||
}
|
||||
@ -517,7 +586,7 @@ void GraphicalItem::paintGraph(const QList<float> value)
|
||||
void GraphicalItem::paintHorizontal(const float value)
|
||||
{
|
||||
QPen pen;
|
||||
float percent = value / 100.0;
|
||||
float percent = (value - m_minValue) / (m_maxValue - m_minValue);
|
||||
|
||||
pen.setWidth(m_height);
|
||||
// inactive
|
||||
@ -534,7 +603,7 @@ void GraphicalItem::paintHorizontal(const float value)
|
||||
void GraphicalItem::paintVertical(const float value)
|
||||
{
|
||||
QPen pen;
|
||||
float percent = value / 100.0;
|
||||
float percent = (value - m_minValue) / (m_maxValue - m_minValue);
|
||||
|
||||
pen.setWidth(m_width);
|
||||
// inactive
|
||||
@ -569,7 +638,11 @@ void GraphicalItem::translate()
|
||||
{
|
||||
ui->label_name->setText(i18n("Name"));
|
||||
ui->label_comment->setText(i18n("Comment"));
|
||||
ui->checkBox_custom->setText(i18n("Use custom formula"));
|
||||
ui->label_value->setText(i18n("Value"));
|
||||
ui->label_customValue->setText(i18n("Value"));
|
||||
ui->label_max->setText(i18n("Max value"));
|
||||
ui->label_min->setText(i18n("Min value"));
|
||||
ui->label_activeColor->setText(i18n("Active color"));
|
||||
ui->label_inactiveColor->setText(i18n("Inactive color"));
|
||||
ui->label_type->setText(i18n("Type"));
|
||||
|
@ -36,10 +36,14 @@ class GraphicalItem : public AbstractExtItem
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString bar READ bar WRITE setBar)
|
||||
Q_PROPERTY(QString activeColor READ activeColor WRITE setActiveColor)
|
||||
Q_PROPERTY(bool custom READ isCustom WRITE setCustom)
|
||||
Q_PROPERTY(QString inactiveColor READ inactiveColor WRITE setInactiveColor)
|
||||
Q_PROPERTY(Type type READ type WRITE setType)
|
||||
Q_PROPERTY(Direction direction READ direction WRITE setDirection)
|
||||
Q_PROPERTY(int height READ height WRITE setHeight)
|
||||
Q_PROPERTY(float maxValue READ maxValue WRITE setMaxValue)
|
||||
Q_PROPERTY(float minValue READ minValue WRITE setMinValue)
|
||||
Q_PROPERTY(QStringList usedKeys READ usedKeys WRITE setUsedKeys)
|
||||
Q_PROPERTY(int width READ width WRITE setWidth)
|
||||
|
||||
public:
|
||||
@ -51,28 +55,35 @@ public:
|
||||
const QStringList directories = QStringList());
|
||||
virtual ~GraphicalItem();
|
||||
GraphicalItem *copy(const QString _fileName, const int _number);
|
||||
QString image(const QVariant value);
|
||||
QString image(const QVariant &value);
|
||||
// get methods
|
||||
QString bar() const;
|
||||
QString activeColor() const;
|
||||
QString inactiveColor() const;
|
||||
QString tag() const;
|
||||
bool isCustom() const;
|
||||
float minValue() const;
|
||||
float maxValue() const;
|
||||
Type type() const;
|
||||
QString strType() const;
|
||||
Direction direction() const;
|
||||
QString strDirection() const;
|
||||
int height() const;
|
||||
QStringList usedKeys() const;
|
||||
int width() const;
|
||||
QString uniq() const;
|
||||
// set methods
|
||||
void setBar(const QString _bar = QString("cpu"));
|
||||
void setActiveColor(const QString _color = QString("0,0,0,130"));
|
||||
void setCustom(const bool _custom);
|
||||
void setInactiveColor(const QString _color = QString("255,255,255,130"));
|
||||
void setMinValue(const float _value);
|
||||
void setMaxValue(const float _value);
|
||||
void setType(const Type _type = Horizontal);
|
||||
void setStrType(const QString _type = QString("Horizontal"));
|
||||
void setDirection(const Direction _direction = LeftToRight);
|
||||
void setStrDirection(const QString _direction = QString("LeftToRight"));
|
||||
void setHeight(const int _height = 100);
|
||||
void setUsedKeys(const QStringList _usedKeys = QStringList());
|
||||
void setWidth(const int _width = 100);
|
||||
|
||||
public slots:
|
||||
@ -83,10 +94,9 @@ public slots:
|
||||
|
||||
private slots:
|
||||
void changeColor();
|
||||
void changeValue(const int state);
|
||||
|
||||
private:
|
||||
QString m_fileName;
|
||||
QStringList m_dirs;
|
||||
QGraphicsScene *m_scene = nullptr;
|
||||
QGraphicsView *m_view = nullptr;
|
||||
Ui::GraphicalItem *ui;
|
||||
@ -101,11 +111,15 @@ private:
|
||||
void translate();
|
||||
// properties
|
||||
QString m_bar = QString("cpu");
|
||||
bool m_custom = false;
|
||||
QString m_activeColor = QString("0,0,0,130");
|
||||
QString m_inactiveColor = QString("255,255,255,130");
|
||||
float m_minValue = 0.0f;
|
||||
float m_maxValue = 100.0f;
|
||||
Type m_type = Horizontal;
|
||||
Direction m_direction = LeftToRight;
|
||||
int m_height = 100;
|
||||
QStringList m_usedKeys;
|
||||
int m_width = 100;
|
||||
};
|
||||
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>416</width>
|
||||
<height>325</height>
|
||||
<height>461</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -18,6 +18,12 @@
|
||||
<layout class="QHBoxLayout" name="layout_name">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_name">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
@ -27,11 +33,7 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_nameValue">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="lineEdit_name"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
@ -59,11 +61,96 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_value">
|
||||
<widget class="Line" name="line_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_custom">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_value">
|
||||
<spacer name="spacer_custom">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_custom">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Value</string>
|
||||
<string>Use custom formula</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_value" native="true">
|
||||
<layout class="QHBoxLayout" name="layout_value">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_value">
|
||||
<property name="text">
|
||||
<string>Value</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox_value">
|
||||
<property name="editable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_customValue" native="true">
|
||||
<layout class="QHBoxLayout" name="layout_customValue">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_customValue">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Value</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_customValue"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_max">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_max">
|
||||
<property name="text">
|
||||
<string>Max value</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
@ -71,14 +158,42 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox_value">
|
||||
<property name="editable">
|
||||
<bool>false</bool>
|
||||
<widget class="QDoubleSpinBox" name="doubleSpinBox_max">
|
||||
<property name="maximum">
|
||||
<double>9999.989999999999782</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_min">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_min">
|
||||
<property name="text">
|
||||
<string>Min value</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="doubleSpinBox_min">
|
||||
<property name="maximum">
|
||||
<double>9999.989999999999782</double>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout_activeColor">
|
||||
<item>
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
// configuraion
|
||||
// graphical items api version
|
||||
#define AWGIAPI 3
|
||||
#define AWGIAPI 4
|
||||
// extquotes api version
|
||||
#define AWEQAPI 3
|
||||
// extscript api version
|
||||
|
Loading…
Reference in New Issue
Block a user