* Model Labels Selector * Portrait Layout * Receiver ID Check * Fix Labels .yml format * Companion Initial Commit commit 967ddf3979b4954402fe62c858faba4b7a416bba Author: dlktdr <cblackburn320@gmail.com> Date: Mon Aug 29 01:49:15 2022 -0700 Fix Labels .yml format commit 534221cad9e01146c47a9ac1080a655e04f1f6c8 Author: dlktdr <cblackburn320@gmail.com> Date: Mon Aug 29 01:20:57 2022 -0700 Receiver ID Check commit f32c0939d44e9ae60bc0705a9176354c23fec198 Author: dlktdr <cblackburn320@gmail.com> Date: Sun Aug 28 23:13:25 2022 -0700 Portrait Layout commit 961181217c7841ff3f21299ac6aa419b810f80e9 Author: dlktdr <cblackburn320@gmail.com> Date: Sat Dec 11 16:56:13 2021 -0800 Model Labels Selector commitdc99dd40d2Author: David PHAM-VAN <1387855+DavBfr@users.noreply.github.com> Date: Fri Aug 26 03:04:34 2022 -0300 feat: Allow Lua widget to override built-in widget with same name (#2208) * Allow CPP Widgets Override with LUA * Reset a widget option it the type differs commit4b747caff9Author: eshifri <46511024+eshifri@users.noreply.github.com> Date: Thu Aug 25 19:47:53 2022 -0700 fix: Write model name into models.yml when duplicating model (#2224) * Update model name in the models.yml file (#2214) * Fix the length of the name. commite97f23a305Author: eshifri <46511024+eshifri@users.noreply.github.com> Date: Wed Aug 24 21:19:52 2022 -0700 fix(cpn): Fix full path to model notes for Simulator (#2223) * Correct Highlighted Column * labels .yml indentation * Update da.h New defines translated to Danish * Update dataconstants.h Omit warnings due to difference of LEN_MODEL_FILENAME and LEN_MODEL_NAME in modellist.cpp * Update modelslist.cpp Wonder if this are the right file in PR #1374 (?), seems a lot are changed to the better in #1374 * Update dataconstants.h Restore #define for LEN_MODEL_FILENAME to 16 * Rebase, Correct Issues Delete now deletes instead of select New model stores correct information Duplicate save all information in cell Rework items to use cell over button Reword function variables * CMPN: Add context menu Fix output not functional. Removed Yaml::null at some point :) Fix some compiler warnings * CMPN: Compiler warning, replace ,->_ in list * FW: Various Changes Change view to a grid Don't allow comma in label name Add scroll indicators Save sort order Co-authored-by: HThuren <99370924+HThuren@users.noreply.github.com>
188 lines
5.0 KiB
C++
188 lines
5.0 KiB
C++
/*
|
|
* 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 "comparedialog.h"
|
|
#include "ui_comparedialog.h"
|
|
#include "appdata.h"
|
|
#include "helpers.h"
|
|
#include "modelslist.h"
|
|
#include "styleeditdialog.h"
|
|
#include <QtPrintSupport/QPrinter>
|
|
#include <QtPrintSupport/QPrintDialog>
|
|
|
|
CompareDialog::CompareDialog(QWidget * parent, Firmware * firmware):
|
|
QDialog(parent, Qt::Window),
|
|
multimodelprinter(new MultiModelPrinter(firmware)),
|
|
ui(new Ui::CompareDialog)
|
|
{
|
|
ui->setupUi(this);
|
|
setWindowIcon(CompanionIcon("compare.png"));
|
|
setAcceptDrops(true);
|
|
if (!g.compareWinGeo().isEmpty()) {
|
|
restoreGeometry(g.compareWinGeo());
|
|
}
|
|
}
|
|
|
|
CompareDialog::~CompareDialog()
|
|
{
|
|
delete multimodelprinter;
|
|
delete ui;
|
|
}
|
|
|
|
void CompareDialog::dragMoveEvent(QDragMoveEvent * event)
|
|
{
|
|
if (event->mimeData()->hasFormat("application/x-companion-modeldata")) {
|
|
event->acceptProposedAction();
|
|
}
|
|
else {
|
|
event->ignore();
|
|
}
|
|
}
|
|
|
|
void CompareDialog::dragEnterEvent(QDragEnterEvent * event)
|
|
{
|
|
if (event->mimeData()->hasFormat("application/x-companion-modeldata")) {
|
|
event->acceptProposedAction();
|
|
}
|
|
else {
|
|
event->ignore();
|
|
}
|
|
}
|
|
|
|
void CompareDialog::dragLeaveEvent(QDragLeaveEvent * event)
|
|
{
|
|
event->accept();
|
|
}
|
|
|
|
bool CompareDialog::handleMimeData(const QMimeData * mimeData)
|
|
{
|
|
QVector<ModelData> mList;
|
|
GeneralSettings gs;
|
|
if (!ModelsListModel::decodeMimeData(mimeData, &mList, &gs) || mList.isEmpty())
|
|
return false;
|
|
for (int i=0; i < mList.size(); ++i) {
|
|
GMData data;
|
|
data.model = mList[i];
|
|
data.gs = gs;
|
|
modelsList.append(data);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void CompareDialog::closeEvent(QCloseEvent * event)
|
|
{
|
|
g.compareWinGeo(saveGeometry());
|
|
}
|
|
|
|
void CompareDialog::dropEvent(QDropEvent *event)
|
|
{
|
|
if (handleMimeData(event->mimeData())) {
|
|
event->accept();
|
|
compare();
|
|
}
|
|
}
|
|
|
|
void CompareDialog::compare()
|
|
{
|
|
QLayoutItem *child;
|
|
while ((child = ui->layout_modelNames->takeAt(0))) {
|
|
if (child->widget())
|
|
delete child->widget();
|
|
delete child;
|
|
}
|
|
|
|
multimodelprinter->clearModels();
|
|
ui->textEdit->clear();
|
|
|
|
for (int i=0; i < modelsList.size(); ++i) {
|
|
multimodelprinter->setModel(i, &modelsList[i].model, &modelsList[i].gs);
|
|
QString name(modelsList.at(i).model.name);
|
|
if (name.isEmpty())
|
|
name = tr("Unnamed Model %1").arg(i+1);
|
|
|
|
QWidget * hdr = new QWidget(this);
|
|
hdr->setLayout(new QHBoxLayout());
|
|
hdr->layout()->setContentsMargins(0, 0, 0, 0);
|
|
hdr->layout()->setSpacing(2);
|
|
QToolButton * btn = new QToolButton(hdr);
|
|
btn->setIcon(CompanionIcon("clear.png"));
|
|
btn->setProperty("index", i);
|
|
btn->setFixedSize(18, 18);
|
|
btn->setToolTip(tr("Click to remove this model."));
|
|
hdr->layout()->addWidget(btn);
|
|
QLabel * lbl = new QLabel(name, this);
|
|
lbl->setStyleSheet("font-weight: bold;");
|
|
hdr->layout()->addWidget(lbl);
|
|
connect(btn, &QToolButton::clicked, this, &CompareDialog::removeModelBtnClicked);
|
|
|
|
ui->layout_modelNames->addWidget(hdr);
|
|
}
|
|
if (modelsList.size())
|
|
ui->textEdit->setHtml(multimodelprinter->print(ui->textEdit->document()));
|
|
}
|
|
|
|
void CompareDialog::removeModel(int idx)
|
|
{
|
|
if (idx < modelsList.size()) {
|
|
modelsList.remove(idx);
|
|
compare();
|
|
}
|
|
}
|
|
|
|
void CompareDialog::removeModelBtnClicked()
|
|
{
|
|
if (sender() && sender()->property("index").isValid())
|
|
removeModel(sender()->property("index").toInt());
|
|
}
|
|
|
|
void CompareDialog::on_printButton_clicked()
|
|
{
|
|
QPrinter printer;
|
|
printer.setPageMargins(10.0, 10.0, 10.0, 10.0, printer.Millimeter);
|
|
QPrintDialog * dialog = new QPrintDialog(&printer, this);
|
|
dialog->setWindowTitle(tr("Print Document"));
|
|
if (dialog->exec() != QDialog::Accepted)
|
|
return;
|
|
ui->textEdit->print(&printer);
|
|
}
|
|
|
|
void CompareDialog::on_printFileButton_clicked()
|
|
{
|
|
QPrinter printer;
|
|
QString filename = QFileDialog::getSaveFileName(this, tr("Select PDF output file"), QString(), "Pdf File(*.pdf)");
|
|
printer.setPageMargins(10.0, 10.0, 10.0, 10.0, printer.Millimeter);
|
|
printer.setOutputFormat(QPrinter::PdfFormat);
|
|
printer.setOrientation(QPrinter::Landscape);
|
|
printer.setColorMode(QPrinter::Color);
|
|
if (!filename.isEmpty()) {
|
|
if (QFileInfo(filename).suffix().isEmpty())
|
|
filename.append(".pdf");
|
|
printer.setOutputFileName(filename);
|
|
ui->textEdit->print(&printer);
|
|
}
|
|
}
|
|
|
|
void CompareDialog::on_styleButton_clicked()
|
|
{
|
|
StyleEditDialog *g = new StyleEditDialog(this, MODEL_PRINT_CSS);
|
|
if (g->exec() == QDialog::Accepted)
|
|
compare();
|
|
}
|