diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index ca46b81..5540997 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -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") diff --git a/sources/awesome-widget/package/contents/ui/main.qml b/sources/awesome-widget/package/contents/ui/main.qml index 0e20bc9..5e1f77c 100644 --- a/sources/awesome-widget/package/contents/ui/main.qml +++ b/sources/awesome-widget/package/contents/ui/main.qml @@ -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 diff --git a/sources/awesome-widget/plugin/awkeysaggregator.cpp b/sources/awesome-widget/plugin/awkeysaggregator.cpp index 7a1887b..d5b651a 100644 --- a/sources/awesome-widget/plugin/awkeysaggregator.cpp +++ b/sources/awesome-widget/plugin/awkeysaggregator.cpp @@ -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::IntegerFive; + m_formater[QString("memtotgb")] = FormaterType::Float; // 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::IntegerFive; + m_formater[QString("swaptotgb")] = FormaterType::Float; } @@ -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(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,11 @@ 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::IntegerFive; + m_formater[QString("hddtotgb%1").arg(index)] = FormaterType::Float; } } else if (source.contains(mountFreeRegExp)) { // free space @@ -350,11 +348,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 +363,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 +377,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 +385,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 +424,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 +489,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 diff --git a/sources/awesome-widget/plugin/awkeysaggregator.h b/sources/awesome-widget/plugin/awkeysaggregator.h index 1e2ef6c..a7087c4 100644 --- a/sources/awesome-widget/plugin/awkeysaggregator.h +++ b/sources/awesome-widget/plugin/awkeysaggregator.h @@ -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, diff --git a/sources/awesomewidgets/extscript.cpp b/sources/awesomewidgets/extscript.cpp index 90c61d1..a859d26 100644 --- a/sources/awesomewidgets/extscript.cpp +++ b/sources/awesomewidgets/extscript.cpp @@ -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(_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; } diff --git a/sources/awesomewidgets/extscript.h b/sources/awesomewidgets/extscript.h index 511c032..5d099af 100644 --- a/sources/awesomewidgets/extscript.h +++ b/sources/awesomewidgets/extscript.h @@ -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; diff --git a/sources/awesomewidgets/graphicalitem.cpp b/sources/awesomewidgets/graphicalitem.cpp index 73c771b..7d033b2 100644 --- a/sources/awesomewidgets/graphicalitem.cpp +++ b/sources/awesomewidgets/graphicalitem.cpp @@ -102,27 +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(m_direction) + 1; break; - case Circle: + case Type::Circle: m_helper->paintCircle(converted); // scale scale[0] = -2 * static_cast(m_direction) + 1; break; - case Graph: + case Type::Graph: m_helper->paintGraph(converted); - // direction option is not recognized by this GI type - break; - case Bars: - m_helper->paintBars(converted); - // direction option is not recognized by this GI type + scale[0] = -2 * static_cast(m_direction) + 1; scale[1] = -1; break; - case Horizontal: - default: + case Type::Bars: + m_helper->paintBars(converted); + scale[0] = -2 * static_cast(m_direction) + 1; + scale[1] = -1; + break; + case Type::Horizontal: m_helper->paintHorizontal(converted); // scale scale[0] = -2 * static_cast(m_direction) + 1; @@ -194,20 +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 Bars: + case Type::Bars: value = QString("Bars"); break; - case Horizontal: - default: + case Type::Horizontal: value = QString("Horizontal"); break; } @@ -226,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; } @@ -323,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(_type); m_type = _type; } @@ -334,21 +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(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(_direction); m_direction = _direction; } @@ -359,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); } diff --git a/sources/awesomewidgets/graphicalitem.h b/sources/awesomewidgets/graphicalitem.h index 50f4ed5..18d2630 100644 --- a/sources/awesomewidgets/graphicalitem.h +++ b/sources/awesomewidgets/graphicalitem.h @@ -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, Bars }; + 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(), @@ -83,9 +83,9 @@ public: = 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()); @@ -117,8 +117,8 @@ private: 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; diff --git a/sources/awesomewidgets/graphicalitemhelper.cpp b/sources/awesomewidgets/graphicalitemhelper.cpp index bf274bd..7aea398 100644 --- a/sources/awesomewidgets/graphicalitemhelper.cpp +++ b/sources/awesomewidgets/graphicalitemhelper.cpp @@ -144,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 = -m_values.at(i) * normY + 0.5f; + float y1 = m_values.at(i) * normY + 0.5f; float x2 = (i + 1) * normX; - float y2 = -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); } }