#include "Gui/Parameters/IntSliderParm.h" #include "Engine/Parameter/Range.h" #include "Engine/Types.h" #include #include #include #include #include #include #include #include #include #include enzo::ui::IntSliderParm::IntSliderParm(std::weak_ptr parameter, QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) { // tells qt to style the widget even though it's a Q_OBJECT setAttribute(Qt::WA_StyledBackground, true); setFixedHeight(24); notchPen_ = QPen(QColor("#383838"), notchWidth, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin); parameter_=parameter; mainLayout_ = new QVBoxLayout(); setLayout(mainLayout_); valueLabel_ = new QLabel(); valueLabel_->setAlignment(Qt::AlignCenter); valueLabel_->setStyleSheet("background-color: none;"); setProperty("type", "SliderParm"); setStyleSheet(R"( QWidget[type="SliderParm"] { border-radius: 6px; border: 1px solid #383838; } )"); mainLayout_->addWidget(valueLabel_); if(auto parameterShared=parameter_.lock()) { auto range = parameterShared->getTemplate().getRange(); minValue_=range.getMin(); maxValue_=range.getMax(); clampMin_=range.getMinFlag()==prm::RangeFlag::LOCKED; clampMax_=range.getMaxFlag()==prm::RangeFlag::LOCKED; setValueImpl(parameterShared->evalInt()); } else { throw std::bad_weak_ptr(); } } void enzo::ui::IntSliderParm::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); const int valueRange = maxValue_-minValue_; float fillPercent = std::clamp(static_cast(value_-minValue_)/valueRange, 0, 1); float margin = 3; float fillWidth = rect().width()-margin*2; fillWidth *= fillPercent; QRectF fillRect = {rect().left()+margin, rect().top()+margin, fillWidth, rect().height()-margin*2}; painter.setPen(notchPen_); QRectF markerLinesRect = rect(); markerLinesRect.adjust(margin, margin, -margin, -margin); const int notchCount = std::min(valueRange, 100); for(int i=1;imaxValue_) { value = maxValue_; } value_ = value; QString valStr = QString::number(value_); valStr.truncate(4); valueLabel_->setText(valStr); } void enzo::ui::IntSliderParm::setValue(bt::intT value) { setValueImpl(value); update(); valueChanged(value_); } void enzo::ui::IntSliderParm::mouseMoveEvent(QMouseEvent *event) { // normalized float value = static_cast(event->pos().x())/rect().width(); //remap value = minValue_+(maxValue_-minValue_)*value; setValue(rint(value)); } void enzo::ui::IntSliderParm::mousePressEvent(QMouseEvent *event) { // normalized float value = static_cast(event->pos().x())/rect().width(); //remap value = minValue_+(maxValue_-minValue_)*value; setValue(rint(value)); }