Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
801 - 1
/***************************************************************************
2
 *   Copyright (C) 2009 by Manuel Schrape                                  *
3
 *   manuel.schrape@gmx.de                                                 *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation; either version 2 of the License.        *
8
 *                                                                         *
9
 *   This program is distributed in the hope that it will be useful,       *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU General Public License for more details.                          *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
19
 
20
#include <QMessageBox>
21
#include <QCryptographicHash>
22
 
23
#include "dlg_Main.h"
24
 
25
// Konstruktor Main-Form
26
dlg_Main::dlg_Main()
27
{
28
    setupUi(this);
29
 
30
 
31
    o_Settings = new cSettings();
32
 
33
    o_Settings->read_DebugLabels(0);
34
 
35
    wg_Connection->set_Client(ID_SCOPE, QA_NAME + " " + QA_VERSION, DataFields);
36
 
37
    init_GUI();
38
    init_Connections();
39
    init_Plotter();
40
}
41
 
42
// Grafische Oberfläche initialisieren
43
void dlg_Main::init_GUI()
44
{
45
    setWindowTitle(QA_NAME + " " + QA_VERSION);
46
 
47
    resize(o_Settings->GUI.Size);
48
    move(o_Settings->GUI.Point);
49
 
50
    if (o_Settings->GUI.isMax)
51
    {
52
        showMaximized();
53
    }
54
 
55
    wg_Connection->set_SelectVisible(false);
56
    wg_Connection->set_ButtonVisible(false);
57
 
58
    btn_Start->setCheckable(true);
59
 
60
    ac_Plotter->setChecked(true);
61
 
62
    Font_1.setFamily(QString::fromUtf8("Adobe Courier"));
63
    Font_1.setBold(true);
64
    Font_1.setWeight(75);
65
 
66
    for(int z = 0; z < MAX_DebugData; z++)
67
    {
68
 
69
        lb_Debug[z] = new QLabel(wg_Debug);
70
        le_Debug[z] = new QLineEdit(wg_Debug);
71
        cb_Debug[z] = new QCheckBox(wg_Config);
72
        le_Debug[z]->setFont(Font_1);
73
        le_Debug[z]->setAlignment(Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter);
74
        le_Debug[z]->setReadOnly(true);
75
 
76
        wg_Grid->addWidget(lb_Debug[z], (z % 8), z / 8 * 2, 0);
77
        wg_Grid->addWidget(le_Debug[z], (z % 8), z / 8 * 2 + 1 , 0);
78
 
79
        wg_Grid_2->addWidget(cb_Debug[z], (z % 8), z / 8, 0);
80
 
81
        lb_Debug[z]->setText(o_Settings->DebugData.Label[z]);
82
        cb_Debug[z]->setText(o_Settings->DebugData.Label[z]);
83
 
84
        cb_Debug[z]->setChecked(o_Settings->DebugData.Show_Plotter[z]);
85
    }
86
}
87
 
88
// Signale mit Slots verbinden
89
void dlg_Main::init_Connections()
90
{
91
    connect(ac_Connect, SIGNAL(triggered()), wg_Connection, SLOT(slot_btn_Connect()));
92
 
93
    connect(ac_Plotter, SIGNAL(triggered()), this, SLOT(slot_ac_Plotter()));
94
    connect(ac_Debug,   SIGNAL(triggered()), this, SLOT(slot_ac_Debug()));
95
    connect(ac_Chose,   SIGNAL(triggered()), this, SLOT(slot_ac_Chose()));
96
 
97
    connect(ac_ReadLabels, SIGNAL(triggered()), this, SLOT(slot_ac_ReadLabels()));
98
 
99
    connect(Plotter_Scroll, SIGNAL(valueChanged(int)), this, SLOT(slot_Plotter_Scroll(int)));
100
 
101
    connect(btn_Start, SIGNAL(clicked()), this, SLOT(slot_Plotter_Start()));
102
    connect(btn_ChoseOK, SIGNAL(clicked()), this, SLOT(slot_btn_ChoseOK()));
103
 
104
    // About QMK-Kernel & About-QT Dialog einfügen
105
    connect(ac_About, SIGNAL(triggered()), this, SLOT(slot_ac_About()));
106
    menu_Help->addAction(trUtf8("Über &Qt"), qApp, SLOT(aboutQt()));
107
 
108
    connect(wg_Connection, SIGNAL(sig_Status(int)), this, SLOT(slot_ConnectionStatus(int)));
109
    connect(wg_Connection, SIGNAL(sig_MK_Version(s_Hardware)), this, SLOT(slot_MK_Version(s_Hardware)));
110
    connect(wg_Connection, SIGNAL(sig_MK_Debug(s_MK_Debug)), this, SLOT(slot_MK_Debug(s_MK_Debug)));
111
    connect(wg_Connection, SIGNAL(sig_MK_DebugLabels(s_MK_DebugLabels)), this, SLOT(slot_MK_DebugLabels(s_MK_DebugLabels)));
112
}
113
 
114
void dlg_Main::init_Plotter()
115
{
116
    NextPlot = 0;
117
 
118
    qwt_Plotter->setCanvasBackground(QColor(QRgb(0x00000000)));
119
 
120
    qwt_Plotter->insertLegend(new QwtLegend(), QwtPlot::RightLegend);
121
 
122
    QwtPlotGrid *Grid = new QwtPlotGrid();
123
    Grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
124
 
125
    Grid->attach(qwt_Plotter);
126
 
127
    qwt_Plotter->setAxisScale(QwtPlot::xBottom,0,o_Settings->DATA.Plotter_Count,0);
128
 
129
    for (int a = 0; a < MAX_DebugData; a++)
130
    {
131
        Plot[a] = new QwtPlotCurve(o_Settings->DebugData.Label[a]);
132
        Plot[a]->setPen(QPen(QColor(DEF_DebugColors[a])));
133
        Plot[a]->setRenderHint(QwtPlotItem::RenderAntialiased);
134
 
135
        if (o_Settings->DebugData.Show_Plotter[a])
136
            Plot[a]->attach(qwt_Plotter);
137
    }
138
    qwt_Plotter->replot();
139
}
140
 
141
void dlg_Main::update_Plotter()
142
{
143
    pl_ID[NextPlot] = NextPlot;
144
 
145
    for (int a = 0; a < MAX_DebugData; a++)
146
    {
147
        pl_Data[a][NextPlot] = Debug_Data[a];
148
        Plot[a]->setData(pl_ID,pl_Data[a],NextPlot);
149
    }
150
 
151
    NextPlot++;
152
 
153
    if ((NextPlot > o_Settings->DATA.Plotter_Count))
154
    {
155
        Plotter_Scroll->setMaximum(NextPlot - o_Settings->DATA.Plotter_Count);
156
    }
157
 
158
    if ((Plotter_Scroll->value() == NextPlot - (o_Settings->DATA.Plotter_Count + 1)))
159
    {
160
        qwt_Plotter->setAxisScale(QwtPlot::xBottom,NextPlot - o_Settings->DATA.Plotter_Count,NextPlot,0);
161
        Plotter_Scroll->setValue(NextPlot - o_Settings->DATA.Plotter_Count);
162
    }
163
 
164
    qwt_Plotter->replot();
165
}
166
 
167
void dlg_Main::config_Plotter()
168
{
169
    qwt_Plotter->setAxisScale(QwtPlot::xBottom,0,o_Settings->DATA.Plotter_Count,0);
170
 
171
    for (int a = 0; a < MAX_DebugData; a++)
172
    {
173
        Plot[a]->detach();
174
        Plot[a]->setPen(QPen(QColor(DEF_DebugColors[a])));
175
 
176
        if (o_Settings->DebugData.Show_Plotter[a])
177
        {
178
            Plot[a]->setTitle(o_Settings->DebugData.Label[a]);
179
            Plot[a]->attach(qwt_Plotter);
180
        }
181
    }
182
    qwt_Plotter->replot();
183
}
184
 
185
void dlg_Main::slot_Plotter_Scroll(int Position)
186
{
187
    qwt_Plotter->setAxisScale(QwtPlot::xBottom,Position,Position + o_Settings->DATA.Plotter_Count,0);
188
    qwt_Plotter->replot();
189
}
190
 
191
///////////
192
// Slots //
193
///////////
194
 
195
// About-Dialog
196
void dlg_Main::slot_ac_About()
197
{
198
    QMessageBox::about(this, trUtf8(("Über ")) + QA_NAME, QA_ABOUT);
199
}
200
 
201
void dlg_Main::slot_ConnectionStatus(int li_Status)
202
{
203
    if (li_Status)
204
    {
205
        ac_Connect->setChecked(true);
206
        ac_Connect->setText(tr("Trennen"));
207
    }
208
    else
209
    {
210
        ac_Connect->setChecked(false);
211
        ac_Connect->setText(tr("Verbinden"));
212
    }
213
}
214
 
215
void dlg_Main::slot_MK_Version(s_Hardware ls_Version)
216
{
217
    gs_Version = ls_Version;
218
    setWindowTitle(QA_NAME + " " + QA_VERSION + " - " + ls_Version.Hardware + " " + ls_Version.Version);
219
 
220
    o_Settings->read_DebugLabels(gs_Version.ID);
221
 
222
    if (o_Settings->DebugData.Version != gs_Version.Version)
223
    {
224
        qDebug(QString("Debug-Labels unterschiedlich. Neue anforden. " + o_Settings->DebugData.Version + " <> " + gs_Version.Version).toLatin1().data());
225
        usleep(50000);
226
 
227
        slot_ac_ReadLabels();
228
    }
229
    else
230
    {
231
        for(int z = 0; z < MAX_DebugData; z++)
232
        {
233
            lb_Debug[z]->setText(o_Settings->DebugData.Label[z]);
234
            cb_Debug[z]->setText(o_Settings->DebugData.Label[z]);
235
            cb_Debug[z]->setChecked(o_Settings->DebugData.Show_Plotter[z]);
236
        }
237
        config_Plotter();
238
    }
239
}
240
 
241
void dlg_Main::slot_MK_Debug(s_MK_Debug ls_Debug)
242
{
243
    gs_Debug = ls_Debug;
244
 
245
    for (int z = 0; z < MAX_DebugData; z++)
246
    {
247
        Debug_Data[z] = ls_Debug.Analog[z];
248
        if (ac_Debug->isChecked())
249
        {
250
           le_Debug[z]->setText(QString("%1").arg(Debug_Data[z]));
251
        }
252
    }
253
    if (btn_Start->isChecked())
254
    {
255
       update_Plotter();
256
    }
257
}
258
 
259
void dlg_Main::slot_MK_DebugLabels(s_MK_DebugLabels MK_DebugLabels)
260
{
261
    if (MK_DebugLabels.Position < 32)
262
    {
263
        o_Settings->DebugData.Label[MK_DebugLabels.Position] = MK_DebugLabels.Text;
264
        if (o_Settings->DebugData.Label[MK_DebugLabels.Position] == "")
265
        {
266
            o_Settings->DebugData.Label[MK_DebugLabels.Position] = "Debug-" + QString("%1").arg(MK_DebugLabels.Position);
267
        }
268
        lb_Debug[MK_DebugLabels.Position]->setText("" + o_Settings->DebugData.Label[MK_DebugLabels.Position]);
269
        cb_Debug[MK_DebugLabels.Position]->setText("" + o_Settings->DebugData.Label[MK_DebugLabels.Position]);
270
 
271
    }
272
    if (MK_DebugLabels.Position == 31)
273
    {
274
        o_Settings->DebugData.Version = gs_Version.Version;
275
        o_Settings->write_DebugLabels(gs_Version.ID);
276
        config_Plotter();
277
    }
278
}
279
 
280
void dlg_Main::slot_Plotter_Start()
281
{
282
    if (btn_Start->isChecked())
283
    {
284
        btn_Start->setText(tr("Plotter stoppen"));
285
    }
286
    else
287
    {
288
        btn_Start->setText(tr("Plotter starten"));
289
    }
290
}
291
 
292
void dlg_Main::slot_btn_ChoseOK()
293
{
294
    for(int z = 0; z < MAX_DebugData; z++)
295
    {
296
        o_Settings->DebugData.Show_Plotter[z] = cb_Debug[z]->isChecked();
297
    }
298
    config_Plotter();
299
    o_Settings->write_DebugLabels(gs_Version.ID);
300
}
301
 
302
void dlg_Main::slot_ac_Chose()
303
{
304
    for(int z = 0; z < MAX_DebugData; z++)
305
    {
306
        cb_Debug[z]->setChecked(o_Settings->DebugData.Show_Plotter[z]);
307
    }
308
 
309
    ac_Chose->setChecked(true);
310
    ac_Debug->setChecked(false);
311
    ac_Plotter->setChecked(false);
312
    wg_Pages->setCurrentIndex(2);
313
}
314
 
315
void dlg_Main::slot_ac_Debug()
316
{
317
    ac_Debug->setChecked(true);
318
    ac_Chose->setChecked(false);
319
    ac_Plotter->setChecked(false);
320
    wg_Pages->setCurrentIndex(1);
321
}
322
 
323
void dlg_Main::slot_ac_Plotter()
324
{
325
    ac_Plotter->setChecked(true);
326
    ac_Debug->setChecked(false);
327
    ac_Chose->setChecked(false);
328
    wg_Pages->setCurrentIndex(0);
329
}
330
 
331
void dlg_Main::slot_ac_ReadLabels()
332
{
333
    c_Data[0] = 0;
334
    wg_Connection->send_Data(HandlerMK::make_Frame('a', ADDRESS_ALL, c_Data, 1).toLatin1().data(), DATA_READ_LABEL);
335
}
336
 
337
// Programm Ende
338
dlg_Main::~dlg_Main()
339
{
340
    o_Settings->GUI.isMax       = isMaximized();
341
    o_Settings->GUI.Size        = size();
342
    o_Settings->GUI.Point       = pos();
343
 
344
    o_Settings->write_Settings();
345
}