Merge pull request #90 from arcan1s/development

Master update
This commit is contained in:
Evgenii Alekseev 2016-04-21 17:46:47 +04:00
commit 7eb82c8c8d
22 changed files with 463 additions and 390 deletions

View File

@ -0,0 +1,37 @@
diff --git a/sources/awesome-widget/plugin/awkeysaggregator.cpp b/sources/awesome-widget/plugin/awkeysaggregator.cpp
index 7a1887b..9f39e2f 100644
--- a/sources/awesome-widget/plugin/awkeysaggregator.cpp
+++ b/sources/awesome-widget/plugin/awkeysaggregator.cpp
@@ -34,8 +34,8 @@ AWKeysAggregator::AWKeysAggregator(QObject *parent)
// default formaters
// memory
m_formater[QString("mem")] = Float;
- m_formater[QString("memtotmb")] = IntegerFive;
- m_formater[QString("memtotgb")] = Float;
+ m_formater[QString("memtotmb")] = MemMBFormat;
+ m_formater[QString("memtotgb")] = MemGBFormat;
// network
m_formater[QString("down")] = NetSmartFormat;
m_formater[QString("downkb")] = Integer;
@@ -45,8 +45,8 @@ AWKeysAggregator::AWKeysAggregator(QObject *parent)
m_formater[QString("upunits")] = NetSmartUnits;
// swap
m_formater[QString("swap")] = Float;
- m_formater[QString("swaptotmb")] = IntegerFive;
- m_formater[QString("swaptotgb")] = Float;
+ m_formater[QString("swaptotmb")] = MemMBFormat;
+ m_formater[QString("swaptotgb")] = MemGBFormat;
}
@@ -338,8 +338,8 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
m_map[source] = key;
m_formater[key] = Float;
// additional keys
- m_formater[QString("hddtotmb%1").arg(index)] = IntegerFive;
- m_formater[QString("hddtotgb%1").arg(index)] = Float;
+ m_formater[QString("hddtotmb%1").arg(index)] = MemMBFormat;
+ m_formater[QString("hddtotgb%1").arg(index)] = MemGBFormat;
}
} else if (source.contains(mountFreeRegExp)) {
// free space

@ -1 +1 @@
Subproject commit ef47b1146e88caaa9be4f68d5b42919f36ab051c
Subproject commit e7bcf8ee858e7be3012168e12c7b14ccc28535b4

View File

@ -42,14 +42,14 @@ include(changelog.cmake)
# flags
if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-Wall -Wno-cpp -std=c++14")
set(CMAKE_CXX_FLAGS "-Wall -Wno-cpp -std=c++11")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG")
# avoid newer gcc warnings
add_definitions(-D_DEFAULT_SOURCE)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "-Wall -std=c++14 -stdlib=libc++")
set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -stdlib=libc++")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG")

View File

@ -84,7 +84,7 @@ Item {
// ui
Text {
id: text
anchors.fill: parent
anchors.fill: Layout
renderType: Text.NativeRendering
textFormat: Text.RichText
wrapMode: plasmoid.configuration.wrapText ? Text.WordWrap : Text.NoWrap

View File

@ -61,7 +61,22 @@ Item {
height: implicitHeight
width: parent.width
QtControls.Button {
width: parent.width * 3 / 12
width: parent.width * 3 / 15
text: i18n("Bgcolor")
onClicked: backgroundDialog.visible = true
QtDialogs.ColorDialog {
id: backgroundDialog
title: i18n("Select a color")
onAccepted: {
var text = textPattern.text
textPattern.text = "<body bgcolor=\"" + backgroundDialog.color + "\">" + text + "</body>"
}
}
}
QtControls.Button {
width: parent.width * 3 / 15
text: i18n("Font")
iconName: "font"
@ -73,123 +88,119 @@ Item {
"size": plasmoid.configuration.fontSize
}
var font = awActions.getFont(defaultFont)
var pos = textPattern.cursorPosition
if (font.applied != 1) {
if (debug) console.debug("No font selected")
return
}
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<span style=\"color:" + font.color +
"; font-family:'" + font.family +
"'; font-size:" + font.size + "pt;\">" +
selected + "</span>")
textPattern.insert(textPattern.cursorPosition,
"<span style=\"color:" + font.color +
"; font-family:'" + font.family +
"'; font-size:" + font.size + "pt;\">" +
selected + "</span>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-indent-more"
onClicked: {
if (debug) console.debug("Indent button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, selected + "<br>\n")
textPattern.insert(textPattern.cursorPosition, selected + "<br>\n")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-text-bold"
onClicked: {
if (debug) console.debug("Bold button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<b>" + selected + "</b>")
textPattern.insert(textPattern.cursorPosition, "<b>" + selected + "</b>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-text-italic"
onClicked: {
if (debug) console.debug("Italic button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<i>" + selected + "</i>")
textPattern.insert(textPattern.cursorPosition, "<i>" + selected + "</i>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-text-underline"
onClicked: {
if (debug) console.debug("Underline button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<u>" + selected + "</u>")
textPattern.insert(textPattern.cursorPosition, "<u>" + selected + "</u>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-text-strikethrough"
onClicked: {
if (debug) console.debug("Strike button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<s>" + selected + "</s>")
textPattern.insert(textPattern.cursorPosition, "<s>" + selected + "</s>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-justify-left"
onClicked: {
if (debug) console.debug("Left button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<p align=\"left\">" + selected + "</p>")
textPattern.insert(textPattern.cursorPosition, "<p align=\"left\">" + selected + "</p>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-justify-center"
onClicked: {
if (debug) console.debug("Center button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<p align=\"center\">" + selected + "</p>")
textPattern.insert(textPattern.cursorPosition, "<p align=\"center\">" + selected + "</p>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-justify-right"
onClicked: {
if (debug) console.debug("Right button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<p align=\"right\">" + selected + "</p>")
textPattern.insert(textPattern.cursorPosition, "<p align=\"right\">" + selected + "</p>")
}
}
QtControls.Button {
width: parent.width / 12
width: parent.width / 15
iconName: "format-justify-fill"
onClicked: {
if (debug) console.debug("Justify button")
var pos = textPattern.cursorPosition
var selected = textPattern.selectedText
textPattern.remove(textPattern.selectionStart, textPattern.selectionEnd)
textPattern.insert(pos, "<p align=\"justify\">" + selected + "</p>")
textPattern.insert(textPattern.cursorPosition, "<p align=\"justify\">" + selected + "</p>")
}
}
}

View File

@ -154,11 +154,14 @@ QVariantMap AWActions::getFont(const QVariantMap defaultFont) const
qCDebug(LOG_AW) << "Default font is" << defaultFont;
QVariantMap fontMap;
int ret = 0;
CFont defaultCFont = CFont(defaultFont[QString("family")].toString(),
defaultFont[QString("size")].toInt(), 400, false,
defaultFont[QString("color")].toString());
CFont font
= CFontDialog::getFont(i18n("Select font"), defaultCFont, false, false);
CFont font = CFontDialog::getFont(i18n("Select font"), defaultCFont, false,
false, &ret);
fontMap[QString("applied")] = ret;
fontMap[QString("color")] = font.color().name();
fontMap[QString("family")] = font.family();
fontMap[QString("size")] = font.pointSize();

View File

@ -312,14 +312,12 @@ QString AWKeys::parsePattern(QString pattern) const
// bars
for (auto bar : m_foundBars) {
GraphicalItem *item = keyOperator->giByKey(bar);
if (item->isCustom())
pattern.replace(
QString("$%1").arg(bar),
item->image(AWPatternFunctions::expandLambdas(
item->bar(), aggregator, values, item->usedKeys())));
else
pattern.replace(QString("$%1").arg(bar),
item->image(values[item->bar()]));
QString image
= item->isCustom()
? item->image(AWPatternFunctions::expandLambdas(
item->bar(), aggregator, values, item->usedKeys()))
: item->image(values[item->bar()]);
pattern.replace(QString("$%1").arg(bar), image);
}
// prepare strings

View File

@ -33,20 +33,20 @@ AWKeysAggregator::AWKeysAggregator(QObject *parent)
// default formaters
// memory
m_formater[QString("mem")] = Float;
m_formater[QString("memtotmb")] = IntegerFive;
m_formater[QString("memtotgb")] = Float;
m_formater[QString("mem")] = FormaterType::Float;
m_formater[QString("memtotmb")] = FormaterType::MemMBFormat;
m_formater[QString("memtotgb")] = FormaterType::MemGBFormat;
// network
m_formater[QString("down")] = NetSmartFormat;
m_formater[QString("downkb")] = Integer;
m_formater[QString("downunits")] = NetSmartUnits;
m_formater[QString("up")] = NetSmartFormat;
m_formater[QString("upkb")] = Integer;
m_formater[QString("upunits")] = NetSmartUnits;
m_formater[QString("down")] = FormaterType::NetSmartFormat;
m_formater[QString("downkb")] = FormaterType::Integer;
m_formater[QString("downunits")] = FormaterType::NetSmartUnits;
m_formater[QString("up")] = FormaterType::NetSmartFormat;
m_formater[QString("upkb")] = FormaterType::Integer;
m_formater[QString("upunits")] = FormaterType::NetSmartUnits;
// swap
m_formater[QString("swap")] = Float;
m_formater[QString("swaptotmb")] = IntegerFive;
m_formater[QString("swaptotgb")] = Float;
m_formater[QString("swap")] = FormaterType::Float;
m_formater[QString("swaptotmb")] = FormaterType::MemMBFormat;
m_formater[QString("swaptotgb")] = FormaterType::MemGBFormat;
}
@ -65,35 +65,35 @@ QString AWKeysAggregator::formater(const QVariant &data,
QLocale loc = m_translate ? QLocale::system() : QLocale::c();
// case block
switch (m_formater[key]) {
case Float:
case FormaterType::Float:
output = QString("%1").arg(data.toFloat(), 5, 'f', 1);
break;
case FloatTwoSymbols:
case FormaterType::FloatTwoSymbols:
output = QString("%1").arg(data.toFloat(), 5, 'f', 2);
break;
case Integer:
case FormaterType::Integer:
output = QString("%1").arg(data.toFloat(), 4, 'f', 0);
break;
case IntegerFive:
case FormaterType::IntegerFive:
output = QString("%1").arg(data.toFloat(), 5, 'f', 0);
break;
case IntegerThree:
case FormaterType::IntegerThree:
output = QString("%1").arg(data.toFloat(), 3, 'f', 0);
break;
case List:
case FormaterType::List:
output = data.toStringList().join(QChar(','));
break;
case ACFormat:
case FormaterType::ACFormat:
output = data.toBool() ? m_acOnline : m_acOffline;
break;
case MemGBFormat:
case FormaterType::MemGBFormat:
output
= QString("%1").arg(data.toFloat() / (1024.0 * 1024.0), 5, 'f', 1);
break;
case MemMBFormat:
case FormaterType::MemMBFormat:
output = QString("%1").arg(data.toFloat() / 1024.0, 5, 'f', 0);
break;
case NetSmartFormat:
case FormaterType::NetSmartFormat:
output = [](const float value) {
if (value > 1024.0)
return QString("%1").arg(value / 1024.0, 4, 'f', 1);
@ -101,41 +101,41 @@ QString AWKeysAggregator::formater(const QVariant &data,
return QString("%1").arg(value, 4, 'f', 0);
}(data.toFloat());
break;
case NetSmartUnits:
case FormaterType::NetSmartUnits:
if (data.toFloat() > 1024.0)
output = m_translate ? i18n("MB/s") : QString("MB/s");
else
output = m_translate ? i18n("KB/s") : QString("KB/s");
break;
case Quotes:
case FormaterType::Quotes:
// first cast
output = QString("%1").arg(data.toDouble(), 0, 'f');
output = output.rightJustified(8, QLatin1Char(' '), true);
break;
case Temperature:
case FormaterType::Temperature:
output = QString("%1").arg(temperature(data.toFloat()), 5, 'f', 1);
break;
case Time:
case FormaterType::Time:
output = data.toDateTime().toString();
break;
case TimeCustom:
case FormaterType::TimeCustom:
output = m_customTime;
[&output, loc, this](const QDateTime dt) {
for (auto key : timeKeys)
output.replace(QString("$%1").arg(key), loc.toString(dt, key));
}(data.toDateTime());
break;
case TimeISO:
case FormaterType::TimeISO:
output = data.toDateTime().toString(Qt::ISODate);
break;
case TimeLong:
case FormaterType::TimeLong:
output = loc.toString(data.toDateTime(), QLocale::LongFormat);
break;
case TimeShort:
case FormaterType::TimeShort:
output = loc.toString(data.toDateTime(), QLocale::ShortFormat);
break;
case Uptime:
case UptimeCustom:
case FormaterType::Uptime:
case FormaterType::UptimeCustom:
output =
[](QString source, const int uptime) {
int seconds = uptime - uptime % 60;
@ -152,16 +152,13 @@ QString AWKeysAggregator::formater(const QVariant &data,
QString("%1").arg(minutes, 2, 10, QChar('0')));
source.replace(QString("$m"), QString("%1").arg(minutes));
return source;
}(m_formater[key] == Uptime ? QString("$ddd$hhh$mmm")
: m_customUptime,
}(m_formater[key] == FormaterType::Uptime ? QString("$ddd$hhh$mmm")
: m_customUptime,
static_cast<int>(data.toFloat()));
break;
case NoFormat:
case FormaterType::NoFormat:
output = data.toString();
break;
default:
output = QString();
break;
}
return output;
@ -254,52 +251,52 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
if (source == QString("battery/ac")) {
// AC
m_map[source] = QString("ac");
m_formater[QString("ac")] = ACFormat;
m_formater[QString("ac")] = FormaterType::ACFormat;
} else if (source.startsWith(QString("battery/"))) {
// battery stats
QString key = source;
key.remove(QString("battery/"));
m_map[source] = key;
m_formater[key] = IntegerThree;
m_formater[key] = FormaterType::IntegerThree;
} else if (source == QString("cpu/system/TotalLoad")) {
// cpu
m_map[source] = QString("cpu");
m_formater[QString("cpu")] = Float;
m_formater[QString("cpu")] = FormaterType::Float;
} else if (source.contains(cpuRegExp)) {
// cpus
QString key = source;
key.remove(QString("cpu/")).remove(QString("/TotalLoad"));
m_map[source] = key;
m_formater[key] = Float;
m_formater[key] = FormaterType::Float;
} else if (source == QString("cpu/system/AverageClock")) {
// cpucl
m_map[source] = QString("cpucl");
m_formater[QString("cpucl")] = Integer;
m_formater[QString("cpucl")] = FormaterType::Integer;
} else if (source.contains(cpuclRegExp)) {
// cpucls
QString key = source;
key.remove(QString("cpu/cpu")).remove(QString("/clock"));
key = QString("cpucl%1").arg(key);
m_map[source] = key;
m_formater[key] = Integer;
m_formater[key] = FormaterType::Integer;
} else if (source.startsWith(QString("custom"))) {
// custom
QString key = source;
key.remove(QString("custom/"));
m_map[source] = key;
m_formater[key] = NoFormat;
m_formater[key] = FormaterType::NoFormat;
} else if (source == QString("desktop/current/name")) {
// current desktop name
m_map[source] = QString("desktop");
m_formater[QString("desktop")] = NoFormat;
m_formater[QString("desktop")] = FormaterType::NoFormat;
} else if (source == QString("desktop/current/number")) {
// current desktop number
m_map[source] = QString("ndesktop");
m_formater[QString("ndesktop")] = NoFormat;
m_formater[QString("ndesktop")] = FormaterType::NoFormat;
} else if (source == QString("desktop/total/number")) {
// desktop count
m_map[source] = QString("tdesktops");
m_formater[QString("tdesktops")] = NoFormat;
m_formater[QString("tdesktops")] = FormaterType::NoFormat;
} else if (source.contains(hddrRegExp)) {
// read speed
QString device = source;
@ -308,7 +305,7 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
if (index > -1) {
QString key = QString("hddr%1").arg(index);
m_map[source] = key;
m_formater[key] = Integer;
m_formater[key] = FormaterType::Integer;
}
} else if (source.contains(hddwRegExp)) {
// write speed
@ -318,16 +315,16 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
if (index > -1) {
QString key = QString("hddw%1").arg(index);
m_map[source] = key;
m_formater[key] = Integer;
m_formater[key] = FormaterType::Integer;
}
} else if (source == QString("gpu/load")) {
// gpu load
m_map[source] = QString("gpu");
m_formater[QString("gpu")] = Float;
m_formater[QString("gpu")] = FormaterType::Float;
} else if (source == QString("gpu/temperature")) {
// gpu temperature
m_map[source] = QString("gputemp");
m_formater[QString("gputemp")] = Temperature;
m_formater[QString("gputemp")] = FormaterType::Temperature;
} else if (source.contains(mountFillRegExp)) {
// fill level
QString device = source;
@ -336,10 +333,12 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
if (index > -1) {
QString key = QString("hdd%1").arg(index);
m_map[source] = key;
m_formater[key] = Float;
m_formater[key] = FormaterType::Float;
// additional keys
m_formater[QString("hddtotmb%1").arg(index)] = IntegerFive;
m_formater[QString("hddtotgb%1").arg(index)] = Float;
m_formater[QString("hddtotmb%1").arg(index)]
= FormaterType::MemMBFormat;
m_formater[QString("hddtotgb%1").arg(index)]
= FormaterType::MemGBFormat;
}
} else if (source.contains(mountFreeRegExp)) {
// free space
@ -350,11 +349,11 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
// mb
QString key = QString("hddfreemb%1").arg(index);
m_map[source] = key;
m_formater[key] = MemMBFormat;
m_formater[key] = FormaterType::MemMBFormat;
// gb
key = QString("hddfreegb%1").arg(index);
m_map.insertMulti(source, key);
m_formater[key] = MemGBFormat;
m_formater[key] = FormaterType::MemGBFormat;
}
} else if (source.contains(mountUsedRegExp)) {
// used
@ -365,11 +364,11 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
// mb
QString key = QString("hddmb%1").arg(index);
m_map[source] = key;
m_formater[key] = MemMBFormat;
m_formater[key] = FormaterType::MemMBFormat;
// gb
key = QString("hddgb%1").arg(index);
m_map.insertMulti(source, key);
m_formater[key] = MemGBFormat;
m_formater[key] = FormaterType::MemGBFormat;
}
} else if (source.startsWith(QString("hdd/temperature"))) {
// hdd temperature
@ -379,7 +378,7 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
if (index > -1) {
QString key = QString("hddtemp%1").arg(index);
m_map[source] = key;
m_formater[key] = Temperature;
m_formater[key] = FormaterType::Temperature;
}
} else if (source.startsWith(QString("cpu/system/loadavg"))) {
// load average
@ -387,35 +386,35 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
time.remove(QString("cpu/system/loadavg"));
QString key = QString("la%1").arg(time);
m_map[source] = key;
m_formater[key] = FloatTwoSymbols;
m_formater[key] = FormaterType::FloatTwoSymbols;
} else if (source == QString("mem/physical/application")) {
// app memory
// mb
m_map[source] = QString("memmb");
m_formater[QString("memmb")] = MemMBFormat;
m_formater[QString("memmb")] = FormaterType::MemMBFormat;
// gb
m_map.insertMulti(source, QString("memgb"));
m_formater[QString("memgb")] = MemGBFormat;
m_formater[QString("memgb")] = FormaterType::MemGBFormat;
} else if (source == QString("mem/physical/free")) {
// free memory
// mb
m_map[source] = QString("memfreemb");
m_formater[QString("memfreemb")] = MemMBFormat;
m_formater[QString("memfreemb")] = FormaterType::MemMBFormat;
// gb
m_map.insertMulti(source, QString("memfreegb"));
m_formater[QString("memfreegb")] = MemGBFormat;
m_formater[QString("memfreegb")] = FormaterType::MemGBFormat;
} else if (source == QString("mem/physical/used")) {
// used memory
// mb
m_map[source] = QString("memusedmb");
m_formater[QString("memusedmb")] = MemMBFormat;
m_formater[QString("memusedmb")] = FormaterType::MemMBFormat;
// gb
m_map.insertMulti(source, QString("memusedgb"));
m_formater[QString("memusedgb")] = MemGBFormat;
m_formater[QString("memusedgb")] = FormaterType::MemGBFormat;
} else if (source == QString("network/current/name")) {
// network device
m_map[source] = QString("netdev");
m_formater[QString("netdev")] = NoFormat;
m_formater[QString("netdev")] = FormaterType::NoFormat;
} else if (source.contains(netRegExp)) {
// network speed
QString type = source.contains(QString("receiver")) ? QString("down")
@ -426,62 +425,62 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
// kb
QString key = QString("%1kb%2").arg(type).arg(index);
m_map[source] = key;
m_formater[key] = Integer;
m_formater[key] = FormaterType::Integer;
// smart
key = QString("%1%2").arg(type).arg(index);
m_map.insertMulti(source, key);
m_formater[key] = NetSmartFormat;
m_formater[key] = FormaterType::NetSmartFormat;
// units
key = QString("%1units%2").arg(type).arg(index);
m_map.insertMulti(source, key);
m_formater[key] = NetSmartUnits;
m_formater[key] = FormaterType::NetSmartUnits;
}
} else if (source.startsWith(QString("upgrade"))) {
// package manager
QString key = source;
key.remove(QString("upgrade/"));
m_map[source] = key;
m_formater[key] = IntegerThree;
m_formater[key] = FormaterType::IntegerThree;
} else if (source.startsWith(QString("player"))) {
// player
QString key = source;
key.remove(QString("player/"));
m_map[source] = key;
m_formater[key] = NoFormat;
m_formater[key] = FormaterType::NoFormat;
} else if (source == QString("ps/running/count")) {
// running processes count
m_map[source] = QString("pscount");
m_formater[QString("pscount")] = NoFormat;
m_formater[QString("pscount")] = FormaterType::NoFormat;
} else if (source == QString("ps/running/list")) {
// list of running processes
m_map[source] = QString("ps");
m_formater[QString("ps")] = List;
m_formater[QString("ps")] = FormaterType::List;
} else if (source == QString("ps/total/count")) {
// total processes count
m_map[source] = QString("pstotal");
m_formater[QString("pstotal")] = NoFormat;
m_formater[QString("pstotal")] = FormaterType::NoFormat;
} else if (source.startsWith(QString("quotes"))) {
// quotes
QString key = source;
key.remove(QString("quotes/"));
m_map[source] = key;
m_formater[key] = Quotes;
m_formater[key] = FormaterType::Quotes;
} else if (source == QString("mem/swap/free")) {
// free swap
// mb
m_map[source] = QString("swapfreemb");
m_formater[QString("swapfreemb")] = MemMBFormat;
m_formater[QString("swapfreemb")] = FormaterType::MemMBFormat;
// gb
m_map.insertMulti(source, QString("swapfreegb"));
m_formater[QString("swapfreegb")] = MemGBFormat;
m_formater[QString("swapfreegb")] = FormaterType::MemGBFormat;
} else if (source == QString("mem/swap/used")) {
// used swap
// mb
m_map[source] = QString("swapmb");
m_formater[QString("swapmb")] = MemMBFormat;
m_formater[QString("swapmb")] = FormaterType::MemMBFormat;
// gb
m_map.insertMulti(source, QString("swapgb"));
m_formater[QString("swapgb")] = MemGBFormat;
m_formater[QString("swapgb")] = FormaterType::MemGBFormat;
} else if (source.startsWith(QString("lmsensors/"))) {
// temperature
int index = m_devices[QString("temp")].indexOf(source);
@ -491,49 +490,50 @@ QStringList AWKeysAggregator::registerSource(const QString &source,
if (index > -1) {
QString key = QString("temp%1").arg(index);
m_map[source] = key;
m_formater[key] = units == QString("°C") ? Temperature : Integer;
m_formater[key] = units == QString("°C") ? FormaterType::Temperature
: FormaterType::Integer;
}
} else if (source == QString("Local")) {
// time
m_map[source] = QString("time");
m_formater[QString("time")] = Time;
m_formater[QString("time")] = FormaterType::Time;
// custom time
m_map.insertMulti(source, QString("ctime"));
m_formater[QString("ctime")] = TimeCustom;
m_formater[QString("ctime")] = FormaterType::TimeCustom;
// ISO time
m_map.insertMulti(source, QString("isotime"));
m_formater[QString("isotime")] = TimeISO;
m_formater[QString("isotime")] = FormaterType::TimeISO;
// long time
m_map.insertMulti(source, QString("longtime"));
m_formater[QString("longtime")] = TimeLong;
m_formater[QString("longtime")] = FormaterType::TimeLong;
// short time
m_map.insertMulti(source, QString("shorttime"));
m_formater[QString("shorttime")] = TimeShort;
m_formater[QString("shorttime")] = FormaterType::TimeShort;
} else if (source == QString("system/uptime")) {
// uptime
m_map[source] = QString("uptime");
m_formater[QString("uptime")] = Uptime;
m_formater[QString("uptime")] = FormaterType::Uptime;
// custom uptime
m_map.insertMulti(source, QString("cuptime"));
m_formater[QString("cuptime")] = UptimeCustom;
m_formater[QString("cuptime")] = FormaterType::UptimeCustom;
} else if (source.startsWith(QString("weather/temperature"))) {
// temperature
QString key = source;
key.remove(QString("weather/"));
m_map[source] = key;
m_formater[key] = Temperature;
m_formater[key] = FormaterType::Temperature;
} else if (source.startsWith(QString("weather/"))) {
// other weather
QString key = source;
key.remove(QString("weather/"));
m_map[source] = key;
m_formater[key] = NoFormat;
m_formater[key] = FormaterType::NoFormat;
} else if (source.startsWith(QString("load/load"))) {
// load source
QString key = source;
key.remove(QString("load/"));
m_map[source] = key;
m_formater[key] = Temperature;
m_formater[key] = FormaterType::Temperature;
}
// drop key from dictionary if no one user requested key required it

View File

@ -36,7 +36,7 @@ class AWKeysAggregator : public QObject
Q_PROPERTY(QString tempUnits MEMBER m_tempUnits WRITE setTempUnits);
Q_PROPERTY(bool translate MEMBER m_translate WRITE setTranslate);
enum FormaterType {
enum class FormaterType {
// general formaters
NoFormat = 0,
Float,

View File

@ -74,14 +74,18 @@ bool AWUpdateHelper::checkVersion()
// update version
settings.setValue(QString("Version"), QString(VERSION));
settings.sync();
qCInfo(LOG_AW) << "Found version" << version << "actual one is"
<< m_foundVersion;
qCInfo(LOG_AW) << "Found version" << version << "actual one is" << VERSION;
if (version != QVersionNumber::fromString(VERSION)) {
if ((version != m_foundVersion) && (!QString(CHANGELOG).isEmpty())) {
genMessageBox(i18n("Changelog of %1", QString(VERSION)),
QString(CHANGELOG).replace(QChar('@'), QChar('\n')),
QMessageBox::Ok)
->open();
return true;
} else if (version != m_foundVersion) {
qCWarning(LOG_AW) << "No changelog information provided";
return true;
} else {
qCInfo(LOG_AW) << "No need to update version";
}

View File

@ -6,11 +6,11 @@ X-AW-Value=bat
X-AW-Custom=false
X-AW-Max=100.0
X-AW-Min=0.0
X-AW-ActiveColor="0,0,0,255"
X-AW-InactiveColor="255,255,255,255"
X-AW-ActiveColor="color://0,0,0,255"
X-AW-InactiveColor="color://255,255,255,255"
X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=4
X-AW-ApiVersion=5
X-AW-Number=3

View File

@ -6,11 +6,11 @@ X-AW-Value=cpu
X-AW-Custom=false
X-AW-Max=100.0
X-AW-Min=0.0
X-AW-ActiveColor="0,0,0,255"
X-AW-InactiveColor="255,255,255,255"
X-AW-ActiveColor="color://0,0,0,255"
X-AW-InactiveColor="color://255,255,255,255"
X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=4
X-AW-ApiVersion=5
X-AW-Number=0

View File

@ -6,11 +6,11 @@ X-AW-Value=mem
X-AW-Custom=false
X-AW-Max=100.0
X-AW-Min=0.0
X-AW-ActiveColor="0,0,0,255"
X-AW-InactiveColor="255,255,255,255"
X-AW-ActiveColor="color://0,0,0,255"
X-AW-InactiveColor="color://255,255,255,255"
X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=4
X-AW-ApiVersion=5
X-AW-Number=1

View File

@ -6,11 +6,11 @@ X-AW-Value=swap
X-AW-Custom=false
X-AW-Max=100.0
X-AW-Min=0.0
X-AW-ActiveColor="0,0,0,255"
X-AW-InactiveColor="255,255,255,255"
X-AW-ActiveColor="color://0,0,0,255"
X-AW-InactiveColor="color://255,255,255,255"
X-AW-Type=Horizontal
X-AW-Direction=LeftToRight
X-AW-Height=25
X-AW-Width=100
X-AW-ApiVersion=4
X-AW-ApiVersion=5
X-AW-Number=2

View File

@ -112,17 +112,16 @@ QString ExtScript::strRedirect() const
{
QString value;
switch (m_redirect) {
case stdout2stderr:
case Redirect::stdout2stderr:
value = QString("stdout2stderr");
break;
case stderr2stdout:
case Redirect::stderr2stdout:
value = QString("stderr2stdout");
break;
case swap:
case Redirect::swap:
value = QString("swap");
break;
case nothing:
default:
case Redirect::nothing:
value = QString("nothing");
break;
}
@ -158,7 +157,7 @@ void ExtScript::setPrefix(const QString _prefix)
void ExtScript::setRedirect(const Redirect _redirect)
{
qCDebug(LOG_LIB) << "Redirect" << _redirect;
qCDebug(LOG_LIB) << "Redirect" << static_cast<int>(_redirect);
m_redirect = _redirect;
}
@ -169,13 +168,13 @@ void ExtScript::setStrRedirect(const QString _redirect)
qCDebug(LOG_LIB) << "Redirect" << _redirect;
if (_redirect == QString("stdout2sdterr"))
m_redirect = stdout2stderr;
m_redirect = Redirect::stdout2stderr;
else if (_redirect == QString("stderr2sdtout"))
m_redirect = stderr2stdout;
m_redirect = Redirect::stderr2stdout;
else if (_redirect == QString("swap"))
m_redirect = swap;
m_redirect = Redirect::swap;
else
m_redirect = nothing;
m_redirect = Redirect::nothing;
}
@ -376,16 +375,15 @@ void ExtScript::updateValue()
QString strValue;
switch (m_redirect) {
case stdout2stderr:
case Redirect::stdout2stderr:
break;
case stderr2stdout:
case Redirect::stderr2stdout:
strValue = QString("%1\n%2").arg(qdebug).arg(qoutput);
break;
case swap:
case Redirect::swap:
strValue = qdebug;
break;
case nothing:
default:
case Redirect::nothing:
strValue = qoutput;
break;
}

View File

@ -37,7 +37,7 @@ class ExtScript : public AbstractExtItem
Q_PROPERTY(Redirect redirect READ redirect WRITE setRedirect)
public:
enum Redirect { stdout2stderr = 0, nothing, stderr2stdout, swap };
enum class Redirect { stdout2stderr = 0, nothing, stderr2stdout, swap };
explicit ExtScript(QWidget *parent = nullptr,
const QString scriptName = QString(),
@ -56,7 +56,7 @@ public:
void setExecutable(const QString _executable = QString("/usr/bin/true"));
void setFilters(const QStringList _filters = QStringList());
void setPrefix(const QString _prefix = QString(""));
void setRedirect(const Redirect _redirect = nothing);
void setRedirect(const Redirect _redirect = Redirect::nothing);
void setStrRedirect(const QString _redirect = QString("nothing"));
// filters
QString applyFilters(QString _value) const;
@ -80,7 +80,7 @@ private:
QString m_executable = QString("/usr/bin/true");
QStringList m_filters = QStringList();
QString m_prefix = QString("");
Redirect m_redirect = nothing;
Redirect m_redirect = Redirect::nothing;
// internal properties
QVariantMap jsonFilters = QVariantMap();
int times = 0;

View File

@ -50,9 +50,9 @@ GraphicalItem::GraphicalItem(QWidget *parent, const QString desktopName,
SLOT(changeValue(int)));
connect(ui->comboBox_type, SIGNAL(currentIndexChanged(int)), this,
SLOT(changeCountState(int)));
connect(ui->pushButton_activeColor, SIGNAL(clicked()), this,
connect(ui->toolButton_activeColor, SIGNAL(clicked()), this,
SLOT(changeColor()));
connect(ui->pushButton_inactiveColor, SIGNAL(clicked()), this,
connect(ui->toolButton_inactiveColor, SIGNAL(clicked()), this,
SLOT(changeColor()));
}
@ -102,22 +102,27 @@ QString GraphicalItem::image(const QVariant &value)
// paint
switch (m_type) {
case Vertical:
case Type::Vertical:
m_helper->paintVertical(converted);
// scale
scale[1] = -2 * static_cast<int>(m_direction) + 1;
break;
case Circle:
case Type::Circle:
m_helper->paintCircle(converted);
// scale
scale[0] = -2 * static_cast<int>(m_direction) + 1;
break;
case Graph:
case Type::Graph:
m_helper->paintGraph(converted);
// direction option is not recognized by this GI type
scale[0] = -2 * static_cast<int>(m_direction) + 1;
scale[1] = -1;
break;
case Horizontal:
default:
case Type::Bars:
m_helper->paintBars(converted);
scale[0] = -2 * static_cast<int>(m_direction) + 1;
scale[1] = -1;
break;
case Type::Horizontal:
m_helper->paintHorizontal(converted);
// scale
scale[0] = -2 * static_cast<int>(m_direction) + 1;
@ -189,17 +194,19 @@ QString GraphicalItem::strType() const
{
QString value;
switch (m_type) {
case Vertical:
case Type::Vertical:
value = QString("Vertical");
break;
case Circle:
case Type::Circle:
value = QString("Circle");
break;
case Graph:
case Type::Graph:
value = QString("Graph");
break;
case Horizontal:
default:
case Type::Bars:
value = QString("Bars");
break;
case Type::Horizontal:
value = QString("Horizontal");
break;
}
@ -218,11 +225,10 @@ QString GraphicalItem::strDirection() const
{
QString value;
switch (m_direction) {
case RightToLeft:
case Direction::RightToLeft:
value = QString("RightToLeft");
break;
case LeftToRight:
default:
case Direction::LeftToRight:
value = QString("LeftToRight");
break;
}
@ -315,7 +321,7 @@ void GraphicalItem::setMinValue(const float _value)
void GraphicalItem::setType(const Type _type)
{
qCDebug(LOG_LIB) << "Type" << _type;
qCDebug(LOG_LIB) << "Type" << static_cast<int>(_type);
m_type = _type;
}
@ -326,19 +332,21 @@ void GraphicalItem::setStrType(const QString _type)
qCDebug(LOG_LIB) << "Type" << _type;
if (_type == QString("Vertical"))
setType(Vertical);
setType(Type::Vertical);
else if (_type == QString("Circle"))
setType(Circle);
setType(Type::Circle);
else if (_type == QString("Graph"))
setType(Graph);
setType(Type::Graph);
else if (_type == QString("Bars"))
setType(Type::Bars);
else
setType(Horizontal);
setType(Type::Horizontal);
}
void GraphicalItem::setDirection(const Direction _direction)
{
qCDebug(LOG_LIB) << "Direction" << _direction;
qCDebug(LOG_LIB) << "Direction" << static_cast<int>(_direction);
m_direction = _direction;
}
@ -349,9 +357,9 @@ void GraphicalItem::setStrDirection(const QString _direction)
qCDebug(LOG_LIB) << "Direction" << _direction;
if (_direction == QString("RightToLeft"))
setDirection(RightToLeft);
setDirection(Direction::RightToLeft);
else
setDirection(LeftToRight);
setDirection(Direction::LeftToRight);
}
@ -370,7 +378,13 @@ void GraphicalItem::setUsedKeys(const QStringList _usedKeys)
qCDebug(LOG_LIB) << "Used keys" << _usedKeys;
// remove dubs
m_usedKeys = QSet<QString>::fromList(_usedKeys).toList();
// HACK converting to set may break order
m_usedKeys.clear();
for (auto key : _usedKeys) {
if (m_usedKeys.contains(key))
continue;
m_usedKeys.append(key);
}
}
@ -415,9 +429,18 @@ void GraphicalItem::readConfiguration()
.toString());
setHeight(settings.value(QString("X-AW-Height"), m_height).toInt());
setWidth(settings.value(QString("X-AW-Width"), m_width).toInt());
// api == 2
if (apiVersion() < 2)
setNumber(bar().remove(QString("bar")).toInt());
// api == 5
if (apiVersion() < 5) {
QString prefix;
prefix = m_activeColor.startsWith(QString("/"))
? QString("file://%1")
: QString("color://%1");
m_activeColor = prefix.arg(m_activeColor);
prefix = m_inactiveColor.startsWith(QString("/"))
? QString("file://%1")
: QString("color://%1");
m_inactiveColor = prefix.arg(m_inactiveColor);
}
settings.endGroup();
}
@ -438,6 +461,7 @@ int GraphicalItem::showConfiguration(const QVariant args)
ui->lineEdit_name->setText(name());
ui->lineEdit_comment->setText(comment());
ui->label_numberValue->setText(QString("%1").arg(number()));
ui->checkBox_custom->setChecked(m_custom);
ui->comboBox_value->addItems(tags);
if (m_custom) {
@ -449,12 +473,16 @@ int GraphicalItem::showConfiguration(const QVariant args)
ui->doubleSpinBox_max->setValue(m_maxValue);
ui->doubleSpinBox_min->setValue(m_minValue);
ui->spinBox_count->setValue(m_count);
ui->checkBox_activeCheck->setChecked(
m_activeColor.startsWith(QString("/")));
ui->pushButton_activeColor->setText(m_activeColor);
ui->checkBox_inactiveCheck->setChecked(
m_inactiveColor.startsWith(QString("/")));
ui->pushButton_inactiveColor->setText(m_inactiveColor);
if (m_helper->isColor(m_activeColor))
ui->comboBox_activeImageType->setCurrentIndex(0);
else
ui->comboBox_activeImageType->setCurrentIndex(1);
ui->lineEdit_activeColor->setText(m_activeColor);
if (m_helper->isColor(m_inactiveColor))
ui->comboBox_inactiveImageType->setCurrentIndex(0);
else
ui->comboBox_inactiveImageType->setCurrentIndex(1);
ui->lineEdit_inactiveColor->setText(m_inactiveColor);
ui->comboBox_type->setCurrentIndex(static_cast<int>(m_type));
ui->comboBox_direction->setCurrentIndex(static_cast<int>(m_direction));
ui->spinBox_height->setValue(m_height);
@ -477,8 +505,8 @@ int GraphicalItem::showConfiguration(const QVariant args)
: 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('&')));
setActiveColor(ui->lineEdit_activeColor->text());
setInactiveColor(ui->lineEdit_inactiveColor->text());
setStrType(ui->comboBox_type->currentText());
setStrDirection(ui->comboBox_direction->currentText());
setHeight(ui->spinBox_height->value());
@ -518,22 +546,20 @@ void GraphicalItem::writeConfiguration() const
void GraphicalItem::changeColor()
{
QString outputColor;
bool imageRequired = sender() == ui->pushButton_activeColor
? ui->checkBox_activeCheck->isChecked()
: ui->checkBox_inactiveCheck->isChecked();
if (imageRequired) {
QString path = static_cast<QPushButton *>(sender())->text();
QString directory = QFileInfo(path).absolutePath();
outputColor = QFileDialog::getOpenFileName(
this, tr("Select path"), directory,
tr("Images (*.png *.bpm *.jpg);;All files (*.*)"));
qCInfo(LOG_LIB) << "Selected path" << outputColor;
QLineEdit *lineEdit;
int state;
if (sender() == ui->toolButton_activeColor) {
lineEdit = ui->lineEdit_activeColor;
state = ui->comboBox_activeImageType->currentIndex();
} else {
QColor color = m_helper->stringToColor(
(static_cast<QPushButton *>(sender()))->text());
lineEdit = ui->lineEdit_inactiveColor;
state = ui->comboBox_inactiveImageType->currentIndex();
}
qCInfo(LOG_LIB) << "Using state" << state << "and lineEdit" << lineEdit;
QString outputColor;
if (state == 0) {
QColor color = m_helper->stringToColor(lineEdit->text());
QColor newColor = QColorDialog::getColor(
color, this, tr("Select color"), QColorDialog::ShowAlphaChannel);
if (!newColor.isValid())
@ -546,10 +572,23 @@ void GraphicalItem::changeColor()
colorText.append(QString("%1").arg(newColor.blue()));
colorText.append(QString("%1").arg(newColor.alpha()));
outputColor = colorText.join(QChar(','));
outputColor = QString("color://%1").arg(colorText.join(QChar(',')));
} else if (state == 1) {
QString path = lineEdit->text();
QString directory = QFileInfo(path).absolutePath();
outputColor = QFileDialog::getOpenFileUrl(
this, tr("Select path"), directory,
tr("Images (*.png *.bpm *.jpg);;All files (*.*)"))
.toString();
qCInfo(LOG_LIB) << "Selected path" << outputColor;
}
return static_cast<QPushButton *>(sender())->setText(outputColor);
if (outputColor.isEmpty()) {
qCWarning(LOG_LIB) << "Empty color selected, skipping";
return;
}
return lineEdit->setText(outputColor);
}
@ -596,18 +635,24 @@ void GraphicalItem::translate()
{
ui->label_name->setText(i18n("Name"));
ui->label_comment->setText(i18n("Comment"));
ui->label_count->setText(i18n("Points count"));
ui->label_number->setText(i18n("Tag"));
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->checkBox_activeCheck->setText(i18n("Use image for active"));
ui->label_activeColor->setText(i18n("Active color"));
ui->checkBox_inactiveCheck->setText(i18n("Use image for inactive"));
ui->label_inactiveColor->setText(i18n("Inactive color"));
ui->label_activeImageType->setText(i18n("Active image type"));
ui->label_inactiveImageType->setText(i18n("Inctive image type"));
ui->label_type->setText(i18n("Type"));
ui->label_count->setText(i18n("Points count"));
ui->label_direction->setText(i18n("Direction"));
ui->label_height->setText(i18n("Height"));
ui->label_width->setText(i18n("Width"));
ui->comboBox_activeImageType->clear();
ui->comboBox_activeImageType->addItem(i18n("color"));
ui->comboBox_activeImageType->addItem(i18n("image"));
ui->comboBox_inactiveImageType->clear();
ui->comboBox_inactiveImageType->addItem(i18n("color"));
ui->comboBox_inactiveImageType->addItem(i18n("image"));
}

View File

@ -49,8 +49,8 @@ class GraphicalItem : public AbstractExtItem
Q_PROPERTY(int width READ width WRITE setWidth)
public:
enum Direction { LeftToRight = 0, RightToLeft };
enum Type { Horizontal = 0, Vertical, Circle, Graph };
enum class Direction { LeftToRight = 0, RightToLeft = 1 };
enum class Type { Horizontal = 0, Vertical, Circle, Graph, Bars };
explicit GraphicalItem(QWidget *parent = nullptr,
const QString desktopName = QString(),
@ -76,15 +76,16 @@ public:
QString uniq() const;
// set methods
void setBar(const QString _bar = QString("cpu"));
void setActiveColor(const QString _color = QString("0,0,0,130"));
void setActiveColor(const QString _color = QString("color://0,0,0,130"));
void setCount(const int _count = 100);
void setCustom(const bool _custom = false);
void setInactiveColor(const QString _color = QString("255,255,255,130"));
void setInactiveColor(const QString _color
= QString("color://255,255,255,130"));
void setMinValue(const float _value = 0.0);
void setMaxValue(const float _value = 100.0);
void setType(const Type _type = Horizontal);
void setType(const Type _type = Type::Horizontal);
void setStrType(const QString _type = QString("Horizontal"));
void setDirection(const Direction _direction = LeftToRight);
void setDirection(const Direction _direction = Direction::LeftToRight);
void setStrDirection(const QString _direction = QString("LeftToRight"));
void setHeight(const int _height = 100);
void setUsedKeys(const QStringList _usedKeys = QStringList());
@ -112,12 +113,12 @@ private:
QString m_bar = QString("cpu");
int m_count = 100;
bool m_custom = false;
QString m_activeColor;
QString m_inactiveColor;
QString m_activeColor = QString("color://0,0,0,130");
QString m_inactiveColor = QString("color://255,255,255,130");
float m_minValue = 0.0f;
float m_maxValue = 100.0f;
Type m_type = Horizontal;
Direction m_direction = LeftToRight;
Type m_type = Type::Horizontal;
Direction m_direction = Direction::LeftToRight;
int m_height = 100;
QStringList m_usedKeys;
int m_width = 100;

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>416</width>
<height>537</height>
<height>569</height>
</rect>
</property>
<property name="windowTitle">
@ -60,6 +60,27 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_number">
<item>
<widget class="QLabel" name="label_number">
<property name="text">
<string>Tag</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_numberValue">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
@ -100,16 +121,7 @@
<item>
<widget class="QWidget" name="widget_value" native="true">
<layout class="QHBoxLayout" name="layout_value">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>0</number>
</property>
<item>
@ -135,16 +147,7 @@
<item>
<widget class="QWidget" name="widget_customValue" native="true">
<layout class="QHBoxLayout" name="layout_customValue">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>0</number>
</property>
<item>
@ -219,134 +222,74 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="layout_activeCheck">
<layout class="QHBoxLayout" name="layout_activeImageType">
<item>
<spacer name="spacer_activeCheck">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<widget class="QLabel" name="label_activeImageType">
<property name="text">
<string>Active image type</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</spacer>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_activeCheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<widget class="QComboBox" name="comboBox_activeImageType"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_activeColorButton">
<item>
<widget class="QLineEdit" name="lineEdit_activeColor">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_activeColor">
<property name="text">
<string>Use image for active</string>
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget_activeColor" native="true">
<layout class="QHBoxLayout" name="layout_activeColor">
<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="QLabel" name="label_activeColor">
<property name="text">
<string>Active color</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_activeColor">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="layout_inactiveCheck">
<layout class="QHBoxLayout" name="layout_inactiveImageType">
<item>
<spacer name="spacer_inactiveCheck">
<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_inactiveCheck">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<widget class="QLabel" name="label_inactiveImageType">
<property name="text">
<string>Use image for inactive</string>
<string>Inactive image type</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox_inactiveImageType"/>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget_inactiveColor" native="true">
<layout class="QHBoxLayout" name="layout_inactiveColor">
<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="QLabel" name="label_inactiveColor">
<property name="text">
<string>Inactive color</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_inactiveColor">
<property name="text">
<string notr="true"/>
</property>
</widget>
</item>
</layout>
</widget>
<layout class="QHBoxLayout" name="layout_inactiveColorButton">
<item>
<widget class="QLineEdit" name="lineEdit_inactiveColor">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_inactiveColor">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="layout_type">
@ -382,6 +325,11 @@
<string notr="true">Graph</string>
</property>
</item>
<item>
<property name="text">
<string notr="true">Bars</string>
</property>
</item>
</widget>
</item>
</layout>
@ -417,16 +365,7 @@
<item>
<widget class="QWidget" name="widget_count" native="true">
<layout class="QHBoxLayout" name="layout_count">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>0</number>
</property>
<item>

View File

@ -50,29 +50,29 @@ void GraphicalItemHelper::setParameters(const QString active,
// put images to pens if any otherwise set pen colors
// Images resize to content here as well
if (active.startsWith(QString("/"))) {
if (isColor(active)) {
m_activePen.setBrush(QBrush(stringToColor(active)));
} else {
qCInfo(LOG_LIB) << "Found path, trying to load Pixmap from" << active;
QPixmap pixmap = QPixmap(active);
if (pixmap.isNull()) {
qCInfo(LOG_LIB) << "Invalid pixmap found" << active;
m_activePen.setColor(QColor(0, 0, 0, 130));
m_activePen.setBrush(QBrush(QColor(0, 0, 0, 130)));
} else {
m_activePen.setBrush(QBrush(pixmap.scaled(width, height)));
}
} else {
m_activePen.setColor(stringToColor(active));
}
if (inactive.startsWith(QString("/"))) {
if (isColor(inactive)) {
m_inactivePen.setBrush(QBrush(stringToColor(inactive)));
} else {
qCInfo(LOG_LIB) << "Found path, trying to load Pixmap from" << inactive;
QPixmap pixmap = QPixmap(inactive);
if (pixmap.isNull()) {
qCInfo(LOG_LIB) << "Invalid pixmap found" << inactive;
m_inactivePen.setColor(QColor(255, 255, 255, 130));
m_inactivePen.setBrush(QBrush(QColor(255, 255, 255, 130)));
} else {
m_inactivePen.setBrush(QBrush(pixmap.scaled(width, height)));
}
} else {
m_inactivePen.setColor(stringToColor(inactive));
}
m_width = width;
m_height = height;
@ -80,6 +80,30 @@ void GraphicalItemHelper::setParameters(const QString active,
}
void GraphicalItemHelper::paintBars(const float &value)
{
qCDebug(LOG_LIB) << "Paint with value" << value;
// refresh background image
m_scene->setBackgroundBrush(m_inactivePen.brush());
storeValue(value);
// default norms
float normX
= static_cast<float>(m_width) / static_cast<float>(m_values.count());
float normY = static_cast<float>(m_height - 1);
// paint graph
for (int i = 0; i < m_values.count(); i++) {
float x = i * normX;
float y = 0.5f;
float width = normX;
float height = m_values.at(i) * normY + 0.5f;
m_scene->addRect(x, y, width, height, m_activePen, m_activePen.brush());
}
}
void GraphicalItemHelper::paintCircle(const float &percent)
{
qCDebug(LOG_LIB) << "Paint with percent" << percent;
@ -120,9 +144,9 @@ void GraphicalItemHelper::paintGraph(const float &value)
for (int i = 0; i < m_values.count() - 1; i++) {
// some magic here
float x1 = i * normX;
float y1 = -fabs(m_values.at(i)) * normY + 0.5f;
float y1 = m_values.at(i) * normY + 0.5f;
float x2 = (i + 1) * normX;
float y2 = -fabs(m_values.at(i + 1)) * normY + 0.5f;
float y2 = m_values.at(i + 1) * normY + 0.5f;
m_scene->addLine(x1, y1, x2, y2, m_activePen);
}
}
@ -171,14 +195,25 @@ float GraphicalItemHelper::getPercents(const float &value, const float &min,
}
bool GraphicalItemHelper::isColor(const QString &input)
{
qCDebug(LOG_LIB) << "Define input type in" << input;
return input.startsWith(QString("color://"));
}
QColor GraphicalItemHelper::stringToColor(const QString &color)
{
qCDebug(LOG_LIB) << "Color" << color;
QColor qColor;
QStringList listColor = color.split(QChar(','));
while (listColor.count() < 4)
listColor.append(QString("0"));
// remove prefix
listColor[0].remove(QString("color://"));
// init color
QColor qColor;
qColor.setRed(listColor.at(0).toInt());
qColor.setGreen(listColor.at(1).toInt());
qColor.setBlue(listColor.at(2).toInt());

View File

@ -35,12 +35,14 @@ public:
void setParameters(const QString active, const QString inactive,
const int width, const int height, const int count);
// paint methods
void paintBars(const float &value);
void paintCircle(const float &percent);
void paintGraph(const float &value);
void paintHorizontal(const float &percent);
void paintVertical(const float &percent);
// additional conversion methods
float getPercents(const float &value, const float &min, const float &max);
bool isColor(const QString &input);
QColor stringToColor(const QString &color);
private:

View File

@ -24,7 +24,7 @@
// configuraion
// graphical items api version
#define AWGIAPI 4
#define AWGIAPI 5
// extquotes api version
#define AWEQAPI 3
// extscript api version