/***************************************************************************
 *   Copyright (C) 2006 by Andreas Krumnow   *
 *   andreas@krumnow.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, 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; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

/* * TODO:
    - FIX: korrektes resize beim zurückklappen der Options und Plotterfield.height() < Options.height()

    DONE:
    
    - FIX: TransmittedBytes wurde falsch berechnet
    - auslesen der Traffixdaten als eigene Klasse 'NetTraffix'
    - ColorSlider direkt von QSlider abgeleitet
    - umbenennung der Main Klasse in 'Traffix', versionshift auf 0.7
*/

#include "traffix.h"

Traffix::Traffix()
{
    /* Global Inits */
    version = "0.7.2";             // Programmversion: wird bei About ausgegeben
    last_edited = "10. Sep 2006";   // Tag der letzten Änderung
    firstRTx = true;               // Anzahl der übertragenen Bytes wird zum ersten mal ausgelesen
    optionsHeight = 184;            // Pixelhöhe des Optionen-Popups
    hz_genau = 2;                   // Nachkommastellen der Hz Angabe
    val_clockRange = 2000;
    
    /* Definitions: Widgets, Ui,  */
    {   /* plotPane */
    plotPane = new PlotterField(this);
    plotPane->setObjectName(QString::fromUtf8("plotPane"));
    plotPane->setUnitsHorizontalLeft("bytes");
    plotPane->setUnitsHorizontalRight("");
    plotPane->setUnitsVerticalBelow("sec");
    plotPane->setUnitsVerticalAbove("min:sec");
    }

    {   /* extension */
    extension = new QFrame(this);
    extension->setObjectName(QString::fromUtf8("extension"));
    extension->setFrameStyle(QFrame::Panel | QFrame::Sunken);
    extension->setLineWidth(2);
    extension->setMaximumSize (1000000,optionsHeight);
    }

    {   /* lbl_... */
    lbl_gridCol = new QLabel(tr("Rasterfarbe"),extension);
    lbl_gridCol->setObjectName(QString::fromUtf8("lbl_gridCol"));
    lbl_gridCol->setToolTip(tr("Raster- und Skala- Farbe"));
    lbl_alpha = new QLabel(tr("Raster-alpha"),extension);
    lbl_alpha->setObjectName(QString::fromUtf8("lbl_alpha"));
    lbl_alpha->setToolTip(tr("Durchsichtigkeit des Rasters"));
    lbl_bkcol = new QLabel(tr("Feld"),extension);
    lbl_bkcol->setObjectName(QString::fromUtf8("lbl_bkcol"));
    lbl_bkcol->setToolTip(tr("Hintergrundfarbe"));
    lbl_plotCol1 = new QLabel(tr("Rx"),extension);
    lbl_plotCol1->setObjectName(QString::fromUtf8("lbl_plotCol1"));
    lbl_plotCol1->setToolTip(tr("Empfangene Bytes - Farbe"));
    lbl_plotCol2 = new QLabel(tr("Tx"),extension);
    lbl_plotCol2->setObjectName(QString::fromUtf8("lbl_plotCol2"));
    lbl_plotCol2->setToolTip(tr("Gesendete Bytes - Farbe"));
    lbl_clockInterval = new QLabel(" ms / hz  ");
    lbl_clockInterval->setObjectName(QString::fromUtf8("lbl_clockInterval"));
    lbl_clockInterval->setToolTip(tr("aktuelles Sample-Intervall"));
    lbl_clockInterv_2 = new QLabel(tr("Intervall"));
    lbl_clockInterv_2->setObjectName(QString::fromUtf8("lbl_clockInterv_2"));
    lbl_clockInterv_2->setToolTip(tr("Millisekunden zwischen den Werten"));
    Lbl_colorSliders = new QLabel();
    Lbl_colorSliders->setObjectName(QString::fromUtf8("Lbl_colorSliders"));
    Lbl_colorSliders->setMaximumSize(16777215,4);
    
    statusLine = new QLabel(tr(""),this);
    }

    {   /* sld_... */
    sld_alpha = new QSlider(Qt::Horizontal);
    sld_alpha->setObjectName(QString::fromUtf8("sld_alpha"));
    sld_alpha->setRange(0, 255);
    sld_alpha->setTickPosition(QSlider::TicksAbove);
    sld_alpha->setTickInterval(51);
    sld_alpha->setToolTip(tr("Durchsichtigkeit des Rasters"));

    sld_gridCol = new ColorSlider(Qt::Horizontal);
    sld_gridCol->setObjectName(QString::fromUtf8("sld_gridCol"));
    sld_gridCol->setToolTip(tr("Raster- und Skala- Farbe"));
    sld_gridCol->setMinimumHeight ( 18 );

    sld_bkCol = new ColorSlider(Qt::Horizontal);
    sld_bkCol->setObjectName(QString::fromUtf8("sld_bkCol"));
    sld_bkCol->setToolTip(tr("Hintergrundfarbe"));
    sld_bkCol->setMinimumHeight ( 10 );

    sld_plotCol1 = new ColorSlider(Qt::Horizontal);
    sld_plotCol1->setObjectName(QString::fromUtf8("sld_plotCol1"));
    sld_plotCol1->setToolTip(tr("Empfangene Bytes - Farbe"));
    sld_plotCol1->setMinimumHeight ( 10 );

    sld_plotCol2 = new ColorSlider(Qt::Horizontal);
    sld_plotCol2->setObjectName(QString::fromUtf8("sld_plotCol2"));
    sld_plotCol2->setToolTip(tr("Gesendete Bytes - Farbe"));
    sld_plotCol2->setMinimumHeight ( 10 );

    sld_clockInterval = new QSlider(Qt::Horizontal);
    sld_clockInterval->setObjectName(QString::fromUtf8("sld_clockInterval"));
    sld_clockInterval->setRange(0, val_clockRange );
    sld_clockInterval->setTickPosition(QSlider::TicksBelow);
    sld_clockInterval->setTickInterval(10);
    sld_clockInterval->setToolTip(tr("Millisekunden zwischen den Werten"));
    }

    {   /* cbx_... */
    cbx_Hlines = new QCheckBox("=",extension);
    cbx_Hlines->setObjectName(QString::fromUtf8("cbx_Hlines"));
    cbx_Hlines->setCheckState(Qt::Checked);
    cbx_Hlines->setToolTip(tr("horizontale Linien einschalten"));

    cbx_Vlines = new QCheckBox("||",extension);
    cbx_Vlines->setObjectName(QString::fromUtf8("cbx_Vlines"));
    cbx_Vlines->setCheckState(Qt::Checked);
    cbx_Vlines->setToolTip(tr("vertikale Linien einschalten"));

    cbx_HTxt = new QCheckBox("tx-",extension);
    cbx_HTxt->setObjectName(QString::fromUtf8("cbx_HTxt"));
    cbx_HTxt->setCheckState(Qt::Checked);
    cbx_HTxt->setToolTip(tr("Beschriftung der horizontalen Skala einschalten"));

    cbx_VTxt = new QCheckBox("tx|",extension);
    cbx_VTxt->setObjectName(QString::fromUtf8("cbx_VTxt"));
    cbx_VTxt->setCheckState(Qt::Checked);
    cbx_VTxt->setToolTip(tr("Beschriftung der vertikalen Skala einschalten"));
    }

    {   /* btn_... */
    btn_Options = new QPushButton(QIcon(":/options_off.png"),tr(""));
    btn_Options->setObjectName(QString::fromUtf8("btn_Options"));
    btn_Options->setCheckable(true);
    btn_Options->setAutoDefault(false);
    btn_Options->setMaximumSize (20,18);
    btn_Options->setToolTip(tr("Einstellungen: Farben, Samplerate, ..."));

    btn_Quit = new QPushButton(tr("Quit"));
    btn_Quit->setObjectName(QString::fromUtf8("btn_Quit"));
    btn_Quit->setMaximumSize (50,18);
    btn_Quit->setToolTip(tr("Beendet die Anwendung"));

    btn_About = new QPushButton(tr("About"));
    btn_About->setObjectName(QString::fromUtf8("btn_About"));
    btn_About->setMaximumSize (50,18);
    btn_About->setToolTip(tr("weitere Infos"));

    btn_saveSettings = new QPushButton(QIcon(":/saveSettings.png"),tr(""));
    btn_saveSettings->setObjectName(QString::fromUtf8("btn_saveSettings"));
    btn_saveSettings->setMaximumSize (20,18);
    btn_saveSettings->setToolTip(tr("aktuelle Einstellungen (Farben, Intervall, Fensterposition, ...) speichern"));

    btn_restoreSettings = new QPushButton(QIcon(":/restoreSettings.png"),tr(""));
    btn_restoreSettings->setObjectName(QString::fromUtf8("btn_restoreSettings"));
    btn_restoreSettings->setMaximumSize (20,18);
    btn_restoreSettings->setToolTip(tr("gespeicherte Einstellungen wiederherstellen"));

    btn_ClockRun = new QPushButton(tr("Stop"));
    btn_ClockRun->setObjectName(QString::fromUtf8("btn_ClockRun"));
    btn_ClockRun->setCheckable(true);
    btn_ClockRun->setAutoDefault(true);
    btn_ClockRun->setMaximumSize (50,18);
    btn_ClockRun->setToolTip(tr("Schaltet den Zeitgeber ein und aus"));
    }

    {    /* Definitions: Helper*/
    clock = new QTimer(this);
    netTraffics = new NetTraffix();
    }

    {    /* Signalbehandlung: connect */
    connect(clock, SIGNAL(timeout()),
                this, SLOT(newSample()));
    this->on_clockRun( flg_ClockRun );

    connect(sld_alpha, SIGNAL(valueChanged(int)),
                    plotPane, SLOT(setLinesAlpha(int)));
    connect(sld_alpha, SIGNAL(valueChanged(int)),
                    this, SLOT(on_sld_alpha(int)));
    connect(sld_gridCol, SIGNAL(valueChanged(QRgb)),
                    plotPane, SLOT(setLinesColor(QRgb)));
    connect(sld_gridCol, SIGNAL(valueChanged(int)),
                    this, SLOT(on_sld_gridCol(int)));
    connect(sld_bkCol, SIGNAL(valueChanged(QRgb)),
                    plotPane, SLOT(setPaneColor(QRgb)));
    connect(sld_bkCol, SIGNAL(valueChanged(int)),
                    this, SLOT(on_sld_bkCol(int)));
    connect(sld_plotCol1, SIGNAL(valueChanged(QRgb)),
                    plotPane, SLOT(setPlotColor1(QRgb)));
    connect(sld_plotCol1, SIGNAL(valueChanged(int)),
                    this, SLOT(on_sld_plotCol1(int)));
    connect(sld_plotCol2, SIGNAL(valueChanged(QRgb)),
                    plotPane, SLOT(setPlotColor2(QRgb)));
    connect(sld_plotCol2, SIGNAL(valueChanged(int)),
                    this, SLOT(on_sld_plotCol2(int)));
    connect(sld_clockInterval, SIGNAL(valueChanged(int)), 
                    this, SLOT(set_clockInterval(int)));
    connect(btn_Options, SIGNAL(toggled(bool)), 
                    this, SLOT(on_btn_Options(bool)));
    connect(btn_Quit, SIGNAL(clicked()), 
                    qApp, SLOT(quit()));
    connect(btn_About, SIGNAL(clicked()), 
                    this, SLOT(about()));
    connect(btn_saveSettings, SIGNAL(clicked()), 
                    this, SLOT(saveSettings()));
    connect(btn_restoreSettings, SIGNAL(clicked()), 
                    this, SLOT(restoreSettings()));
    connect(btn_ClockRun, SIGNAL(toggled(bool)),
                    this, SLOT(on_clockRun(bool)));
    connect(cbx_Hlines, SIGNAL(stateChanged(int)), 
                    plotPane, SLOT(onCbxHLines(int)));
    connect(cbx_Hlines, SIGNAL(toggled(bool)), 
                    this, SLOT(on_cbx_Hlines(bool)));
    connect(cbx_Vlines, SIGNAL(stateChanged(int)), 
                    plotPane, SLOT(onCbxVLines(int)));
    connect(cbx_Vlines, SIGNAL(toggled(bool)), 
                    this, SLOT(on_cbx_Vlines(bool)));
    connect(cbx_HTxt, SIGNAL(stateChanged(int)), 
                    plotPane, SLOT(onCbxHTxt(int)));
    connect(cbx_HTxt, SIGNAL(toggled(bool)), 
                    this, SLOT(on_cbx_HTxt(bool)));
    connect(cbx_VTxt, SIGNAL(stateChanged(int)), 
                    plotPane, SLOT(onCbxVTxt(int)));
    connect(cbx_VTxt, SIGNAL(toggled(bool)), 
                    this, SLOT(on_cbx_VTxt(bool)));
    }

    {   /* settings */
    settings = new QSettings("A_Krumnow_Soft","TraffiX");   // Vendor, appName

   /*  Nötig, wenn das Programm zum ersten mal läuft und die Ini-/Registry-Keys erzeugt werden müssen ...*/
    bool iniExists = false;
    settingsIni = new QFile(settings->fileName());
    iniExists = settingsIni->exists();                      // Nachsehen ob es die Ini-Datei / den Registry-Key gibt.
    delete settingsIni;
    if(!iniExists)
    {
        val_gridCol       = 235;
        val_alpha         = 190;
        val_plotCol1      =  60;
        val_plotCol2      = 110;
        val_bkCol         =  80;
        val_clockInterval = 100;
        flg_Hlines   = true;
        flg_Vlines   = true;
        flg_HTxt     = true;
        flg_VTxt     = true;
        flg_ClockRun = true;
        saveSettings();
        settings->beginGroup("TraffiX");
        settings->setValue("winSize", QSize(600,250));
        settings->setValue("winPos", QPoint(200,200));
        settings->endGroup();
        settings->sync();
    }
    setWindowIcon(QIcon(":/traffix.png"));
    setWindowTitle("TraffiX");
    restoreSettings(); 
    /* ... die IMMER ausgelesen werden ! */
    }

    {    /* Layout festlegen */
    spacerItem = new QSpacerItem(391, 2, QSizePolicy::Expanding, QSizePolicy::Minimum);

    normalLayout = new QGridLayout;
    normalLayout->setSpacing(0);
    normalLayout->setMargin(0);
    normalLayout->setObjectName(QString::fromUtf8("normalLayout"));
    normalLayout->addWidget( plotPane,          0, 0, 1,10);
    normalLayout->addWidget( lbl_clockInterval, 1, 0, 1, 1);
    normalLayout->addWidget( btn_ClockRun,      1, 1, 1, 1);
    normalLayout->addWidget( statusLine,        1, 2, 1, 1);
    normalLayout->addItem( spacerItem,          1, 3, 1, 1);
    normalLayout->addWidget( btn_saveSettings,  1, 4, 1, 1);
    normalLayout->addWidget( btn_restoreSettings,1,5, 1, 1);
    normalLayout->addItem( spacerItem,          1, 6, 1, 1);
    normalLayout->addWidget( btn_Options,       1, 7, 1, 1);
    normalLayout->addItem( spacerItem,          1, 8, 1, 1);
    normalLayout->addWidget( btn_Quit,          1, 9, 1, 1);

    extensionLayout = new QGridLayout;
    extensionLayout->setSpacing(6);
    extensionLayout->setMargin(6);
    extensionLayout->setObjectName(QString::fromUtf8("extensionLayout"));
    extensionLayout->addItem( spacerItem,          0, 4, 1, 3);
    extensionLayout->addWidget( sld_clockInterval, 1, 0, 1, 7);
    extensionLayout->addWidget( lbl_clockInterv_2, 1, 7, 1, 2);
    extensionLayout->addWidget( cbx_Hlines,       2, 0, 1, 1);
    extensionLayout->addWidget( cbx_HTxt,         2, 1, 1, 1);
    extensionLayout->addWidget( cbx_Vlines,       2, 2, 1, 1);
    extensionLayout->addWidget( cbx_VTxt,         2, 3, 1, 1);
    extensionLayout->addWidget( sld_alpha,         2, 4, 1, 3);
    extensionLayout->addWidget( lbl_alpha,         2, 7, 1, 2);
    extensionLayout->addWidget( Lbl_colorSliders,  3, 0, 1, 6);
    extensionLayout->addWidget( sld_gridCol,       4, 0, 1, 7);
    extensionLayout->addWidget( lbl_gridCol,       4, 7, 1, 2);
    extensionLayout->addWidget( sld_bkCol,         5, 0, 1, 7);
    extensionLayout->addWidget( lbl_bkcol,         5, 7, 1, 2);
    extensionLayout->addWidget( sld_plotCol1,      6, 0, 1, 7);
    extensionLayout->addWidget( lbl_plotCol1,      6, 7, 1, 1);
    extensionLayout->addWidget( sld_plotCol2,      7, 0, 1, 7);
    extensionLayout->addWidget( lbl_plotCol2,      7, 7, 1, 1);
    extensionLayout->addWidget( btn_About,         7, 8, 1, 1);
    extension->setLayout(extensionLayout);

    mainLayout = new QGridLayout;
    mainLayout->setObjectName(QString::fromUtf8("mainLayout"));
    mainLayout->setSpacing(0);
    mainLayout->setMargin(0);
    mainLayout->addLayout(normalLayout, 0, 0, 1, 2);
    mainLayout->addWidget(extension,    1, 0, 1, 2);
    setLayout(mainLayout);
    extension->hide();
    }
}

Traffix::~Traffix()
{
    delete normalLayout;
    delete plotPane;
    delete spacerItem;
    delete btn_ClockRun;
    delete btn_Options;
    delete btn_Quit;
    delete extension;
    delete extensionLayout;
    delete lbl_gridCol;
    delete lbl_alpha;
    delete lbl_bkcol;
    delete lbl_plotCol1;
    delete lbl_plotCol2;
    delete lbl_clockInterval;
    delete lbl_clockInterv_2;
    delete cbx_Hlines;
    delete cbx_Vlines;
    delete cbx_HTxt;
    delete cbx_VTxt;
    delete sld_gridCol;
    delete sld_alpha;
    delete sld_bkCol;
    delete sld_plotCol1;
    delete sld_plotCol2;
    delete sld_clockInterval;
    delete mainLayout;
    delete clock;
    delete statusLine;  /*  --Debug Ausgabe-- */
    delete settings;
    delete netTraffics;
    delete Lbl_colorSliders;
}

void Traffix::newSample()
{
    if(clockMsecs == 0)   
    {
        benchmark = new QTime();
        benchmark->start();
    }
    
    int rx, tx;
    netTraffics->digValues();
    rx = netTraffics->receivedBytes();
    tx = netTraffics->transmittedBytes();
    if(firstRTx){
        bytesRx = rx;
        bytesTx = tx;
        firstRTx = false;
    }
    if(rx < bytesRx) diffRx  = rx;
    else diffRx  = rx - bytesRx;
    bytesRx = rx;

    if(tx < bytesTx) diffTx  = tx;
    else diffTx  = tx - bytesTx;
    bytesTx = tx;
    
    if(clockMsecs == 0)
    {
        int tt = benchmark->elapsed();
        if(tt > 0){
            hz = (double)(1000 / tt);
        } else {
            hz = 10000;
        }
        plotPane->setIntervalTime(tt);
        lbl_clockInterval->setText(QString::number(tt) 
                                    + " ms / " 
                                    + QString::number((double)(hz),'F',hz_genau) 
                                    + " hz  ");
        delete benchmark;
    }
    plotPane->setNextValue(diffRx, diffTx);
}

void Traffix::on_clockRun( bool b)
{
    flg_ClockRun = b;
    if(b){
        firstRTx = true;
        clock->start(clockMsecs);
        btn_ClockRun->setText(" Stop ");
    } else {
        clock->stop();
        btn_ClockRun->setText("Start");
    }
}

void Traffix::set_clockInterval(const int s)
{
    val_clockInterval = s;
    clockMsecs = 10 * s;
    if(clockMsecs > 0) hz = (double)(1000) / clockMsecs;
    else hz = 10000;
    if(hz > 100) hz_genau = 0;
    if(hz > 2) hz_genau = 1;
    if(hz > 1) hz_genau = 2;
    if(hz < 0.5) hz_genau = 3;
    clock->setInterval(clockMsecs);
    plotPane->setIntervalTime(clockMsecs);
    lbl_clockInterval->setText(QString::number(clockMsecs) + " ms / " + QString::number((double)(hz),'F',hz_genau) + " hz  ");
}

void Traffix::resizeEvent ( QResizeEvent * )
{
    plotPane->setNewScaleFactor();
//    statusLine->setText("Height: "+QString::number(height()));
}

void Traffix::on_btn_Options(bool b)
{
    int w, h, s;
    s = h = this->height();
    w = this->width();
    
    extension->setVisible(b);
    if(b){
     //   btn_Options->setText("No Options <<");
        btn_Options->setToolTip(tr("Einstellungen schliessen"));
        btn_Options->setIcon(QIcon(":/options_on.png"));
        winPos = pos();
        s = h + optionsHeight;
        resize( w, s);
    } else {
        extension->hide();
     //   btn_Options->setText("Options >>");
        btn_Options->setToolTip(tr("Einstellungen: Farben, Samplerate, ..."));
        btn_Options->setIcon(QIcon(":/options_off.png"));
        resize( w, (h - optionsHeight));
        if(pos() != winPos) move(winPos);
    }
}

void Traffix::about()
{
    QMessageBox::about(this,
                        (tr("About TraffiX")),
                        (   tr(" <b>TraffiX ver. ") + version + ("</b> <br>") 
                            + last_edited +
(" <br>by Andreas Krumnow <br><hr>\
<br><b>Traffix</b> wertet die Differenz der Anzahl &uuml;bertragener Bytes aus,\
<br>wobei das Zeitintervall zwischen zwei Messungen einstellbar von ")
+ QString::number( val_clockRange ) +
(" Sekunden, bis zu ca. einer millisekunde (je nach Systemressourcen) ist.\
<br>Die Werte werden auf der Zeitachse von rechts nach links fortlaufend dargestellt.\
Die Skala passt sich automatisch dem h&ouml;chsten, innerhalb des sichtbaren Bereichs befindlichen, Wert an.\
<br>Die Quellwerte werden unter Linux der Systemdatei:\
<br><b><i>/proc/net/dev</i></b> entnommen.<br><hr>")
                        )
                      );
}

void Traffix::on_cbx_Hlines(bool b){flg_Hlines = b;}
void Traffix::on_cbx_Vlines(bool b){flg_Vlines = b;}
void Traffix::on_cbx_HTxt(bool b){flg_HTxt = b;}
void Traffix::on_cbx_VTxt(bool b){flg_VTxt = b;}
void Traffix::on_sld_gridCol(int i){val_gridCol = i;}
void Traffix::on_sld_alpha(int i){val_alpha = i;}
void Traffix::on_sld_plotCol1(int i){val_plotCol1 = i;}
void Traffix::on_sld_plotCol2(int i){val_plotCol2 = i;}
void Traffix::on_sld_bkCol(int i){val_bkCol = i;}

void Traffix::saveSettings()
{
    settings->beginGroup("TraffiX");
    settings->setValue("gridCol",val_gridCol);
    settings->setValue("alpha",val_alpha);
    settings->setValue("plotCol1",val_plotCol1);
    settings->setValue("plotCol2",val_plotCol2);
    settings->setValue("bkCol",val_bkCol);
    settings->setValue("clockInterval",val_clockInterval);
    settings->setValue("Hlines",flg_Hlines);
    settings->setValue("Vlines",flg_Vlines);
    settings->setValue("HTxt",flg_HTxt);
    settings->setValue("VTxt",flg_VTxt);
    settings->setValue("ClockRun",flg_ClockRun);
    settings->setValue("winSize",size());
    settings->setValue("winPos",pos());
    settings->endGroup();
    settings->sync();
}

void Traffix::restoreSettings()
{
    settings->beginGroup("TraffiX");
    val_gridCol         = settings->value("gridCol",       235).toInt();
    val_alpha           = settings->value("alpha",         190).toInt();
    val_plotCol1        = settings->value("plotCol1",       60).toInt();
    val_plotCol2        = settings->value("plotCol2",      110).toInt();
    val_bkCol           = settings->value("bkCol",          80).toInt();
    val_clockInterval   = settings->value("clockInterval", 100).toInt();
    flg_Hlines          = settings->value("Hlines",     true ).toBool();
    flg_Vlines          = settings->value("Vlines",     true ).toBool();
    flg_HTxt            = settings->value("HTxt",       true ).toBool();
    flg_VTxt            = settings->value("VTxt",       true ).toBool();
    flg_ClockRun        = settings->value("ClockRun",   true ).toBool();
    resize(               settings->value("winSize", QSize(600,250)).toSize());
    move(                 settings->value("winPos", QPoint(200,200)).toPoint());
    settings->endGroup();

    sld_gridCol->setValue( val_gridCol);
    sld_gridCol->setSliderPosition( val_gridCol);
    plotPane->setLinesColor( sld_gridCol->intSldrToRgb( val_gridCol));
    sld_alpha->setValue( val_alpha);
    sld_alpha->setSliderPosition( val_alpha);
    plotPane->setLinesAlpha( val_alpha);
    sld_bkCol->setValue( val_bkCol);
    sld_bkCol->setSliderPosition( val_bkCol);
    plotPane->setPaneColor( sld_bkCol->intSldrToRgb( val_bkCol));
    sld_plotCol1->setValue( val_plotCol1);
    sld_plotCol1->setSliderPosition( val_plotCol1);
    plotPane->setPlotColor1( sld_plotCol1->intSldrToRgb( val_plotCol1));
    sld_plotCol2->setValue( val_plotCol2);
    sld_plotCol2->setSliderPosition( val_plotCol2);
    plotPane->setPlotColor2( sld_plotCol2->intSldrToRgb( val_plotCol2));
    btn_ClockRun->setChecked(flg_ClockRun);
    cbx_Hlines->setChecked(flg_Hlines);
    plotPane->onCbxHLines( flg_Hlines );
    cbx_Vlines->setChecked( flg_Vlines );
    plotPane->onCbxVLines( flg_Vlines );
    cbx_HTxt->setChecked( flg_HTxt );
    plotPane->onCbxHTxt(flg_HTxt);
    cbx_VTxt->setChecked( flg_VTxt );
    plotPane->onCbxVTxt(flg_VTxt);
    sld_clockInterval->setValue(val_clockInterval);
    sld_clockInterval->setSliderPosition(val_clockInterval);
    clockMsecs = val_clockInterval * 10;
    hz = (double)(1000 / clockMsecs);
    lbl_clockInterval->setText(QString::number(clockMsecs) + (tr(" ms / ")) + QString::number(double(hz),'F',hz_genau) + " hz");
    plotPane->setIntervalTime(clockMsecs);
    set_clockInterval(val_clockInterval);
}