00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef QwavWAVEVIEW_H
00019 #define QwavWAVEVIEW_H
00020
00021
00022
00023
00024
00025
00026 #include <qwidget.h>
00027 #include <qpixmap.h>
00028 #include <qscrollbar.h>
00029
00030
00031
00032
00033
00034 #include <vector>
00035 #include <iostream>
00036 #include <string>
00037
00038
00039
00040
00041
00042 #include "qwavdefines.h"
00043 #include "qwavwaveviewinterface.h"
00044 #include "qwavviewlayer.h"
00045 #include "qwavselection.h"
00046 #include "qwavexceptions.h"
00047 #include "qwavwavedatainterface.h"
00048
00049 using namespace std;
00050
00051 Qwav_BEGIN_NAMESPACE
00052
00053
00054
00055
00056
00057 class QwavViewLayer;
00058 class QwavPeakDataLayer;
00059 class QwavAverageLayer;
00060 class QwavZeroLineLayer;
00061 class QwavBackgroundLayer;
00062 class QwavMarkerLayer;
00063 class QwavSelectionLayer;
00064 class QwavLinePeakDataLayer;
00065 class QwavPosLayer;
00066 class QwavPeakInterpolator;
00067
00068
00069
00070
00071
00115 class QWAV_EXPORTIMPORT QwavWaveView
00116 : public QWidget,
00117 public QwavWaveViewInterface
00118 {
00119 Q_OBJECT
00120 Q_PROPERTY( QColor bgColor READ bgColor WRITE setBgColor )
00121 Q_PROPERTY( QColor peakColor READ peakColor WRITE setPeakColor )
00122 Q_PROPERTY( QColor avgColor READ avgColor WRITE setAvgColor )
00123
00124 friend class QwavMonoWaveView;
00125 friend class QwavStereoWaveView;
00126
00127 public:
00128
00132 QwavWaveView(QwavWaveDataInterface* waveData,
00133 QWidget* parent,
00134 const char* name,
00135 int wflags=WDestructiveClose)
00136
00137
00138
00139
00140 throw(InvalidNrOfChannels, FileOpenError)
00141
00142 ;
00143
00144 QwavWaveView(const string& file,
00145 QWidget* parent,
00146 const char* name )
00147
00148 throw(InvalidNrOfChannels,
00149 FileOpenError,
00150 FileReadError)
00151
00152 ;
00153
00154 virtual ~QwavWaveView();
00155
00159
00163 int addLayer (QwavViewLayer* layer);
00164 QwavViewLayer* getLayer (const string& name);
00165 inline QwavViewLayer* getLayer (uint index);
00166 inline uint getNrOfLayers (void) const;
00167 inline QPixmap* getBackbuf (void);
00168
00172
00176 inline int sample2Pixel (long sample) const;
00177 inline long pixel2Sample (int pixel) const;
00178
00179 inline bool isSampleVisible(long sample) const;
00180 inline const int nrOfPixels (void) const;
00181
00182 inline double zoomFac (void) const;
00183 inline double zoomYFac (void) const;
00184 inline double maxZoomFac (void) const;
00185
00186 inline const ulong firstSample(void) const;
00187 inline const long lastSample (void) const;
00188 inline const long samplesVisible (void) const;
00189
00190 inline void setPeakInterpolator(QwavPeakInterpolator* s);
00191 inline QwavPeakInterpolator* peakInterpolator() const;
00194
00198 void setPosition(const ulong sample);
00199 const ulong& position() const ;
00200
00204
00208 uint addSelection (const QwavSelection& s);
00209 inline uint getNrOfSelections(void) const;
00210 const QwavSelection& getSelection (uint index=0) const;
00211 QwavSelection& getSelection (uint index=0);
00212 inline int isSelectionBegin (int pixel ) ;
00213 inline int isSelectionEnd (int pixel ) ;
00214 inline int activeSelection (void) const;
00215 void clearSelections (void);
00216
00219 inline const QwavWaveViewInterface::State& state(void) const;
00220
00221 signals:
00222 void selBeginChanged(long sample);
00223 void selEndChanged (long sample);
00224 void zoomFacChanged (double fac );
00225 void positionChanged(ulong sample);
00226 void firstSampleChanged(ulong sample);
00227
00228 public slots:
00229
00230
00234 void setBgColor (const QColor& c);
00235 const QColor& bgColor (void) const;
00236 void setPeakColor (const QColor& c);
00237 const QColor& peakColor (void) const;
00238 void setAvgColor (const QColor& c);
00239 const QColor& avgColor (void) const;
00240
00244
00248 void setSamplesVisible(const long& newVal);
00249 void setZoomFac (double zoomFac);
00250 inline void setZoomYFac (double zoomYFac);
00251 void setFirstSample (ulong sample);
00252 inline void setChannel (uint channel=1);
00253 inline uint channel (void) const;
00254 void scrollBy (int pixel);
00255 void displayHelp (void);
00258 protected:
00259 virtual void paintEvent (QPaintEvent* e);
00260 virtual void resizeEvent (QResizeEvent* e);
00261 virtual void mousePressEvent (QMouseEvent* e);
00262 virtual void mouseMoveEvent (QMouseEvent* e);
00263 virtual void mouseReleaseEvent (QMouseEvent* e);
00264 virtual void mouseDoubleClickEvent(QMouseEvent* e);
00265 virtual void wheelEvent (QWheelEvent* e);
00266 virtual void keyPressEvent (QKeyEvent* e);
00267 virtual void keyReleaseEvent (QKeyEvent* e);
00268 void setState (State s);
00269
00270 virtual void initLayers();
00271
00272 private:
00273
00274 typedef vector<QwavViewLayer*> LayerVector;
00275
00278 typedef vector<QwavSelection> QwavSelectionVector;
00279
00282 typedef map<string,long> TimeMap;
00283
00284 TimeMap _timeMap;
00285
00286 uint _nrOfRuns;
00287
00288 QwavPeakInterpolator* _interpolator;
00289 QwavWaveViewInterface::State _state;
00290 QwavSelectionVector _selections;
00291 int _activeSelection;
00292 QPoint _lastPos;
00293
00294 LayerVector _layer;
00295 unsigned long _firstVisible;
00296 double _zoomFac;
00297 double _zoomYFac;
00298
00299 QwavPeakDataLayer* _peakLayer;
00300 QwavAverageLayer* _averageLayer;
00301 QwavZeroLineLayer* _zeroLineLayer;
00302 QwavBackgroundLayer* _bgLayer;
00303 QwavMarkerLayer* _endMarkerLayer;
00304 QwavSelectionLayer* _selectionLayer;
00305 QwavLinePeakDataLayer* _linePeakLayer;
00306 QwavPosLayer* _posLayer;
00307
00308 QPixmap _backbuf;
00309 bool _doFastRepaint;
00310 uint _channel;
00311
00312 };
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324 uint QwavWaveView::getNrOfLayers() const
00325 {
00326 return _layer.size();
00327 }
00328
00329
00330
00331
00332
00333 QwavViewLayer* QwavWaveView::getLayer(uint index)
00334 {
00335 if( index < _layer.size() )
00336 return _layer[index];
00337 else
00338 return 0;
00339 }
00340
00341
00342
00343
00344
00345
00346 const long QwavWaveView::samplesVisible() const
00347 {
00348 return long( rint(_zoomFac * width()) );
00349 }
00350
00351
00352
00353
00354
00355
00362 QPixmap* QwavWaveView::getBackbuf()
00363 {
00364 return &_backbuf;
00365 }
00366
00367
00368
00369
00370
00371
00379 int QwavWaveView::sample2Pixel(long sample) const
00380 {
00381 return ::sample2Pixel(sample, firstSample(), zoomFac());
00382 }
00383
00384
00385
00386
00387
00388
00394 long QwavWaveView::pixel2Sample(int pixel) const
00395 {
00396 return ::pixel2Sample(pixel, firstSample(), zoomFac() );
00397 }
00398
00399
00400
00401
00402
00403
00404
00405 double QwavWaveView::zoomFac() const
00406 {
00407 return _zoomFac;
00408 }
00409
00410
00411
00412
00413
00414 double QwavWaveView::zoomYFac() const
00415 {
00416 return _zoomYFac;
00417 }
00418
00419
00420
00421
00422
00423
00424
00425 void QwavWaveView::setZoomYFac (double zoomYFac)
00426 {
00427
00428
00429 if(_zoomYFac != zoomYFac )
00430 {
00431 _zoomYFac = zoomYFac;
00432 update();
00433 }
00434 }
00435
00436
00437
00438
00439
00440 double QwavWaveView::maxZoomFac(void) const
00441 {
00442 return nrOfSamples()/width()*2.0;
00443 }
00444
00445
00446
00447
00448
00449
00450 const ulong QwavWaveView::firstSample() const
00451 {
00452 return _firstVisible;
00453 }
00454
00455
00456
00457
00458
00459 const long QwavWaveView::lastSample() const
00460 {
00461 return long( firstSample() + width() * zoomFac() );
00462 }
00463
00464
00465
00466
00467
00468
00469 bool QwavWaveView::isSampleVisible(long sample) const
00470 {
00471 if( sample2Pixel(sample) < width() )
00472 return true;
00473 else
00474 return false;
00475 }
00476
00477
00478
00479
00480
00481
00482 const int QwavWaveView::nrOfPixels() const
00483 {
00484 return width();
00485 }
00486
00487
00488
00489
00490
00491 uint QwavWaveView::getNrOfSelections() const
00492 {
00493 return _selections.size();
00494 }
00495
00496
00497
00498
00499
00500
00501 int QwavWaveView::isSelectionBegin( int pixel )
00502 {
00503 int firstPixel;
00504 for( uint i=0; i<_selections.size(); ++i )
00505 {
00506 firstPixel = sample2Pixel( _selections[i].firstSample() );
00507 if( firstPixel == pixel )
00508 return i;
00509 }
00510
00511 return -1;
00512 }
00513
00514
00515
00516
00517
00518
00519 int QwavWaveView::isSelectionEnd ( int pixel )
00520 {
00521 int lastPixel;
00522 for( uint i=0; i<_selections.size(); ++i )
00523 {
00524 lastPixel = sample2Pixel( _selections[i].lastSample() );
00525 if( lastPixel == pixel )
00526 return i;
00527 }
00528
00529 return -1;
00530 }
00531
00532
00533
00534
00535
00536
00537
00538 const QwavWaveViewInterface::State& QwavWaveView::state() const
00539 {
00540 return _state;
00541 }
00542
00543
00544
00545
00546
00547
00548
00549 int QwavWaveView::activeSelection() const
00550 {
00551 return _activeSelection;
00552 }
00553
00554
00555
00556
00557
00558
00559 void QwavWaveView::setChannel(uint channel)
00560 {
00561 if( _channel != channel )
00562 {
00563 _channel = channel;
00564 update();
00565 }
00566 }
00567
00568
00569
00570
00571
00572
00573 uint QwavWaveView::channel (void) const
00574 {
00575 return _channel;
00576 }
00577
00578
00579
00580
00581
00582
00583 void QwavWaveView::setPeakInterpolator(QwavPeakInterpolator* s)
00584 {
00585 delete _interpolator;
00586 cout << "QwavWaveView::setPeakInterpolator(" << s->getName() << ")\n";
00587 _interpolator = s;
00588 }
00589
00590
00591
00592
00593
00594
00595 QwavPeakInterpolator* QwavWaveView::peakInterpolator() const
00596 {
00597 return _interpolator;
00598 }
00599
00600
00601
00602 Qwav_END_NAMESPACE
00603
00604 #endif // QwavWAVEVIEW_H
00605