rock_widget_collection  0.1
Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions | Properties | List of all members
QWaterfallDisplay Class Reference

#include <qwaterfalldisplay.h>

Inherits QFrame.

Public Types

enum  Resizestyle {
  Scale, ScaleAspect, ScaleEven, Cut,
  CutMixed
}
 

Public Slots

void setColumns (int cols)
 
void setRows (int rows)
 
void setColumnsRows (int cols, int rows)
 
int columns () const
 
int rows () const
 
void setResizestyle (Resizestyle resizestyle)
 
Resizestyle resizestyle () const
 
void setBackColor (QColor back)
 
QColor backColor () const
 
void setMaxValue (double max)
 
void setMinValue (double min)
 
void setMaxMinValue (double max, double min)
 
double maxValue () const
 
double minValue () const
 
void pushData (const std::vector< float > &new_data)
 
void pushDataFloat (const float *new_data, int elements)
 
void pushDataQList (const QList< float > &new_data)
 
void pushDataUint8 (const char *new_data, int length)
 
void pushDataUint16 (const char *new_data, int length)
 
void pushDataUint32 (const char *new_data, int length)
 
void clearData ()
 
void redrawData ()
 
void pauseDrawing (bool onoff)
 

Signals

void rowsChanged (uint)
 
void columnsChanged (uint)
 
void minChanged (double)
 
void maxChanged (double)
 
void drawingPaused ()
 
void drawingStarted ()
 
void drawing (bool)
 
void paused (bool)
 

Public Member Functions

 QWaterfallDisplay (int rows=1, int columns=1, QWidget *parent=0)
 
 ~QWaterfallDisplay ()
 
QSize minimumSizeHint ()
 
QSize sizeHint ()
 
bool isPaused ()
 
bool isDrawing ()
 

Protected Member Functions

void paintEvent (QPaintEvent *event)
 
void resizeEvent (QResizeEvent *event)
 

Properties

uint rows
 
uint columns
 
Resizestyle resizestyle
 
QColor backColor
 
double maxValue
 
double minValue
 

Detailed Description

Definition at line 27 of file qwaterfalldisplay.h.

Member Enumeration Documentation

Enumerator
Scale 
ScaleAspect 
ScaleEven 
Cut 
CutMixed 

Definition at line 40 of file qwaterfalldisplay.h.

40  {
41  Scale, // Just Scales (could be akward)
42  ScaleAspect, // Scales, keeping the aspect ratio and centers
43  ScaleEven, // Scales only n times where widgetsize > n*rows and then centers for n<1 scales like ScaleAspect
44  Cut, // Just cuts if the widget is smaller and centers if bigger
45  CutMixed // Scales cols even and cuts rows
46  };

Constructor & Destructor Documentation

QWaterfallDisplay::QWaterfallDisplay ( int  rows = 1,
int  columns = 1,
QWidget *  parent = 0 
)
explicit

Definition at line 15 of file qwaterfalldisplay.cc.

15  :
16  QFrame(parent), m_cols(columns), m_rows(rows), m_resizes(ScaleAspect), back_color(QColor("black")),
17  m_max(1.0), m_min(0.0),
18  dirty_lines(0), widget_resized(true), redraw_all(true), is_drawing(true),
19  m_size_hint(0,0), m_minimum_size(0,0),
20  m_buffer(QSize(rows,columns),QImage::Format_RGB32), waterfall(QSize(rows,columns),QImage::Format_RGB32), data()
21 {
22 
23  // Init the buffer
24  m_buffer.fill(0);
25 
26  // Init the watterwafll image
27  waterfall.fill(0);
28 
29  // Init the data Array
30  initData(m_cols, m_rows);
31 
32  // calculates the size hints
33  calcSizeHint();
34 }
int columns() const
int rows() const
QWaterfallDisplay::~QWaterfallDisplay ( )

Definition at line 36 of file qwaterfalldisplay.cc.

37 {
38 }

Member Function Documentation

QColor QWaterfallDisplay::backColor ( ) const
slot
void QWaterfallDisplay::clearData ( )
slot

Definition at line 322 of file qwaterfalldisplay.cc.

323 {
324  data.clear(); // I am not sure if this really deletes the content -> check (jca)
325 
326  // redraw!
327  redrawData();
328 }
int QWaterfallDisplay::columns ( ) const
slot
void QWaterfallDisplay::columnsChanged ( uint  )
signal
void QWaterfallDisplay::drawing ( bool  )
signal
void QWaterfallDisplay::drawingPaused ( )
signal
void QWaterfallDisplay::drawingStarted ( )
signal
bool QWaterfallDisplay::isDrawing ( )

Definition at line 54 of file qwaterfalldisplay.cc.

55 {
56  return is_drawing;
57 }
bool QWaterfallDisplay::isPaused ( )

Definition at line 59 of file qwaterfalldisplay.cc.

60 {
61  return !is_drawing;
62 }
void QWaterfallDisplay::maxChanged ( double  )
signal
double QWaterfallDisplay::maxValue ( ) const
slot
void QWaterfallDisplay::minChanged ( double  )
signal
QSize QWaterfallDisplay::minimumSizeHint ( )

Definition at line 44 of file qwaterfalldisplay.cc.

45 {
46  return m_minimum_size;
47 }
double QWaterfallDisplay::minValue ( ) const
slot
void QWaterfallDisplay::paintEvent ( QPaintEvent *  event)
protected

Definition at line 355 of file qwaterfalldisplay.cc.

356 {
357  //
358  // This function is currently the ONE AND ONLY function for PAINTING!!!
359  //
360 
361  // init the painter for the widget
362  QPainter widget_painter(this);
363 
364  // this is needed for a lot of copying in the function
365  QRect target;
366  QRect source;
367 
368  // Do we have to redraw all or part of the widget due to changes in data or size
369  if (redraw_all || widget_resized || (dirty_lines>0)) {
370 
371 
372  // new content and we draw
373  if (is_drawing && (redraw_all || (dirty_lines>0))) {
374  //if ((redraw_all || (dirty_lines>0))) {
375  QSize waterfall_size(m_cols,m_rows);
376  QImage new_waterfall(waterfall_size,QImage::Format_RGB32);
377  new_waterfall.fill(0);
378  QPainter waterfall_painter(&new_waterfall);
379  waterfall_painter.fillRect(new_waterfall.rect(),back_color);
380 
381  if (!(data.empty())) { // for safety reasons
382  QRgb* t_line = NULL;
383  list< vector<float> >::const_iterator it;
384 
385  // we have to redraw the widget
386  if (redraw_all) {
387  int it_count = 0;
388  // draw the widget line-by-line
389  for(it = data.begin(); it != data.end(); it++) {
390  t_line = (QRgb*)(new_waterfall.scanLine(it_count));
391  drawLine(t_line, *it);
392  it_count++;
393  }
394 
395  // there are no dirty lines anymore 8]
396  // neede to prevent a go in the next if, for the case of dirty_lines AND redraw_all
397  dirty_lines = 0;
398  }
399  else if (dirty_lines>0) {
400  // first copy the first height-dirty_lines from the old
401  // waterfall
402  target.setTopLeft(QPoint(0,dirty_lines));
403  target.setWidth(new_waterfall.width());
404  target.setHeight((new_waterfall.height())-dirty_lines);
405  source.setTopLeft(QPoint(0,0));
406  source.setWidth(waterfall.width());
407  source.setHeight((waterfall.height())-dirty_lines);
408 
409  waterfall_painter.drawImage(target,waterfall,source);
410 
411  int it_count = 0;
412  for(it = data.begin(); ((dirty_lines>0) && (it != data.end())); it++) {
413  t_line = (QRgb*)(new_waterfall.scanLine(it_count));
414  drawLine(t_line, *it);
415  it_count++;
416  dirty_lines--;
417  }
418  }
419 
420  }
421 
422  // end painting
423  waterfall_painter.end();
424 
425 
426  // switch the waterfall
427  waterfall = new_waterfall;
428 
429  // clear the flags
430  redraw_all = false;
431  dirty_lines = 0;
432 
433  // force a new paint via resize
434  widget_resized = true;
435  }
436 
437 
438  // widget resized or new content (flag set to dirty above)
439  if (widget_resized) {
440  QImage new_buffer(size(),QImage::Format_RGB32);
441  new_buffer.fill(0);
442 
443  QPainter buffer_painter(&new_buffer);
444  buffer_painter.fillRect(new_buffer.rect(), back_color);
445 
446  QSize copy_size;
447  float wf_aspect = 0;
448  float bf_aspect = 0;
449  int m_y = 0;
450  int m_x = 0;
451  int m_width = 0;
452  int m_height = 0;
453 
454 
455  // Here is the big switch for resizing and painting it into the new buffer
456  switch(m_resizes) {
457  case Scale:
458  // this is akward, but easy to implement
459  target = new_buffer.rect();
460  source = waterfall.rect();
461  buffer_painter.drawImage(target,waterfall,source);
462  break;
463 
464  case ScaleAspect:
465  // scales with respect to the aspect ratio of waterfall,
466  // looks nicer than Scale but still...
467  source = waterfall.rect();
468  wf_aspect = (float)(waterfall.width())/(float)(waterfall.height());
469  bf_aspect = (float)(new_buffer.width())/(float)(new_buffer.height());
470  if (wf_aspect >= bf_aspect) {
471  // scale to width of new_buffer and center in height
472  m_width = new_buffer.width();
473  m_height = (int)((float)((new_buffer.width())*(waterfall.height()))/(float)(waterfall.width()));
474  m_y = ((new_buffer.height()) - m_height) / 2;
475  }
476  else {
477  // scale to height of new buffer and center in width
478  m_height = new_buffer.height();
479  m_width = wf_aspect * (float)(new_buffer.height());
480  m_x = ((new_buffer.width()) - m_width) / 2;
481  }
482  target.setTopLeft(QPoint(m_x,m_y));
483  target.setHeight(m_height);
484  target.setWidth(m_width);
485  buffer_painter.drawImage(target,waterfall,source);
486  break;
487 
488  case ScaleEven:
489  // Scales only n times columns while keeping the aspect ratio and the centers:
490  // widgetsize > n*cols -> centered
491  // is a bit more true to the values painted
492  source = waterfall.rect();
493  qDebug()<<"QWaterfallDisplay: Resize Type:"<<m_resizes<<"not implemented ATM!";
494  break;
495 
496  case Cut:
497  // just put it into the window and cut of what can not be seen
498  target.setTopLeft(QPoint(0,0));
499  source.setTopLeft(QPoint(0,0));
500  if (new_buffer.width() > waterfall.width())
501  copy_size.setWidth(waterfall.width());
502  else
503  copy_size.setWidth(new_buffer.width());
504  if (new_buffer.height() > waterfall.height())
505  copy_size.setHeight(waterfall.height());
506  else
507  copy_size.setHeight(new_buffer.height());
508  target.setSize(copy_size);
509  source.setSize(copy_size);
510 
511  // draw it
512  buffer_painter.drawImage(target,waterfall,source);
513  break;
514 
515  case CutMixed:
516  qDebug()<<"QWaterfallDisplay: Resize Type: "<<m_resizes<<" not implemented ATM!";
517  break;
518 
519  default:
520  qDebug()<<"QWaterfallDisplay: Unkown Resize Type: "<<m_resizes;
521  break;
522  }
523 
524  // end painting
525  buffer_painter.end();
526 
527  // switch the buffer
528  m_buffer = new_buffer;
529 
530  // clear the flags
531  widget_resized = false;
532  }
533 
534 
535  // Copy the the buffer onto the widget
536  widget_painter.drawImage(event->rect(),m_buffer,event->rect());
537  }
538  else {
539  // we have to copy only the rect of the paint event
540  // remember m_buffer is exactly the size of the widget!
541  widget_painter.drawImage(event->rect(),m_buffer,event->rect());
542  }
543 
544  // just to be safe
545  widget_painter.end();
546 }
void QWaterfallDisplay::paused ( bool  )
signal
void QWaterfallDisplay::pauseDrawing ( bool  onoff)
slot

Definition at line 339 of file qwaterfalldisplay.cc.

340 {
341  is_drawing = onoff;
342 
343  emit drawing(is_drawing);
344  emit paused(!is_drawing);
345 
346  if (is_drawing)
347  emit drawingStarted();
348  else
349  emit drawingPaused();
350 }
void paused(bool)
void drawing(bool)
void QWaterfallDisplay::pushData ( const std::vector< float > &  new_data)
slot

Definition at line 204 of file qwaterfalldisplay.cc.

205 {
206  // push it to the std::list
207  data.push_front(new_data);
208 
209  if (data.front().size() > m_cols) {
210  // shorten the thing
211  data.front().resize(m_cols);
212  }
213 
214 
215  // check wether we have grown too much
216  while (data.size() > m_rows) {
217  data.pop_back();
218  }
219 
220  // increase the number of lines to be updated
221  dirty_lines++;
222 
223  // redraw!
224  update();
225 }
void QWaterfallDisplay::pushDataFloat ( const float *  new_data,
int  elements 
)
slot

Definition at line 247 of file qwaterfalldisplay.cc.

248 {
249  vector<float> temp(new_data, new_data + length);
250  if ((uint)(length)>m_cols)
251  temp.resize(m_cols);
252 
253  // do the real push
254  pushData(temp);
255 }
void pushData(const std::vector< float > &new_data)
void QWaterfallDisplay::pushDataQList ( const QList< float > &  new_data)
slot

Definition at line 227 of file qwaterfalldisplay.cc.

228 {
229  uint i=0;
230  vector<float> temp(new_data.size());
231 
232  if ((uint)(new_data.size()) > m_cols) {
233  temp.resize(m_cols);
234  for(i=0;i<m_cols;i++)
235  temp[i] = new_data[i];
236  }
237  else {
238  //temp.resize(new_data.size());
239  for(i=0;i<temp.size();i++)
240  temp[i] = new_data[i];
241  }
242 
243  // do the real push
244  pushData(temp);
245 }
void pushData(const std::vector< float > &new_data)
void QWaterfallDisplay::pushDataUint16 ( const char *  new_data,
int  length 
)
slot

Definition at line 278 of file qwaterfalldisplay.cc.

279 {
280  uint i=0;
281  uint16_t* new_data = (uint16_t*)new_data_in;
282  uint length = length_in/2;
283  vector<float> temp(length);
284 
285  if (length > m_cols) {
286  temp.resize(m_cols);
287  for(i=0;i<m_cols;i++)
288  temp[i] = (float)(new_data[i]);
289  }
290  else {
291  //temp.resize(length);
292  for(i=0;i<length;i++)
293  temp[i] = (float)(new_data[i]);
294  }
295 
296  // do the real push
297  pushData(temp);
298 }
void pushData(const std::vector< float > &new_data)
void QWaterfallDisplay::pushDataUint32 ( const char *  new_data,
int  length 
)
slot

Definition at line 300 of file qwaterfalldisplay.cc.

301 {
302  uint i=0;
303  uint32_t* new_data = (uint32_t*)new_data_in;
304  uint length = length_in/4;
305  vector<float> temp(length);
306 
307  if (length > m_cols) {
308  temp.resize(m_cols);
309  for(i=0;i<m_cols;i++)
310  temp[i] = (float)(new_data[i]);
311  }
312  else {
313  //temp.resize(length);
314  for(i=0;i<length;i++)
315  temp[i] = (float)(new_data[i]);
316  }
317 
318  // do the real push
319  pushData(temp);
320 }
void pushData(const std::vector< float > &new_data)
void QWaterfallDisplay::pushDataUint8 ( const char *  new_data,
int  length 
)
slot

Definition at line 258 of file qwaterfalldisplay.cc.

259 {
260  uint i=0;
261  vector<float> temp(length);
262 
263  if (length > m_cols) {
264  temp.resize(m_cols);
265  for(i=0;i<m_cols;i++)
266  temp[i] = (float)(new_data[i]);
267  }
268  else {
269  //temp.resize(length);
270  for(i=0;i<length;i++)
271  temp[i] = (float)(new_data[i]);
272  }
273 
274  // do the real push
275  pushData(temp);
276 }
void pushData(const std::vector< float > &new_data)
void QWaterfallDisplay::redrawData ( )
slot

Definition at line 332 of file qwaterfalldisplay.cc.

333 {
334  redraw_all = true; // signals paintEvent to do a complete overhaul
335  //if(!(data.isEmpty()))
336  update(); // envoces a repaint
337 }
void QWaterfallDisplay::resizeEvent ( QResizeEvent *  event)
protected

Definition at line 548 of file qwaterfalldisplay.cc.

549 {
550  widget_resized = true; // signals the paintEvent, that a resize has occured
551 }
Resizestyle QWaterfallDisplay::resizestyle ( ) const
slot
int QWaterfallDisplay::rows ( ) const
slot
void QWaterfallDisplay::rowsChanged ( uint  )
signal
void QWaterfallDisplay::setBackColor ( QColor  back)
slot

Definition at line 138 of file qwaterfalldisplay.cc.

139 {
140  back_color = back;
141  redrawData();
142 }
void QWaterfallDisplay::setColumns ( int  cols)
slot

Definition at line 70 of file qwaterfalldisplay.cc.

71 {
72  initData(cols,m_rows); // resize the data storage
73  m_cols = cols;
74  emit columnsChanged(cols);
75 
76  // recalc size hints
77  calcSizeHint();
78 
79  // redraw!
80  redrawData();
81 }
void columnsChanged(uint)
void QWaterfallDisplay::setColumnsRows ( int  cols,
int  rows 
)
slot

Definition at line 106 of file qwaterfalldisplay.cc.

107 {
108  initData(cols,rows); // resize the data storage
109  m_cols = cols;
110  m_rows = rows;
111  emit columnsChanged(cols);
112  emit rowsChanged(rows);
113 
114  // recalc size hints
115  calcSizeHint();
116 
117  // redraw!
118  redrawData();
119 }
int rows() const
void rowsChanged(uint)
void columnsChanged(uint)
void QWaterfallDisplay::setMaxMinValue ( double  max,
double  min 
)
slot

Definition at line 189 of file qwaterfalldisplay.cc.

190 {
191  m_max = max;
192  m_min = min;
193  // sanity check
194  if (m_min >= m_max)
195  m_min = m_max-1.0;
196  emit maxChanged(m_max);
197  emit minChanged(m_min);
198 
199  // redraw!
200  redrawData();
201 }
void minChanged(double)
void maxChanged(double)
void QWaterfallDisplay::setMaxValue ( double  max)
slot

Definition at line 151 of file qwaterfalldisplay.cc.

152 {
153  m_max = max;
154  // sanity check
155  if (m_min >= m_max) {
156  m_min = m_max-1.0;
157  emit minChanged(m_min);
158  }
159  emit maxChanged(m_max);
160 
161  // redraw!
162  redrawData();
163 }
void minChanged(double)
void maxChanged(double)
void QWaterfallDisplay::setMinValue ( double  min)
slot

Definition at line 170 of file qwaterfalldisplay.cc.

171 {
172  m_min = min;
173  // sanity check
174  if (m_min >= m_max) {
175  m_max = m_min+1.0;
176  emit maxChanged(m_max);
177  }
178  emit minChanged(m_min);
179 
180  // redraw!
181  redrawData();
182 }
void minChanged(double)
void maxChanged(double)
void QWaterfallDisplay::setResizestyle ( Resizestyle  resizestyle)
slot

Definition at line 123 of file qwaterfalldisplay.cc.

124 {
125  m_resizes = resizestyle;
126  // same as geometry change
127  widget_resized = true;
128  update();
129 }
Resizestyle resizestyle() const
void QWaterfallDisplay::setRows ( int  rows)
slot

Definition at line 88 of file qwaterfalldisplay.cc.

89 {
90  initData(m_cols,rows); // resize the data storage
91  m_rows = rows;
92  emit rowsChanged(rows);
93 
94  // recalc size hints
95  calcSizeHint();
96 
97  // redraw!
98  redrawData();
99 }
int rows() const
void rowsChanged(uint)
QSize QWaterfallDisplay::sizeHint ( )

Definition at line 49 of file qwaterfalldisplay.cc.

50 {
51  return m_size_hint;
52 }

Property Documentation

QColor QWaterfallDisplay::backColor
readwrite

Definition at line 34 of file qwaterfalldisplay.h.

int QWaterfallDisplay::columns
readwrite

Definition at line 32 of file qwaterfalldisplay.h.

double QWaterfallDisplay::maxValue
readwrite

Definition at line 35 of file qwaterfalldisplay.h.

double QWaterfallDisplay::minValue
readwrite

Definition at line 36 of file qwaterfalldisplay.h.

QWaterfallDisplay::Resizestyle QWaterfallDisplay::resizestyle
readwrite

Definition at line 33 of file qwaterfalldisplay.h.

int QWaterfallDisplay::rows
readwrite

Definition at line 31 of file qwaterfalldisplay.h.


The documentation for this class was generated from the following files: