Graphic updates.
This commit is contained in:
@@ -67,26 +67,22 @@ public:
|
||||
: QProxyStyle()
|
||||
{}
|
||||
|
||||
// Wichtig: Genug Platz für Handle reservieren
|
||||
int pixelMetric(PixelMetric metric, const QStyleOption* option = nullptr, const QWidget* widget = nullptr) const override
|
||||
{
|
||||
switch (metric)
|
||||
{
|
||||
case PM_SliderThickness:
|
||||
return 32; // Höhe für horizontalen Slider
|
||||
return 24; // Höhe für horizontalen Slider
|
||||
case PM_SliderLength:
|
||||
return 20; // Handle-Größe
|
||||
return 16; // Handle-Größe
|
||||
case PM_SliderControlThickness:
|
||||
return 20;
|
||||
return 16;
|
||||
case PM_SliderSpaceAvailable:
|
||||
if (option)
|
||||
{
|
||||
if (const QStyleOptionSlider* sliderOpt = qstyleoption_cast<const QStyleOptionSlider*>(option)) {
|
||||
if (sliderOpt->orientation == Qt::Horizontal) {
|
||||
return sliderOpt->rect.width() - 20;
|
||||
} else {
|
||||
return sliderOpt->rect.height() - 20;
|
||||
}
|
||||
if (const QStyleOptionSlider* sliderOpt = qstyleoption_cast<const QStyleOptionSlider*>(option))
|
||||
{
|
||||
return sliderOpt->rect.width() - 20;
|
||||
}
|
||||
}
|
||||
return QProxyStyle::pixelMetric(metric, option, widget);
|
||||
@@ -99,9 +95,10 @@ public:
|
||||
QRect subControlRect(ComplexControl cc, const QStyleOptionComplex* opt,SubControl sc, const QWidget* widget) const override
|
||||
{
|
||||
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;
|
||||
int handleSize = 20;
|
||||
int handleSize = 16;
|
||||
|
||||
if (sc == SC_SliderHandle) {
|
||||
// Handle Position korrekt berechnen
|
||||
@@ -141,12 +138,10 @@ public:
|
||||
QColor accentColor(0, 120, 212); // #0078D4
|
||||
QColor inactiveColor(138, 136, 134); // #8A8886
|
||||
QColor bgColor(255, 255, 255); // White background
|
||||
|
||||
if (slider->orientation == Qt::Horizontal) {
|
||||
drawHorizontalFluentSlider(painter, slider, accentColor, inactiveColor, bgColor);
|
||||
} else {
|
||||
drawVerticalFluentSlider(painter, slider, accentColor, inactiveColor, bgColor);
|
||||
}
|
||||
//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);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -157,7 +152,8 @@ private:
|
||||
|
||||
void drawHorizontalFluentSlider(QPainter* painter, const QStyleOptionSlider* slider,
|
||||
const QColor& activeColor, const QColor& inactiveColor,
|
||||
const QColor& bgColor) const {
|
||||
const QColor& bgColor) const
|
||||
{
|
||||
QRect groove = slider->rect;
|
||||
QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, nullptr);
|
||||
|
||||
@@ -178,16 +174,17 @@ private:
|
||||
painter->drawRoundedRect(activeTrack, grooveHeight / 2, grooveHeight / 2);
|
||||
|
||||
// Handle (Thumb) - Fluent style is more subtle
|
||||
int handleSize = 20;
|
||||
int handleSize = 16;
|
||||
QRect thumbRect(handle.center().x() - handleSize / 2,
|
||||
handle.center().y() - handleSize / 2,
|
||||
handleSize, handleSize);
|
||||
|
||||
// Hover effect - subtle glow
|
||||
if (slider->state & State_MouseOver) {
|
||||
if (slider->state & State_MouseOver)
|
||||
{
|
||||
painter->setBrush(QColor(activeColor.red(), activeColor.green(),
|
||||
activeColor.blue(), 30));
|
||||
int glowSize = 32;
|
||||
int glowSize = 18;
|
||||
QRect glow(handle.center().x() - glowSize / 2,
|
||||
handle.center().y() - glowSize / 2,
|
||||
glowSize, glowSize);
|
||||
@@ -201,7 +198,7 @@ private:
|
||||
|
||||
// Inner circle for pressed state
|
||||
if (slider->state & State_Sunken) {
|
||||
int innerSize = 8;
|
||||
int innerSize = 6;
|
||||
QRect inner(handle.center().x() - innerSize / 2,
|
||||
handle.center().y() - innerSize / 2,
|
||||
innerSize, innerSize);
|
||||
@@ -211,58 +208,6 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
void drawVerticalFluentSlider(QPainter* painter, const QStyleOptionSlider* slider,
|
||||
const QColor& activeColor, const QColor& inactiveColor,
|
||||
const QColor& bgColor) const {
|
||||
QRect groove = slider->rect;
|
||||
QRect handle = subControlRect(CC_Slider, slider, SC_SliderHandle, nullptr);
|
||||
|
||||
int grooveWidth = 4;
|
||||
// Track sollte im Widget-Zentrum sein
|
||||
int grooveX = slider->rect.center().x() - grooveWidth / 2;
|
||||
|
||||
// Full background track
|
||||
QRect fullTrack(grooveX, groove.top(), grooveWidth, groove.height());
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(inactiveColor.lighter(150));
|
||||
painter->drawRoundedRect(fullTrack, grooveWidth / 2, grooveWidth / 2);
|
||||
|
||||
// Active track
|
||||
int activeHeight = groove.bottom() - handle.center().y();
|
||||
QRect activeTrack(grooveX, handle.center().y(), grooveWidth, activeHeight);
|
||||
painter->setBrush(activeColor);
|
||||
painter->drawRoundedRect(activeTrack, grooveWidth / 2, grooveWidth / 2);
|
||||
|
||||
// Handle
|
||||
int handleSize = 20;
|
||||
QRect thumbRect(handle.center().x() - handleSize / 2,
|
||||
handle.center().y() - handleSize / 2,
|
||||
handleSize, handleSize);
|
||||
|
||||
if (slider->state & State_MouseOver) {
|
||||
painter->setBrush(QColor(activeColor.red(), activeColor.green(),
|
||||
activeColor.blue(), 30));
|
||||
int glowSize = 32;
|
||||
QRect glow(handle.center().x() - glowSize / 2,
|
||||
handle.center().y() - glowSize / 2,
|
||||
glowSize, glowSize);
|
||||
painter->drawEllipse(glow);
|
||||
}
|
||||
|
||||
painter->setBrush(bgColor);
|
||||
painter->setPen(QPen(activeColor, 2));
|
||||
painter->drawEllipse(thumbRect);
|
||||
|
||||
if (slider->state & State_Sunken) {
|
||||
int innerSize = 8;
|
||||
QRect inner(handle.center().x() - innerSize / 2,
|
||||
handle.center().y() - innerSize / 2,
|
||||
innerSize, innerSize);
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(activeColor);
|
||||
painter->drawEllipse(inner);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user