| 636 | } |
| 637 | |
| 638 | void OutputWidget::addSection(const QString& section) |
| 639 | { |
| 640 | if (_sections.contains(section)) { |
| 641 | return; |
| 642 | } |
| 643 | _sections[section] = true; |
| 644 | |
| 645 | #ifdef Q_OS_MAC |
| 646 | auto* button = new QCheckBox(section); |
| 647 | #else |
| 648 | auto* button = new QPushButton(section); |
| 649 | button->setCursor(Qt::PointingHandCursor); |
| 650 | button->setFlat(true); |
| 651 | button->setCheckable(true); |
| 652 | #endif |
| 653 | button->setChecked(true); |
| 654 | |
| 655 | connect(button, &QAbstractButton::toggled, this, [=](bool checked) { setSectionVisibility(section, checked); }); |
| 656 | |
| 657 | auto* menu = new QMenu(button); |
| 658 | auto handler = [=] () { toggleSectionVisibility(section); }; |
| 659 | auto* toggleSection = menu->addAction("Show section", this, handler); |
| 660 | menu->addSeparator(); |
| 661 | menu->addAction("Show only this section", this, [=] () { |
| 662 | setAllSectionsVisibility(false); |
| 663 | setSectionVisibility(section, true); |
| 664 | }); |
| 665 | menu->addAction("Show all but this section", this, [=] () { |
| 666 | setAllSectionsVisibility(true); |
| 667 | setSectionVisibility(section, false); |
| 668 | }); |
| 669 | |
| 670 | button->setContextMenuPolicy(Qt::CustomContextMenu); |
| 671 | connect(button, &QWidget::customContextMenuRequested, this, [=] (const QPoint &p) { |
| 672 | toggleSection->setText(_sections[section] ? "Hide section" : "Show section"); |
| 673 | menu->exec(button->mapToGlobal(p)); |
| 674 | }); |
| 675 | |
| 676 | auto* menuItem = ui->sectionMenu_pushButton->menu()->addAction(section, this, handler); |
| 677 | menuItem->setCheckable(true); |
| 678 | |
| 679 | connect(this, &OutputWidget::sectionToggled, button, [=] (const QString& s, bool visible) { |
| 680 | if (section == s) { |
| 681 | button->setChecked(visible); |
| 682 | menuItem->setChecked(visible); |
| 683 | } |
| 684 | }); |
| 685 | |
| 686 | ui->toggleAll_pushButton->setEnabled(true); |
| 687 | |
| 688 | button->setMinimumWidth(1); |
| 689 | |
| 690 | ui->sectionButtons_horizontalLayout->addWidget(button); |
| 691 | |
| 692 | layoutButtons(); |
| 693 | } |
| 694 | |
| 695 | void OutputWidget::setSectionVisibility(const QString& section, bool visible) |