* [Windows][MinGW] Update some WIN32 macro checks in source code to be MSVC-specific (not needed for GCC-based builds).
* [build] CMakeLists updates:
Adjust for Windows MinGW builds: now fully compatible with Qt5.5+ and MinGW-w64 toolchain (included in Qt installs);
Add option to specify path to required libraries/includes (instead of hard-coding `c:\programs`);
Add package check for Python and use found executable name;
Remove custom FindSdl package handler in favor of stock (and improved) CMake one (still works with Windows);
Do not force SIMU_AUDIO and LUA_COMPILER in SIMU builds (leave it up to user);
Add SIMU_LUA_COMPILER option specifically for SIMU builds (default = ON);
* [build][Windows] Rewrite/Fix Windows Companion `install` target, with two options:
a) just copy supporting Qt and c++ DLLs to build folder so programs can be quickly be run from there (this is default and similar to the old behavior);
b) full installation to CMAKE_INSTALL_PREFIX path, including all binaries, supporting DLLs, language files, and OTx utilities.
Option b) can be selected with new WIN_DO_FULL_INSTALL parameter;
Also cleans up the Linux install a bit and consolidates the OS X parts;
* [simulator][Windows] Add option to build Windows simulator with system console/terminal enabled (both standalone and when launched from Companion). Mostly useful for debug as it gives output messages much sooner in the startup process than the current debug console. Also helpful because you don't have to open it manually on every launch, and it remembers last window position and size. Possible candidate for a user-selectable runtime option in the future.
* [Windows] Fix MSVC build issues.
* [build] More build fixes:
Use a customized FindSDL.cmake script again due to bugs and deficiencies in the official version (based on script from CMake v3.7);
Fixes missing SDL DLL error in NSIS installer);
Use string for Timers option (checkbox in GUI is confusing);
Remove an unused variable.
* [simu][Windows] Fix f_getcwd() cutting off too many characters (fixes SD browser interactions).
159 lines
4.4 KiB
C++
159 lines
4.4 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 "helpers.h"
|
|
#include <QPrinter>
|
|
#include <QPrintDialog>
|
|
|
|
class DragDropHeader {
|
|
public:
|
|
DragDropHeader():
|
|
general_settings(false),
|
|
models_count(0)
|
|
{
|
|
}
|
|
bool general_settings;
|
|
uint8_t models_count;
|
|
uint8_t models[CPN_MAX_MODELS];
|
|
};
|
|
|
|
CompareDialog::CompareDialog(QWidget * parent, Firmware * firmware):
|
|
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
|
multimodelprinter(firmware),
|
|
model1Valid(false),
|
|
model2Valid(false),
|
|
ui(new Ui::CompareDialog)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
setWindowIcon(CompanionIcon("compare.png"));
|
|
setAcceptDrops(true);
|
|
|
|
//setDragDropOverwriteMode(true);
|
|
//setDropIndicatorShown(true);
|
|
// TODO scroll to top ... ui->textEdit->scrollToAnchor("1");
|
|
}
|
|
|
|
void CompareDialog::dragMoveEvent(QDragMoveEvent * event)
|
|
{
|
|
if (event->mimeData()->hasFormat("application/x-companion")) {
|
|
event->acceptProposedAction();
|
|
}
|
|
else {
|
|
event->ignore();
|
|
}
|
|
}
|
|
|
|
void CompareDialog::dragEnterEvent(QDragEnterEvent * event)
|
|
{
|
|
// accept just text/uri-list mime format
|
|
if (event->mimeData()->hasFormat("application/x-companion")) {
|
|
event->acceptProposedAction();
|
|
}
|
|
else {
|
|
event->ignore();
|
|
}
|
|
}
|
|
|
|
void CompareDialog::dragLeaveEvent(QDragLeaveEvent * event)
|
|
{
|
|
event->accept();
|
|
}
|
|
|
|
bool CompareDialog::handleDroppedModel(const QMimeData * mimeData, ModelData & model, QLabel * label)
|
|
{
|
|
if (mimeData->hasFormat("application/x-companion")) {
|
|
QByteArray gmData = mimeData->data("application/x-companion");
|
|
DragDropHeader * header = (DragDropHeader *)gmData.data();
|
|
if (!header->general_settings) {
|
|
char * gData = gmData.data() + sizeof(DragDropHeader);
|
|
if (gData[0] == 'M') {
|
|
ModelData * modeltemp = (ModelData *)(gData + 1);
|
|
if (modeltemp->used) {
|
|
memcpy(&model, modeltemp, sizeof(ModelData));
|
|
QString name(model.name);
|
|
if (!name.isEmpty())
|
|
label->setText(name);
|
|
else
|
|
label->setText(tr("No name"));
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void CompareDialog::dropEvent(QDropEvent *event)
|
|
{
|
|
QLabel * child = qobject_cast<QLabel*>(childAt(event->pos()));
|
|
if (!child) return;
|
|
if (child->objectName().contains("label_1")) {
|
|
model1Valid = handleDroppedModel(event->mimeData(), model1, ui->label_1);
|
|
}
|
|
else if (child->objectName().contains("label_2")) {
|
|
model2Valid = handleDroppedModel(event->mimeData(), model2, ui->label_2);
|
|
}
|
|
event->accept();
|
|
if (model1Valid && model2Valid) {
|
|
multimodelprinter.setModel(0, model1);
|
|
multimodelprinter.setModel(1, model2);
|
|
ui->textEdit->setHtml(multimodelprinter.print(ui->textEdit->document()));
|
|
}
|
|
}
|
|
|
|
void CompareDialog::closeEvent(QCloseEvent *event)
|
|
{
|
|
}
|
|
|
|
CompareDialog::~CompareDialog()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|