1 && compareColumns[0]!=compareColumns[1])
- cellColor = "green";
+ style = "mpc-diff1";
else if (i>0 && compareColumns[i]!=compareColumns[0])
- cellColor = "red";
- // font instructions must be applied at table cell level if they exist in the comparison string
- if (compareColumns[i].indexOf(QString("| -1) {
- QString t = compareColumns[i];
- int p1 = 0;
- int p2 = 0;
- int p3 = 0;
- while (t.indexOf(QString(" | -1) {
- p1 = t.indexOf(QString(" | "), p1 + 3);
- p3 = t.indexOf(QString(" | "), p2 + 1);
- QString td = t.mid(p2 + 1, p3 - (p2 + 1));
- // remove existing font instructions from current cell
- if (td.contains(QString(""), p4) + 6;
- if (p5 < p3)
- t.remove(p4, p5 - p4 + 1);
- }
- t.insert(p2 + 1, QString("").arg(cellColor));
- p3 = t.indexOf(QString(""), p2);
- t.insert(p3, QString(""));
- p1 = p3 + QString("").size();
- }
- compareColumns[i] = t;
- columns[i].append(QString("%1").arg(compareColumns[i]));
- }
- else {
- columns[i].append(QString("%2").arg(cellColor).arg(compareColumns[i]));
- }
+ style = "mpc-diff2";
+ if (style!="")
+ columns[i].append(QString("%2").arg(style).arg(compareColumns[i]));
+ else
+ columns[i].append(compareColumns[i]);
}
delete[] compareColumns;
compareColumns = NULL;
@@ -250,7 +225,7 @@ void MultiModelPrinter::MultiColumns::appendFieldSeparator(const bool sep)
QString MultiModelPrinter::printTitle(const QString & label)
{
- return QString("").arg(modelPrinterMap.count()) + label + " |
";
+ return QString("| ").arg(modelPrinterMap.count()) + label + " |
";
}
MultiModelPrinter::MultiModelPrinter(Firmware * firmware):
@@ -292,8 +267,10 @@ void MultiModelPrinter::clearModels()
QString MultiModelPrinter::print(QTextDocument * document)
{
if (document) document->clear();
-
- QString str = "";
+ Stylesheet css(MODEL_PRINT_CSS);
+ if (css.load(Stylesheet::StyleType::STYLE_TYPE_EFFECTIVE))
+ document->setDefaultStyleSheet(css.text());
+ QString str = ""; // attributes not settable via QT stylesheet
str.append(printSetup());
if (firmware->getCapability(Timers)) {
str.append(printTimers());
@@ -328,7 +305,7 @@ QString MultiModelPrinter::printSetup()
MultiColumns columns(modelPrinterMap.size());
columns.appendSectionTableStart();
- ROWLABELCOMPARECELL(tr("Name"), 25, model->name, 75);
+ ROWLABELCOMPARECELL(tr("Name"), 20, model->name, 80);
ROWLABELCOMPARECELL(tr("EEprom Size"), 0, modelPrinter->printEEpromSize(), 0);
if (firmware->getCapability(ModelImage)) {
ROWLABELCOMPARECELL(tr("Model Image"), 0, model->bitmap, 0);
@@ -351,18 +328,18 @@ QString MultiModelPrinter::printTimers()
QString str;
MultiColumns columns(modelPrinterMap.size());
columns.appendSectionTableStart();
- columns.appendRowHeader(QStringList() << tr("Timers") << tr("Time") << tr("Switch") << tr("Countdown") << tr("Minute call") << tr("Persistence"));
+ columns.appendRowHeader(QStringList() << tr("Timers") << tr("Time") << tr("Switch") << tr("Countdown") << tr("Min.call") << tr("Persist"));
for (int i=0; igetCapability(Timers); i++) {
columns.appendRowStart();
columns.appendCellStart(20, true);
COMPARE(modelPrinter->printTimerName(i));
columns.appendCellEnd(true);
- COMPARECELL(modelPrinter->printTimerTimeValue(model->timers[i].val));
- COMPARECELL(model->timers[i].mode.toString());
- COMPARECELL(modelPrinter->printTimerCountdownBeep(model->timers[i].countdownBeep));
- COMPARECELL(modelPrinter->printTimerMinuteBeep(model->timers[i].minuteBeep));
- COMPARECELL(modelPrinter->printTimerPersistent(model->timers[i].persistent));
+ COMPARECELLWIDTH(modelPrinter->printTimerTimeValue(model->timers[i].val), 15);
+ COMPARECELLWIDTH(model->timers[i].mode.toString(), 15);
+ COMPARECELLWIDTH(modelPrinter->printTimerCountdownBeep(model->timers[i].countdownBeep), 15);
+ COMPARECELLWIDTH(modelPrinter->printTimerMinuteBeep(model->timers[i].minuteBeep), 15);
+ COMPARECELLWIDTH(modelPrinter->printTimerPersistent(model->timers[i].persistent), 20);
columns.appendRowEnd();
}
columns.appendTableEnd();
@@ -377,10 +354,10 @@ QString MultiModelPrinter::printModules()
columns.appendSectionTableStart();
for (int i=0; igetCapability(NumModules); i++) {
columns.appendRowStart();
- columns.appendCellStart(25, true);
+ columns.appendCellStart(20, true);
COMPARE(modelPrinter->printModuleType(i));
columns.appendCellEnd(true);
- COMPARECELLWIDTH(modelPrinter->printModule(i), 75);
+ COMPARECELLWIDTH(modelPrinter->printModule(i), 80);
columns.appendRowEnd();
}
if (firmware->getCapability(ModelTrainerEnable))
@@ -439,22 +416,22 @@ QString MultiModelPrinter::printFlightModes()
{
MultiColumns columns(modelPrinterMap.size());
columns.appendSectionTableStart();
- QStringList hd = QStringList() << tr("Flight mode") << tr("Switch") << tr("Fade IN") << tr("Fade OUT");
+ QStringList hd = QStringList() << tr("Flight mode") << tr("Switch") << tr("F.In") << tr("F.Out");
for (int i=0; i < getBoardCapability(getCurrentBoard(), Board::NumTrims); i++) {
hd << RawSource(SOURCE_TYPE_TRIM, i).toString();
}
columns.appendRowHeader(hd);
-
+ int wd = 80/(getBoardCapability(getCurrentBoard(), Board::NumTrims) + 3);
for (int i=0; igetCapability(FlightModes); i++) {
columns.appendRowStart();
- columns.appendCellStart(0,true);
+ columns.appendCellStart(20,true);
COMPARE(modelPrinter->printFlightModeName(i));
columns.appendCellEnd(true);
- COMPARECELL(modelPrinter->printFlightModeSwitch(model->flightModeData[i].swtch));
- COMPARECELL(model->flightModeData[i].fadeIn);
- COMPARECELL(model->flightModeData[i].fadeOut);
+ COMPARECELLWIDTH(modelPrinter->printFlightModeSwitch(model->flightModeData[i].swtch), wd);
+ COMPARECELLWIDTH(model->flightModeData[i].fadeIn, wd);
+ COMPARECELLWIDTH(model->flightModeData[i].fadeOut, wd);
for (int k=0; k < getBoardCapability(getCurrentBoard(), Board::NumTrims); k++) {
- COMPARECELL(modelPrinter->printTrim(i, k));
+ COMPARECELLWIDTH(modelPrinter->printTrim(i, k), wd);
}
columns.appendRowEnd();
}
@@ -468,7 +445,7 @@ QString MultiModelPrinter::printFlightModes()
if ((gvars && firmware->getCapability(GvarsFlightModes)) || firmware->getCapability(RotaryEncoders)) {
MultiColumns columns(modelPrinterMap.size());
columns.appendSectionTableStart();
- QStringList hd = QStringList() << tr("Global variables");
+ QStringList hd = QStringList() << tr("Global vars");
if (firmware->getCapability(GvarsFlightModes)) {
for (int i=0; igetCapability(GvarsFlightModes)) {
- columns.appendRowStart(tr("Name"));
+ columns.appendRowStart(tr("Name"), 20);
for (int i=0; igvarData[i].name);
+ COMPARECELLWIDTH(model->gvarData[i].name, wd);
}
columns.appendRowEnd();
columns.appendRowStart(tr("Unit"));
@@ -549,7 +526,14 @@ QString MultiModelPrinter::printOutputs()
if (firmware->getCapability(SYMLimits))
hd << tr("Linear");
columns.appendRowHeader(hd);
-
+ int cols = 4;
+ if (IS_HORUS_OR_TARANIS(firmware->getBoard()))
+ cols++;
+ if (firmware->getCapability(PPMCenter))
+ cols++;
+ if (firmware->getCapability(SYMLimits))
+ cols++;
+ int wd = 80/cols;
for (int i=0; igetCapability(Outputs); i++) {
int count = 0;
for (int k=0; k < modelPrinterMap.size(); k++)
@@ -557,21 +541,21 @@ QString MultiModelPrinter::printOutputs()
if (!count)
continue;
columns.appendRowStart();
- columns.appendCellStart(0, true);
+ columns.appendCellStart(20, true);
COMPARE(modelPrinter->printChannelName(i));
columns.appendCellEnd(true);
- COMPARECELL(modelPrinter->printOutputOffset(i));
- COMPARECELL(modelPrinter->printOutputMin(i));
- COMPARECELL(modelPrinter->printOutputMax(i));
- COMPARECELL(modelPrinter->printOutputRevert(i));
+ COMPARECELLWIDTH(modelPrinter->printOutputOffset(i), wd);
+ COMPARECELLWIDTH(modelPrinter->printOutputMin(i), wd);
+ COMPARECELLWIDTH(modelPrinter->printOutputMax(i), wd);
+ COMPARECELLWIDTH(modelPrinter->printOutputRevert(i), wd);
if (IS_HORUS_OR_TARANIS(firmware->getBoard())) {
- COMPARECELL(modelPrinter->printOutputCurve(i));
+ COMPARECELLWIDTH(modelPrinter->printOutputCurve(i), wd);
}
if (firmware->getCapability(PPMCenter)) {
- COMPARECELL(modelPrinter->printOutputPpmCenter(i));
+ COMPARECELLWIDTH(modelPrinter->printOutputPpmCenter(i), wd);
}
if (firmware->getCapability(SYMLimits)) {
- COMPARECELL(modelPrinter->printOutputSymetrical(i));
+ COMPARECELLWIDTH(modelPrinter->printOutputSymetrical(i), wd);
}
columns.appendRowEnd();
}
@@ -875,7 +859,6 @@ QString MultiModelPrinter::printSensors()
int count = 0;
columns.appendSectionTableStart();
columns.appendRowHeader(QStringList() << tr("Name") << tr("Type") << tr("Parameters"));
- //columns.appendRowHeader(QStringList() << tr("Name") << tr("Type") << tr("Formula/Source") << tr("Unit") << tr("Prec") << tr("Ratio") << tr("Ofst") << tr("A.Ofst") << tr("Fltr") << tr("Pers.") << tr("+ve") << tr("Log"));
for (int i=0; isensorData[i].nameToString(i));
columns.appendCellEnd(true);
COMPARECELLWIDTH(modelPrinter->printSensorTypeCond(i), 15);
- COMPARECELLWIDTH(modelPrinter->printSensorParams(i), 70);
- //COMPARESTRING("", modelPrinter->printSensorDetails(i), 0);
+ COMPARECELLWIDTH(modelPrinter->printSensorParams(i), 65);
columns.appendRowEnd();
}
}
diff --git a/companion/src/multimodelprinter.h b/companion/src/multimodelprinter.h
index f5a0f609d..a00e5d4e3 100644
--- a/companion/src/multimodelprinter.h
+++ b/companion/src/multimodelprinter.h
@@ -51,7 +51,7 @@ class MultiModelPrinter: public QObject
void append(int idx, const QString & str);
template void append(int idx, T val);
void beginCompare();
- void endCompare(const QString & color = "black"); // was grey
+ void endCompare();
void appendLineBreak();
void appendSectionTableStart();
void appendTableEnd();
diff --git a/companion/src/printdialog.cpp b/companion/src/printdialog.cpp
index 8ea8d0525..decd83ae4 100644
--- a/companion/src/printdialog.cpp
+++ b/companion/src/printdialog.cpp
@@ -21,6 +21,7 @@
#include "printdialog.h"
#include "ui_printdialog.h"
#include "helpers.h"
+#include "styleeditdialog.h"
#include
#include
@@ -31,13 +32,13 @@ PrintDialog::PrintDialog(QWidget *parent, Firmware * firmware, GeneralSettings &
model(model),
printfilename(filename),
ui(new Ui::PrintDialog),
- multimodelprinter(firmware)
+ multiModelPrinter(firmware)
{
ui->setupUi(this);
setWindowIcon(CompanionIcon("print.png"));
setWindowTitle(model.name);
- multimodelprinter.setModel(0, &model, &generalSettings);
- ui->textEdit->setHtml(multimodelprinter.print(ui->textEdit->document()));
+ multiModelPrinter.setModel(0, &model, &generalSettings);
+ ui->textEdit->setHtml(multiModelPrinter.print(ui->textEdit->document()));
if (!printfilename.isEmpty()) {
printToFile();
QTimer::singleShot(0, this, SLOT(autoClose()));
@@ -109,3 +110,10 @@ void PrintDialog::autoClose()
{
this->close();
}
+
+void PrintDialog::on_styleButton_clicked()
+{
+ StyleEditDialog *g = new StyleEditDialog(this, MODEL_PRINT_CSS);
+ if (g->exec() == QDialog::Accepted)
+ ui->textEdit->setHtml(multiModelPrinter.print(ui->textEdit->document()));
+}
diff --git a/companion/src/printdialog.h b/companion/src/printdialog.h
index 31fca1438..eb28d0975 100644
--- a/companion/src/printdialog.h
+++ b/companion/src/printdialog.h
@@ -31,13 +31,13 @@ namespace Ui {
class PrintDialog : public QDialog
{
- Q_OBJECT
+ Q_OBJECT
public:
PrintDialog(QWidget * parent, Firmware * firmware, GeneralSettings & generalSettings, ModelData & model, const QString & filename="");
~PrintDialog();
void closeEvent(QCloseEvent * event);
-
+
Firmware * firmware;
GeneralSettings & generalSettings;
ModelData & model;
@@ -46,7 +46,7 @@ class PrintDialog : public QDialog
protected:
Ui::PrintDialog *ui;
- MultiModelPrinter multimodelprinter; // TODO multimodelPrinter
+ MultiModelPrinter multiModelPrinter;
void printToFile();
@@ -54,6 +54,7 @@ class PrintDialog : public QDialog
void on_printButton_clicked();
void on_printFileButton_clicked();
void autoClose();
+ void on_styleButton_clicked();
};
#endif // _PRINTDIALOG_H_
diff --git a/companion/src/printdialog.ui b/companion/src/printdialog.ui
index 20e2a7b63..719d8377d 100644
--- a/companion/src/printdialog.ui
+++ b/companion/src/printdialog.ui
@@ -55,6 +55,13 @@
+ -
+
+
+ Style
+
+
+
-
diff --git a/companion/src/styleeditdialog.cpp b/companion/src/styleeditdialog.cpp
new file mode 100644
index 000000000..a1032b91b
--- /dev/null
+++ b/companion/src/styleeditdialog.cpp
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) OpenTX
+ *
+ * Based on code named
+ * th9x - http://code.google.com/p/th9x
+ * er9x - http://code.google.com/p/er9x
+ * gruvin9x - http://code.google.com/p/gruvin9x
+ *
+ * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include "styleeditdialog.h"
+#include "ui_styleeditdialog.h"
+#include "helpers.h"
+
+StyleEditDialog::StyleEditDialog(QWidget * parent, const QString stylesheet):
+ QDialog(parent),
+ ui(new Ui::StyleEditDialog),
+ mStylesheet(stylesheet),
+ mDirty(false)
+{
+ ui->setupUi(this);
+ setWindowIcon(CompanionIcon("edit.png"));
+ if (!mStylesheet.load(Stylesheet::StyleType::STYLE_TYPE_EFFECTIVE))
+ QMessageBox::critical(this, tr("Style Sheet Editor"), tr("Cannot retrieve style %1\nError: %2").arg(mStylesheet.name(), mStylesheet.errormsg()));
+ QFont f;
+ f.setFamily("monospace");
+ f.setPointSize(10);
+ ui->pteStyle->setFont(f);
+ ui->pteStyle->setPlainText(mStylesheet.text());
+ connect(ui->pteStyle, SIGNAL(textChanged()), this, SLOT(changed()));
+ connect(ui->pbDefault, SIGNAL(clicked()), this, SLOT(resetToDefault()));
+ connect(ui->pbCancel, SIGNAL(clicked()), this, SLOT(reject()));
+ connect(ui->pbOK, SIGNAL(clicked()), this, SLOT(update()));
+}
+
+StyleEditDialog::~StyleEditDialog()
+{
+ delete ui;
+}
+
+void StyleEditDialog::changed()
+{
+ mDirty = true;
+}
+
+void StyleEditDialog::resetToDefault()
+{
+ mStylesheet.deleteCustom(); // ignore result
+ if (!mStylesheet.load(Stylesheet::StyleType::STYLE_TYPE_DEFAULT))
+ QMessageBox::critical(this, tr("Style Sheet Editor"), tr("Cannot retrieve default style %1\nError: %2").arg(mStylesheet.name(), mStylesheet.errormsg()));
+ ui->pteStyle->setPlainText(mStylesheet.text());
+ mDirty = false;
+}
+
+void StyleEditDialog::update()
+{
+ if (mDirty) {
+ mStylesheet.setText(ui->pteStyle->toPlainText());
+ if (!mStylesheet.update())
+ QMessageBox::critical(this, tr("Style Sheet Editor"), tr("Cannot update custom style %1\nError: %2").arg(mStylesheet.name(), mStylesheet.errormsg()));
+ }
+ emit accept();
+}
diff --git a/companion/src/styleeditdialog.h b/companion/src/styleeditdialog.h
new file mode 100644
index 000000000..d66c54602
--- /dev/null
+++ b/companion/src/styleeditdialog.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) OpenTX
+ *
+ * Based on code named
+ * th9x - http://code.google.com/p/th9x
+ * er9x - http://code.google.com/p/er9x
+ * gruvin9x - http://code.google.com/p/gruvin9x
+ *
+ * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _STYLEEDITDIALOG_H_
+#define _STYLEEDITDIALOG_H_
+
+#include "helpers_html.h"
+#include
+
+namespace Ui {
+ class StyleEditDialog;
+}
+
+class StyleEditDialog : public QDialog
+{
+ Q_OBJECT
+
+ public:
+ StyleEditDialog(QWidget * parent, const QString stylesheet);
+ ~StyleEditDialog();
+
+ private slots:
+ void update();
+ void changed();
+ void resetToDefault();
+
+ private:
+ Ui::StyleEditDialog *ui;
+ Stylesheet mStylesheet;
+ bool mDirty;
+};
+
+#endif // _STYLEEDITDIALOG_H_
diff --git a/companion/src/styleeditdialog.ui b/companion/src/styleeditdialog.ui
new file mode 100644
index 000000000..7a9c1dd7d
--- /dev/null
+++ b/companion/src/styleeditdialog.ui
@@ -0,0 +1,146 @@
+
+
+ StyleEditDialog
+
+
+
+ 0
+ 0
+ 630
+ 373
+
+
+
+ Style Sheet Editor
+
+
+
-
+
+
+ Qt::Vertical
+
+
+ QSizePolicy::Fixed
+
+
+
+ 20
+ 3
+
+
+
+
+ -
+
+
+
+ 0
+ 1
+
+
+
+ Qt::ScrollBarAsNeeded
+
+
+ Qt::ScrollBarAsNeeded
+
+
+ true
+
+
+ QPlainTextEdit::NoWrap
+
+
+
+ -
+
+
+ 6
+
+
+ QLayout::SetMinimumSize
+
+
-
+
+
+ Qt::Horizontal
+
+
+ QSizePolicy::Expanding
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ &Reset to default
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ &Cancel
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ &OK
+
+
+
+
+
+ false
+
+
+
+
+
+ -
+
+
+ This feature does not validate your changes and assumes you are familiar with CSS syntax for QT.
+
+
+ true
+
+
+
+
+
+
+ pteStyle
+ pbOK
+ pbCancel
+ pbDefault
+
+
+
+
diff --git a/companion/src/themes/default/modelprt.css b/companion/src/themes/default/modelprt.css
new file mode 100644
index 000000000..3c2b83c0b
--- /dev/null
+++ b/companion/src/themes/default/modelprt.css
@@ -0,0 +1,71 @@
+/*
+ User by Model Print and Compare
+
+ QT 5
+ 1. Supports a subset of the HTML 4 and CSS 2.1 standards
+ 2. Translates css to inline HTML which can lead to unexpected formatting
+
+ Reference Official QT 5 website https://doc.qt.io/qt-5/
+*/
+
+/* overide environment defaults */
+p, table, td, th {
+ font-family: monospace;
+ font-size: 15px;
+ color: black;
+ font-style: normal;
+ font-weight: normal;
+}
+
+table {
+ border-style: solid;
+ border-color: grey;
+ border-width: 1px;
+}
+
+td, th {
+ margin: 0px;
+ padding: 1px;
+}
+
+/* The style applied to section titles */
+.mpc-section-title {
+ color: black;
+ background-color: white;
+ font-size: 20px;
+ font-style: normal;
+ font-weight: bold;
+}
+
+/*
+ These model compare differences style classes inherit field classes above
+
+ Notes:
+ 1. The class is applied as some content
+ 2. It is strongly recommended customisation is limited to font attributes
+*/
+
+/* model 1 */
+.mpc-diff1 {
+ color: green;
+/*
+ font-weight: bold;
+ font-style: normal;
+ font-weight: normal;
+ text-decoration: none;
+ background-color: white;
+*/
+}
+
+/* model 2 */
+.mpc-diff2 {
+ color: red;
+/*
+ font-weight: bold;
+ font-style: normal;
+ font-weight: normal;
+ text-decoration: none;
+ background-color: white;
+*/
+}
+