Fixed slider painting, part II, before slider widget rewrite
This commit is contained in:
@@ -46,7 +46,7 @@ BCDeviceView::BCDeviceView(QWidget *parent)
|
||||
// __fix! ziemlich wildes ge-pointere, hier
|
||||
_itemDelegate = new BCValueDelegate( _valueModel.getValueList(), this);
|
||||
setItemDelegateForColumn( 1, _itemDelegate );
|
||||
|
||||
setStyleSheet("padding-left: 8px;");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <QAbstractButton>
|
||||
|
||||
|
||||
// Vorwärtsdeklaration spart Include-Zeit
|
||||
class QPropertyAnimation;
|
||||
|
||||
class BCToggleSwitch : public QAbstractButton
|
||||
|
||||
@@ -143,10 +143,14 @@ void BCValueDelegate::paint(QPainter *painter, const QStyleOptionViewItem& optio
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Zeichnet der 'Sliderindicator', also den Anteil des Gesamtwerts als Fortschrittsbalken
|
||||
*/
|
||||
|
||||
void BCValueDelegate::paintPlainSliderIndicator(QPainter* painter, const QRect& rect, double ratio )const
|
||||
{
|
||||
QRect sliderRect = BCValueSlider::updateEditorRect( rect );
|
||||
qDebug() << " --- Paint SLIDER ";
|
||||
QRect sliderRect = BCValueSlider::clipToSliderRect( rect );
|
||||
BCValueSlider::paintSliderIndicator(painter, sliderRect, ratio );
|
||||
}
|
||||
|
||||
@@ -181,8 +185,8 @@ void BCValueDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionVie
|
||||
void BCValueDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex& index) const
|
||||
{
|
||||
Q_UNUSED(index)
|
||||
|
||||
QRect sliderRect = BCValueSlider::updateEditorRect( option.rect );
|
||||
QRect baseRect = option.rect.adjusted( 0,0,0 + BCValueSlider::cToolIconOffset, 0 );
|
||||
QRect sliderRect = BCValueSlider::clipToSliderRect( baseRect );
|
||||
editor->setGeometry(sliderRect); // Slider nur über Progress Bar
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ BCValueSlider::BCValueSlider( QWidget *parent )
|
||||
|
||||
// wir wollen ja modern sein
|
||||
_sliderStyle = std::make_unique<BCValueSliderStyle>();
|
||||
_slider->setStyle(_sliderStyle.get());
|
||||
//_slider->setStyle(_sliderStyle.get());
|
||||
setAutoFillBackground(true);
|
||||
|
||||
QSizePolicy sp = _commitButton->sizePolicy();
|
||||
@@ -83,13 +83,13 @@ void BCValueSlider::setValueAndRange( const BCValue::ValueRange& params )
|
||||
}
|
||||
|
||||
|
||||
QRect BCValueSlider::updateEditorRect( const QRect& rect)
|
||||
QRect BCValueSlider::clipToSliderRect( const QRect& rect)
|
||||
{
|
||||
return rect.adjusted
|
||||
(
|
||||
rect.width() - cTextBlockOffset, // Von rechts: cTextBlockOffset (==130) px (Breite der Progress Bar)
|
||||
0, // Oben: kein Offset
|
||||
-cPaddingRight, // Rechts: 8px Padding
|
||||
-(cPaddingRight +24 ), // Rechts: 8px Padding
|
||||
0 // Unten: kein Offset
|
||||
);
|
||||
}
|
||||
@@ -105,17 +105,13 @@ void BCValueSlider::paintSliderIndicator(QPainter* painter, const QRect& rect, d
|
||||
painter->save();
|
||||
painter->setRenderHint(QPainter::Antialiasing);
|
||||
|
||||
|
||||
QRect barRect = rect;//.adjusted( 0, 12, 0, -12 );
|
||||
QRect barRect2 = rect;//.adjusted( 0, 12, 0, -12 );
|
||||
QRect barRect = rect;
|
||||
|
||||
const int third = rect.height() / 3;
|
||||
|
||||
barRect.setY( rect.y() + third);
|
||||
barRect.setHeight( third );
|
||||
|
||||
qDebug() << " --- doPaint: " << third << " rect:" << rect << " adj: " << barRect << " 2:" << barRect2;
|
||||
|
||||
// Mini Progress Bar: der Gesamtbereich
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(QColor(0xE0E0E0));
|
||||
@@ -126,10 +122,6 @@ void BCValueSlider::paintSliderIndicator(QPainter* painter, const QRect& rect, d
|
||||
painter->setBrush(QColor(0x0078D4));
|
||||
painter->drawRoundedRect(barRect, 2, 2);
|
||||
|
||||
//painter->setPen(Qt::red);
|
||||
//painter->setBrush(Qt::blue);
|
||||
//painter->drawRoundedRect(barRect, 2, 2);
|
||||
|
||||
painter->restore();
|
||||
}
|
||||
|
||||
@@ -168,7 +160,8 @@ int BCValueSlider::BCValueSliderStyle::pixelMetric(PixelMetric metric, const QSt
|
||||
|
||||
QRect BCValueSlider::BCValueSliderStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex* opt,SubControl sc, const QWidget* widget) const
|
||||
{
|
||||
if (cc == CC_Slider) {
|
||||
if (cc == CC_Slider)
|
||||
{
|
||||
if (const QStyleOptionSlider* slider = qstyleoption_cast<const QStyleOptionSlider*>(opt))
|
||||
{
|
||||
QRect rect = slider->rect;
|
||||
@@ -214,13 +207,17 @@ void BCValueSlider::BCValueSliderStyle::drawHorizontalFluentSlider(QPainter* pai
|
||||
QRect groove = slider->rect;
|
||||
|
||||
|
||||
|
||||
paintSliderIndicator(painter, groove, 0.5 );
|
||||
|
||||
painter->setBrush(Qt::red);
|
||||
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;
|
||||
paintSliderIndicator(painter, groove, 0.5 );
|
||||
painter->setBrush(Qt::red);
|
||||
qDebug() << " --- drawHorizontalFluentSlider" << groove << " Handle: " << handleRect;
|
||||
|
||||
painter->drawRect(handleRect);
|
||||
|
||||
return;
|
||||
@@ -250,8 +247,6 @@ void BCValueSlider::BCValueSliderStyle::drawHorizontalFluentSlider(QPainter* pai
|
||||
painter->setPen(QPen(activeColor, 2));
|
||||
painter->drawEllipse(thumbRect);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
// Inner circle for pressed state
|
||||
if (slider->state & State_Sunken)
|
||||
|
||||
@@ -15,6 +15,7 @@ class QSlider;
|
||||
class QPushButton;
|
||||
class BCValue;
|
||||
|
||||
|
||||
class BCValueSlider : public QWidget, private Ui::BCValueSlider
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -27,14 +28,17 @@ public:
|
||||
void setValueAndRange( const BCValue::ValueRange& params );
|
||||
|
||||
// helper functions
|
||||
static QRect updateEditorRect( const QRect& rect);
|
||||
static QRect clipToSliderRect( const QRect& rect);
|
||||
static void paintSliderIndicator(QPainter* painter, const QRect& rect, double ratio );
|
||||
|
||||
static constexpr int cToolIconOffset = 24;
|
||||
|
||||
signals:
|
||||
|
||||
void valueChanged(int value);
|
||||
void valueCommited(int value);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Fluent Design Slider Style
|
||||
|
||||
Reference in New Issue
Block a user