GNU Radio 3.7.2.2 C++ API
form_menus.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef FORM_MENUS_H
24 #define FORM_MENUS_H
25 
26 #include <stdexcept>
27 #include <vector>
28 #include <QtGui/QtGui>
29 #include <QtGui/QIntValidator>
30 #include <QtGui/QDoubleValidator>
31 #include <qwt_symbol.h>
32 #include <gnuradio/filter/firdes.h>
35 
36 class LineColorMenu: public QMenu
37 {
38  Q_OBJECT
39 
40 public:
41  LineColorMenu(int which, QWidget *parent)
42  : QMenu("Line Color", parent), d_which(which)
43  {
44  d_act.push_back(new QAction("Blue", this));
45  d_act.push_back(new QAction("Red", this));
46  d_act.push_back(new QAction("Green", this));
47  d_act.push_back(new QAction("Black", this));
48  d_act.push_back(new QAction("Cyan", this));
49  d_act.push_back(new QAction("Magenta", this));
50  d_act.push_back(new QAction("Yellow", this));
51  d_act.push_back(new QAction("Gray", this));
52  d_act.push_back(new QAction("Dark Red", this));
53  d_act.push_back(new QAction("Dark Green", this));
54  d_act.push_back(new QAction("Dark Blue", this));
55  d_act.push_back(new QAction("Dark Gray", this));
56 
57  connect(d_act[0], SIGNAL(triggered()), this, SLOT(getBlue()));
58  connect(d_act[1], SIGNAL(triggered()), this, SLOT(getRed()));
59  connect(d_act[2], SIGNAL(triggered()), this, SLOT(getGreen()));
60  connect(d_act[3], SIGNAL(triggered()), this, SLOT(getBlack()));
61  connect(d_act[4], SIGNAL(triggered()), this, SLOT(getCyan()));
62  connect(d_act[5], SIGNAL(triggered()), this, SLOT(getMagenta()));
63  connect(d_act[6], SIGNAL(triggered()), this, SLOT(getYellow()));
64  connect(d_act[7], SIGNAL(triggered()), this, SLOT(getGray()));
65  connect(d_act[8], SIGNAL(triggered()), this, SLOT(getDarkRed()));
66  connect(d_act[9], SIGNAL(triggered()), this, SLOT(getDarkGreen()));
67  connect(d_act[10], SIGNAL(triggered()), this, SLOT(getDarkBlue()));
68  connect(d_act[11], SIGNAL(triggered()), this, SLOT(getDarkGray()));
69 
70  QListIterator<QAction*> i(d_act);
71  while(i.hasNext()) {
72  QAction *a = i.next();
73  addAction(a);
74  }
75  }
76 
78  {}
79 
80  int getNumActions() const
81  {
82  return d_act.size();
83  }
84 
85  QAction * getAction(int which)
86  {
87  if(which < d_act.size())
88  return d_act[which];
89  else
90  throw std::runtime_error("LineColorMenu::getAction: which out of range.\n");
91  }
92 
93 signals:
94  void whichTrigger(int which, const QString &name);
95 
96 public slots:
97  void getBlue() { emit whichTrigger(d_which, "blue"); }
98  void getRed() { emit whichTrigger(d_which, "red"); }
99  void getGreen() { emit whichTrigger(d_which, "green"); }
100  void getBlack() { emit whichTrigger(d_which, "black"); }
101  void getCyan() { emit whichTrigger(d_which, "cyan"); }
102  void getMagenta() { emit whichTrigger(d_which, "magenta"); }
103  void getYellow() { emit whichTrigger(d_which, "yellow"); }
104  void getGray() { emit whichTrigger(d_which, "gray"); }
105  void getDarkRed() { emit whichTrigger(d_which, "darkred"); }
106  void getDarkGreen() { emit whichTrigger(d_which, "darkgreen"); }
107  void getDarkBlue() { emit whichTrigger(d_which, "darkblue"); }
108  void getDarkGray() { emit whichTrigger(d_which, "darkgray"); }
109 
110 private:
111  QList<QAction *> d_act;
112  int d_which;
113 };
114 
115 
116 /********************************************************************/
117 
118 
119 class LineWidthMenu: public QMenu
120 {
121  Q_OBJECT
122 
123 public:
124  LineWidthMenu(int which, QWidget *parent)
125  : QMenu("Line Width", parent), d_which(which)
126  {
127  d_act.push_back(new QAction("1", this));
128  d_act.push_back(new QAction("2", this));
129  d_act.push_back(new QAction("3", this));
130  d_act.push_back(new QAction("4", this));
131  d_act.push_back(new QAction("5", this));
132  d_act.push_back(new QAction("6", this));
133  d_act.push_back(new QAction("7", this));
134  d_act.push_back(new QAction("8", this));
135  d_act.push_back(new QAction("9", this));
136  d_act.push_back(new QAction("10", this));
137 
138  connect(d_act[0], SIGNAL(triggered()), this, SLOT(getOne()));
139  connect(d_act[1], SIGNAL(triggered()), this, SLOT(getTwo()));
140  connect(d_act[2], SIGNAL(triggered()), this, SLOT(getThree()));
141  connect(d_act[3], SIGNAL(triggered()), this, SLOT(getFour()));
142  connect(d_act[4], SIGNAL(triggered()), this, SLOT(getFive()));
143  connect(d_act[5], SIGNAL(triggered()), this, SLOT(getSix()));
144  connect(d_act[6], SIGNAL(triggered()), this, SLOT(getSeven()));
145  connect(d_act[7], SIGNAL(triggered()), this, SLOT(getEight()));
146  connect(d_act[8], SIGNAL(triggered()), this, SLOT(getNine()));
147  connect(d_act[9], SIGNAL(triggered()), this, SLOT(getTen()));
148 
149  QListIterator<QAction*> i(d_act);
150  while(i.hasNext()) {
151  QAction *a = i.next();
152  addAction(a);
153  }
154  }
155 
157  {}
158 
159  int getNumActions() const
160  {
161  return d_act.size();
162  }
163 
164  QAction * getAction(int which)
165  {
166  if(which < d_act.size())
167  return d_act[which];
168  else
169  throw std::runtime_error("LineWidthMenu::getAction: which out of range.\n");
170  }
171 
172 signals:
173  void whichTrigger(int which, int width);
174 
175 public slots:
176  void getOne() { emit whichTrigger(d_which, 1); }
177  void getTwo() { emit whichTrigger(d_which, 2); }
178  void getThree() { emit whichTrigger(d_which, 3); }
179  void getFour() { emit whichTrigger(d_which, 4); }
180  void getFive() { emit whichTrigger(d_which, 5); }
181  void getSix() { emit whichTrigger(d_which, 6); }
182  void getSeven() { emit whichTrigger(d_which, 7); }
183  void getEight() { emit whichTrigger(d_which, 8); }
184  void getNine() { emit whichTrigger(d_which, 9); }
185  void getTen() { emit whichTrigger(d_which, 10); }
186 
187 private:
188  QList<QAction *> d_act;
189  int d_which;
190 };
191 
192 
193 /********************************************************************/
194 
195 
196 class LineStyleMenu: public QMenu
197 {
198  Q_OBJECT
199 
200 public:
201  LineStyleMenu(int which, QWidget *parent)
202  : QMenu("Line Style", parent), d_which(which)
203  {
204  d_act.push_back(new QAction("None", this));
205  d_act.push_back(new QAction("Solid", this));
206  d_act.push_back(new QAction("Dash", this));
207  d_act.push_back(new QAction("Dots", this));
208  d_act.push_back(new QAction("Dash-Dot", this));
209  d_act.push_back(new QAction("Dash-Dot-Dot", this));
210 
211  connect(d_act[0], SIGNAL(triggered()), this, SLOT(getNone()));
212  connect(d_act[1], SIGNAL(triggered()), this, SLOT(getSolid()));
213  connect(d_act[2], SIGNAL(triggered()), this, SLOT(getDash()));
214  connect(d_act[3], SIGNAL(triggered()), this, SLOT(getDots()));
215  connect(d_act[4], SIGNAL(triggered()), this, SLOT(getDashDot()));
216  connect(d_act[5], SIGNAL(triggered()), this, SLOT(getDashDotDot()));
217 
218  QListIterator<QAction*> i(d_act);
219  while(i.hasNext()) {
220  QAction *a = i.next();
221  addAction(a);
222  }
223  }
224 
226  {}
227 
228  int getNumActions() const
229  {
230  return d_act.size();
231  }
232 
233  QAction * getAction(int which)
234  {
235  if(which < d_act.size())
236  return d_act[which];
237  else
238  throw std::runtime_error("LineStyleMenu::getAction: which out of range.\n");
239  }
240 
241 signals:
242  void whichTrigger(int which, Qt::PenStyle);
243 
244 public slots:
245  void getNone() { emit whichTrigger(d_which, Qt::NoPen); }
246  void getSolid() { emit whichTrigger(d_which, Qt::SolidLine); }
247  void getDash() { emit whichTrigger(d_which, Qt::DashLine); }
248  void getDots() { emit whichTrigger(d_which, Qt::DotLine); }
249  void getDashDot() { emit whichTrigger(d_which, Qt::DashDotLine); }
250  void getDashDotDot() { emit whichTrigger(d_which, Qt::DashDotDotLine); }
251 
252 private:
253  QList<QAction *> d_act;
254  int d_which;
255 };
256 
257 
258 /********************************************************************/
259 
260 
261 class LineMarkerMenu: public QMenu
262 {
263  Q_OBJECT
264 
265 public:
266  LineMarkerMenu(int which, QWidget *parent)
267  : QMenu("Line Marker", parent), d_which(which)
268  {
269  d_act.push_back(new QAction("None", this));
270  d_act.push_back(new QAction("Circle", this));
271  d_act.push_back(new QAction("Rectangle", this));
272  d_act.push_back(new QAction("Diamond", this));
273  d_act.push_back(new QAction("Triangle", this));
274  d_act.push_back(new QAction("Down Triangle", this));
275  d_act.push_back(new QAction("Left Triangle", this));
276  d_act.push_back(new QAction("Right Triangle", this));
277  d_act.push_back(new QAction("Cross", this));
278  d_act.push_back(new QAction("X-Cross", this));
279  d_act.push_back(new QAction("Horiz. Line", this));
280  d_act.push_back(new QAction("Vert. Line", this));
281  d_act.push_back(new QAction("Star 1", this));
282  d_act.push_back(new QAction("Star 2", this));
283  d_act.push_back(new QAction("Hexagon", this));
284 
285  connect(d_act[0], SIGNAL(triggered()), this, SLOT(getNone()));
286  connect(d_act[1], SIGNAL(triggered()), this, SLOT(getCircle()));
287  connect(d_act[2], SIGNAL(triggered()), this, SLOT(getRect()));
288  connect(d_act[3], SIGNAL(triggered()), this, SLOT(getDiamond()));
289  connect(d_act[4], SIGNAL(triggered()), this, SLOT(getTriangle()));
290  connect(d_act[5], SIGNAL(triggered()), this, SLOT(getDTriangle()));
291  connect(d_act[6], SIGNAL(triggered()), this, SLOT(getLTriangle()));
292  connect(d_act[7], SIGNAL(triggered()), this, SLOT(getRTriangle()));
293  connect(d_act[8], SIGNAL(triggered()), this, SLOT(getCross()));
294  connect(d_act[9], SIGNAL(triggered()), this, SLOT(getXCross()));
295  connect(d_act[10], SIGNAL(triggered()), this, SLOT(getHLine()));
296  connect(d_act[11], SIGNAL(triggered()), this, SLOT(getVLine()));
297  connect(d_act[12], SIGNAL(triggered()), this, SLOT(getStar1()));
298  connect(d_act[13], SIGNAL(triggered()), this, SLOT(getStar2()));
299  connect(d_act[14], SIGNAL(triggered()), this, SLOT(getHexagon()));
300 
301  QListIterator<QAction*> i(d_act);
302  while(i.hasNext()) {
303  QAction *a = i.next();
304  addAction(a);
305  }
306  }
307 
309  {}
310 
311  int getNumActions() const
312  {
313  return d_act.size();
314  }
315 
316  QAction * getAction(int which)
317  {
318  if(which < d_act.size())
319  return d_act[which];
320  else
321  throw std::runtime_error("LineMarkerMenu::getAction: which out of range.\n");
322  }
323 
324 signals:
325  void whichTrigger(int which, QwtSymbol::Style);
326 
327 public slots:
328  void getNone() { emit whichTrigger(d_which, QwtSymbol::NoSymbol); }
329  void getCircle() { emit whichTrigger(d_which, QwtSymbol::Ellipse); }
330  void getRect() { emit whichTrigger(d_which, QwtSymbol::Rect); }
331  void getDiamond() { emit whichTrigger(d_which, QwtSymbol::Diamond); }
332  void getTriangle() { emit whichTrigger(d_which, QwtSymbol::Triangle); }
333  void getDTriangle() { emit whichTrigger(d_which, QwtSymbol::DTriangle); }
334  void getLTriangle() { emit whichTrigger(d_which, QwtSymbol::LTriangle); }
335  void getRTriangle() { emit whichTrigger(d_which, QwtSymbol::RTriangle); }
336  void getCross() { emit whichTrigger(d_which, QwtSymbol::Cross); }
337  void getXCross() { emit whichTrigger(d_which, QwtSymbol::XCross); }
338  void getHLine() { emit whichTrigger(d_which, QwtSymbol::HLine); }
339  void getVLine() { emit whichTrigger(d_which, QwtSymbol::VLine); }
340  void getStar1() { emit whichTrigger(d_which, QwtSymbol::Star1); }
341  void getStar2() { emit whichTrigger(d_which, QwtSymbol::Star2); }
342  void getHexagon() { emit whichTrigger(d_which, QwtSymbol::Hexagon); }
343 
344 private:
345  QList<QAction *> d_act;
346  int d_which;
347 };
348 
349 
350 /********************************************************************/
351 
352 
353 class MarkerAlphaMenu: public QMenu
354 {
355  Q_OBJECT
356 
357 public:
358  MarkerAlphaMenu(int which, QWidget *parent)
359  : QMenu("Line Transparency", parent), d_which(which)
360  {
361  d_act.push_back(new QAction("None", this));
362  d_act.push_back(new QAction("Low", this));
363  d_act.push_back(new QAction("Medium", this));
364  d_act.push_back(new QAction("High", this));
365  d_act.push_back(new QAction("Off", this));
366 
367  connect(d_act[0], SIGNAL(triggered()), this, SLOT(getNone()));
368  connect(d_act[1], SIGNAL(triggered()), this, SLOT(getLow()));
369  connect(d_act[2], SIGNAL(triggered()), this, SLOT(getMedium()));
370  connect(d_act[3], SIGNAL(triggered()), this, SLOT(getHigh()));
371  connect(d_act[4], SIGNAL(triggered()), this, SLOT(getOff()));
372 
373  QListIterator<QAction*> i(d_act);
374  while(i.hasNext()) {
375  QAction *a = i.next();
376  addAction(a);
377  }
378  }
379 
381  {}
382 
383  int getNumActions() const
384  {
385  return d_act.size();
386  }
387 
388  QAction * getAction(int which)
389  {
390  if(which < d_act.size())
391  return d_act[which];
392  else
393  throw std::runtime_error("MarkerAlphaMenu::getAction: which out of range.\n");
394  }
395 
396 signals:
397  void whichTrigger(int which, int);
398 
399 public slots:
400  void getNone() { emit whichTrigger(d_which, 255); }
401  void getLow() { emit whichTrigger(d_which, 200); }
402  void getMedium() { emit whichTrigger(d_which, 125); }
403  void getHigh() { emit whichTrigger(d_which, 50); }
404  void getOff() { emit whichTrigger(d_which, 0); }
405 
406 private:
407  QList<QAction *> d_act;
408  int d_which;
409 };
410 
411 
412 /********************************************************************/
413 
414 
415 class LineTitleAction: public QAction
416 {
417  Q_OBJECT
418 
419 public:
420  LineTitleAction(int which, QWidget *parent)
421  : QAction("Line Title", parent), d_which(which)
422  {
423  d_diag = new QDialog(parent);
424  d_diag->setModal(true);
425 
426  d_text = new QLineEdit();
427 
428  QGridLayout *layout = new QGridLayout(d_diag);
429  QPushButton *btn_ok = new QPushButton(tr("OK"));
430  QPushButton *btn_cancel = new QPushButton(tr("Cancel"));
431 
432  layout->addWidget(d_text, 0, 0, 1, 2);
433  layout->addWidget(btn_ok, 1, 0);
434  layout->addWidget(btn_cancel, 1, 1);
435 
436  connect(btn_ok, SIGNAL(clicked()), this, SLOT(getText()));
437  connect(btn_cancel, SIGNAL(clicked()), d_diag, SLOT(close()));
438 
439  connect(this, SIGNAL(triggered()), this, SLOT(getTextDiag()));
440  }
441 
443  {}
444 
445 signals:
446  void whichTrigger(int which, const QString &text);
447 
448 public slots:
449  void getTextDiag()
450  {
451  d_diag->exec();
452  }
453 
454 private slots:
455  void getText()
456  {
457  emit whichTrigger(d_which, d_text->text());
458  d_diag->accept();
459  }
460 
461 private:
462  int d_which;
463 
464  QDialog *d_diag;
465  QLineEdit *d_text;
466 };
467 
468 
469 /********************************************************************/
470 
471 
472 class OtherAction: public QAction
473 {
474  Q_OBJECT
475 
476 public:
477  OtherAction(QWidget *parent)
478  : QAction("Other", parent)
479  {
480  d_diag = new QDialog(parent);
481  d_diag->setWindowTitle("Other");
482  d_diag->setModal(true);
483 
484  d_text = new QLineEdit();
485 
486  QGridLayout *layout = new QGridLayout(d_diag);
487  QPushButton *btn_ok = new QPushButton(tr("OK"));
488  QPushButton *btn_cancel = new QPushButton(tr("Cancel"));
489 
490  layout->addWidget(d_text, 0, 0, 1, 2);
491  layout->addWidget(btn_ok, 1, 0);
492  layout->addWidget(btn_cancel, 1, 1);
493 
494  connect(btn_ok, SIGNAL(clicked()), this, SLOT(getText()));
495  connect(btn_cancel, SIGNAL(clicked()), d_diag, SLOT(close()));
496 
497  connect(this, SIGNAL(triggered()), this, SLOT(getTextDiag()));
498  }
499 
501  {}
502 
503  void setValidator(QValidator *v)
504  {
505  d_text->setValidator(v);
506  }
507 
508  void setDiagText(QString text)
509  {
510  d_text->setText(text);
511  }
512 
513 signals:
514  void whichTrigger(const QString &text);
515 
516 public slots:
517  void getTextDiag()
518  {
519  d_diag->exec();
520  }
521 
522 private slots:
523  void getText()
524  {
525  emit whichTrigger(d_text->text());
526  d_diag->accept();
527  }
528 
529 private:
530  QDialog *d_diag;
531  QLineEdit *d_text;
532 };
533 
534 /********************************************************************/
535 
536 
537 class OtherDualAction: public QAction
538 {
539  Q_OBJECT
540 
541 public:
542  OtherDualAction(QString label0, QString label1, QWidget *parent)
543  : QAction("Other", parent)
544  {
545  d_diag = new QDialog(parent);
546  d_diag->setWindowTitle("Other");
547  d_diag->setModal(true);
548 
549  d_text0 = new QLineEdit();
550  d_text1 = new QLineEdit();
551 
552  QLabel *_label0 = new QLabel(label0);
553  QLabel *_label1 = new QLabel(label1);
554 
555  QGridLayout *layout = new QGridLayout(d_diag);
556  QPushButton *btn_ok = new QPushButton(tr("OK"));
557  QPushButton *btn_cancel = new QPushButton(tr("Cancel"));
558 
559  layout->addWidget(_label0, 0, 0, 1, 2);
560  layout->addWidget(_label1, 1, 0, 1, 2);
561 
562  layout->addWidget(d_text0, 0, 1, 1, 2);
563  layout->addWidget(d_text1, 1, 1, 1, 2);
564  layout->addWidget(btn_ok, 2, 0);
565  layout->addWidget(btn_cancel, 2, 1);
566 
567  connect(btn_ok, SIGNAL(clicked()), this, SLOT(getText()));
568  connect(btn_cancel, SIGNAL(clicked()), d_diag, SLOT(close()));
569 
570  connect(this, SIGNAL(triggered()), this, SLOT(getTextDiag()));
571  }
572 
574  {}
575 
576 signals:
577  void whichTrigger(const QString &text0, const QString &text1);
578 
579 public slots:
580  void getTextDiag()
581  {
582  d_diag->exec();
583  }
584 
585 private slots:
586  void getText()
587  {
588  emit whichTrigger(d_text0->text(), d_text1->text());
589  d_diag->accept();
590  }
591 
592 private:
593  QDialog *d_diag;
594  QLineEdit *d_text0;
595  QLineEdit *d_text1;
596 };
597 
598 
599 /********************************************************************/
600 
601 
602 class FFTSizeMenu: public QMenu
603 {
604  Q_OBJECT
605 
606 public:
607  FFTSizeMenu(QWidget *parent)
608  : QMenu("FFT Size", parent)
609  {
610  d_act.push_back(new QAction("32", this));
611  d_act.push_back(new QAction("64", this));
612  d_act.push_back(new QAction("128", this));
613  d_act.push_back(new QAction("256", this));
614  d_act.push_back(new QAction("512", this));
615  d_act.push_back(new QAction("1024", this));
616  d_act.push_back(new QAction("2048", this));
617  d_act.push_back(new QAction("4096", this));
618  //d_act.push_back(new QAction("8192", this));
619  //d_act.push_back(new QAction("16384", this));
620  //d_act.push_back(new QAction("32768", this));
621  d_act.push_back(new OtherAction(this));
622 
623  d_grp = new QActionGroup(this);
624  for(int t = 0; t < d_act.size(); t++) {
625  d_act[t]->setCheckable(true);
626  d_act[t]->setActionGroup(d_grp);
627  }
628 
629  QIntValidator *valid = new QIntValidator(32, 4096, this);
630  ((OtherAction*)d_act[d_act.size()-1])->setValidator(valid);
631 
632  connect(d_act[0], SIGNAL(triggered()), this, SLOT(get05()));
633  connect(d_act[1], SIGNAL(triggered()), this, SLOT(get06()));
634  connect(d_act[2], SIGNAL(triggered()), this, SLOT(get07()));
635  connect(d_act[3], SIGNAL(triggered()), this, SLOT(get08()));
636  connect(d_act[4], SIGNAL(triggered()), this, SLOT(get09()));
637  connect(d_act[5], SIGNAL(triggered()), this, SLOT(get10()));
638  connect(d_act[6], SIGNAL(triggered()), this, SLOT(get11()));
639  connect(d_act[7], SIGNAL(triggered()), this, SLOT(get12()));
640  //connect(d_act[8], SIGNAL(triggered()), this, SLOT(get13()));
641  //connect(d_act[9], SIGNAL(triggered()), this, SLOT(get14()));
642  //connect(d_act[10], SIGNAL(triggered()), this, SLOT(get15()));
643  connect(d_act[8], SIGNAL(whichTrigger(const QString&)),
644  this, SLOT(getOther(const QString&)));
645 
646  QListIterator<QAction*> i(d_act);
647  while(i.hasNext()) {
648  QAction *a = i.next();
649  addAction(a);
650  }
651  }
652 
654  {}
655 
656  int getNumActions() const
657  {
658  return d_act.size();
659  }
660 
661  QAction * getAction(int which)
662  {
663  if(which < d_act.size())
664  return d_act[which];
665  else
666  throw std::runtime_error("FFTSizeMenu::getAction: which out of range.\n");
667  }
668 
669  QAction * getActionFromSize(int size)
670  {
671  float ipt;
672  float which = logf(static_cast<float>(size))/logf(2.0) - 5;
673  // If we're a predefined value
674  if(modff(which,&ipt) == 0) {
675  if(which < d_act.size()-1)
676  return d_act[static_cast<int>(which)];
677  else
678  throw std::runtime_error("FFTSizeMenu::getActionFromString: which out of range.\n");
679  }
680  // Or a non-predefined value, return Other
681  else {
682  ((OtherAction*)d_act[d_act.size()-1])->setDiagText(QString().setNum(size));
683  return d_act[d_act.size()-1];
684  }
685  }
686 
687 signals:
688  void whichTrigger(int size);
689 
690 public slots:
691  void get05() { emit whichTrigger(32); }
692  void get06() { emit whichTrigger(64); }
693  void get07() { emit whichTrigger(128); }
694  void get08() { emit whichTrigger(256); }
695  void get09() { emit whichTrigger(512); }
696  void get10() { emit whichTrigger(1024); }
697  void get11() { emit whichTrigger(2048); }
698  void get12() { emit whichTrigger(4096); }
699  //void get13() { emit whichTrigger(8192); }
700  //void get14() { emit whichTrigger(16384); }
701  //void get15() { emit whichTrigger(32768); }
702  void getOther(const QString &str)
703  {
704  int value = str.toInt();
705  emit whichTrigger(value);
706  }
707 
708 private:
709  QList<QAction *> d_act;
710  OtherAction *d_other;
711  QActionGroup *d_grp;
712 };
713 
714 
715 /********************************************************************/
716 
717 
718 class FFTAverageMenu: public QMenu
719 {
720  Q_OBJECT
721 
722 public:
723  FFTAverageMenu(QWidget *parent)
724  : QMenu("FFT Average", parent)
725  {
726  d_off = 1.0;
727  d_high = 0.05;
728  d_medium = 0.1;
729  d_low = 0.2;
730 
731  d_act.push_back(new QAction("Off", this));
732  d_act.push_back(new QAction("High", this));
733  d_act.push_back(new QAction("Medium", this));
734  d_act.push_back(new QAction("Low", this));
735  d_act.push_back(new OtherAction(this));
736 
737  d_grp = new QActionGroup(this);
738  for(int t = 0; t < d_act.size(); t++) {
739  d_act[t]->setCheckable(true);
740  d_act[t]->setActionGroup(d_grp);
741  }
742  d_act[0]->setChecked(true);
743 
744  QDoubleValidator *valid = new QDoubleValidator(0.0, 1.0, 2, this);
745  ((OtherAction*)d_act[d_act.size()-1])->setValidator(valid);
746 
747  connect(d_act[0], SIGNAL(triggered()), this, SLOT(getOff()));
748  connect(d_act[1], SIGNAL(triggered()), this, SLOT(getHigh()));
749  connect(d_act[2], SIGNAL(triggered()), this, SLOT(getMedium()));
750  connect(d_act[3], SIGNAL(triggered()), this, SLOT(getLow()));
751  connect(d_act[4], SIGNAL(whichTrigger(const QString&)),
752  this, SLOT(getOther(const QString&)));
753 
754  QListIterator<QAction*> i(d_act);
755  while(i.hasNext()) {
756  QAction *a = i.next();
757  addAction(a);
758  }
759  }
760 
762  {}
763 
764  int getNumActions() const
765  {
766  return d_act.size();
767  }
768 
769  QAction * getAction(int which)
770  {
771  if(which < d_act.size())
772  return d_act[which];
773  else
774  throw std::runtime_error("FFTSizeMenu::getAction: which out of range.\n");
775  }
776 
777  QAction * getActionFromAvg(float avg)
778  {
779  int which = 0;
780  if(avg == d_off)
781  which = 0;
782  else if(avg == d_high)
783  which = 1;
784  else if(avg == d_medium)
785  which = 2;
786  else if(avg == d_low)
787  which = 3;
788  else {
789  ((OtherAction*)d_act[d_act.size()-1])->setDiagText(QString().setNum(avg));
790  which = 4;
791  }
792  return d_act[static_cast<int>(which)];
793  }
794 
795  signals:
796  void whichTrigger(float alpha);
797 
798  public slots:
799  void getOff() { emit whichTrigger(d_off); }
800  void getHigh() { emit whichTrigger(d_high); }
801  void getMedium() { emit whichTrigger(d_medium); }
802  void getLow() { emit whichTrigger(d_low); }
803  void getOther(const QString &str)
804  {
805  float value = str.toFloat();
806  emit whichTrigger(value);
807  }
808 
809 private:
810  QList<QAction *> d_act;
811  OtherAction *d_other;
812  QActionGroup *d_grp;
813  float d_off, d_high, d_medium, d_low;
814 };
815 
816 
817 /********************************************************************/
818 
819 
820 class FFTWindowMenu: public QMenu
821 {
822  Q_OBJECT
823 
824 public:
825  FFTWindowMenu(QWidget *parent)
826  : QMenu("FFT Window", parent)
827  {
828  d_act.push_back(new QAction("None", this));
829  d_act.push_back(new QAction("Hamming", this));
830  d_act.push_back(new QAction("Hann", this));
831  d_act.push_back(new QAction("Blackman", this));
832  d_act.push_back(new QAction("Blackman-harris", this));
833  d_act.push_back(new QAction("Rectangular", this));
834  d_act.push_back(new QAction("Kaiser", this));
835  d_act.push_back(new QAction("Flat-top", this));
836 
837  d_grp = new QActionGroup(this);
838  for(int t = 0; t < d_act.size(); t++) {
839  d_act[t]->setCheckable(true);
840  d_act[t]->setActionGroup(d_grp);
841  }
842 
843  connect(d_act[0], SIGNAL(triggered()), this, SLOT(getNone()));
844  connect(d_act[1], SIGNAL(triggered()), this, SLOT(getHamming()));
845  connect(d_act[2], SIGNAL(triggered()), this, SLOT(getHann()));
846  connect(d_act[3], SIGNAL(triggered()), this, SLOT(getBlackman()));
847  connect(d_act[4], SIGNAL(triggered()), this, SLOT(getBlackmanharris()));
848  connect(d_act[5], SIGNAL(triggered()), this, SLOT(getRectangular()));
849  connect(d_act[6], SIGNAL(triggered()), this, SLOT(getKaiser()));
850  connect(d_act[7], SIGNAL(triggered()), this, SLOT(getFlattop()));
851 
852  QListIterator<QAction*> i(d_act);
853  while(i.hasNext()) {
854  QAction *a = i.next();
855  addAction(a);
856  }
857  }
858 
860  {}
861 
862  int getNumActions() const
863  {
864  return d_act.size();
865  }
866 
867  QAction * getAction(int which)
868  {
869  if(which < d_act.size())
870  return d_act[which];
871  else
872  throw std::runtime_error("FFTWindowMenu::getAction: which out of range.\n");
873  }
874 
876  {
877  int which = 0;
878  switch(static_cast<int>(type)) {
879  case((gr::filter::firdes::WIN_NONE)): which = 0; break;
880  case((gr::filter::firdes::WIN_HAMMING)): which = 1; break;
881  case((gr::filter::firdes::WIN_HANN)): which = 2; break;
882  case((gr::filter::firdes::WIN_BLACKMAN)): which = 3; break;
883  case((gr::filter::firdes::WIN_BLACKMAN_hARRIS)): which = 4; break;
884  case((gr::filter::firdes::WIN_RECTANGULAR)): which = 5; break;
885  case((gr::filter::firdes::WIN_KAISER)): which = 6; break;
886  case((gr::filter::firdes::WIN_FLATTOP)): which = 7; break;
887  }
888  return d_act[which];
889  }
890 
891 signals:
893 
894 public slots:
903 
904 private:
905  QList<QAction *> d_act;
906  QActionGroup *d_grp;
907  int d_which;
908 };
909 
910 
911 /********************************************************************/
912 
913 
914 class NPointsMenu: public QAction
915 {
916  Q_OBJECT
917 
918 public:
919  NPointsMenu(QWidget *parent)
920  : QAction("Number of Points", parent)
921  {
922  d_diag = new QDialog(parent);
923  d_diag->setWindowTitle("Number of Points");
924  d_diag->setModal(true);
925 
926  d_text = new QLineEdit();
927 
928  QGridLayout *layout = new QGridLayout(d_diag);
929  QPushButton *btn_ok = new QPushButton(tr("OK"));
930  QPushButton *btn_cancel = new QPushButton(tr("Cancel"));
931 
932  layout->addWidget(d_text, 0, 0, 1, 2);
933  layout->addWidget(btn_ok, 1, 0);
934  layout->addWidget(btn_cancel, 1, 1);
935 
936  connect(btn_ok, SIGNAL(clicked()), this, SLOT(getText()));
937  connect(btn_cancel, SIGNAL(clicked()), d_diag, SLOT(close()));
938 
939  connect(this, SIGNAL(triggered()), this, SLOT(getTextDiag()));
940  }
941 
943  {}
944 
945  void setDiagText(const int npts)
946  {
947  d_text->setText(QString().setNum(npts));
948  }
949 
950 signals:
951  void whichTrigger(const int npts);
952 
953 public slots:
954  void getTextDiag()
955  {
956  d_diag->show();
957  }
958 
959 private slots:
960  void getText()
961  {
962  emit whichTrigger(d_text->text().toInt());
963  d_diag->accept();
964  }
965 
966 private:
967  QDialog *d_diag;
968  QLineEdit *d_text;
969 };
970 
971 
972 /********************************************************************/
973 
974 
975 class ColorMapMenu: public QMenu
976 {
977  Q_OBJECT
978 
979 public:
980  ColorMapMenu(int which, QWidget *parent)
981  : QMenu("Color Map", parent), d_which(which)
982  {
983  d_act.push_back(new QAction("Multi-Color", this));
984  d_act.push_back(new QAction("White Hot", this));
985  d_act.push_back(new QAction("Black Hot", this));
986  d_act.push_back(new QAction("Incandescent", this));
987  d_act.push_back(new QAction("Other", this));
988  //d_act.push_back(new OtherDualAction("Min Intensity: ", "Max Intensity: ", this));
989 
990  connect(d_act[0], SIGNAL(triggered()), this, SLOT(getMultiColor()));
991  connect(d_act[1], SIGNAL(triggered()), this, SLOT(getWhiteHot()));
992  connect(d_act[2], SIGNAL(triggered()), this, SLOT(getBlackHot()));
993  connect(d_act[3], SIGNAL(triggered()), this, SLOT(getIncandescent()));
994  connect(d_act[4], SIGNAL(triggered()), this, SLOT(getOther()));
995 
996  QListIterator<QAction*> i(d_act);
997  while(i.hasNext()) {
998  QAction *a = i.next();
999  addAction(a);
1000  }
1001 
1002  d_max_value = QColor("white");
1003  d_min_value = QColor("white");
1004  }
1005 
1007  {}
1008 
1009  int getNumActions() const
1010  {
1011  return d_act.size();
1012  }
1013 
1014  QAction * getAction(int which)
1015  {
1016  if(which < d_act.size())
1017  return d_act[which];
1018  else
1019  throw std::runtime_error("ColorMapMenu::getAction: which out of range.\n");
1020  }
1021 
1022  signals:
1023  void whichTrigger(int which, const int type,
1024  const QColor &min_color=QColor(),
1025  const QColor &max_color=QColor());
1026 
1027  public slots:
1032  //void getOther(d_which, const QString &min_str, const QString &max_str)
1033  void getOther()
1034  {
1035  QMessageBox::information(this, "Set low and high intensities",
1036  "In the next windows, select the low and then the high intensity colors.",
1037  QMessageBox::Ok);
1038  d_min_value = QColorDialog::getColor(d_min_value, this);
1039  d_max_value = QColorDialog::getColor(d_max_value, this);
1040 
1042  d_min_value, d_max_value);
1043  }
1044 
1045 private:
1046  QList<QAction *> d_act;
1047  OtherDualAction *d_other;
1048  QColor d_max_value, d_min_value;
1049  int d_which;
1050 };
1051 
1052 
1053 /********************************************************************/
1054 
1055 
1056 class TriggerModeMenu: public QMenu
1057 {
1058  Q_OBJECT
1059 
1060 public:
1061  TriggerModeMenu(QWidget *parent)
1062  : QMenu("Mode", parent)
1063  {
1064  d_grp = new QActionGroup(this);
1065  d_act.push_back(new QAction("Free", this));
1066  d_act.push_back(new QAction("Auto", this));
1067  d_act.push_back(new QAction("Normal", this));
1068  d_act.push_back(new QAction("Tag", this));
1069 
1070  connect(d_act[0], SIGNAL(triggered()), this, SLOT(getFree()));
1071  connect(d_act[1], SIGNAL(triggered()), this, SLOT(getAuto()));
1072  connect(d_act[2], SIGNAL(triggered()), this, SLOT(getNorm()));
1073  connect(d_act[3], SIGNAL(triggered()), this, SLOT(getTag()));
1074 
1075  QListIterator<QAction*> i(d_act);
1076  while(i.hasNext()) {
1077  QAction *a = i.next();
1078  a->setCheckable(true);
1079  a->setActionGroup(d_grp);
1080  addAction(a);
1081  }
1082  }
1083 
1085  {}
1086 
1087  int getNumActions() const
1088  {
1089  return d_act.size();
1090  }
1091 
1092  QAction * getAction(int which)
1093  {
1094  if(which < d_act.size())
1095  return d_act[which];
1096  else
1097  throw std::runtime_error("TriggerModeMenu::getAction: which out of range.\n");
1098  }
1099 
1101  {
1102  switch(mode) {
1104  return d_act[0];
1105  break;
1107  return d_act[1];
1108  break;
1110  return d_act[2];
1111  break;
1113  return d_act[3];
1114  break;
1115  default:
1116  throw std::runtime_error("TriggerModeMenu::getAction: unknown trigger mode.\n");
1117  }
1118  }
1119 
1120 signals:
1122 
1123 public slots:
1128 
1129 private:
1130  QList<QAction *> d_act;
1131  QActionGroup *d_grp;
1132 };
1133 
1134 
1135 /********************************************************************/
1136 
1137 
1138 class TriggerSlopeMenu: public QMenu
1139 {
1140  Q_OBJECT
1141 
1142 public:
1143  TriggerSlopeMenu(QWidget *parent)
1144  : QMenu("Slope", parent)
1145  {
1146  d_grp = new QActionGroup(this);
1147  d_act.push_back(new QAction("Positive", this));
1148  d_act.push_back(new QAction("Negative", this));
1149 
1150  connect(d_act[0], SIGNAL(triggered()), this, SLOT(getPos()));
1151  connect(d_act[1], SIGNAL(triggered()), this, SLOT(getNeg()));
1152 
1153  QListIterator<QAction*> i(d_act);
1154  while(i.hasNext()) {
1155  QAction *a = i.next();
1156  a->setCheckable(true);
1157  a->setActionGroup(d_grp);
1158  addAction(a);
1159  }
1160  }
1161 
1163  {}
1164 
1165  int getNumActions() const
1166  {
1167  return d_act.size();
1168  }
1169 
1170  QAction * getAction(int which)
1171  {
1172  if(which < d_act.size())
1173  return d_act[which];
1174  else
1175  throw std::runtime_error("TriggerSlopeMenu::getAction: which out of range.\n");
1176  }
1177 
1179  {
1180  switch(slope) {
1182  return d_act[0];
1183  break;
1185  return d_act[1];
1186  break;
1187  default:
1188  throw std::runtime_error("TriggerSlopeMenu::getAction: unknown trigger slope.\n");
1189  }
1190  }
1191 
1192 signals:
1194 
1195 public slots:
1198 
1199 private:
1200  QList<QAction *> d_act;
1201  QActionGroup *d_grp;
1202 };
1203 
1204 
1205 /********************************************************************/
1206 
1207 
1208 class TriggerChannelMenu: public QMenu
1209 {
1210  Q_OBJECT
1211 
1212 public:
1213  TriggerChannelMenu(int nchans, QWidget *parent)
1214  : QMenu("Channel", parent)
1215  {
1216  d_grp = new QActionGroup(this);
1217  for(int i = 0; i < nchans; i++) {
1218  d_act.push_back(new QAction(QString().setNum(i), this));
1219  d_act[i]->setCheckable(true);
1220  d_act[i]->setActionGroup(d_grp);
1221 
1222  addAction(d_act[i]);
1223  connect(d_act[i], SIGNAL(triggered()), this, SLOT(getChannel()));
1224  }
1225  }
1226 
1228  {}
1229 
1230  int getNumActions() const
1231  {
1232  return d_act.size();
1233  }
1234 
1235  QAction * getAction(int which)
1236  {
1237  if(which < d_act.size())
1238  return d_act[which];
1239  else
1240  throw std::runtime_error("TriggerChannelMenu::getAction: which out of range.\n");
1241  }
1242 
1243 
1244 signals:
1245  void whichTrigger(int n);
1246 
1247 public slots:
1248  void getChannel()
1249  {
1250  QAction *a = d_grp->checkedAction();
1251  int which = a->text().toInt();
1252  emit whichTrigger(which);
1253  }
1254 
1255 private:
1256  QList<QAction *> d_act;
1257  QActionGroup *d_grp;
1258 };
1259 
1260 
1261 /********************************************************************/
1262 
1263 
1264 class PopupMenu: public QAction
1265 {
1266  Q_OBJECT
1267 
1268 public:
1269  PopupMenu(QString desc, QWidget *parent)
1270  : QAction(desc, parent)
1271  {
1272  d_diag = new QDialog(parent);
1273  d_diag->setWindowTitle(desc);
1274  d_diag->setModal(true);
1275 
1276  d_text = new QLineEdit();
1277 
1278  QGridLayout *layout = new QGridLayout(d_diag);
1279  QPushButton *btn_ok = new QPushButton(tr("OK"));
1280  QPushButton *btn_cancel = new QPushButton(tr("Cancel"));
1281 
1282  layout->addWidget(d_text, 0, 0, 1, 2);
1283  layout->addWidget(btn_ok, 1, 0);
1284  layout->addWidget(btn_cancel, 1, 1);
1285 
1286  connect(btn_ok, SIGNAL(clicked()), this, SLOT(getText()));
1287  connect(btn_cancel, SIGNAL(clicked()), d_diag, SLOT(close()));
1288 
1289  connect(this, SIGNAL(triggered()), this, SLOT(getTextDiag()));
1290  }
1291 
1293  {}
1294 
1295  void setText(QString s)
1296  {
1297  d_text->setText(s);
1298  }
1299 
1300 signals:
1301  void whichTrigger(const QString data);
1302 
1303 public slots:
1305  {
1306  d_diag->show();
1307  }
1308 
1309 private slots:
1310  void getText()
1311  {
1312  emit whichTrigger(d_text->text());
1313  d_diag->accept();
1314  }
1315 
1316 private:
1317  QDialog *d_diag;
1318  QLineEdit *d_text;
1319 };
1320 
1321 
1322 /********************************************************************/
1323 
1324 
1325 #endif /* FORM_MENUS_H */