From 41419b4cee00a36159be54f3d68e2aeb62fe73c0 Mon Sep 17 00:00:00 2001 From: Max Paperno Date: Sun, 3 Jun 2018 16:49:44 -0400 Subject: [PATCH] [Companion] Move some single-use functions out of helpers module; cosmetics. --- companion/src/firmwares/telem_data.h | 26 +++++ companion/src/helpers.cpp | 135 ++++++++------------------ companion/src/helpers.h | 27 ++---- companion/src/modeledit/telemetry.cpp | 17 ++++ companion/src/multimodelprinter.cpp | 6 +- 5 files changed, 92 insertions(+), 119 deletions(-) diff --git a/companion/src/firmwares/telem_data.h b/companion/src/firmwares/telem_data.h index 5598e3702..9b98cc7ba 100644 --- a/companion/src/firmwares/telem_data.h +++ b/companion/src/firmwares/telem_data.h @@ -26,6 +26,8 @@ #include class FrSkyAlarmData { + Q_DECLARE_TR_FUNCTIONS(FrSkyAlarmData) + public: FrSkyAlarmData() { clear(); } unsigned int level; // 0=none, 1=Yellow, 2=Orange, 3=Red @@ -33,6 +35,20 @@ class FrSkyAlarmData { unsigned int value; // 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. void clear() { memset(this, 0, sizeof(FrSkyAlarmData)); } + + static QString alarmLevelName(int alarm) + { + switch (alarm) { + case 1: + return tr("Yellow"); + case 2: + return tr("Orange"); + case 3: + return tr("Red"); + default: + return "----"; + } + } }; class FrSkyChannelData { @@ -49,6 +65,16 @@ class FrSkyChannelData { float getRatio() const; RawSourceRange getRange() const; void clear() { memset(this, 0, sizeof(FrSkyChannelData)); } + + static QString unitString(int units) + { + switch(units) { + case 1: + return QCoreApplication::translate("FrSkyChannelData", "---"); + default: + return QCoreApplication::translate("FrSkyChannelData", "V"); + } + } }; struct FrSkyBarData { diff --git a/companion/src/helpers.cpp b/companion/src/helpers.cpp index 8b2ef1648..abf7663b4 100644 --- a/companion/src/helpers.cpp +++ b/companion/src/helpers.cpp @@ -75,6 +75,37 @@ const QColor colors[CPN_MAX_CURVES] = { QColor(255,127,0), }; + +/* + * CompanionIcon +*/ + +static QString iconThemeFolder(int theme_set) +{ + switch(theme_set) { + case 0: + return QStringLiteral("classic"); + case 2: + return QStringLiteral("monowhite"); + case 3: + return QStringLiteral("monochrome"); + case 4: + return QStringLiteral("monoblue"); + default: + return QStringLiteral("yerico"); + } +} + +CompanionIcon::CompanionIcon(const QString &baseimage) +{ + const QString theme = iconThemeFolder(g.theme()); + addFile(":/themes/"+theme+"/16/"+baseimage, QSize(16,16)); + addFile(":/themes/"+theme+"/24/"+baseimage, QSize(24,24)); + addFile(":/themes/"+theme+"/32/"+baseimage, QSize(32,32)); + addFile(":/themes/"+theme+"/48/"+baseimage, QSize(48,48)); +} + + /* * GVarGroup */ @@ -172,6 +203,7 @@ void GVarGroup::setWeight(int val) lock = false; } + /* * CurveGroup */ @@ -334,6 +366,7 @@ void CurveGroup::valuesChanged() } } + /* * Helpers namespace functions */ @@ -390,6 +423,11 @@ void Helpers::populateGvarUseCB(QComboBox * b, unsigned int phase) } } +static bool caseInsensitiveLessThan(const QString &s1, const QString &s2) +{ + return s1.toLower() < s2.toLower(); +} + void Helpers::populateFileComboBox(QComboBox * b, const QSet & set, const QString & current) { b->clear(); @@ -500,98 +538,6 @@ QStandardItemModel * Helpers::getRawSourceItemModel(const GeneralSettings * cons return itemModel; } -QString image2qstring(QImage image) -{ - if (image.isNull()) - return ""; - QBuffer buffer; - image.save(&buffer, "PNG"); - QString ImageStr; - int b=0; - int size=buffer.data().size(); - for (int j = 0; j < size; j++) { - b=buffer.data().at(j); - ImageStr += QString("%1").arg(b&0xff, 2, 16, QChar('0')); - } - return ImageStr; -} - -int findmult(float value, float base) -{ - int vvalue = value*10; - int vbase = base*10; - vvalue--; - - int mult = 0; - for (int i=8; i>=0; i--) { - if (vvalue/vbase >= (1<getId()); @@ -754,11 +700,6 @@ QSet getFilesSet(const QString &path, const QStringList &filter, int ma return result; } -bool caseInsensitiveLessThan(const QString &s1, const QString &s2) -{ - return s1.toLower() < s2.toLower(); -} - bool GpsGlitchFilter::isGlitch(GpsCoord coord) { if ((fabs(coord.latitude) < 0.1) && (fabs(coord.longitude) < 0.1)) { diff --git a/companion/src/helpers.h b/companion/src/helpers.h index 47cc12f7c..2891d9573 100644 --- a/companion/src/helpers.h +++ b/companion/src/helpers.h @@ -52,8 +52,6 @@ extern const QColor colors[CPN_MAX_CURVES]; #define TRIM_MODE_NONE 0x1F // 0b11111 -QString getTheme(); - class CompanionIcon: public QIcon { public: CompanionIcon(const QString &baseimage); @@ -146,14 +144,7 @@ namespace Helpers void getFileComboBoxValue(QComboBox * b, char * dest, int length); } // namespace Helpers -// TODO : move to Helpers namespace - -QString image2qstring(QImage image); -int findmult(float value, float base); - -/* FrSky helpers */ -QString getFrSkyAlarmType(int alarm); -QString getFrSkyUnits(int units); +// TODO : move globals to Helpers namespace void startSimulation(QWidget * parent, RadioData & radioData, int modelIdx); @@ -163,14 +154,6 @@ QPixmap makePixMap(const QImage & image); int version2index(const QString & version); const QString index2version(int index); -class QTimeS : public QTime -{ - public: - QTimeS(int s) { int h = s/3600; s %= 3600; int m = s/60; s %=60; setHMS(h, m, s); } - QTimeS(const QTime & q) : QTime(q) {} - int seconds() const { return hour()*3600 + minute()*60 + second(); } -}; - bool qunlink(const QString & fileName); QString generateProcessUniqueTempFileName(const QString & fileName); @@ -179,8 +162,14 @@ bool isTempFileName(const QString & fileName); QString getSoundsPath(const GeneralSettings &generalSettings); QSet getFilesSet(const QString &path, const QStringList &filter, int maxLen); -bool caseInsensitiveLessThan(const QString &s1, const QString &s2); +class QTimeS : public QTime +{ + public: + QTimeS(int s) { int h = s/3600; s %= 3600; int m = s/60; s %=60; setHMS(h, m, s); } + QTimeS(const QTime & q) : QTime(q) {} + int seconds() const { return hour()*3600 + minute()*60 + second(); } +}; class GpsCoord { diff --git a/companion/src/modeledit/telemetry.cpp b/companion/src/modeledit/telemetry.cpp index 4583b539b..c9a0d5c2a 100644 --- a/companion/src/modeledit/telemetry.cpp +++ b/companion/src/modeledit/telemetry.cpp @@ -93,6 +93,23 @@ void TelemetryAnalog::update() ui->CalibSB->setValue(mini); } +static int findmult(float value, float base) +{ + int vvalue = value*10; + int vbase = base*10; + vvalue--; + + int mult = 0; + for (int i=8; i>=0; i--) { + if (vvalue/vbase >= (1<frsky.channels[i].type), 20); + COMPARECELLWIDTH(FrSkyChannelData::unitString(model->frsky.channels[i].type), 20); COMPARECELLWIDTH(QString::number((model->frsky.channels[i].ratio / (model->frsky.channels[i].type==0 ? 10.0 : 1)), 10, (model->frsky.channels[i].type==0 ? 1 : 0)), 20); COMPARECELLWIDTH(QString::number((model->frsky.channels[i].offset*(model->frsky.channels[i].ratio / (model->frsky.channels[i].type==0 ?10.0 : 1)))/255, 10, (model->frsky.channels[i].type==0 ? 1 : 0)), 40); columns.appendRowEnd(); @@ -769,10 +769,10 @@ QString MultiModelPrinter::printTelemetry() { columns.appendRowStart(tr("RSSI Alarms"), 20); columns.appendCellStart(80); - COMPARESTRING("", (IS_ARM(getCurrentBoard()) ? tr("Low") : getFrSkyAlarmType(model->rssiAlarms.level[0])), false); + COMPARESTRING("", (IS_ARM(getCurrentBoard()) ? tr("Low") : FrSkyAlarmData::alarmLevelName(model->rssiAlarms.level[0])), false); columns.append(": "); COMPARESTRING("", QString("< %1").arg(QString::number(model->rssiAlarms.warning, 10)), true); - COMPARESTRING("", (IS_ARM(getCurrentBoard()) ? tr("Critical") : getFrSkyAlarmType(model->rssiAlarms.level[1])), false); + COMPARESTRING("", (IS_ARM(getCurrentBoard()) ? tr("Critical") : FrSkyAlarmData::alarmLevelName(model->rssiAlarms.level[1])), false); columns.append(": "); COMPARESTRING("", QString("< %1").arg(QString::number(model->rssiAlarms.critical, 10)), true); COMPARESTRING(tr("Telemetry audio"), modelPrinter->printRssiAlarmsDisabled(model->rssiAlarms.disabled), false);