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 <QtGui/QDoubleValidator> 27 #include <QtGui/QIntValidator> 28 #include <QtGui/QtGui> 29 #include <stdexcept> 30 #include <vector> 31 32 #if QT_VERSION >= 0x050000 33 #include <QtWidgets/QtWidgets> 34 #endif 35 36 #include <gnuradio/filter/firdes.h> 37 #include <gnuradio/qtgui/qtgui_types.h> 38 #include <gnuradio/qtgui/trigger_mode.h> 39 #include <qwt_symbol.h> 40 41 class LineColorMenu : public QMenu 42 { 43 Q_OBJECT 44 45 public: LineColorMenu(unsigned int which,QWidget * parent)46 LineColorMenu(unsigned int which, QWidget* parent) 47 : QMenu("Line Color", parent), d_which(which) 48 { 49 d_grp = new QActionGroup(this); 50 51 d_act.push_back(new QAction("Blue", this)); 52 d_act.push_back(new QAction("Red", this)); 53 d_act.push_back(new QAction("Green", this)); 54 d_act.push_back(new QAction("Black", this)); 55 d_act.push_back(new QAction("Cyan", this)); 56 d_act.push_back(new QAction("Magenta", this)); 57 d_act.push_back(new QAction("Yellow", this)); 58 d_act.push_back(new QAction("Gray", this)); 59 d_act.push_back(new QAction("Dark Red", this)); 60 d_act.push_back(new QAction("Dark Green", this)); 61 d_act.push_back(new QAction("Dark Blue", this)); 62 d_act.push_back(new QAction("Dark Gray", this)); 63 64 connect(d_act[0], SIGNAL(triggered()), this, SLOT(getBlue())); 65 connect(d_act[1], SIGNAL(triggered()), this, SLOT(getRed())); 66 connect(d_act[2], SIGNAL(triggered()), this, SLOT(getGreen())); 67 connect(d_act[3], SIGNAL(triggered()), this, SLOT(getBlack())); 68 connect(d_act[4], SIGNAL(triggered()), this, SLOT(getCyan())); 69 connect(d_act[5], SIGNAL(triggered()), this, SLOT(getMagenta())); 70 connect(d_act[6], SIGNAL(triggered()), this, SLOT(getYellow())); 71 connect(d_act[7], SIGNAL(triggered()), this, SLOT(getGray())); 72 connect(d_act[8], SIGNAL(triggered()), this, SLOT(getDarkRed())); 73 connect(d_act[9], SIGNAL(triggered()), this, SLOT(getDarkGreen())); 74 connect(d_act[10], SIGNAL(triggered()), this, SLOT(getDarkBlue())); 75 connect(d_act[11], SIGNAL(triggered()), this, SLOT(getDarkGray())); 76 77 QListIterator<QAction*> i(d_act); 78 while (i.hasNext()) { 79 QAction* a = i.next(); 80 a->setCheckable(true); 81 a->setActionGroup(d_grp); 82 addAction(a); 83 } 84 } 85 ~LineColorMenu()86 ~LineColorMenu() {} 87 getNumActions()88 int getNumActions() const { return d_act.size(); } 89 getAction(unsigned int which)90 QAction* getAction(unsigned int which) 91 { 92 if (which < static_cast<unsigned int>(d_act.size())) 93 return d_act[which]; 94 else 95 throw std::runtime_error("LineColorMenu::getAction: which out of range.\n"); 96 } 97 98 signals: 99 void whichTrigger(unsigned int which, const QString& name); 100 101 public slots: getBlue()102 void getBlue() { emit whichTrigger(d_which, "blue"); } getRed()103 void getRed() { emit whichTrigger(d_which, "red"); } getGreen()104 void getGreen() { emit whichTrigger(d_which, "green"); } getBlack()105 void getBlack() { emit whichTrigger(d_which, "black"); } getCyan()106 void getCyan() { emit whichTrigger(d_which, "cyan"); } getMagenta()107 void getMagenta() { emit whichTrigger(d_which, "magenta"); } getYellow()108 void getYellow() { emit whichTrigger(d_which, "yellow"); } getGray()109 void getGray() { emit whichTrigger(d_which, "gray"); } getDarkRed()110 void getDarkRed() { emit whichTrigger(d_which, "darkred"); } getDarkGreen()111 void getDarkGreen() { emit whichTrigger(d_which, "darkgreen"); } getDarkBlue()112 void getDarkBlue() { emit whichTrigger(d_which, "darkblue"); } getDarkGray()113 void getDarkGray() { emit whichTrigger(d_which, "darkgray"); } 114 115 private: 116 QActionGroup* d_grp; 117 QList<QAction*> d_act; 118 int d_which; 119 }; 120 121 122 /********************************************************************/ 123 124 125 class LineWidthMenu : public QMenu 126 { 127 Q_OBJECT 128 129 public: LineWidthMenu(unsigned int which,QWidget * parent)130 LineWidthMenu(unsigned int which, QWidget* parent) 131 : QMenu("Line Width", parent), d_which(which) 132 { 133 d_grp = new QActionGroup(this); 134 135 d_act.push_back(new QAction("1", this)); 136 d_act.push_back(new QAction("2", this)); 137 d_act.push_back(new QAction("3", this)); 138 d_act.push_back(new QAction("4", this)); 139 d_act.push_back(new QAction("5", this)); 140 d_act.push_back(new QAction("6", this)); 141 d_act.push_back(new QAction("7", this)); 142 d_act.push_back(new QAction("8", this)); 143 d_act.push_back(new QAction("9", this)); 144 d_act.push_back(new QAction("10", this)); 145 146 connect(d_act[0], SIGNAL(triggered()), this, SLOT(getOne())); 147 connect(d_act[1], SIGNAL(triggered()), this, SLOT(getTwo())); 148 connect(d_act[2], SIGNAL(triggered()), this, SLOT(getThree())); 149 connect(d_act[3], SIGNAL(triggered()), this, SLOT(getFour())); 150 connect(d_act[4], SIGNAL(triggered()), this, SLOT(getFive())); 151 connect(d_act[5], SIGNAL(triggered()), this, SLOT(getSix())); 152 connect(d_act[6], SIGNAL(triggered()), this, SLOT(getSeven())); 153 connect(d_act[7], SIGNAL(triggered()), this, SLOT(getEight())); 154 connect(d_act[8], SIGNAL(triggered()), this, SLOT(getNine())); 155 connect(d_act[9], SIGNAL(triggered()), this, SLOT(getTen())); 156 157 QListIterator<QAction*> i(d_act); 158 while (i.hasNext()) { 159 QAction* a = i.next(); 160 a->setCheckable(true); 161 a->setActionGroup(d_grp); 162 addAction(a); 163 } 164 } 165 ~LineWidthMenu()166 ~LineWidthMenu() {} 167 getNumActions()168 int getNumActions() const { return d_act.size(); } 169 getAction(unsigned int which)170 QAction* getAction(unsigned int which) 171 { 172 if (which < static_cast<unsigned int>(d_act.size())) 173 return d_act[which]; 174 else 175 throw std::runtime_error("LineWidthMenu::getAction: which out of range.\n"); 176 } 177 178 signals: 179 void whichTrigger(unsigned int which, unsigned int width); 180 181 public slots: getOne()182 void getOne() { emit whichTrigger(d_which, 1); } getTwo()183 void getTwo() { emit whichTrigger(d_which, 2); } getThree()184 void getThree() { emit whichTrigger(d_which, 3); } getFour()185 void getFour() { emit whichTrigger(d_which, 4); } getFive()186 void getFive() { emit whichTrigger(d_which, 5); } getSix()187 void getSix() { emit whichTrigger(d_which, 6); } getSeven()188 void getSeven() { emit whichTrigger(d_which, 7); } getEight()189 void getEight() { emit whichTrigger(d_which, 8); } getNine()190 void getNine() { emit whichTrigger(d_which, 9); } getTen()191 void getTen() { emit whichTrigger(d_which, 10); } 192 193 private: 194 QActionGroup* d_grp; 195 QList<QAction*> d_act; 196 int d_which; 197 }; 198 199 200 /********************************************************************/ 201 202 203 class LineStyleMenu : public QMenu 204 { 205 Q_OBJECT 206 207 public: LineStyleMenu(unsigned int which,QWidget * parent)208 LineStyleMenu(unsigned int which, QWidget* parent) 209 : QMenu("Line Style", parent), d_which(which) 210 { 211 d_grp = new QActionGroup(this); 212 213 d_act.push_back(new QAction("None", this)); 214 d_act.push_back(new QAction("Solid", this)); 215 d_act.push_back(new QAction("Dash", this)); 216 d_act.push_back(new QAction("Dots", this)); 217 d_act.push_back(new QAction("Dash-Dot", this)); 218 d_act.push_back(new QAction("Dash-Dot-Dot", this)); 219 220 connect(d_act[0], SIGNAL(triggered()), this, SLOT(getNone())); 221 connect(d_act[1], SIGNAL(triggered()), this, SLOT(getSolid())); 222 connect(d_act[2], SIGNAL(triggered()), this, SLOT(getDash())); 223 connect(d_act[3], SIGNAL(triggered()), this, SLOT(getDots())); 224 connect(d_act[4], SIGNAL(triggered()), this, SLOT(getDashDot())); 225 connect(d_act[5], SIGNAL(triggered()), this, SLOT(getDashDotDot())); 226 227 QListIterator<QAction*> i(d_act); 228 while (i.hasNext()) { 229 QAction* a = i.next(); 230 a->setCheckable(true); 231 a->setActionGroup(d_grp); 232 addAction(a); 233 } 234 } 235 ~LineStyleMenu()236 ~LineStyleMenu() {} 237 getNumActions()238 int getNumActions() const { return d_act.size(); } 239 getAction(unsigned int which)240 QAction* getAction(unsigned int which) 241 { 242 if (which < static_cast<unsigned int>(d_act.size())) 243 return d_act[which]; 244 else 245 throw std::runtime_error("LineStyleMenu::getAction: which out of range.\n"); 246 } 247 248 signals: 249 void whichTrigger(unsigned int which, Qt::PenStyle); 250 251 public slots: getNone()252 void getNone() { emit whichTrigger(d_which, Qt::NoPen); } getSolid()253 void getSolid() { emit whichTrigger(d_which, Qt::SolidLine); } getDash()254 void getDash() { emit whichTrigger(d_which, Qt::DashLine); } getDots()255 void getDots() { emit whichTrigger(d_which, Qt::DotLine); } getDashDot()256 void getDashDot() { emit whichTrigger(d_which, Qt::DashDotLine); } getDashDotDot()257 void getDashDotDot() { emit whichTrigger(d_which, Qt::DashDotDotLine); } 258 259 private: 260 QActionGroup* d_grp; 261 QList<QAction*> d_act; 262 int d_which; 263 }; 264 265 266 /********************************************************************/ 267 268 269 class LineMarkerMenu : public QMenu 270 { 271 Q_OBJECT 272 273 public: LineMarkerMenu(unsigned int which,QWidget * parent)274 LineMarkerMenu(unsigned int which, QWidget* parent) 275 : QMenu("Line Marker", parent), d_which(which) 276 { 277 d_grp = new QActionGroup(this); 278 279 d_act.push_back(new QAction("None", this)); 280 d_act.push_back(new QAction("Circle", this)); 281 d_act.push_back(new QAction("Rectangle", this)); 282 d_act.push_back(new QAction("Diamond", this)); 283 d_act.push_back(new QAction("Triangle", this)); 284 d_act.push_back(new QAction("Down Triangle", this)); 285 d_act.push_back(new QAction("Left Triangle", this)); 286 d_act.push_back(new QAction("Right Triangle", this)); 287 d_act.push_back(new QAction("Cross", this)); 288 d_act.push_back(new QAction("X-Cross", this)); 289 d_act.push_back(new QAction("Horiz. Line", this)); 290 d_act.push_back(new QAction("Vert. Line", this)); 291 d_act.push_back(new QAction("Star 1", this)); 292 d_act.push_back(new QAction("Star 2", this)); 293 d_act.push_back(new QAction("Hexagon", this)); 294 295 connect(d_act[0], SIGNAL(triggered()), this, SLOT(getNone())); 296 connect(d_act[1], SIGNAL(triggered()), this, SLOT(getCircle())); 297 connect(d_act[2], SIGNAL(triggered()), this, SLOT(getRect())); 298 connect(d_act[3], SIGNAL(triggered()), this, SLOT(getDiamond())); 299 connect(d_act[4], SIGNAL(triggered()), this, SLOT(getTriangle())); 300 connect(d_act[5], SIGNAL(triggered()), this, SLOT(getDTriangle())); 301 connect(d_act[6], SIGNAL(triggered()), this, SLOT(getLTriangle())); 302 connect(d_act[7], SIGNAL(triggered()), this, SLOT(getRTriangle())); 303 connect(d_act[8], SIGNAL(triggered()), this, SLOT(getCross())); 304 connect(d_act[9], SIGNAL(triggered()), this, SLOT(getXCross())); 305 connect(d_act[10], SIGNAL(triggered()), this, SLOT(getHLine())); 306 connect(d_act[11], SIGNAL(triggered()), this, SLOT(getVLine())); 307 connect(d_act[12], SIGNAL(triggered()), this, SLOT(getStar1())); 308 connect(d_act[13], SIGNAL(triggered()), this, SLOT(getStar2())); 309 connect(d_act[14], SIGNAL(triggered()), this, SLOT(getHexagon())); 310 311 QListIterator<QAction*> i(d_act); 312 while (i.hasNext()) { 313 QAction* a = i.next(); 314 a->setCheckable(true); 315 a->setActionGroup(d_grp); 316 addAction(a); 317 } 318 } 319 ~LineMarkerMenu()320 ~LineMarkerMenu() {} 321 getNumActions()322 int getNumActions() const { return d_act.size(); } 323 getAction(unsigned int which)324 QAction* getAction(unsigned int which) 325 { 326 if (which < static_cast<unsigned int>(d_act.size())) 327 return d_act[which]; 328 else 329 throw std::runtime_error("LineMarkerMenu::getAction: which out of range.\n"); 330 } 331 332 signals: 333 void whichTrigger(unsigned int which, QwtSymbol::Style); 334 335 public slots: getNone()336 void getNone() { emit whichTrigger(d_which, QwtSymbol::NoSymbol); } getCircle()337 void getCircle() { emit whichTrigger(d_which, QwtSymbol::Ellipse); } getRect()338 void getRect() { emit whichTrigger(d_which, QwtSymbol::Rect); } getDiamond()339 void getDiamond() { emit whichTrigger(d_which, QwtSymbol::Diamond); } getTriangle()340 void getTriangle() { emit whichTrigger(d_which, QwtSymbol::Triangle); } getDTriangle()341 void getDTriangle() { emit whichTrigger(d_which, QwtSymbol::DTriangle); } getLTriangle()342 void getLTriangle() { emit whichTrigger(d_which, QwtSymbol::LTriangle); } getRTriangle()343 void getRTriangle() { emit whichTrigger(d_which, QwtSymbol::RTriangle); } getCross()344 void getCross() { emit whichTrigger(d_which, QwtSymbol::Cross); } getXCross()345 void getXCross() { emit whichTrigger(d_which, QwtSymbol::XCross); } getHLine()346 void getHLine() { emit whichTrigger(d_which, QwtSymbol::HLine); } getVLine()347 void getVLine() { emit whichTrigger(d_which, QwtSymbol::VLine); } getStar1()348 void getStar1() { emit whichTrigger(d_which, QwtSymbol::Star1); } getStar2()349 void getStar2() { emit whichTrigger(d_which, QwtSymbol::Star2); } getHexagon()350 void getHexagon() { emit whichTrigger(d_which, QwtSymbol::Hexagon); } 351 352 private: 353 QActionGroup* d_grp; 354 QList<QAction*> d_act; 355 int d_which; 356 }; 357 358 359 /********************************************************************/ 360 361 362 class MarkerAlphaMenu : public QMenu 363 { 364 Q_OBJECT 365 366 public: MarkerAlphaMenu(unsigned int which,QWidget * parent)367 MarkerAlphaMenu(unsigned int which, QWidget* parent) 368 : QMenu("Line Transparency", parent), d_which(which) 369 { 370 d_grp = new QActionGroup(this); 371 372 d_act.push_back(new QAction("None", this)); 373 d_act.push_back(new QAction("Low", this)); 374 d_act.push_back(new QAction("Medium", this)); 375 d_act.push_back(new QAction("High", this)); 376 d_act.push_back(new QAction("Off", this)); 377 378 connect(d_act[0], SIGNAL(triggered()), this, SLOT(getNone())); 379 connect(d_act[1], SIGNAL(triggered()), this, SLOT(getLow())); 380 connect(d_act[2], SIGNAL(triggered()), this, SLOT(getMedium())); 381 connect(d_act[3], SIGNAL(triggered()), this, SLOT(getHigh())); 382 connect(d_act[4], SIGNAL(triggered()), this, SLOT(getOff())); 383 384 QListIterator<QAction*> i(d_act); 385 while (i.hasNext()) { 386 QAction* a = i.next(); 387 a->setCheckable(true); 388 a->setActionGroup(d_grp); 389 addAction(a); 390 } 391 } 392 ~MarkerAlphaMenu()393 ~MarkerAlphaMenu() {} 394 getNumActions()395 int getNumActions() const { return d_act.size(); } 396 getAction(unsigned int which)397 QAction* getAction(unsigned int which) 398 { 399 if (which < static_cast<unsigned int>(d_act.size())) 400 return d_act[which]; 401 else 402 throw std::runtime_error("MarkerAlphaMenu::getAction: which out of range.\n"); 403 } 404 405 signals: 406 void whichTrigger(unsigned int which, unsigned int); 407 408 public slots: getNone()409 void getNone() { emit whichTrigger(d_which, 255); } getLow()410 void getLow() { emit whichTrigger(d_which, 200); } getMedium()411 void getMedium() { emit whichTrigger(d_which, 125); } getHigh()412 void getHigh() { emit whichTrigger(d_which, 50); } getOff()413 void getOff() { emit whichTrigger(d_which, 0); } 414 415 private: 416 QActionGroup* d_grp; 417 QList<QAction*> d_act; 418 int d_which; 419 }; 420 421 422 /********************************************************************/ 423 424 425 class LineTitleAction : public QAction 426 { 427 Q_OBJECT 428 429 public: LineTitleAction(unsigned int which,QWidget * parent)430 LineTitleAction(unsigned int which, QWidget* parent) 431 : QAction("Line Title", parent), d_which(which) 432 { 433 d_diag = new QDialog(parent); 434 d_diag->setModal(true); 435 436 d_text = new QLineEdit(); 437 438 QGridLayout* layout = new QGridLayout(d_diag); 439 QPushButton* btn_ok = new QPushButton(tr("OK")); 440 QPushButton* btn_cancel = new QPushButton(tr("Cancel")); 441 442 layout->addWidget(d_text, 0, 0, 1, 2); 443 layout->addWidget(btn_ok, 1, 0); 444 layout->addWidget(btn_cancel, 1, 1); 445 446 connect(btn_ok, SIGNAL(clicked()), this, SLOT(getText())); 447 connect(btn_cancel, SIGNAL(clicked()), d_diag, SLOT(close())); 448 449 connect(this, SIGNAL(triggered()), this, SLOT(getTextDiag())); 450 } 451 ~LineTitleAction()452 ~LineTitleAction() {} 453 454 signals: 455 void whichTrigger(unsigned int which, const QString& text); 456 457 public slots: getTextDiag()458 void getTextDiag() { d_diag->exec(); } 459 460 private slots: getText()461 void getText() 462 { 463 emit whichTrigger(d_which, d_text->text()); 464 d_diag->accept(); 465 } 466 467 private: 468 int d_which; 469 470 QDialog* d_diag; 471 QLineEdit* d_text; 472 }; 473 474 475 /********************************************************************/ 476 477 478 class OtherAction : public QAction 479 { 480 Q_OBJECT 481 482 public: OtherAction(QWidget * parent)483 OtherAction(QWidget* parent) : QAction("Other", parent) 484 { 485 d_diag = new QDialog(parent); 486 d_diag->setWindowTitle("Other"); 487 d_diag->setModal(true); 488 489 d_text = new QLineEdit(); 490 491 QGridLayout* layout = new QGridLayout(d_diag); 492 QPushButton* btn_ok = new QPushButton(tr("OK")); 493 QPushButton* btn_cancel = new QPushButton(tr("Cancel")); 494 495 layout->addWidget(d_text, 0, 0, 1, 2); 496 layout->addWidget(btn_ok, 1, 0); 497 layout->addWidget(btn_cancel, 1, 1); 498 499 connect(btn_ok, SIGNAL(clicked()), this, SLOT(getText())); 500 connect(btn_cancel, SIGNAL(clicked()), d_diag, SLOT(close())); 501 502 connect(this, SIGNAL(triggered()), this, SLOT(getTextDiag())); 503 } 504 ~OtherAction()505 ~OtherAction() {} 506 setValidator(QValidator * v)507 void setValidator(QValidator* v) { d_text->setValidator(v); } 508 setDiagText(QString text)509 void setDiagText(QString text) { d_text->setText(text); } 510 511 signals: 512 void whichTrigger(const QString& text); 513 514 public slots: getTextDiag()515 void getTextDiag() { d_diag->exec(); } 516 517 private slots: getText()518 void getText() 519 { 520 emit whichTrigger(d_text->text()); 521 d_diag->accept(); 522 } 523 524 private: 525 QDialog* d_diag; 526 QLineEdit* d_text; 527 }; 528 529 /********************************************************************/ 530 531 532 class OtherDualAction : public QAction 533 { 534 Q_OBJECT 535 536 public: OtherDualAction(QString label0,QString label1,QWidget * parent)537 OtherDualAction(QString label0, QString label1, QWidget* parent) 538 : QAction("Other", parent) 539 { 540 d_diag = new QDialog(parent); 541 d_diag->setWindowTitle("Other"); 542 d_diag->setModal(true); 543 544 d_text0 = new QLineEdit(); 545 d_text1 = new QLineEdit(); 546 547 QLabel* _label0 = new QLabel(label0); 548 QLabel* _label1 = new QLabel(label1); 549 550 QGridLayout* layout = new QGridLayout(d_diag); 551 QPushButton* btn_ok = new QPushButton(tr("OK")); 552 QPushButton* btn_cancel = new QPushButton(tr("Cancel")); 553 554 layout->addWidget(_label0, 0, 0, 1, 2); 555 layout->addWidget(_label1, 1, 0, 1, 2); 556 557 layout->addWidget(d_text0, 0, 1, 1, 2); 558 layout->addWidget(d_text1, 1, 1, 1, 2); 559 layout->addWidget(btn_ok, 2, 0); 560 layout->addWidget(btn_cancel, 2, 1); 561 562 connect(btn_ok, SIGNAL(clicked()), this, SLOT(getText())); 563 connect(btn_cancel, SIGNAL(clicked()), d_diag, SLOT(close())); 564 565 connect(this, SIGNAL(triggered()), this, SLOT(getTextDiag())); 566 } 567 ~OtherDualAction()568 ~OtherDualAction() {} 569 570 signals: 571 void whichTrigger(const QString& text0, const QString& text1); 572 573 public slots: getTextDiag()574 void getTextDiag() { d_diag->exec(); } 575 576 private slots: getText()577 void getText() 578 { 579 emit whichTrigger(d_text0->text(), d_text1->text()); 580 d_diag->accept(); 581 } 582 583 private: 584 QDialog* d_diag; 585 QLineEdit* d_text0; 586 QLineEdit* d_text1; 587 }; 588 589 590 /********************************************************************/ 591 592 593 class FFTSizeMenu : public QMenu 594 { 595 Q_OBJECT 596 597 public: FFTSizeMenu(QWidget * parent)598 FFTSizeMenu(QWidget* parent) : QMenu("FFT Size", parent) 599 { 600 d_grp = new QActionGroup(this); 601 602 d_act.push_back(new QAction("32", this)); 603 d_act.push_back(new QAction("64", this)); 604 d_act.push_back(new QAction("128", this)); 605 d_act.push_back(new QAction("256", this)); 606 d_act.push_back(new QAction("512", this)); 607 d_act.push_back(new QAction("1024", this)); 608 d_act.push_back(new QAction("2048", this)); 609 d_act.push_back(new QAction("4096", this)); 610 // d_act.push_back(new QAction("8192", this)); 611 // d_act.push_back(new QAction("16384", this)); 612 // d_act.push_back(new QAction("32768", this)); 613 d_act.push_back(new OtherAction(this)); 614 615 d_grp = new QActionGroup(this); 616 for (int t = 0; t < d_act.size(); t++) { 617 d_act[t]->setCheckable(true); 618 d_act[t]->setActionGroup(d_grp); 619 } 620 621 QIntValidator* valid = new QIntValidator(32, 4096, this); 622 ((OtherAction*)d_act[d_act.size() - 1])->setValidator(valid); 623 624 connect(d_act[0], SIGNAL(triggered()), this, SLOT(get05())); 625 connect(d_act[1], SIGNAL(triggered()), this, SLOT(get06())); 626 connect(d_act[2], SIGNAL(triggered()), this, SLOT(get07())); 627 connect(d_act[3], SIGNAL(triggered()), this, SLOT(get08())); 628 connect(d_act[4], SIGNAL(triggered()), this, SLOT(get09())); 629 connect(d_act[5], SIGNAL(triggered()), this, SLOT(get10())); 630 connect(d_act[6], SIGNAL(triggered()), this, SLOT(get11())); 631 connect(d_act[7], SIGNAL(triggered()), this, SLOT(get12())); 632 // connect(d_act[8], SIGNAL(triggered()), this, SLOT(get13())); 633 // connect(d_act[9], SIGNAL(triggered()), this, SLOT(get14())); 634 // connect(d_act[10], SIGNAL(triggered()), this, SLOT(get15())); 635 connect(d_act[8], 636 SIGNAL(whichTrigger(const QString&)), 637 this, 638 SLOT(getOther(const QString&))); 639 640 QListIterator<QAction*> i(d_act); 641 while (i.hasNext()) { 642 QAction* a = i.next(); 643 a->setCheckable(true); 644 a->setActionGroup(d_grp); 645 addAction(a); 646 } 647 } 648 ~FFTSizeMenu()649 ~FFTSizeMenu() {} 650 getNumActions()651 int getNumActions() const { return d_act.size(); } 652 getAction(unsigned int which)653 QAction* getAction(unsigned int which) 654 { 655 if (which < static_cast<unsigned int>(d_act.size())) 656 return d_act[which]; 657 else 658 throw std::runtime_error("FFTSizeMenu::getAction: which out of range.\n"); 659 } 660 getActionFromSize(int size)661 QAction* getActionFromSize(int size) 662 { 663 float ipt; 664 float which = std::log(static_cast<float>(size)) / std::log(2.0f) - 5; 665 // If we're a predefined value 666 if (std::modf(which, &ipt) == 0) { 667 if (which < static_cast<unsigned int>(d_act.size()) - 1) 668 return d_act[static_cast<int>(which)]; 669 else 670 throw std::runtime_error( 671 "FFTSizeMenu::getActionFromString: which out of range.\n"); 672 } 673 // Or a non-predefined value, return Other 674 else { 675 ((OtherAction*)d_act[d_act.size() - 1])->setDiagText(QString().setNum(size)); 676 return d_act[d_act.size() - 1]; 677 } 678 } 679 680 signals: 681 void whichTrigger(int size); 682 683 public slots: get05()684 void get05() { emit whichTrigger(32); } get06()685 void get06() { emit whichTrigger(64); } get07()686 void get07() { emit whichTrigger(128); } get08()687 void get08() { emit whichTrigger(256); } get09()688 void get09() { emit whichTrigger(512); } get10()689 void get10() { emit whichTrigger(1024); } get11()690 void get11() { emit whichTrigger(2048); } get12()691 void get12() { emit whichTrigger(4096); } 692 // void get13() { emit whichTrigger(8192); } 693 // void get14() { emit whichTrigger(16384); } 694 // void get15() { emit whichTrigger(32768); } getOther(const QString & str)695 void getOther(const QString& str) 696 { 697 int value = str.toInt(); 698 emit whichTrigger(value); 699 } 700 701 private: 702 QList<QAction*> d_act; 703 QActionGroup* d_grp; 704 }; 705 706 /********************************************************************/ 707 708 class AverageMenu : public QMenu 709 { 710 Q_OBJECT 711 712 public: AverageMenu(const std::string & menuTitle,QWidget * parent)713 AverageMenu(const std::string& menuTitle, QWidget* parent) 714 : QMenu(menuTitle.c_str(), parent) 715 { 716 d_grp = new QActionGroup(this); 717 718 d_off = 1.0; 719 d_high = 0.05; 720 d_medium = 0.1; 721 d_low = 0.2; 722 723 d_act.push_back(new QAction("Off", this)); 724 d_act.push_back(new QAction("High", this)); 725 d_act.push_back(new QAction("Medium", this)); 726 d_act.push_back(new QAction("Low", this)); 727 d_act.push_back(new OtherAction(this)); 728 729 d_grp = new QActionGroup(this); 730 for (int t = 0; t < d_act.size(); t++) { 731 d_act[t]->setCheckable(true); 732 d_act[t]->setActionGroup(d_grp); 733 } 734 d_act[0]->setChecked(true); 735 736 QDoubleValidator* valid = new QDoubleValidator(0.0, 1.0, 3, this); 737 ((OtherAction*)d_act[d_act.size() - 1])->setValidator(valid); 738 739 connect(d_act[0], SIGNAL(triggered()), this, SLOT(getOff())); 740 connect(d_act[1], SIGNAL(triggered()), this, SLOT(getHigh())); 741 connect(d_act[2], SIGNAL(triggered()), this, SLOT(getMedium())); 742 connect(d_act[3], SIGNAL(triggered()), this, SLOT(getLow())); 743 connect(d_act[4], 744 SIGNAL(whichTrigger(const QString&)), 745 this, 746 SLOT(getOther(const QString&))); 747 748 QListIterator<QAction*> i(d_act); 749 while (i.hasNext()) { 750 QAction* a = i.next(); 751 a->setCheckable(true); 752 a->setActionGroup(d_grp); 753 addAction(a); 754 } 755 } 756 ~AverageMenu()757 ~AverageMenu() {} 758 getNumActions()759 int getNumActions() const { return d_act.size(); } 760 getAction(unsigned int which)761 QAction* getAction(unsigned int which) 762 { 763 if (which < static_cast<unsigned int>(d_act.size())) 764 return d_act[which]; 765 else 766 throw std::runtime_error("FFTSizeMenu::getAction: which out of range.\n"); 767 } 768 getActionFromAvg(float avg)769 QAction* getActionFromAvg(float avg) 770 { 771 int which = 0; 772 if (avg == d_off) 773 which = 0; 774 else if (avg == d_high) 775 which = 1; 776 else if (avg == d_medium) 777 which = 2; 778 else if (avg == d_low) 779 which = 3; 780 else { 781 ((OtherAction*)d_act[d_act.size() - 1])->setDiagText(QString().setNum(avg)); 782 which = 4; 783 } 784 return d_act[static_cast<int>(which)]; 785 } 786 setHigh(float x)787 void setHigh(float x) { d_high = x; } 788 setMedium(float x)789 void setMedium(float x) { d_medium = x; } 790 setLow(float x)791 void setLow(float x) { d_low = x; } 792 793 signals: 794 void whichTrigger(float alpha); 795 796 public slots: getOff()797 void getOff() { emit whichTrigger(d_off); } getHigh()798 void getHigh() { emit whichTrigger(d_high); } getMedium()799 void getMedium() { emit whichTrigger(d_medium); } getLow()800 void getLow() { emit whichTrigger(d_low); } getOther(const QString & str)801 void getOther(const QString& str) 802 { 803 float value = str.toFloat(); 804 emit whichTrigger(value); 805 } 806 807 private: 808 QList<QAction*> d_act; 809 QActionGroup* d_grp; 810 float d_off, d_high, d_medium, d_low; 811 }; 812 813 /********************************************************************/ 814 815 class FFTAverageMenu : public AverageMenu 816 { 817 public: FFTAverageMenu(QWidget * parent)818 FFTAverageMenu(QWidget* parent) : AverageMenu("FFT Average", parent) 819 { 820 // nop 821 } 822 ~FFTAverageMenu()823 ~FFTAverageMenu() {} 824 }; 825 826 /********************************************************************/ 827 828 829 class FFTWindowMenu : public QMenu 830 { 831 Q_OBJECT 832 833 public: FFTWindowMenu(QWidget * parent)834 FFTWindowMenu(QWidget* parent) : QMenu("FFT Window", parent) 835 { 836 d_act.push_back(new QAction("None", this)); 837 d_act.push_back(new QAction("Hamming", this)); 838 d_act.push_back(new QAction("Hann", this)); 839 d_act.push_back(new QAction("Blackman", this)); 840 d_act.push_back(new QAction("Blackman-harris", this)); 841 d_act.push_back(new QAction("Rectangular", this)); 842 d_act.push_back(new QAction("Kaiser", this)); 843 d_act.push_back(new QAction("Flat-top", this)); 844 845 d_grp = new QActionGroup(this); 846 for (int t = 0; t < d_act.size(); t++) { 847 d_act[t]->setCheckable(true); 848 d_act[t]->setActionGroup(d_grp); 849 } 850 851 connect(d_act[0], SIGNAL(triggered()), this, SLOT(getNone())); 852 connect(d_act[1], SIGNAL(triggered()), this, SLOT(getHamming())); 853 connect(d_act[2], SIGNAL(triggered()), this, SLOT(getHann())); 854 connect(d_act[3], SIGNAL(triggered()), this, SLOT(getBlackman())); 855 connect(d_act[4], SIGNAL(triggered()), this, SLOT(getBlackmanharris())); 856 connect(d_act[5], SIGNAL(triggered()), this, SLOT(getRectangular())); 857 connect(d_act[6], SIGNAL(triggered()), this, SLOT(getKaiser())); 858 connect(d_act[7], SIGNAL(triggered()), this, SLOT(getFlattop())); 859 860 QListIterator<QAction*> i(d_act); 861 while (i.hasNext()) { 862 QAction* a = i.next(); 863 addAction(a); 864 } 865 } 866 ~FFTWindowMenu()867 ~FFTWindowMenu() {} 868 getNumActions()869 int getNumActions() const { return d_act.size(); } 870 getAction(unsigned int which)871 QAction* getAction(unsigned int which) 872 { 873 if (which < static_cast<unsigned int>(d_act.size())) 874 return d_act[which]; 875 else 876 throw std::runtime_error("FFTWindowMenu::getAction: which out of range.\n"); 877 } 878 getActionFromWindow(gr::filter::firdes::win_type type)879 QAction* getActionFromWindow(gr::filter::firdes::win_type type) 880 { 881 int which = 0; 882 switch (static_cast<int>(type)) { 883 case ((gr::filter::firdes::WIN_NONE)): 884 which = 0; 885 break; 886 case ((gr::filter::firdes::WIN_HAMMING)): 887 which = 1; 888 break; 889 case ((gr::filter::firdes::WIN_HANN)): 890 which = 2; 891 break; 892 case ((gr::filter::firdes::WIN_BLACKMAN)): 893 which = 3; 894 break; 895 case ((gr::filter::firdes::WIN_BLACKMAN_hARRIS)): 896 which = 4; 897 break; 898 case ((gr::filter::firdes::WIN_RECTANGULAR)): 899 which = 5; 900 break; 901 case ((gr::filter::firdes::WIN_KAISER)): 902 which = 6; 903 break; 904 case ((gr::filter::firdes::WIN_FLATTOP)): 905 which = 7; 906 break; 907 } 908 return d_act[which]; 909 } 910 911 signals: 912 void whichTrigger(const gr::filter::firdes::win_type type); 913 914 public slots: getNone()915 void getNone() { emit whichTrigger(gr::filter::firdes::WIN_NONE); } getHamming()916 void getHamming() { emit whichTrigger(gr::filter::firdes::WIN_HAMMING); } getHann()917 void getHann() { emit whichTrigger(gr::filter::firdes::WIN_HANN); } getBlackman()918 void getBlackman() { emit whichTrigger(gr::filter::firdes::WIN_BLACKMAN); } getBlackmanharris()919 void getBlackmanharris() 920 { 921 emit whichTrigger(gr::filter::firdes::WIN_BLACKMAN_hARRIS); 922 } getRectangular()923 void getRectangular() { emit whichTrigger(gr::filter::firdes::WIN_RECTANGULAR); } getKaiser()924 void getKaiser() { emit whichTrigger(gr::filter::firdes::WIN_KAISER); } getFlattop()925 void getFlattop() { emit whichTrigger(gr::filter::firdes::WIN_FLATTOP); } 926 927 private: 928 QList<QAction*> d_act; 929 QActionGroup* d_grp; 930 }; 931 932 933 /********************************************************************/ 934 935 936 class NPointsMenu : public QAction 937 { 938 Q_OBJECT 939 940 public: NPointsMenu(QWidget * parent)941 NPointsMenu(QWidget* parent) : QAction("Number of Points", parent) 942 { 943 d_diag = new QDialog(parent); 944 d_diag->setWindowTitle("Number of Points"); 945 d_diag->setModal(true); 946 947 d_text = new QLineEdit(); 948 949 QGridLayout* layout = new QGridLayout(d_diag); 950 QPushButton* btn_ok = new QPushButton(tr("OK")); 951 QPushButton* btn_cancel = new QPushButton(tr("Cancel")); 952 953 layout->addWidget(d_text, 0, 0, 1, 2); 954 layout->addWidget(btn_ok, 1, 0); 955 layout->addWidget(btn_cancel, 1, 1); 956 957 connect(btn_ok, SIGNAL(clicked()), this, SLOT(getText())); 958 connect(btn_cancel, SIGNAL(clicked()), d_diag, SLOT(close())); 959 960 connect(this, SIGNAL(triggered()), this, SLOT(getTextDiag())); 961 } 962 ~NPointsMenu()963 ~NPointsMenu() {} 964 965 signals: 966 void whichTrigger(const int npts); 967 968 public slots: setDiagText(const int npts)969 void setDiagText(const int npts) { d_text->setText(QString().setNum(npts)); } 970 getTextDiag()971 void getTextDiag() { d_diag->show(); } 972 973 private slots: getText()974 void getText() 975 { 976 emit whichTrigger(d_text->text().toInt()); 977 d_diag->accept(); 978 } 979 980 private: 981 QDialog* d_diag; 982 QLineEdit* d_text; 983 }; 984 985 986 /********************************************************************/ 987 988 989 class ColorMapMenu : public QMenu 990 { 991 Q_OBJECT 992 993 public: ColorMapMenu(unsigned int which,QWidget * parent)994 ColorMapMenu(unsigned int which, QWidget* parent) 995 : QMenu("Color Map", parent), d_which(which) 996 { 997 d_grp = new QActionGroup(this); 998 999 d_act.push_back(new QAction("Multi-Color", this)); 1000 d_act.push_back(new QAction("White Hot", this)); 1001 d_act.push_back(new QAction("Black Hot", this)); 1002 d_act.push_back(new QAction("Incandescent", this)); 1003 d_act.push_back(new QAction("Sunset", this)); 1004 d_act.push_back(new QAction("Cool", this)); 1005 d_act.push_back(new QAction("Other", this)); 1006 // d_act.push_back(new OtherDualAction("Min Intensity: ", "Max Intensity: ", 1007 // this)); 1008 1009 connect(d_act[0], SIGNAL(triggered()), this, SLOT(getMultiColor())); 1010 connect(d_act[1], SIGNAL(triggered()), this, SLOT(getWhiteHot())); 1011 connect(d_act[2], SIGNAL(triggered()), this, SLOT(getBlackHot())); 1012 connect(d_act[3], SIGNAL(triggered()), this, SLOT(getIncandescent())); 1013 connect(d_act[4], SIGNAL(triggered()), this, SLOT(getSunset())); 1014 connect(d_act[5], SIGNAL(triggered()), this, SLOT(getCool())); 1015 connect(d_act[6], SIGNAL(triggered()), this, SLOT(getOther())); 1016 1017 QListIterator<QAction*> i(d_act); 1018 while (i.hasNext()) { 1019 QAction* a = i.next(); 1020 a->setCheckable(true); 1021 a->setActionGroup(d_grp); 1022 addAction(a); 1023 } 1024 1025 d_max_value = QColor("white"); 1026 d_min_value = QColor("white"); 1027 } 1028 ~ColorMapMenu()1029 ~ColorMapMenu() {} 1030 getNumActions()1031 int getNumActions() const { return d_act.size(); } 1032 getAction(unsigned int which)1033 QAction* getAction(unsigned int which) 1034 { 1035 if (which < static_cast<unsigned int>(d_act.size())) 1036 return d_act[which]; 1037 else 1038 throw std::runtime_error("ColorMapMenu::getAction: which out of range.\n"); 1039 } 1040 1041 signals: 1042 void whichTrigger(unsigned int which, 1043 const int type, 1044 const QColor& min_color = QColor(), 1045 const QColor& max_color = QColor()); 1046 1047 public slots: getMultiColor()1048 void getMultiColor() 1049 { 1050 emit whichTrigger(d_which, INTENSITY_COLOR_MAP_TYPE_MULTI_COLOR); 1051 } getWhiteHot()1052 void getWhiteHot() { emit whichTrigger(d_which, INTENSITY_COLOR_MAP_TYPE_WHITE_HOT); } getBlackHot()1053 void getBlackHot() { emit whichTrigger(d_which, INTENSITY_COLOR_MAP_TYPE_BLACK_HOT); } getIncandescent()1054 void getIncandescent() 1055 { 1056 emit whichTrigger(d_which, INTENSITY_COLOR_MAP_TYPE_INCANDESCENT); 1057 } getSunset()1058 void getSunset() { emit whichTrigger(d_which, INTENSITY_COLOR_MAP_TYPE_SUNSET); } getCool()1059 void getCool() { emit whichTrigger(d_which, INTENSITY_COLOR_MAP_TYPE_COOL); } 1060 // void getOther(d_which, const QString &min_str, const QString &max_str) getOther()1061 void getOther() 1062 { 1063 QMessageBox::information( 1064 this, 1065 "Set low and high intensities", 1066 "In the next windows, select the low and then the high intensity colors.", 1067 QMessageBox::Ok); 1068 d_min_value = QColorDialog::getColor(d_min_value, this); 1069 d_max_value = QColorDialog::getColor(d_max_value, this); 1070 1071 emit whichTrigger( 1072 d_which, INTENSITY_COLOR_MAP_TYPE_USER_DEFINED, d_min_value, d_max_value); 1073 } 1074 1075 private: 1076 QActionGroup* d_grp; 1077 QList<QAction*> d_act; 1078 QColor d_max_value, d_min_value; 1079 int d_which; 1080 }; 1081 1082 1083 /********************************************************************/ 1084 1085 1086 class TriggerModeMenu : public QMenu 1087 { 1088 Q_OBJECT 1089 1090 public: TriggerModeMenu(QWidget * parent)1091 TriggerModeMenu(QWidget* parent) : QMenu("Mode", parent) 1092 { 1093 d_grp = new QActionGroup(this); 1094 d_act.push_back(new QAction("Free", this)); 1095 d_act.push_back(new QAction("Auto", this)); 1096 d_act.push_back(new QAction("Normal", this)); 1097 d_act.push_back(new QAction("Tag", this)); 1098 1099 connect(d_act[0], SIGNAL(triggered()), this, SLOT(getFree())); 1100 connect(d_act[1], SIGNAL(triggered()), this, SLOT(getAuto())); 1101 connect(d_act[2], SIGNAL(triggered()), this, SLOT(getNorm())); 1102 connect(d_act[3], SIGNAL(triggered()), this, SLOT(getTag())); 1103 1104 QListIterator<QAction*> i(d_act); 1105 while (i.hasNext()) { 1106 QAction* a = i.next(); 1107 a->setCheckable(true); 1108 a->setActionGroup(d_grp); 1109 addAction(a); 1110 } 1111 } 1112 ~TriggerModeMenu()1113 ~TriggerModeMenu() {} 1114 getNumActions()1115 int getNumActions() const { return d_act.size(); } 1116 getAction(unsigned int which)1117 QAction* getAction(unsigned int which) 1118 { 1119 if (which < static_cast<unsigned int>(d_act.size())) 1120 return d_act[which]; 1121 else 1122 throw std::runtime_error("TriggerModeMenu::getAction: which out of range.\n"); 1123 } 1124 getAction(gr::qtgui::trigger_mode mode)1125 QAction* getAction(gr::qtgui::trigger_mode mode) 1126 { 1127 switch (mode) { 1128 case gr::qtgui::TRIG_MODE_FREE: 1129 return d_act[0]; 1130 break; 1131 case gr::qtgui::TRIG_MODE_AUTO: 1132 return d_act[1]; 1133 break; 1134 case gr::qtgui::TRIG_MODE_NORM: 1135 return d_act[2]; 1136 break; 1137 case gr::qtgui::TRIG_MODE_TAG: 1138 return d_act[3]; 1139 break; 1140 default: 1141 throw std::runtime_error( 1142 "TriggerModeMenu::getAction: unknown trigger mode.\n"); 1143 } 1144 } 1145 1146 signals: 1147 void whichTrigger(gr::qtgui::trigger_mode mode); 1148 1149 public slots: getFree()1150 void getFree() { emit whichTrigger(gr::qtgui::TRIG_MODE_FREE); } getAuto()1151 void getAuto() { emit whichTrigger(gr::qtgui::TRIG_MODE_AUTO); } getNorm()1152 void getNorm() { emit whichTrigger(gr::qtgui::TRIG_MODE_NORM); } getTag()1153 void getTag() { emit whichTrigger(gr::qtgui::TRIG_MODE_TAG); } 1154 1155 private: 1156 QList<QAction*> d_act; 1157 QActionGroup* d_grp; 1158 }; 1159 1160 1161 /********************************************************************/ 1162 1163 1164 class TriggerSlopeMenu : public QMenu 1165 { 1166 Q_OBJECT 1167 1168 public: TriggerSlopeMenu(QWidget * parent)1169 TriggerSlopeMenu(QWidget* parent) : QMenu("Slope", parent) 1170 { 1171 d_grp = new QActionGroup(this); 1172 d_act.push_back(new QAction("Positive", this)); 1173 d_act.push_back(new QAction("Negative", this)); 1174 1175 connect(d_act[0], SIGNAL(triggered()), this, SLOT(getPos())); 1176 connect(d_act[1], SIGNAL(triggered()), this, SLOT(getNeg())); 1177 1178 QListIterator<QAction*> i(d_act); 1179 while (i.hasNext()) { 1180 QAction* a = i.next(); 1181 a->setCheckable(true); 1182 a->setActionGroup(d_grp); 1183 addAction(a); 1184 } 1185 } 1186 ~TriggerSlopeMenu()1187 ~TriggerSlopeMenu() {} 1188 getNumActions()1189 int getNumActions() const { return d_act.size(); } 1190 getAction(unsigned int which)1191 QAction* getAction(unsigned int which) 1192 { 1193 if (which < static_cast<unsigned int>(d_act.size())) 1194 return d_act[which]; 1195 else 1196 throw std::runtime_error( 1197 "TriggerSlopeMenu::getAction: which out of range.\n"); 1198 } 1199 getAction(gr::qtgui::trigger_slope slope)1200 QAction* getAction(gr::qtgui::trigger_slope slope) 1201 { 1202 switch (slope) { 1203 case gr::qtgui::TRIG_SLOPE_POS: 1204 return d_act[0]; 1205 break; 1206 case gr::qtgui::TRIG_SLOPE_NEG: 1207 return d_act[1]; 1208 break; 1209 default: 1210 throw std::runtime_error( 1211 "TriggerSlopeMenu::getAction: unknown trigger slope.\n"); 1212 } 1213 } 1214 1215 signals: 1216 void whichTrigger(gr::qtgui::trigger_slope slope); 1217 1218 public slots: getPos()1219 void getPos() { emit whichTrigger(gr::qtgui::TRIG_SLOPE_POS); } getNeg()1220 void getNeg() { emit whichTrigger(gr::qtgui::TRIG_SLOPE_NEG); } 1221 1222 private: 1223 QList<QAction*> d_act; 1224 QActionGroup* d_grp; 1225 }; 1226 1227 1228 /********************************************************************/ 1229 1230 1231 class TriggerChannelMenu : public QMenu 1232 { 1233 Q_OBJECT 1234 1235 public: TriggerChannelMenu(int nchans,QWidget * parent)1236 TriggerChannelMenu(int nchans, QWidget* parent) : QMenu("Channel", parent) 1237 { 1238 d_grp = new QActionGroup(this); 1239 for (int i = 0; i < nchans; i++) { 1240 d_act.push_back(new QAction(QString().setNum(i), this)); 1241 d_act[i]->setCheckable(true); 1242 d_act[i]->setActionGroup(d_grp); 1243 1244 addAction(d_act[i]); 1245 connect(d_act[i], SIGNAL(triggered()), this, SLOT(getChannel())); 1246 } 1247 } 1248 ~TriggerChannelMenu()1249 ~TriggerChannelMenu() {} 1250 getNumActions()1251 int getNumActions() const { return d_act.size(); } 1252 getAction(unsigned int which)1253 QAction* getAction(unsigned int which) 1254 { 1255 if (which < static_cast<unsigned int>(d_act.size())) 1256 return d_act[which]; 1257 else 1258 throw std::runtime_error( 1259 "TriggerChannelMenu::getAction: which out of range.\n"); 1260 } 1261 1262 1263 signals: 1264 void whichTrigger(int n); 1265 1266 public slots: getChannel()1267 void getChannel() 1268 { 1269 QAction* a = d_grp->checkedAction(); 1270 int which = a->text().toInt(); 1271 emit whichTrigger(which); 1272 } 1273 1274 private: 1275 QList<QAction*> d_act; 1276 QActionGroup* d_grp; 1277 }; 1278 1279 1280 /********************************************************************/ 1281 1282 1283 class NumberLayoutMenu : public QMenu 1284 { 1285 Q_OBJECT 1286 1287 public: NumberLayoutMenu(QWidget * parent)1288 NumberLayoutMenu(QWidget* parent) : QMenu("Layout", parent) 1289 { 1290 d_grp = new QActionGroup(this); 1291 d_act.push_back(new QAction("Horizontal", this)); 1292 d_act.push_back(new QAction("Vertical", this)); 1293 d_act.push_back(new QAction("None", this)); 1294 1295 connect(d_act[0], SIGNAL(triggered()), this, SLOT(getHoriz())); 1296 connect(d_act[1], SIGNAL(triggered()), this, SLOT(getVert())); 1297 connect(d_act[2], SIGNAL(triggered()), this, SLOT(getNone())); 1298 1299 QListIterator<QAction*> i(d_act); 1300 while (i.hasNext()) { 1301 QAction* a = i.next(); 1302 a->setCheckable(true); 1303 a->setActionGroup(d_grp); 1304 addAction(a); 1305 } 1306 } 1307 ~NumberLayoutMenu()1308 ~NumberLayoutMenu() {} 1309 getNumActions()1310 int getNumActions() const { return d_act.size(); } 1311 getAction(unsigned int which)1312 QAction* getAction(unsigned int which) 1313 { 1314 if (which < static_cast<unsigned int>(d_act.size())) 1315 return d_act[which]; 1316 else 1317 throw std::runtime_error( 1318 "NumberLayoutMenu::getAction: which out of range.\n"); 1319 } 1320 getAction(gr::qtgui::graph_t layout)1321 QAction* getAction(gr::qtgui::graph_t layout) 1322 { 1323 switch (layout) { 1324 case gr::qtgui::NUM_GRAPH_HORIZ: 1325 return d_act[0]; 1326 break; 1327 case gr::qtgui::NUM_GRAPH_VERT: 1328 return d_act[1]; 1329 break; 1330 case gr::qtgui::NUM_GRAPH_NONE: 1331 return d_act[1]; 1332 break; 1333 default: 1334 throw std::runtime_error( 1335 "NumberLayoutMenu::getAction: unknown layout type.\n"); 1336 } 1337 } 1338 1339 signals: 1340 void whichTrigger(gr::qtgui::graph_t layout); 1341 1342 public slots: getHoriz()1343 void getHoriz() { emit whichTrigger(gr::qtgui::NUM_GRAPH_HORIZ); } getVert()1344 void getVert() { emit whichTrigger(gr::qtgui::NUM_GRAPH_VERT); } getNone()1345 void getNone() { emit whichTrigger(gr::qtgui::NUM_GRAPH_NONE); } 1346 1347 private: 1348 QList<QAction*> d_act; 1349 QActionGroup* d_grp; 1350 }; 1351 1352 1353 /********************************************************************/ 1354 1355 1356 class NumberColorMapMenu : public QMenu 1357 { 1358 Q_OBJECT 1359 1360 public: NumberColorMapMenu(unsigned int which,QWidget * parent)1361 NumberColorMapMenu(unsigned int which, QWidget* parent) 1362 : QMenu("Color Map", parent), d_which(which) 1363 { 1364 d_grp = new QActionGroup(this); 1365 1366 d_act.push_back(new QAction("Black", this)); 1367 d_act.push_back(new QAction("Blue-Red", this)); 1368 d_act.push_back(new QAction("White Hot", this)); 1369 d_act.push_back(new QAction("Black Hot", this)); 1370 d_act.push_back(new QAction("Black-Red", this)); 1371 d_act.push_back(new QAction("Other", this)); 1372 1373 connect(d_act[0], SIGNAL(triggered()), this, SLOT(getBlack())); 1374 connect(d_act[1], SIGNAL(triggered()), this, SLOT(getBlueRed())); 1375 connect(d_act[2], SIGNAL(triggered()), this, SLOT(getWhiteHot())); 1376 connect(d_act[3], SIGNAL(triggered()), this, SLOT(getBlackHot())); 1377 connect(d_act[4], SIGNAL(triggered()), this, SLOT(getBlackRed())); 1378 connect(d_act[5], SIGNAL(triggered()), this, SLOT(getOther())); 1379 1380 QListIterator<QAction*> i(d_act); 1381 while (i.hasNext()) { 1382 QAction* a = i.next(); 1383 a->setCheckable(true); 1384 a->setActionGroup(d_grp); 1385 addAction(a); 1386 } 1387 1388 d_max_value = QColor("black"); 1389 d_min_value = QColor("black"); 1390 } 1391 ~NumberColorMapMenu()1392 ~NumberColorMapMenu() {} 1393 getNumActions()1394 int getNumActions() const { return d_act.size(); } 1395 getAction(unsigned int which)1396 QAction* getAction(unsigned int which) 1397 { 1398 if (which < static_cast<unsigned int>(d_act.size())) 1399 return d_act[which]; 1400 else 1401 throw std::runtime_error("ColorMapMenu::getAction: which out of range.\n"); 1402 } 1403 1404 signals: 1405 void 1406 whichTrigger(unsigned int which, const QColor& min_color, const QColor& max_color); 1407 1408 public slots: getBlack()1409 void getBlack() { emit whichTrigger(d_which, QColor("black"), QColor("black")); } getBlueRed()1410 void getBlueRed() { emit whichTrigger(d_which, QColor("blue"), QColor("red")); } getWhiteHot()1411 void getWhiteHot() { emit whichTrigger(d_which, QColor("black"), QColor("white")); } getBlackHot()1412 void getBlackHot() { emit whichTrigger(d_which, QColor("white"), QColor("black")); } getBlackRed()1413 void getBlackRed() { emit whichTrigger(d_which, QColor("black"), QColor("red")); } getOther()1414 void getOther() 1415 { 1416 QMessageBox::information( 1417 this, 1418 "Set low and high intensities", 1419 "In the next windows, select the low and then the high intensity colors.", 1420 QMessageBox::Ok); 1421 d_min_value = QColorDialog::getColor(d_min_value, this); 1422 d_max_value = QColorDialog::getColor(d_max_value, this); 1423 1424 emit whichTrigger(d_which, d_min_value, d_max_value); 1425 } 1426 1427 private: 1428 QActionGroup* d_grp; 1429 QList<QAction*> d_act; 1430 QColor d_max_value, d_min_value; 1431 int d_which; 1432 }; 1433 1434 1435 /********************************************************************/ 1436 1437 1438 class PopupMenu : public QAction 1439 { 1440 Q_OBJECT 1441 1442 public: PopupMenu(QString desc,QWidget * parent)1443 PopupMenu(QString desc, QWidget* parent) : QAction(desc, parent) 1444 { 1445 d_diag = new QDialog(parent); 1446 d_diag->setWindowTitle(desc); 1447 d_diag->setModal(true); 1448 1449 d_text = new QLineEdit(); 1450 1451 QGridLayout* layout = new QGridLayout(d_diag); 1452 QPushButton* btn_ok = new QPushButton(tr("OK")); 1453 QPushButton* btn_cancel = new QPushButton(tr("Cancel")); 1454 1455 layout->addWidget(d_text, 0, 0, 1, 2); 1456 layout->addWidget(btn_ok, 1, 0); 1457 layout->addWidget(btn_cancel, 1, 1); 1458 1459 connect(btn_ok, SIGNAL(clicked()), this, SLOT(getText())); 1460 connect(btn_cancel, SIGNAL(clicked()), d_diag, SLOT(close())); 1461 1462 connect(this, SIGNAL(triggered()), this, SLOT(getTextDiag())); 1463 } 1464 ~PopupMenu()1465 ~PopupMenu() {} 1466 setText(QString s)1467 void setText(QString s) { d_text->setText(s); } 1468 1469 signals: 1470 void whichTrigger(const QString data); 1471 1472 public slots: getTextDiag()1473 void getTextDiag() { d_diag->show(); } 1474 1475 private slots: getText()1476 void getText() 1477 { 1478 emit whichTrigger(d_text->text()); 1479 d_diag->accept(); 1480 } 1481 1482 private: 1483 QDialog* d_diag; 1484 QLineEdit* d_text; 1485 }; 1486 1487 1488 /********************************************************************/ 1489 1490 1491 class ItemFloatAct : public QAction 1492 { 1493 Q_OBJECT 1494 1495 public: ItemFloatAct(unsigned int which,QString title,QWidget * parent)1496 ItemFloatAct(unsigned int which, QString title, QWidget* parent) 1497 : QAction(title, parent), d_which(which) 1498 { 1499 d_diag = new QDialog(parent); 1500 d_diag->setWindowTitle(title); 1501 d_diag->setModal(true); 1502 1503 d_text = new QLineEdit(); 1504 1505 QGridLayout* layout = new QGridLayout(d_diag); 1506 QPushButton* btn_ok = new QPushButton(tr("OK")); 1507 QPushButton* btn_cancel = new QPushButton(tr("Cancel")); 1508 1509 layout->addWidget(d_text, 0, 0, 1, 2); 1510 layout->addWidget(btn_ok, 1, 0); 1511 layout->addWidget(btn_cancel, 1, 1); 1512 1513 connect(btn_ok, SIGNAL(clicked()), this, SLOT(getText())); 1514 connect(btn_cancel, SIGNAL(clicked()), d_diag, SLOT(close())); 1515 1516 connect(this, SIGNAL(triggered()), this, SLOT(getTextDiag())); 1517 } 1518 ~ItemFloatAct()1519 ~ItemFloatAct() {} 1520 setText(float f)1521 void setText(float f) { d_text->setText(QString("%1").arg(f)); } 1522 1523 1524 signals: 1525 void whichTrigger(unsigned int which, float data); 1526 1527 public slots: getTextDiag()1528 void getTextDiag() { d_diag->show(); } 1529 1530 private slots: getText()1531 void getText() 1532 { 1533 emit whichTrigger(d_which, d_text->text().toFloat()); 1534 d_diag->accept(); 1535 } 1536 1537 private: 1538 int d_which; 1539 QDialog* d_diag; 1540 QLineEdit* d_text; 1541 }; 1542 1543 1544 /********************************************************************/ 1545 1546 1547 #endif /* FORM_MENUS_H */ 1548