mirror of
https://github.com/Linloir/SceneEditor.git
synced 2025-12-18 16:08:11 +08:00
[UI][ADD] Model attribute slider
- Combined label, slider and value label - Provide redesigned signals
This commit is contained in:
parent
946febaf8d
commit
929fa790b1
79
FinalProject/modelattrslide.cpp
Normal file
79
FinalProject/modelattrslide.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "modelattrslide.h"
|
||||||
|
|
||||||
|
ModelAttributeSlide::ModelAttributeSlide(const QString& label, float min, float max, int step, QWidget* parent) :
|
||||||
|
QWidget(parent)
|
||||||
|
{
|
||||||
|
// Create main stretch layout
|
||||||
|
_stretchLayout = new QHBoxLayout(this);
|
||||||
|
_stretchLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
_stretchLayout->setSpacing(0);
|
||||||
|
setLayout(_stretchLayout);
|
||||||
|
|
||||||
|
// Create Slider
|
||||||
|
_slider = new Slider(min, max, step, this);
|
||||||
|
_stretchLayout->addWidget(_slider);
|
||||||
|
_slider->show();
|
||||||
|
|
||||||
|
// Create Label
|
||||||
|
_label = new QLabel(label, this);
|
||||||
|
_label->setMinimumWidth(56);
|
||||||
|
_label->setFont(QFont("Corbel", 11));
|
||||||
|
_label->show();
|
||||||
|
_slider->mainLayout()->insertWidget(0, _label);
|
||||||
|
_slider->mainLayout()->insertSpacing(1, 8);
|
||||||
|
|
||||||
|
// Create Value label
|
||||||
|
_val = new QLabel(this);
|
||||||
|
_val->setMinimumWidth(32);
|
||||||
|
_val->setFont(QFont("Corbel", 11));
|
||||||
|
_val->setText(QString::number(_slider->val(), 'f', 1));
|
||||||
|
_val->show();
|
||||||
|
_slider->mainLayout()->addSpacing(8);
|
||||||
|
_slider->mainLayout()->addWidget(_val);
|
||||||
|
|
||||||
|
// Connect
|
||||||
|
connect(_slider, &Slider::onChanged, this, &ModelAttributeSlide::onChanged);
|
||||||
|
connect(_slider, &Slider::onSetValue, this, [=]() {
|
||||||
|
_val->setText(QString::number(_slider->val(), 'f', 1));
|
||||||
|
});
|
||||||
|
connect(_slider, &Slider::onDragStart, this, &ModelAttributeSlide::onChangeStart);
|
||||||
|
connect(_slider, &Slider::onDragEnd, this, &ModelAttributeSlide::onChangeEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
ModelAttributeSlide::~ModelAttributeSlide()
|
||||||
|
{}
|
||||||
|
|
||||||
|
void ModelAttributeSlide::setLabel(const QString& label)
|
||||||
|
{
|
||||||
|
_label->setText(label);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelAttributeSlide::setMin(float min)
|
||||||
|
{
|
||||||
|
_slider->setMin(min);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelAttributeSlide::setMax(float max)
|
||||||
|
{
|
||||||
|
_slider->setMax(max);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelAttributeSlide::setStep(float step)
|
||||||
|
{
|
||||||
|
_slider->setStep(step);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelAttributeSlide::setValue(float val)
|
||||||
|
{
|
||||||
|
_slider->setValue(val);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelAttributeSlide::setTransformation(std::function<float(float)> transform, std::function<float(float)> inverse)
|
||||||
|
{
|
||||||
|
_slider->setTransformation(transform, inverse);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelAttributeSlide::setEnabled(bool enable)
|
||||||
|
{
|
||||||
|
_slider->setEnabled(enable);
|
||||||
|
}
|
||||||
42
FinalProject/modelattrslide.h
Normal file
42
FinalProject/modelattrslide.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <qwidget.h>
|
||||||
|
#include <qboxlayout.h>
|
||||||
|
#include <qlabel.h>
|
||||||
|
|
||||||
|
#include "slider.h"
|
||||||
|
|
||||||
|
class ModelAttributeSlide : public QWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
ModelAttributeSlide(const QString& label, float min, float max, int step, QWidget* parent = 0);
|
||||||
|
~ModelAttributeSlide();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QHBoxLayout* _stretchLayout;
|
||||||
|
QLabel* _label;
|
||||||
|
QLabel* _val;
|
||||||
|
Slider* _slider;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Getter APIs
|
||||||
|
float val() const { return _slider->val(); }
|
||||||
|
float lev() const { return _slider->lev(); }
|
||||||
|
|
||||||
|
// Setter APIs
|
||||||
|
void setLabel(const QString& label);
|
||||||
|
void setMin(float min);
|
||||||
|
void setMax(float max);
|
||||||
|
void setStep(float max);
|
||||||
|
void setValue(float val); // Set the actual value
|
||||||
|
void setTransformation(std::function<float(float)> transform, std::function<float(float)> inverse);
|
||||||
|
|
||||||
|
void setEnabled(bool enable = true);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void onChanged(float val);
|
||||||
|
void onChangeStart();
|
||||||
|
void onChangeEnd();
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user