From c8a088173f6820f0ba0598733a1d383313bf9905 Mon Sep 17 00:00:00 2001 From: chris Date: Sun, 29 Mar 2026 16:35:58 +0200 Subject: [PATCH] Fixed slider painting, part I --- bcvaluedelegate.cpp | 2 +- bcvalueslider.cpp | 57 ++++----------- bcvalueslider.h | 4 +- main.cpp | 164 -------------------------------------------- 4 files changed, 15 insertions(+), 212 deletions(-) diff --git a/bcvaluedelegate.cpp b/bcvaluedelegate.cpp index 9abf480..9aae2cc 100644 --- a/bcvaluedelegate.cpp +++ b/bcvaluedelegate.cpp @@ -147,7 +147,7 @@ void BCValueDelegate::paintPlainSliderIndicator(QPainter* painter, const QRect& { QRect sliderRect = BCValueSlider::updateEditorRect( rect ); qDebug() << " --- Paint SLIDER "; - BCValueSlider::paintSliderIndicator2(painter, sliderRect, ratio ); + BCValueSlider::paintSliderIndicator(painter, sliderRect, ratio ); } void BCValueDelegate::paintHighlightRow(QPainter* painter, const QStyleOptionViewItem& option, int row) const diff --git a/bcvalueslider.cpp b/bcvalueslider.cpp index cec66ba..c770b9d 100644 --- a/bcvalueslider.cpp +++ b/bcvalueslider.cpp @@ -101,49 +101,22 @@ QRect BCValueSlider::updateEditorRect( const QRect& rect) void BCValueSlider::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 BCValueSlider::paintSliderIndicator2(QPainter* painter, const QRect& rect, double ratio ) -{ - // Kleinen Slider-Indikator zeichnen - painter->save(); - painter->setRenderHint(QPainter::Antialiasing); - - qDebug() << " --- doPaint: in paintSliderIndicator: " <setPen(Qt::NoPen); painter->setBrush(QColor(0xE0E0E0)); painter->drawRoundedRect(barRect, 2, 2); @@ -152,14 +125,10 @@ void BCValueSlider::paintSliderIndicator2(QPainter* painter, const QRect& rect, barRect.setWidth( ratio * barRect.width() ); painter->setBrush(QColor(0x0078D4)); painter->drawRoundedRect(barRect, 2, 2); -*/ - BCValueSlider::updateEditorRect( rect ); - painter->setBrush(Qt::gray); - painter->drawRoundedRect(rect, 2, 2); - - painter->setBrush(Qt::blue); - painter->drawRoundedRect(barRect, 2, 2); + //painter->setPen(Qt::red); + //painter->setBrush(Qt::blue); + //painter->drawRoundedRect(barRect, 2, 2); painter->restore(); } @@ -250,7 +219,7 @@ void BCValueSlider::BCValueSliderStyle::drawHorizontalFluentSlider(QPainter* pai handleRect.setY( handleRect.y() + 2 ); qDebug() << " --- doPaint: drawHorizontalFluentSlider" << groove << " Handle: " << handleRect; - paintSliderIndicator2(painter, groove, 0.5 ); + paintSliderIndicator(painter, groove, 0.5 ); painter->setBrush(Qt::red); painter->drawRect(handleRect); diff --git a/bcvalueslider.h b/bcvalueslider.h index 2add1ca..ca875ba 100644 --- a/bcvalueslider.h +++ b/bcvalueslider.h @@ -28,9 +28,7 @@ public: // helper functions static QRect updateEditorRect( const QRect& rect); - - static void paintSliderIndicator(QPainter* painter, const QRect& rect, double ratio ); - static void paintSliderIndicator2(QPainter* painter, const QRect& rect, double ratio ); + static void paintSliderIndicator(QPainter* painter, const QRect& rect, double ratio ); signals: diff --git a/main.cpp b/main.cpp index 6eb49b0..1308b34 100644 --- a/main.cpp +++ b/main.cpp @@ -39,174 +39,10 @@ #include -/* -#ifdef _WIN32 -#include // Stellt sicher, dass die Makros __argc und __argv bekannt sind - -extern "C" { -// Wir definieren die fehlenden Import-Pointer manuell und -// leiten sie auf die echten Variablen der neuen MinGW-Laufzeitumgebung um. -int* __imp___argc = &__argc; -char*** __imp___argv = &__argv; -} -#endif -*/ - -/* -// Intermediäre CRTP-Schicht übernimmt die generische Implementierung -template -struct cloneable : public Base -{ - Derived* clone() override - { - return new Derived(static_cast(*this)); - } -}; - - -// Base bleibt sauber – nur pure virtual -struct base -{ - virtual base* clone() = 0; - virtual void moo() const = 0; - virtual ~base() = default; -}; - -// Abgeleitete Klassen erben clone() automatisch -struct derived1 : public cloneable -{ - void moo() const override { qDebug() << " -- derived1 moo"; } -}; - -struct derived2 : public cloneable -{ - void moo() const override { qDebug() << " -- derived2 moo"; } -}; -*/ - -// --- - -/* -struct base -{ - virtual base* clone() = 0; - virtual void moo() const = 0; - virtual ~base() = default; -}; - - -// CRTP-Schicht -template -struct cloneable : public Base -{ - Base* clone() override // Base* statt Derived* - { - return new Derived(static_cast(*this)); - } -}; -*/ - -/* - // Der Rückgabetyp wird exakt nach deinen Vorgaben zur Kompilierzeit ermittelt - template - auto makeD3(this Self&& self) -> std::conditional_t< - std::is_const_v>, - const derived3&, - derived3&> - { - // Da der Rückgabetyp in der Signatur festgeschrieben ist, - // reicht ein einfaches return. Der Compiler bindet die Referenz automatisch korrekt. - return self; - } - - - 2. Der CRTP-Klon-Automatismus - - - Das NVI-Pattern (Non-Virtual Interface) in Kombination mit CRTP ist eine der elegantesten Architekturen im modernen C++, um dieses Problem zu lösen. - */ - -/* -// Abgeleitete Klassen erben clone() automatisch -struct derived1 //: public cloneable -{ - - // Eine einzige Methode für beide Value Categories - auto& nimmMich(this auto& self) - { - return self; - } - -}; - - -struct derived2 : public cloneable -{ - void moo() const override { qDebug() << " -- derived2 moo"; } - - void mooDerived2() const { qDebug() << " -- derived2 moo"; } - - - - - - - void machWasKonstantes() const - { - - const derived1& d3 = d1.nimmMich(); - } - - void machWasSchmutziges() - { - derived1& d3 = d1.nimmMich(); - } - - -private: - - derived1 d1; - -}; - - - -struct derived3 : public cloneable -{ - void moo() const override { qDebug() << " -- derived3 moo"; } - - derived3* clone() override // Base* statt Derived* - { - return new derived3; - } - - - derived2 m_myD2; - -}; -*/ - -/* - Das NVI-Pattern (Non-Virtual Interface) in Kombination mit CRTP ist eine der elegantesten Architekturen - im modernen C++, um dieses Problem zu lösen. Der Trick dabei beruht auf einer C++-Eigenheit: Die Sprache unterstützt "Kovarianz" - (Covariant Return Types) nativ nur bei rohen Zeigern und Referenzen, nicht aber bei Templates wie std::unique_ptr. -*/ int main(int argc, char *argv[]) { - qDebug() << "Starting NtxNode XML Test Suite..."; - - /* - derived2 myDerived2; - base& d2 = *myDerived2.clone(); - d2.moo(); - - derived3 myDerived3; - derived3& d3 = *myDerived3.clone(); - d3.moo(); - - return 0; -*/ - QApplication app(argc, argv);