From 39620bc8f02e0a6a4cb0bbaa868a364c6437f338 Mon Sep 17 00:00:00 2001 From: Uwe Rathmann Date: Thu, 22 Feb 2024 10:11:50 +0100 Subject: [PATCH] obsolete code removed --- examples/tabview/CMakeLists.txt | 7 +- examples/tabview/CustomSlider.cpp | 58 ---- examples/tabview/CustomSlider.h | 20 -- examples/tabview/CustomSliderSkinlet.cpp | 377 ----------------------- examples/tabview/CustomSliderSkinlet.h | 45 --- examples/tabview/OtherSlider.cpp | 91 ------ examples/tabview/OtherSlider.h | 15 - examples/tabview/main.cpp | 42 --- 8 files changed, 1 insertion(+), 654 deletions(-) delete mode 100644 examples/tabview/CustomSlider.cpp delete mode 100644 examples/tabview/CustomSlider.h delete mode 100644 examples/tabview/CustomSliderSkinlet.cpp delete mode 100644 examples/tabview/CustomSliderSkinlet.h delete mode 100644 examples/tabview/OtherSlider.cpp delete mode 100644 examples/tabview/OtherSlider.h diff --git a/examples/tabview/CMakeLists.txt b/examples/tabview/CMakeLists.txt index 70e4c967..564835fa 100644 --- a/examples/tabview/CMakeLists.txt +++ b/examples/tabview/CMakeLists.txt @@ -3,9 +3,4 @@ # SPDX-License-Identifier: BSD-3-Clause ############################################################################ -qsk_add_example(tabview - CustomSlider.h CustomSlider.cpp - CustomSliderSkinlet.h CustomSliderSkinlet.cpp - OtherSlider.h OtherSlider.cpp - main.cpp -) +qsk_add_example(tabview main.cpp) diff --git a/examples/tabview/CustomSlider.cpp b/examples/tabview/CustomSlider.cpp deleted file mode 100644 index aedfec13..00000000 --- a/examples/tabview/CustomSlider.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - * QSkinny - Copyright (C) The authors - * SPDX-License-Identifier: BSD-3-Clause - *****************************************************************************/ - -#include "CustomSlider.h" -#include "CustomSliderSkinlet.h" - -#include -#include -#include -#include -#include - -#include -#include - -QSK_SUBCONTROL( CustomSlider, Scale ) -QSK_SUBCONTROL( CustomSlider, Decoration ) - -CustomSlider::CustomSlider( QQuickItem* parentItem ) - : QskSlider( parentItem ) -{ - using namespace QskRgb; - - QskSkinHintTableEditor ed( &hintTable() ); - - ed.setBoxShape( Fill, 0 ); - ed.setGradient( Fill, QskRgb::DimGray ); - ed.setColor( Scale, qRgb( 178, 178, 178 ) ); // for the ticks - - ed.setStrutSize( Handle, 80, 80 ); - ed.setColor( Handle, QskRgb::DimGray ); - - ed.setColor( Handle | Pressed, QskRgb::Orange ); - - const auto combinationMask = Focused | Hovered; - - ed.setColor( Handle, QskRgb::Orange, combinationMask ); - ed.setAnimation( Handle | QskAspect::Color, 300, combinationMask ); - - ed.setAnimation( Handle | QskAspect::Color, 1000 ); - - // using an individual skinlet, not known by the skin - - auto skinlet = new CustomSliderSkinlet(); - skinlet->setOwnedBySkinnable( true ); - - setSkinlet( skinlet ); - - connect( this, &QskSlider::valueChanged, - this, &QskControl::focusIndicatorRectChanged ); -} - -QRectF CustomSlider::focusIndicatorRect() const -{ - return subControlRect( Handle ); -} diff --git a/examples/tabview/CustomSlider.h b/examples/tabview/CustomSlider.h deleted file mode 100644 index 628a171e..00000000 --- a/examples/tabview/CustomSlider.h +++ /dev/null @@ -1,20 +0,0 @@ -/****************************************************************************** - * QSkinny - Copyright (C) The authors - * SPDX-License-Identifier: BSD-3-Clause - *****************************************************************************/ - -#pragma once - -#include - -class CustomSlider : public QskSlider -{ - using Inherited = QskSlider; - - public: - QSK_SUBCONTROLS( Scale, Decoration ) - - CustomSlider( QQuickItem* parent = nullptr ); - - QRectF focusIndicatorRect() const override; -}; diff --git a/examples/tabview/CustomSliderSkinlet.cpp b/examples/tabview/CustomSliderSkinlet.cpp deleted file mode 100644 index af511854..00000000 --- a/examples/tabview/CustomSliderSkinlet.cpp +++ /dev/null @@ -1,377 +0,0 @@ -/****************************************************************************** - * QSkinny - Copyright (C) The authors - * SPDX-License-Identifier: BSD-3-Clause - *****************************************************************************/ - -#include "CustomSliderSkinlet.h" -#include "CustomSlider.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include - -#if 1 -// should be skin hints -static const qreal qskMinorTick = 20; -static const qreal qskMajorTick = 1.5 * qskMinorTick; -static const qreal qskMargin = 20; -static const qreal qskPeak = 10; - -static QFont qskLabelFont; - -#endif - -namespace -{ - class TicksNode : public QSGGeometryNode - { - public: - TicksNode( const QColor& color ) - : m_geometry( QSGGeometry::defaultAttributes_Point2D(), 0 ) - { - m_geometry.setDrawingMode( QSGGeometry::DrawLines ); - m_geometry.setVertexDataPattern( QSGGeometry::StaticPattern ); - - m_material.setColor( color ); - - setGeometry( &m_geometry ); - setMaterial( &m_material ); - } - - private: - QSGFlatColorMaterial m_material; - QSGGeometry m_geometry; - }; - - class HandleNode : public QSGGeometryNode - { - public: - HandleNode() - : m_geometry( QSGGeometry::defaultAttributes_Point2D(), 8 * 2 ) - { - setGeometry( &m_geometry ); - setMaterial( &m_material ); - } - - void update( const QRectF& rect, qreal peakPos, const QColor& color ) - { - if ( color != m_color ) - { - m_material.setColor( color ); - - m_color = color; - markDirty( QSGNode::DirtyMaterial ); - } - - if ( rect != m_rect || peakPos != m_peakPos ) - { - auto p = reinterpret_cast< QSGGeometry::Point2D* >( m_geometry.vertexData() ); - - const qreal y0 = rect.y() + qskPeak; - - setLine( p, peakPos, peakPos, rect.y() ); - setLine( p + 2, peakPos - 5, peakPos + 5, y0 ); - - // corners manually "rounded" by 3 pixels - - setLine( p + 4, rect.left() + 2, rect.right() - 2, y0 ); - setLine( p + 6, rect.left() + 1, rect.right() - 1, y0 + 1 ); - setLine( p + 8, rect.left(), rect.right(), y0 + 2 ); - setLine( p + 10, rect.left(), rect.right(), rect.bottom() - 1 ); - setLine( p + 12, rect.left() + 1, rect.right() - 1, rect.bottom() - 1 ); - setLine( p + 14, rect.left() + 2, rect.right() - 2, rect.bottom() ); - - m_rect = rect; - m_peakPos = peakPos; - markDirty( QSGNode::DirtyGeometry ); - } - } - - private: - inline void setLine( QSGGeometry::Point2D* points, float x1, float x2, qreal y ) - { - points[ 0 ].x = x1; - points[ 0 ].y = y; - - points[ 1 ].x = x2; - points[ 1 ].y = y; - } - - QRectF m_rect; - qreal m_peakPos; - QColor m_color; - - QSGFlatColorMaterial m_material; - QSGGeometry m_geometry; - }; -} - -CustomSliderSkinlet::CustomSliderSkinlet() -{ - qskLabelFont = QFont(); - setNodeRoles( { ScaleRole, FillRole, DecorationRole, HandleRole } ); -} - -QRectF CustomSliderSkinlet::subControlRect( const QskSkinnable* skinnable, - const QRectF& contentsRect, QskAspect::Subcontrol subControl ) const -{ - const auto slider = static_cast< const QskSlider* >( skinnable ); - - if ( subControl == QskSlider::Groove ) - { - return QRectF(); // we don't have a groove - } - else if ( subControl == QskSlider::Fill ) - { - return fillRect( slider, contentsRect ); - } - else if ( subControl == QskSlider::Handle ) - { - return handleRect( slider, contentsRect ); - } - else if ( subControl == CustomSlider::Scale ) - { - return scaleRect( contentsRect ); - } - else if ( subControl == CustomSlider::Decoration ) - { - return decorationRect( slider, contentsRect ); - } - - return Inherited::subControlRect( skinnable, contentsRect, subControl ); -} - -QSGNode* CustomSliderSkinlet::updateSubNode( - const QskSkinnable* skinnable, quint8 nodeRole, QSGNode* node ) const -{ - const auto slider = static_cast< const QskSlider* >( skinnable ); - - switch ( nodeRole ) - { - case ScaleRole: - return updateScaleNode( slider, node ); - - case DecorationRole: - return updateDecorationNode( slider, node ); - - case FillRole: - return Inherited::updateSubNode( skinnable, nodeRole, node ); - - case HandleRole: - return updateHandleNode( slider, node ); - - default: - return nullptr; - } -} - -QRectF CustomSliderSkinlet::scaleRect( const QRectF& contentsRect ) const -{ - auto r = contentsRect; - - r.setX( r.left() + qskMargin ); - r.setBottom( r.center().y() ); - r.setTop( r.bottom() - qskMajorTick ); - r.setWidth( r.width() - qskMargin ); - - return r; -} - -QRectF CustomSliderSkinlet::fillRect( - const QskSlider* slider, const QRectF& contentsRect ) const -{ - auto r = subControlRect( slider, contentsRect, CustomSlider::Scale ); - - r.setTop( r.bottom() - qskMinorTick ); - r.setWidth( r.width() * slider->valueAsRatio() ); - - return r; -} - -QRectF CustomSliderSkinlet::decorationRect( - const QskSlider* slider, const QRectF& contentsRect ) const -{ - // decoration exceeds scale !!!! - - auto r = subControlRect( slider, contentsRect, CustomSlider::Scale ); - r.setBottom( r.top() ); - r.setTop( r.bottom() - QFontMetricsF( qskLabelFont ).height() ); - - return r; -} - -QRectF CustomSliderSkinlet::handleRect( - const QskSlider* slider, const QRectF& contentsRect ) const -{ - const QRectF fillRect = subControlRect( slider, contentsRect, QskSlider::Fill ); - const QRectF scaleRect = subControlRect( slider, contentsRect, CustomSlider::Scale ); - - QRectF handleRect( 0, scaleRect.bottom(), 80, 50 ); - handleRect.moveCenter( QPointF( fillRect.right(), handleRect.center().y() ) ); - - if ( handleRect.left() < contentsRect.left() ) - { - handleRect.moveLeft( contentsRect.left() ); - } - else if ( handleRect.right() > contentsRect.right() ) - { - handleRect.moveRight( contentsRect.right() ); - } - - return handleRect; -} - -QSGNode* CustomSliderSkinlet::updateScaleNode( - const QskSlider* slider, QSGNode* node ) const -{ - const auto scaleRect = subControlRect( - slider, slider->contentsRect(), CustomSlider::Scale ); - - if ( scaleRect.isEmpty() ) - return nullptr; - - auto ticksNode = static_cast< TicksNode* >( node ); - if ( ticksNode == nullptr ) - ticksNode = new TicksNode( slider->color( CustomSlider::Scale ) ); - - const int tickCount = std::floor( slider->boundaryLength() / slider->stepSize() ) + 1; - - auto geometry = ticksNode->geometry(); - geometry->allocate( tickCount * 2 ); - - auto vertexData = geometry->vertexDataAsPoint2D(); - memset( vertexData, 0, geometry->vertexCount() ); - - auto stepStride = slider->stepSize() / slider->boundaryLength() * scaleRect.width(); - - auto x = scaleRect.x(); - const auto y = scaleRect.bottom(); - - // Create a series of tickmarks from minimum to maximum - for ( int i = 0; i < tickCount; ++i ) - { - vertexData[ 0 ].set( x, y ); - vertexData[ 1 ].set( x, y - ( ( i % 10 ) ? qskMinorTick : qskMajorTick ) ); - - vertexData += 2; - x += stepStride; - } - geometry->setLineWidth( 1 ); - geometry->markVertexDataDirty(); - - ticksNode->markDirty( QSGNode::DirtyGeometry ); - - return ticksNode; -} - -QSGNode* CustomSliderSkinlet::updateDecorationNode( - const QskSlider* slider, QSGNode* node ) const -{ - const QRectF decorationRect = subControlRect( - slider, slider->contentsRect(), CustomSlider::Decoration ); - - if ( decorationRect.isEmpty() ) - return nullptr; - - auto decorationNode = static_cast< QSGTransformNode* >( node ); - if ( decorationNode == nullptr ) - decorationNode = new QSGTransformNode(); - - const int tickCount = std::floor( slider->boundaryLength() / slider->stepSize() ) + 1; - - auto stepStride = slider->stepSize() / slider->boundaryLength() * decorationRect.width(); - - auto x = decorationRect.x(); - const auto y = decorationRect.y(); - - auto labelNode = decorationNode->firstChild(); - - const QFontMetrics fm( qskLabelFont ); - - for ( int i = 0; i < tickCount; i += 100 ) - { - const auto text = QString::number( slider->minimum() + slider->stepSize() * i, 'f', 0 ); - - const auto w = qskHorizontalAdvance( fm, text ); - const auto h = fm.height(); - - labelNode = QskSkinlet::updateTextNode( slider, labelNode, - QRectF( x - 0.5 * w, y, w, h ), Qt::AlignHCenter, text, qskLabelFont, - QskTextOptions(), QskTextColors( QskRgb::DimGray ), Qsk::Normal ); - - if ( labelNode ) - { - if ( labelNode->parent() != decorationNode ) - decorationNode->appendChildNode( labelNode ); - - labelNode = labelNode->nextSibling(); - } - - x += 100 * stepStride; - } - - QskSGNode::removeAllChildNodesAfter( decorationNode, labelNode ); - return decorationNode; -} - -QSGNode* CustomSliderSkinlet::updateHandleNode( - const QskSlider* slider, QSGNode* node ) const -{ - const auto cr = slider->contentsRect(); - - const auto handleRect = subControlRect( slider, cr, QskSlider::Handle ); - - if ( handleRect.isEmpty() ) - return nullptr; - - const auto fillRect = subControlRect( slider, cr, QskSlider::Fill ); - - auto handleNode = static_cast< HandleNode* >( node ); - if ( handleNode == nullptr ) - handleNode = new HandleNode(); - - const auto handleColor = slider->color( QskSlider::Handle ); - handleNode->update( handleRect, fillRect.right(), handleColor ); - - // finally the value label - - QFont font( QStringLiteral( "Roboto" ) ); - font.setPixelSize( 26 ); - - const qreal h = QFontMetrics( font ).height(); - - auto textRect = handleRect; - textRect.setTop( textRect.bottom() - 0.5 * ( textRect.height() - qskPeak + h ) ); - - const auto text = QString::number( slider->value(), 'f', 0 ); - - auto labelNode = QskSkinlet::updateTextNode( slider, handleNode->firstChild(), - textRect, Qt::AlignHCenter, text, font, QskTextOptions(), - QskTextColors( Qt::white ), Qsk::Normal ); - - if ( labelNode->parent() != handleNode ) - handleNode->appendChildNode( labelNode ); - - return handleNode; -} - -QSizeF CustomSliderSkinlet::sizeHint( const QskSkinnable* skinnable, - Qt::SizeHint which, const QSizeF& constraint ) const -{ - auto size = Inherited::sizeHint( skinnable, which, constraint ); - - if ( which == Qt::PreferredSize && size.height() >= 0 ) - size.rheight() += 60; - - return size; -} diff --git a/examples/tabview/CustomSliderSkinlet.h b/examples/tabview/CustomSliderSkinlet.h deleted file mode 100644 index deb23a6f..00000000 --- a/examples/tabview/CustomSliderSkinlet.h +++ /dev/null @@ -1,45 +0,0 @@ -/****************************************************************************** - * QSkinny - Copyright (C) The authors - * SPDX-License-Identifier: BSD-3-Clause - *****************************************************************************/ - -#pragma once - -#include - -class QSGTransformNode; - -class CustomSliderSkinlet : public QskSliderSkinlet -{ - using Inherited = QskSliderSkinlet; - - public: - enum NodeRole - { - // we have a scale instead of a groove - ScaleRole = QskSliderSkinlet::HandleRole + 1, - DecorationRole - }; - - CustomSliderSkinlet(); - - QRectF subControlRect( const QskSkinnable*, - const QRectF&, QskAspect::Subcontrol ) const override; - - QSizeF sizeHint( const QskSkinnable*, - Qt::SizeHint, const QSizeF& ) const override; - - protected: - QSGNode* updateSubNode( const QskSkinnable*, - quint8 nodeRole, QSGNode* ) const override; - - private: - QSGNode* updateScaleNode( const QskSlider*, QSGNode* ) const; - QSGNode* updateDecorationNode( const QskSlider*, QSGNode* ) const; - QSGNode* updateHandleNode( const QskSlider*, QSGNode* ) const; - - QRectF scaleRect( const QRectF& ) const; - QRectF fillRect( const QskSlider*, const QRectF& ) const; - QRectF decorationRect( const QskSlider*, const QRectF& ) const; - QRectF handleRect( const QskSlider*, const QRectF& ) const; -}; diff --git a/examples/tabview/OtherSlider.cpp b/examples/tabview/OtherSlider.cpp deleted file mode 100644 index b8c7f157..00000000 --- a/examples/tabview/OtherSlider.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/****************************************************************************** - * QSkinny - Copyright (C) The authors - * SPDX-License-Identifier: BSD-3-Clause - *****************************************************************************/ - -#include "OtherSlider.h" - -#include -#include -#include -#include -#include - -#include -#include - -#include - -OtherSlider::OtherSlider( QQuickItem* parentItem ) - : QskSlider( parentItem ) -{ - using A = QskAspect; - using namespace QskRgb; - - const qreal h = 30; - const qreal w = 2.0 * h; - const qreal paddingW = 0.5 * w + 1; - - QskSkinHintTableEditor ed( &hintTable() ); - - // Panel - - for ( auto variation : { A::Horizontal, A::Vertical } ) - { - const auto aspect = Panel | variation; - - ed.setMetric( aspect | A::Size, h ); - ed.setBoxShape( aspect, 4 ); - ed.setBoxBorderMetrics( aspect, 1 ); - ed.setBoxBorderColors( aspect, DimGray ); - ed.setGradient( aspect, Silver ); - - if ( variation == A::Horizontal ) - ed.setPadding( aspect, QskMargins( paddingW, 0 ) ); - else - ed.setPadding( aspect, QskMargins( 0, paddingW ) ); - } - - // Groove - - for ( auto variation : { A::Horizontal, A::Vertical } ) - { - const auto aspect = Groove | variation; - - ed.setMetric( aspect | A::Size, 4 ); - ed.setBoxBorderMetrics( aspect, 0 ); - ed.setBoxShape( aspect, 1 ); - - ed.setGradient( aspect, Qt::black ); - } - - // no Fill - for ( auto variation : { A::Horizontal, A::Vertical } ) - { - const auto aspect = Fill | variation; - ed.setMetric( aspect | A::Size, 0 ); - } - - // Handle - - for ( auto variation : { A::Horizontal, A::Vertical } ) - { - const auto aspect = Handle | variation; - - ed.setBoxBorderMetrics( aspect, 1 ); - ed.setBoxShape( aspect, 4 ); - - const qreal m = 0.5 * std::ceil( 0.5 * ( w - h ) ) + 1; - - if ( variation == A::Horizontal ) - ed.setMargin( aspect, QskMargins( -m, 0 ) ); - else - ed.setMargin( aspect, QskMargins( 0, -m ) ); - - for ( auto state : { A::NoState, Pressed } ) - { - ed.setBoxBorderColors( aspect | state, SlateGrey ); - ed.setGradient( aspect | state, DodgerBlue ); - } - } -} diff --git a/examples/tabview/OtherSlider.h b/examples/tabview/OtherSlider.h deleted file mode 100644 index 0cb01910..00000000 --- a/examples/tabview/OtherSlider.h +++ /dev/null @@ -1,15 +0,0 @@ -/****************************************************************************** - * QSkinny - Copyright (C) The authors - * SPDX-License-Identifier: BSD-3-Clause - *****************************************************************************/ - -#pragma once - -#include - -class OtherSlider : public QskSlider -{ - public: - // Slider overriding many hints from the skin. - OtherSlider( QQuickItem* = nullptr ); -}; diff --git a/examples/tabview/main.cpp b/examples/tabview/main.cpp index 0a3b7ab9..29504d9f 100644 --- a/examples/tabview/main.cpp +++ b/examples/tabview/main.cpp @@ -3,13 +3,8 @@ * SPDX-License-Identifier: BSD-3-Clause *****************************************************************************/ -#include "CustomSlider.h" -#include "OtherSlider.h" - #include -#include -#include #include #include #include @@ -35,36 +30,6 @@ class Label : public QskTextLabel } }; -class SliderBox : public QskLinearBox -{ - public: - SliderBox( QQuickItem* parent = nullptr ) - : QskLinearBox( Qt::Vertical, parent ) - { - setMargins( 30 ); - setSpacing( 50 ); - setExtraSpacingAt( Qt::BottomEdge ); - - { - auto slider = new OtherSlider( this ); - - slider->setMinimum( 0 ); - slider->setMaximum( 10 ); - slider->setStepSize( 1 ); - } - - { - auto slider = new CustomSlider( this ); - - slider->setSnap( true ); - slider->setMinimum( 0 ); - slider->setMaximum( 2000 ); - slider->setStepSize( 10 ); - slider->setPageSize( 10 ); - } - } -}; - class TabView : public QskTabView { public: @@ -78,16 +43,11 @@ class TabView : public QskTabView const auto text = QStringLiteral( "Another Tab" ); addTab( text, new Label( text ) ); } - else if ( i == 7 ) - { - addTab( "Sliders", new SliderBox() ); - } else { const auto text = QString( "Tab %1" ).arg( i + 1 ); addTab( text, new Label( text ) ); } - } setTabEnabled( 2, false ); @@ -168,8 +128,6 @@ int main( int argc, char* argv[] ) layoutBox->addItem( tabView ); auto focusIndicator = new QskFocusIndicator(); - focusIndicator->setObjectName( "FocusIndicator" ); - focusIndicator->setBoxBorderColorsHint( QskFocusIndicator::Panel, Qt::red ); QskWindow window; window.resize( 800, 600 );