You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
3.3 KiB
131 lines
3.3 KiB
4 years ago
|
#pragma once
|
||
|
|
||
|
#include <QFrame>
|
||
|
#include <QHBoxLayout>
|
||
|
#include <QLabel>
|
||
|
#include <QPushButton>
|
||
|
#include <QVBoxLayout>
|
||
|
|
||
|
#include "common/params.h"
|
||
4 years ago
|
#include "toggle.h"
|
||
4 years ago
|
|
||
|
QFrame *horizontal_line(QWidget *parent = nullptr);
|
||
|
|
||
|
class AbstractControl : public QFrame {
|
||
|
Q_OBJECT
|
||
|
|
||
4 years ago
|
public:
|
||
|
void setDescription(const QString &desc) {
|
||
|
if(description) description->setText(desc);
|
||
|
}
|
||
|
|
||
|
signals:
|
||
|
void showDescription();
|
||
|
|
||
4 years ago
|
protected:
|
||
4 years ago
|
AbstractControl(const QString &title, const QString &desc = "", const QString &icon = "", QWidget *parent = nullptr);
|
||
4 years ago
|
void hideEvent(QHideEvent *e);
|
||
4 years ago
|
|
||
|
QSize minimumSizeHint() const override {
|
||
|
QSize size = QFrame::minimumSizeHint();
|
||
4 years ago
|
size.setHeight(120);
|
||
4 years ago
|
return size;
|
||
|
};
|
||
|
|
||
|
QHBoxLayout *hlayout;
|
||
4 years ago
|
QPushButton *title_label;
|
||
|
QLabel *description = nullptr;
|
||
4 years ago
|
};
|
||
|
|
||
4 years ago
|
// widget to display a value
|
||
4 years ago
|
class LabelControl : public AbstractControl {
|
||
|
Q_OBJECT
|
||
|
|
||
|
public:
|
||
4 years ago
|
LabelControl(const QString &title, const QString &text, const QString &desc = "", QWidget *parent = nullptr) : AbstractControl(title, desc, "", parent) {
|
||
4 years ago
|
label.setText(text);
|
||
|
label.setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||
|
hlayout->addWidget(&label);
|
||
|
}
|
||
|
void setText(const QString &text) { label.setText(text); }
|
||
|
|
||
|
private:
|
||
|
QLabel label;
|
||
|
};
|
||
|
|
||
4 years ago
|
// widget for a button with a label
|
||
4 years ago
|
class ButtonControl : public AbstractControl {
|
||
|
Q_OBJECT
|
||
|
|
||
|
public:
|
||
|
template <typename Functor>
|
||
4 years ago
|
ButtonControl(const QString &title, const QString &text, const QString &desc, Functor functor, const QString &icon = "", QWidget *parent = nullptr) : AbstractControl(title, desc, icon, parent) {
|
||
4 years ago
|
btn.setText(text);
|
||
|
btn.setStyleSheet(R"(
|
||
4 years ago
|
QPushButton {
|
||
|
padding: 0;
|
||
|
border-radius: 50px;
|
||
|
font-size: 35px;
|
||
|
font-weight: 500;
|
||
|
color: #E4E4E4;
|
||
|
background-color: #393939;
|
||
|
}
|
||
|
QPushButton:disabled {
|
||
|
color: #33E4E4E4;
|
||
|
}
|
||
4 years ago
|
)");
|
||
4 years ago
|
btn.setFixedSize(250, 100);
|
||
4 years ago
|
QObject::connect(&btn, &QPushButton::released, functor);
|
||
|
hlayout->addWidget(&btn);
|
||
|
}
|
||
|
void setText(const QString &text) { btn.setText(text); }
|
||
|
|
||
4 years ago
|
public slots:
|
||
|
void setEnabled(bool enabled) {
|
||
|
btn.setEnabled(enabled);
|
||
|
};
|
||
|
|
||
4 years ago
|
private:
|
||
|
QPushButton btn;
|
||
|
};
|
||
|
|
||
|
class ToggleControl : public AbstractControl {
|
||
|
Q_OBJECT
|
||
|
|
||
|
public:
|
||
4 years ago
|
ToggleControl(const QString &title, const QString &desc = "", const QString &icon = "", const bool state = false, QWidget *parent = nullptr) : AbstractControl(title, desc, icon, parent) {
|
||
4 years ago
|
toggle.setFixedSize(150, 100);
|
||
4 years ago
|
if (state) {
|
||
4 years ago
|
toggle.togglePosition();
|
||
|
}
|
||
|
hlayout->addWidget(&toggle);
|
||
4 years ago
|
QObject::connect(&toggle, &Toggle::stateChanged, this, &ToggleControl::toggleFlipped);
|
||
4 years ago
|
}
|
||
|
|
||
|
void setEnabled(bool enabled) { toggle.setEnabled(enabled); }
|
||
|
|
||
4 years ago
|
signals:
|
||
|
void toggleFlipped(bool state);
|
||
|
|
||
|
protected:
|
||
4 years ago
|
Toggle toggle;
|
||
|
};
|
||
4 years ago
|
|
||
|
// widget to toggle params
|
||
|
class ParamControl : public ToggleControl {
|
||
|
Q_OBJECT
|
||
|
|
||
|
public:
|
||
4 years ago
|
ParamControl(const QString ¶m, const QString &title, const QString &desc, const QString &icon, QWidget *parent = nullptr) : ToggleControl(title, desc, icon, false, parent) {
|
||
|
if (params.getBool(param.toStdString().c_str())) {
|
||
4 years ago
|
toggle.togglePosition();
|
||
|
}
|
||
4 years ago
|
QObject::connect(this, &ToggleControl::toggleFlipped, [=](bool state) {
|
||
|
params.putBool(param.toStdString().c_str(), state);
|
||
4 years ago
|
});
|
||
|
}
|
||
4 years ago
|
|
||
|
private:
|
||
|
Params params;
|
||
4 years ago
|
};
|