00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <QtGui>
00026
00027 #include "centralwidget.h"
00028 #include "plotting.h"
00029 #include "datahandler.h"
00030 #include "mferreader.h"
00031 #include "simpleplot.h"
00032 #include "filereader.h"
00033
00034 CentralWidget::CentralWidget(QWidget *parent)
00035 : QWidget(parent)
00036 {
00037 plotting = 0;
00038 dataToPlot = 0;
00039 mferReader = 0;
00040 fileReader = 0;
00041 QVBoxLayout *layout = new QVBoxLayout;
00042 setLayout(layout);
00043 init();
00044 }
00045
00046 void CentralWidget::init()
00047 {
00048 activeMode=NODATA_MODE;
00049
00050 noDataModeImageLabel = new QLabel();
00051 QPixmap helper(tr(":/ourstyle/images/ecg.png"));
00052 noDataModeImageLabel->setPixmap(helper);
00053 noDataModeImageLabel->setAlignment(Qt::AlignCenter);
00054
00055 noDataModeTextLabel = new QLabel();
00056 noDataModeTextLabel->setText(tr("<span align=center><h1>Cardio Curves</h1>"
00057 "<h2>Open a file, or press F1 for help.</h2></span>"));
00058
00059 layout()->addWidget(noDataModeTextLabel);
00060 layout()->addWidget(noDataModeImageLabel);
00061
00062 if (plotting) delete plotting;
00063 plotting = new Plotting(this);
00064
00065 if (dataToPlot) delete dataToPlot;
00066 dataToPlot = new DataHandler();
00067
00068 if (mferReader) delete mferReader;
00069 mferReader = new MferReader();
00070
00071 if (fileReader) delete fileReader;
00072 fileReader = new FileReader();
00073 }
00074
00075 void CentralWidget::setActiveMode(ModeSelector newMode)
00076 {
00077 if (newMode != activeMode)
00078 {
00079 switch (newMode)
00080 {
00081 case NODATA_MODE:
00082
00083 init();
00084 break;
00085 case SINGLECHANNEL_MODE:
00086
00087 layout()->removeWidget(noDataModeImageLabel);
00088 delete noDataModeImageLabel;
00089 layout()->removeWidget(noDataModeTextLabel);
00090 delete noDataModeTextLabel;
00091
00092 layout()->addWidget(plotting);
00093 layout()->update();
00094 break;
00095 case MULTICHANNEL_MODE:
00096
00097 break;
00098 case LIVE_MODE:
00099
00100 break;
00101 }
00102 activeMode = newMode;
00103 }
00104 }
00105
00106 bool CentralWidget::readFile(const QString &fileName)
00107 {
00108 this->fileName = fileName;
00109
00110 if (fileName.endsWith(".mwf", Qt::CaseInsensitive))
00111 {
00112 mferReader->readFile(fileName);
00113 dataToPlot->setSampleprSecond(mferReader->samplesprSecond());
00114
00115 int screens = mferReader->fillData(dataToPlot->getYLines(), 0, 10);
00116 qDebug() << "screens:" << screens;
00117 dataToPlot->setLineAxisBounds(mferReader->lineAxisBounds());
00118 plotting->plotSingelChannel(*dataToPlot);
00119 emit setupSliders(screens, 0, NULL);
00120 return true;
00121 }
00122 else if (fileName.endsWith(".txt", Qt::CaseInsensitive))
00123 {
00124 fileReader->readFile(fileName);
00125 int screens = fileReader->fillData(dataToPlot->getYLines(), 0, 10);
00126 dataToPlot->setLineAxisBounds(fileReader->lineAxisBounds());
00127 plotting->plotSingelChannel(*dataToPlot);
00128 emit setupSliders(screens, 0, NULL);
00129 return true;
00130 }
00131 else
00132 {
00133 return false;
00134 }
00135 }
00136
00137 void CentralWidget::printSlot(QPrinter *thePrinter)
00138 {
00139 QPainter painter(thePrinter);
00140 QRect r = painter.viewport();
00141 QSize s = size();
00142 s.scale(r.size(), Qt::KeepAspectRatio);
00143 painter.setViewport(r.x(), r.y(), s.width(), s.height());
00144 painter.setWindow(rect());
00145
00146 QColor c(Qt::white), old = palette().background().color();
00147 QPalette p;
00148 p.setColor(backgroundRole(), c);
00149 setPalette(p);
00150 this->render(&painter);
00151 p.setColor(backgroundRole(), old);
00152 setPalette(p);
00153 }
00154
00155 void CentralWidget::updateScreen(int screenNumber)
00156 {
00157 if (fileName.endsWith(".mwf", Qt::CaseInsensitive))
00158 {
00159 mferReader->fillData(dataToPlot->getYLines(), screenNumber, 10);
00160 }
00161 else if (fileName.endsWith(".txt", Qt::CaseInsensitive))
00162 {
00163 fileReader->fillData(dataToPlot->getYLines(), screenNumber, 10);
00164 }
00165
00166 plotting->updateScreen(*dataToPlot);
00167 }