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