#include "headers/macro-segment.hpp" #include "headers/section.hpp" #include #include #include #include #include bool MacroSegment::Save(obs_data_t *obj) { obs_data_set_bool(obj, "collapsed", static_cast(_collapsed)); return true; } bool MacroSegment::Load(obs_data_t *obj) { _collapsed = obs_data_get_bool(obj, "collapsed"); return true; } std::string MacroSegment::GetShortDesc() { return ""; } MouseWheelWidgetAdjustmentGuard::MouseWheelWidgetAdjustmentGuard(QObject *parent) : QObject(parent) { } bool MouseWheelWidgetAdjustmentGuard::eventFilter(QObject *o, QEvent *e) { const QWidget *widget = static_cast(o); if (e->type() == QEvent::Wheel && widget && !widget->hasFocus()) { e->ignore(); return true; } return QObject::eventFilter(o, e); } MacroSegmentEdit::MacroSegmentEdit(QWidget *parent) : QWidget(parent) { _section = new Section(300); _headerInfo = new QLabel(); _frame = new QFrame; _frame->setObjectName("segmentFrame"); _highLightFrameLayout = new QVBoxLayout; SetSelected(false); _frame->setLayout(_highLightFrameLayout); // Set background transparent to avoid blocking highlight frame setStyleSheet("QCheckBox { background-color: rgba(0,0,0,0); }" "QLabel { background-color: rgba(0,0,0,0); }" "QSlider { background-color: rgba(0,0,0,0); }"); // Keep the size of macro segments consistent, even if there is room in // the edit areas setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); QWidget::connect(_section, &Section::Collapsed, this, &MacroSegmentEdit::Collapsed); // Macro signals QWidget::connect(parent, SIGNAL(MacroAdded(const QString &)), this, SIGNAL(MacroAdded(const QString &))); QWidget::connect(parent, SIGNAL(MacroRemoved(const QString &)), this, SIGNAL(MacroRemoved(const QString &))); QWidget::connect(parent, SIGNAL(MacroRenamed(const QString &, const QString)), this, SIGNAL(MacroRenamed(const QString &, const QString))); // Scene group signals QWidget::connect(parent, SIGNAL(SceneGroupAdded(const QString &)), this, SIGNAL(SceneGroupAdded(const QString &))); QWidget::connect(parent, SIGNAL(SceneGroupRemoved(const QString &)), this, SIGNAL(SceneGroupRemoved(const QString &))); QWidget::connect( parent, SIGNAL(SceneGroupRenamed(const QString &, const QString)), this, SIGNAL(SceneGroupRenamed(const QString &, const QString))); } void MacroSegmentEdit::HeaderInfoChanged(const QString &text) { _headerInfo->setVisible(!text.isEmpty()); _headerInfo->setText(text); } void MacroSegmentEdit::Collapsed(bool collapsed) { if (Data()) { Data()->SetCollapsed(collapsed); } } void MacroSegmentEdit::mousePressEvent(QMouseEvent *event) { if (event->button() == Qt::LeftButton && Data()) { emit SelectionChagned(Data()->GetIndex()); } } void MacroSegmentEdit::SetFocusPolicyOfWidgets() { QList widgets = this->findChildren(); for (auto w : widgets) { w->setFocusPolicy(Qt::StrongFocus); // Ignore QScrollBar as there is no danger of accidentally modifying anything // and long expanded QComboBox would be difficult to interact with otherwise. if (qobject_cast(w)) { continue; } w->installEventFilter(new MouseWheelWidgetAdjustmentGuard(w)); } } void MacroSegmentEdit::SetCollapsed(bool collapsed) { _section->SetCollapsed(collapsed); } void MacroSegmentEdit::SetSelected(bool selected) { if (selected) { _frame->setStyleSheet("#segmentFrame {" "border-color: rgba(0, 0, 0, 255);" "border-width: 2px;" "border-style: dashed;" "border-radius: 4px;" "background-color: rgba(0,0,0,100);" "}"); } else { _frame->setStyleSheet("#segmentFrame {" "border-color: rgba(0, 0, 0, 0);" "border-width: 2px;" "border-style: dashed;" "border-radius: 4px;" "background-color: rgba(0,0,0,50);" "}"); } }