diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index ec82b290e0..3aa038180a 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -92,7 +92,7 @@ add_definitions(-DBOOST_ALL_DYN_LINK) find_package(Boost COMPONENTS system filesystem thread chrono REQUIRED) message(STATUS "Building " ${PROJECT_NAME}) -add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES} ${PROJECT_RESOURCES} include/gui/widgets/compositewidget.h) +add_library(${PROJECT_NAME} SHARED ${PROJECT_SOURCES} ${PROJECT_RESOURCES}) generate_export_header( ${PROJECT_NAME} EXPORT_FILE_NAME ${CMAKE_CURRENT_SOURCE_DIR}/include/${SCOPY_MODULE}/${PROJECT_NAME}_export.h diff --git a/gui/include/gui/stylehelper.h b/gui/include/gui/stylehelper.h index cc308c0158..e402b85546 100644 --- a/gui/include/gui/stylehelper.h +++ b/gui/include/gui/stylehelper.h @@ -73,6 +73,7 @@ class SCOPY_GUI_EXPORT StyleHelper : public QObject static void MenuOnOffSwitchButton(SmallOnOffSwitch *w, QString objectName = ""); static void MenuCollapseSection(QWidget *w, QString objectName = ""); static void MenuCollapseHeaderLabel(QLabel *w, QString objectName = ""); + static void MenuCollapseHeaderLineEdit(QLineEdit *w, QString objectName =""); static void MenuComboLabel(QLabel *w, QString objectName = ""); static void MenuHeaderLabel(QLabel *w, QString objectName = ""); static void MenuControlLabel(QLabel *w, QString objectName = ""); diff --git a/gui/include/gui/widgets/compositewidget.h b/gui/include/gui/widgets/compositewidget.h index 4d3547b8ad..c064eaae05 100644 --- a/gui/include/gui/widgets/compositewidget.h +++ b/gui/include/gui/widgets/compositewidget.h @@ -3,6 +3,13 @@ #include +class Collapsable { +public: + virtual bool collapsed() = 0; + virtual void setCollapsed(bool b) = 0; + +}; + class CompositeWidget { public: diff --git a/gui/include/gui/widgets/menucollapsesection.h b/gui/include/gui/widgets/menucollapsesection.h index f0ee3e9bc8..50a0e36c1f 100644 --- a/gui/include/gui/widgets/menucollapsesection.h +++ b/gui/include/gui/widgets/menucollapsesection.h @@ -50,11 +50,11 @@ class SCOPY_GUI_EXPORT MenuCollapseHeader : public QAbstractButton public: MenuCollapseHeader(QString title, MenuCollapseSection::MenuHeaderCollapseStyle style, QWidget *parent); ~MenuCollapseHeader(); - QLabel *label(); + QLineEdit *title(); private: QAbstractButton *m_ctrl; - QLabel *m_label; + QLineEdit *m_label; QHBoxLayout *lay; }; diff --git a/gui/include/gui/widgets/menucontrolbutton.h b/gui/include/gui/widgets/menucontrolbutton.h index 29832dae9b..a0a1e9d712 100644 --- a/gui/include/gui/widgets/menucontrolbutton.h +++ b/gui/include/gui/widgets/menucontrolbutton.h @@ -14,7 +14,15 @@ #include namespace scopy { -class SCOPY_GUI_EXPORT MenuControlButton : public QAbstractButton + +class MenuControlButton; +class SCOPY_GUI_EXPORT MenuControlWidget { + +public: + virtual MenuControlButton* header() = 0; +}; + +class SCOPY_GUI_EXPORT MenuControlButton : public QAbstractButton, public MenuControlWidget { Q_OBJECT QWIDGET_PAINT_EVENT_HELPER @@ -32,7 +40,6 @@ class SCOPY_GUI_EXPORT MenuControlButton : public QAbstractButton void setColor(QColor c); void setCheckBoxStyle(MenuControlButton::CheckboxStyle cs); - void setName(QString s); void setDoubleClickToOpenMenu(bool b); void setOpenMenuChecksThis(bool b); @@ -40,6 +47,11 @@ class SCOPY_GUI_EXPORT MenuControlButton : public QAbstractButton QCheckBox *checkBox(); QPushButton *button(); + MenuControlButton *header() override {return this;} + +public Q_SLOTS: + void setName(QString s); + Q_SIGNALS: void doubleClicked(); @@ -61,16 +73,17 @@ class SCOPY_GUI_EXPORT MenuControlButton : public QAbstractButton void mousePressEvent(QMouseEvent *event) override; }; -class SCOPY_GUI_EXPORT CollapsableMenuControlButton : public QWidget, public CompositeWidget +class SCOPY_GUI_EXPORT CollapsableMenuControlButton : public QWidget, public CompositeWidget, public MenuControlWidget { Q_OBJECT public: CollapsableMenuControlButton(QWidget *parent = nullptr); ~CollapsableMenuControlButton(); - void add(QWidget *ch); - void remove(QWidget *ch); + void add(QWidget *ch) override; + void remove(QWidget *ch) override; MenuControlButton *getControlBtn(); + MenuControlButton *header() override {return m_ctrl;} private: MenuControlButton *m_ctrl; diff --git a/gui/include/gui/widgets/menuheader.h b/gui/include/gui/widgets/menuheader.h index 35f51beb1b..1a1a2827d9 100644 --- a/gui/include/gui/widgets/menuheader.h +++ b/gui/include/gui/widgets/menuheader.h @@ -16,11 +16,11 @@ class SCOPY_GUI_EXPORT MenuHeaderWidget : public QWidget MenuHeaderWidget(QString title, QPen pen, QWidget *parent = nullptr); ~MenuHeaderWidget(); - QLabel *label(); + QLineEdit *title(); void applyStylesheet(); private: - QLabel *m_label; + QLineEdit *m_title; QFrame *m_line; QPen m_pen; }; diff --git a/gui/include/gui/widgets/menusectionwidget.h b/gui/include/gui/widgets/menusectionwidget.h index 6040745dda..0364bd129e 100644 --- a/gui/include/gui/widgets/menusectionwidget.h +++ b/gui/include/gui/widgets/menusectionwidget.h @@ -1,5 +1,7 @@ #ifndef MENUSECTIONWIDGET_H #define MENUSECTIONWIDGET_H +#include "compositewidget.h" +#include "menucollapsesection.h" #include #include #include @@ -8,6 +10,7 @@ #include namespace scopy { + class SCOPY_GUI_EXPORT MenuSectionWidget : public QWidget { Q_OBJECT @@ -34,5 +37,28 @@ class SCOPY_GUI_EXPORT MenuVScrollArea : public QScrollArea QVBoxLayout *m_layout; }; +class SCOPY_GUI_EXPORT MenuSectionCollapseWidget : public QWidget, public Collapsable, public CompositeWidget { + Q_OBJECT + QWIDGET_PAINT_EVENT_HELPER +public: + + MenuSectionCollapseWidget(QString title, MenuCollapseSection::MenuHeaderCollapseStyle style, QWidget *parent = nullptr); + ~MenuSectionCollapseWidget(); + QVBoxLayout *contentLayout() const; + + void add(QWidget *w) override; + void remove(QWidget *w) override; + + bool collapsed() override; + void setCollapsed(bool b) override; + MenuCollapseSection* collapseSection(); + +private: + QVBoxLayout *m_layout; + MenuSectionWidget* m_section; + MenuCollapseSection *m_collapse; + +}; + } // namespace scopy #endif // MENUSECTIONWIDGET_H diff --git a/gui/include/gui/widgets/menuwidget.h b/gui/include/gui/widgets/menuwidget.h new file mode 100644 index 0000000000..491487aa04 --- /dev/null +++ b/gui/include/gui/widgets/menuwidget.h @@ -0,0 +1,54 @@ +#ifndef MENUWIDGET_H +#define MENUWIDGET_H + +#include +#include "compositewidget.h" +#include "menuheader.h" +#include +#include +#include +#include + +namespace scopy { +namespace gui { +class SCOPY_GUI_EXPORT MenuWidget : public QWidget, public CompositeWidget { + Q_OBJECT +public: + + enum MenuAlignment + { + MA_TOPFIRST, + MA_TOPLAST, + MA_BOTTOMFIRST, + MA_BOTTOMLAST + }; + + MenuWidget(QString name, QPen p, QWidget *parent); + ~MenuWidget(); + + void add(QWidget *, QString name, MenuAlignment position); + void add(QWidget *) override; + void remove(QWidget *) override; + void add(QWidget *, QString name); + void remove(QString); + MenuHeaderWidget* header(); + + QWidget* findWidget(QString name); + QString widgetName(QWidget*); + + void collapseAll(); + void setCollapsed(QString name, bool b); + +private: + QMap m_widgetMap; + QSpacerItem *m_spacer; + QVBoxLayout *m_layScroll; + MenuHeaderWidget *m_header; + int uuid; + +}; +} + +} + +#endif // MENUWIDGET_H diff --git a/gui/src/plotchannel.cpp b/gui/src/plotchannel.cpp index dc836229c1..13149e66f1 100644 --- a/gui/src/plotchannel.cpp +++ b/gui/src/plotchannel.cpp @@ -12,6 +12,8 @@ PlotChannel::PlotChannel(QString name, QPen pen, PlotAxis *xAxis, PlotAxis *yAxi , m_handle(nullptr) , m_pen(pen) , m_name(name) + , m_style(0) + , m_thickness(1) { diff --git a/gui/src/stylehelper.cpp b/gui/src/stylehelper.cpp index 0559890bd2..57fa0a3033 100644 --- a/gui/src/stylehelper.cpp +++ b/gui/src/stylehelper.cpp @@ -868,7 +868,8 @@ void StyleHelper::MenuSectionWidget(QWidget *w, QString objectName) w->setObjectName(objectName); w->layout()->setContentsMargins(10, 10, 10, 10); QString style = QString(R"css( - scopy--MenuSectionWidget {background-color: &&UIElementBackground&&; + QWidget{ background-color: &&UIElementBackground&&;} + scopy--MenuSectionWidget { border-radius: 4px; margin-bottom: 3px; } @@ -991,6 +992,35 @@ void StyleHelper::MenuCollapseHeaderLabel(QLabel *w, QString objectName) StyleHelper::MenuMediumLabel(w, objectName); } +void StyleHelper::MenuCollapseHeaderLineEdit(QLineEdit *w, QString objectName) +{ + if(!objectName.isEmpty()) + w->setObjectName(objectName); + w->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); + w->setMinimumWidth(50); + // lbl->setMaximumWidth(80); + QString style = QString(R"css( + QLineEdit { + color: white; + background-color: rgba(255,255,255,0); + font-weight: 500; + font-family: Open Sans; + font-size: 14px; + font-style: normal; + border: 0px solid gray; + border-bottom: 1px solid rgba(255, 255, 255, 102); +padding-left: -2px; + } + QLineEdit:disabled { + border: 0px solid gray; + border-bottom: 0px solid rgba(255, 255, 255, 102); +padding-left: -2px; + } + + )css"); + w->setStyleSheet(style); +} + void StyleHelper::MenuOnOffSwitchButton(SmallOnOffSwitch *w, QString objectName) { if(!objectName.isEmpty()) diff --git a/gui/src/widgets/menucollapsesection.cpp b/gui/src/widgets/menucollapsesection.cpp index 9a86b59fb4..4ab61c058d 100644 --- a/gui/src/widgets/menucollapsesection.cpp +++ b/gui/src/widgets/menucollapsesection.cpp @@ -1,3 +1,4 @@ +#include "qlineedit.h" #include #include @@ -16,8 +17,13 @@ MenuCollapseHeader::MenuCollapseHeader(QString title, MenuCollapseSection::MenuH setCheckable(true); setLayout(lay); - m_label = new QLabel(title, this); - StyleHelper::MenuCollapseHeaderLabel(m_label, "menuCollapseLabel"); + m_label = new QLineEdit(title, this); + m_label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Maximum); + m_label->setEnabled(false); + m_label->setReadOnly(false); + + StyleHelper::MenuCollapseHeaderLineEdit(m_label, "menuCollapseLabel"); + m_label->setTextMargins(0,0,0,0); switch(style) { case MenuCollapseSection::MHCW_ARROW: @@ -42,13 +48,13 @@ MenuCollapseHeader::MenuCollapseHeader(QString title, MenuCollapseSection::MenuH m_ctrl->setAttribute(Qt::WA_TransparentForMouseEvents); lay->addWidget(m_label); - lay->addSpacerItem(new QSpacerItem(40, 40, QSizePolicy::Expanding, QSizePolicy::Maximum)); + lay->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Maximum)); lay->addWidget(m_ctrl); } MenuCollapseHeader::~MenuCollapseHeader() {} -QLabel *MenuCollapseHeader::label() { return m_label; } +QLineEdit *MenuCollapseHeader::title() { return m_label; } MenuCollapseSection::MenuCollapseSection(QString title, MenuCollapseSection::MenuHeaderCollapseStyle style, QWidget *parent) @@ -83,11 +89,7 @@ QString MenuCollapseSection::title() { return m_title; } void MenuCollapseSection::setTitle(QString s) { m_title = s; - m_header->label()->setText(m_title); + m_header->title()->setText(m_title); } -// void MenuCollapseSection::add(QWidget *ch) { -// m_contLayout->addWidget(ch); -//} - #include "moc_menucollapsesection.cpp" diff --git a/gui/src/widgets/menuheader.cpp b/gui/src/widgets/menuheader.cpp index 21625c038b..e62c28c895 100644 --- a/gui/src/widgets/menuheader.cpp +++ b/gui/src/widgets/menuheader.cpp @@ -1,3 +1,4 @@ +#include "qlineedit.h" #include #include @@ -14,22 +15,25 @@ MenuHeaderWidget::MenuHeaderWidget(QString title, QPen pen, QWidget *parent) lay->setMargin(3); // lay->setContentsMargins(3,3,3,3); - m_label = new QLabel(title, this); + m_title = new QLineEdit(title, this); + m_title->setEnabled(false); + m_title->setReadOnly(false); + m_line = new QFrame(this); m_pen = pen; - lay->addWidget(m_label); + lay->addWidget(m_title); lay->addWidget(m_line); applyStylesheet(); } MenuHeaderWidget::~MenuHeaderWidget() {} -QLabel *MenuHeaderWidget::label() { return m_label; } +QLineEdit *MenuHeaderWidget::title() { return m_title; } void MenuHeaderWidget::applyStylesheet() { - StyleHelper::MenuHeaderLabel(m_label, "menuLabel"); + StyleHelper::MenuCollapseHeaderLineEdit(m_title, "menuLabel"); StyleHelper::MenuHeaderLine(m_line, m_pen, "menuSeparator"); StyleHelper::MenuHeaderWidget(this, "menuHeader"); } diff --git a/gui/src/widgets/menusectionwidget.cpp b/gui/src/widgets/menusectionwidget.cpp index eefbbc1e53..3d80ac7bba 100644 --- a/gui/src/widgets/menusectionwidget.cpp +++ b/gui/src/widgets/menusectionwidget.cpp @@ -34,4 +34,51 @@ MenuVScrollArea::~MenuVScrollArea() {} QVBoxLayout *MenuVScrollArea::contentLayout() const { return m_layout; } + +MenuSectionCollapseWidget::MenuSectionCollapseWidget(QString title, MenuCollapseSection::MenuHeaderCollapseStyle style, QWidget *parent) : QWidget(parent) +{ + m_layout = new QVBoxLayout(this); + m_layout->setSpacing(0); + m_layout->setMargin(0); + setLayout(m_layout); + m_section = new MenuSectionWidget(parent); + m_collapse = new MenuCollapseSection(title, style, m_section); + m_layout->addWidget(m_section); + m_section->contentLayout()->addWidget(m_collapse); +} + +MenuSectionCollapseWidget::~MenuSectionCollapseWidget() +{ + +} + +QVBoxLayout *MenuSectionCollapseWidget::contentLayout() const +{ + return m_collapse->contentLayout(); +} + +void MenuSectionCollapseWidget::add(QWidget *w) +{ + m_collapse->contentLayout()->addWidget(w); +} + +void MenuSectionCollapseWidget::remove(QWidget *w) +{ + m_collapse->contentLayout()->removeWidget(w); +} + +bool MenuSectionCollapseWidget::collapsed() +{ + return m_collapse->header()->isChecked(); +} + +void MenuSectionCollapseWidget::setCollapsed(bool b) +{ + m_collapse->header()->setChecked(!b); +} + +MenuCollapseSection *MenuSectionCollapseWidget::collapseSection() +{ + return m_collapse; +} #include "moc_menusectionwidget.cpp" diff --git a/gui/src/widgets/menuwidget.cpp b/gui/src/widgets/menuwidget.cpp new file mode 100644 index 0000000000..da9262c15b --- /dev/null +++ b/gui/src/widgets/menuwidget.cpp @@ -0,0 +1,122 @@ +#include "menuwidget.h" +#include +#include + +using namespace scopy; +using namespace scopy::gui; + +MenuWidget::MenuWidget(QString name, QPen p, QWidget *parent) : QWidget(parent) +{ + uuid = 0; + QVBoxLayout *lay = new QVBoxLayout(); + + QScrollArea *scroll = new QScrollArea(parent); + QWidget *wScroll = new QWidget(scroll); + + m_layScroll = new QVBoxLayout(); + m_layScroll->setMargin(0); + m_layScroll->setSpacing(10); + + wScroll->setLayout(m_layScroll); + scroll->setWidgetResizable(true); + scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + // if ScrollBarAlwaysOn - layScroll->setContentsMargins(0,0,6,0); + + scroll->setWidget(wScroll); + + lay->setMargin(0); + lay->setSpacing(10); + setLayout(lay); + + m_spacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding); + m_layScroll->addSpacerItem(m_spacer); + + m_header = new MenuHeaderWidget(name, p, this); + lay->addWidget(m_header); + lay->addWidget(scroll); + +} + +MenuWidget::~MenuWidget() +{ + +} + +void MenuWidget::add(QWidget *w, QString name, MenuAlignment position) +{ + m_widgetMap.insert(name, w); + int spacerIndex = m_layScroll->indexOf(m_spacer); + switch(position){ + + case MA_TOPFIRST: + m_layScroll->insertWidget(0,w); + break; + case MA_TOPLAST: + m_layScroll->insertWidget(spacerIndex, w); + break; + case MA_BOTTOMFIRST: + m_layScroll->insertWidget(spacerIndex + 1, w); + break; + case MA_BOTTOMLAST: + m_layScroll->insertWidget(-1,w); + break; + } +} + +void MenuWidget::add(QWidget *w) +{ + add(w,"widget" + QString(uuid), MA_TOPLAST); + uuid++; +} + +void MenuWidget::add(QWidget *w, QString name) +{ + add(w, name, MA_TOPLAST); +} + +void MenuWidget::remove(QWidget *w) +{ + m_widgetMap.remove(widgetName(w)); + m_layScroll->removeWidget(w); +} + + +void MenuWidget::remove(QString s) +{ + QWidget *w = findWidget(s); + m_widgetMap.remove(s); + m_layScroll->removeWidget(w); +} + +MenuHeaderWidget *MenuWidget::header() +{ + return m_header; +} + +QWidget *MenuWidget::findWidget(QString name) +{ + return m_widgetMap.value(name, nullptr); +} + +QString MenuWidget::widgetName(QWidget *w) +{ + return m_widgetMap.key(w, ""); +} + +void MenuWidget::collapseAll() { + for(QWidget *w : m_widgetMap.values()) { + Collapsable *c = dynamic_cast(w); + if(c != nullptr) { + c->setCollapsed(true); + } + } +} + +void MenuWidget::setCollapsed(QString name, bool b) { + QWidget *w = findWidget(name); + Collapsable *c = dynamic_cast(w); + if(c != nullptr) { + c->setCollapsed(b); + } +} diff --git a/plugins/adc/src/adcinstrumentcontroller.cpp b/plugins/adc/src/adcinstrumentcontroller.cpp index 3993eac703..d1d8f27ef2 100644 --- a/plugins/adc/src/adcinstrumentcontroller.cpp +++ b/plugins/adc/src/adcinstrumentcontroller.cpp @@ -256,7 +256,8 @@ void ADCInstrumentController::addChannel(AcqTreeNode *node) Q_ASSERT(grtsc); m_plotComponentManager->addChannel(c); - c->insertMenuWidget(m_plotComponentManager->plotCombo(c)); + QWidget *ww = m_plotComponentManager->plotCombo(c); + c->menu()->add(ww,"plot",gui::MenuWidget::MA_BOTTOMFIRST); /*** This is a bit of a mess because CollapsableMenuControlButton is not a MenuControlButton ***/ @@ -293,7 +294,7 @@ void ADCInstrumentController::addChannel(AcqTreeNode *node) new ImportChannelComponent(ifcn, chIdP->pen(idx)); m_plotComponentManager->addChannel(c); - c->insertMenuWidget(m_plotComponentManager->plotCombo(c)); + c->menu()->add(m_plotComponentManager->plotCombo(c),"plot",gui::MenuWidget::MA_BOTTOMFIRST); CompositeWidget *cw = m_otherCMCB; m_acqNodeComponentMap[ifcn] = c; @@ -302,6 +303,8 @@ void ADCInstrumentController::addChannel(AcqTreeNode *node) connect(c->ctrl(), &QAbstractButton::clicked, this, [=]() { m_plotComponentManager->selectChannel(c); }); + c->ctrl()->animateClick(); + m_timePlotSettingsComponent->addChannel(c); // SingleY/etc addComponent(c); diff --git a/plugins/adc/src/adcplugin.cpp b/plugins/adc/src/adcplugin.cpp index 19aa8e0d05..5b913e46ca 100644 --- a/plugins/adc/src/adcplugin.cpp +++ b/plugins/adc/src/adcplugin.cpp @@ -69,13 +69,9 @@ bool ADCPlugin::loadPreferencesPage() m_preferencesPage = new QWidget(); QVBoxLayout *lay = new QVBoxLayout(m_preferencesPage); - MenuSectionWidget *generalWidget = new MenuSectionWidget(m_preferencesPage); - MenuCollapseSection *generalSection = - new MenuCollapseSection("General", MenuCollapseSection::MHCW_NONE, generalWidget); - generalWidget->contentLayout()->setSpacing(10); - generalWidget->contentLayout()->addWidget(generalSection); + MenuSectionCollapseWidget *generalSection = new MenuSectionCollapseWidget("General", MenuCollapseSection::MHCW_NONE); generalSection->contentLayout()->setSpacing(10); - lay->addWidget(generalWidget); + lay->addWidget(generalSection); lay->setMargin(0); lay->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); diff --git a/plugins/adc/src/channelcomponent.cpp b/plugins/adc/src/channelcomponent.cpp index 42c082eda0..eede99971e 100644 --- a/plugins/adc/src/channelcomponent.cpp +++ b/plugins/adc/src/channelcomponent.cpp @@ -1,4 +1,5 @@ #include "channelcomponent.h" +#include "qlineedit.h" #include #include #include @@ -7,6 +8,7 @@ #include #include #include +#include Q_LOGGING_CATEGORY(CAT_TIME_CHANNELCOMPONENT, "TimeChannelComponent"); @@ -20,6 +22,7 @@ ChannelComponent::ChannelComponent(QString ch, TimePlotComponent *m_plot, QPen p , m_pen(pen) , m_chData(new ChannelData(this)) , m_plotChannelCmpt(new TimePlotComponentChannel(this, m_plot, this)) + , m_menu(nullptr) { m_ctrl = nullptr; @@ -67,9 +70,25 @@ void ChannelComponent::removeChannelFromPlot() } -void ChannelComponent::insertMenuWidget(QWidget *) +MenuWidget *ChannelComponent::menu() { + return m_menu; +} + +void ChannelComponent::enable() +{ + m_plotChannelCmpt->enable(); + ToolComponent::enable(); +} +void ChannelComponent::disable() +{ + m_plotChannelCmpt->disable(); + ToolComponent::disable(); +} + +void ChannelComponent::initMenu(QWidget *parent){ + m_menu = new MenuWidget(m_channelName, m_pen, parent); } void ChannelComponent::createMenuControlButton(ChannelComponent *c, QWidget *parent) @@ -84,12 +103,15 @@ void ChannelComponent::createMenuControlButton(ChannelComponent *c, QWidget *par c->m_ctrl->setCheckable(true); connect(c->m_ctrl->checkBox(), &QCheckBox::toggled, c, [=](bool b) { - if(b) + if(b) { c->enable(); - else + } else { c->disable(); + } + c->plotChannelCmpt()->m_plotComponent->replot(); }); c->m_ctrl->checkBox()->setChecked(true); + } ImportChannelComponent::ImportChannelComponent(ImportFloatChannelNode *node, QPen pen, QWidget *parent) : ChannelComponent(node->recipe().name, node->recipe().targetPlot, pen, parent) @@ -104,10 +126,8 @@ ImportChannelComponent::ImportChannelComponent(ImportFloatChannelNode *node, QPe widget = createMenu(this); m_lay->addWidget(widget); setLayout(m_lay); - createMenuControlButton(this); - } ImportChannelComponent::~ImportChannelComponent() @@ -125,60 +145,37 @@ void ImportChannelComponent::onInit() addChannelToPlot(); chData()->onNewData(rec.x.data(), rec.y.data(), rec.x.size(), true); - m_plotChannelCmpt->refreshData(false); + m_plotChannelCmpt->refreshData(true); } QWidget *ImportChannelComponent::createMenu(QWidget *parent) { - QWidget *w = new QWidget(parent); - QVBoxLayout *lay = new QVBoxLayout(); - - QScrollArea *scroll = new QScrollArea(parent); - QWidget *wScroll = new QWidget(scroll); - - m_layScroll = new QVBoxLayout(); - m_layScroll->setMargin(0); - m_layScroll->setSpacing(10); - - wScroll->setLayout(m_layScroll); - scroll->setWidgetResizable(true); - scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - // if ScrollBarAlwaysOn - layScroll->setContentsMargins(0,0,6,0); - - scroll->setWidget(wScroll); - - lay->setMargin(0); - lay->setSpacing(10); - w->setLayout(lay); - - MenuHeaderWidget *header = new MenuHeaderWidget(m_channelName, m_pen, w); - QWidget *yaxismenu = createYAxisMenu(w); - QWidget *curvemenu = createCurveMenu(w); + initMenu(parent); + QWidget *yaxismenu = createYAxisMenu(m_menu); + QWidget *curvemenu = createCurveMenu(m_menu); // QWidget *measuremenu = m_measureMgr->createMeasurementMenu(w); - lay->addWidget(header); - lay->addWidget(scroll); + m_menu->header()->title()->setEnabled(true); + connect(m_menu->header()->title(), &QLineEdit::textChanged, this, [=](QString s) { + m_ctrl->setName(s); + }); QPushButton *m_forget = new QPushButton("Remove reference channel"); StyleHelper::BlueButton(m_forget); connect(m_forget, &QAbstractButton::clicked, this, &ImportChannelComponent::forgetChannel); - m_layScroll->addWidget(yaxismenu); - m_layScroll->addWidget(curvemenu); - + m_menu->add(yaxismenu,"yaxis"); + m_menu->add(curvemenu,"curve"); + m_menu->add(m_forget,"forget",gui::MenuWidget::MA_BOTTOMLAST); - m_layScroll->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); - m_layScroll->addWidget(m_forget); - return w; + return m_menu; } QWidget *ImportChannelComponent::createYAxisMenu(QWidget *parent) { - MenuSectionWidget *yaxiscontainer = new MenuSectionWidget(parent); - MenuCollapseSection *yaxis = new MenuCollapseSection("Y-AXIS", MenuCollapseSection::MHCW_NONE, yaxiscontainer); - m_yAxisCtrl = new MenuOnOffSwitch("LOCK Y-Axis"); - m_yCtrl = new MenuPlotAxisRangeControl(m_plotChannelCmpt->m_timePlotYAxis, yaxis); - m_autoscaleBtn = new QPushButton(tr("AUTOSCALE"), yaxis); + MenuSectionCollapseWidget *section = new MenuSectionCollapseWidget("Y-AXIS", MenuCollapseSection::MHCW_NONE, parent); + + m_yCtrl = new MenuPlotAxisRangeControl(m_plotChannelCmpt->m_timePlotYAxis, section); + m_autoscaleBtn = new QPushButton(tr("AUTOSCALE"), section); StyleHelper::BlueButton(m_autoscaleBtn); m_autoscaler = new PlotAutoscaler(this); m_autoscaler->addChannels(m_plotChannelCmpt->m_timePlotCh); @@ -190,42 +187,31 @@ QWidget *ImportChannelComponent::createYAxisMenu(QWidget *parent) m_plotChannelCmpt->m_xyPlotYAxis->setInterval(m_yCtrl->min(), m_yCtrl->max()); }); - connect(m_yAxisCtrl->onOffswitch(), &QAbstractButton::toggled, this, [=](bool b){ + connect(section->collapseSection()->header(), &QAbstractButton::toggled, this, [=](bool b){ m_yLock = b; - m_yCtrl->setVisible(!b); - m_autoscaleBtn->setVisible(!b); - m_plotChannelCmpt->setSingleYMode(b); + m_plotChannelCmpt->lockYAxis(!b); }); - m_yAxisCtrl->onOffswitch()->setChecked(true); connect(m_autoscaleBtn, &QAbstractButton::pressed, m_autoscaler, &PlotAutoscaler::autoscale); - yaxis->contentLayout()->addWidget(m_yAxisCtrl); - yaxis->contentLayout()->addWidget(m_yCtrl); - yaxis->contentLayout()->addWidget(m_autoscaleBtn); + section->contentLayout()->addWidget(m_yCtrl); + section->contentLayout()->addWidget(m_autoscaleBtn); - yaxiscontainer->contentLayout()->addWidget(yaxis); - return yaxiscontainer; + return section; } QWidget *ImportChannelComponent::createCurveMenu(QWidget *parent) { - MenuSectionWidget *curvecontainer = new MenuSectionWidget(parent); - m_curveSection = new MenuCollapseSection("CURVE", MenuCollapseSection::MHCW_NONE, curvecontainer); - m_curveSection->contentLayout()->setSpacing(10); + MenuSectionCollapseWidget *section = new MenuSectionCollapseWidget("CURVE", MenuCollapseSection::MHCW_NONE, parent); + section->contentLayout()->setSpacing(10); - m_curvemenu = new MenuPlotChannelCurveStyleControl(m_curveSection); - curvecontainer->contentLayout()->addWidget(m_curveSection); - m_curveSection->contentLayout()->addWidget(m_curvemenu); - return curvecontainer; + m_curvemenu = new MenuPlotChannelCurveStyleControl(section); + section->contentLayout()->addWidget(m_curvemenu); + return section; } void ImportChannelComponent::forgetChannel() { AcqTreeNode* treeRoot= m_node->treeRoot(); treeRoot->removeTreeChild(m_node); } - -void ImportChannelComponent::insertMenuWidget(QWidget *w) { - m_layScroll->insertWidget(3,w); -} diff --git a/plugins/adc/src/channelcomponent.h b/plugins/adc/src/channelcomponent.h index ed11f1f0eb..bc375428c4 100644 --- a/plugins/adc/src/channelcomponent.h +++ b/plugins/adc/src/channelcomponent.h @@ -9,12 +9,15 @@ #include "menucollapsesection.h" #include "menuplotchannelcurvestylecontrol.h" #include "menuplotaxisrangecontrol.h" +#include "menuwidget.h" + namespace scopy { namespace adc { class TimePlotComponentChannel; + class GRChannel { public: @@ -22,7 +25,7 @@ class GRChannel virtual void onNewData(const float *xData, const float *yData, size_t size, bool copy) = 0; }; -class SCOPY_ADC_EXPORT ChannelComponent : public QWidget, public ToolComponent +class SCOPY_ADC_EXPORT ChannelComponent : public QWidget, public ToolComponent, public Menu { Q_OBJECT public: @@ -38,8 +41,8 @@ class SCOPY_ADC_EXPORT ChannelComponent : public QWidget, public ToolComponent virtual MenuControlButton* ctrl(); virtual void addChannelToPlot(); virtual void removeChannelFromPlot(); - virtual void insertMenuWidget(QWidget *); + MenuWidget *menu() override; static void createMenuControlButton(ChannelComponent *c, QWidget *parent = nullptr); protected: @@ -47,12 +50,16 @@ class SCOPY_ADC_EXPORT ChannelComponent : public QWidget, public ToolComponent QPen m_pen; QWidget *widget; MenuControlButton *m_ctrl; + MenuWidget *m_menu; ChannelData *m_chData; TimePlotComponentChannel *m_plotChannelCmpt; + void initMenu(QWidget *parent = nullptr); public Q_SLOTS: + virtual void enable() override; + virtual void disable() override; virtual void onStart() override; virtual void onStop() override; virtual void onInit() override; @@ -70,7 +77,6 @@ class SCOPY_ADC_EXPORT ImportChannelComponent : public ChannelComponent ~ImportChannelComponent(); virtual void onInit() override; - virtual void insertMenuWidget(QWidget*) override; public Q_SLOTS: void forgetChannel(); private: @@ -78,9 +84,7 @@ public Q_SLOTS: QVBoxLayout *m_layScroll; MenuPlotChannelCurveStyleControl *m_curvemenu; - MenuCollapseSection *m_curveSection; - MenuOnOffSwitch *m_yAxisCtrl; MenuPlotAxisRangeControl *m_yCtrl; PlotAutoscaler *m_autoscaler; QPushButton *m_autoscaleBtn; diff --git a/plugins/adc/src/interfaces.h b/plugins/adc/src/interfaces.h index df7e887afc..8a01e67912 100644 --- a/plugins/adc/src/interfaces.h +++ b/plugins/adc/src/interfaces.h @@ -3,8 +3,11 @@ #include "scopy-adc_export.h" #include #include "measurementcontroller.h" +#include "menuwidget.h" namespace scopy::adc { +using namespace scopy; +using namespace scopy::gui; typedef enum { @@ -28,6 +31,10 @@ typedef struct QString name; } SnapshotRecipe; +class SCOPY_ADC_EXPORT Menu { +public: + virtual MenuWidget* menu() = 0; +}; class SCOPY_ADC_EXPORT SampleRateProvider { diff --git a/plugins/adc/src/measurementcontroller.cpp b/plugins/adc/src/measurementcontroller.cpp index 8ed93046a9..c56a57ad6b 100644 --- a/plugins/adc/src/measurementcontroller.cpp +++ b/plugins/adc/src/measurementcontroller.cpp @@ -225,12 +225,9 @@ QWidget *TimeMeasureManager::createMeasurementMenuSection(QString category, QWid { auto m_measureController = getController(); - MenuSectionWidget *measureContainer = new MenuSectionWidget(parent); - MenuCollapseSection *measureSection = - new MenuCollapseSection("MEASUREMENT " + category, MenuCollapseSection::MHCW_ARROW, measureContainer); + MenuSectionCollapseWidget *measureSection = new MenuSectionCollapseWidget("MEASUREMENT " + category, MenuCollapseSection::MHCW_ARROW, parent); QScrollArea *measureScroll = new QScrollArea(measureSection); MeasurementSelector *measureSelector = new MeasurementSelector(); - measureContainer->contentLayout()->addWidget(measureSection); measureSection->contentLayout()->addWidget(measureScroll); measureScroll->setWidget(measureSelector); measureScroll->setWidgetResizable(true); @@ -257,13 +254,13 @@ QWidget *TimeMeasureManager::createMeasurementMenuSection(QString category, QWid }); } } - measureSection->header()->setChecked(false); + measureSection->setCollapsed(true); connect(this, &MeasureManagerInterface::toggleAllMeasurement, measureSelector, &MeasurementSelector::toggleAllMeasurement); connect(this, &MeasureManagerInterface::toggleAllStats, measureSelector, &MeasurementSelector::toggleAllStats); - return measureContainer; + return measureSection; } /* diff --git a/plugins/adc/src/time/grdevicecomponent.cpp b/plugins/adc/src/time/grdevicecomponent.cpp index 6f0be5ce29..d81ac3f53b 100644 --- a/plugins/adc/src/time/grdevicecomponent.cpp +++ b/plugins/adc/src/time/grdevicecomponent.cpp @@ -32,9 +32,7 @@ GRDeviceComponent::GRDeviceComponent(GRIIODeviceSourceNode *node, QWidget *paren QWidget *GRDeviceComponent::createAttrMenu(QWidget *parent) { - MenuSectionWidget *attrContainer = new MenuSectionWidget(parent); - MenuCollapseSection *attr = - new MenuCollapseSection("ATTRIBUTES", MenuCollapseSection::MHCW_NONE, attrContainer); + MenuSectionCollapseWidget *attr = new MenuSectionCollapseWidget("ATTRIBUTES", MenuCollapseSection::MHCW_NONE, parent); QList attrWidgets = IIOWidgetFactory::buildAllAttrsForDevice(m_src->iioDev()); const struct iio_context *ctx = iio_device_get_context(m_src->iioDev()); attrWidgets.append(IIOWidgetFactory::buildSingle( @@ -51,9 +49,8 @@ QWidget *GRDeviceComponent::createAttrMenu(QWidget *parent) } attr->contentLayout()->addLayout(layout); - attrContainer->contentLayout()->addWidget(attr); - attr->header()->setChecked(false); - return attrContainer; + attr->setCollapsed(true); + return attr; } QWidget *GRDeviceComponent::createMenu(QWidget *parent) diff --git a/plugins/adc/src/time/grtimechannelcomponent.cpp b/plugins/adc/src/time/grtimechannelcomponent.cpp index 6bbfe258e7..586beba297 100644 --- a/plugins/adc/src/time/grtimechannelcomponent.cpp +++ b/plugins/adc/src/time/grtimechannelcomponent.cpp @@ -40,8 +40,6 @@ GRTimeChannelComponent::GRTimeChannelComponent(GRIIOFloatChannelNode *node, Time m_measureMgr->initMeasure(m_pen); m_measureMgr->getModel()->setAdcBitCount(m_src->getFmt()->bits); - widget = createMenu(); - setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); auto m_lay = new QVBoxLayout(this); m_lay->setMargin(0); @@ -57,11 +55,10 @@ GRTimeChannelComponent::~GRTimeChannelComponent() {} QWidget *GRTimeChannelComponent::createYAxisMenu(QWidget *parent) { - MenuSectionWidget *yaxiscontainer = new MenuSectionWidget(parent); - MenuCollapseSection *yaxis = new MenuCollapseSection("Y-AXIS", MenuCollapseSection::MHCW_NONE, yaxiscontainer); + MenuSectionCollapseWidget *section = new MenuSectionCollapseWidget("Y-AXIS", MenuCollapseSection::MHCW_ONOFF, parent); // Y-MODE - m_ymodeCb = new MenuCombo("YMODE", yaxis); + m_ymodeCb = new MenuCombo("YMODE", section); auto cb = m_ymodeCb->combo(); cb->addItem("ADC Counts", YMODE_COUNT); cb->addItem("% Full Scale", YMODE_FS); @@ -72,9 +69,8 @@ QWidget *GRTimeChannelComponent::createYAxisMenu(QWidget *parent) m_scaleWidget = IIOWidgetFactory::buildAttrForChannel(m_src->channel(), m_src->scaleAttribute(),this); } - m_yAxisCtrl = new MenuOnOffSwitch("LOCK Y-Axis"); - m_yCtrl = new MenuPlotAxisRangeControl(m_plotChannelCmpt->m_timePlotYAxis, yaxis); - m_autoscaleBtn = new MenuOnOffSwitch(tr("AUTOSCALE"), yaxis, false); + m_yCtrl = new MenuPlotAxisRangeControl(m_plotChannelCmpt->m_timePlotYAxis, section); + m_autoscaleBtn = new MenuOnOffSwitch(tr("AUTOSCALE"), section, false); m_autoscaler = new PlotAutoscaler(this); m_autoscaler->addChannels(m_plotChannelCmpt->m_timePlotCh); @@ -85,14 +81,11 @@ QWidget *GRTimeChannelComponent::createYAxisMenu(QWidget *parent) m_plotChannelCmpt->m_xyPlotYAxis->setInterval(m_yCtrl->min(), m_yCtrl->max()); }); - connect(m_yAxisCtrl->onOffswitch(), &QAbstractButton::toggled, this, [=](bool b){ - m_yLock = b; - m_yCtrl->setVisible(!b); - m_autoscaleBtn->setVisible(!b); - m_plotChannelCmpt->setSingleYMode(b); + connect(section->collapseSection()->header(), &QAbstractButton::toggled, this, [=](bool b){ + m_yLock = b; + m_plotChannelCmpt->lockYAxis(!b); }); - m_yAxisCtrl->onOffswitch()->setChecked(true); connect(m_autoscaleBtn->onOffswitch(), &QAbstractButton::toggled, this, [=](bool b) { m_yCtrl->setEnabled(!b); @@ -100,14 +93,12 @@ QWidget *GRTimeChannelComponent::createYAxisMenu(QWidget *parent) toggleAutoScale(); }); - yaxis->contentLayout()->addWidget(m_yAxisCtrl); - yaxis->contentLayout()->addWidget(m_autoscaleBtn); - yaxis->contentLayout()->addWidget(m_yCtrl); - yaxis->contentLayout()->addWidget(m_ymodeCb); + section->contentLayout()->addWidget(m_autoscaleBtn); + section->contentLayout()->addWidget(m_yCtrl); + section->contentLayout()->addWidget(m_ymodeCb); if(m_scaleWidget) - yaxis->contentLayout()->addWidget(m_scaleWidget); + section->contentLayout()->addWidget(m_scaleWidget); - yaxiscontainer->contentLayout()->addWidget(yaxis); connect(cb, qOverload(&QComboBox::currentIndexChanged), this, [=](int idx) { auto mode = cb->itemData(idx).toInt(); @@ -126,19 +117,17 @@ QWidget *GRTimeChannelComponent::createYAxisMenu(QWidget *parent) cb->setCurrentIndex(idx); }); - return yaxiscontainer; + return section; } QWidget *GRTimeChannelComponent::createCurveMenu(QWidget *parent) { - MenuSectionWidget *curvecontainer = new MenuSectionWidget(parent); - m_curveSection = new MenuCollapseSection("CURVE", MenuCollapseSection::MHCW_NONE, curvecontainer); - m_curveSection->contentLayout()->setSpacing(10); - - m_curvemenu = new MenuPlotChannelCurveStyleControl(m_curveSection); - curvecontainer->contentLayout()->addWidget(m_curveSection); - m_curveSection->contentLayout()->addWidget(m_curvemenu); - return curvecontainer; + MenuSectionCollapseWidget *section = new MenuSectionCollapseWidget("CURVE", MenuCollapseSection::MHCW_NONE, parent); + section->contentLayout()->setSpacing(10); + + m_curvemenu = new MenuPlotChannelCurveStyleControl(section); + section->contentLayout()->addWidget(m_curvemenu); + return section; } @@ -168,53 +157,26 @@ QPushButton *GRTimeChannelComponent::createSnapshotButton(QWidget *parent) QWidget *GRTimeChannelComponent::createMenu(QWidget *parent) { - QWidget *w = new QWidget(parent); - QVBoxLayout *lay = new QVBoxLayout(); - - QScrollArea *scroll = new QScrollArea(parent); - QWidget *wScroll = new QWidget(scroll); - - m_layScroll = new QVBoxLayout(); - m_layScroll->setMargin(0); - m_layScroll->setSpacing(10); - - wScroll->setLayout(m_layScroll); - scroll->setWidgetResizable(true); - scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); - // if ScrollBarAlwaysOn - layScroll->setContentsMargins(0,0,6,0); - - scroll->setWidget(wScroll); - - lay->setMargin(0); - lay->setSpacing(10); - w->setLayout(lay); - - MenuHeaderWidget *header = new MenuHeaderWidget(m_channelName, m_pen, w); - QWidget *yaxismenu = createYAxisMenu(w); - - QWidget *curvemenu = createCurveMenu(w); - QWidget *attrmenu = createAttrMenu(w); - QWidget *measuremenu = m_measureMgr->createMeasurementMenu(w); - m_snapBtn = createSnapshotButton(w); - - lay->addWidget(header); - lay->addWidget(scroll); - m_layScroll->addWidget(yaxismenu); - m_layScroll->addWidget(curvemenu); - m_layScroll->addWidget(attrmenu); - m_layScroll->addWidget(measuremenu); - m_layScroll->addWidget(m_snapBtn); - - m_layScroll->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); - return w; + ChannelComponent::initMenu(parent); + QWidget *yaxismenu = createYAxisMenu(m_menu); + QWidget *curvemenu = createCurveMenu(m_menu); + QWidget *attrmenu = createAttrMenu(m_menu); + QWidget *measuremenu = m_measureMgr->createMeasurementMenu(m_menu); + m_snapBtn = createSnapshotButton(m_menu); + + m_menu->add(yaxismenu, "yaxis"); + m_menu->add(curvemenu, "curve"); + m_menu->add(attrmenu, "attr"); + m_menu->add(measuremenu, "measure"); + m_menu->add(m_snapBtn, "snap",MenuWidget::MA_BOTTOMLAST); + + return m_menu; + } QWidget *GRTimeChannelComponent::createAttrMenu(QWidget *parent) { - MenuSectionWidget *attrcontainer = new MenuSectionWidget(parent); - MenuCollapseSection *attr = - new MenuCollapseSection("ATTRIBUTES", MenuCollapseSection::MHCW_NONE, attrcontainer); + MenuSectionCollapseWidget *section = new MenuSectionCollapseWidget("ATTRIBUTES", MenuCollapseSection::MHCW_NONE, parent); QList attrWidgets = IIOWidgetFactory::buildAllAttrsForChannel(m_src->channel()); auto layout = new QVBoxLayout(); @@ -226,10 +188,9 @@ QWidget *GRTimeChannelComponent::createAttrMenu(QWidget *parent) layout->addWidget(w); } - attr->contentLayout()->addLayout(layout); - attrcontainer->contentLayout()->addWidget(attr); - attr->header()->setChecked(false); - return attrcontainer; + section->contentLayout()->addLayout(layout); + section->setCollapsed(true); + return section; } void GRTimeChannelComponent::onStart() @@ -357,11 +318,6 @@ MeasureManagerInterface *GRTimeChannelComponent::getMeasureManager() { return m_ GRSignalPath *GRTimeChannelComponent::sigpath() { return m_grtch->m_signalPath; } -void GRTimeChannelComponent::insertMenuWidget(QWidget *w) -{ - m_curveSection->contentLayout()->addWidget(w); -} - QVBoxLayout *GRTimeChannelComponent::menuLayout() { return m_layScroll; @@ -370,14 +326,12 @@ QVBoxLayout *GRTimeChannelComponent::menuLayout() void GRTimeChannelComponent::enable() { m_grtch->m_signalPath->setEnabled(true); - m_plotChannelCmpt->enable(); ChannelComponent::enable(); } void GRTimeChannelComponent::disable() { m_grtch->m_signalPath->setEnabled(false); - m_plotChannelCmpt->disable(); ChannelComponent::disable(); } diff --git a/plugins/adc/src/time/grtimechannelcomponent.h b/plugins/adc/src/time/grtimechannelcomponent.h index 1b5077c287..b668c38b31 100644 --- a/plugins/adc/src/time/grtimechannelcomponent.h +++ b/plugins/adc/src/time/grtimechannelcomponent.h @@ -13,6 +13,7 @@ #include #include "interfaces.h" #include +#include namespace scopy { namespace adc { @@ -71,7 +72,6 @@ class SCOPY_ADC_EXPORT GRTimeChannelComponent MeasureManagerInterface *getMeasureManager() override; GRSignalPath *sigpath() override; - void insertMenuWidget(QWidget *w) override; QVBoxLayout* menuLayout(); YMode ymode() const override; @@ -112,7 +112,6 @@ public Q_SLOTS: QVBoxLayout *m_layScroll; TimeMeasureManager *m_measureMgr; - MenuOnOffSwitch *m_yAxisCtrl; MenuPlotAxisRangeControl *m_yCtrl; PlotAutoscaler *m_autoscaler; MenuOnOffSwitch *m_autoscaleBtn; @@ -120,7 +119,6 @@ public Q_SLOTS: IIOWidget* m_scaleWidget; MenuPlotChannelCurveStyleControl *m_curvemenu; - MenuCollapseSection *m_curveSection; QPushButton *m_snapBtn; @@ -130,6 +128,7 @@ public Q_SLOTS: bool m_running; QString m_unit; + QWidget *createMenu(QWidget *parent = nullptr); QWidget *createAttrMenu(QWidget *parent); QWidget *createYAxisMenu(QWidget *parent); diff --git a/plugins/adc/src/time/grtimesinkcomponent.h b/plugins/adc/src/time/grtimesinkcomponent.h index e675b08826..34ccb4a63e 100644 --- a/plugins/adc/src/time/grtimesinkcomponent.h +++ b/plugins/adc/src/time/grtimesinkcomponent.h @@ -18,9 +18,6 @@ class GRTimeSinkComponent : public QObject, public ToolComponent, public DataPro ~GRTimeSinkComponent(); bool finished() override; - bool enabled() const; - - QWidget* createMenu(QWidget *parent = nullptr); public Q_SLOTS: void connectSignalPaths(); void tearDownSignalPaths(); diff --git a/plugins/adc/src/timeplotcomponent.cpp b/plugins/adc/src/timeplotcomponent.cpp index c42b1ea1c3..25d957d29f 100644 --- a/plugins/adc/src/timeplotcomponent.cpp +++ b/plugins/adc/src/timeplotcomponent.cpp @@ -86,7 +86,7 @@ void TimePlotComponent::setSingleYMode(bool b) { m_singleYMode = b; for(TimePlotComponentChannel *pcc : qAsConst(m_channels)) { - pcc->setSingleYMode(b); + pcc->lockYAxis(b); } } @@ -129,6 +129,14 @@ void TimePlotComponent::onXyXNewData(const float *xData_, const float *yData_, s xyXData = yData_; for(TimePlotComponentChannel *ch : qAsConst(m_channels)) { ch->setXyXData(xyXData); + ch->refreshData(copy); + } +} + +void TimePlotComponent::refreshXYXData() { + for(TimePlotComponentChannel *ch : qAsConst(m_channels)) { + ch->setXyXData(xyXData); + ch->refreshData(true); } } @@ -137,8 +145,10 @@ void TimePlotComponent::addChannel(ChannelComponent *c) { m_channels.append(c->plotChannelCmpt()); if(m_XYXChannel == nullptr) { + // if we don't have an XY channel, set this one setXYXChannel(c); } + refreshXYXData(); m_plotMenu->addChannel(c); } diff --git a/plugins/adc/src/timeplotcomponent.h b/plugins/adc/src/timeplotcomponent.h index 395de8c98b..009454ee50 100644 --- a/plugins/adc/src/timeplotcomponent.h +++ b/plugins/adc/src/timeplotcomponent.h @@ -46,6 +46,7 @@ public Q_SLOTS: ChannelComponent *XYXChannel(); void setXYXChannel(ChannelComponent *c); + void refreshXYXData(); Q_SIGNALS: void nameChanged(QString); void requestDeletePlot(); diff --git a/plugins/adc/src/timeplotcomponentchannel.cpp b/plugins/adc/src/timeplotcomponentchannel.cpp index b7cc39f2bf..6e08836200 100644 --- a/plugins/adc/src/timeplotcomponentchannel.cpp +++ b/plugins/adc/src/timeplotcomponentchannel.cpp @@ -83,7 +83,7 @@ void TimePlotComponentChannel::initPlotComponent(TimePlotComponent *plotComponen xyplot->addPlotChannel(m_xyPlotCh); m_xyPlotCh->setEnabled(true); - setSingleYMode(m_plotComponent->singleYMode()); + lockYAxis(m_plotComponent->singleYMode()); m_timePlotYAxis->setInterval(-2048, 2048); m_xyPlotYAxis->setInterval(-2048, 2048); refreshData(true); @@ -108,7 +108,7 @@ void TimePlotComponentChannel::onNewData(const float *xData_, const float *yData void TimePlotComponentChannel::setXyXData(const float *xyxdata) { m_xyXData = xyxdata; } -void TimePlotComponentChannel::setSingleYMode(bool b) +void TimePlotComponentChannel::lockYAxis(bool b) { m_singleYMode = b; if(m_singleYMode) { @@ -130,16 +130,14 @@ void TimePlotComponentChannel::setSingleYMode(bool b) QWidget *TimePlotComponentChannel::createCurveMenu(QWidget *parent) { - MenuSectionWidget *curvecontainer = new MenuSectionWidget(parent); - MenuCollapseSection *curve = new MenuCollapseSection("CURVE", MenuCollapseSection::MHCW_NONE, curvecontainer); + MenuSectionCollapseWidget *curve = new MenuSectionCollapseWidget("CURVE", MenuCollapseSection::MHCW_NONE, parent); MenuPlotChannelCurveStyleControl *curveSettings = new MenuPlotChannelCurveStyleControl(curve); curveSettings->addChannels(m_timePlotCh); curve->contentLayout()->addWidget(curveSettings); - curvecontainer->contentLayout()->addWidget(curve); - return curvecontainer; + return curve; } void TimePlotComponentChannel::enable() diff --git a/plugins/adc/src/timeplotcomponentchannel.h b/plugins/adc/src/timeplotcomponentchannel.h index e1d7ba621b..303a2dbe5a 100644 --- a/plugins/adc/src/timeplotcomponentchannel.h +++ b/plugins/adc/src/timeplotcomponentchannel.h @@ -23,7 +23,7 @@ public Q_SLOTS: void disable(); void onNewData(const float *xData_, const float *yData_, size_t size, bool copy); void setXyXData(const float *); - void setSingleYMode(bool); + void lockYAxis(bool); void refreshData(bool copy); void initPlotComponent(TimePlotComponent *plotComponent); diff --git a/plugins/adc/src/timeplotcomponentsettings.cpp b/plugins/adc/src/timeplotcomponentsettings.cpp index fef3e2efba..d8007f30f2 100644 --- a/plugins/adc/src/timeplotcomponentsettings.cpp +++ b/plugins/adc/src/timeplotcomponentsettings.cpp @@ -23,11 +23,10 @@ TimePlotComponentSettings::TimePlotComponentSettings(TimePlotComponent *plt, QWi setLayout(v); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); - MenuSectionWidget *w = new MenuSectionWidget(this); - v->addWidget(w); - MenuCollapseSection *plotMenu = - new MenuCollapseSection("PLOT - " + plt->name(), MenuCollapseSection::MHCW_NONE, w); + MenuSectionCollapseWidget *section = new MenuSectionCollapseWidget("APLOT - " + plt->name(), MenuCollapseSection::MHCW_NONE, parent); + MenuCollapseSection *plotMenu = section->collapseSection(); + v->addWidget(section); QLabel *plotTitleLabel = new QLabel("Plot title"); StyleHelper::MenuSmallLabel(plotTitleLabel); @@ -81,8 +80,6 @@ TimePlotComponentSettings::TimePlotComponentSettings(TimePlotComponent *plt, QWi connect(m_xAxisShow->onOffswitch(), &QAbstractButton::toggled, this, [=](bool b) { m_plotComponent->showXSourceOnXy(b); }); - w->contentLayout()->addWidget(plotMenu); - m_yModeCb = new MenuCombo("YMODE", plotMenu); auto ycb = m_yModeCb->combo(); ycb->addItem("ADC Counts", YMODE_COUNT); @@ -129,6 +126,24 @@ TimePlotComponentSettings::TimePlotComponentSettings(TimePlotComponent *plt, QWi m_yCtrl->setMax(2048); labelsSwitch->onOffswitch()->setChecked(true); labelsSwitch->onOffswitch()->setChecked(false); + + m_deletePlotHover = new QPushButton("",nullptr); + m_deletePlotHover->setMaximumSize(16, 16); + m_deletePlotHover->setIcon(QIcon(":/gui/icons/orange_close.svg")); + + HoverWidget *hv = new HoverWidget(m_deletePlotHover,m_plotComponent,m_plotComponent); + hv->setStyleSheet("background-color: transparent; border: 0px;"); + hv->setContentPos(HP_TOPLEFT); + hv->setAnchorPos(HP_BOTTOMRIGHT); + hv->setVisible(true); + hv->raise(); + + connect(m_deletePlotHover, &QAbstractButton::clicked, this, [=](){Q_EMIT requestDeletePlot();}); +} + +void TimePlotComponentSettings::showDeleteButtons(bool b) { + m_deletePlot->setVisible(b); + m_deletePlotHover->setVisible(b); } TimePlotComponentSettings::~TimePlotComponentSettings() {} diff --git a/plugins/adc/src/timeplotcomponentsettings.h b/plugins/adc/src/timeplotcomponentsettings.h index 0e978f7954..4f13d65b2d 100644 --- a/plugins/adc/src/timeplotcomponentsettings.h +++ b/plugins/adc/src/timeplotcomponentsettings.h @@ -18,6 +18,8 @@ class SCOPY_ADC_EXPORT TimePlotComponentSettings : public QWidget, public ToolCo TimePlotComponentSettings(TimePlotComponent *plt, QWidget *parent = nullptr); ~TimePlotComponentSettings(); + void showDeleteButtons(bool b); + public Q_SLOTS: void addChannel(ChannelComponent *c); void removeChannel(ChannelComponent *c); @@ -26,6 +28,7 @@ public Q_SLOTS: void onStart() override; void onStop() override; void updateYAxis(); + Q_SIGNALS: void requestDeletePlot(); @@ -41,12 +44,14 @@ public Q_SLOTS: QList m_channels; QList m_scaleProviders; QPushButton *m_deletePlot; + QPushButton *m_deletePlotHover; bool m_autoscaleEnabled; bool m_running; + private: void toggleAutoScale(); void updateYModeCombo(); diff --git a/plugins/adc/src/timeplotmanager.cpp b/plugins/adc/src/timeplotmanager.cpp index d9c9e9f891..6cd024709b 100644 --- a/plugins/adc/src/timeplotmanager.cpp +++ b/plugins/adc/src/timeplotmanager.cpp @@ -81,6 +81,13 @@ uint32_t TimePlotManager::addPlot(QString name) for(TimePlotManagerCombobox *p : m_channelPlotcomboMap.values()) { p->addPlot(plt); } + + bool b = m_plots.count() > 1; + for(TimePlotComponent *plt : qAsConst(m_plots)) { + plt->plotMenu()->showDeleteButtons(b); + } + + return plt->uuid(); } @@ -94,6 +101,11 @@ void TimePlotManager::removePlot(uint32_t uuid) for(TimePlotManagerCombobox *p : m_channelPlotcomboMap.values()) { p->removePlot(plt); } + + bool b = m_plots.count() > 1; + for(TimePlotComponent *plt : qAsConst(m_plots)) { + plt->plotMenu()->showDeleteButtons(b); + } } void TimePlotManager::addChannel(ChannelComponent *c) @@ -103,7 +115,6 @@ void TimePlotManager::addChannel(ChannelComponent *c) plt->addChannel(c); m_channelPlotcomboMap.insert(c, new TimePlotManagerCombobox(this, c)); c->addChannelToPlot(); - } void TimePlotManager::removeChannel(ChannelComponent *c) diff --git a/plugins/adc/src/timeplotmanagercombobox.cpp b/plugins/adc/src/timeplotmanagercombobox.cpp index 553d4a5632..0559560240 100644 --- a/plugins/adc/src/timeplotmanagercombobox.cpp +++ b/plugins/adc/src/timeplotmanagercombobox.cpp @@ -1,5 +1,6 @@ #include "timeplotmanagercombobox.h" #include "timeplotcomponentchannel.h" +#include using namespace scopy; using namespace scopy::adc; @@ -9,7 +10,8 @@ TimePlotManagerCombobox::TimePlotManagerCombobox(TimePlotManager *man, ChannelCo lay->setSpacing(0); lay->setMargin(0); - m_mcombo = new MenuCombo("PLOT", parent); + MenuSectionWidget *sec = new MenuSectionWidget(this); + m_mcombo = new MenuCombo("PLOT", sec); m_combo = m_mcombo->combo(); m_man = man; m_ch = c; @@ -28,8 +30,8 @@ TimePlotManagerCombobox::TimePlotManagerCombobox(TimePlotManager *man, ChannelCo man->moveChannel(m_ch, uuid); man->replot(); }); - - lay->addWidget(m_mcombo); + lay->addWidget(sec); + sec->contentLayout()->addWidget(m_mcombo); } diff --git a/plugins/adc/src/timeplotmanagersettings.cpp b/plugins/adc/src/timeplotmanagersettings.cpp index 575941eaa3..303cb29ec2 100644 --- a/plugins/adc/src/timeplotmanagersettings.cpp +++ b/plugins/adc/src/timeplotmanagersettings.cpp @@ -27,26 +27,14 @@ TimePlotManagerSettings::TimePlotManagerSettings(TimePlotManager *mgr, QWidget * TimePlotManagerSettings::~TimePlotManagerSettings() {} + + QWidget *TimePlotManagerSettings::createMenu(QWidget *parent) { - QScrollArea *scroll = new QScrollArea(parent); - scroll->setWidgetResizable(true); - QWidget *w = new QWidget(scroll); - scroll->setWidget(w); - QVBoxLayout *lay = new QVBoxLayout(w); - lay->setMargin(0); - lay->setSpacing(10); - w->setLayout(lay); - m_pen = QPen(StyleHelper::getColor("ScopyBlue")); + m_menu = new MenuWidget("TIME PLOT", m_pen, parent); - MenuHeaderWidget *header = new MenuHeaderWidget("TIME PLOT", m_pen, w); - QWidget *xaxismenu = createXAxisMenu(w); - - m_plotContainerLayout = new QVBoxLayout(w); - m_plotContainerLayout->setMargin(0); - m_plotContainerLayout->setSpacing(10); - m_plotContainerLayout->setAlignment(Qt::AlignTop); + QWidget *xaxismenu = createXAxisMenu(m_menu); m_addPlotBtn = new QPushButton("Add Plot", this); StyleHelper::BlueButton(m_addPlotBtn, "AddPlotButton"); @@ -63,21 +51,16 @@ QWidget *TimePlotManagerSettings::createMenu(QWidget *parent) removePlot(plt); }); - lay->addWidget(header); - lay->addWidget(xaxismenu); - lay->addLayout(m_plotContainerLayout); - lay->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding)); - lay->addWidget(m_addPlotBtn); - - return scroll; + m_menu->add(xaxismenu, "xaxis"); + m_menu->add(m_addPlotBtn, "add", gui::MenuWidget::MA_BOTTOMLAST); + return m_menu; } QWidget *TimePlotManagerSettings::createXAxisMenu(QWidget *parent) { - MenuSectionWidget *xaxiscontainer = new MenuSectionWidget(parent); - MenuCollapseSection *xaxis = new MenuCollapseSection("X-AXIS", MenuCollapseSection::MHCW_NONE, xaxiscontainer); + MenuSectionCollapseWidget *section = new MenuSectionCollapseWidget("X-AXIS", MenuCollapseSection::MHCW_NONE, parent); - QWidget *bufferPlotSize = new QWidget(xaxis); + QWidget *bufferPlotSize = new QWidget(section); QHBoxLayout *bufferPlotSizeLayout = new QHBoxLayout(bufferPlotSize); bufferPlotSizeLayout->setMargin(0); bufferPlotSizeLayout->setSpacing(10); @@ -113,7 +96,7 @@ QWidget *TimePlotManagerSettings::createXAxisMenu(QWidget *parent) bufferPlotSizeLayout->addWidget(m_bufferSizeSpin); bufferPlotSizeLayout->addWidget(m_plotSizeSpin); - m_syncBufferPlot = new MenuOnOffSwitch(tr("SYNC BUFFER-PLOT SIZES"), xaxis, false); + m_syncBufferPlot = new MenuOnOffSwitch(tr("SYNC BUFFER-PLOT SIZES"), section, false); connect(m_syncBufferPlot->onOffswitch(), &QAbstractButton::toggled, this, [=](bool b) { m_plotSizeSpin->setEnabled(!b); m_rollingModeSw->setEnabled(!b); @@ -127,11 +110,11 @@ QWidget *TimePlotManagerSettings::createXAxisMenu(QWidget *parent) &ScaleSpinButton::setValue); } }); - m_rollingModeSw = new MenuOnOffSwitch(tr("ROLLING MODE"), xaxis, false); + m_rollingModeSw = new MenuOnOffSwitch(tr("ROLLING MODE"), section, false); connect(m_rollingModeSw->onOffswitch(), &QAbstractButton::toggled, this, &TimePlotManagerSettings::setRollingMode); - QWidget *xMinMax = new QWidget(xaxis); + QWidget *xMinMax = new QWidget(section); QHBoxLayout *xMinMaxLayout = new QHBoxLayout(xMinMax); xMinMaxLayout->setMargin(0); xMinMaxLayout->setSpacing(10); @@ -169,7 +152,7 @@ QWidget *TimePlotManagerSettings::createXAxisMenu(QWidget *parent) xMinMaxLayout->addWidget(m_xmin); xMinMaxLayout->addWidget(m_xmax); - m_xModeCb = new MenuCombo("XMode", xaxis); + m_xModeCb = new MenuCombo("XMode", section); auto xcb = m_xModeCb->combo(); xcb->addItem("Samples", XMODE_SAMPLES); @@ -204,7 +187,7 @@ QWidget *TimePlotManagerSettings::createXAxisMenu(QWidget *parent) {"MHz", 1e6}, {"GHz", 1e9}, }, - "SampleRate", 1, DBL_MAX, false, false, xaxis); + "SampleRate", 1, DBL_MAX, false, false, section); m_sampleRateSpin->setValue(10); m_sampleRateSpin->setEnabled(false); @@ -212,17 +195,17 @@ QWidget *TimePlotManagerSettings::createXAxisMenu(QWidget *parent) connect(this, &TimePlotManagerSettings::sampleRateChanged, m_sampleRateSpin, &PositionSpinButton::setValue); - xaxiscontainer->contentLayout()->setSpacing(10); - xaxiscontainer->contentLayout()->addWidget(xaxis); - xaxis->contentLayout()->addWidget(bufferPlotSize); - xaxis->contentLayout()->addWidget(m_syncBufferPlot); - xaxis->contentLayout()->addWidget(m_rollingModeSw); - xaxis->contentLayout()->addWidget(xMinMax); - xaxis->contentLayout()->addWidget(m_xModeCb); - xaxis->contentLayout()->addWidget(m_sampleRateSpin); - xaxis->contentLayout()->setSpacing(10); - - return xaxiscontainer; + section->contentLayout()->setSpacing(10); + + section->contentLayout()->addWidget(bufferPlotSize); + section->contentLayout()->addWidget(m_syncBufferPlot); + section->contentLayout()->addWidget(m_rollingModeSw); + section->contentLayout()->addWidget(xMinMax); + section->contentLayout()->addWidget(m_xModeCb); + section->contentLayout()->addWidget(m_sampleRateSpin); + section->contentLayout()->setSpacing(10); + + return section; } void TimePlotManagerSettings::onInit() @@ -300,6 +283,11 @@ void TimePlotManagerSettings::updateXAxis() } } +MenuWidget *TimePlotManagerSettings::menu() +{ + return m_menu; +} + void TimePlotManagerSettings::onStart() { QComboBox *cb = m_xModeCb->combo(); @@ -329,15 +317,16 @@ void TimePlotManagerSettings::setSyncBufferPlotSize(bool newSyncBufferPlotSize) Q_EMIT syncBufferPlotSizeChanged(newSyncBufferPlotSize); } -void TimePlotManagerSettings::addPlot(TimePlotComponent *plt) +void TimePlotManagerSettings::addPlot(TimePlotComponent *p) { - QWidget *plotMenu = plt->plotMenu(); - m_plotContainerLayout->addWidget(plotMenu); + QWidget *plotMenu = p->plotMenu(); + m_menu->add(plotMenu,p->name()+QString(p->uuid()),gui::MenuWidget::MA_TOPLAST); } void TimePlotManagerSettings::removePlot(TimePlotComponent *p) { - m_plotContainerLayout->removeWidget(p->plotMenu()); + QWidget *plotMenu = p->plotMenu(); + m_menu->remove(plotMenu); } @@ -390,6 +379,11 @@ void TimePlotManagerSettings::updateXModeCombo() } } +/*void TimePlotManagerSettings::collapseAllAndOpenMenu(QString s) { + m_menu->collapseAll(); + m_menu->setCollapsed(s, true); +}*/ + } // namespace adc } // namespace scopy diff --git a/plugins/adc/src/timeplotmanagersettings.h b/plugins/adc/src/timeplotmanagersettings.h index 6b53964a7b..a701098126 100644 --- a/plugins/adc/src/timeplotmanagersettings.h +++ b/plugins/adc/src/timeplotmanagersettings.h @@ -22,7 +22,7 @@ namespace adc { using namespace scopy::gui; -class SCOPY_ADC_EXPORT TimePlotManagerSettings : public QWidget, public ToolComponent +class SCOPY_ADC_EXPORT TimePlotManagerSettings : public QWidget, public ToolComponent, public Menu { Q_OBJECT public: @@ -52,6 +52,7 @@ class SCOPY_ADC_EXPORT TimePlotManagerSettings : public QWidget, public ToolComp void setBufferSize(uint32_t newBufferSize); void updateXAxis(); + MenuWidget *menu() override; public Q_SLOTS: void onStart() override; @@ -68,6 +69,8 @@ public Q_SLOTS: void addPlot(TimePlotComponent *plt); void removePlot(TimePlotComponent *p); + void collapseAllAndOpenMenu(QString s); + Q_SIGNALS: void plotSizeChanged(uint32_t); void bufferSizeChanged(uint32_t); @@ -85,6 +88,7 @@ public Q_SLOTS: void updateXModeCombo(); QPen m_pen; + MenuWidget *m_menu; ScaleSpinButton *m_bufferSizeSpin; ScaleSpinButton *m_plotSizeSpin; @@ -98,7 +102,6 @@ public Q_SLOTS: MenuCombo *m_xModeCb; QPushButton *m_addPlotBtn; - QVBoxLayout *m_plotContainerLayout; QMap m_plotWidgetMap; bool m_sampleRateAvailable;