cleanups.
This commit is contained in:
@@ -30,17 +30,17 @@
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include <bcsliderstyle.h>
|
||||
#include <bcvalueeditor.h>
|
||||
#include <bcvaluesliderstyle.h>
|
||||
#include <bcvalueslider.h>
|
||||
|
||||
|
||||
BCSliderStyle::BCSliderStyle()
|
||||
BCValueSliderStyle::BCValueSliderStyle()
|
||||
: QProxyStyle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int BCSliderStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, const QWidget* widget ) const
|
||||
int BCValueSliderStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, const QWidget* widget ) const
|
||||
{
|
||||
switch (metric)
|
||||
{
|
||||
@@ -65,7 +65,7 @@ int BCSliderStyle::pixelMetric(PixelMetric metric, const QStyleOption* option, c
|
||||
}
|
||||
}
|
||||
|
||||
QRect BCSliderStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex* opt,SubControl sc, const QWidget* widget) const
|
||||
QRect BCValueSliderStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex* opt,SubControl sc, const QWidget* widget) const
|
||||
{
|
||||
if (cc == CC_Slider) {
|
||||
if (const QStyleOptionSlider* slider = qstyleoption_cast<const QStyleOptionSlider*>(opt))
|
||||
@@ -76,35 +76,21 @@ QRect BCSliderStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex
|
||||
if (sc == SC_SliderHandle)
|
||||
{
|
||||
// Handle Position korrekt berechnen
|
||||
if (slider->orientation == Qt::Horizontal)
|
||||
{
|
||||
int range = slider->maximum - slider->minimum;
|
||||
int pos = slider->sliderPosition - slider->minimum;
|
||||
int pixelRange = rect.width() - handleSize;
|
||||
int pixelPos = (range != 0) ? (pos * pixelRange) / range : 0;
|
||||
int range = slider->maximum - slider->minimum;
|
||||
int pos = slider->sliderPosition - slider->minimum;
|
||||
int pixelRange = rect.width() - handleSize;
|
||||
int pixelPos = (range != 0) ? (pos * pixelRange) / range : 0;
|
||||
|
||||
return QRect(rect.x() + pixelPos,
|
||||
rect.center().y() - handleSize / 2,
|
||||
handleSize, handleSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
int range = slider->maximum - slider->minimum;
|
||||
int pos = slider->sliderPosition - slider->minimum;
|
||||
int pixelRange = rect.height() - handleSize;
|
||||
int pixelPos = (range != 0) ? (pos * pixelRange) / range : 0;
|
||||
|
||||
return QRect(rect.center().x() - handleSize / 2,
|
||||
rect.bottom() - pixelPos - handleSize,
|
||||
handleSize, handleSize);
|
||||
}
|
||||
return QRect(rect.x() + pixelPos,
|
||||
rect.center().y() - handleSize / 2,
|
||||
handleSize, handleSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
return QProxyStyle::subControlRect(cc, opt, sc, widget);
|
||||
}
|
||||
|
||||
void BCSliderStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget) const
|
||||
void BCValueSliderStyle::drawComplexControl(ComplexControl control, const QStyleOptionComplex* option, QPainter* painter, const QWidget* widget) const
|
||||
{
|
||||
if (control == CC_Slider)
|
||||
{
|
||||
@@ -113,12 +99,8 @@ void BCSliderStyle::drawComplexControl(ComplexControl control, const QStyleOptio
|
||||
|
||||
// Fluent Colors
|
||||
QColor accentColor(0, 120, 212); // #0078D4
|
||||
QColor inactiveColor(138, 136, 134); // #8A8886
|
||||
QColor bgColor(255, 255, 255); // White background
|
||||
//QColor disabledText = option.palette.color(QPalette::Disabled, QPalette::Text);
|
||||
//painter->setBrush(disabledText);
|
||||
//QColor bgColor = Qt::green;//option->palette.color(QPalette::Base);
|
||||
drawHorizontalFluentSlider(painter, slider, accentColor, inactiveColor, bgColor);
|
||||
drawHorizontalFluentSlider(painter, slider, accentColor, bgColor);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -126,67 +108,56 @@ void BCSliderStyle::drawComplexControl(ComplexControl control, const QStyleOptio
|
||||
}
|
||||
|
||||
|
||||
void BCSliderStyle::drawHorizontalFluentSlider(QPainter* painter, const QStyleOptionSlider* slider,
|
||||
const QColor& activeColor, const QColor& inactiveColor,
|
||||
void BCValueSliderStyle::drawHorizontalFluentSlider(QPainter* painter, const QStyleOptionSlider* slider,
|
||||
const QColor& activeColor,
|
||||
const QColor& bgColor) const
|
||||
{
|
||||
QRect groove = slider->rect;
|
||||
QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, nullptr);
|
||||
|
||||
qDebug() << " ---WTF: " << groove;
|
||||
|
||||
|
||||
BCValueEditor::paintSliderIndicator(painter, groove, 0.5 );
|
||||
/*
|
||||
int grooveHeight = 4;
|
||||
// Track sollte im Widget-Zentrum sein, nicht im groove-Zentrum
|
||||
int grooveY = groove.center().y() - grooveHeight / 2;
|
||||
|
||||
// Full background track
|
||||
QRect fullTrack(groove.left(), grooveY, groove.width(), grooveHeight);
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(inactiveColor.lighter(150));
|
||||
painter->drawRoundedRect(fullTrack, grooveHeight / 2, grooveHeight / 2);
|
||||
|
||||
QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, nullptr);
|
||||
|
||||
// Active track (filled portion)
|
||||
int activeWidth = handle.center().x() - groove.left();
|
||||
QRect activeTrack(groove.left(), grooveY, activeWidth, grooveHeight);
|
||||
painter->setBrush(activeColor);
|
||||
painter->drawRoundedRect(activeTrack, grooveHeight / 2, grooveHeight / 2);
|
||||
*/
|
||||
QRect handleRect = subControlRect(CC_Slider, slider, SC_SliderHandle, nullptr);
|
||||
// Das 'subControlRect' für den SC_SliderHandle ist _nicht_ mittig
|
||||
handleRect.setY( handleRect.y() + 2 );
|
||||
|
||||
qDebug() << " --- doPaint: drawHorizontalFluentSlider" << groove << " Handle: " << handleRect;
|
||||
paintSliderIndicator2(painter, groove, 0.5 );
|
||||
|
||||
painter->setBrush(Qt::red);
|
||||
painter->drawRect(handleRect);
|
||||
|
||||
return;
|
||||
|
||||
// Handle (Thumb) - Fluent style is more subtle
|
||||
int handleSize = 16;
|
||||
QRect thumbRect(handle.center().x() - handleSize / 2,
|
||||
handle.center().y() - handleSize / 2,
|
||||
int handleSize = 14;
|
||||
QRect thumbRect(handleRect.center().x() - handleSize / 2,
|
||||
handleRect.center().y() - handleSize / 2,
|
||||
handleSize, handleSize);
|
||||
|
||||
/*
|
||||
// Hover effect - subtle glow
|
||||
if (slider->state & State_MouseOver)
|
||||
{
|
||||
painter->setBrush(QColor(activeColor.red(), activeColor.green(),
|
||||
activeColor.blue(), 30));
|
||||
int glowSize = 18;
|
||||
int glowSize = 16;
|
||||
QRect glow(handle.center().x() - glowSize / 2,
|
||||
handle.center().y() - glowSize / 2,
|
||||
glowSize, glowSize);
|
||||
painter->drawEllipse(glow);
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
// Thumb
|
||||
painter->setBrush(bgColor);
|
||||
painter->setPen(QPen(activeColor, 2));
|
||||
painter->drawEllipse(thumbRect);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
// Inner circle for pressed state
|
||||
if (slider->state & State_Sunken) {
|
||||
if (slider->state & State_Sunken)
|
||||
{
|
||||
int innerSize = 6;
|
||||
QRect inner(handle.center().x() - innerSize / 2,
|
||||
handle.center().y() - innerSize / 2,
|
||||
@@ -195,5 +166,70 @@ void BCSliderStyle::drawHorizontalFluentSlider(QPainter* painter, const QStyleOp
|
||||
painter->setBrush(activeColor);
|
||||
painter->drawEllipse(inner);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Zeichnet eine passiven Slider, um den möglichen Wertebereich des übergebenen BCValue anzuzeigen.
|
||||
*/
|
||||
|
||||
void BCValueSliderStyle::paintSliderIndicator(QPainter* painter, const QRect& rect, double ratio )
|
||||
{
|
||||
return;
|
||||
|
||||
// Kleinen Slider-Indikator zeichnen
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
int adjX = rect.width() - 130; //cTextBlockOffset;
|
||||
|
||||
// Mini Progress Bar: der Gesamtbereich
|
||||
QRect barRect = rect.adjusted( adjX, 12, -10-24, -12 );
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(QColor(0xE0E0E0));
|
||||
painter->drawRoundedRect(barRect, 2, 2);
|
||||
|
||||
qDebug() << " --- doPaint: in paintSliderIndicator1: " << rect;
|
||||
qDebug() << " --- doPaint: in paintSliderIndicator2: " << barRect;
|
||||
|
||||
// Mini Progress Bar: der Wertebereich
|
||||
barRect.setWidth( ratio * barRect.width() );
|
||||
painter->setBrush(QColor(0x0078D4));
|
||||
painter->drawRoundedRect(barRect, 2, 2);
|
||||
|
||||
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
void BCValueSliderStyle::paintSliderIndicator2(QPainter* painter, const QRect& rect, double ratio )
|
||||
{
|
||||
// Kleinen Slider-Indikator zeichnen
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
qDebug() << " --- doPaint: in paintSliderIndicator: " <<rect;
|
||||
|
||||
painter->setBrush(Qt::green);
|
||||
QRect barRect = rect.adjusted( 0, 5, 0, -5 );
|
||||
painter->drawRoundedRect(barRect, 2, 2);
|
||||
|
||||
/*
|
||||
// Mini Progress Bar: der Gesamtbereich
|
||||
//QRect barRect = rect.adjusted( 0, 12, -10-24, -12 );
|
||||
QRect barRect = rect;//.adjusted( 0, 12, 0, -12 );
|
||||
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(QColor(0xE0E0E0));
|
||||
painter->drawRoundedRect(barRect, 2, 2);
|
||||
|
||||
// Mini Progress Bar: der Wertebereich
|
||||
barRect.setWidth( ratio * barRect.width() );
|
||||
painter->setBrush(QColor(0x0078D4));
|
||||
painter->drawRoundedRect(barRect, 2, 2);
|
||||
*/
|
||||
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user