From 2f91eba85de2f0a0dadc3add6f4bbe04b14c8c61 Mon Sep 17 00:00:00 2001 From: Neil Horne Date: Mon, 21 May 2018 18:07:49 +1000 Subject: [PATCH] Model print and compare user customisable style (#5866) * New feature: Model print and compare customisable style * Layout cosmetics. * File handling tweak Message cosmetics --- companion/src/CMakeLists.txt | 4 + companion/src/companion.qrc | 1 + companion/src/comparedialog.cpp | 8 ++ companion/src/comparedialog.h | 1 + companion/src/comparedialog.ui | 10 ++ companion/src/helpers_html.cpp | 147 ++++++++++++++++++++++ companion/src/helpers_html.h | 40 +++++- companion/src/multimodelprinter.cpp | 120 ++++++++---------- companion/src/multimodelprinter.h | 2 +- companion/src/printdialog.cpp | 14 ++- companion/src/printdialog.h | 7 +- companion/src/printdialog.ui | 7 ++ companion/src/styleeditdialog.cpp | 73 +++++++++++ companion/src/styleeditdialog.h | 50 ++++++++ companion/src/styleeditdialog.ui | 146 +++++++++++++++++++++ companion/src/themes/default/modelprt.css | 71 +++++++++++ 16 files changed, 624 insertions(+), 77 deletions(-) create mode 100644 companion/src/styleeditdialog.cpp create mode 100644 companion/src/styleeditdialog.h create mode 100644 companion/src/styleeditdialog.ui create mode 100644 companion/src/themes/default/modelprt.css diff --git a/companion/src/CMakeLists.txt b/companion/src/CMakeLists.txt index 9343d71b9..f9ad14463 100644 --- a/companion/src/CMakeLists.txt +++ b/companion/src/CMakeLists.txt @@ -244,6 +244,7 @@ set(companion_SRCS radionotfound.cpp wizarddata.cpp wizarddialog.cpp + styleeditdialog.cpp ) set(companion_MOC_HDRS @@ -275,6 +276,8 @@ set(companion_MOC_HDRS modelprinter.h multimodelprinter.h modelslist.h + styleeditdialog.h + helpers_html.h ) set(companion_UIS @@ -295,6 +298,7 @@ set(companion_UIS flashfirmwaredialog.ui flasheepromdialog.ui radionotfound.ui + styleeditdialog.ui ) if(WIN32) diff --git a/companion/src/companion.qrc b/companion/src/companion.qrc index c3088a53e..6c8d9e4e9 100644 --- a/companion/src/companion.qrc +++ b/companion/src/companion.qrc @@ -235,6 +235,7 @@ images/library/10802.png themes/default/style.css themes/default/style-osx.css + themes/default/modelprt.css themes/monochrome/16/paintbrush.png themes/monochrome/16/open.png themes/monochrome/16/edit.png diff --git a/companion/src/comparedialog.cpp b/companion/src/comparedialog.cpp index 1fc7a743d..4897f74ba 100644 --- a/companion/src/comparedialog.cpp +++ b/companion/src/comparedialog.cpp @@ -23,6 +23,7 @@ #include "appdata.h" #include "helpers.h" #include "modelslist.h" +#include "styleeditdialog.h" #include #include @@ -189,3 +190,10 @@ void CompareDialog::on_printFileButton_clicked() ui->textEdit->print(&printer); } } + +void CompareDialog::on_styleButton_clicked() +{ + StyleEditDialog *g = new StyleEditDialog(this, MODEL_PRINT_CSS); + if (g->exec() == QDialog::Accepted) + compare(); +} diff --git a/companion/src/comparedialog.h b/companion/src/comparedialog.h index 03e709360..c9da983fa 100644 --- a/companion/src/comparedialog.h +++ b/companion/src/comparedialog.h @@ -51,6 +51,7 @@ class CompareDialog : public QDialog void removeModelBtnClicked(); void on_printButton_clicked(); void on_printFileButton_clicked(); + void on_styleButton_clicked(); protected: virtual void closeEvent(QCloseEvent * event); diff --git a/companion/src/comparedialog.ui b/companion/src/comparedialog.ui index ba4d24c81..b05e6075e 100644 --- a/companion/src/comparedialog.ui +++ b/companion/src/comparedialog.ui @@ -43,6 +43,9 @@ To compare models, drag and drop them anywhere in this window. + + true + @@ -65,6 +68,13 @@ + + + + Style + + + diff --git a/companion/src/helpers_html.cpp b/companion/src/helpers_html.cpp index 9625b8818..f417e0dff 100644 --- a/companion/src/helpers_html.cpp +++ b/companion/src/helpers_html.cpp @@ -18,7 +18,12 @@ * GNU General Public License for more details. */ +#include "helpers.h" #include "helpers_html.h" +#include +#include +#include +#include QString tdAlign(const QString & s, const QString & align, const QString & color, bool bold) { @@ -80,3 +85,145 @@ QString doTableBlankRow() { return ""; } + +Stylesheet::Stylesheet(const QString & name): + mName(name) +{ + init(); +} + +Stylesheet::Stylesheet(const QString & name, const StyleType styleType): + mName(name) +{ + init(); + mResult = load(styleType); +} + +Stylesheet::~Stylesheet() +{ +} + +void Stylesheet::init() +{ + mResult = false; + mErrormsg = ""; + mText = ""; + QStringList p = QStandardPaths::standardLocations(QStandardPaths::AppDataLocation); + mCustomPath = p[0]; + mCustomFile = p[0] + "/" + mName; + mDefaultFile = THEMES_DEFAULT_PATH + mName; +} + +bool Stylesheet::load(const StyleType styleType) +{ + mResult = false; + switch (styleType) { + case STYLE_TYPE_NONE: + case STYLE_TYPE_DEFAULT: + mResult = read(mDefaultFile); + case STYLE_TYPE_CUSTOM: + mResult = read(mCustomFile); + case STYLE_TYPE_EFFECTIVE: + mResult = read(mCustomFile); + if(!mResult) + mResult = read(mDefaultFile); + } + return mResult; +} + +bool Stylesheet::read(const QString & path) +{ + mResult = false; + mText = ""; + + QFile file(path); + if (file.exists()) { + if (file.open(QFile::ReadOnly | QFile::Text)) { + QTextStream in(&file); + if (in.status()==QTextStream::Ok) { + mText = in.readAll(); + if (in.status()==QTextStream::Ok) + mResult = true; + else + mText = ""; + } + file.close(); + } + } + if (mResult) + mErrormsg = tr("Style sheet data read from '%1'").arg(QDir::toNativeSeparators(path)); + else + mErrormsg = tr("Style sheet data unable to be read from '%1'").arg(QDir::toNativeSeparators(path)); + qDebug() << mErrormsg; + return mResult; +} + +bool Stylesheet::update() +{ + mResult = false; + mErrormsg = ""; + QDir path(mCustomPath); + if (!path.exists()) { + QDir dir; + if (!dir.mkpath(mCustomPath)) + mErrormsg = tr("Cannot create folder '%1'").arg(QDir::toNativeSeparators(mCustomPath)); + } + if (path.exists()) { + QFile file(mCustomFile); + if (!file.open(QFile::WriteOnly | QFile::Text)) { + mErrormsg = tr("Cannot open file for writing '%1': Error: %2").arg(QDir::toNativeSeparators(mCustomFile), file.errorString()); + } + else { + QTextStream out(&file); + if (out.status()==QTextStream::Ok) { + out << mText; + if (!(out.status()==QTextStream::Ok)) { + mErrormsg = tr("Cannot write to file '%1': Error: %2").arg(QDir::toNativeSeparators(mCustomFile), file.errorString()); + if (!file.flush()) { + mErrormsg = tr("Cannot flush buffer for file '%1': Error: %2").arg(QDir::toNativeSeparators(mCustomFile), file.errorString()); + } + } + else { + mResult = true; + mErrormsg = tr("Style sheet written to '%1'").arg(QDir::toNativeSeparators(mCustomFile)); + } + } + } + file.close(); + } + qDebug() << mErrormsg; + return mResult; +} + +bool Stylesheet::deleteCustom() +{ + QFile file(mCustomFile); + mResult = file.remove(); + if (mResult) + mErrormsg = tr("Custom style sheet deleted: '%1'").arg(QDir::toNativeSeparators(mCustomFile)); + else + mErrormsg = tr("Unable to delete custom style sheet: '%1'").arg(QDir::toNativeSeparators(mCustomFile)); + qDebug() << mErrormsg; + return mResult; +} + +QString Stylesheet::name() +{ + return mName; +} + +QString Stylesheet::text() +{ + return mText; +} + +void Stylesheet::setText(const QString & text) +{ + mText = text; +} + +QString Stylesheet::errormsg() +{ + return mErrormsg; +} + diff --git a/companion/src/helpers_html.h b/companion/src/helpers_html.h index e126624e9..2c0f54169 100644 --- a/companion/src/helpers_html.h +++ b/companion/src/helpers_html.h @@ -21,8 +21,11 @@ #ifndef _HELPERS_HTML_H_ #define _HELPERS_HTML_H_ +#include #include -#include + +#define THEMES_DEFAULT_PATH ":/themes/default/" +#define MODEL_PRINT_CSS "modelprt.css" QString tdAlign(const QString & s, const QString & align, const QString & color, bool bold); QString doTC(const QString & s, const QString & color = "", bool bold = false); @@ -33,4 +36,39 @@ QString doTableCell(const QString & s, const unsigned int width = 0, const QStri QString doTableRow(const QStringList & strl, const unsigned int width = 0, const QString & align = "", const QString & color = "", bool bold = false); QString doTableBlankRow(); +class Stylesheet: public QObject +{ + Q_OBJECT + + public: + enum StyleType { + STYLE_TYPE_NONE, + STYLE_TYPE_DEFAULT, + STYLE_TYPE_CUSTOM, + STYLE_TYPE_EFFECTIVE + }; + + Stylesheet(const QString & name); + Stylesheet(const QString & name, const StyleType styleType); + ~Stylesheet(); + bool load(const StyleType styleType); + bool update(); + bool deleteCustom(); + QString name(); + QString text(); + QString errormsg(); + void setText(const QString & text); + + private: + bool mResult; + QString mErrormsg; + QString mName; + QString mText; + QString mCustomFile; + QString mCustomPath; + QString mDefaultFile; + void init(); + bool read(const QString & filepath); +}; + #endif // _HELPERS_HTML_H_ diff --git a/companion/src/multimodelprinter.cpp b/companion/src/multimodelprinter.cpp index a198432bc..0233c9ef0 100644 --- a/companion/src/multimodelprinter.cpp +++ b/companion/src/multimodelprinter.cpp @@ -61,43 +61,18 @@ void MultiModelPrinter::MultiColumns::beginCompare() compareColumns = new QString[count]; } -void MultiModelPrinter::MultiColumns::endCompare(const QString & color) +void MultiModelPrinter::MultiColumns::endCompare() { for (int i=0; i1 && 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; +*/ +} +