ponyprog/SrcPony/infomdlg.cpp

426 lines
9.7 KiB
C++
Raw Normal View History

2000-02-05 22:37:44 +00:00
//=========================================================================//
// //
// PonyProg - Serial Device Programmer //
// //
2019-02-08 00:29:55 +01:00
// Copyright (C) 1997-2019 Claudio Lanconelli //
2000-02-05 22:37:44 +00:00
// //
// http://ponyprog.sourceforge.net //
2000-02-05 22:37:44 +00:00
// //
//-------------------------------------------------------------------------//
// //
// This program is free software; you can redistribute it and/or //
// modify it under the terms of the GNU General Public License //
// as published by the Free Software Foundation; either version2 of //
// the License, or (at your option) any later version. //
// //
// 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. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program (see LICENSE); if not, write to the //
2000-02-05 22:37:44 +00:00
// Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. //
// //
//=========================================================================//
2017-04-18 01:25:22 +02:00
#include <QDebug>
#include <QString>
#include "e2cmdw.h"
2004-11-30 17:46:48 +00:00
#include "globals.h"
#include "infomdlg.h"
class e2CmdWindow;
2000-02-05 22:37:44 +00:00
2017-04-29 01:56:50 +02:00
e24xx_infoModalDialog::e24xx_infoModalDialog(QWidget *bw, int rlv, uint16_t crc, long size, const QString title) :
2017-04-18 01:25:22 +02:00
QDialog(bw)
2000-02-05 22:37:44 +00:00
{
2017-04-18 01:25:22 +02:00
setupUi(this);
setWindowTitle(title);
e2CmdWindow *cmdw = static_cast<e2CmdWindow *>(bw);
if (cmdw->getStyleSheet().length() > 0)
{
setStyleSheet(cmdw->getStyleSheet());
}
2004-11-30 17:46:48 +00:00
if (rlv == 1)
{
txiFrom->setText(translate(STR_YES));
2004-11-30 17:46:48 +00:00
}
2017-04-18 01:25:22 +02:00
else if (rlv == 2)
2004-11-30 17:46:48 +00:00
{
txiFrom->setText(translate(STR_NO));
2004-11-30 17:46:48 +00:00
}
else
{
txiFrom->setText(translate(STR_MSGUNKNOWN));
2004-11-30 17:46:48 +00:00
}
2000-02-05 22:37:44 +00:00
lblFrom->setText(translate(STR_MSGCRC)); // crc label
lblTo->setText(translate(STR_MSGEEPSIZE)); // size label
lblVal->setText(translate(STR_MSGFLASHSIZE)); // flash size label
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
QString str;
str = QString().sprintf("%04Xh", crc);
txiTo->setText(str);
txiTo->setReadOnly(true);
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
str = QString().sprintf("%ld Byte", size);
txiVal->setText(str);
txiVal->setReadOnly(true);
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
lblVal->setHidden(true);
txiVal->setHidden(true);
2000-02-05 22:37:44 +00:00
pushOk->setText(translate(STR_BTNCLOSE));
2017-04-18 01:25:22 +02:00
pushCancel->setHidden(true);
connect(pushOk, SIGNAL(clicked()), this, SLOT(onOk()));
// connect(pushCancel, SIGNAL(clicked()), this, SLOT(reject()));
2004-11-30 17:46:48 +00:00
}
2017-04-18 01:25:22 +02:00
2004-11-30 17:46:48 +00:00
e24xx_infoModalDialog::~e24xx_infoModalDialog()
{
2017-04-18 01:25:22 +02:00
qDebug() << "infoModalDialog::~infoModalDialog()";
2000-02-05 22:37:44 +00:00
}
2017-04-18 01:25:22 +02:00
void e24xx_infoModalDialog::onOk()
{
accept();
2000-02-05 22:37:44 +00:00
}
2017-04-18 01:25:22 +02:00
2017-04-29 01:56:50 +02:00
other_infoModalDialog::other_infoModalDialog(QWidget *bw, long fsize, long esize, uint16_t crc, const QString title) :
2017-04-18 01:25:22 +02:00
QDialog(bw)
2000-02-05 22:37:44 +00:00
{
2017-04-18 01:25:22 +02:00
setupUi(this);
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
setWindowTitle(title);
2000-02-05 22:37:44 +00:00
e2CmdWindow *cmdw = static_cast<e2CmdWindow *>(bw);
if (cmdw->getStyleSheet().length() > 0)
{
setStyleSheet(cmdw->getStyleSheet());
}
2017-04-18 01:25:22 +02:00
QString str;
2000-02-05 22:37:44 +00:00
lblFrom->setText(translate(STR_MSGCRC)); // crc label
lblTo->setText(translate(STR_MSGEEPSIZE)); // size label
lblVal->setText(translate(STR_MSGFLASHSIZE)); // flash size label
2000-02-05 22:37:44 +00:00
2017-04-29 01:56:50 +02:00
str = QString().sprintf("%04Xh", crc);
2017-04-18 01:25:22 +02:00
txiFrom->setText(str);
txiFrom->setReadOnly(true);
2004-11-30 17:46:48 +00:00
2017-04-29 01:56:50 +02:00
str = QString().sprintf("%ld Byte", fsize);
2017-04-18 01:25:22 +02:00
txiTo->setText(str);
txiTo->setReadOnly(true);
2004-11-30 17:46:48 +00:00
2017-04-29 01:56:50 +02:00
str = QString().sprintf("%ld Byte", esize);
2017-04-18 01:25:22 +02:00
txiVal->setText(str);
txiVal->setReadOnly(true);
2004-11-30 17:46:48 +00:00
pushOk->setText(translate(STR_BTNCLOSE));
2017-04-18 01:25:22 +02:00
pushCancel->setHidden(true);
connect(pushOk, SIGNAL(clicked()), this, SLOT(onOk()));
// connect(pushCancel, SIGNAL(clicked()), this, SLOT(reject()));
2000-02-05 22:37:44 +00:00
}
2004-11-30 17:46:48 +00:00
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
other_infoModalDialog::~other_infoModalDialog()
{
qDebug() << "infoModalDialog::~infoModalDialog()";
}
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
void other_infoModalDialog::onOk()
2000-02-05 22:37:44 +00:00
{
2017-04-18 01:25:22 +02:00
accept();
2000-02-05 22:37:44 +00:00
}
2017-04-18 01:25:22 +02:00
2017-04-29 01:56:50 +02:00
notesModalDialog::notesModalDialog(QWidget *bw, QString &id, QString &cm, const QString title) :
2017-04-18 01:25:22 +02:00
QDialog(bw)
2000-02-05 22:37:44 +00:00
{
2017-04-18 01:25:22 +02:00
setupUi(this);
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
setWindowTitle(title);
2000-02-05 22:37:44 +00:00
e2CmdWindow *cmdw = static_cast<e2CmdWindow *>(bw);
if (cmdw->getStyleSheet().length() > 0)
{
setStyleSheet(cmdw->getStyleSheet());
}
2017-04-18 01:25:22 +02:00
qDebug() << "notesModalDialog::notesModalDialog()";
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
id_ptr = &id;
cm_ptr = &cm;
2000-02-05 22:37:44 +00:00
lblStrID->setText(translate(STR_MSGCHIPID));
lblCommnt->setText(translate(STR_MSGNOTE));
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
if (id.length() && cm.length())
{
id_txt = id;
txiStrID->setText(id_txt);
cmt_txt = cm;
txiCommnt->setText(cmt_txt);
}
2000-02-05 22:37:44 +00:00
pushOk->setText(translate(STR_BTNOK));
pushCancel->setText(translate(STR_BTNCANC));
2017-04-18 01:25:22 +02:00
connect(pushOk, SIGNAL(clicked()), this, SLOT(onOk()));
connect(pushCancel, SIGNAL(clicked()), this, SLOT(reject()));
}
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
notesModalDialog::~notesModalDialog()
2000-02-05 22:37:44 +00:00
{
2017-04-18 01:25:22 +02:00
qDebug() << "notesModalDialog::~notesModalDialog()";
}
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
void notesModalDialog::onOk()
{
cmt_txt = txiCommnt->text();
id_txt = txiStrID->text();
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
*id_ptr = id_txt;
*cm_ptr = cmt_txt;
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
accept();
}
2000-02-05 22:37:44 +00:00
#if 0
2017-04-29 01:56:50 +02:00
editModalDialog::editModalDialog(QWidget *bw, int curval, const QString title) :
2017-04-18 01:25:22 +02:00
QDialog(bw)
2000-02-05 22:37:44 +00:00
{
2017-04-18 01:25:22 +02:00
setupUi(this);
setWindowTitle(title);
e2CmdWindow *cmdw = static_cast<e2CmdWindow *>(bw);
if (cmdw->getStyleSheet().length() > 0)
{
setStyleSheet(cmdw->getStyleSheet());
}
2017-04-18 01:25:22 +02:00
qDebug() << "editModalDialog::editModalDialog()";
2000-02-05 22:37:44 +00:00
if (curval < 0)
2017-04-18 01:25:22 +02:00
{
2000-02-05 22:37:44 +00:00
curval = 0;
2017-04-18 01:25:22 +02:00
}
lblFrom->setText(translate(STR_MSGHEX));
lblTo->setText(translate(STR_MSGDECIMAL));
lblVal->setText(translate(STR_MSGCHAR));
2000-02-05 22:37:44 +00:00
oldval = curval;
2017-04-18 01:25:22 +02:00
QString str;
str = QString().sprintf("%02X", curval);
txiFrom->setText(str);
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
connect(txiFrom, SIGNAL(changed()), this, SLOT(onEdit()));
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
str = QString().sprintf("%d", curval);
txiTo->setText(str);
connect(txiTo, SIGNAL(changed()), this, SLOT(onEdit()));
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
str = QString().sprintf("%c", curval);
txiVal->setText(str);
connect(txiVal, SIGNAL(changed()), this, SLOT(onEdit()));
2000-02-05 22:37:44 +00:00
pushOk->setText(translate(STR_BTNOK));
pushCancel->setText(translate(STR_BTNCANC));
2017-04-18 01:25:22 +02:00
connect(pushOk, SIGNAL(clicked()), this, SLOT(onOk()));
connect(pushCancel, SIGNAL(clicked()), this, SLOT(reject()));
2000-02-05 22:37:44 +00:00
}
2017-04-18 01:25:22 +02:00
2000-02-05 22:37:44 +00:00
editModalDialog::~editModalDialog()
{
2017-04-18 01:25:22 +02:00
qDebug() << "editModalDialog::~editModalDialog()";
2000-02-05 22:37:44 +00:00
}
2017-04-18 01:25:22 +02:00
void editModalDialog::onOk()
2000-02-05 22:37:44 +00:00
{
2017-04-18 01:25:22 +02:00
accept();
}
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
int editModalDialog::GetVal()
{
return oldval;
2000-02-05 22:37:44 +00:00
}
2017-04-18 01:25:22 +02:00
void editModalDialog::onEdit()
2000-02-05 22:37:44 +00:00
{
2017-04-18 01:25:22 +02:00
int newval;
bool ok;
2017-04-29 01:56:50 +02:00
QLineEdit *l = static_cast<QLineEdit *>(sender());
2017-04-18 01:25:22 +02:00
disconnect(txiFrom, SIGNAL(changed()), this, SLOT(onEdit())); // hex
disconnect(txiTo, SIGNAL(changed()), this, SLOT(onEdit())); // dec
disconnect(txiVal, SIGNAL(changed()), this, SLOT(onEdit())); // char
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
if (l == txiFrom) // hex
{
QString n = txiFrom->text();
newval = n.toInt(&ok, 16);
if (ok == true)
{
QPalette *palette = new QPalette();
palette->setColor(QPalette::Text, Qt::black);
txiFrom->setPalette(*palette);
}
else
{
QPalette *palette = new QPalette();
palette->setColor(QPalette::Text, Qt::red);
txiFrom->setPalette(*palette);
}
2017-04-18 01:25:22 +02:00
}
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
if (l == txiTo) // dec
{
QString n = txiTo->text();
2017-04-18 01:25:22 +02:00
newval = n.toInt(&ok, 10);
if (ok == true)
{
QPalette *palette = new QPalette();
palette->setColor(QPalette::Text, Qt::black);
txiTo->setPalette(*palette);
}
else
{
QPalette *palette = new QPalette();
palette->setColor(QPalette::Text, Qt::red);
txiTo->setPalette(*palette);
}
2017-04-18 01:25:22 +02:00
}
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
if (l == txiVal) // char
{
QString n = txiVal->text();
2017-04-18 01:25:22 +02:00
if (n.length() != 1)
2017-04-18 01:25:22 +02:00
{
ok = false;
QPalette *palette = new QPalette();
palette->setColor(QPalette::Text, Qt::red);
txiVal->setPalette(*palette);
2017-04-18 01:25:22 +02:00
}
else
{
newval = static_cast<unsigned char>(n.at(0).toLatin1());
ok = true;
QPalette *palette = new QPalette();
palette->setColor(QPalette::Text, Qt::black);
txiVal->setPalette(*palette);
2017-04-18 01:25:22 +02:00
}
}
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
if (ok == true)
{
if (oldval != newval)
{
oldval = newval;
txiFrom->setText(QString().sprintf("%02X", newval));
txiTo->setText(QString().sprintf("%d", newval));
txiVal->setText(QString().sprintf("%c", newval));
}
}
connect(txiFrom, SIGNAL(changed()), this, SLOT(onEdit()));
connect(txiTo, SIGNAL(changed()), this, SLOT(onEdit()));
connect(txiVal, SIGNAL(changed()), this, SLOT(onEdit()));
}
const int MAXLEN = 80;
2017-04-18 01:25:22 +02:00
2017-04-29 01:56:50 +02:00
editModalDialog2::editModalDialog2(QWidget *bw, const QString curval, const QString title) :
2017-04-18 01:25:22 +02:00
QDialog(bw)
2000-02-05 22:37:44 +00:00
{
2017-04-18 01:25:22 +02:00
setupUi(this);
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
setWindowTitle(title);
2000-02-05 22:37:44 +00:00
e2CmdWindow *cmdw = static_cast<e2CmdWindow *>(bw);
if (cmdw->getStyleSheet().length() > 0)
{
setStyleSheet(cmdw->getStyleSheet());
}
2017-04-18 01:25:22 +02:00
lblFrom->setHidden(true);
txiFrom->setHidden(true);
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
lblTo->setHidden(true);
txiTo->setHidden(true);
lblVal->setText(translate(STR_MSGCHAR));
2017-04-18 01:25:22 +02:00
qDebug() << "editModalDialog::editModalDialog()";
val = curval;
if (val.length() > MAXLEN)
{
val = val.left(MAXLEN);
}
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
txiVal->setText(val);
pushOk->setText(translate(STR_BTNOK));
pushCancel->setText(translate(STR_BTNCANC));
2017-04-18 01:25:22 +02:00
connect(pushOk, SIGNAL(clicked()), this, SLOT(onOk()));
connect(pushCancel, SIGNAL(clicked()), this, SLOT(reject()));
2000-02-05 22:37:44 +00:00
}
2017-04-18 01:25:22 +02:00
2000-02-05 22:37:44 +00:00
editModalDialog2::~editModalDialog2()
{
2017-04-18 01:25:22 +02:00
qDebug() << "editModalDialog::~editModalDialog()";
2000-02-05 22:37:44 +00:00
}
2017-04-18 01:25:22 +02:00
QString editModalDialog2::GetVal()
{
return val;
}
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
void editModalDialog2::onOk()
{
val = txiVal->text();
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
if (val.length() > MAXLEN)
{
val = val.left(MAXLEN);
}
2000-02-05 22:37:44 +00:00
2017-04-18 01:25:22 +02:00
accept();
2000-02-05 22:37:44 +00:00
}
#endif