wip: slider draw algo

This commit is contained in:
Hane 2024-05-02 23:25:06 +02:00
commit c7d77c30ab

View file

@ -11,6 +11,69 @@ void MeterSlider::setPeakValue(float peakValue) {
} }
void MeterSlider::paintEvent(QPaintEvent *event) { void MeterSlider::paintEvent(QPaintEvent *event) {
QStyleOptionSlider sliderComplex = QStyleOptionSlider();
sliderComplex.initFrom(this);
/*
* sliderComplex.initFrom(this);
* sliderComplex.subControls = QStyle::SC_None;
* sliderComplex.activeSubControls = QStyle::SC_None;
* sliderComplex.orientation = this->orientation();
* sliderComplex.maximum = this->maximum();
* sliderComplex.minimum = this->minimum();
* sliderComplex.tickPosition = (QSlider::TickPosition)this->tickPosition();
* sliderComplex.tickInterval = this->tickInterval();
* sliderComplex.upsideDown = (this->orientation() == Qt::Horizontal) ?
* (this->invertedAppearance() != (sliderComplex.direction == Qt::RightToLeft))
* : (!this->invertedAppearance());
* sliderComplex.direction = Qt::LeftToRight; // we use the upsideDown option instead
* sliderComplex.sliderPosition = this->sliderPosition();
* sliderComplex.sliderValue = this->value();
* sliderComplex.singleStep = this->singleStep();
* sliderComplex.pageStep = this->pageStep();
* if (this->orientation() == Qt::Horizontal)
* sliderComplex.state |= QStyle::State_Horizontal;
*
* if (this->isSliderDown()) {
* sliderComplex.activeSubControls = QStyle::SC_SliderHandle;
* sliderComplex.state |= QStyle::State_Sunken;
* } else {
* sliderComplex.activeSubControls = QStyle::SC_SliderHandle;
* }
*
* //sliderComplex.subControls = QStyle::SC_SliderGroove;
* if (this->tickPosition() != NoTicks) sliderComplex.subControls |= QStyle::SC_SliderTickmarks;
* QStylePainter p(this);
* p.drawComplexControl(QStyle::CC_Slider, sliderComplex);
*/
/*
* QStyleOptionSlider sliderComplex2 = QStyleOptionSlider();
* sliderComplex2.initFrom(this);
* sliderComplex2.orientation = this->orientation();
* sliderComplex2.maximum = this->maximum();
* sliderComplex2.minimum = this->minimum();
* sliderComplex2.tickPosition = (QSlider::TickPosition)this->tickPosition();
* sliderComplex2.tickInterval = this->tickInterval();
* sliderComplex2.upsideDown = (this->orientation() == Qt::Horizontal) ?
* (this->invertedAppearance() != (sliderComplex2.direction == Qt::RightToLeft))
* : (!this->invertedAppearance());
* sliderComplex2.subControls = QStyle::SC_SliderHandle;
* sliderComplex2.direction = Qt::LeftToRight; // we use the upsideDown option instead
* sliderComplex2.sliderPosition = this->sliderPosition();
* sliderComplex2.sliderValue = this->value();
* sliderComplex2.singleStep = this->singleStep();
* sliderComplex2.pageStep = this->pageStep();
* if (this->orientation() == Qt::Horizontal)
* sliderComplex2.state |= QStyle::State_Horizontal;
*
* if (this->isSliderDown()) {
* sliderComplex2.activeSubControls = QStyle::SC_SliderHandle;
* sliderComplex2.state |= QStyle::State_Sunken;
* } else {
* sliderComplex2.activeSubControls = QStyle::SC_SliderHandle;
* }
*/
//Q_D(QSlider); //Q_D(QSlider);
/* /*
* QStylePainter p(this); * QStylePainter p(this);
@ -23,7 +86,9 @@ void MeterSlider::paintEvent(QPaintEvent *event) {
* *
* //p.drawComplexControl(QStyle::CC_Slider, opt); * //p.drawComplexControl(QStyle::CC_Slider, opt);
*/ */
QSlider::paintEvent(event); //QSlider::paintEvent(event);
int left = 0, top = 0, right = 0, bottom = 0;
((QWidget*)parent())->layout()->getContentsMargins(&left, &top, &right, &bottom);
QStyle *style = QApplication::style(); QStyle *style = QApplication::style();
int lol = style->pixelMetric(QStyle::PM_SliderSpaceAvailable); int lol = style->pixelMetric(QStyle::PM_SliderSpaceAvailable);
@ -36,11 +101,26 @@ void MeterSlider::paintEvent(QPaintEvent *event) {
double stepWidth = (double)this->width() * ((double)this->singleStep() / (this->maximum() - this->minimum())); double stepWidth = (double)this->width() * ((double)this->singleStep() / (this->maximum() - this->minimum()));
//Fusion seems to fuck around with bar's height and width //Fusion seems to fuck around with bar's height and width
//const qreal dpr = painter->device()->devicePixelRatio(); //const qreal dpr = painter->device()->devicePixelRatio();
QStyleOptionSlider slider = QStyleOptionSlider(); //slider.initFrom(this); //QStyleOptionSlider sliderComplex = QStyleOptionSlider(); //slider.initFrom(this);
QRect test = style->subControlRect(QStyle::CC_Slider, (QStyleOptionComplex*)&slider, QStyle::SC_SliderHandle); QRect sliderSize = style->subControlRect(QStyle::CC_Slider, (QStyleOptionComplex*)&sliderComplex, QStyle::SC_SliderHandle);
int handleCenterPos = QStyle::sliderPositionFromValue(this->minimum(), this->maximum(), this->value(), this->width());
int unattenuatedPeakMeter = ((this->width() * this->peakValue) >= handleCenterPos - (sliderSize.width() / 2))
? this->width() - (sliderSize.width() / 2)
: this->width() * this->peakValue;
//QApplication::style()->subControlRect(QStyle::CC_Slider, (QStyleOptionComplex*)&slider, QStyle::SC_SliderHandle); //QApplication::style()->subControlRect(QStyle::CC_Slider, (QStyleOptionComplex*)&slider, QStyle::SC_SliderHandle);
painter.fillRect(0, (this->height() / 2) - 3, this->width(),
4, Qt::white);
painter.fillRect(0, (this->height() / 2) - 3, this->width() * this->peakValue,
4, Qt::gray);
painter.fillRect(0, (this->height() / 2) - 3, (this->width() - ((this->maximum() - this->value()) * stepWidth)) * this->peakValue, painter.fillRect(0, (this->height() / 2) - 3, (this->width() - ((this->maximum() - this->value()) * stepWidth)) * this->peakValue,
4, Qt::green); 4, Qt::green);
// - ((this->maximum() - this->value()) * stepWidth))
//double ratio = ;
double handleShift = (double)((sliderSize.width() * ((double)(this->maximum() - this->value()) / 100)));
painter.fillRect((this->width() - ((this->maximum() - this->value()) * stepWidth)) - (sliderSize.width()) + handleShift,
top / 2, sliderSize.width(), sliderSize.height() - bottom, Qt::magenta);
//sliderComplex.subControls = QStyle::SC_SliderHandle;
//p.drawComplexControl(QStyle::CC_Slider, sliderComplex);
} }
void ExtendedCheckBox::customEvent(QEvent* ev) { void ExtendedCheckBox::customEvent(QEvent* ev) {