#include "Gui/Parameters/AbstractSliderParm.h" #include "Engine/Types.h" #include #include #include #include #include #include #include #include enzo::ui::AbstractSliderParm::AbstractSliderParm(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f) { setFixedHeight(24); value_ = defaultValue_; mainLayout_ = new QVBoxLayout(); setLayout(mainLayout_); valueLabel_ = new QLabel(); valueLabel_->setAlignment(Qt::AlignCenter); valueLabel_->setStyleSheet("background-color: transparent;"); setStyleSheet("border-radius: 6px;"); mainLayout_->addWidget(valueLabel_); setValue(value_); } void enzo::ui::AbstractSliderParm::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); painter.setPen(Qt::NoPen); painter.setBrush(QColor("#383838")); QRectF fillRect = event->rect(); float fillPercent = value_/maxValue_; std::cout << "fill percent" << fillPercent << "\n"; float margin = 3; fillRect.adjust(margin, margin, std::max(-fillRect.width()+margin, -fillRect.width()*(1-fillPercent)-margin), -margin); painter.drawRoundedRect(fillRect, 6, 6); } void enzo::ui::AbstractSliderParm::setValue(bt::floatT value) { if(value_==value) return; if(clampMin_ && valuemaxValue_) { value = maxValue_; } value_ = value; update(); QString valStr = QString::number(value); valStr.truncate(4); valueLabel_->setText(valStr); } void enzo::ui::AbstractSliderParm::mouseMoveEvent(QMouseEvent *event) { setValue(static_cast(event->pos().x())/rect().width() * maxValue_); } void enzo::ui::AbstractSliderParm::mousePressEvent(QMouseEvent *event) { setValue(static_cast(event->pos().x())/rect().width() * maxValue_); }