0,0 → 1,345 |
/*************************************************************************** |
* Copyright (C) 2009 by Manuel Schrape * |
* manuel.schrape@gmx.de * |
* * |
* 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 version 2 of the License. * |
* * |
* 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; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
***************************************************************************/ |
|
#include <QMessageBox> |
#include <QCryptographicHash> |
|
#include "dlg_Main.h" |
|
// Konstruktor Main-Form |
dlg_Main::dlg_Main() |
{ |
setupUi(this); |
|
|
o_Settings = new cSettings(); |
|
o_Settings->read_DebugLabels(0); |
|
wg_Connection->set_Client(ID_SCOPE, QA_NAME + " " + QA_VERSION, DataFields); |
|
init_GUI(); |
init_Connections(); |
init_Plotter(); |
} |
|
// Grafische Oberfläche initialisieren |
void dlg_Main::init_GUI() |
{ |
setWindowTitle(QA_NAME + " " + QA_VERSION); |
|
resize(o_Settings->GUI.Size); |
move(o_Settings->GUI.Point); |
|
if (o_Settings->GUI.isMax) |
{ |
showMaximized(); |
} |
|
wg_Connection->set_SelectVisible(false); |
wg_Connection->set_ButtonVisible(false); |
|
btn_Start->setCheckable(true); |
|
ac_Plotter->setChecked(true); |
|
Font_1.setFamily(QString::fromUtf8("Adobe Courier")); |
Font_1.setBold(true); |
Font_1.setWeight(75); |
|
for(int z = 0; z < MAX_DebugData; z++) |
{ |
|
lb_Debug[z] = new QLabel(wg_Debug); |
le_Debug[z] = new QLineEdit(wg_Debug); |
cb_Debug[z] = new QCheckBox(wg_Config); |
le_Debug[z]->setFont(Font_1); |
le_Debug[z]->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter); |
le_Debug[z]->setReadOnly(true); |
|
wg_Grid->addWidget(lb_Debug[z], (z % 8), z / 8 * 2, 0); |
wg_Grid->addWidget(le_Debug[z], (z % 8), z / 8 * 2 + 1 , 0); |
|
wg_Grid_2->addWidget(cb_Debug[z], (z % 8), z / 8, 0); |
|
lb_Debug[z]->setText(o_Settings->DebugData.Label[z]); |
cb_Debug[z]->setText(o_Settings->DebugData.Label[z]); |
|
cb_Debug[z]->setChecked(o_Settings->DebugData.Show_Plotter[z]); |
} |
} |
|
// Signale mit Slots verbinden |
void dlg_Main::init_Connections() |
{ |
connect(ac_Connect, SIGNAL(triggered()), wg_Connection, SLOT(slot_btn_Connect())); |
|
connect(ac_Plotter, SIGNAL(triggered()), this, SLOT(slot_ac_Plotter())); |
connect(ac_Debug, SIGNAL(triggered()), this, SLOT(slot_ac_Debug())); |
connect(ac_Chose, SIGNAL(triggered()), this, SLOT(slot_ac_Chose())); |
|
connect(ac_ReadLabels, SIGNAL(triggered()), this, SLOT(slot_ac_ReadLabels())); |
|
connect(Plotter_Scroll, SIGNAL(valueChanged(int)), this, SLOT(slot_Plotter_Scroll(int))); |
|
connect(btn_Start, SIGNAL(clicked()), this, SLOT(slot_Plotter_Start())); |
connect(btn_ChoseOK, SIGNAL(clicked()), this, SLOT(slot_btn_ChoseOK())); |
|
// About QMK-Kernel & About-QT Dialog einfügen |
connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About())); |
menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt())); |
|
connect(wg_Connection, SIGNAL(sig_Status(int)), this, SLOT(slot_ConnectionStatus(int))); |
connect(wg_Connection, SIGNAL(sig_MK_Version(s_Hardware)), this, SLOT(slot_MK_Version(s_Hardware))); |
connect(wg_Connection, SIGNAL(sig_MK_Debug(s_MK_Debug)), this, SLOT(slot_MK_Debug(s_MK_Debug))); |
connect(wg_Connection, SIGNAL(sig_MK_DebugLabels(s_MK_DebugLabels)), this, SLOT(slot_MK_DebugLabels(s_MK_DebugLabels))); |
} |
|
void dlg_Main::init_Plotter() |
{ |
NextPlot = 0; |
|
qwt_Plotter->setCanvasBackground(QColor(QRgb(0x00000000))); |
|
qwt_Plotter->insertLegend(new QwtLegend(), QwtPlot::RightLegend); |
|
QwtPlotGrid *Grid = new QwtPlotGrid(); |
Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine)); |
|
Grid->attach(qwt_Plotter); |
|
qwt_Plotter->setAxisScale(QwtPlot::xBottom,0,o_Settings->DATA.Plotter_Count,0); |
|
for (int a = 0; a < MAX_DebugData; a++) |
{ |
Plot[a] = new QwtPlotCurve(o_Settings->DebugData.Label[a]); |
Plot[a]->setPen(QPen(QColor(DEF_DebugColors[a]))); |
Plot[a]->setRenderHint(QwtPlotItem::RenderAntialiased); |
|
if (o_Settings->DebugData.Show_Plotter[a]) |
Plot[a]->attach(qwt_Plotter); |
} |
qwt_Plotter->replot(); |
} |
|
void dlg_Main::update_Plotter() |
{ |
pl_ID[NextPlot] = NextPlot; |
|
for (int a = 0; a < MAX_DebugData; a++) |
{ |
pl_Data[a][NextPlot] = Debug_Data[a]; |
Plot[a]->setData(pl_ID,pl_Data[a],NextPlot); |
} |
|
NextPlot++; |
|
if ((NextPlot > o_Settings->DATA.Plotter_Count)) |
{ |
Plotter_Scroll->setMaximum(NextPlot - o_Settings->DATA.Plotter_Count); |
} |
|
if ((Plotter_Scroll->value() == NextPlot - (o_Settings->DATA.Plotter_Count + 1))) |
{ |
qwt_Plotter->setAxisScale(QwtPlot::xBottom,NextPlot - o_Settings->DATA.Plotter_Count,NextPlot,0); |
Plotter_Scroll->setValue(NextPlot - o_Settings->DATA.Plotter_Count); |
} |
|
qwt_Plotter->replot(); |
} |
|
void dlg_Main::config_Plotter() |
{ |
qwt_Plotter->setAxisScale(QwtPlot::xBottom,0,o_Settings->DATA.Plotter_Count,0); |
|
for (int a = 0; a < MAX_DebugData; a++) |
{ |
Plot[a]->detach(); |
Plot[a]->setPen(QPen(QColor(DEF_DebugColors[a]))); |
|
if (o_Settings->DebugData.Show_Plotter[a]) |
{ |
Plot[a]->setTitle(o_Settings->DebugData.Label[a]); |
Plot[a]->attach(qwt_Plotter); |
} |
} |
qwt_Plotter->replot(); |
} |
|
void dlg_Main::slot_Plotter_Scroll(int Position) |
{ |
qwt_Plotter->setAxisScale(QwtPlot::xBottom,Position,Position + o_Settings->DATA.Plotter_Count,0); |
qwt_Plotter->replot(); |
} |
|
/////////// |
// Slots // |
/////////// |
|
// About-Dialog |
void dlg_Main::slot_ac_About() |
{ |
QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT); |
} |
|
void dlg_Main::slot_ConnectionStatus(int li_Status) |
{ |
if (li_Status) |
{ |
ac_Connect->setChecked(true); |
ac_Connect->setText(tr("Trennen")); |
} |
else |
{ |
ac_Connect->setChecked(false); |
ac_Connect->setText(tr("Verbinden")); |
} |
} |
|
void dlg_Main::slot_MK_Version(s_Hardware ls_Version) |
{ |
gs_Version = ls_Version; |
setWindowTitle(QA_NAME + " " + QA_VERSION + " - " + ls_Version.Hardware + " " + ls_Version.Version); |
|
o_Settings->read_DebugLabels(gs_Version.ID); |
|
if (o_Settings->DebugData.Version != gs_Version.Version) |
{ |
qDebug(QString("Debug-Labels unterschiedlich. Neue anforden. " + o_Settings->DebugData.Version + " <> " + gs_Version.Version).toLatin1().data()); |
usleep(50000); |
|
slot_ac_ReadLabels(); |
} |
else |
{ |
for(int z = 0; z < MAX_DebugData; z++) |
{ |
lb_Debug[z]->setText(o_Settings->DebugData.Label[z]); |
cb_Debug[z]->setText(o_Settings->DebugData.Label[z]); |
cb_Debug[z]->setChecked(o_Settings->DebugData.Show_Plotter[z]); |
} |
config_Plotter(); |
} |
} |
|
void dlg_Main::slot_MK_Debug(s_MK_Debug ls_Debug) |
{ |
gs_Debug = ls_Debug; |
|
for (int z = 0; z < MAX_DebugData; z++) |
{ |
Debug_Data[z] = ls_Debug.Analog[z]; |
if (ac_Debug->isChecked()) |
{ |
le_Debug[z]->setText(QString("%1").arg(Debug_Data[z])); |
} |
} |
if (btn_Start->isChecked()) |
{ |
update_Plotter(); |
} |
} |
|
void dlg_Main::slot_MK_DebugLabels(s_MK_DebugLabels MK_DebugLabels) |
{ |
if (MK_DebugLabels.Position < 32) |
{ |
o_Settings->DebugData.Label[MK_DebugLabels.Position] = MK_DebugLabels.Text; |
if (o_Settings->DebugData.Label[MK_DebugLabels.Position] == "") |
{ |
o_Settings->DebugData.Label[MK_DebugLabels.Position] = "Debug-" + QString("%1").arg(MK_DebugLabels.Position); |
} |
lb_Debug[MK_DebugLabels.Position]->setText("" + o_Settings->DebugData.Label[MK_DebugLabels.Position]); |
cb_Debug[MK_DebugLabels.Position]->setText("" + o_Settings->DebugData.Label[MK_DebugLabels.Position]); |
|
} |
if (MK_DebugLabels.Position == 31) |
{ |
o_Settings->DebugData.Version = gs_Version.Version; |
o_Settings->write_DebugLabels(gs_Version.ID); |
config_Plotter(); |
} |
} |
|
void dlg_Main::slot_Plotter_Start() |
{ |
if (btn_Start->isChecked()) |
{ |
btn_Start->setText(tr("Plotter stoppen")); |
} |
else |
{ |
btn_Start->setText(tr("Plotter starten")); |
} |
} |
|
void dlg_Main::slot_btn_ChoseOK() |
{ |
for(int z = 0; z < MAX_DebugData; z++) |
{ |
o_Settings->DebugData.Show_Plotter[z] = cb_Debug[z]->isChecked(); |
} |
config_Plotter(); |
o_Settings->write_DebugLabels(gs_Version.ID); |
} |
|
void dlg_Main::slot_ac_Chose() |
{ |
for(int z = 0; z < MAX_DebugData; z++) |
{ |
cb_Debug[z]->setChecked(o_Settings->DebugData.Show_Plotter[z]); |
} |
|
ac_Chose->setChecked(true); |
ac_Debug->setChecked(false); |
ac_Plotter->setChecked(false); |
wg_Pages->setCurrentIndex(2); |
} |
|
void dlg_Main::slot_ac_Debug() |
{ |
ac_Debug->setChecked(true); |
ac_Chose->setChecked(false); |
ac_Plotter->setChecked(false); |
wg_Pages->setCurrentIndex(1); |
} |
|
void dlg_Main::slot_ac_Plotter() |
{ |
ac_Plotter->setChecked(true); |
ac_Debug->setChecked(false); |
ac_Chose->setChecked(false); |
wg_Pages->setCurrentIndex(0); |
} |
|
void dlg_Main::slot_ac_ReadLabels() |
{ |
c_Data[0] = 0; |
wg_Connection->send_Data(HandlerMK::make_Frame('a', ADDRESS_ALL, c_Data, 1).toLatin1().data(), DATA_READ_LABEL); |
} |
|
// Programm Ende |
dlg_Main::~dlg_Main() |
{ |
o_Settings->GUI.isMax = isMaximized(); |
o_Settings->GUI.Size = size(); |
o_Settings->GUI.Point = pos(); |
|
o_Settings->write_Settings(); |
} |