• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

src/DGVAnimatedScan.cpp

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     //setTitle("Scan for " + FileName);
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     //firstIndex i;
00078 
00079     //xValues.resize(data.cols());
00080     //xValues = i;
00081     //yValues.resize(data.cols());
00082 
00084     //cRight->setRawData(xValues.data(), yValues.data(), scanData->cols());
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     //dtor
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 //  Generate new values
00218 void DGVAnimatedScan::timerEvent(QTimerEvent *)
00219 {
00220     //QString tmp;
00221 
00222     newValues();
00223 
00224     // update the display
00225     updateAxes();
00226     replot();
00227 
00228     /*if(saveAnimation && frameNo >= 0 && frameNo < data.rows())
00229     {
00230         saveFrame("ani" + tmp.setNum(frameNo) + ".png");
00231         frameNo ++;
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     /*QToolBar *toolBar = new QToolBar(this);
00259     toolBar->setFixedHeight(80);
00260 
00261 #if QT_VERSION < 0x040000
00262     setDockEnabled(TornOff, true);
00263     setRightJustification(true);
00264 #else
00265     toolBar->setAllowedAreas(Qt::TopToolBarArea | Qt::BottomToolBarArea);
00266 #endif
00267     QWidget *hBox = new QWidget(toolBar);
00268     QLabel *label = new QLabel("Timer Interval", hBox);
00269     QwtCounter *counter = new QwtCounter(hBox);
00270     counter->setRange(-1.0, 500.0, 1.0);
00271 
00272     QHBoxLayout *layout = new QHBoxLayout(hBox);
00273     layout->addWidget(label);
00274     layout->addWidget(counter);
00275     layout->addWidget(new QWidget(hBox), 10); // spacer);
00276 
00277 #if QT_VERSION >= 0x040000
00278     toolBar->addWidget(hBox);
00279 #endif
00280     addToolBar(toolBar);*/
00281 }
00282 
00283 void DGVAnimatedScan::newValues()
00284 {
00285     yValues = (*scanData)(plotRow,Range::all());
00286 
00287     plotRow ++;
00288     plotRow = plotRow % scanData->rows();
00289 }

Generated on Wed Sep 8 2010 01:36:51 for DGV by  doxygen 1.7.1