Go to the documentation of this file.00001
00022 #include <QFileInfo>
00023
00024 #include <qwt_painter.h>
00025 #include <qwt_plot_canvas.h>
00026 #include <qwt_legend.h>
00027 #include <qwt_plot_curve.h>
00028 #include <qwt_scale_widget.h>
00029
00030 #include "DGVAnimatedScan.h"
00031
00032 DGVAnimatedScan::DGVAnimatedScan(QWidget *parent) :
00033 QwtPlot(parent),
00034 d_interval(0),
00035 d_timerId(-1)
00036 {
00037 plotRow = 1;
00038 frameNo = 0;
00039
00041 QwtPainter::setDeviceClipping(false);
00042
00044 canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
00045 canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);
00046
00047 #if QT_VERSION >= 0x040000
00048 #ifdef Q_WS_X11
00049
00053 canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
00054 #endif
00055 #endif
00056
00058 const QColor bgColor(Qt::white);
00059 QPalette p = palette();
00060 p.setColor(backgroundRole(), bgColor);
00061 setPalette(p);
00062
00063 alignScales();
00064
00066
00067 insertLegend(new QwtLegend(), QwtPlot::BottomLegend);
00068
00070 QwtPlotCurve *cRight = new QwtPlotCurve("Data");
00071 cRight->attach(this);
00072
00074 cRight->setPen(QPen(Qt::red));
00075
00077
00078
00079
00080
00081
00082
00084
00085
00086 #if 0
00087
00088 QwtPlotMarker *mY = new QwtPlotMarker();
00089 mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
00090 mY->setLineStyle(QwtPlotMarker::HLine);
00091 mY->setYValue(0.0);
00092 mY->attach(this);
00093 #endif
00094
00096 setAxisTitle(QwtPlot::xBottom, "Bin");
00097 setAxisAutoScale(QwtPlot::xBottom);
00098
00099 setAxisTitle(QwtPlot::yLeft, "Values");
00100 setAxisAutoScale(QwtPlot::yLeft);
00101
00102 setTimerInterval(0.0);
00103 }
00104
00105 DGVAnimatedScan::DGVAnimatedScan(Array<imageType,2> &rowWiseData, QString scanName, QWidget *parent) :
00106 QwtPlot(parent),
00107 d_interval(0),
00108 d_timerId(-1)
00109 {
00110 plotRow = 0;
00111 frameNo = 0;
00112
00114 QwtPainter::setDeviceClipping(false);
00115
00117 canvas()->setPaintAttribute(QwtPlotCanvas::PaintCached, false);
00118 canvas()->setPaintAttribute(QwtPlotCanvas::PaintPacked, false);
00119
00120 #if QT_VERSION >= 0x040000
00121 #ifdef Q_WS_X11
00122
00126 canvas()->setAttribute(Qt::WA_PaintOnScreen, true);
00127 #endif
00128 #endif
00129
00131 const QColor bgColor(Qt::white);
00132 QPalette p = palette();
00133 p.setColor(backgroundRole(), bgColor);
00134 setPalette(p);
00135
00136 alignScales();
00137
00139 name = scanName;
00140 setTitle(name);
00141 insertLegend(new QwtLegend(), QwtPlot::BottomLegend);
00142
00144 QwtPlotCurve *cRight = new QwtPlotCurve("Data");
00145 cRight->attach(this);
00146
00148 cRight->setPen(QPen(Qt::red));
00149
00151 firstIndex i;
00152
00153 scanData = &rowWiseData;
00154 xValues.resize(scanData->cols());
00155 xValues = i;
00156 yValues.resize(scanData->cols());
00157 yValues = (*scanData)(0,Range::all());
00158
00159 cRight->setRawData(xValues.data(), yValues.data(), scanData->cols());
00160
00161 #if 0
00162
00163 QwtPlotMarker *mY = new QwtPlotMarker();
00164 mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
00165 mY->setLineStyle(QwtPlotMarker::HLine);
00166 mY->setYValue(0.0);
00167 mY->attach(this);
00168 #endif
00169
00171 setAxisTitle(QwtPlot::xBottom, "Bin");
00172 setAxisAutoScale(QwtPlot::xBottom);
00173
00174 setAxisTitle(QwtPlot::yLeft, "Values");
00175 setAxisAutoScale(QwtPlot::yLeft);
00176
00177 setTimerInterval(0.0);
00178 }
00179
00180 DGVAnimatedScan::~DGVAnimatedScan()
00181 {
00182
00183 }
00184
00185 QString DGVAnimatedScan::strippedName()
00186 {
00187 return QFileInfo(name).fileName();
00188 }
00189
00190 QString DGVAnimatedScan::strippedNamePrefix()
00191 {
00192 return "Scan: " + QFileInfo(name).fileName();
00193 }
00194
00195 void DGVAnimatedScan::setTimerInterval(double ms)
00196 {
00197 d_interval = qRound(ms);
00198
00199 if ( d_timerId >= 0 )
00200 {
00201 killTimer(d_timerId);
00202 d_timerId = -1;
00203 }
00204 if (d_interval >= 0 )
00205 d_timerId = startTimer(d_interval);
00206 }
00207
00208 void DGVAnimatedScan::saveFrame(QString filename)
00209 {
00210 QPixmap frame;
00211
00212 frame = QPixmap::grabWidget(this);
00213
00214 frame.save(filename,0,100);
00215 }
00216
00217
00218 void DGVAnimatedScan::timerEvent(QTimerEvent *)
00219 {
00220
00221
00222 newValues();
00223
00224
00225 updateAxes();
00226 replot();
00227
00228
00229
00230
00231
00232
00233 }
00234
00235 void DGVAnimatedScan::alignScales()
00236 {
00240
00241 canvas()->setFrameStyle(QFrame::Box | QFrame::Plain );
00242 canvas()->setLineWidth(1);
00243
00244 for ( int i = 0; i < QwtPlot::axisCnt; i++ )
00245 {
00246 QwtScaleWidget *scaleWidget = (QwtScaleWidget *)axisWidget(i);
00247 if ( scaleWidget )
00248 scaleWidget->setMargin(0);
00249
00250 QwtScaleDraw *scaleDraw = (QwtScaleDraw *)axisScaleDraw(i);
00251 if ( scaleDraw )
00252 scaleDraw->enableComponent(QwtAbstractScaleDraw::Backbone, false);
00253 }
00254 }
00255
00256 void setupCounter()
00257 {
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281 }
00282
00283 void DGVAnimatedScan::newValues()
00284 {
00285 yValues = (*scanData)(plotRow,Range::all());
00286
00287 plotRow ++;
00288 plotRow = plotRow % scanData->rows();
00289 }