Add MacroListEntryWidget

To be used for macro tab's macro list as regular QListWidgetItem are too
limited
This commit is contained in:
WarmUpTill
2022-01-30 22:15:02 +01:00
committed by WarmUpTill
parent a4f66dbbcd
commit dc698e426d
3 changed files with 65 additions and 0 deletions

View File

@@ -246,6 +246,7 @@ set(advanced-scene-switcher_HEADERS
src/headers/macro-condition-window.hpp
src/headers/macro.hpp
src/headers/macro-controls.hpp
src/headers/macro-list-entry-widget.hpp
src/headers/macro-segment.hpp
src/headers/macro-selection.hpp
src/headers/curl-helper.hpp
@@ -346,6 +347,7 @@ set(advanced-scene-switcher_SOURCES
src/macro-condition-window.cpp
src/macro.cpp
src/macro-controls.cpp
src/macro-list-entry-widget.cpp
src/macro-segment.cpp
src/macro-selection.cpp
src/macro-tab.cpp

View File

@@ -0,0 +1,24 @@
#pragma once
#include <QLabel>
#include <QCheckBox>
#include <memory>
class Macro;
class MacroListEntryWidget : public QWidget {
Q_OBJECT
public:
MacroListEntryWidget(std::shared_ptr<Macro>, QWidget *parent);
void SetName(const QString &);
void SetMacro(std::shared_ptr<Macro> &);
private slots:
void PauseChanged(int);
private:
QLabel *_name;
QCheckBox *_running;
std::shared_ptr<Macro> _macro;
};

View File

@@ -0,0 +1,39 @@
#include "headers/macro-list-entry-widget.hpp"
#include "headers/macro.hpp"
MacroListEntryWidget::MacroListEntryWidget(std::shared_ptr<Macro> macro,
QWidget *parent)
: QWidget(parent), _macro(macro)
{
_name = new QLabel(QString::fromStdString(macro->Name()));
_running = new QCheckBox();
_running->setChecked(!macro->Paused());
connect(_running, SIGNAL(stateChanged(int)), this,
SLOT(PauseChanged(int)));
setStyleSheet("\
QCheckBox { background-color: rgba(0,0,0,0); }\
QLabel { background-color: rgba(0,0,0,0); }");
auto layout = new QHBoxLayout;
layout->setContentsMargins(3, 3, 3, 3);
layout->addWidget(_running);
layout->addWidget(_name);
layout->addStretch();
setLayout(layout);
}
void MacroListEntryWidget::PauseChanged(int state)
{
_macro->SetPaused(!state);
}
void MacroListEntryWidget::SetName(const QString &name)
{
_name->setText(name);
}
void MacroListEntryWidget::SetMacro(std::shared_ptr<Macro> &m)
{
_macro = m;
}